17 #ifndef QGSSYMBOLLAYERV2UTILS_H
18 #define QGSSYMBOLLAYERV2UTILS_H
45 static QString encodeColor( QColor color );
46 static QColor decodeColor( QString str );
48 static QString encodeSldAlpha(
int alpha );
49 static int decodeSldAlpha( QString str );
51 static QString encodeSldFontStyle( QFont::Style style );
52 static QFont::Style decodeSldFontStyle( QString str );
54 static QString encodeSldFontWeight(
int weight );
55 static int decodeSldFontWeight( QString str );
57 static QString encodePenStyle( Qt::PenStyle style );
58 static Qt::PenStyle decodePenStyle( QString str );
60 static QString encodePenJoinStyle( Qt::PenJoinStyle style );
61 static Qt::PenJoinStyle decodePenJoinStyle( QString str );
63 static QString encodePenCapStyle( Qt::PenCapStyle style );
64 static Qt::PenCapStyle decodePenCapStyle( QString str );
66 static QString encodeSldLineJoinStyle( Qt::PenJoinStyle style );
67 static Qt::PenJoinStyle decodeSldLineJoinStyle( QString str );
69 static QString encodeSldLineCapStyle( Qt::PenCapStyle style );
70 static Qt::PenCapStyle decodeSldLineCapStyle( QString str );
72 static QString encodeBrushStyle( Qt::BrushStyle style );
73 static Qt::BrushStyle decodeBrushStyle( QString str );
75 static QString encodeSldBrushStyle( Qt::BrushStyle style );
76 static Qt::BrushStyle decodeSldBrushStyle( QString str );
78 static QString encodePoint( QPointF point );
79 static QPointF decodePoint( QString str );
81 static QString encodeRealVector(
const QVector<qreal>& v );
82 static QVector<qreal> decodeRealVector(
const QString& s );
84 static QString encodeSldRealVector(
const QVector<qreal>& v );
85 static QVector<qreal> decodeSldRealVector(
const QString& s );
100 static void drawStippledBackround( QPainter* painter, QRect rect );
102 static QPixmap symbolPreviewPixmap(
QgsSymbolV2* symbol, QSize size );
105 static QgsSymbolV2* loadSymbol( QDomElement& element );
107 static QDomElement saveSymbol( QString symbolName,
QgsSymbolV2* symbol, QDomDocument& doc );
115 static bool convertPolygonSymbolizerToPointMarker( QDomElement &element,
QgsSymbolLayerV2List &layerList );
116 static bool hasExternalGraphic( QDomElement &element );
117 static bool hasWellKnownMark( QDomElement &element );
119 static bool needFontMarker( QDomElement &element );
120 static bool needSvgMarker( QDomElement &element );
121 static bool needEllipseMarker( QDomElement &element );
122 static bool needMarkerLine( QDomElement &element );
123 static bool needLinePatternFill( QDomElement &element );
124 static bool needPointPatternFill( QDomElement &element );
125 static bool needSvgFill( QDomElement &element );
127 static void fillToSld( QDomDocument &doc, QDomElement &element,
128 Qt::BrushStyle brushStyle, QColor color = QColor() );
129 static bool fillFromSld( QDomElement &element,
130 Qt::BrushStyle &brushStyle, QColor &color );
133 static void lineToSld( QDomDocument &doc, QDomElement &element,
134 Qt::PenStyle penStyle, QColor color,
double width = -1,
135 const Qt::PenJoinStyle *penJoinStyle = 0,
const Qt::PenCapStyle *penCapStyle = 0,
136 const QVector<qreal> *customDashPattern = 0,
double dashOffset = 0.0 );
137 static bool lineFromSld( QDomElement &element,
138 Qt::PenStyle &penStyle, QColor &color,
double &width,
139 Qt::PenJoinStyle *penJoinStyle = 0, Qt::PenCapStyle *penCapStyle = 0,
140 QVector<qreal> *customDashPattern = 0,
double *dashOffset = 0 );
142 static void externalGraphicToSld( QDomDocument &doc, QDomElement &element,
143 QString path, QString mime,
144 QColor color,
double size = -1 );
145 static bool externalGraphicFromSld( QDomElement &element,
146 QString &path, QString &mime,
147 QColor &color,
double &size );
149 static void wellKnownMarkerToSld( QDomDocument &doc, QDomElement &element,
150 QString name, QColor color, QColor borderColor = QColor(),
151 double borderWidth = -1,
double size = -1 );
152 static bool wellKnownMarkerFromSld( QDomElement &element,
153 QString &name, QColor &color, QColor &borderColor,
154 double &borderWidth,
double &size );
156 static void externalMarkerToSld( QDomDocument &doc, QDomElement &element,
157 QString path, QString format,
int *markIndex = 0,
158 QColor color = QColor(),
double size = -1 );
159 static bool externalMarkerFromSld( QDomElement &element,
160 QString &path, QString &format,
int &markIndex,
161 QColor &color,
double &size );
164 static void labelTextToSld( QDomDocument &doc, QDomElement &element, QString label,
165 QFont font, QColor color = QColor(),
double size = -1 );
168 static QString ogrFeatureStylePen(
double width,
double mmScaleFactor,
double mapUnitsScaleFactor,
const QColor& c,
169 Qt::PenJoinStyle joinStyle = Qt::MiterJoin,
170 Qt::PenCapStyle capStyle = Qt::FlatCap,
172 const QVector<qreal>* dashPattern = 0 );
175 static QString ogrFeatureStyleBrush(
const QColor& fillColr );
177 static void createRotationElement( QDomDocument &doc, QDomElement &element, QString rotationFunc );
178 static bool rotationFromSldElement( QDomElement &element, QString &rotationFunc );
180 static void createOpacityElement( QDomDocument &doc, QDomElement &element, QString alphaFunc );
181 static bool opacityFromSldElement( QDomElement &element, QString &alphaFunc );
183 static void createDisplacementElement( QDomDocument &doc, QDomElement &element, QPointF offset );
184 static bool displacementFromSldElement( QDomElement &element, QPointF &offset );
186 static void createOnlineResourceElement( QDomDocument &doc, QDomElement &element, QString path, QString format );
187 static bool onlineResourceFromSldElement( QDomElement &element, QString &path, QString &format );
189 static void createGeometryElement( QDomDocument &doc, QDomElement &element, QString geomFunc );
190 static bool geometryFromSldElement( QDomElement &element, QString &geomFunc );
192 static bool createFunctionElement( QDomDocument &doc, QDomElement &element, QString
function );
193 static bool functionFromSldElement( QDomElement &element, QString &
function );
195 static QDomElement createSvgParameterElement( QDomDocument &doc, QString name, QString value );
196 static QgsStringMap getSvgParameterList( QDomElement &element );
198 static QDomElement createVendorOptionElement( QDomDocument &doc, QString name, QString value );
199 static QgsStringMap getVendorOptionList( QDomElement &element );
201 static QgsStringMap parseProperties( QDomElement& element );
202 static void saveProperties(
QgsStringMap props, QDomDocument& doc, QDomElement& element );
205 static QDomElement saveSymbols(
QgsSymbolV2Map& symbols, QString tagName, QDomDocument& doc );
210 static QDomElement saveColorRamp( QString name,
QgsVectorColorRampV2* ramp, QDomDocument& doc );
213 static QColor parseColor( QString colorStr );
223 static void multiplyImageOpacity( QImage* image, qreal alpha );
228 static void blurImageInPlace( QImage& image,
const QRect& rect,
int radius,
bool alphaOnly );
231 static void sortVariantList( QList<QVariant>& list, Qt::SortOrder order );
233 static QPointF pointOnLineWithDistance(
const QPointF& startPoint,
const QPointF& directionPoint,
double distance );
236 static QStringList listSvgFiles();
239 static QStringList listSvgFilesAt( QString directory );
242 static QString symbolNameToPath( QString name );
245 static QString symbolPathToName( QString path );
251 QPolygonF
offsetLine( QPolygonF polyline,
double dist );