2016-08-05 08:08:39 +02:00
|
|
|
class QgsSymbolLayerUtils
|
2012-09-24 02:28:15 +02:00
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
2016-08-05 08:08:39 +02:00
|
|
|
#include <qgssymbollayerutils.h>
|
2012-09-24 02:28:15 +02:00
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
static QString encodeColor( const QColor &color );
|
|
|
|
static QColor decodeColor( const QString &str );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
static QString encodeSldAlpha( int alpha );
|
2017-05-01 18:13:15 +02:00
|
|
|
static int decodeSldAlpha( const QString &str );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
static QString encodeSldFontStyle( QFont::Style style );
|
2017-05-01 18:13:15 +02:00
|
|
|
static QFont::Style decodeSldFontStyle( const QString &str );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
static QString encodeSldFontWeight( int weight );
|
2017-05-01 18:13:15 +02:00
|
|
|
static int decodeSldFontWeight( const QString &str );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
static QString encodePenStyle( Qt::PenStyle style );
|
2017-05-01 18:13:15 +02:00
|
|
|
static Qt::PenStyle decodePenStyle( const QString &str );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
static QString encodePenJoinStyle( Qt::PenJoinStyle style );
|
2017-05-01 18:13:15 +02:00
|
|
|
static Qt::PenJoinStyle decodePenJoinStyle( const QString &str );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
static QString encodePenCapStyle( Qt::PenCapStyle style );
|
2017-05-01 18:13:15 +02:00
|
|
|
static Qt::PenCapStyle decodePenCapStyle( const QString &str );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
static QString encodeSldLineJoinStyle( Qt::PenJoinStyle style );
|
2017-05-01 18:13:15 +02:00
|
|
|
static Qt::PenJoinStyle decodeSldLineJoinStyle( const QString &str );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
static QString encodeSldLineCapStyle( Qt::PenCapStyle style );
|
2017-05-01 18:13:15 +02:00
|
|
|
static Qt::PenCapStyle decodeSldLineCapStyle( const QString &str );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
static QString encodeBrushStyle( Qt::BrushStyle style );
|
2017-05-01 18:13:15 +02:00
|
|
|
static Qt::BrushStyle decodeBrushStyle( const QString &str );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
static QString encodeSldBrushStyle( Qt::BrushStyle style );
|
2017-05-01 18:13:15 +02:00
|
|
|
static Qt::BrushStyle decodeSldBrushStyle( const QString &str );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2016-09-26 08:20:11 +10:00
|
|
|
/** Encodes a QPointF to a string.
|
|
|
|
* @see decodePoint()
|
|
|
|
* @see encodeSize()
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
static QString encodePoint( QPointF point );
|
2016-09-26 08:20:11 +10:00
|
|
|
|
|
|
|
/** Decodes a QSizeF from a string.
|
|
|
|
* @see encodePoint()
|
|
|
|
* @see decodeSize()
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QPointF decodePoint( const QString &string );
|
2016-09-26 08:20:11 +10:00
|
|
|
|
|
|
|
/** Encodes a QSizeF to a string.
|
|
|
|
* @see decodeSize()
|
|
|
|
* @see encodePoint()
|
|
|
|
* @note added in QGIS 3.0
|
|
|
|
*/
|
|
|
|
static QString encodeSize( QSizeF size );
|
|
|
|
|
|
|
|
/** Decodes a QSizeF from a string.
|
|
|
|
* @see encodeSize()
|
|
|
|
* @see decodePoint()
|
|
|
|
* @note added in QGIS 3.0
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QSizeF decodeSize( const QString &string );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
static QString encodeMapUnitScale( const QgsMapUnitScale &mapUnitScale );
|
|
|
|
static QgsMapUnitScale decodeMapUnitScale( const QString &str );
|
2014-05-07 19:02:11 +02:00
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
static QString encodeRealVector( const QVector<qreal> &v );
|
|
|
|
static QVector<qreal> decodeRealVector( const QString &s );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
static QString encodeSldRealVector( const QVector<qreal> &v );
|
|
|
|
static QVector<qreal> decodeSldRealVector( const QString &s );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2016-07-18 09:42:45 +10:00
|
|
|
/** Encodes a render unit into an SLD unit of measure string.
|
|
|
|
* @param unit unit to encode
|
|
|
|
* @param scaleFactor if specified, will be set to scale factor for unit of measure
|
|
|
|
* @returns encoded string
|
|
|
|
* @see decodeSldUom()
|
|
|
|
*/
|
2016-07-17 22:11:17 +10:00
|
|
|
static QString encodeSldUom( QgsUnitTypes::RenderUnit unit, double *scaleFactor );
|
2016-07-18 09:42:45 +10:00
|
|
|
|
|
|
|
/** Decodes a SLD unit of measure string to a render unit.
|
|
|
|
* @param str string to decode
|
|
|
|
* @param scaleFactor if specified, will be set to scale factor for unit of measure
|
|
|
|
* @returns matching render unit
|
|
|
|
* @see encodeSldUom()
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QgsUnitTypes::RenderUnit decodeSldUom( const QString &str, double *scaleFactor );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2017-05-16 10:41:09 +02:00
|
|
|
/** Returns the size scaled in pixels according to the uom attribute.
|
|
|
|
* \param uom The uom attribute from SLD 1.1 version
|
|
|
|
* \param size The original size
|
|
|
|
* \returns the size in pixels
|
|
|
|
* \since QGIS 3.0
|
|
|
|
*/
|
|
|
|
static double sizeInPixelsFromSldUom( const QString &uom, double size );
|
|
|
|
|
2016-08-05 08:09:43 +02:00
|
|
|
static QString encodeScaleMethod( QgsSymbol::ScaleMethod scaleMethod );
|
2017-05-01 18:13:15 +02:00
|
|
|
static QgsSymbol::ScaleMethod decodeScaleMethod( const QString &str );
|
2014-08-17 13:37:26 +02:00
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
static QPainter::CompositionMode decodeBlendMode( const QString &s );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2016-11-17 11:43:53 +07:00
|
|
|
/** Returns an icon preview for a color ramp.
|
|
|
|
* @param symbol symbol
|
|
|
|
* @param size target pixmap size
|
|
|
|
* @param padding space between icon edge and symbol
|
|
|
|
* @see symbolPreviewPixmap()
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QIcon symbolPreviewIcon( QgsSymbol *symbol, QSize size, int padding = 0 );
|
2016-11-17 11:43:53 +07:00
|
|
|
|
|
|
|
/** Returns a pixmap preview for a color ramp.
|
|
|
|
* @param symbol symbol
|
|
|
|
* @param size target pixmap size
|
|
|
|
* @param padding space between icon edge and symbol
|
|
|
|
* @param customContext render context to use when rendering symbol
|
|
|
|
* @note customContext parameter added in 2.6
|
|
|
|
* @see symbolPreviewIcon()
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QPixmap symbolPreviewPixmap( QgsSymbol *symbol, QSize size, int padding = 0, QgsRenderContext *customContext = 0 );
|
2015-03-28 20:03:37 +11:00
|
|
|
|
|
|
|
/** Draws a symbol layer preview to a QPicture
|
|
|
|
* @param layer symbol layer to draw
|
|
|
|
* @param units size units
|
|
|
|
* @param size target size of preview picture
|
|
|
|
* @param scale map unit scale for preview
|
|
|
|
* @returns QPicture containing symbol layer preview
|
|
|
|
* @note added in QGIS 2.9
|
2016-07-18 09:42:45 +10:00
|
|
|
* @see symbolLayerPreviewIcon()
|
2015-03-28 20:03:37 +11:00
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QPicture symbolLayerPreviewPicture( QgsSymbolLayer *layer, QgsUnitTypes::RenderUnit units, QSize size, const QgsMapUnitScale &scale = QgsMapUnitScale() );
|
2015-03-28 20:03:37 +11:00
|
|
|
|
2016-07-18 09:42:45 +10:00
|
|
|
/** Draws a symbol layer preview to an icon.
|
|
|
|
* @param layer symbol layer to draw
|
|
|
|
* @param u size units
|
|
|
|
* @param size target size of preview icon
|
|
|
|
* @param scale map unit scale for preview
|
|
|
|
* @returns icon containing symbol layer preview
|
|
|
|
* @see symbolLayerPreviewPicture()
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QIcon symbolLayerPreviewIcon( QgsSymbolLayer *layer, QgsUnitTypes::RenderUnit u, QSize size, const QgsMapUnitScale &scale = QgsMapUnitScale() );
|
2016-07-18 09:42:45 +10:00
|
|
|
|
2016-11-17 11:43:53 +07:00
|
|
|
/** Returns a icon preview for a color ramp.
|
|
|
|
* @param ramp color ramp
|
|
|
|
* @param size target icon size
|
|
|
|
* @param padding space between icon edge and symbol
|
|
|
|
* @see colorRampPreviewPixmap()
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QIcon colorRampPreviewIcon( QgsColorRamp *ramp, QSize size, int padding = 0 );
|
2016-11-17 11:43:53 +07:00
|
|
|
/** Returns a pixmap preview for a color ramp.
|
|
|
|
* @param ramp color ramp
|
|
|
|
* @param size target pixmap size
|
|
|
|
* @param padding space between icon edge and symbol
|
|
|
|
* @see colorRampPreviewIcon()
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QPixmap colorRampPreviewPixmap( QgsColorRamp *ramp, QSize size, int padding = 0 );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
static void drawStippledBackground( QPainter *painter, QRect rect );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns the maximum estimated bleed for the symbol */
|
2017-05-01 18:13:15 +02:00
|
|
|
static double estimateMaxSymbolBleed( QgsSymbol *symbol, const QgsRenderContext &context );
|
2014-01-26 18:35:21 +01:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Attempts to load a symbol from a DOM element
|
2015-02-03 21:22:46 +11:00
|
|
|
* @param element DOM element representing symbol
|
|
|
|
* @returns decoded symbol, if possible
|
|
|
|
*/
|
2017-05-12 17:31:01 +08:00
|
|
|
static QgsSymbol* loadSymbol( const QDomElement& element, const QgsReadWriteContext &context ) /Factory/;
|
2015-02-03 21:22:46 +11:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Attempts to load a symbol from a DOM element and cast it to a particular symbol
|
2015-02-03 21:22:46 +11:00
|
|
|
* type.
|
|
|
|
* @param element DOM element representing symbol
|
|
|
|
* @returns decoded symbol cast to specified type, if possible
|
|
|
|
* @note not available in python bindings
|
|
|
|
*/
|
2017-05-12 17:31:01 +08:00
|
|
|
//template <class SymbolType> static SymbolType* loadSymbol( const QDomElement& element, const QgsReadWriteContext &context );
|
2015-02-03 21:22:46 +11:00
|
|
|
|
2017-05-12 17:31:01 +08:00
|
|
|
static QgsSymbolLayer* loadSymbolLayer( QDomElement& element, const QgsReadWriteContext &context ) /Factory/;
|
|
|
|
static QDomElement saveSymbol( const QString& symbolName, QgsSymbol* symbol, QDomDocument& doc, const QgsReadWriteContext &context );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2015-10-08 07:10:36 +11:00
|
|
|
/** Returns a string representing the symbol. Can be used to test for equality
|
|
|
|
* between symbols.
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QString symbolProperties( QgsSymbol *symbol );
|
2015-10-08 07:10:36 +11:00
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
static bool createSymbolLayerListFromSld( QDomElement &element, QgsWkbTypes::GeometryType geomType, QgsSymbolLayerList &layers );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
static QgsSymbolLayer *createFillLayerFromSld( QDomElement &element );
|
|
|
|
static QgsSymbolLayer *createLineLayerFromSld( QDomElement &element );
|
|
|
|
static QgsSymbolLayer *createMarkerLayerFromSld( QDomElement &element );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2016-08-05 08:08:39 +02:00
|
|
|
static bool convertPolygonSymbolizerToPointMarker( QDomElement &element, QgsSymbolLayerList &layerList );
|
2012-09-24 02:28:15 +02:00
|
|
|
static bool hasExternalGraphic( QDomElement &element );
|
|
|
|
static bool hasWellKnownMark( QDomElement &element );
|
|
|
|
|
|
|
|
static bool needFontMarker( QDomElement &element );
|
|
|
|
static bool needSvgMarker( QDomElement &element );
|
|
|
|
static bool needEllipseMarker( QDomElement &element );
|
|
|
|
static bool needMarkerLine( QDomElement &element );
|
|
|
|
static bool needLinePatternFill( QDomElement &element );
|
|
|
|
static bool needPointPatternFill( QDomElement &element );
|
|
|
|
static bool needSvgFill( QDomElement &element );
|
|
|
|
|
|
|
|
static void fillToSld( QDomDocument &doc, QDomElement &element,
|
2017-05-01 18:13:15 +02:00
|
|
|
Qt::BrushStyle brushStyle, const QColor &color = QColor() );
|
2012-09-24 02:28:15 +02:00
|
|
|
static bool fillFromSld( QDomElement &element,
|
|
|
|
Qt::BrushStyle &brushStyle, QColor &color );
|
|
|
|
|
2014-01-26 18:35:21 +01:00
|
|
|
//! @note not available in python bindings
|
2012-09-24 18:16:27 +02:00
|
|
|
/*
|
2012-09-24 02:28:15 +02:00
|
|
|
static void lineToSld( QDomDocument &doc, QDomElement &element,
|
2015-10-07 18:32:24 +11:00
|
|
|
Qt::PenStyle penStyle, const QColor& color, double width = -1,
|
2012-09-24 02:28:15 +02:00
|
|
|
const Qt::PenJoinStyle *penJoinStyle = 0, const Qt::PenCapStyle *penCapStyle = 0,
|
|
|
|
const QVector<qreal> *customDashPattern = 0, double dashOffset = 0.0 );
|
2012-09-24 18:16:27 +02:00
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
static bool lineFromSld( QDomElement &element,
|
|
|
|
Qt::PenStyle &penStyle, QColor &color, double &width,
|
|
|
|
Qt::PenJoinStyle *penJoinStyle = 0, Qt::PenCapStyle *penCapStyle = 0,
|
|
|
|
QVector<qreal> *customDashPattern = 0, double *dashOffset = 0 );
|
|
|
|
|
|
|
|
static void externalGraphicToSld( QDomDocument &doc, QDomElement &element,
|
2015-10-07 11:55:34 +11:00
|
|
|
const QString& path, const QString& mime,
|
2017-05-01 18:13:15 +02:00
|
|
|
const QColor &color, double size = -1 );
|
2012-09-24 02:28:15 +02:00
|
|
|
static bool externalGraphicFromSld( QDomElement &element,
|
|
|
|
QString &path, QString &mime,
|
|
|
|
QColor &color, double &size );
|
|
|
|
|
2013-12-30 22:07:53 +01:00
|
|
|
static void wellKnownMarkerToSld( QDomDocument &doc, QDomElement &element,
|
2017-02-22 17:13:57 +10:00
|
|
|
const QString& name, const QColor& color, const QColor& strokeColor, Qt::PenStyle strokeStyle,
|
|
|
|
double strokeWidth = -1, double size = -1 );
|
2015-11-08 19:18:00 +00:00
|
|
|
|
|
|
|
//! @note available in python as wellKnownMarkerFromSld2
|
2012-09-24 02:28:15 +02:00
|
|
|
static bool wellKnownMarkerFromSld( QDomElement &element,
|
2017-02-22 17:13:57 +10:00
|
|
|
QString &name, QColor &color, QColor &strokeColor, Qt::PenStyle &strokeStyle,
|
|
|
|
double &strokeWidth, double &size ) /PyName=wellKnownMarkerFromSld2/;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
static void externalMarkerToSld( QDomDocument &doc, QDomElement &element,
|
2015-10-07 11:55:34 +11:00
|
|
|
const QString& path, const QString& format, int *markIndex = 0,
|
2017-05-01 18:13:15 +02:00
|
|
|
const QColor &color = QColor(), double size = -1 );
|
2012-09-24 02:28:15 +02:00
|
|
|
static bool externalMarkerFromSld( QDomElement &element,
|
|
|
|
QString &path, QString &format, int &markIndex,
|
|
|
|
QColor &color, double &size );
|
|
|
|
|
|
|
|
|
2015-10-07 11:55:34 +11:00
|
|
|
static void labelTextToSld( QDomDocument &doc, QDomElement &element, const QString& label,
|
2017-05-01 18:13:15 +02:00
|
|
|
const QFont &font, const QColor &color = QColor(), double size = -1 );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Create ogr feature style string for pen */
|
2013-06-23 16:00:16 +02:00
|
|
|
static QString ogrFeatureStylePen( double width, double mmScaleFactor, double mapUnitsScaleFactor, const QColor& c,
|
|
|
|
Qt::PenJoinStyle joinStyle = Qt::MiterJoin,
|
|
|
|
Qt::PenCapStyle capStyle = Qt::FlatCap,
|
|
|
|
double offset = 0.0,
|
2017-05-01 18:13:15 +02:00
|
|
|
const QVector<qreal> *dashPattern = 0 );
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Create ogr feature style string for brush
|
2014-05-07 19:02:11 +02:00
|
|
|
@param fillColr fill color*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QString ogrFeatureStyleBrush( const QColor &fillColr );
|
2013-06-23 16:00:16 +02:00
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
static void createRotationElement( QDomDocument &doc, QDomElement &element, const QString &rotationFunc );
|
2012-09-24 02:28:15 +02:00
|
|
|
static bool rotationFromSldElement( QDomElement &element, QString &rotationFunc );
|
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
static void createOpacityElement( QDomDocument &doc, QDomElement &element, const QString &alphaFunc );
|
2012-09-24 02:28:15 +02:00
|
|
|
static bool opacityFromSldElement( QDomElement &element, QString &alphaFunc );
|
|
|
|
|
|
|
|
static void createDisplacementElement( QDomDocument &doc, QDomElement &element, QPointF offset );
|
|
|
|
static bool displacementFromSldElement( QDomElement &element, QPointF &offset );
|
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
static void createOnlineResourceElement( QDomDocument &doc, QDomElement &element, const QString &path, const QString &format );
|
2012-09-24 02:28:15 +02:00
|
|
|
static bool onlineResourceFromSldElement( QDomElement &element, QString &path, QString &format );
|
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
static void createGeometryElement( QDomDocument &doc, QDomElement &element, const QString &geomFunc );
|
2012-09-24 02:28:15 +02:00
|
|
|
static bool geometryFromSldElement( QDomElement &element, QString &geomFunc );
|
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
static bool createExpressionElement( QDomDocument &doc, QDomElement &element, const QString &function );
|
|
|
|
static bool createFunctionElement( QDomDocument &doc, QDomElement &element, const QString &function );
|
2012-09-24 02:28:15 +02:00
|
|
|
static bool functionFromSldElement( QDomElement &element, QString &function );
|
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
static QDomElement createSvgParameterElement( QDomDocument &doc, const QString &name, const QString &value );
|
2012-09-24 02:28:15 +02:00
|
|
|
static QgsStringMap getSvgParameterList( QDomElement &element );
|
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
static QDomElement createVendorOptionElement( QDomDocument &doc, const QString &name, const QString &value );
|
2012-09-24 02:28:15 +02:00
|
|
|
static QgsStringMap getVendorOptionList( QDomElement &element );
|
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
static QgsStringMap parseProperties( QDomElement &element );
|
|
|
|
static void saveProperties( QgsStringMap props, QDomDocument &doc, QDomElement &element );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2017-05-12 17:31:01 +08:00
|
|
|
static QgsSymbolMap loadSymbols( QDomElement& element, const QgsReadWriteContext &context ) /Factory/;
|
|
|
|
static QDomElement saveSymbols( QgsSymbolMap& symbols, const QString& tagName, QDomDocument& doc, const QgsReadWriteContext &context );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
static void clearSymbolMap( QgsSymbolMap &symbols );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
static QgsColorRamp *loadColorRamp( QDomElement &element ) /Factory/;
|
|
|
|
static QDomElement saveColorRamp( const QString &name, QgsColorRamp *ramp, QDomDocument &doc );
|
2017-03-09 09:46:06 +01:00
|
|
|
static QVariant colorRampToVariant( const QString &name, QgsColorRamp *ramp );
|
|
|
|
static QgsColorRamp *loadColorRamp( const QVariant &value );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2014-09-13 08:40:59 +10:00
|
|
|
/**
|
|
|
|
* Returns a friendly display name for a color
|
|
|
|
* @param color source color
|
|
|
|
* @returns display name for color
|
|
|
|
* @note added in 2.5
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QString colorToName( const QColor &color );
|
2014-11-13 23:13:13 +01:00
|
|
|
|
2014-08-16 22:41:30 +10:00
|
|
|
/**
|
|
|
|
* Attempts to parse a string as a list of colors using a variety of common formats, including hex
|
|
|
|
* codes, rgb and rgba strings.
|
|
|
|
* @param colorStr string representing the color list
|
|
|
|
* @returns list of parsed colors
|
|
|
|
* @note added in 2.5
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QList< QColor > parseColorList( const QString &colorStr );
|
2014-08-17 13:37:26 +02:00
|
|
|
|
2014-09-11 21:56:48 +10:00
|
|
|
/**
|
|
|
|
* Creates mime data from a color. Sets both the mime data's color data, and the
|
|
|
|
* mime data's text with the color's hex code.
|
|
|
|
* @param color color to encode as mime data
|
|
|
|
* @see colorFromMimeData
|
|
|
|
* @note added in 2.5
|
|
|
|
*/
|
2014-11-20 14:17:51 +01:00
|
|
|
static QMimeData *colorToMimeData( const QColor &color );
|
2014-09-11 21:56:48 +10:00
|
|
|
|
2014-09-11 21:11:04 +10:00
|
|
|
/**
|
|
|
|
* Attempts to parse mime data as a color
|
|
|
|
* @param data mime data to parse
|
|
|
|
* @param hasAlpha will be set to true if mime data was interpreted as a color containing
|
|
|
|
* an explicit alpha value
|
|
|
|
* @returns valid color if mimedata could be interpreted as a color, otherwise an
|
|
|
|
* invalid color
|
|
|
|
* @note added in 2.5
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QColor colorFromMimeData( const QMimeData *data, bool &hasAlpha );
|
2014-11-13 23:13:13 +01:00
|
|
|
|
2014-08-17 14:41:13 +10:00
|
|
|
/**
|
|
|
|
* Attempts to parse mime data as a list of named colors
|
|
|
|
* @param data mime data to parse
|
|
|
|
* @returns list of parsed colors
|
|
|
|
* @note added in 2.5
|
|
|
|
*/
|
|
|
|
static QgsNamedColorList colorListFromMimeData( const QMimeData *data );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates mime data from a list of named colors
|
|
|
|
* @param colorList list of named colors
|
|
|
|
* @param allFormats set to true to include additional mime formats, include text/plain and application/x-color
|
|
|
|
* @returns mime data containing encoded colors
|
|
|
|
* @note added in 2.5
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QMimeData *colorListToMimeData( const QgsNamedColorList &colorList, const bool allFormats = true );
|
2014-08-17 13:37:26 +02:00
|
|
|
|
2014-08-17 21:04:54 +10:00
|
|
|
/**
|
|
|
|
* Exports colors to a gpl GIMP palette file
|
|
|
|
* @param file destination file
|
|
|
|
* @param paletteName name of palette, which is stored in gpl file
|
|
|
|
* @param colors colors to export
|
|
|
|
* @returns true if export was successful
|
|
|
|
* @see importColorsFromGpl
|
2016-02-14 03:50:23 +01:00
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static bool saveColorsToGpl( QFile &file, const QString &paletteName, const QgsNamedColorList &colors );
|
2014-08-17 21:04:54 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Imports colors from a gpl GIMP palette file
|
|
|
|
* @param file source gpl file
|
|
|
|
* @param ok will be true if file was successfully read
|
2014-09-17 22:52:23 +10:00
|
|
|
* @param name will be set to palette name from gpl file, if present
|
2014-08-17 21:04:54 +10:00
|
|
|
* @returns list of imported colors
|
|
|
|
* @see saveColorsToGpl
|
2016-02-14 03:50:23 +01:00
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QgsNamedColorList importColorsFromGpl( QFile &file, bool &ok, QString &name );
|
2014-08-17 13:37:26 +02:00
|
|
|
|
2014-05-12 23:58:47 +10:00
|
|
|
/**
|
|
|
|
* Attempts to parse a string as a color using a variety of common formats, including hex
|
|
|
|
* codes, rgb and rgba strings.
|
|
|
|
* @param colorStr string representing the color
|
2014-08-16 22:41:30 +10:00
|
|
|
* @param strictEval set to true for stricter color parsing rules
|
2014-05-12 23:58:47 +10:00
|
|
|
* @returns parsed color
|
|
|
|
* @note added in 2.3
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QColor parseColor( const QString &colorStr, bool strictEval = false );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2014-05-12 23:58:47 +10:00
|
|
|
/**
|
|
|
|
* Attempts to parse a string as a color using a variety of common formats, including hex
|
|
|
|
* codes, rgb and rgba strings.
|
|
|
|
* @param colorStr string representing the color
|
|
|
|
* @param containsAlpha if colorStr contains an explicit alpha value then containsAlpha will be set to true
|
2014-08-16 22:41:30 +10:00
|
|
|
* @param strictEval set to true for stricter color parsing rules
|
2014-05-12 23:58:47 +10:00
|
|
|
* @returns parsed color
|
|
|
|
* @note added in 2.3
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QColor parseColorWithAlpha( const QString &colorStr, bool &containsAlpha, bool strictEval = false );
|
2014-05-12 23:58:47 +10:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Multiplies opacity of image pixel values with a (global) transparency value*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static void multiplyImageOpacity( QImage *image, qreal alpha );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2014-11-20 14:17:51 +01:00
|
|
|
/** Blurs an image in place, e.g. creating Qt-independent drop shadows */
|
2017-05-01 18:13:15 +02:00
|
|
|
static void blurImageInPlace( QImage &image, QRect rect, int radius, bool alphaOnly );
|
2013-04-05 18:31:31 -06:00
|
|
|
|
2014-03-21 12:50:50 +11:00
|
|
|
/** Converts a QColor into a premultiplied ARGB QColor value using a specified alpha value
|
|
|
|
* @note added in 2.3
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static void premultiplyColor( QColor &rgb, int alpha );
|
2014-03-21 12:50:50 +11:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Sorts the passed list in requested order*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static void sortVariantList( QList<QVariant> &list, Qt::SortOrder order );
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns a point on the line from startPoint to directionPoint that is a certain distance away from the starting point*/
|
2016-02-02 19:46:18 +11:00
|
|
|
static QPointF pointOnLineWithDistance( QPointF startPoint, QPointF directionPoint, double distance );
|
2012-11-30 02:17:55 +01:00
|
|
|
|
|
|
|
//! Return a list of all available svg files
|
|
|
|
static QStringList listSvgFiles();
|
|
|
|
|
|
|
|
//! Return a list of svg files at the specified directory
|
2017-05-01 18:13:15 +02:00
|
|
|
static QStringList listSvgFilesAt( const QString &directory );
|
2012-11-30 02:17:55 +01:00
|
|
|
|
2017-04-27 14:26:21 +08:00
|
|
|
static QString svgSymbolNameToPath( QString name, const QgsPathResolver& pathResolver );
|
2012-11-30 02:17:55 +01:00
|
|
|
|
2017-04-27 14:26:21 +08:00
|
|
|
static QString svgSymbolPathToName( QString path, const QgsPathResolver& pathResolver );
|
2014-01-26 18:35:21 +01:00
|
|
|
|
|
|
|
//! Calculate the centroid point of a QPolygonF
|
2017-05-01 18:13:15 +02:00
|
|
|
static QPointF polygonCentroid( const QPolygonF &points );
|
2014-02-11 14:19:48 +07:00
|
|
|
|
2014-11-20 14:17:51 +01:00
|
|
|
//! Calculate a point within of a QPolygonF
|
2017-05-01 18:13:15 +02:00
|
|
|
static QPointF polygonPointOnSurface( const QPolygonF &points );
|
2014-11-20 14:17:51 +01:00
|
|
|
|
|
|
|
//! Calculate whether a point is within of a QPolygonF
|
2016-02-02 19:46:18 +11:00
|
|
|
static bool pointInPolygon( const QPolygonF &points, QPointF point );
|
2014-11-20 14:17:51 +01:00
|
|
|
|
2014-02-11 14:19:48 +07:00
|
|
|
/** Return a new valid expression instance for given field or expression string.
|
|
|
|
* If the input is not a valid expression, it is assumed that it is a field name and gets properly quoted.
|
|
|
|
* If the string is empty, returns null pointer.
|
|
|
|
* This is useful when accepting input which could be either a non-quoted field name or expression.
|
|
|
|
* @note added in 2.2
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QgsExpression *fieldOrExpressionToExpression( const QString &fieldOrExpression ) /Factory/;
|
2014-02-11 14:19:48 +07:00
|
|
|
|
|
|
|
/** Return a field name if the whole expression is just a name of the field .
|
|
|
|
* Returns full expression string if the expression is more complex than just one field.
|
|
|
|
* Using just expression->expression() method may return quoted field name, but that is not
|
|
|
|
* wanted for saving (due to backward compatibility) or display in GUI.
|
|
|
|
* @note added in 2.2
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QString fieldOrExpressionFromExpression( QgsExpression *expression );
|
2014-11-20 14:17:51 +01:00
|
|
|
|
2015-04-27 09:57:20 +10:00
|
|
|
/** Computes a sequence of about 'classes' equally spaced round values
|
|
|
|
* which cover the range of values from 'minimum' to 'maximum'.
|
|
|
|
* The values are chosen so that they are 1, 2 or 5 times a power of 10.
|
|
|
|
* @note added in 2.10
|
|
|
|
*/
|
|
|
|
static QList<double> prettyBreaks( double minimum, double maximum, int classes );
|
|
|
|
|
2016-08-26 11:33:36 +02:00
|
|
|
/** Rescales the given size based on the uomScale found in the props, if any is found, otherwise
|
|
|
|
* returns the value un-modified
|
|
|
|
* @note added in 3.0
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static double rescaleUom( double size, QgsUnitTypes::RenderUnit unit, const QgsStringMap &props );
|
2016-08-26 11:33:36 +02:00
|
|
|
|
|
|
|
/** Rescales the given point based on the uomScale found in the props, if any is found, otherwise
|
|
|
|
* returns a copy of the original point
|
|
|
|
* @note added in 3.0
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QPointF rescaleUom( QPointF point, QgsUnitTypes::RenderUnit unit, const QgsStringMap &props ) /PyName=rescalePointUom/;
|
2016-08-26 11:33:36 +02:00
|
|
|
|
|
|
|
/** Rescales the given array based on the uomScale found in the props, if any is found, otherwise
|
|
|
|
* returns a copy of the original point
|
|
|
|
* @note added in 3.0
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QVector<qreal> rescaleUom( const QVector<qreal> &array, QgsUnitTypes::RenderUnit unit, const QgsStringMap &props ) /PyName=rescaleArrayUom/;
|
2016-08-26 11:33:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the properties contain scaleMinDenom and scaleMaxDenom, if available, they are added into the SE Rule element
|
|
|
|
* @note added in 3.0
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static void applyScaleDependency( QDomDocument &doc, QDomElement &ruleElem, QgsStringMap &props );
|
2016-08-26 11:33:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Merges the local scale limits, if any, with the ones already in the map, if any
|
|
|
|
* @note added in 3.0
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static void mergeScaleDependencies( int mScaleMinDenom, int mScaleMaxDenom, QgsStringMap &props );
|
2016-08-26 11:33:36 +02:00
|
|
|
|
2016-10-09 11:57:38 +02:00
|
|
|
/**
|
|
|
|
* Encodes a reference to a parametric SVG into SLD, as a succession of parametric SVG using URL parameters,
|
2017-02-22 17:13:57 +10:00
|
|
|
* a fallback SVG without parameters, and a final fallback as a mark with the right colors and stroke for systems
|
2016-10-09 11:57:38 +02:00
|
|
|
* that cannot do SVG at all
|
|
|
|
* @note added in 3.0
|
|
|
|
*/
|
|
|
|
static void parametricSvgToSld( QDomDocument &doc, QDomElement &graphicElem,
|
|
|
|
const QString& path,
|
2017-05-01 18:13:15 +02:00
|
|
|
const QColor &fillColor, double size, const QColor &strokeColor, double strokeWidth );
|
2016-10-09 11:57:38 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Encodes a reference to a parametric SVG into a path with parameters according to the SVG Parameters spec
|
|
|
|
* @note added in 3.0
|
|
|
|
*/
|
2017-05-01 18:13:15 +02:00
|
|
|
static QString getSvgParametricPath( const QString &basePath, const QColor &fillColor, const QColor &strokeColor, double strokeWidth );
|
2016-10-09 11:57:38 +02:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
};
|