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