QGIS API Documentation  2.2.0-Valmiera
 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 QgsExpression;
29 class QgsSymbolLayerV2;
31 
32 typedef QMap<QString, QString> QgsStringMap;
33 typedef QMap<QString, QgsSymbolV2* > QgsSymbolV2Map;
34 
35 class QDomDocument;
36 class QDomElement;
37 class QIcon;
38 class QPixmap;
39 class QPointF;
40 class QSize;
41 
42 class CORE_EXPORT QgsSymbolLayerV2Utils
43 {
44  public:
45 
46  static QString encodeColor( QColor color );
47  static QColor decodeColor( QString str );
48 
49  static QString encodeSldAlpha( int alpha );
50  static int decodeSldAlpha( QString str );
51 
52  static QString encodeSldFontStyle( QFont::Style style );
53  static QFont::Style decodeSldFontStyle( QString str );
54 
55  static QString encodeSldFontWeight( int weight );
56  static int decodeSldFontWeight( QString str );
57 
58  static QString encodePenStyle( Qt::PenStyle style );
59  static Qt::PenStyle decodePenStyle( QString str );
60 
61  static QString encodePenJoinStyle( Qt::PenJoinStyle style );
62  static Qt::PenJoinStyle decodePenJoinStyle( QString str );
63 
64  static QString encodePenCapStyle( Qt::PenCapStyle style );
65  static Qt::PenCapStyle decodePenCapStyle( QString str );
66 
67  static QString encodeSldLineJoinStyle( Qt::PenJoinStyle style );
68  static Qt::PenJoinStyle decodeSldLineJoinStyle( QString str );
69 
70  static QString encodeSldLineCapStyle( Qt::PenCapStyle style );
71  static Qt::PenCapStyle decodeSldLineCapStyle( QString str );
72 
73  static QString encodeBrushStyle( Qt::BrushStyle style );
74  static Qt::BrushStyle decodeBrushStyle( QString str );
75 
76  static QString encodeSldBrushStyle( Qt::BrushStyle style );
77  static Qt::BrushStyle decodeSldBrushStyle( QString str );
78 
79  static QString encodePoint( QPointF point );
80  static QPointF decodePoint( QString str );
81 
82  static QString encodeRealVector( const QVector<qreal>& v );
83  static QVector<qreal> decodeRealVector( const QString& s );
84 
85  static QString encodeSldRealVector( const QVector<qreal>& v );
86  static QVector<qreal> decodeSldRealVector( const QString& s );
87 
88  static QString encodeOutputUnit( QgsSymbolV2::OutputUnit unit );
89  static QgsSymbolV2::OutputUnit decodeOutputUnit( QString str );
90 
91  static QString encodeSldUom( QgsSymbolV2::OutputUnit unit, double *scaleFactor );
92  static QgsSymbolV2::OutputUnit decodeSldUom( QString str, double *scaleFactor );
93 
94  static QString encodeScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
95  static QgsSymbolV2::ScaleMethod decodeScaleMethod( QString str );
96 
97  static QIcon symbolPreviewIcon( QgsSymbolV2* symbol, QSize size );
98  static QIcon symbolLayerPreviewIcon( QgsSymbolLayerV2* layer, QgsSymbolV2::OutputUnit u, QSize size );
99  static QIcon colorRampPreviewIcon( QgsVectorColorRampV2* ramp, QSize size );
100 
101  static void drawStippledBackround( QPainter* painter, QRect rect );
102 
103  static QPixmap symbolPreviewPixmap( QgsSymbolV2* symbol, QSize size );
104  static QPixmap colorRampPreviewPixmap( QgsVectorColorRampV2* ramp, QSize size );
105 
107  static double estimateMaxSymbolBleed( QgsSymbolV2* symbol );
108 
109  static QgsSymbolV2* loadSymbol( QDomElement& element );
110  static QgsSymbolLayerV2* loadSymbolLayer( QDomElement& element );
111  static QDomElement saveSymbol( QString symbolName, QgsSymbolV2* symbol, QDomDocument& doc );
112 
113  static bool createSymbolLayerV2ListFromSld( QDomElement& element, QGis::GeometryType geomType, QgsSymbolLayerV2List &layers );
114 
115  static QgsSymbolLayerV2* createFillLayerFromSld( QDomElement &element );
116  static QgsSymbolLayerV2* createLineLayerFromSld( QDomElement &element );
117  static QgsSymbolLayerV2* createMarkerLayerFromSld( QDomElement &element );
118 
119  static bool convertPolygonSymbolizerToPointMarker( QDomElement &element, QgsSymbolLayerV2List &layerList );
120  static bool hasExternalGraphic( QDomElement &element );
121  static bool hasWellKnownMark( QDomElement &element );
122 
123  static bool needFontMarker( QDomElement &element );
124  static bool needSvgMarker( QDomElement &element );
125  static bool needEllipseMarker( QDomElement &element );
126  static bool needMarkerLine( QDomElement &element );
127  static bool needLinePatternFill( QDomElement &element );
128  static bool needPointPatternFill( QDomElement &element );
129  static bool needSvgFill( QDomElement &element );
130 
131  static void fillToSld( QDomDocument &doc, QDomElement &element,
132  Qt::BrushStyle brushStyle, QColor color = QColor() );
133  static bool fillFromSld( QDomElement &element,
134  Qt::BrushStyle &brushStyle, QColor &color );
135 
137  static void lineToSld( QDomDocument &doc, QDomElement &element,
138  Qt::PenStyle penStyle, QColor color, double width = -1,
139  const Qt::PenJoinStyle *penJoinStyle = 0, const Qt::PenCapStyle *penCapStyle = 0,
140  const QVector<qreal> *customDashPattern = 0, double dashOffset = 0.0 );
141  static bool lineFromSld( QDomElement &element,
142  Qt::PenStyle &penStyle, QColor &color, double &width,
143  Qt::PenJoinStyle *penJoinStyle = 0, Qt::PenCapStyle *penCapStyle = 0,
144  QVector<qreal> *customDashPattern = 0, double *dashOffset = 0 );
145 
146  static void externalGraphicToSld( QDomDocument &doc, QDomElement &element,
147  QString path, QString mime,
148  QColor color, double size = -1 );
149  static bool externalGraphicFromSld( QDomElement &element,
150  QString &path, QString &mime,
151  QColor &color, double &size );
152 
154  Q_DECL_DEPRECATED static void wellKnownMarkerToSld( QDomDocument &doc, QDomElement &element,
155  QString name, QColor color, QColor borderColor = QColor(),
156  double borderWidth = -1, double size = -1 );
157  static void wellKnownMarkerToSld( QDomDocument &doc, QDomElement &element,
158  QString name, QColor color, QColor borderColor, Qt::PenStyle borderStyle,
159  double borderWidth = -1, double size = -1 );
161  Q_DECL_DEPRECATED static bool wellKnownMarkerFromSld( QDomElement &element,
162  QString &name, QColor &color, QColor &borderColor,
163  double &borderWidth, double &size );
164  static bool wellKnownMarkerFromSld( QDomElement &element,
165  QString &name, QColor &color, QColor &borderColor, Qt::PenStyle &borderStyle,
166  double &borderWidth, double &size );
167 
168  static void externalMarkerToSld( QDomDocument &doc, QDomElement &element,
169  QString path, QString format, int *markIndex = 0,
170  QColor color = QColor(), double size = -1 );
171  static bool externalMarkerFromSld( QDomElement &element,
172  QString &path, QString &format, int &markIndex,
173  QColor &color, double &size );
174 
175 
176  static void labelTextToSld( QDomDocument &doc, QDomElement &element, QString label,
177  QFont font, QColor color = QColor(), double size = -1 );
178 
180  static QString ogrFeatureStylePen( double width, double mmScaleFactor, double mapUnitsScaleFactor, const QColor& c,
181  Qt::PenJoinStyle joinStyle = Qt::MiterJoin,
182  Qt::PenCapStyle capStyle = Qt::FlatCap,
183  double offset = 0.0,
184  const QVector<qreal>* dashPattern = 0 );
187  static QString ogrFeatureStyleBrush( const QColor& fillColr );
188 
189  static void createRotationElement( QDomDocument &doc, QDomElement &element, QString rotationFunc );
190  static bool rotationFromSldElement( QDomElement &element, QString &rotationFunc );
191 
192  static void createOpacityElement( QDomDocument &doc, QDomElement &element, QString alphaFunc );
193  static bool opacityFromSldElement( QDomElement &element, QString &alphaFunc );
194 
195  static void createDisplacementElement( QDomDocument &doc, QDomElement &element, QPointF offset );
196  static bool displacementFromSldElement( QDomElement &element, QPointF &offset );
197 
198  static void createOnlineResourceElement( QDomDocument &doc, QDomElement &element, QString path, QString format );
199  static bool onlineResourceFromSldElement( QDomElement &element, QString &path, QString &format );
200 
201  static void createGeometryElement( QDomDocument &doc, QDomElement &element, QString geomFunc );
202  static bool geometryFromSldElement( QDomElement &element, QString &geomFunc );
203 
204  static bool createFunctionElement( QDomDocument &doc, QDomElement &element, QString function );
205  static bool functionFromSldElement( QDomElement &element, QString &function );
206 
207  static QDomElement createSvgParameterElement( QDomDocument &doc, QString name, QString value );
208  static QgsStringMap getSvgParameterList( QDomElement &element );
209 
210  static QDomElement createVendorOptionElement( QDomDocument &doc, QString name, QString value );
211  static QgsStringMap getVendorOptionList( QDomElement &element );
212 
213  static QgsStringMap parseProperties( QDomElement& element );
214  static void saveProperties( QgsStringMap props, QDomDocument& doc, QDomElement& element );
215 
216  static QgsSymbolV2Map loadSymbols( QDomElement& element );
217  static QDomElement saveSymbols( QgsSymbolV2Map& symbols, QString tagName, QDomDocument& doc );
218 
219  static void clearSymbolMap( QgsSymbolV2Map& symbols );
220 
221  static QgsVectorColorRampV2* loadColorRamp( QDomElement& element );
222  static QDomElement saveColorRamp( QString name, QgsVectorColorRampV2* ramp, QDomDocument& doc );
223 
225  static QColor parseColor( QString colorStr );
226 
228  static double lineWidthScaleFactor( const QgsRenderContext& c, QgsSymbolV2::OutputUnit u );
230  static double pixelSizeScaleFactor( const QgsRenderContext& c, QgsSymbolV2::OutputUnit u );
232  static QgsRenderContext createRenderContext( QPainter* p );
233 
235  static void multiplyImageOpacity( QImage* image, qreal alpha );
236 
240  static void blurImageInPlace( QImage& image, const QRect& rect, int radius, bool alphaOnly );
241 
243  static void sortVariantList( QList<QVariant>& list, Qt::SortOrder order );
245  static QPointF pointOnLineWithDistance( const QPointF& startPoint, const QPointF& directionPoint, double distance );
246 
248  static QStringList listSvgFiles();
249 
251  static QStringList listSvgFilesAt( QString directory );
252 
257  static QString symbolNameToPath( QString name );
258 
260  static QString symbolPathToName( QString path );
261 
263  static QPointF polygonCentroid( const QPolygonF& points );
264 
271  static QgsExpression* fieldOrExpressionToExpression( const QString& fieldOrExpression );
272 
279  static QString fieldOrExpressionFromExpression( QgsExpression* expression );
280 };
281 
282 class QPolygonF;
283 
285 QPolygonF offsetLine( QPolygonF polyline, double dist );
286 
287 
288 #endif