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 drawStippledBackround( QPainter* painter, QRect rect );
116 static double estimateMaxSymbolBleed(
QgsSymbolV2* symbol );
118 static QgsSymbolV2* loadSymbol( QDomElement& element );
120 static QDomElement saveSymbol( QString symbolName,
QgsSymbolV2* symbol, QDomDocument& doc );
128 static bool convertPolygonSymbolizerToPointMarker( QDomElement &element,
QgsSymbolLayerV2List &layerList );
129 static bool hasExternalGraphic( QDomElement &element );
130 static bool hasWellKnownMark( QDomElement &element );
132 static bool needFontMarker( QDomElement &element );
133 static bool needSvgMarker( QDomElement &element );
134 static bool needEllipseMarker( QDomElement &element );
135 static bool needMarkerLine( QDomElement &element );
136 static bool needLinePatternFill( QDomElement &element );
137 static bool needPointPatternFill( QDomElement &element );
138 static bool needSvgFill( QDomElement &element );
140 static void fillToSld( QDomDocument &doc, QDomElement &element,
141 Qt::BrushStyle brushStyle, QColor color = QColor() );
142 static bool fillFromSld( QDomElement &element,
143 Qt::BrushStyle &brushStyle, QColor &color );
146 static void lineToSld( QDomDocument &doc, QDomElement &element,
147 Qt::PenStyle penStyle, QColor color,
double width = -1,
148 const Qt::PenJoinStyle *penJoinStyle = 0,
const Qt::PenCapStyle *penCapStyle = 0,
149 const QVector<qreal> *customDashPattern = 0,
double dashOffset = 0.0 );
150 static bool lineFromSld( QDomElement &element,
151 Qt::PenStyle &penStyle, QColor &color,
double &width,
152 Qt::PenJoinStyle *penJoinStyle = 0, Qt::PenCapStyle *penCapStyle = 0,
153 QVector<qreal> *customDashPattern = 0,
double *dashOffset = 0 );
155 static void externalGraphicToSld( QDomDocument &doc, QDomElement &element,
156 QString path, QString mime,
157 QColor color,
double size = -1 );
158 static bool externalGraphicFromSld( QDomElement &element,
159 QString &path, QString &mime,
160 QColor &color,
double &size );
163 Q_DECL_DEPRECATED
static void wellKnownMarkerToSld( QDomDocument &doc, QDomElement &element,
164 QString name, QColor color, QColor borderColor = QColor(),
165 double borderWidth = -1,
double size = -1 );
166 static void wellKnownMarkerToSld( QDomDocument &doc, QDomElement &element,
167 QString name, QColor color, QColor borderColor, Qt::PenStyle borderStyle,
168 double borderWidth = -1,
double size = -1 );
170 Q_DECL_DEPRECATED
static bool wellKnownMarkerFromSld( QDomElement &element,
171 QString &name, QColor &color, QColor &borderColor,
172 double &borderWidth,
double &size );
173 static bool wellKnownMarkerFromSld( QDomElement &element,
174 QString &name, QColor &color, QColor &borderColor, Qt::PenStyle &borderStyle,
175 double &borderWidth,
double &size );
177 static void externalMarkerToSld( QDomDocument &doc, QDomElement &element,
178 QString path, QString format,
int *markIndex = 0,
179 QColor color = QColor(),
double size = -1 );
180 static bool externalMarkerFromSld( QDomElement &element,
181 QString &path, QString &format,
int &markIndex,
182 QColor &color,
double &size );
185 static void labelTextToSld( QDomDocument &doc, QDomElement &element, QString label,
186 QFont font, QColor color = QColor(),
double size = -1 );
189 static QString ogrFeatureStylePen(
double width,
double mmScaleFactor,
double mapUnitsScaleFactor,
const QColor& c,
190 Qt::PenJoinStyle joinStyle = Qt::MiterJoin,
191 Qt::PenCapStyle capStyle = Qt::FlatCap,
193 const QVector<qreal>* dashPattern = 0 );
196 static QString ogrFeatureStyleBrush(
const QColor& fillColr );
198 static void createRotationElement( QDomDocument &doc, QDomElement &element, QString rotationFunc );
199 static bool rotationFromSldElement( QDomElement &element, QString &rotationFunc );
201 static void createOpacityElement( QDomDocument &doc, QDomElement &element, QString alphaFunc );
202 static bool opacityFromSldElement( QDomElement &element, QString &alphaFunc );
204 static void createDisplacementElement( QDomDocument &doc, QDomElement &element, QPointF offset );
205 static bool displacementFromSldElement( QDomElement &element, QPointF &offset );
207 static void createOnlineResourceElement( QDomDocument &doc, QDomElement &element, QString path, QString format );
208 static bool onlineResourceFromSldElement( QDomElement &element, QString &path, QString &format );
210 static void createGeometryElement( QDomDocument &doc, QDomElement &element, QString geomFunc );
211 static bool geometryFromSldElement( QDomElement &element, QString &geomFunc );
213 static bool createFunctionElement( QDomDocument &doc, QDomElement &element, QString
function );
214 static bool functionFromSldElement( QDomElement &element, QString &
function );
216 static QDomElement createSvgParameterElement( QDomDocument &doc, QString name, QString value );
217 static QgsStringMap getSvgParameterList( QDomElement &element );
219 static QDomElement createVendorOptionElement( QDomDocument &doc, QString name, QString value );
220 static QgsStringMap getVendorOptionList( QDomElement &element );
222 static QgsStringMap parseProperties( QDomElement& element );
223 static void saveProperties(
QgsStringMap props, QDomDocument& doc, QDomElement& element );
226 static QDomElement saveSymbols(
QgsSymbolV2Map& symbols, QString tagName, QDomDocument& doc );
231 static QDomElement saveColorRamp( QString name,
QgsVectorColorRampV2* ramp, QDomDocument& doc );
239 static QString colorToName(
const QColor& color );
248 static QList< QColor > parseColorList(
const QString colorStr );
257 static QMimeData * colorToMimeData(
const QColor color );
268 static QColor colorFromMimeData(
const QMimeData *data,
bool& hasAlpha );
285 static QMimeData* colorListToMimeData(
const QgsNamedColorList colorList,
const bool allFormats =
true );
305 static QgsNamedColorList importColorsFromGpl( QFile &file,
bool &ok, QString& name );
315 static QColor parseColor( QString colorStr,
bool strictEval =
false );
326 static QColor parseColorWithAlpha(
const QString colorStr,
bool &containsAlpha,
bool strictEval =
false );
336 static void multiplyImageOpacity( QImage* image, qreal alpha );
339 static void blurImageInPlace( QImage& image,
const QRect& rect,
int radius,
bool alphaOnly );
344 static void premultiplyColor( QColor& rgb,
int alpha );
347 static void sortVariantList( QList<QVariant>& list, Qt::SortOrder order );
349 static QPointF pointOnLineWithDistance(
const QPointF& startPoint,
const QPointF& directionPoint,
double distance );
352 static QStringList listSvgFiles();
355 static QStringList listSvgFilesAt( QString directory );
361 static QString symbolNameToPath( QString name );
364 static QString symbolPathToName( QString path );
367 static QPointF polygonCentroid(
const QPolygonF& points );
370 static QPointF polygonPointOnSurface(
const QPolygonF& points );
373 static bool pointInPolygon(
const QPolygonF &points,
const QPointF &point );
381 static QgsExpression* fieldOrExpressionToExpression(
const QString& fieldOrExpression );
389 static QString fieldOrExpressionFromExpression(
QgsExpression* expression );
396 QList<QPolygonF>
offsetLine( QPolygonF polyline,
double dist );