|
QGIS API Documentation
master-6227475
|
00001 /*************************************************************************** 00002 qgsmarkersymbollayerv2.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 QGSMARKERSYMBOLLAYERV2_H 00017 #define QGSMARKERSYMBOLLAYERV2_H 00018 00019 #include "qgssymbollayerv2.h" 00020 #include "qgsvectorlayer.h" 00021 00022 #define DEFAULT_SIMPLEMARKER_NAME "circle" 00023 #define DEFAULT_SIMPLEMARKER_COLOR QColor(255,0,0) 00024 #define DEFAULT_SIMPLEMARKER_BORDERCOLOR QColor(0,0,0) 00025 #define DEFAULT_SIMPLEMARKER_SIZE DEFAULT_POINT_SIZE 00026 #define DEFAULT_SIMPLEMARKER_ANGLE 0 00027 00028 #include <QPen> 00029 #include <QBrush> 00030 #include <QPicture> 00031 #include <QPolygonF> 00032 #include <QFont> 00033 00034 class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2 00035 { 00036 public: 00037 QgsSimpleMarkerSymbolLayerV2( QString name = DEFAULT_SIMPLEMARKER_NAME, 00038 QColor color = DEFAULT_SIMPLEMARKER_COLOR, 00039 QColor borderColor = DEFAULT_SIMPLEMARKER_BORDERCOLOR, 00040 double size = DEFAULT_SIMPLEMARKER_SIZE, 00041 double angle = DEFAULT_SIMPLEMARKER_ANGLE, 00042 QgsSymbolV2::ScaleMethod scaleMethod = DEFAULT_SCALE_METHOD ); 00043 00044 // static stuff 00045 00046 static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() ); 00047 static QgsSymbolLayerV2* createFromSld( QDomElement &element ); 00048 00049 // implemented from base classes 00050 00051 QString layerType() const; 00052 00053 void startRender( QgsSymbolV2RenderContext& context ); 00054 00055 void stopRender( QgsSymbolV2RenderContext& context ); 00056 00057 void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ); 00058 00059 QgsStringMap properties() const; 00060 00061 QgsSymbolLayerV2* clone() const; 00062 00063 void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const; 00064 00065 QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const; 00066 00067 QString name() const { return mName; } 00068 void setName( QString name ) { mName = name; } 00069 00070 QColor borderColor() const { return mBorderColor; } 00071 void setBorderColor( QColor color ) { mBorderColor = color; } 00072 00073 double outlineWidth() const { return mOutlineWidth; } 00074 void setOutlineWidth( double w ) { mOutlineWidth = w; } 00075 00076 QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; } 00077 void setOutlineWidthUnit( QgsSymbolV2::OutputUnit u ) { mOutlineWidthUnit = u; } 00078 00079 protected: 00080 00081 void drawMarker( QPainter* p, QgsSymbolV2RenderContext& context ); 00082 00083 bool prepareShape( QString name = QString() ); 00084 bool preparePath( QString name = QString() ); 00085 00086 void prepareCache( QgsSymbolV2RenderContext& context ); 00087 00088 QColor mBorderColor; 00089 double mOutlineWidth; 00090 QgsSymbolV2::OutputUnit mOutlineWidthUnit; 00091 QPen mPen; 00092 QBrush mBrush; 00093 QPolygonF mPolygon; 00094 QPainterPath mPath; 00095 QString mName; 00096 QImage mCache; 00097 QPen mSelPen; 00098 QBrush mSelBrush; 00099 QImage mSelCache; 00100 bool mUsingCache; 00101 }; 00102 00104 00105 #define DEFAULT_SVGMARKER_NAME "/crosses/Star1.svg" 00106 #define DEFAULT_SVGMARKER_SIZE 2*DEFAULT_POINT_SIZE 00107 #define DEFAULT_SVGMARKER_ANGLE 0 00108 00109 class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2 00110 { 00111 public: 00112 QgsSvgMarkerSymbolLayerV2( QString name = DEFAULT_SVGMARKER_NAME, 00113 double size = DEFAULT_SVGMARKER_SIZE, 00114 double angle = DEFAULT_SVGMARKER_ANGLE ); 00115 00116 // static stuff 00117 00118 static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() ); 00119 static QgsSymbolLayerV2* createFromSld( QDomElement &element ); 00120 00121 // implemented from base classes 00122 00123 QString layerType() const; 00124 00125 void startRender( QgsSymbolV2RenderContext& context ); 00126 00127 void stopRender( QgsSymbolV2RenderContext& context ); 00128 00129 void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ); 00130 00131 QgsStringMap properties() const; 00132 00133 QgsSymbolLayerV2* clone() const; 00134 00135 void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const; 00136 00137 QString path() const { return mPath; } 00138 void setPath( QString path ); 00139 00140 QColor fillColor() const { return mFillColor; } 00141 void setFillColor( const QColor& c ) { mFillColor = c; } 00142 00143 QColor outlineColor() const { return mOutlineColor; } 00144 void setOutlineColor( const QColor& c ) { mOutlineColor = c; } 00145 00146 double outlineWidth() const { return mOutlineWidth; } 00147 void setOutlineWidth( double w ) { mOutlineWidth = w; } 00148 00149 void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mOutlineWidthUnit = unit; } 00150 QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; } 00151 00152 void setOutputUnit( QgsSymbolV2::OutputUnit unit ); 00153 QgsSymbolV2::OutputUnit outputUnit() const; 00154 00155 protected: 00156 QString mPath; 00157 00158 //param(fill), param(outline), param(outline-width) are going 00159 //to be replaced in memory 00160 QColor mFillColor; 00161 QColor mOutlineColor; 00162 double mOutlineWidth; 00163 QgsSymbolV2::OutputUnit mOutlineWidthUnit; 00164 double mOrigSize; 00165 }; 00166 00167 00169 00170 #define POINT2MM(x) ( (x) * 25.4 / 72 ) // point is 1/72 of inch 00171 #define MM2POINT(x) ( (x) * 72 / 25.4 ) 00172 00173 #define DEFAULT_FONTMARKER_FONT "Dingbats" 00174 #define DEFAULT_FONTMARKER_CHR QChar('A') 00175 #define DEFAULT_FONTMARKER_SIZE POINT2MM(12) 00176 #define DEFAULT_FONTMARKER_COLOR QColor(Qt::black) 00177 #define DEFAULT_FONTMARKER_ANGLE 0 00178 00179 class CORE_EXPORT QgsFontMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2 00180 { 00181 public: 00182 QgsFontMarkerSymbolLayerV2( QString fontFamily = DEFAULT_FONTMARKER_FONT, 00183 QChar chr = DEFAULT_FONTMARKER_CHR, 00184 double pointSize = DEFAULT_FONTMARKER_SIZE, 00185 QColor color = DEFAULT_FONTMARKER_COLOR, 00186 double angle = DEFAULT_FONTMARKER_ANGLE ); 00187 00188 // static stuff 00189 00190 static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() ); 00191 static QgsSymbolLayerV2* createFromSld( QDomElement &element ); 00192 00193 // implemented from base classes 00194 00195 QString layerType() const; 00196 00197 void startRender( QgsSymbolV2RenderContext& context ); 00198 00199 void stopRender( QgsSymbolV2RenderContext& context ); 00200 00201 void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ); 00202 00203 QgsStringMap properties() const; 00204 00205 QgsSymbolLayerV2* clone() const; 00206 00207 void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const; 00208 00209 // new methods 00210 00211 QString fontFamily() const { return mFontFamily; } 00212 void setFontFamily( QString family ) { mFontFamily = family; } 00213 00214 QChar character() const { return mChr; } 00215 void setCharacter( QChar ch ) { mChr = ch; } 00216 00217 protected: 00218 00219 QString mFontFamily; 00220 QChar mChr; 00221 00222 QPointF mChrOffset; 00223 QFont mFont; 00224 double mOrigSize; 00225 }; 00226 00227 00228 #endif