Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgssymbol.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbol.h - description
3  -------------------
4  begin : Sat Jun 22 2002
5  copyright : (C) 2002 by Gary E.Sherman
6  email : sherman at mrcc.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 /* $Id$ */
18 
19 #ifndef QGSSYMBOL_H
20 #define QGSSYMBOL_H
21 
22 #include "qgis.h"
23 #include <QBrush>
24 #include <QPen>
25 #include <QImage>
26 
27 class QDomNode;
28 class QDomDocument;
29 class QDomElement;
30 
31 class QgsVectorLayer;
32 
35 class CORE_EXPORT QgsSymbol
36 {
37  public:
39  QgsSymbol( QGis::GeometryType t, QString lvalue = "", QString uvalue = "", QString label = "" );
41  QgsSymbol( QGis::GeometryType t, QString lvalue, QString uvalue, QString label, QColor c );
42  QgsSymbol( const QgsSymbol& );
44  QgsSymbol();
45  QgsSymbol( QColor c );
47  virtual void setBrush( QBrush b );
49  virtual const QBrush& brush() const;
51  virtual void setColor( QColor c );
53  virtual QColor color() const;
55  virtual QColor fillColor() const;
57  virtual void setFillColor( QColor c );
59  virtual double lineWidth() const;
61  virtual void setLineWidth( double w );
63  virtual void setPen( QPen p );
65  virtual const QPen& pen() const;
66 
68  virtual void setLineStyle( Qt::PenStyle s );
70  virtual void setFillStyle( Qt::BrushStyle s );
71 
73  virtual QString customTexture() const;
75  virtual void setCustomTexture( QString path );
76 
77  virtual void setLowerValue( QString value );
78  virtual QString lowerValue() const;
79  virtual void setUpperValue( QString value );
80  virtual QString upperValue() const;
81  virtual void setLabel( QString label );
82  virtual QString label() const;
83 
85  virtual void setNamedPointSymbol( QString name );
87  virtual QString pointSymbolName() const;
88 
90  virtual void setPointSize( double s );
92  virtual double pointSize() const;
93 
95  virtual void setPointSizeUnits( bool sizeInMapUnits );
97  virtual bool pointSizeUnits() const;
98 
100  virtual ~QgsSymbol();
101 
103  virtual QImage getLineSymbolAsImage();
104 
106  virtual QImage getPolygonSymbolAsImage();
107 
110  virtual QImage getCachedPointSymbolAsImage( double widthScale = 1.0,
111  bool selected = false,
112  QColor selectionColor = Qt::yellow,
113  double opacity = 1.0 );
114 
118  virtual QImage getPointSymbolAsImage( double widthScale = 1.0,
119  bool selected = false,
120  QColor selectionColor = Qt::yellow,
121  double scale = 1.0,
122  double rotation = 0.0,
123  double rasterScaleFactor = 1.0,
124  double opacity = 1.0 );
125 
128  virtual bool writeXML( QDomNode & item, QDomDocument & document, const QgsVectorLayer *vl ) const;
131  virtual bool readXML( QDomNode & symbol, const QgsVectorLayer *vl );
133  QGis::GeometryType type() const {return mType;}
134 
136  int rotationClassificationField() const;
139  void setRotationClassificationField( int field );
140 
142  int scaleClassificationField() const;
145  void setScaleClassificationField( int field );
146 
148  int symbolField() const;
151  void setSymbolField( int field );
152 
153  protected:
154 
156  QString mLowerValue;
158  QString mUpperValue;
159  QString mLabel;
162 
163  QPen mPen;
164  QBrush mBrush;
166  /* Point symbol name */
168  /* size */
169  double mSize;
170  /* units of size */
172 
173 
174  /* TODO Because for printing we always need a symbol without oversampling but with line width scale,
175  * we keep also separate picture with line width scale */
176 
177  //
178  //
179  // NOTE THE LOGIC OF THESE MEMBER VARS NEED TO BE REVISITED NOW THAT
180  // I HAVE REMOVED SVG OVERSAMPLING (NEEDED IN QT3 WITH POOR SVG SUPPORT)
181  // Tim Sutton 2006 XXX FIXME
182  //
183  //
184 
185 
186  /* Point symbol cache */
188 
189  /* Point symbol cache */
191 
192  /* Current line width scale used by mPointSymbolVectorImage. Equals -1.0 if not set */
193  double mWidthScale;
194 
195  /* Point symbol cache but with line width scale mWidthScale */
198 
199  /* The alpha channel of the symbol */
200  double mOpacity;
201 
202  /* Create point symbol mPointSymbolImage/mPointSymbolImage cache */
203  void cache( QColor selectionColor );
204 
205  /* Create point symbol mPointSymbolImage2 cache */
206  void cache2( double widthScale, QColor selectionColor, double opacity );
207 
208  /* mPointSymbolImage/mPointSymbolImage cache updated */
210 
211  /* mPointSymbolImage2 cache updated */
213 
214  /* Selection color used in cache */
217 
222 
223  private:
224  int readFieldName( QDomNode &synode, QString name, const QgsVectorLayer &vl );
225  void appendField( QDomElement &symbol, QDomDocument &document, const QgsVectorLayer &vl, QString name, int idx ) const;
226  void appendText( QDomElement &symbol, QDomDocument &document, QString name, QString value ) const;
227 
228 };
229 
230 inline void QgsSymbol::setBrush( QBrush b )
231 {
232  mBrush = b;
233 }
234 
235 inline const QBrush& QgsSymbol::brush() const
236 {
237  return mBrush;
238 }
239 
240 inline void QgsSymbol::setPen( QPen p )
241 {
242  mPen = p;
243 }
244 
245 inline const QPen& QgsSymbol::pen() const
246 {
247  return mPen;
248 }
249 
250 inline void QgsSymbol::setLowerValue( QString value )
251 {
252  mLowerValue = value;
253 }
254 
255 inline QString QgsSymbol::lowerValue() const
256 {
257  return mLowerValue;
258 }
259 
260 inline void QgsSymbol::setUpperValue( QString value )
261 {
262  mUpperValue = value;
263 }
264 
265 inline QString QgsSymbol::upperValue() const
266 {
267  return mUpperValue;
268 }
269 
270 inline void QgsSymbol::setLabel( QString label )
271 {
272  mLabel = label;
273 }
274 
275 inline QString QgsSymbol::label() const
276 {
277  return mLabel;
278 }
279 
280 #endif // QGSSYMBOL_H
281 
282