17 #ifndef QGSSYMBOLLAYERUTILS_H
18 #define QGSSYMBOLLAYERUTILS_H
20 #include "qgis_core.h"
66 static QString encodeColor(
const QColor &color );
67 static QColor decodeColor(
const QString &str );
69 static QString encodeSldAlpha(
int alpha );
70 static int decodeSldAlpha(
const QString &str );
72 static QString encodeSldFontStyle( QFont::Style style );
73 static QFont::Style decodeSldFontStyle(
const QString &str );
75 static QString encodeSldFontWeight(
int weight );
76 static int decodeSldFontWeight(
const QString &str );
78 static QString encodePenStyle( Qt::PenStyle style );
79 static Qt::PenStyle decodePenStyle(
const QString &str );
81 static QString encodePenJoinStyle( Qt::PenJoinStyle style );
82 static Qt::PenJoinStyle decodePenJoinStyle(
const QString &str );
84 static QString encodePenCapStyle( Qt::PenCapStyle style );
85 static Qt::PenCapStyle decodePenCapStyle(
const QString &str );
87 static QString encodeSldLineJoinStyle( Qt::PenJoinStyle style );
88 static Qt::PenJoinStyle decodeSldLineJoinStyle(
const QString &str );
90 static QString encodeSldLineCapStyle( Qt::PenCapStyle style );
91 static Qt::PenCapStyle decodeSldLineCapStyle(
const QString &str );
93 static QString encodeBrushStyle( Qt::BrushStyle style );
94 static Qt::BrushStyle decodeBrushStyle(
const QString &str );
96 static QString encodeSldBrushStyle( Qt::BrushStyle style );
97 static Qt::BrushStyle decodeSldBrushStyle(
const QString &str );
116 static QString encodePoint( QPointF point );
123 static QPointF decodePoint(
const QString &
string );
137 static QPointF toPoint(
const QVariant &value,
bool *ok
SIP_OUT =
nullptr );
145 static QString encodeSize( QSizeF size );
153 static QSizeF decodeSize(
const QString &
string );
167 static QSizeF toSize(
const QVariant &value,
bool *ok
SIP_OUT =
nullptr );
169 static QString encodeMapUnitScale(
const QgsMapUnitScale &mapUnitScale );
172 static QString encodeRealVector(
const QVector<qreal> &v );
173 static QVector<qreal> decodeRealVector(
const QString &s );
175 static QString encodeSldRealVector(
const QVector<qreal> &v );
176 static QVector<qreal> decodeSldRealVector(
const QString &s );
203 static double sizeInPixelsFromSldUom(
const QString &uom,
double size );
208 static QPainter::CompositionMode decodeBlendMode(
const QString &s );
235 static QPixmap symbolPreviewPixmap(
const QgsSymbol *symbol, QSize size,
int padding = 0,
QgsRenderContext *customContext =
nullptr,
bool selected =
false,
269 static QIcon colorRampPreviewIcon(
QgsColorRamp *ramp, QSize size,
int padding = 0 );
278 static QPixmap colorRampPreviewPixmap(
QgsColorRamp *ramp, QSize size,
int padding = 0 );
280 static void drawStippledBackground( QPainter *painter, QRect rect );
310 SymbolType *symbolCastToType =
dynamic_cast<SymbolType *
>( tmpSymbol );
312 if ( symbolCastToType )
314 return symbolCastToType;
327 static QDomElement saveSymbol(
const QString &symbolName,
const QgsSymbol *symbol, QDomDocument &doc,
const QgsReadWriteContext &context );
334 static QString symbolProperties(
QgsSymbol *symbol );
342 static bool convertPolygonSymbolizerToPointMarker( QDomElement &element,
QgsSymbolLayerList &layerList );
343 static bool hasExternalGraphic( QDomElement &element );
344 static bool hasWellKnownMark( QDomElement &element );
346 static bool needFontMarker( QDomElement &element );
347 static bool needSvgMarker( QDomElement &element );
348 static bool needEllipseMarker( QDomElement &element );
349 static bool needMarkerLine( QDomElement &element );
350 static bool needLinePatternFill( QDomElement &element );
351 static bool needPointPatternFill( QDomElement &element );
352 static bool needSvgFill( QDomElement &element );
354 static void fillToSld( QDomDocument &doc, QDomElement &element,
355 Qt::BrushStyle brushStyle,
const QColor &color = QColor() );
356 static bool fillFromSld( QDomElement &element,
357 Qt::BrushStyle &brushStyle, QColor &color );
360 static void lineToSld( QDomDocument &doc, QDomElement &element,
361 Qt::PenStyle penStyle,
const QColor &color,
double width = -1,
362 const Qt::PenJoinStyle *penJoinStyle =
nullptr,
const Qt::PenCapStyle *penCapStyle =
nullptr,
363 const QVector<qreal> *customDashPattern =
nullptr,
double dashOffset = 0.0 )
SIP_SKIP;
364 static
bool lineFromSld( QDomElement &element,
365 Qt::PenStyle &penStyle, QColor &color,
double &width,
366 Qt::PenJoinStyle *penJoinStyle =
nullptr, Qt::PenCapStyle *penCapStyle =
nullptr,
367 QVector<qreal> *customDashPattern =
nullptr,
double *dashOffset =
nullptr );
369 static
void externalGraphicToSld( QDomDocument &doc, QDomElement &element,
370 const QString &path, const QString &mime,
371 const QColor &color,
double size = -1 );
372 static
bool externalGraphicFromSld( QDomElement &element,
373 QString &path, QString &mime,
374 QColor &color,
double &size );
376 static
void wellKnownMarkerToSld( QDomDocument &doc, QDomElement &element,
377 const QString &name, const QColor &color, const QColor &strokeColor, Qt::PenStyle strokeStyle,
378 double strokeWidth = -1,
double size = -1 );
381 static
bool wellKnownMarkerFromSld( QDomElement &element,
382 QString &name, QColor &color, QColor &strokeColor, Qt::PenStyle &strokeStyle,
383 double &strokeWidth,
double &size )
SIP_PYNAME( wellKnownMarkerFromSld2 );
385 static
void externalMarkerToSld( QDomDocument &doc, QDomElement &element,
386 const QString &path, const QString &format,
int *markIndex =
nullptr,
387 const QColor &color = QColor(),
double size = -1 );
388 static
bool externalMarkerFromSld( QDomElement &element,
389 QString &path, QString &format,
int &markIndex,
390 QColor &color,
double &size );
393 static
void labelTextToSld( QDomDocument &doc, QDomElement &element, const QString &label,
394 const QFont &font, const QColor &color = QColor(),
double size = -1 );
397 static QString ogrFeatureStylePen(
double width,
double mmScaleFactor,
double mapUnitsScaleFactor, const QColor &
c,
398 Qt::PenJoinStyle joinStyle = Qt::MiterJoin,
399 Qt::PenCapStyle capStyle = Qt::FlatCap,
401 const QVector<qreal> *dashPattern =
nullptr );
406 static QString ogrFeatureStyleBrush( const QColor &fillColr );
408 static
void createRotationElement( QDomDocument &doc, QDomElement &element, const QString &rotationFunc );
409 static
bool rotationFromSldElement( QDomElement &element, QString &rotationFunc );
411 static
void createOpacityElement( QDomDocument &doc, QDomElement &element, const QString &alphaFunc );
412 static
bool opacityFromSldElement( QDomElement &element, QString &alphaFunc );
414 static
void createDisplacementElement( QDomDocument &doc, QDomElement &element, QPointF offset );
415 static
bool displacementFromSldElement( QDomElement &element, QPointF &offset );
423 static
void createAnchorPointElement( QDomDocument &doc, QDomElement &element, QPointF anchor );
425 static
void createOnlineResourceElement( QDomDocument &doc, QDomElement &element, const QString &path, const QString &format );
426 static
bool onlineResourceFromSldElement( QDomElement &element, QString &path, QString &format );
428 static
void createGeometryElement( QDomDocument &doc, QDomElement &element, const QString &geomFunc );
429 static
bool geometryFromSldElement( QDomElement &element, QString &geomFunc );
437 static
bool createExpressionElement( QDomDocument &doc, QDomElement &element, const QString &function );
438 static
bool createFunctionElement( QDomDocument &doc, QDomElement &element, const QString &function );
439 static
bool functionFromSldElement( QDomElement &element, QString &function );
441 static QDomElement createSvgParameterElement( QDomDocument &doc, const QString &name, const QString &value );
442 static
QgsStringMap getSvgParameterList( QDomElement &element );
444 static QDomElement createVendorOptionElement( QDomDocument &doc, const QString &name, const QString &value );
445 static
QgsStringMap getVendorOptionList( QDomElement &element );
447 static
QgsStringMap parseProperties( QDomElement &element );
448 static
void saveProperties(
QgsStringMap props, QDomDocument &doc, QDomElement &element );
490 static QDomElement saveColorRamp( const QString &name,
QgsColorRamp *ramp, QDomDocument &doc );
498 static QVariant colorRampToVariant( const QString &name,
QgsColorRamp *ramp );
514 static QString colorToName( const QColor &color );
523 static QList< QColor > parseColorList( const QString &colorStr );
532 static QMimeData *colorToMimeData( const QColor &color )
SIP_FACTORY;
543 static QColor colorFromMimeData( const QMimeData *data,
bool &hasAlpha );
570 static
bool saveColorsToGpl( QFile &file, const QString &paletteName, const
QgsNamedColorList &colors );
580 static
QgsNamedColorList importColorsFromGpl( QFile &file,
bool &ok, QString &name );
590 static QColor parseColor( const QString &colorStr,
bool strictEval = false );
601 static QColor parseColorWithAlpha( const QString &colorStr,
bool &containsAlpha,
bool strictEval = false );
606 static
void multiplyImageOpacity( QImage *image, qreal opacity );
609 static
void blurImageInPlace( QImage &image, QRect rect,
int radius,
bool alphaOnly );
615 static
void premultiplyColor( QColor &rgb,
int alpha );
618 static
void sortVariantList( QList<QVariant> &list, Qt::SortOrder order );
620 static QPointF pointOnLineWithDistance( QPointF startPoint, QPointF directionPoint,
double distance );
623 static QStringList listSvgFiles();
626 static QStringList listSvgFilesAt( const QString &directory );
634 static QString svgSymbolNameToPath( const QString &name, const
QgsPathResolver &pathResolver );
640 static QString svgSymbolPathToName( const QString &path, const
QgsPathResolver &pathResolver );
643 static QPointF polygonCentroid( const QPolygonF &points );
646 static QPointF polygonPointOnSurface( const QPolygonF &points, const QVector<QPolygonF> *rings =
nullptr );
649 static
bool pointInPolygon( const QPolygonF &points, QPointF point );
667 static QString fieldOrExpressionFromExpression(
QgsExpression *expression );
675 static QList<
double> prettyBreaks(
double minimum,
double maximum,
int classes );
702 static
void applyScaleDependency( QDomDocument &doc, QDomElement &ruleElem,
QgsStringMap &props );
708 static
void mergeScaleDependencies(
double mScaleMinDenom,
double mScaleMaxDenom,
QgsStringMap &props );
716 static
void parametricSvgToSld( QDomDocument &doc, QDomElement &graphicElem,
718 const QColor &fillColor,
double size, const QColor &strokeColor,
double strokeWidth );
724 static QString getSvgParametricPath( const QString &basePath, const QColor &fillColor, const QColor &strokeColor,
double strokeWidth );