17 #ifndef QGSSYMBOLLAYERUTILS_H
18 #define QGSSYMBOLLAYERUTILS_H
20 #include "qgis_core.h"
61 static QString encodeColor(
const QColor &color );
62 static QColor decodeColor(
const QString &
str );
64 static QString encodeSldAlpha(
int alpha );
65 static int decodeSldAlpha(
const QString &
str );
67 static QString encodeSldFontStyle( QFont::Style style );
68 static QFont::Style decodeSldFontStyle(
const QString &
str );
70 static QString encodeSldFontWeight(
int weight );
71 static int decodeSldFontWeight(
const QString &
str );
73 static QString encodePenStyle( Qt::PenStyle style );
74 static Qt::PenStyle decodePenStyle(
const QString &
str );
76 static QString encodePenJoinStyle( Qt::PenJoinStyle style );
77 static Qt::PenJoinStyle decodePenJoinStyle(
const QString &
str );
79 static QString encodePenCapStyle( Qt::PenCapStyle style );
80 static Qt::PenCapStyle decodePenCapStyle(
const QString &
str );
82 static QString encodeSldLineJoinStyle( Qt::PenJoinStyle style );
83 static Qt::PenJoinStyle decodeSldLineJoinStyle(
const QString &
str );
85 static QString encodeSldLineCapStyle( Qt::PenCapStyle style );
86 static Qt::PenCapStyle decodeSldLineCapStyle(
const QString &
str );
88 static QString encodeBrushStyle( Qt::BrushStyle style );
89 static Qt::BrushStyle decodeBrushStyle(
const QString &
str );
91 static QString encodeSldBrushStyle( Qt::BrushStyle style );
92 static Qt::BrushStyle decodeSldBrushStyle(
const QString &
str );
172 static QString encodePoint( QPointF point );
179 static QPointF decodePoint(
const QString &
string );
193 static QPointF toPoint(
const QVariant &value,
bool *ok
SIP_OUT =
nullptr );
201 static QString encodeSize( QSizeF size );
209 static QSizeF decodeSize(
const QString &
string );
223 static QSizeF toSize(
const QVariant &value,
bool *ok
SIP_OUT =
nullptr );
225 static QString encodeMapUnitScale(
const QgsMapUnitScale &mapUnitScale );
228 static QString encodeRealVector(
const QVector<qreal> &v );
229 static QVector<qreal> decodeRealVector(
const QString &s );
231 static QString encodeSldRealVector(
const QVector<qreal> &v );
232 static QVector<qreal> decodeSldRealVector(
const QString &s );
259 static double sizeInPixelsFromSldUom(
const QString &uom,
double size );
275 static QPainter::CompositionMode decodeBlendMode(
const QString &s );
302 static QPixmap symbolPreviewPixmap(
const QgsSymbol *symbol, QSize size,
int padding = 0,
QgsRenderContext *customContext =
nullptr,
bool selected =
false,
338 static QIcon colorRampPreviewIcon(
QgsColorRamp *ramp, QSize size,
int padding = 0 );
352 static QPixmap colorRampPreviewPixmap(
QgsColorRamp *ramp, QSize size,
int padding = 0, Qt::Orientation direction = Qt::Horizontal,
353 bool flipDirection =
false,
bool drawTransparentBackground =
true );
355 static void drawStippledBackground( QPainter *painter, QRect rect );
361 static void drawVertexMarker(
double x,
double y, QPainter &p,
Qgis::VertexMarkerType type,
int markerSize );
385 SymbolType *symbolCastToType =
dynamic_cast<SymbolType *
>( tmpSymbol );
387 if ( symbolCastToType )
389 return symbolCastToType;
402 static QDomElement saveSymbol(
const QString &symbolName,
const QgsSymbol *symbol, QDomDocument &doc,
const QgsReadWriteContext &context );
409 static QString symbolProperties(
QgsSymbol *symbol );
414 static bool createSymbolLayerListFromSld( QDomElement &element,
QgsWkbTypes::GeometryType geomType, QList<QgsSymbolLayer *> &layers );
423 static bool convertPolygonSymbolizerToPointMarker( QDomElement &element, QList<QgsSymbolLayer *> &layerList );
424 static bool hasExternalGraphic( QDomElement &element );
425 static bool hasWellKnownMark( QDomElement &element );
427 static bool needFontMarker( QDomElement &element );
428 static bool needSvgMarker( QDomElement &element );
429 static bool needEllipseMarker( QDomElement &element );
430 static bool needMarkerLine( QDomElement &element );
431 static bool needLinePatternFill( QDomElement &element );
432 static bool needPointPatternFill( QDomElement &element );
433 static bool needSvgFill( QDomElement &element );
435 static void fillToSld( QDomDocument &doc, QDomElement &element,
436 Qt::BrushStyle brushStyle,
const QColor &color = QColor() );
437 static bool fillFromSld( QDomElement &element,
438 Qt::BrushStyle &brushStyle, QColor &color );
441 static void lineToSld( QDomDocument &doc, QDomElement &element,
442 Qt::PenStyle penStyle,
const QColor &color,
double width = -1,
443 const Qt::PenJoinStyle *penJoinStyle =
nullptr,
const Qt::PenCapStyle *penCapStyle =
nullptr,
444 const QVector<qreal> *customDashPattern =
nullptr,
double dashOffset = 0.0 )
SIP_SKIP;
445 static
bool lineFromSld( QDomElement &element,
446 Qt::PenStyle &penStyle, QColor &color,
double &width,
447 Qt::PenJoinStyle *penJoinStyle =
nullptr, Qt::PenCapStyle *penCapStyle =
nullptr,
448 QVector<qreal> *customDashPattern =
nullptr,
double *dashOffset =
nullptr );
450 static
void externalGraphicToSld( QDomDocument &doc, QDomElement &element,
451 const QString &path, const QString &mime,
452 const QColor &color,
double size = -1 );
453 static
bool externalGraphicFromSld( QDomElement &element,
454 QString &path, QString &mime,
455 QColor &color,
double &size );
457 static
void wellKnownMarkerToSld( QDomDocument &doc, QDomElement &element,
458 const QString &name, const QColor &color, const QColor &strokeColor, Qt::PenStyle strokeStyle,
459 double strokeWidth = -1,
double size = -1 );
462 static
bool wellKnownMarkerFromSld( QDomElement &element,
463 QString &name, QColor &color, QColor &strokeColor, Qt::PenStyle &strokeStyle,
464 double &strokeWidth,
double &size )
SIP_PYNAME( wellKnownMarkerFromSld2 );
466 static
void externalMarkerToSld( QDomDocument &doc, QDomElement &element,
467 const QString &path, const QString &format,
int *markIndex =
nullptr,
468 const QColor &color = QColor(),
double size = -1 );
469 static
bool externalMarkerFromSld( QDomElement &element,
470 QString &path, QString &format,
int &markIndex,
471 QColor &color,
double &size );
474 static
void labelTextToSld( QDomDocument &doc, QDomElement &element, const QString &label,
475 const QFont &font, const QColor &color = QColor(),
double size = -1 );
478 static QString ogrFeatureStylePen(
double width,
double mmScaleFactor,
double mapUnitsScaleFactor, const QColor &
c,
479 Qt::PenJoinStyle joinStyle = Qt::MiterJoin,
480 Qt::PenCapStyle capStyle = Qt::FlatCap,
482 const QVector<qreal> *dashPattern =
nullptr );
488 static QString ogrFeatureStyleBrush( const QColor &fillColr );
490 static
void createRotationElement( QDomDocument &doc, QDomElement &element, const QString &rotationFunc );
491 static
bool rotationFromSldElement( QDomElement &element, QString &rotationFunc );
493 static
void createOpacityElement( QDomDocument &doc, QDomElement &element, const QString &alphaFunc );
494 static
bool opacityFromSldElement( QDomElement &element, QString &alphaFunc );
496 static
void createDisplacementElement( QDomDocument &doc, QDomElement &element, QPointF offset );
497 static
bool displacementFromSldElement( QDomElement &element, QPointF &offset );
505 static
void createAnchorPointElement( QDomDocument &doc, QDomElement &element, QPointF anchor );
507 static
void createOnlineResourceElement( QDomDocument &doc, QDomElement &element, const QString &path, const QString &format );
508 static
bool onlineResourceFromSldElement( QDomElement &element, QString &path, QString &format );
510 static
void createGeometryElement( QDomDocument &doc, QDomElement &element, const QString &geomFunc );
511 static
bool geometryFromSldElement( QDomElement &element, QString &geomFunc );
519 static
bool createExpressionElement( QDomDocument &doc, QDomElement &element, const QString &function );
520 static
bool createFunctionElement( QDomDocument &doc, QDomElement &element, const QString &function );
521 static
bool functionFromSldElement( QDomElement &element, QString &function );
523 static QDomElement createSvgParameterElement( QDomDocument &doc, const QString &name, const QString &value );
524 static
QgsStringMap getSvgParameterList( QDomElement &element );
526 static QDomElement createVendorOptionElement( QDomDocument &doc, const QString &name, const QString &value );
527 static
QgsStringMap getVendorOptionList( QDomElement &element );
530 static QVariantMap parseProperties( const QDomElement &element );
532 static
void saveProperties( QVariantMap props, QDomDocument &doc, QDomElement &element );
574 static QDomElement saveColorRamp( const QString &name,
QgsColorRamp *ramp, QDomDocument &doc );
582 static QVariant colorRampToVariant( const QString &name,
QgsColorRamp *ramp );
598 static QString colorToName( const QColor &color );
607 static QList< QColor > parseColorList( const QString &colorStr );
616 static QMimeData *colorToMimeData( const QColor &color )
SIP_FACTORY;
626 static QColor colorFromMimeData( const QMimeData *data,
bool &hasAlpha
SIP_OUT );
653 static
bool saveColorsToGpl( QFile &file, const QString &paletteName, const
QgsNamedColorList &colors );
663 static
QgsNamedColorList importColorsFromGpl( QFile &file,
bool &ok, QString &name );
673 static QColor parseColor( const QString &colorStr,
bool strictEval = false );
684 static QColor parseColorWithAlpha( const QString &colorStr,
bool &containsAlpha,
bool strictEval = false );
689 static
void multiplyImageOpacity( QImage *image, qreal opacity );
692 static
void blurImageInPlace( QImage &image, QRect rect,
int radius,
bool alphaOnly );
698 static
void premultiplyColor( QColor &rgb,
int alpha );
715 static
void sortVariantList( QList<QVariant> &list, Qt::SortOrder order );
717 static QPointF pointOnLineWithDistance( QPointF startPoint, QPointF directionPoint,
double distance );
720 static QStringList listSvgFiles();
723 static QStringList listSvgFilesAt( const QString &directory );
731 static QString svgSymbolNameToPath( const QString &name, const
QgsPathResolver &pathResolver );
737 static QString svgSymbolPathToName( const QString &path, const
QgsPathResolver &pathResolver );
740 static QPointF polygonCentroid( const QPolygonF &points );
743 static QPointF polygonPointOnSurface( const QPolygonF &points, const QVector<QPolygonF> *rings =
nullptr );
746 static
bool pointInPolygon( const QPolygonF &points, QPointF point );
753 static
double polylineLength( const QPolygonF &polyline );
767 static QPolygonF polylineSubstring( const QPolygonF &polyline,
double startOffset,
double endOffset );
776 static
bool isSharpCorner( QPointF p1, QPointF p2, QPointF p3 );
785 static
void appendPolyline( QPolygonF &target, const QPolygonF &line );
803 static QString fieldOrExpressionFromExpression(
QgsExpression *expression );
811 static QList<
double> prettyBreaks(
double minimum,
double maximum,
int classes );
818 static
double rescaleUom(
double size,
QgsUnitTypes::RenderUnit unit, const QVariantMap &props );
825 static QPointF rescaleUom( QPointF point,
QgsUnitTypes::RenderUnit unit, const QVariantMap &props )
SIP_PYNAME( rescalePointUom );
832 static QVector<qreal> rescaleUom( const QVector<qreal> &array,
QgsUnitTypes::RenderUnit unit, const QVariantMap &props )
SIP_PYNAME( rescaleArrayUom );
838 static
void applyScaleDependency( QDomDocument &doc, QDomElement &ruleElem, QVariantMap &props );
844 static
void mergeScaleDependencies(
double mScaleMinDenom,
double mScaleMaxDenom, QVariantMap &props );
852 static
void parametricSvgToSld( QDomDocument &doc, QDomElement &graphicElem,
854 const QColor &fillColor,
double size, const QColor &strokeColor,
double strokeWidth );
860 static QString getSvgParametricPath( const QString &basePath, const QColor &fillColor, const QColor &strokeColor,
double strokeWidth );
900 static QgsProperty scaleWholeSymbol(
double scaleFactorX,
double scaleFactorY,
const QgsProperty &property )
904 ( !
qgsDoubleNear( scaleFactorX, 0.0 ) ?
"tostring(" + QString::number( scaleFactorX ) +
"*(" + exprString +
"))" : QStringLiteral(
"'0'" ) ) +
906 ( !
qgsDoubleNear( scaleFactorY, 0.0 ) ?
"tostring(" + QString::number( scaleFactorY ) +
"*(" + exprString +
"))" : QStringLiteral(
"'0'" ) ) );
MarkerClipMode
Marker clipping modes.
LineClipMode
Line clipping modes.
ScaleMethod
Scale methods.
VertexMarkerType
Editing vertex markers, used for showing vertices during a edit operation.
SymbolCoordinateReference
Symbol coordinate reference modes.
HeadType
Possible head types.
ArrowType
Possible arrow types.
Abstract base class for color ramps.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Class for parsing and evaluation of expressions (formerly called "search strings").
Represents a patch shape for use in map legends.
Struct for storing maximum and minimum scales for measurements in map units.
Resolves relative paths into absolute paths and vice versa.
A store for object properties.
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
We may need stable references to symbol layers, when pointers to symbol layers is not usable (when a ...
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.
static QgsSymbol * loadSymbol(const QDomElement &element, const QgsReadWriteContext &context)
Attempts to load a symbol from a DOM element.
Abstract base class for all rendered symbols.
Helper functions for various unit types.
RenderUnit
Rendering size units.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QMap< QString, QString > QgsStringMap
QMap< QString, QgsSymbol * > QgsSymbolMap
QList< QPolygonF > offsetLine(QPolygonF polyline, double dist, QgsWkbTypes::GeometryType geometryType)
calculate geometry shifted by a specified distance
QMap< QString, QgsSymbol * > QgsSymbolMap
QMap< QString, QString > QgsStringMap