Quantum GIS API Documentation
1.7.4
|
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 00093 qreal alpha() const { return mAlpha; } 00094 void setAlpha( qreal alpha ) { mAlpha = alpha; } 00095 00097 void setRenderHints( int hints ) { mRenderHints = hints; } 00099 int renderHints() { return mRenderHints; } 00100 00101 protected: 00102 QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated 00103 00104 QgsSymbolLayerV2List cloneLayers() const; 00105 00109 bool isSymbolLayerCompatible( SymbolType t ); 00110 00111 SymbolType mType; 00112 QgsSymbolLayerV2List mLayers; 00113 00114 OutputUnit mOutputUnit; 00115 00117 qreal mAlpha; 00118 00119 int mRenderHints; 00120 }; 00121 00123 00124 class CORE_EXPORT QgsSymbolV2RenderContext 00125 { 00126 public: 00127 QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u , qreal alpha = 1.0, bool selected = false, int renderHints = 0 ); 00128 ~QgsSymbolV2RenderContext(); 00129 00130 QgsRenderContext& renderContext() { return mRenderContext; } 00131 //void setRenderContext( QgsRenderContext& c ) { mRenderContext = c;} 00132 00133 QgsSymbolV2::OutputUnit outputUnit() const { return mOutputUnit; } 00134 void setOutputUnit( QgsSymbolV2::OutputUnit u ) { mOutputUnit = u; } 00135 00136 qreal alpha() const { return mAlpha; } 00137 void setAlpha( qreal alpha ) { mAlpha = alpha; } 00138 00139 bool selected() const { return mSelected; } 00140 void setSelected( bool selected ) { mSelected = selected; } 00141 00143 int renderHints() const { return mRenderHints; } 00145 void setRenderHints( int hints ) { mRenderHints = hints; } 00146 00147 // Color used for selections 00148 static QColor selectionColor(); 00149 00150 double outputLineWidth( double width ) const; 00151 double outputPixelSize( double size ) const; 00152 00153 // workaround for sip 4.7. Don't use assignment - will fail with assertion error 00154 QgsSymbolV2RenderContext& operator=( const QgsSymbolV2RenderContext& ); 00155 00156 private: 00157 QgsRenderContext& mRenderContext; 00158 QgsSymbolV2::OutputUnit mOutputUnit; 00159 qreal mAlpha; 00160 bool mSelected; 00161 int mRenderHints; 00162 }; 00163 00164 00165 00167 00168 00169 00170 class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2 00171 { 00172 public: 00177 static QgsMarkerSymbolV2* createSimple( const QgsStringMap& properties ); 00178 00179 QgsMarkerSymbolV2( QgsSymbolLayerV2List layers = QgsSymbolLayerV2List() ); 00180 00181 void setAngle( double angle ); 00182 double angle(); 00183 00184 void setSize( double size ); 00185 double size(); 00186 00187 void renderPoint( const QPointF& point, QgsRenderContext& context, int layer = -1, bool selected = false ); 00188 00189 virtual QgsSymbolV2* clone() const; 00190 }; 00191 00192 00193 00194 class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2 00195 { 00196 public: 00201 static QgsLineSymbolV2* createSimple( const QgsStringMap& properties ); 00202 00203 QgsLineSymbolV2( QgsSymbolLayerV2List layers = QgsSymbolLayerV2List() ); 00204 00205 void setWidth( double width ); 00206 double width(); 00207 00208 void renderPolyline( const QPolygonF& points, QgsRenderContext& context, int layer = -1, bool selected = false ); 00209 00210 virtual QgsSymbolV2* clone() const; 00211 }; 00212 00213 00214 00215 class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2 00216 { 00217 public: 00222 static QgsFillSymbolV2* createSimple( const QgsStringMap& properties ); 00223 00224 QgsFillSymbolV2( QgsSymbolLayerV2List layers = QgsSymbolLayerV2List() ); 00225 void setAngle( double angle ); 00226 void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context, int layer = -1, bool selected = false ); 00227 00228 virtual QgsSymbolV2* clone() const; 00229 }; 00230 00231 #endif 00232 00233 00234 /* 00235 00236 QgsSymbolV2* ps = new QgsPointSymbol(); 00237 00238 // ---- 00239 00240 sl = QgsSymbolLayerV2Registry::instance()->createSymbolLayer("SimpleLine", { "color", "..." }) 00241 00242 // (or) 00243 00244 sl = QgsSymbolLayerV2Registry::defaultSymbolLayer(QgsSymbolV2::Line) 00245 00246 // (or) 00247 00248 QgsSymbolLayerV2* sl = new QgsSimpleLineSymbolLayer(x,y,z); 00249 QgsLineSymbol* s = new LineSymbol( [ sl ] ); 00250 00251 // ---- 00252 00253 rend = QgsSingleSymbolRenderer( new LineSymbol() ); 00254 */