17 #ifndef QGSSYMBOLLAYERUTILS_H 18 #define QGSSYMBOLLAYERUTILS_H 20 #include "qgis_core.h" 57 static QString encodeColor(
const QColor &color );
58 static QColor decodeColor(
const QString &str );
60 static QString encodeSldAlpha(
int alpha );
61 static int decodeSldAlpha(
const QString &str );
63 static QString encodeSldFontStyle( QFont::Style style );
64 static QFont::Style decodeSldFontStyle(
const QString &str );
66 static QString encodeSldFontWeight(
int weight );
67 static int decodeSldFontWeight(
const QString &str );
69 static QString encodePenStyle( Qt::PenStyle style );
70 static Qt::PenStyle decodePenStyle(
const QString &str );
72 static QString encodePenJoinStyle( Qt::PenJoinStyle style );
73 static Qt::PenJoinStyle decodePenJoinStyle(
const QString &str );
75 static QString encodePenCapStyle( Qt::PenCapStyle style );
76 static Qt::PenCapStyle decodePenCapStyle(
const QString &str );
78 static QString encodeSldLineJoinStyle( Qt::PenJoinStyle style );
79 static Qt::PenJoinStyle decodeSldLineJoinStyle(
const QString &str );
81 static QString encodeSldLineCapStyle( Qt::PenCapStyle style );
82 static Qt::PenCapStyle decodeSldLineCapStyle(
const QString &str );
84 static QString encodeBrushStyle( Qt::BrushStyle style );
85 static Qt::BrushStyle decodeBrushStyle(
const QString &str );
87 static QString encodeSldBrushStyle( Qt::BrushStyle style );
88 static Qt::BrushStyle decodeSldBrushStyle(
const QString &str );
95 static QString encodePoint( QPointF point );
102 static QPointF decodePoint(
const QString &
string );
110 static QString encodeSize( QSizeF size );
118 static QSizeF decodeSize(
const QString &
string );
120 static QString encodeMapUnitScale(
const QgsMapUnitScale &mapUnitScale );
123 static QString encodeRealVector(
const QVector<qreal> &v );
124 static QVector<qreal> decodeRealVector(
const QString &s );
126 static QString encodeSldRealVector(
const QVector<qreal> &v );
127 static QVector<qreal> decodeSldRealVector(
const QString &s );
154 static double sizeInPixelsFromSldUom(
const QString &uom,
double size );
159 static QPainter::CompositionMode decodeBlendMode(
const QString &s );
168 static QIcon symbolPreviewIcon(
QgsSymbol *symbol, QSize size,
int padding = 0 );
179 static QPixmap symbolPreviewPixmap(
QgsSymbol *symbol, QSize size,
int padding = 0,
QgsRenderContext *customContext =
nullptr );
211 static QIcon colorRampPreviewIcon(
QgsColorRamp *ramp, QSize size,
int padding = 0 );
220 static QPixmap colorRampPreviewPixmap(
QgsColorRamp *ramp, QSize size,
int padding = 0 );
222 static void drawStippledBackground( QPainter *painter, QRect rect );
246 SymbolType *symbolCastToType =
dynamic_cast<SymbolType *
>( tmpSymbol );
248 if ( symbolCastToType )
250 return symbolCastToType;
270 static QString symbolProperties(
QgsSymbol *symbol );
278 static bool convertPolygonSymbolizerToPointMarker( QDomElement &element,
QgsSymbolLayerList &layerList );
279 static bool hasExternalGraphic( QDomElement &element );
280 static bool hasWellKnownMark( QDomElement &element );
282 static bool needFontMarker( QDomElement &element );
283 static bool needSvgMarker( QDomElement &element );
284 static bool needEllipseMarker( QDomElement &element );
285 static bool needMarkerLine( QDomElement &element );
286 static bool needLinePatternFill( QDomElement &element );
287 static bool needPointPatternFill( QDomElement &element );
288 static bool needSvgFill( QDomElement &element );
290 static void fillToSld( QDomDocument &doc, QDomElement &element,
291 Qt::BrushStyle brushStyle,
const QColor &color = QColor() );
292 static bool fillFromSld( QDomElement &element,
293 Qt::BrushStyle &brushStyle, QColor &color );
296 static void lineToSld( QDomDocument &doc, QDomElement &element,
297 Qt::PenStyle penStyle,
const QColor &color,
double width = -1,
298 const Qt::PenJoinStyle *penJoinStyle =
nullptr,
const Qt::PenCapStyle *penCapStyle =
nullptr,
299 const QVector<qreal> *customDashPattern =
nullptr,
double dashOffset = 0.0 )
SIP_SKIP;
300 static bool lineFromSld( QDomElement &element,
301 Qt::PenStyle &penStyle, QColor &color,
double &width,
302 Qt::PenJoinStyle *penJoinStyle =
nullptr, Qt::PenCapStyle *penCapStyle =
nullptr,
303 QVector<qreal> *customDashPattern =
nullptr,
double *dashOffset =
nullptr );
305 static void externalGraphicToSld( QDomDocument &doc, QDomElement &element,
306 const QString &path,
const QString &mime,
307 const QColor &color,
double size = -1 );
308 static bool externalGraphicFromSld( QDomElement &element,
309 QString &path, QString &mime,
310 QColor &color,
double &size );
312 static void wellKnownMarkerToSld( QDomDocument &doc, QDomElement &element,
313 const QString &name,
const QColor &color,
const QColor &strokeColor, Qt::PenStyle strokeStyle,
314 double strokeWidth = -1,
double size = -1 );
317 static bool wellKnownMarkerFromSld( QDomElement &element,
318 QString &name, QColor &color, QColor &strokeColor, Qt::PenStyle &strokeStyle,
319 double &strokeWidth,
double &size )
SIP_PYNAME( wellKnownMarkerFromSld2 );
321 static void externalMarkerToSld( QDomDocument &doc, QDomElement &element,
322 const QString &path,
const QString &format,
int *markIndex =
nullptr,
323 const QColor &color = QColor(),
double size = -1 );
324 static bool externalMarkerFromSld( QDomElement &element,
325 QString &path, QString &format,
int &markIndex,
326 QColor &color,
double &size );
329 static void labelTextToSld( QDomDocument &doc, QDomElement &element,
const QString &label,
330 const QFont &font,
const QColor &color = QColor(),
double size = -1 );
333 static QString ogrFeatureStylePen(
double width,
double mmScaleFactor,
double mapUnitsScaleFactor,
const QColor &c,
334 Qt::PenJoinStyle joinStyle = Qt::MiterJoin,
335 Qt::PenCapStyle capStyle = Qt::FlatCap,
337 const QVector<qreal> *dashPattern =
nullptr );
342 static QString ogrFeatureStyleBrush(
const QColor &fillColr );
344 static void createRotationElement( QDomDocument &doc, QDomElement &element,
const QString &rotationFunc );
345 static bool rotationFromSldElement( QDomElement &element, QString &rotationFunc );
347 static void createOpacityElement( QDomDocument &doc, QDomElement &element,
const QString &alphaFunc );
348 static bool opacityFromSldElement( QDomElement &element, QString &alphaFunc );
350 static void createDisplacementElement( QDomDocument &doc, QDomElement &element, QPointF offset );
351 static bool displacementFromSldElement( QDomElement &element, QPointF &offset );
359 static void createAnchorPointElement( QDomDocument &doc, QDomElement &element, QPointF anchor );
361 static void createOnlineResourceElement( QDomDocument &doc, QDomElement &element,
const QString &path,
const QString &format );
362 static bool onlineResourceFromSldElement( QDomElement &element, QString &path, QString &format );
364 static void createGeometryElement( QDomDocument &doc, QDomElement &element,
const QString &geomFunc );
365 static bool geometryFromSldElement( QDomElement &element, QString &geomFunc );
374 static bool createExpressionElement( QDomDocument &doc, QDomElement &element,
const QString &
function );
375 static bool createFunctionElement( QDomDocument &doc, QDomElement &element,
const QString &
function );
376 static bool functionFromSldElement( QDomElement &element, QString &
function );
378 static QDomElement createSvgParameterElement( QDomDocument &doc,
const QString &name,
const QString &value );
379 static QgsStringMap getSvgParameterList( QDomElement &element );
381 static QDomElement createVendorOptionElement( QDomDocument &doc,
const QString &name,
const QString &value );
382 static QgsStringMap getVendorOptionList( QDomElement &element );
384 static QgsStringMap parseProperties( QDomElement &element );
385 static void saveProperties(
QgsStringMap props, QDomDocument &doc, QDomElement &element );
427 static QDomElement saveColorRamp(
const QString &name,
QgsColorRamp *ramp, QDomDocument &doc );
435 static QVariant colorRampToVariant(
const QString &name,
QgsColorRamp *ramp );
451 static QString colorToName(
const QColor &color );
460 static QList< QColor > parseColorList(
const QString &colorStr );
469 static QMimeData *colorToMimeData(
const QColor &color )
SIP_FACTORY;
480 static QColor colorFromMimeData(
const QMimeData *data,
bool &hasAlpha );
507 static bool saveColorsToGpl( QFile &file,
const QString &paletteName,
const QgsNamedColorList &colors );
517 static QgsNamedColorList importColorsFromGpl( QFile &file,
bool &ok, QString &name );
527 static QColor parseColor(
const QString &colorStr,
bool strictEval =
false );
538 static QColor parseColorWithAlpha(
const QString &colorStr,
bool &containsAlpha,
bool strictEval =
false );
543 static void multiplyImageOpacity( QImage *image, qreal opacity );
546 static void blurImageInPlace( QImage &image, QRect rect,
int radius,
bool alphaOnly );
552 static void premultiplyColor( QColor &rgb,
int alpha );
555 static void sortVariantList( QList<QVariant> &list, Qt::SortOrder order );
557 static QPointF pointOnLineWithDistance( QPointF startPoint, QPointF directionPoint,
double distance );
560 static QStringList listSvgFiles();
563 static QStringList listSvgFilesAt(
const QString &directory );
570 static QString svgSymbolNameToPath( QString name,
const QgsPathResolver &pathResolver );
573 static QString svgSymbolPathToName( QString path,
const QgsPathResolver &pathResolver );
576 static QPointF polygonCentroid(
const QPolygonF &points );
579 static QPointF polygonPointOnSurface(
const QPolygonF &points );
582 static bool pointInPolygon(
const QPolygonF &points, QPointF point );
591 static QgsExpression *fieldOrExpressionToExpression(
const QString &fieldOrExpression )
SIP_FACTORY;
600 static QString fieldOrExpressionFromExpression( QgsExpression *expression );
608 static QList<double> prettyBreaks(
double minimum,
double maximum,
int classes );
635 static void applyScaleDependency( QDomDocument &doc, QDomElement &ruleElem,
QgsStringMap &props );
641 static void mergeScaleDependencies(
int mScaleMinDenom,
int mScaleMaxDenom,
QgsStringMap &props );
649 static void parametricSvgToSld( QDomDocument &doc, QDomElement &graphicElem,
651 const QColor &fillColor,
double size,
const QColor &strokeColor,
double strokeWidth );
657 static QString getSvgParametricPath(
const QString &basePath,
const QColor &fillColor,
const QColor &strokeColor,
double strokeWidth );
The class is used as a container of context for various read/write operations on other objects...
Abstract base class for color ramps.
QList< QPolygonF > offsetLine(QPolygonF polyline, double dist, QgsWkbTypes::GeometryType geometryType)
calculate geometry shifted by a specified distance
static QgsSymbol * loadSymbol(const QDomElement &element, const QgsReadWriteContext &context)
Attempts to load a symbol from a DOM element.
QMap< QString, QString > QgsStringMap
QMap< QString, QString > QgsStringMap
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
QList< QgsSymbolLayer * > QgsSymbolLayerList
static SymbolType * loadSymbol(const QDomElement &element, const QgsReadWriteContext &context)
Attempts to load a symbol from a DOM element and cast it to a particular symbol type.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Contains information about the context of a rendering operation.
Struct for storing maximum and minimum scales for measurements in map units.
QMap< QString, QgsSymbol *> QgsSymbolMap
QMap< QString, QgsSymbol *> QgsSymbolMap
Resolves relative paths into absolute paths and vice versa.
RenderUnit
Rendering size units.