17 #ifndef QGSSYMBOLLAYERV2UTILS_H
18 #define QGSSYMBOLLAYERV2UTILS_H
46 static QString encodeColor( QColor color );
47 static QColor decodeColor( QString str );
49 static QString encodeSldAlpha(
int alpha );
50 static int decodeSldAlpha( QString str );
52 static QString encodeSldFontStyle( QFont::Style style );
53 static QFont::Style decodeSldFontStyle( QString str );
55 static QString encodeSldFontWeight(
int weight );
56 static int decodeSldFontWeight( QString str );
58 static QString encodePenStyle( Qt::PenStyle style );
59 static Qt::PenStyle decodePenStyle( QString str );
61 static QString encodePenJoinStyle( Qt::PenJoinStyle style );
62 static Qt::PenJoinStyle decodePenJoinStyle( QString str );
64 static QString encodePenCapStyle( Qt::PenCapStyle style );
65 static Qt::PenCapStyle decodePenCapStyle( QString str );
67 static QString encodeSldLineJoinStyle( Qt::PenJoinStyle style );
68 static Qt::PenJoinStyle decodeSldLineJoinStyle( QString str );
70 static QString encodeSldLineCapStyle( Qt::PenCapStyle style );
71 static Qt::PenCapStyle decodeSldLineCapStyle( QString str );
73 static QString encodeBrushStyle( Qt::BrushStyle style );
74 static Qt::BrushStyle decodeBrushStyle( QString str );
76 static QString encodeSldBrushStyle( Qt::BrushStyle style );
77 static Qt::BrushStyle decodeSldBrushStyle( QString str );
79 static QString encodePoint( QPointF point );
80 static QPointF decodePoint( QString str );
82 static QString encodeRealVector(
const QVector<qreal>& v );
83 static QVector<qreal> decodeRealVector(
const QString& s );
85 static QString encodeSldRealVector(
const QVector<qreal>& v );
86 static QVector<qreal> decodeSldRealVector(
const QString& s );
101 static void drawStippledBackround( QPainter* painter, QRect rect );
103 static QPixmap symbolPreviewPixmap(
QgsSymbolV2* symbol, QSize size );
107 static double estimateMaxSymbolBleed(
QgsSymbolV2* symbol );
109 static QgsSymbolV2* loadSymbol( QDomElement& element );
111 static QDomElement saveSymbol( QString symbolName,
QgsSymbolV2* symbol, QDomDocument& doc );
119 static bool convertPolygonSymbolizerToPointMarker( QDomElement &element,
QgsSymbolLayerV2List &layerList );
120 static bool hasExternalGraphic( QDomElement &element );
121 static bool hasWellKnownMark( QDomElement &element );
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 );
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 );
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 );
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 );
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 );
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 );
176 static void labelTextToSld( QDomDocument &doc, QDomElement &element, QString label,
177 QFont font, QColor color = QColor(),
double size = -1 );
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,
184 const QVector<qreal>* dashPattern = 0 );
187 static QString ogrFeatureStyleBrush(
const QColor& fillColr );
189 static void createRotationElement( QDomDocument &doc, QDomElement &element, QString rotationFunc );
190 static bool rotationFromSldElement( QDomElement &element, QString &rotationFunc );
192 static void createOpacityElement( QDomDocument &doc, QDomElement &element, QString alphaFunc );
193 static bool opacityFromSldElement( QDomElement &element, QString &alphaFunc );
195 static void createDisplacementElement( QDomDocument &doc, QDomElement &element, QPointF offset );
196 static bool displacementFromSldElement( QDomElement &element, QPointF &offset );
198 static void createOnlineResourceElement( QDomDocument &doc, QDomElement &element, QString path, QString format );
199 static bool onlineResourceFromSldElement( QDomElement &element, QString &path, QString &format );
201 static void createGeometryElement( QDomDocument &doc, QDomElement &element, QString geomFunc );
202 static bool geometryFromSldElement( QDomElement &element, QString &geomFunc );
204 static bool createFunctionElement( QDomDocument &doc, QDomElement &element, QString
function );
205 static bool functionFromSldElement( QDomElement &element, QString &
function );
207 static QDomElement createSvgParameterElement( QDomDocument &doc, QString name, QString value );
208 static QgsStringMap getSvgParameterList( QDomElement &element );
210 static QDomElement createVendorOptionElement( QDomDocument &doc, QString name, QString value );
211 static QgsStringMap getVendorOptionList( QDomElement &element );
213 static QgsStringMap parseProperties( QDomElement& element );
214 static void saveProperties(
QgsStringMap props, QDomDocument& doc, QDomElement& element );
217 static QDomElement saveSymbols(
QgsSymbolV2Map& symbols, QString tagName, QDomDocument& doc );
222 static QDomElement saveColorRamp( QString name,
QgsVectorColorRampV2* ramp, QDomDocument& doc );
225 static QColor parseColor( QString colorStr );
235 static void multiplyImageOpacity( QImage* image, qreal alpha );
240 static void blurImageInPlace( QImage& image,
const QRect& rect,
int radius,
bool alphaOnly );
243 static void sortVariantList( QList<QVariant>& list, Qt::SortOrder order );
245 static QPointF pointOnLineWithDistance(
const QPointF& startPoint,
const QPointF& directionPoint,
double distance );
248 static QStringList listSvgFiles();
251 static QStringList listSvgFilesAt( QString directory );
257 static QString symbolNameToPath( QString name );
260 static QString symbolPathToName( QString path );
263 static QPointF polygonCentroid(
const QPolygonF& points );
271 static QgsExpression* fieldOrExpressionToExpression(
const QString& fieldOrExpression );
279 static QString fieldOrExpressionFromExpression(
QgsExpression* expression );
285 QPolygonF
offsetLine( QPolygonF polyline,
double dist );