17 #ifndef QGSSYMBOLLAYERV2UTILS_H
18 #define QGSSYMBOLLAYERV2UTILS_H
49 static QString encodeColor( QColor color );
50 static QColor decodeColor( QString str );
52 static QString encodeSldAlpha(
int alpha );
53 static int decodeSldAlpha( QString str );
55 static QString encodeSldFontStyle( QFont::Style style );
56 static QFont::Style decodeSldFontStyle( QString str );
58 static QString encodeSldFontWeight(
int weight );
59 static int decodeSldFontWeight( QString str );
61 static QString encodePenStyle( Qt::PenStyle style );
62 static Qt::PenStyle decodePenStyle( QString str );
64 static QString encodePenJoinStyle( Qt::PenJoinStyle style );
65 static Qt::PenJoinStyle decodePenJoinStyle( QString str );
67 static QString encodePenCapStyle( Qt::PenCapStyle style );
68 static Qt::PenCapStyle decodePenCapStyle( QString str );
70 static QString encodeSldLineJoinStyle( Qt::PenJoinStyle style );
71 static Qt::PenJoinStyle decodeSldLineJoinStyle( QString str );
73 static QString encodeSldLineCapStyle( Qt::PenCapStyle style );
74 static Qt::PenCapStyle decodeSldLineCapStyle( QString str );
76 static QString encodeBrushStyle( Qt::BrushStyle style );
77 static Qt::BrushStyle decodeBrushStyle( QString str );
79 static QString encodeSldBrushStyle( Qt::BrushStyle style );
80 static Qt::BrushStyle decodeSldBrushStyle( QString str );
82 static QString encodePoint( QPointF point );
83 static QPointF decodePoint( QString str );
85 static QString encodeMapUnitScale(
const QgsMapUnitScale& mapUnitScale );
88 static QString encodeRealVector(
const QVector<qreal>& v );
89 static QVector<qreal> decodeRealVector(
const QString& s );
91 static QString encodeSldRealVector(
const QVector<qreal>& v );
92 static QVector<qreal> decodeSldRealVector(
const QString& s );
103 static QPainter::CompositionMode decodeBlendMode(
const QString& s );
109 static void drawStippledBackground( QPainter* painter, QRect rect );
116 static double estimateMaxSymbolBleed(
QgsSymbolV2* symbol );
122 static QgsSymbolV2* loadSymbol(
const QDomElement& element );
130 template <
class SymbolType>
static SymbolType* loadSymbol(
const QDomElement& element )
133 SymbolType* symbolCastToType =
dynamic_cast<SymbolType*
>( tmpSymbol );
135 if ( symbolCastToType )
137 return symbolCastToType;
148 static QDomElement saveSymbol( QString symbolName,
QgsSymbolV2* symbol, QDomDocument& doc );
156 static bool convertPolygonSymbolizerToPointMarker( QDomElement &element,
QgsSymbolLayerV2List &layerList );
157 static bool hasExternalGraphic( QDomElement &element );
158 static bool hasWellKnownMark( QDomElement &element );
160 static bool needFontMarker( QDomElement &element );
161 static bool needSvgMarker( QDomElement &element );
162 static bool needEllipseMarker( QDomElement &element );
163 static bool needMarkerLine( QDomElement &element );
164 static bool needLinePatternFill( QDomElement &element );
165 static bool needPointPatternFill( QDomElement &element );
166 static bool needSvgFill( QDomElement &element );
168 static void fillToSld( QDomDocument &doc, QDomElement &element,
169 Qt::BrushStyle brushStyle, QColor color = QColor() );
170 static bool fillFromSld( QDomElement &element,
171 Qt::BrushStyle &brushStyle, QColor &color );
174 static void lineToSld( QDomDocument &doc, QDomElement &element,
175 Qt::PenStyle penStyle, QColor color,
double width = -1,
176 const Qt::PenJoinStyle *penJoinStyle = 0,
const Qt::PenCapStyle *penCapStyle = 0,
177 const QVector<qreal> *customDashPattern = 0,
double dashOffset = 0.0 );
178 static bool lineFromSld( QDomElement &element,
179 Qt::PenStyle &penStyle, QColor &color,
double &width,
180 Qt::PenJoinStyle *penJoinStyle = 0, Qt::PenCapStyle *penCapStyle = 0,
181 QVector<qreal> *customDashPattern = 0,
double *dashOffset = 0 );
183 static void externalGraphicToSld( QDomDocument &doc, QDomElement &element,
184 QString path, QString mime,
185 QColor color,
double size = -1 );
186 static bool externalGraphicFromSld( QDomElement &element,
187 QString &path, QString &mime,
188 QColor &color,
double &size );
191 Q_DECL_DEPRECATED
static void wellKnownMarkerToSld( QDomDocument &doc, QDomElement &element,
192 QString name, QColor color, QColor borderColor = QColor(),
193 double borderWidth = -1,
double size = -1 );
194 static void wellKnownMarkerToSld( QDomDocument &doc, QDomElement &element,
195 QString name, QColor color, QColor borderColor, Qt::PenStyle borderStyle,
196 double borderWidth = -1,
double size = -1 );
198 Q_DECL_DEPRECATED
static bool wellKnownMarkerFromSld( QDomElement &element,
199 QString &name, QColor &color, QColor &borderColor,
200 double &borderWidth,
double &size );
201 static bool wellKnownMarkerFromSld( QDomElement &element,
202 QString &name, QColor &color, QColor &borderColor, Qt::PenStyle &borderStyle,
203 double &borderWidth,
double &size );
205 static void externalMarkerToSld( QDomDocument &doc, QDomElement &element,
206 QString path, QString format,
int *markIndex = 0,
207 QColor color = QColor(),
double size = -1 );
208 static bool externalMarkerFromSld( QDomElement &element,
209 QString &path, QString &format,
int &markIndex,
210 QColor &color,
double &size );
213 static void labelTextToSld( QDomDocument &doc, QDomElement &element, QString label,
214 QFont font, QColor color = QColor(),
double size = -1 );
217 static QString ogrFeatureStylePen(
double width,
double mmScaleFactor,
double mapUnitsScaleFactor,
const QColor& c,
218 Qt::PenJoinStyle joinStyle = Qt::MiterJoin,
219 Qt::PenCapStyle capStyle = Qt::FlatCap,
221 const QVector<qreal>* dashPattern = 0 );
224 static QString ogrFeatureStyleBrush(
const QColor& fillColr );
226 static void createRotationElement( QDomDocument &doc, QDomElement &element, QString rotationFunc );
227 static bool rotationFromSldElement( QDomElement &element, QString &rotationFunc );
229 static void createOpacityElement( QDomDocument &doc, QDomElement &element, QString alphaFunc );
230 static bool opacityFromSldElement( QDomElement &element, QString &alphaFunc );
232 static void createDisplacementElement( QDomDocument &doc, QDomElement &element, QPointF offset );
233 static bool displacementFromSldElement( QDomElement &element, QPointF &offset );
235 static void createOnlineResourceElement( QDomDocument &doc, QDomElement &element, QString path, QString format );
236 static bool onlineResourceFromSldElement( QDomElement &element, QString &path, QString &format );
238 static void createGeometryElement( QDomDocument &doc, QDomElement &element, QString geomFunc );
239 static bool geometryFromSldElement( QDomElement &element, QString &geomFunc );
241 static bool createFunctionElement( QDomDocument &doc, QDomElement &element, QString
function );
242 static bool functionFromSldElement( QDomElement &element, QString &
function );
244 static QDomElement createSvgParameterElement( QDomDocument &doc, QString name, QString value );
245 static QgsStringMap getSvgParameterList( QDomElement &element );
247 static QDomElement createVendorOptionElement( QDomDocument &doc, QString name, QString value );
248 static QgsStringMap getVendorOptionList( QDomElement &element );
250 static QgsStringMap parseProperties( QDomElement& element );
251 static void saveProperties(
QgsStringMap props, QDomDocument& doc, QDomElement& element );
254 static QDomElement saveSymbols(
QgsSymbolV2Map& symbols, QString tagName, QDomDocument& doc );
259 static QDomElement saveColorRamp( QString name,
QgsVectorColorRampV2* ramp, QDomDocument& doc );
267 static QString colorToName(
const QColor& color );
276 static QList< QColor > parseColorList(
const QString colorStr );
285 static QMimeData *colorToMimeData(
const QColor &color );
296 static QColor colorFromMimeData(
const QMimeData *data,
bool& hasAlpha );
313 static QMimeData* colorListToMimeData(
const QgsNamedColorList colorList,
const bool allFormats =
true );
343 static QColor parseColor( QString colorStr,
bool strictEval =
false );
354 static QColor parseColorWithAlpha(
const QString colorStr,
bool &containsAlpha,
bool strictEval =
false );
364 static void multiplyImageOpacity( QImage* image, qreal alpha );
367 static void blurImageInPlace( QImage& image,
const QRect& rect,
int radius,
bool alphaOnly );
372 static void premultiplyColor( QColor& rgb,
int alpha );
375 static void sortVariantList( QList<QVariant>& list, Qt::SortOrder order );
377 static QPointF pointOnLineWithDistance(
const QPointF& startPoint,
const QPointF& directionPoint,
double distance );
380 static QStringList listSvgFiles();
383 static QStringList listSvgFilesAt( QString directory );
389 static QString symbolNameToPath( QString name );
392 static QString symbolPathToName( QString path );
395 static QPointF polygonCentroid(
const QPolygonF& points );
398 static QPointF polygonPointOnSurface(
const QPolygonF& points );
401 static bool pointInPolygon(
const QPolygonF &points,
const QPointF &point );
409 static QgsExpression* fieldOrExpressionToExpression(
const QString& fieldOrExpression );
417 static QString fieldOrExpressionFromExpression(
QgsExpression* expression );
424 QList<QPolygonF>
offsetLine( QPolygonF polyline,
double dist );