|
QGIS API Documentation
master-6227475
|
00001 /*************************************************************************** 00002 qgssymbolv2.h 00003 --------------------- 00004 begin : November 2009 00005 copyright : (C) 2009 by Martin Dobias 00006 email : wonder dot sk at gmail dot com 00007 *************************************************************************** 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 ***************************************************************************/ 00015 00016 #ifndef QGSSYMBOLV2_H 00017 #define QGSSYMBOLV2_H 00018 00019 #include "qgis.h" 00020 #include <QList> 00021 #include <QMap> 00022 00023 class QColor; 00024 class QImage; 00025 class QPainter; 00026 class QSize; 00027 class QPointF; 00028 class QPolygonF; 00029 00030 class QDomDocument; 00031 class QDomElement; 00032 //class 00033 00034 class QgsFeature; 00035 class QgsSymbolLayerV2; 00036 class QgsRenderContext; 00037 class QgsVectorLayer; 00038 00039 typedef QList<QgsSymbolLayerV2*> QgsSymbolLayerV2List; 00040 00041 class CORE_EXPORT QgsSymbolV2 00042 { 00043 public: 00044 00045 enum OutputUnit 00046 { 00047 MM = 0, 00048 MapUnit, 00049 Mixed //mixed units in symbol layers 00050 }; 00051 00052 enum SymbolType 00053 { 00054 Marker, 00055 Line, 00056 Fill 00057 }; 00058 00059 enum ScaleMethod 00060 { 00061 ScaleArea, 00062 ScaleDiameter 00063 }; 00064 00066 enum RenderHint 00067 { 00068 DataDefinedSizeScale = 1, 00069 DataDefinedRotation = 2 00070 }; 00071 00072 virtual ~QgsSymbolV2(); 00073 00075 static QgsSymbolV2* defaultSymbol( QGis::GeometryType geomType ); 00076 00077 SymbolType type() const { return mType; } 00078 00079 // symbol layers handling 00080 00081 QgsSymbolLayerV2* symbolLayer( int layer ); 00082 00083 int symbolLayerCount() { return mLayers.count(); } 00084 00086 bool insertSymbolLayer( int index, QgsSymbolLayerV2* layer ); 00087 00089 bool appendSymbolLayer( QgsSymbolLayerV2* layer ); 00090 00092 bool deleteSymbolLayer( int index ); 00093 00095 QgsSymbolLayerV2* takeSymbolLayer( int index ); 00096 00098 bool changeSymbolLayer( int index, QgsSymbolLayerV2* layer ); 00099 00100 void startRender( QgsRenderContext& context, const QgsVectorLayer* layer = 0 ); 00101 void stopRender( QgsRenderContext& context ); 00102 00103 void setColor( const QColor& color ); 00104 QColor color(); 00105 00106 void drawPreviewIcon( QPainter* painter, QSize size ); 00107 00108 QImage bigSymbolPreviewImage(); 00109 00110 QString dump(); 00111 00112 virtual QgsSymbolV2* clone() const = 0; 00113 00114 void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const; 00115 00116 QgsSymbolV2::OutputUnit outputUnit() const; 00117 void setOutputUnit( QgsSymbolV2::OutputUnit u ); 00118 00120 qreal alpha() const { return mAlpha; } 00122 void setAlpha( qreal alpha ) { mAlpha = alpha; } 00123 00125 void setRenderHints( int hints ) { mRenderHints = hints; } 00127 int renderHints() const { return mRenderHints; } 00128 00129 QSet<QString> usedAttributes() const; 00130 00131 protected: 00132 QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated 00133 00134 QgsSymbolLayerV2List cloneLayers() const; 00135 00139 bool isSymbolLayerCompatible( SymbolType t ); 00140 00141 SymbolType mType; 00142 QgsSymbolLayerV2List mLayers; 00143 00145 qreal mAlpha; 00146 00147 int mRenderHints; 00148 }; 00149 00151 00152 class CORE_EXPORT QgsSymbolV2RenderContext 00153 { 00154 public: 00155 QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u , qreal alpha = 1.0, bool selected = false, int renderHints = 0, const QgsFeature* f = 0 ); 00156 ~QgsSymbolV2RenderContext(); 00157 00158 QgsRenderContext& renderContext() { return mRenderContext; } 00159 const QgsRenderContext& renderContext() const { return mRenderContext; } 00160 //void setRenderContext( QgsRenderContext& c ) { mRenderContext = c;} 00161 00162 QgsSymbolV2::OutputUnit outputUnit() const { return mOutputUnit; } 00163 void setOutputUnit( QgsSymbolV2::OutputUnit u ) { mOutputUnit = u; } 00164 00166 qreal alpha() const { return mAlpha; } 00168 void setAlpha( qreal alpha ) { mAlpha = alpha; } 00169 00170 bool selected() const { return mSelected; } 00171 void setSelected( bool selected ) { mSelected = selected; } 00172 00174 int renderHints() const { return mRenderHints; } 00176 void setRenderHints( int hints ) { mRenderHints = hints; } 00177 00178 void setFeature( const QgsFeature* f ) { mFeature = f; } 00179 const QgsFeature* feature() const { return mFeature; } 00180 00181 void setLayer( const QgsVectorLayer* layer ) { mLayer = layer; } 00182 const QgsVectorLayer* layer() const { return mLayer; } 00183 00184 double outputLineWidth( double width ) const; 00185 double outputPixelSize( double size ) const; 00186 00187 // workaround for sip 4.7. Don't use assignment - will fail with assertion error 00188 QgsSymbolV2RenderContext& operator=( const QgsSymbolV2RenderContext& ); 00189 00190 private: 00191 QgsRenderContext& mRenderContext; 00192 QgsSymbolV2::OutputUnit mOutputUnit; 00193 qreal mAlpha; 00194 bool mSelected; 00195 int mRenderHints; 00196 const QgsFeature* mFeature; //current feature 00197 const QgsVectorLayer* mLayer; //current vectorlayer 00198 }; 00199 00200 00201 00203 00204 00205 00206 class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2 00207 { 00208 public: 00213 static QgsMarkerSymbolV2* createSimple( const QgsStringMap& properties ); 00214 00215 QgsMarkerSymbolV2( QgsSymbolLayerV2List layers = QgsSymbolLayerV2List() ); 00216 00217 void setAngle( double angle ); 00218 double angle(); 00219 00220 void setSize( double size ); 00221 double size(); 00222 00223 void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod ); 00224 ScaleMethod scaleMethod(); 00225 00226 void renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false ); 00227 00228 virtual QgsSymbolV2* clone() const; 00229 }; 00230 00231 00232 00233 class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2 00234 { 00235 public: 00240 static QgsLineSymbolV2* createSimple( const QgsStringMap& properties ); 00241 00242 QgsLineSymbolV2( QgsSymbolLayerV2List layers = QgsSymbolLayerV2List() ); 00243 00244 void setWidth( double width ); 00245 double width(); 00246 00247 void renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false ); 00248 00249 virtual QgsSymbolV2* clone() const; 00250 }; 00251 00252 00253 00254 class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2 00255 { 00256 public: 00261 static QgsFillSymbolV2* createSimple( const QgsStringMap& properties ); 00262 00263 QgsFillSymbolV2( QgsSymbolLayerV2List layers = QgsSymbolLayerV2List() ); 00264 void setAngle( double angle ); 00265 void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false ); 00266 00267 virtual QgsSymbolV2* clone() const; 00268 }; 00269 00270 #endif 00271 00272 00273 /* 00274 00275 QgsSymbolV2* ps = new QgsPointSymbol(); 00276 00277 // ---- 00278 00279 sl = QgsSymbolLayerV2Registry::instance()->createSymbolLayer("SimpleLine", { "color", "..." }) 00280 00281 // (or) 00282 00283 sl = QgsSymbolLayerV2Registry::defaultSymbolLayer(QgsSymbolV2::Line) 00284 00285 // (or) 00286 00287 QgsSymbolLayerV2* sl = new QgsSimpleLineSymbolLayer(x,y,z); 00288 QgsLineSymbol* s = new LineSymbol( [ sl ] ); 00289 00290 // ---- 00291 00292 rend = QgsSingleSymbolRenderer( new LineSymbol() ); 00293 */