QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgssymbollayerv2utils.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbollayerv2utils.h
3  ---------------------
4  begin : November 2009
5  copyright : (C) 2009 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 
17 #ifndef QGSSYMBOLLAYERV2UTILS_H
18 #define QGSSYMBOLLAYERV2UTILS_H
19 
20 #include <QMap>
21 #include <Qt>
22 #include <QtCore>
23 #include <QFont>
24 #include <QColor>
25 #include "qgssymbolv2.h"
26 #include "qgis.h"
27 
28 class QgsSymbolLayerV2;
30 
31 typedef QMap<QString, QString> QgsStringMap;
32 typedef QMap<QString, QgsSymbolV2* > QgsSymbolV2Map;
33 
34 class QDomDocument;
35 class QDomElement;
36 class QIcon;
37 class QPixmap;
38 class QPointF;
39 class QSize;
40 
41 class CORE_EXPORT QgsSymbolLayerV2Utils
42 {
43  public:
44 
45  static QString encodeColor( QColor color );
46  static QColor decodeColor( QString str );
47 
48  static QString encodeSldAlpha( int alpha );
49  static int decodeSldAlpha( QString str );
50 
51  static QString encodeSldFontStyle( QFont::Style style );
52  static QFont::Style decodeSldFontStyle( QString str );
53 
54  static QString encodeSldFontWeight( int weight );
55  static int decodeSldFontWeight( QString str );
56 
57  static QString encodePenStyle( Qt::PenStyle style );
58  static Qt::PenStyle decodePenStyle( QString str );
59 
60  static QString encodePenJoinStyle( Qt::PenJoinStyle style );
61  static Qt::PenJoinStyle decodePenJoinStyle( QString str );
62 
63  static QString encodePenCapStyle( Qt::PenCapStyle style );
64  static Qt::PenCapStyle decodePenCapStyle( QString str );
65 
66  static QString encodeSldLineJoinStyle( Qt::PenJoinStyle style );
67  static Qt::PenJoinStyle decodeSldLineJoinStyle( QString str );
68 
69  static QString encodeSldLineCapStyle( Qt::PenCapStyle style );
70  static Qt::PenCapStyle decodeSldLineCapStyle( QString str );
71 
72  static QString encodeBrushStyle( Qt::BrushStyle style );
73  static Qt::BrushStyle decodeBrushStyle( QString str );
74 
75  static QString encodeSldBrushStyle( Qt::BrushStyle style );
76  static Qt::BrushStyle decodeSldBrushStyle( QString str );
77 
78  static QString encodePoint( QPointF point );
79  static QPointF decodePoint( QString str );
80 
81  static QString encodeRealVector( const QVector<qreal>& v );
82  static QVector<qreal> decodeRealVector( const QString& s );
83 
84  static QString encodeSldRealVector( const QVector<qreal>& v );
85  static QVector<qreal> decodeSldRealVector( const QString& s );
86 
87  static QString encodeOutputUnit( QgsSymbolV2::OutputUnit unit );
88  static QgsSymbolV2::OutputUnit decodeOutputUnit( QString str );
89 
90  static QString encodeSldUom( QgsSymbolV2::OutputUnit unit, double *scaleFactor );
91  static QgsSymbolV2::OutputUnit decodeSldUom( QString str, double *scaleFactor );
92 
93  static QString encodeScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
94  static QgsSymbolV2::ScaleMethod decodeScaleMethod( QString str );
95 
96  static QIcon symbolPreviewIcon( QgsSymbolV2* symbol, QSize size );
97  static QIcon symbolLayerPreviewIcon( QgsSymbolLayerV2* layer, QgsSymbolV2::OutputUnit u, QSize size );
98  static QIcon colorRampPreviewIcon( QgsVectorColorRampV2* ramp, QSize size );
99 
100  static void drawStippledBackround( QPainter* painter, QRect rect );
101 
102  static QPixmap symbolPreviewPixmap( QgsSymbolV2* symbol, QSize size );
103  static QPixmap colorRampPreviewPixmap( QgsVectorColorRampV2* ramp, QSize size );
104 
105  static QgsSymbolV2* loadSymbol( QDomElement& element );
106  static QgsSymbolLayerV2* loadSymbolLayer( QDomElement& element );
107  static QDomElement saveSymbol( QString symbolName, QgsSymbolV2* symbol, QDomDocument& doc );
108 
109  static bool createSymbolLayerV2ListFromSld( QDomElement& element, QGis::GeometryType geomType, QgsSymbolLayerV2List &layers );
110 
111  static QgsSymbolLayerV2* createFillLayerFromSld( QDomElement &element );
112  static QgsSymbolLayerV2* createLineLayerFromSld( QDomElement &element );
113  static QgsSymbolLayerV2* createMarkerLayerFromSld( QDomElement &element );
114 
115  static bool convertPolygonSymbolizerToPointMarker( QDomElement &element, QgsSymbolLayerV2List &layerList );
116  static bool hasExternalGraphic( QDomElement &element );
117  static bool hasWellKnownMark( QDomElement &element );
118 
119  static bool needFontMarker( QDomElement &element );
120  static bool needSvgMarker( QDomElement &element );
121  static bool needEllipseMarker( QDomElement &element );
122  static bool needMarkerLine( QDomElement &element );
123  static bool needLinePatternFill( QDomElement &element );
124  static bool needPointPatternFill( QDomElement &element );
125  static bool needSvgFill( QDomElement &element );
126 
127  static void fillToSld( QDomDocument &doc, QDomElement &element,
128  Qt::BrushStyle brushStyle, QColor color = QColor() );
129  static bool fillFromSld( QDomElement &element,
130  Qt::BrushStyle &brushStyle, QColor &color );
131 
133  static void lineToSld( QDomDocument &doc, QDomElement &element,
134  Qt::PenStyle penStyle, QColor color, double width = -1,
135  const Qt::PenJoinStyle *penJoinStyle = 0, const Qt::PenCapStyle *penCapStyle = 0,
136  const QVector<qreal> *customDashPattern = 0, double dashOffset = 0.0 );
137  static bool lineFromSld( QDomElement &element,
138  Qt::PenStyle &penStyle, QColor &color, double &width,
139  Qt::PenJoinStyle *penJoinStyle = 0, Qt::PenCapStyle *penCapStyle = 0,
140  QVector<qreal> *customDashPattern = 0, double *dashOffset = 0 );
141 
142  static void externalGraphicToSld( QDomDocument &doc, QDomElement &element,
143  QString path, QString mime,
144  QColor color, double size = -1 );
145  static bool externalGraphicFromSld( QDomElement &element,
146  QString &path, QString &mime,
147  QColor &color, double &size );
148 
149  static void wellKnownMarkerToSld( QDomDocument &doc, QDomElement &element,
150  QString name, QColor color, QColor borderColor = QColor(),
151  double borderWidth = -1, double size = -1 );
152  static bool wellKnownMarkerFromSld( QDomElement &element,
153  QString &name, QColor &color, QColor &borderColor,
154  double &borderWidth, double &size );
155 
156  static void externalMarkerToSld( QDomDocument &doc, QDomElement &element,
157  QString path, QString format, int *markIndex = 0,
158  QColor color = QColor(), double size = -1 );
159  static bool externalMarkerFromSld( QDomElement &element,
160  QString &path, QString &format, int &markIndex,
161  QColor &color, double &size );
162 
163 
164  static void labelTextToSld( QDomDocument &doc, QDomElement &element, QString label,
165  QFont font, QColor color = QColor(), double size = -1 );
166 
168  static QString ogrFeatureStylePen( double width, double mmScaleFactor, double mapUnitsScaleFactor, const QColor& c,
169  Qt::PenJoinStyle joinStyle = Qt::MiterJoin,
170  Qt::PenCapStyle capStyle = Qt::FlatCap,
171  double offset = 0.0,
172  const QVector<qreal>* dashPattern = 0 );
175  static QString ogrFeatureStyleBrush( const QColor& fillColr );
176 
177  static void createRotationElement( QDomDocument &doc, QDomElement &element, QString rotationFunc );
178  static bool rotationFromSldElement( QDomElement &element, QString &rotationFunc );
179 
180  static void createOpacityElement( QDomDocument &doc, QDomElement &element, QString alphaFunc );
181  static bool opacityFromSldElement( QDomElement &element, QString &alphaFunc );
182 
183  static void createDisplacementElement( QDomDocument &doc, QDomElement &element, QPointF offset );
184  static bool displacementFromSldElement( QDomElement &element, QPointF &offset );
185 
186  static void createOnlineResourceElement( QDomDocument &doc, QDomElement &element, QString path, QString format );
187  static bool onlineResourceFromSldElement( QDomElement &element, QString &path, QString &format );
188 
189  static void createGeometryElement( QDomDocument &doc, QDomElement &element, QString geomFunc );
190  static bool geometryFromSldElement( QDomElement &element, QString &geomFunc );
191 
192  static bool createFunctionElement( QDomDocument &doc, QDomElement &element, QString function );
193  static bool functionFromSldElement( QDomElement &element, QString &function );
194 
195  static QDomElement createSvgParameterElement( QDomDocument &doc, QString name, QString value );
196  static QgsStringMap getSvgParameterList( QDomElement &element );
197 
198  static QDomElement createVendorOptionElement( QDomDocument &doc, QString name, QString value );
199  static QgsStringMap getVendorOptionList( QDomElement &element );
200 
201  static QgsStringMap parseProperties( QDomElement& element );
202  static void saveProperties( QgsStringMap props, QDomDocument& doc, QDomElement& element );
203 
204  static QgsSymbolV2Map loadSymbols( QDomElement& element );
205  static QDomElement saveSymbols( QgsSymbolV2Map& symbols, QString tagName, QDomDocument& doc );
206 
207  static void clearSymbolMap( QgsSymbolV2Map& symbols );
208 
209  static QgsVectorColorRampV2* loadColorRamp( QDomElement& element );
210  static QDomElement saveColorRamp( QString name, QgsVectorColorRampV2* ramp, QDomDocument& doc );
211 
213  static QColor parseColor( QString colorStr );
214 
216  static double lineWidthScaleFactor( const QgsRenderContext& c, QgsSymbolV2::OutputUnit u );
218  static double pixelSizeScaleFactor( const QgsRenderContext& c, QgsSymbolV2::OutputUnit u );
220  static QgsRenderContext createRenderContext( QPainter* p );
221 
223  static void multiplyImageOpacity( QImage* image, qreal alpha );
224 
228  static void blurImageInPlace( QImage& image, const QRect& rect, int radius, bool alphaOnly );
229 
231  static void sortVariantList( QList<QVariant>& list, Qt::SortOrder order );
233  static QPointF pointOnLineWithDistance( const QPointF& startPoint, const QPointF& directionPoint, double distance );
234 
236  static QStringList listSvgFiles();
237 
239  static QStringList listSvgFilesAt( QString directory );
240 
242  static QString symbolNameToPath( QString name );
243 
245  static QString symbolPathToName( QString path );
246 };
247 
248 class QPolygonF;
249 
251 QPolygonF offsetLine( QPolygonF polyline, double dist );
252 
253 
254 #endif