|
QGIS API Documentation
master-59fd5e0
|
00001 /*************************************************************************** 00002 qgsfillsymbollayerv2.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 QGSFILLSYMBOLLAYERV2_H 00017 #define QGSFILLSYMBOLLAYERV2_H 00018 00019 #include "qgssymbollayerv2.h" 00020 00021 #define DEFAULT_SIMPLEFILL_COLOR QColor(0,0,255) 00022 #define DEFAULT_SIMPLEFILL_STYLE Qt::SolidPattern 00023 #define DEFAULT_SIMPLEFILL_BORDERCOLOR QColor(0,0,0) 00024 #define DEFAULT_SIMPLEFILL_BORDERSTYLE Qt::SolidLine 00025 #define DEFAULT_SIMPLEFILL_BORDERWIDTH DEFAULT_LINE_WIDTH 00026 00027 #include <QPen> 00028 #include <QBrush> 00029 00030 class CORE_EXPORT QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2 00031 { 00032 public: 00033 QgsSimpleFillSymbolLayerV2( QColor color = DEFAULT_SIMPLEFILL_COLOR, 00034 Qt::BrushStyle style = DEFAULT_SIMPLEFILL_STYLE, 00035 QColor borderColor = DEFAULT_SIMPLEFILL_BORDERCOLOR, 00036 Qt::PenStyle borderStyle = DEFAULT_SIMPLEFILL_BORDERSTYLE, 00037 double borderWidth = DEFAULT_SIMPLEFILL_BORDERWIDTH ); 00038 00039 // static stuff 00040 00041 static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() ); 00042 static QgsSymbolLayerV2* createFromSld( QDomElement &element ); 00043 00044 // implemented from base classes 00045 00046 QString layerType() const; 00047 00048 void startRender( QgsSymbolV2RenderContext& context ); 00049 00050 void stopRender( QgsSymbolV2RenderContext& context ); 00051 00052 void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ); 00053 00054 QgsStringMap properties() const; 00055 00056 QgsSymbolLayerV2* clone() const; 00057 00058 void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const; 00059 00060 QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const; 00061 00062 Qt::BrushStyle brushStyle() const { return mBrushStyle; } 00063 void setBrushStyle( Qt::BrushStyle style ) { mBrushStyle = style; } 00064 00065 QColor borderColor() const { return mBorderColor; } 00066 void setBorderColor( QColor borderColor ) { mBorderColor = borderColor; } 00067 00068 Qt::PenStyle borderStyle() const { return mBorderStyle; } 00069 void setBorderStyle( Qt::PenStyle borderStyle ) { mBorderStyle = borderStyle; } 00070 00071 double borderWidth() const { return mBorderWidth; } 00072 void setBorderWidth( double borderWidth ) { mBorderWidth = borderWidth; } 00073 00074 void setOffset( QPointF offset ) { mOffset = offset; } 00075 QPointF offset() { return mOffset; } 00076 00077 void setBorderWidthUnit( QgsSymbolV2::OutputUnit unit ) { mBorderWidthUnit = unit; } 00078 QgsSymbolV2::OutputUnit borderWidthUnit() const { return mBorderWidthUnit; } 00079 00080 void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; } 00081 QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; } 00082 00083 void setOutputUnit( QgsSymbolV2::OutputUnit unit ); 00084 QgsSymbolV2::OutputUnit outputUnit() const; 00085 00086 protected: 00087 QBrush mBrush; 00088 QBrush mSelBrush; 00089 Qt::BrushStyle mBrushStyle; 00090 QColor mBorderColor; 00091 Qt::PenStyle mBorderStyle; 00092 double mBorderWidth; 00093 QgsSymbolV2::OutputUnit mBorderWidthUnit; 00094 QPen mPen; 00095 QPen mSelPen; 00096 00097 QPointF mOffset; 00098 QgsSymbolV2::OutputUnit mOffsetUnit; 00099 00100 private: 00101 //helper functions for data defined symbology 00102 void applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QBrush& brush, QPen& pen, QPen& selPen ); 00103 }; 00104 00106 class CORE_EXPORT QgsImageFillSymbolLayer: public QgsFillSymbolLayerV2 00107 { 00108 public: 00109 QgsImageFillSymbolLayer(); 00110 virtual ~QgsImageFillSymbolLayer(); 00111 void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ); 00112 00113 virtual QgsSymbolV2* subSymbol() { return mOutline; } 00114 virtual bool setSubSymbol( QgsSymbolV2* symbol ); 00115 00116 void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mOutlineWidthUnit = unit; } 00117 QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; } 00118 00119 protected: 00120 QBrush mBrush; 00121 00123 double mOutlineWidth; 00124 QgsSymbolV2::OutputUnit mOutlineWidthUnit; 00125 00127 QgsLineSymbolV2* mOutline; 00128 00129 virtual void applyDataDefinedSettings( const QgsSymbolV2RenderContext& context ) { Q_UNUSED( context ); } 00130 }; 00131 00134 class CORE_EXPORT QgsSVGFillSymbolLayer: public QgsImageFillSymbolLayer 00135 { 00136 public: 00137 QgsSVGFillSymbolLayer( const QString& svgFilePath = "", double width = 20, double rotation = 0.0 ); 00138 QgsSVGFillSymbolLayer( const QByteArray& svgData, double width = 20, double rotation = 0.0 ); 00139 ~QgsSVGFillSymbolLayer(); 00140 00141 static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() ); 00142 static QgsSymbolLayerV2* createFromSld( QDomElement &element ); 00143 00144 // implemented from base classes 00145 00146 QString layerType() const; 00147 00148 void startRender( QgsSymbolV2RenderContext& context ); 00149 void stopRender( QgsSymbolV2RenderContext& context ); 00150 00151 QgsStringMap properties() const; 00152 00153 QgsSymbolLayerV2* clone() const; 00154 00155 void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const; 00156 00157 //getters and setters 00158 void setSvgFilePath( const QString& svgPath ); 00159 QString svgFilePath() const { return mSvgFilePath; } 00160 void setPatternWidth( double width ) { mPatternWidth = width;} 00161 double patternWidth() const { return mPatternWidth; } 00162 00163 void setSvgFillColor( const QColor& c ) { mSvgFillColor = c; } 00164 QColor svgFillColor() const { return mSvgFillColor; } 00165 void setSvgOutlineColor( const QColor& c ) { mSvgOutlineColor = c; } 00166 QColor svgOutlineColor() const { return mSvgOutlineColor; } 00167 void setSvgOutlineWidth( double w ) { mSvgOutlineWidth = w; } 00168 double svgOutlineWidth() const { return mSvgOutlineWidth; } 00169 00170 void setPatternWidthUnit( QgsSymbolV2::OutputUnit unit ) { mPatternWidthUnit = unit; } 00171 QgsSymbolV2::OutputUnit patternWidthUnit() const { return mPatternWidthUnit; } 00172 00173 void setSvgOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mSvgOutlineWidthUnit = unit; } 00174 QgsSymbolV2::OutputUnit svgOutlineWidthUnit() const { return mSvgOutlineWidthUnit; } 00175 00176 void setOutputUnit( QgsSymbolV2::OutputUnit unit ); 00177 QgsSymbolV2::OutputUnit outputUnit() const; 00178 00179 protected: 00181 double mPatternWidth; 00182 QgsSymbolV2::OutputUnit mPatternWidthUnit; 00183 00185 QByteArray mSvgData; 00187 QString mSvgFilePath; 00189 QRectF mSvgViewBox; 00192 QImage* mSvgPattern; 00193 00194 //param(fill), param(outline), param(outline-width) are going 00195 //to be replaced in memory 00196 QColor mSvgFillColor; 00197 QColor mSvgOutlineColor; 00198 double mSvgOutlineWidth; 00199 QgsSymbolV2::OutputUnit mSvgOutlineWidthUnit; 00200 00201 void applyDataDefinedSettings( const QgsSymbolV2RenderContext& context ); 00202 00203 private: 00205 void storeViewBox(); 00206 void setDefaultSvgParams(); //fills mSvgFillColor, mSvgOutlineColor, mSvgOutlineWidth with default values for mSvgFilePath 00207 00209 void applyPattern( QBrush& brush, const QString& svgFilePath, double patternWidth, QgsSymbolV2::OutputUnit patternWidthUnit, const QColor& svgFillColor, const QColor& svgOutlineColor, 00210 double svgOutlineWidth, QgsSymbolV2::OutputUnit svgOutlineWidthUnit, const QgsSymbolV2RenderContext& context ); 00211 }; 00212 00213 class CORE_EXPORT QgsLinePatternFillSymbolLayer: public QgsImageFillSymbolLayer 00214 { 00215 public: 00216 QgsLinePatternFillSymbolLayer(); 00217 ~QgsLinePatternFillSymbolLayer(); 00218 00219 static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() ); 00220 static QgsSymbolLayerV2* createFromSld( QDomElement &element ); 00221 00222 QString layerType() const; 00223 00224 void startRender( QgsSymbolV2RenderContext& context ); 00225 00226 void stopRender( QgsSymbolV2RenderContext& context ); 00227 00228 QgsStringMap properties() const; 00229 00230 QgsSymbolLayerV2* clone() const; 00231 00232 void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const; 00233 00234 QString ogrFeatureStyleWidth( double widthScaleFactor ) const; 00235 00236 //getters and setters 00237 void setLineAngle( double a ) { mLineAngle = a; } 00238 double lineAngle() const { return mLineAngle; } 00239 void setDistance( double d ) { mDistance = d; } 00240 double distance() const { return mDistance; } 00241 void setLineWidth( double w ) { mLineWidth = w; } 00242 double lineWidth() const { return mLineWidth; } 00243 void setColor( const QColor& c ) { mColor = c; } 00244 QColor color() const { return mColor; } 00245 void setOffset( double offset ) { mOffset = offset; } 00246 double offset() const { return mOffset; } 00247 00248 void setDistanceUnit( QgsSymbolV2::OutputUnit unit ) { mDistanceUnit = unit; } 00249 QgsSymbolV2::OutputUnit distanceUnit() const { return mDistanceUnit; } 00250 00251 void setLineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mLineWidthUnit = unit; } 00252 QgsSymbolV2::OutputUnit lineWidthUnit() const { return mLineWidthUnit; } 00253 00254 void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; } 00255 QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; } 00256 00257 void setOutputUnit( QgsSymbolV2::OutputUnit unit ); 00258 QgsSymbolV2::OutputUnit outputUnit() const; 00259 00260 protected: 00262 double mDistance; 00263 QgsSymbolV2::OutputUnit mDistanceUnit; 00265 double mLineWidth; 00266 QgsSymbolV2::OutputUnit mLineWidthUnit; 00267 QColor mColor; 00269 double mLineAngle; 00271 double mOffset; 00272 QgsSymbolV2::OutputUnit mOffsetUnit; 00273 00274 void applyDataDefinedSettings( const QgsSymbolV2RenderContext& context ); 00275 00276 private: 00278 void applyPattern( const QgsSymbolV2RenderContext& context, QBrush& brush, double lineAngle, double distance, double lineWidth, const QColor& color ); 00279 }; 00280 00281 class CORE_EXPORT QgsPointPatternFillSymbolLayer: public QgsImageFillSymbolLayer 00282 { 00283 public: 00284 QgsPointPatternFillSymbolLayer(); 00285 ~QgsPointPatternFillSymbolLayer(); 00286 00287 static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() ); 00288 static QgsSymbolLayerV2* createFromSld( QDomElement &element ); 00289 00290 QString layerType() const; 00291 00292 void startRender( QgsSymbolV2RenderContext& context ); 00293 00294 void stopRender( QgsSymbolV2RenderContext& context ); 00295 00296 QgsStringMap properties() const; 00297 00298 QgsSymbolLayerV2* clone() const; 00299 00300 void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const; 00301 00302 //getters and setters 00303 double distanceX() const { return mDistanceX; } 00304 void setDistanceX( double d ) { mDistanceX = d; } 00305 00306 double distanceY() const { return mDistanceY; } 00307 void setDistanceY( double d ) { mDistanceY = d; } 00308 00309 double displacementX() const { return mDisplacementX; } 00310 void setDisplacementX( double d ) { mDisplacementX = d; } 00311 00312 double displacementY() const { return mDisplacementY; } 00313 void setDisplacementY( double d ) { mDisplacementY = d; } 00314 00315 bool setSubSymbol( QgsSymbolV2* symbol ); 00316 virtual QgsSymbolV2* subSymbol() { return mMarkerSymbol; } 00317 00318 void setDistanceXUnit( QgsSymbolV2::OutputUnit unit ) { mDistanceXUnit = unit; } 00319 QgsSymbolV2::OutputUnit distanceXUnit() const { return mDistanceXUnit; } 00320 00321 void setDistanceYUnit( QgsSymbolV2::OutputUnit unit ) { mDistanceYUnit = unit; } 00322 QgsSymbolV2::OutputUnit distanceYUnit() const { return mDistanceYUnit; } 00323 00324 void setDisplacementXUnit( QgsSymbolV2::OutputUnit unit ) { mDisplacementXUnit = unit; } 00325 QgsSymbolV2::OutputUnit displacementXUnit() const { return mDisplacementXUnit; } 00326 00327 void setDisplacementYUnit( QgsSymbolV2::OutputUnit unit ) { mDisplacementYUnit = unit; } 00328 QgsSymbolV2::OutputUnit displacementYUnit() const { return mDisplacementYUnit; } 00329 00330 void setOutputUnit( QgsSymbolV2::OutputUnit unit ); 00331 QgsSymbolV2::OutputUnit outputUnit() const; 00332 00333 protected: 00334 QgsMarkerSymbolV2* mMarkerSymbol; 00335 double mDistanceX; 00336 QgsSymbolV2::OutputUnit mDistanceXUnit; 00337 double mDistanceY; 00338 QgsSymbolV2::OutputUnit mDistanceYUnit; 00339 double mDisplacementX; 00340 QgsSymbolV2::OutputUnit mDisplacementXUnit; 00341 double mDisplacementY; 00342 QgsSymbolV2::OutputUnit mDisplacementYUnit; 00343 00344 void applyDataDefinedSettings( const QgsSymbolV2RenderContext& context ); 00345 00346 private: 00347 void applyPattern( const QgsSymbolV2RenderContext& context, QBrush& brush, double distanceX, double distanceY, 00348 double displacementX, double displacementY ); 00349 }; 00350 00351 class CORE_EXPORT QgsCentroidFillSymbolLayerV2 : public QgsFillSymbolLayerV2 00352 { 00353 public: 00354 QgsCentroidFillSymbolLayerV2(); 00355 ~QgsCentroidFillSymbolLayerV2(); 00356 00357 // static stuff 00358 00359 static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() ); 00360 static QgsSymbolLayerV2* createFromSld( QDomElement &element ); 00361 00362 // implemented from base classes 00363 00364 QString layerType() const; 00365 00366 void startRender( QgsSymbolV2RenderContext& context ); 00367 00368 void stopRender( QgsSymbolV2RenderContext& context ); 00369 00370 void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ); 00371 00372 QgsStringMap properties() const; 00373 00374 QgsSymbolLayerV2* clone() const; 00375 00376 void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const; 00377 00378 void setColor( const QColor& color ); 00379 00380 QgsSymbolV2* subSymbol(); 00381 bool setSubSymbol( QgsSymbolV2* symbol ); 00382 00383 void setOutputUnit( QgsSymbolV2::OutputUnit unit ) { Q_UNUSED( unit ); } 00384 QgsSymbolV2::OutputUnit outputUnit() const; 00385 00386 protected: 00387 QgsMarkerSymbolV2* mMarker; 00388 }; 00389 00390 #endif