|
Quantum GIS API Documentation
1.7.5-Wroclaw
|
00001 00002 #ifndef QGSSYMBOLV2_H 00003 #define QGSSYMBOLV2_H 00004 00005 #include "qgis.h" 00006 #include <QList> 00007 #include <QMap> 00008 00009 class QColor; 00010 class QImage; 00011 class QPainter; 00012 class QSize; 00013 class QPointF; 00014 class QPolygonF; 00015 //class 00016 00017 class QgsSymbolLayerV2; 00018 class QgsRenderContext; 00019 00020 typedef QMap<QString, QString> QgsStringMap; 00021 typedef QList<QgsSymbolLayerV2*> QgsSymbolLayerV2List; 00022 00023 class CORE_EXPORT QgsSymbolV2 00024 { 00025 public: 00026 00027 enum OutputUnit 00028 { 00029 MM, 00030 MapUnit 00031 }; 00032 00033 enum SymbolType 00034 { 00035 Marker, 00036 Line, 00037 Fill 00038 }; 00039 00041 enum RenderHint 00042 { 00043 DataDefinedSizeScale = 1, 00044 DataDefinedRotation = 2 00045 }; 00046 00047 virtual ~QgsSymbolV2(); 00048 00050 static QgsSymbolV2* defaultSymbol( QGis::GeometryType geomType ); 00051 00052 SymbolType type() const { return mType; } 00053 00054 // symbol layers handling 00055 00056 QgsSymbolLayerV2* symbolLayer( int layer ); 00057 00058 int symbolLayerCount() { return mLayers.count(); } 00059 00061 bool insertSymbolLayer( int index, QgsSymbolLayerV2* layer ); 00062 00064 bool appendSymbolLayer( QgsSymbolLayerV2* layer ); 00065 00067 bool deleteSymbolLayer( int index ); 00068 00070 QgsSymbolLayerV2* takeSymbolLayer( int index ); 00071 00073 bool changeSymbolLayer( int index, QgsSymbolLayerV2* layer ); 00074 00075 00076 void startRender( QgsRenderContext& context ); 00077 void stopRender( QgsRenderContext& context ); 00078 00079 void setColor( const QColor& color ); 00080 QColor color(); 00081 00082 void drawPreviewIcon( QPainter* painter, QSize size ); 00083 00084 QImage bigSymbolPreviewImage(); 00085 00086 QString dump(); 00087 00088 virtual QgsSymbolV2* clone() const = 0; 00089 00090 OutputUnit outputUnit() const { return mOutputUnit; } 00091 void setOutputUnit( OutputUnit u ) { mOutputUnit = u; } 00092 00094 qreal alpha() const { return mAlpha; } 00096 void setAlpha( qreal alpha ) { mAlpha = alpha; } 00097 00099 void setRenderHints( int hints ) { mRenderHints = hints; } 00101 int renderHints() { return mRenderHints; } 00102 00103 protected: 00104 QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated 00105 00106 QgsSymbolLayerV2List cloneLayers() const; 00107 00111 bool isSymbolLayerCompatible( SymbolType t ); 00112 00113 SymbolType mType; 00114 QgsSymbolLayerV2List mLayers; 00115 00116 OutputUnit mOutputUnit; 00117 00119 qreal mAlpha; 00120 00121 int mRenderHints; 00122 }; 00123 00125 00126 class CORE_EXPORT QgsSymbolV2RenderContext 00127 { 00128 public: 00129 QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u , qreal alpha = 1.0, bool selected = false, int renderHints = 0 ); 00130 ~QgsSymbolV2RenderContext(); 00131 00132 QgsRenderContext& renderContext() { return mRenderContext; } 00133 //void setRenderContext( QgsRenderContext& c ) { mRenderContext = c;} 00134 00135 QgsSymbolV2::OutputUnit outputUnit() const { return mOutputUnit; } 00136 void setOutputUnit( QgsSymbolV2::OutputUnit u ) { mOutputUnit = u; } 00137 00139 qreal alpha() const { return mAlpha; } 00141 void setAlpha( qreal alpha ) { mAlpha = alpha; } 00142 00143 bool selected() const { return mSelected; } 00144 void setSelected( bool selected ) { mSelected = selected; } 00145 00147 int renderHints() const { return mRenderHints; } 00149 void setRenderHints( int hints ) { mRenderHints = hints; } 00150 00151 // Color used for selections 00152 static QColor selectionColor(); 00153 00154 double outputLineWidth( double width ) const; 00155 double outputPixelSize( double size ) const; 00156 00157 // workaround for sip 4.7. Don't use assignment - will fail with assertion error 00158 QgsSymbolV2RenderContext& operator=( const QgsSymbolV2RenderContext& ); 00159 00160 private: 00161 QgsRenderContext& mRenderContext; 00162 QgsSymbolV2::OutputUnit mOutputUnit; 00163 qreal mAlpha; 00164 bool mSelected; 00165 int mRenderHints; 00166 }; 00167 00168 00169 00171 00172 00173 00174 class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2 00175 { 00176 public: 00181 static QgsMarkerSymbolV2* createSimple( const QgsStringMap& properties ); 00182 00183 QgsMarkerSymbolV2( QgsSymbolLayerV2List layers = QgsSymbolLayerV2List() ); 00184 00185 void setAngle( double angle ); 00186 double angle(); 00187 00188 void setSize( double size ); 00189 double size(); 00190 00191 void renderPoint( const QPointF& point, QgsRenderContext& context, int layer = -1, bool selected = false ); 00192 00193 virtual QgsSymbolV2* clone() const; 00194 }; 00195 00196 00197 00198 class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2 00199 { 00200 public: 00205 static QgsLineSymbolV2* createSimple( const QgsStringMap& properties ); 00206 00207 QgsLineSymbolV2( QgsSymbolLayerV2List layers = QgsSymbolLayerV2List() ); 00208 00209 void setWidth( double width ); 00210 double width(); 00211 00212 void renderPolyline( const QPolygonF& points, QgsRenderContext& context, int layer = -1, bool selected = false ); 00213 00214 virtual QgsSymbolV2* clone() const; 00215 }; 00216 00217 00218 00219 class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2 00220 { 00221 public: 00226 static QgsFillSymbolV2* createSimple( const QgsStringMap& properties ); 00227 00228 QgsFillSymbolV2( QgsSymbolLayerV2List layers = QgsSymbolLayerV2List() ); 00229 void setAngle( double angle ); 00230 void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context, int layer = -1, bool selected = false ); 00231 00232 virtual QgsSymbolV2* clone() const; 00233 }; 00234 00235 #endif 00236 00237 00238 /* 00239 00240 QgsSymbolV2* ps = new QgsPointSymbol(); 00241 00242 // ---- 00243 00244 sl = QgsSymbolLayerV2Registry::instance()->createSymbolLayer("SimpleLine", { "color", "..." }) 00245 00246 // (or) 00247 00248 sl = QgsSymbolLayerV2Registry::defaultSymbolLayer(QgsSymbolV2::Line) 00249 00250 // (or) 00251 00252 QgsSymbolLayerV2* sl = new QgsSimpleLineSymbolLayer(x,y,z); 00253 QgsLineSymbol* s = new LineSymbol( [ sl ] ); 00254 00255 // ---- 00256 00257 rend = QgsSingleSymbolRenderer( new LineSymbol() ); 00258 */
1.7.6.1