|
QGIS API Documentation
master-6164ace
|
00001 /*************************************************************************** 00002 qgssymbollayerv2.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 #ifndef QGSSYMBOLLAYERV2_H 00016 #define QGSSYMBOLLAYERV2_H 00017 00018 // MSVC compiler doesn't have defined M_PI in math.h 00019 #ifndef M_PI 00020 #define M_PI 3.14159265358979323846 00021 #endif 00022 00023 #define DEG2RAD(x) ((x)*M_PI/180) 00024 #define DEFAULT_SCALE_METHOD QgsSymbolV2::ScaleArea 00025 00026 #include <QColor> 00027 #include <QMap> 00028 #include <QPointF> 00029 #include <QSet> 00030 #include <QDomDocument> 00031 #include <QDomElement> 00032 00033 #include "qgssymbolv2.h" 00034 00035 #include "qgssymbollayerv2utils.h" // QgsStringMap 00036 00037 class QPainter; 00038 class QSize; 00039 class QPolygonF; 00040 00041 class QgsExpression; 00042 class QgsRenderContext; 00043 00044 class CORE_EXPORT QgsSymbolLayerV2 00045 { 00046 public: 00047 00048 // not necessarily supported by all symbol layers... 00049 virtual void setColor( const QColor& color ) { mColor = color; } 00050 virtual QColor color() const { return mColor; } 00051 00052 virtual ~QgsSymbolLayerV2() { removeDataDefinedProperties(); } 00053 00054 virtual QString layerType() const = 0; 00055 00056 virtual void startRender( QgsSymbolV2RenderContext& context ) = 0; 00057 virtual void stopRender( QgsSymbolV2RenderContext& context ) = 0; 00058 00059 virtual QgsSymbolLayerV2* clone() const = 0; 00060 00061 virtual void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const 00062 { Q_UNUSED( props ); element.appendChild( doc.createComment( QString( "SymbolLayerV2 %1 not implemented yet" ).arg( layerType() ) ) ); } 00063 00064 virtual QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const { Q_UNUSED( mmScaleFactor ); Q_UNUSED( mapUnitScaleFactor ); return QString(); } 00065 00066 virtual QgsStringMap properties() const = 0; 00067 00068 virtual void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ) = 0; 00069 00070 virtual QgsSymbolV2* subSymbol() { return NULL; } 00071 // set layer's subsymbol. takes ownership of the passed symbol 00072 virtual bool setSubSymbol( QgsSymbolV2* symbol ) { delete symbol; return false; } 00073 00074 QgsSymbolV2::SymbolType type() const { return mType; } 00075 00076 void setLocked( bool locked ) { mLocked = locked; } 00077 bool isLocked() const { return mLocked; } 00078 00079 virtual void setOutputUnit( QgsSymbolV2::OutputUnit unit ) { Q_UNUSED( unit ); } //= 0; 00080 virtual QgsSymbolV2::OutputUnit outputUnit() const { return QgsSymbolV2::Mixed; } //= 0; 00081 00082 // used only with rending with symbol levels is turned on (0 = first pass, 1 = second, ...) 00083 void setRenderingPass( int renderingPass ) { mRenderingPass = renderingPass; } 00084 int renderingPass() const { return mRenderingPass; } 00085 00086 // symbol layers normally only use additional attributes to provide data defined settings 00087 virtual QSet<QString> usedAttributes() const; 00088 00089 virtual const QgsExpression* dataDefinedProperty( const QString& property ) const; 00090 virtual QString dataDefinedPropertyString( const QString& property ) const; 00091 virtual void setDataDefinedProperty( const QString& property, const QString& expressionString ); 00092 virtual void removeDataDefinedProperty( const QString& property ); 00093 virtual void removeDataDefinedProperties(); 00094 00095 protected: 00096 QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false ) 00097 : mType( type ), mLocked( locked ), mRenderingPass( 0 ) {} 00098 00099 QgsSymbolV2::SymbolType mType; 00100 bool mLocked; 00101 QColor mColor; 00102 int mRenderingPass; 00103 00104 QMap< QString, QgsExpression* > mDataDefinedProperties; 00105 00106 // Configuration of selected symbology implementation 00107 static const bool selectionIsOpaque = true; // Selection ignores symbol alpha 00108 static const bool selectFillBorder = false; // Fill symbol layer also selects border symbology 00109 static const bool selectFillStyle = false; // Fill symbol uses symbol layer style.. 00110 00111 virtual void prepareExpressions( const QgsVectorLayer* vl ); 00112 virtual QgsExpression* expression( const QString& property ); 00114 void saveDataDefinedProperties( QgsStringMap& stringMap ) const; 00116 void copyDataDefinedProperties( QgsSymbolLayerV2* destLayer ) const; 00117 }; 00118 00120 00121 class CORE_EXPORT QgsMarkerSymbolLayerV2 : public QgsSymbolLayerV2 00122 { 00123 public: 00124 virtual void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ) = 0; 00125 00126 void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ); 00127 00128 void setAngle( double angle ) { mAngle = angle; } 00129 double angle() const { return mAngle; } 00130 00131 void setSize( double size ) { mSize = size; } 00132 double size() const { return mSize; } 00133 00134 void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod ) { mScaleMethod = scaleMethod; } 00135 QgsSymbolV2::ScaleMethod scaleMethod() const { return mScaleMethod; } 00136 00137 void setOffset( QPointF offset ) { mOffset = offset; } 00138 QPointF offset() { return mOffset; } 00139 00140 virtual void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const; 00141 00142 virtual void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const 00143 { Q_UNUSED( props ); element.appendChild( doc.createComment( QString( "QgsMarkerSymbolLayerV2 %1 not implemented yet" ).arg( layerType() ) ) ); } 00144 00145 void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; } 00146 QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; } 00147 00148 void setSizeUnit( QgsSymbolV2::OutputUnit unit ) { mSizeUnit = unit; } 00149 QgsSymbolV2::OutputUnit sizeUnit() const { return mSizeUnit; } 00150 00151 virtual void setOutputUnit( QgsSymbolV2::OutputUnit unit ); 00152 virtual QgsSymbolV2::OutputUnit outputUnit() const; 00153 00154 protected: 00155 QgsMarkerSymbolLayerV2( bool locked = false ); 00156 void markerOffset( QgsSymbolV2RenderContext& context, double& offsetX, double& offsetY ); 00157 static QPointF _rotatedOffset( const QPointF& offset, double angle ); 00158 00159 double mAngle; 00160 double mSize; 00161 QgsSymbolV2::OutputUnit mSizeUnit; 00162 QPointF mOffset; 00163 QgsSymbolV2::OutputUnit mOffsetUnit; 00164 QgsSymbolV2::ScaleMethod mScaleMethod; 00165 }; 00166 00167 class CORE_EXPORT QgsLineSymbolLayerV2 : public QgsSymbolLayerV2 00168 { 00169 public: 00170 virtual void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) = 0; 00171 00173 virtual void renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ); 00174 00175 virtual void setWidth( double width ) { mWidth = width; } 00176 virtual double width() const { return mWidth; } 00177 00178 void setWidthUnit( QgsSymbolV2::OutputUnit unit ) { mWidthUnit = unit; } 00179 QgsSymbolV2::OutputUnit widthUnit() const { return mWidthUnit; } 00180 00181 void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ); 00182 00183 protected: 00184 QgsLineSymbolLayerV2( bool locked = false ); 00185 00186 double mWidth; 00187 QgsSymbolV2::OutputUnit mWidthUnit; 00188 }; 00189 00190 class CORE_EXPORT QgsFillSymbolLayerV2 : public QgsSymbolLayerV2 00191 { 00192 public: 00193 virtual void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) = 0; 00194 00195 void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ); 00196 00197 void setAngle( double angle ) { mAngle = angle; } 00198 double angle() const { return mAngle; } 00199 00200 protected: 00201 QgsFillSymbolLayerV2( bool locked = false ); 00203 void _renderPolygon( QPainter* p, const QPolygonF& points, const QList<QPolygonF>* rings ); 00204 00205 double mAngle; 00206 }; 00207 00208 class QgsSymbolLayerV2Widget; // why does SIP fail, when this isn't here 00209 00210 #endif