Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgssymbolv2.h
Go to the documentation of this file.
1 
2 #ifndef QGSSYMBOLV2_H
3 #define QGSSYMBOLV2_H
4 
5 #include "qgis.h"
6 #include <QList>
7 #include <QMap>
8 
9 class QColor;
10 class QImage;
11 class QPainter;
12 class QSize;
13 class QPointF;
14 class QPolygonF;
15 //class
16 
17 class QgsSymbolLayerV2;
19 
20 typedef QMap<QString, QString> QgsStringMap;
21 typedef QList<QgsSymbolLayerV2*> QgsSymbolLayerV2List;
22 
23 class CORE_EXPORT QgsSymbolV2
24 {
25  public:
26 
28  {
29  MM,
30  MapUnit
31  };
32 
34  {
37  Fill
38  };
39 
42  {
43  DataDefinedSizeScale = 1,
44  DataDefinedRotation = 2
45  };
46 
47  virtual ~QgsSymbolV2();
48 
50  static QgsSymbolV2* defaultSymbol( QGis::GeometryType geomType );
51 
52  SymbolType type() const { return mType; }
53 
54  // symbol layers handling
55 
56  QgsSymbolLayerV2* symbolLayer( int layer );
57 
58  int symbolLayerCount() { return mLayers.count(); }
59 
61  bool insertSymbolLayer( int index, QgsSymbolLayerV2* layer );
62 
64  bool appendSymbolLayer( QgsSymbolLayerV2* layer );
65 
67  bool deleteSymbolLayer( int index );
68 
70  QgsSymbolLayerV2* takeSymbolLayer( int index );
71 
73  bool changeSymbolLayer( int index, QgsSymbolLayerV2* layer );
74 
75 
76  void startRender( QgsRenderContext& context );
77  void stopRender( QgsRenderContext& context );
78 
79  void setColor( const QColor& color );
80  QColor color();
81 
82  void drawPreviewIcon( QPainter* painter, QSize size );
83 
84  QImage bigSymbolPreviewImage();
85 
86  QString dump();
87 
88  virtual QgsSymbolV2* clone() const = 0;
89 
90  OutputUnit outputUnit() const { return mOutputUnit; }
91  void setOutputUnit( OutputUnit u ) { mOutputUnit = u; }
92 
94  qreal alpha() const { return mAlpha; }
96  void setAlpha( qreal alpha ) { mAlpha = alpha; }
97 
99  void setRenderHints( int hints ) { mRenderHints = hints; }
101  int renderHints() { return mRenderHints; }
102 
103  protected:
104  QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated
105 
106  QgsSymbolLayerV2List cloneLayers() const;
107 
111  bool isSymbolLayerCompatible( SymbolType t );
112 
115 
117 
119  qreal mAlpha;
120 
122 };
123 
125 
126 class CORE_EXPORT QgsSymbolV2RenderContext
127 {
128  public:
129  QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u , qreal alpha = 1.0, bool selected = false, int renderHints = 0 );
131 
132  QgsRenderContext& renderContext() { return mRenderContext; }
133  //void setRenderContext( QgsRenderContext& c ) { mRenderContext = c;}
134 
135  QgsSymbolV2::OutputUnit outputUnit() const { return mOutputUnit; }
136  void setOutputUnit( QgsSymbolV2::OutputUnit u ) { mOutputUnit = u; }
137 
139  qreal alpha() const { return mAlpha; }
141  void setAlpha( qreal alpha ) { mAlpha = alpha; }
142 
143  bool selected() const { return mSelected; }
144  void setSelected( bool selected ) { mSelected = selected; }
145 
147  int renderHints() const { return mRenderHints; }
149  void setRenderHints( int hints ) { mRenderHints = hints; }
150 
151  // Color used for selections
152  static QColor selectionColor();
153 
154  double outputLineWidth( double width ) const;
155  double outputPixelSize( double size ) const;
156 
157  // workaround for sip 4.7. Don't use assignment - will fail with assertion error
159 
160  private:
163  qreal mAlpha;
164  bool mSelected;
166 };
167 
168 
169 
171 
172 
173 
174 class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2
175 {
176  public:
181  static QgsMarkerSymbolV2* createSimple( const QgsStringMap& properties );
182 
184 
185  void setAngle( double angle );
186  double angle();
187 
188  void setSize( double size );
189  double size();
190 
191  void renderPoint( const QPointF& point, QgsRenderContext& context, int layer = -1, bool selected = false );
192 
193  virtual QgsSymbolV2* clone() const;
194 };
195 
196 
197 
198 class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2
199 {
200  public:
205  static QgsLineSymbolV2* createSimple( const QgsStringMap& properties );
206 
208 
209  void setWidth( double width );
210  double width();
211 
212  void renderPolyline( const QPolygonF& points, QgsRenderContext& context, int layer = -1, bool selected = false );
213 
214  virtual QgsSymbolV2* clone() const;
215 };
216 
217 
218 
219 class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2
220 {
221  public:
226  static QgsFillSymbolV2* createSimple( const QgsStringMap& properties );
227 
229  void setAngle( double angle );
230  void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context, int layer = -1, bool selected = false );
231 
232  virtual QgsSymbolV2* clone() const;
233 };
234 
235 #endif
236 
237 
238 /*
239 
240 QgsSymbolV2* ps = new QgsPointSymbol();
241 
242 // ----
243 
244 sl = QgsSymbolLayerV2Registry::instance()->createSymbolLayer("SimpleLine", { "color", "..." })
245 
246 // (or)
247 
248 sl = QgsSymbolLayerV2Registry::defaultSymbolLayer(QgsSymbolV2::Line)
249 
250 // (or)
251 
252 QgsSymbolLayerV2* sl = new QgsSimpleLineSymbolLayer(x,y,z);
253 QgsLineSymbol* s = new LineSymbol( [ sl ] );
254 
255 // ----
256 
257 rend = QgsSingleSymbolRenderer( new LineSymbol() );
258 */