QGIS API Documentation  2.5.0-Master
 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 <QPainter>
26 #include "qgssymbolv2.h"
27 #include "qgis.h"
28 #include "qgsmapunitscale.h"
29 
30 class QgsExpression;
31 class QgsSymbolLayerV2;
33 
34 typedef QMap<QString, QString> QgsStringMap;
35 typedef QMap<QString, QgsSymbolV2* > QgsSymbolV2Map;
36 
37 class QDomDocument;
38 class QDomElement;
39 class QIcon;
40 class QPixmap;
41 class QPointF;
42 class QSize;
43 
44 class CORE_EXPORT QgsSymbolLayerV2Utils
45 {
46  public:
47 
48  static QString encodeColor( QColor color );
49  static QColor decodeColor( QString str );
50 
51  static QString encodeSldAlpha( int alpha );
52  static int decodeSldAlpha( QString str );
53 
54  static QString encodeSldFontStyle( QFont::Style style );
55  static QFont::Style decodeSldFontStyle( QString str );
56 
57  static QString encodeSldFontWeight( int weight );
58  static int decodeSldFontWeight( QString str );
59 
60  static QString encodePenStyle( Qt::PenStyle style );
61  static Qt::PenStyle decodePenStyle( QString str );
62 
63  static QString encodePenJoinStyle( Qt::PenJoinStyle style );
64  static Qt::PenJoinStyle decodePenJoinStyle( QString str );
65 
66  static QString encodePenCapStyle( Qt::PenCapStyle style );
67  static Qt::PenCapStyle decodePenCapStyle( QString str );
68 
69  static QString encodeSldLineJoinStyle( Qt::PenJoinStyle style );
70  static Qt::PenJoinStyle decodeSldLineJoinStyle( QString str );
71 
72  static QString encodeSldLineCapStyle( Qt::PenCapStyle style );
73  static Qt::PenCapStyle decodeSldLineCapStyle( QString str );
74 
75  static QString encodeBrushStyle( Qt::BrushStyle style );
76  static Qt::BrushStyle decodeBrushStyle( QString str );
77 
78  static QString encodeSldBrushStyle( Qt::BrushStyle style );
79  static Qt::BrushStyle decodeSldBrushStyle( QString str );
80 
81  static QString encodePoint( QPointF point );
82  static QPointF decodePoint( QString str );
83 
84  static QString encodeMapUnitScale( const QgsMapUnitScale& mapUnitScale );
85  static QgsMapUnitScale decodeMapUnitScale( const QString& str );
86 
87  static QString encodeRealVector( const QVector<qreal>& v );
88  static QVector<qreal> decodeRealVector( const QString& s );
89 
90  static QString encodeSldRealVector( const QVector<qreal>& v );
91  static QVector<qreal> decodeSldRealVector( const QString& s );
92 
93  static QString encodeOutputUnit( QgsSymbolV2::OutputUnit unit );
94  static QgsSymbolV2::OutputUnit decodeOutputUnit( QString str );
95 
96  static QString encodeSldUom( QgsSymbolV2::OutputUnit unit, double *scaleFactor );
97  static QgsSymbolV2::OutputUnit decodeSldUom( QString str, double *scaleFactor );
98 
99  static QString encodeScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
100  static QgsSymbolV2::ScaleMethod decodeScaleMethod( QString str );
101 
102  static QPainter::CompositionMode decodeBlendMode( const QString& s );
103 
104  static QIcon symbolPreviewIcon( QgsSymbolV2* symbol, QSize size );
105  static QIcon symbolLayerPreviewIcon( QgsSymbolLayerV2* layer, QgsSymbolV2::OutputUnit u, QSize size, const QgsMapUnitScale& scale = QgsMapUnitScale() );
106  static QIcon colorRampPreviewIcon( QgsVectorColorRampV2* ramp, QSize size );
107 
108  static void drawStippledBackround( QPainter* painter, QRect rect );
109 
110  static QPixmap symbolPreviewPixmap( QgsSymbolV2* symbol, QSize size );
111  static QPixmap colorRampPreviewPixmap( QgsVectorColorRampV2* ramp, QSize size );
112 
114  static double estimateMaxSymbolBleed( QgsSymbolV2* symbol );
115 
116  static QgsSymbolV2* loadSymbol( QDomElement& element );
117  static QgsSymbolLayerV2* loadSymbolLayer( QDomElement& element );
118  static QDomElement saveSymbol( QString symbolName, QgsSymbolV2* symbol, QDomDocument& doc );
119 
120  static bool createSymbolLayerV2ListFromSld( QDomElement& element, QGis::GeometryType geomType, QgsSymbolLayerV2List &layers );
121 
122  static QgsSymbolLayerV2* createFillLayerFromSld( QDomElement &element );
123  static QgsSymbolLayerV2* createLineLayerFromSld( QDomElement &element );
124  static QgsSymbolLayerV2* createMarkerLayerFromSld( QDomElement &element );
125 
126  static bool convertPolygonSymbolizerToPointMarker( QDomElement &element, QgsSymbolLayerV2List &layerList );
127  static bool hasExternalGraphic( QDomElement &element );
128  static bool hasWellKnownMark( QDomElement &element );
129 
130  static bool needFontMarker( QDomElement &element );
131  static bool needSvgMarker( QDomElement &element );
132  static bool needEllipseMarker( QDomElement &element );
133  static bool needMarkerLine( QDomElement &element );
134  static bool needLinePatternFill( QDomElement &element );
135  static bool needPointPatternFill( QDomElement &element );
136  static bool needSvgFill( QDomElement &element );
137 
138  static void fillToSld( QDomDocument &doc, QDomElement &element,
139  Qt::BrushStyle brushStyle, QColor color = QColor() );
140  static bool fillFromSld( QDomElement &element,
141  Qt::BrushStyle &brushStyle, QColor &color );
142 
144  static void lineToSld( QDomDocument &doc, QDomElement &element,
145  Qt::PenStyle penStyle, QColor color, double width = -1,
146  const Qt::PenJoinStyle *penJoinStyle = 0, const Qt::PenCapStyle *penCapStyle = 0,
147  const QVector<qreal> *customDashPattern = 0, double dashOffset = 0.0 );
148  static bool lineFromSld( QDomElement &element,
149  Qt::PenStyle &penStyle, QColor &color, double &width,
150  Qt::PenJoinStyle *penJoinStyle = 0, Qt::PenCapStyle *penCapStyle = 0,
151  QVector<qreal> *customDashPattern = 0, double *dashOffset = 0 );
152 
153  static void externalGraphicToSld( QDomDocument &doc, QDomElement &element,
154  QString path, QString mime,
155  QColor color, double size = -1 );
156  static bool externalGraphicFromSld( QDomElement &element,
157  QString &path, QString &mime,
158  QColor &color, double &size );
159 
161  Q_DECL_DEPRECATED static void wellKnownMarkerToSld( QDomDocument &doc, QDomElement &element,
162  QString name, QColor color, QColor borderColor = QColor(),
163  double borderWidth = -1, double size = -1 );
164  static void wellKnownMarkerToSld( QDomDocument &doc, QDomElement &element,
165  QString name, QColor color, QColor borderColor, Qt::PenStyle borderStyle,
166  double borderWidth = -1, double size = -1 );
168  Q_DECL_DEPRECATED static bool wellKnownMarkerFromSld( QDomElement &element,
169  QString &name, QColor &color, QColor &borderColor,
170  double &borderWidth, double &size );
171  static bool wellKnownMarkerFromSld( QDomElement &element,
172  QString &name, QColor &color, QColor &borderColor, Qt::PenStyle &borderStyle,
173  double &borderWidth, double &size );
174 
175  static void externalMarkerToSld( QDomDocument &doc, QDomElement &element,
176  QString path, QString format, int *markIndex = 0,
177  QColor color = QColor(), double size = -1 );
178  static bool externalMarkerFromSld( QDomElement &element,
179  QString &path, QString &format, int &markIndex,
180  QColor &color, double &size );
181 
182 
183  static void labelTextToSld( QDomDocument &doc, QDomElement &element, QString label,
184  QFont font, QColor color = QColor(), double size = -1 );
185 
187  static QString ogrFeatureStylePen( double width, double mmScaleFactor, double mapUnitsScaleFactor, const QColor& c,
188  Qt::PenJoinStyle joinStyle = Qt::MiterJoin,
189  Qt::PenCapStyle capStyle = Qt::FlatCap,
190  double offset = 0.0,
191  const QVector<qreal>* dashPattern = 0 );
194  static QString ogrFeatureStyleBrush( const QColor& fillColr );
195 
196  static void createRotationElement( QDomDocument &doc, QDomElement &element, QString rotationFunc );
197  static bool rotationFromSldElement( QDomElement &element, QString &rotationFunc );
198 
199  static void createOpacityElement( QDomDocument &doc, QDomElement &element, QString alphaFunc );
200  static bool opacityFromSldElement( QDomElement &element, QString &alphaFunc );
201 
202  static void createDisplacementElement( QDomDocument &doc, QDomElement &element, QPointF offset );
203  static bool displacementFromSldElement( QDomElement &element, QPointF &offset );
204 
205  static void createOnlineResourceElement( QDomDocument &doc, QDomElement &element, QString path, QString format );
206  static bool onlineResourceFromSldElement( QDomElement &element, QString &path, QString &format );
207 
208  static void createGeometryElement( QDomDocument &doc, QDomElement &element, QString geomFunc );
209  static bool geometryFromSldElement( QDomElement &element, QString &geomFunc );
210 
211  static bool createFunctionElement( QDomDocument &doc, QDomElement &element, QString function );
212  static bool functionFromSldElement( QDomElement &element, QString &function );
213 
214  static QDomElement createSvgParameterElement( QDomDocument &doc, QString name, QString value );
215  static QgsStringMap getSvgParameterList( QDomElement &element );
216 
217  static QDomElement createVendorOptionElement( QDomDocument &doc, QString name, QString value );
218  static QgsStringMap getVendorOptionList( QDomElement &element );
219 
220  static QgsStringMap parseProperties( QDomElement& element );
221  static void saveProperties( QgsStringMap props, QDomDocument& doc, QDomElement& element );
222 
223  static QgsSymbolV2Map loadSymbols( QDomElement& element );
224  static QDomElement saveSymbols( QgsSymbolV2Map& symbols, QString tagName, QDomDocument& doc );
225 
226  static void clearSymbolMap( QgsSymbolV2Map& symbols );
227 
228  static QgsVectorColorRampV2* loadColorRamp( QDomElement& element );
229  static QDomElement saveColorRamp( QString name, QgsVectorColorRampV2* ramp, QDomDocument& doc );
230 
238  static QColor parseColor( QString colorStr );
239 
248  static QColor parseColorWithAlpha( const QString colorStr, bool &containsAlpha );
249 
251  static double lineWidthScaleFactor( const QgsRenderContext& c, QgsSymbolV2::OutputUnit u, const QgsMapUnitScale& scale = QgsMapUnitScale() );
253  static double pixelSizeScaleFactor( const QgsRenderContext& c, QgsSymbolV2::OutputUnit u, const QgsMapUnitScale& scale = QgsMapUnitScale() );
255  static QgsRenderContext createRenderContext( QPainter* p );
256 
258  static void multiplyImageOpacity( QImage* image, qreal alpha );
259 
263  static void blurImageInPlace( QImage& image, const QRect& rect, int radius, bool alphaOnly );
264 
268  static void premultiplyColor( QColor& rgb, int alpha );
269 
271  static void sortVariantList( QList<QVariant>& list, Qt::SortOrder order );
273  static QPointF pointOnLineWithDistance( const QPointF& startPoint, const QPointF& directionPoint, double distance );
274 
276  static QStringList listSvgFiles();
277 
279  static QStringList listSvgFilesAt( QString directory );
280 
285  static QString symbolNameToPath( QString name );
286 
288  static QString symbolPathToName( QString path );
289 
291  static QPointF polygonCentroid( const QPolygonF& points );
292 
294  static QPointF polygonPointOnSurface( const QPolygonF& points );
295 
297  static bool pointInPolygon( const QPolygonF &points, const QPointF &point );
298 
305  static QgsExpression* fieldOrExpressionToExpression( const QString& fieldOrExpression );
306 
313  static QString fieldOrExpressionFromExpression( QgsExpression* expression );
314 };
315 
316 class QPolygonF;
317 
319 QList<QPolygonF> offsetLine( QPolygonF polyline, double dist );
321 QList<QPolygonF> offsetLine( QPolygonF polyline, double dist, QGis::GeometryType geometryType );
322 
323 #endif
324 
325 
QMap< QString, QgsSymbolV2 * > QgsSymbolV2Map
Definition: qgsrendererv2.h:38
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:89
QMap< QString, QgsSymbolV2 * > QgsSymbolV2Map
GeometryType
Definition: qgis.h:155
QMap< QString, QString > QgsStringMap
Definition: qgis.h:416
QMap< QString, QString > QgsStringMap
Contains information about the context of a rendering operation.
QList< QPolygonF > offsetLine(QPolygonF polyline, double dist)
QList< QgsSymbolLayerV2 * > QgsSymbolLayerV2List
Definition: qgssymbolv2.h:39
double size
Definition: qgssvgcache.cpp:77