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