QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgssymbollayerregistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgssymbollayerregistry.cpp
3 ---------------------
4 begin : November 2009
5 copyright : (C) 2009 by Martin Dobias
6 email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17
18#include "qgsarrowsymbollayer.h"
20#include "qgsfillsymbollayer.h"
24#include "qgslinesymbollayer.h"
26#include "qgsmasksymbollayer.h"
28
29#include <QString>
30
31using namespace Qt::StringLiterals;
32
34{
35 // init registry with known symbol layers
36 addSymbolLayerType( new QgsSymbolLayerMetadata( u"SimpleLine"_s, QObject::tr( "Simple Line" ), Qgis::SymbolType::Line,
38 addSymbolLayerType( new QgsSymbolLayerMetadata( u"MarkerLine"_s, QObject::tr( "Marker Line" ), Qgis::SymbolType::Line,
40 addSymbolLayerType( new QgsSymbolLayerMetadata( u"HashLine"_s, QObject::tr( "Hashed Line" ), Qgis::SymbolType::Line,
42 addSymbolLayerType( new QgsSymbolLayerMetadata( u"ArrowLine"_s, QObject::tr( "Arrow" ), Qgis::SymbolType::Line,
44 addSymbolLayerType( new QgsSymbolLayerMetadata( u"InterpolatedLine"_s, QObject::tr( "Interpolated Line" ), Qgis::SymbolType::Line,
46 addSymbolLayerType( new QgsSymbolLayerMetadata( u"RasterLine"_s, QObject::tr( "Raster Line" ), Qgis::SymbolType::Line,
48 addSymbolLayerType( new QgsSymbolLayerMetadata( u"Lineburst"_s, QObject::tr( "Lineburst" ), Qgis::SymbolType::Line,
50 addSymbolLayerType( new QgsSymbolLayerMetadata( u"FilledLine"_s, QObject::tr( "Filled Line" ), Qgis::SymbolType::Line,
52 addSymbolLayerType( new QgsSymbolLayerMetadata( u"LinearReferencing"_s, QObject::tr( "Linear Referencing" ), Qgis::SymbolType::Line,
54
55 addSymbolLayerType( new QgsSymbolLayerMetadata( u"SimpleMarker"_s, QObject::tr( "Simple Marker" ), Qgis::SymbolType::Marker,
57 addSymbolLayerType( new QgsSymbolLayerMetadata( u"FilledMarker"_s, QObject::tr( "Filled Marker" ), Qgis::SymbolType::Marker,
59 addSymbolLayerType( new QgsSymbolLayerMetadata( u"SvgMarker"_s, QObject::tr( "SVG Marker" ), Qgis::SymbolType::Marker,
61 addSymbolLayerType( new QgsSymbolLayerMetadata( u"RasterMarker"_s, QObject::tr( "Raster Image Marker" ), Qgis::SymbolType::Marker,
63 addSymbolLayerType( new QgsSymbolLayerMetadata( u"AnimatedMarker"_s, QObject::tr( "Animated Marker" ), Qgis::SymbolType::Marker,
65 addSymbolLayerType( new QgsSymbolLayerMetadata( u"FontMarker"_s, QObject::tr( "Font Marker" ), Qgis::SymbolType::Marker,
67 addSymbolLayerType( new QgsSymbolLayerMetadata( u"EllipseMarker"_s, QObject::tr( "Ellipse Marker" ), Qgis::SymbolType::Marker,
69 addSymbolLayerType( new QgsSymbolLayerMetadata( u"VectorField"_s, QObject::tr( "Vector Field Marker" ), Qgis::SymbolType::Marker,
71 addSymbolLayerType( new QgsSymbolLayerMetadata( u"MaskMarker"_s, QObject::tr( "Mask" ), Qgis::SymbolType::Marker,
73
74 addSymbolLayerType( new QgsSymbolLayerMetadata( u"SimpleFill"_s, QObject::tr( "Simple Fill" ), Qgis::SymbolType::Fill,
76 addSymbolLayerType( new QgsSymbolLayerMetadata( u"GradientFill"_s, QObject::tr( "Gradient Fill" ), Qgis::SymbolType::Fill,
78 addSymbolLayerType( new QgsSymbolLayerMetadata( u"ShapeburstFill"_s, QObject::tr( "Shapeburst Fill" ), Qgis::SymbolType::Fill,
80 addSymbolLayerType( new QgsSymbolLayerMetadata( u"RasterFill"_s, QObject::tr( "Raster Image Fill" ), Qgis::SymbolType::Fill,
82 addSymbolLayerType( new QgsSymbolLayerMetadata( u"SVGFill"_s, QObject::tr( "SVG Fill" ), Qgis::SymbolType::Fill,
84 addSymbolLayerType( new QgsSymbolLayerMetadata( u"CentroidFill"_s, QObject::tr( "Centroid Fill" ), Qgis::SymbolType::Fill,
86 addSymbolLayerType( new QgsSymbolLayerMetadata( u"RandomMarkerFill"_s, QObject::tr( "Random Marker Fill" ), Qgis::SymbolType::Fill,
88 addSymbolLayerType( new QgsSymbolLayerMetadata( u"LinePatternFill"_s, QObject::tr( "Line Pattern Fill" ), Qgis::SymbolType::Fill,
90 addSymbolLayerType( new QgsSymbolLayerMetadata( u"PointPatternFill"_s, QObject::tr( "Point Pattern Fill" ), Qgis::SymbolType::Fill,
92
93 addSymbolLayerType( new QgsSymbolLayerMetadata( u"GeometryGenerator"_s, QObject::tr( "Geometry Generator" ), Qgis::SymbolType::Hybrid,
95}
96
98{
99 qDeleteAll( mMetadata );
100}
101
103{
104 if ( !metadata || mMetadata.contains( metadata->name() ) )
105 return false;
106
107 mMetadata[metadata->name()] = metadata;
108 return true;
109}
110
112{
113 if ( !metadata || !mMetadata.contains( metadata->name() ) )
114 return false;
115
116 metadata = mMetadata.take( metadata->name() );
117 delete metadata;
118 return true;
119}
120
121
123{
124 return mMetadata.value( name );
125}
126
127std::unique_ptr< QgsSymbolLayer > QgsSymbolLayerRegistry::defaultSymbolLayer( Qgis::SymbolType type )
128{
129 switch ( type )
130 {
132 return std::unique_ptr< QgsSymbolLayer >( QgsSimpleMarkerSymbolLayer::create() );
133
135 return std::unique_ptr< QgsSymbolLayer >( QgsSimpleLineSymbolLayer::create() );
136
138 return std::unique_ptr< QgsSymbolLayer >( QgsSimpleFillSymbolLayer::create() );
139
141 return nullptr;
142 }
143
144 return nullptr;
145}
146
147std::unique_ptr< QgsSymbolLayer > QgsSymbolLayerRegistry::createSymbolLayer( const QString &name, const QVariantMap &properties ) const
148{
149 if ( !mMetadata.contains( name ) )
150 return nullptr;
151
152 return std::unique_ptr< QgsSymbolLayer>( mMetadata[name]->createSymbolLayer( properties ) );
153}
154
155std::unique_ptr< QgsSymbolLayer > QgsSymbolLayerRegistry::createSymbolLayerFromSld( const QString &name, QDomElement &element ) const
156{
157 if ( !mMetadata.contains( name ) )
158 return nullptr;
159
160 return std::unique_ptr< QgsSymbolLayer>( mMetadata[name]->createSymbolLayerFromSld( element ) );
161}
162
163void QgsSymbolLayerRegistry::resolvePaths( const QString &name, QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving ) const
164{
165 if ( !mMetadata.contains( name ) )
166 return;
167
168 mMetadata[name]->resolvePaths( properties, pathResolver, saving );
169}
170
171void QgsSymbolLayerRegistry::resolveFonts( const QString &name, QVariantMap &properties, const QgsReadWriteContext &context ) const
172{
173 if ( !mMetadata.contains( name ) )
174 return;
175
176 mMetadata[name]->resolveFonts( properties, context );
177}
178
180{
181 QStringList lst;
182 QMap<QString, QgsSymbolLayerAbstractMetadata *>::ConstIterator it = mMetadata.constBegin();
183 for ( ; it != mMetadata.constEnd(); ++it )
184 {
185 if ( it.value()->type() == type || it.value()->type() == Qgis::SymbolType::Hybrid )
186 lst.append( it.key() );
187 }
188 return lst;
189}
SymbolType
Symbol types.
Definition qgis.h:629
@ Marker
Marker symbol.
Definition qgis.h:630
@ Line
Line symbol.
Definition qgis.h:631
@ Fill
Fill symbol.
Definition qgis.h:632
@ Hybrid
Hybrid symbol.
Definition qgis.h:633
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates an animated marker symbol layer from a string map of properties.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Create a new QgsArrowSymbolLayer.
static QgsSymbolLayer * createFromSld(QDomElement &element)
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsCentroidFillSymbolLayer using the specified properties map containing symbol propert...
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates the symbol layer.
static QgsSymbolLayer * createFromSld(QDomElement &element)
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsFilledLineSymbolLayer, using the settings serialized in the properties map (correspo...
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsFilledMarkerSymbolLayer.
static void resolveFonts(const QVariantMap &properties, const QgsReadWriteContext &context)
Resolves fonts from a properties map, raising warnings in the specified context if the required fonts...
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsFontMarkerSymbolLayer from an SLD XML element.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsFontMarkerSymbolLayer from a property map (see properties()).
static QgsSymbolLayer * create(const QVariantMap &properties)
Creates the symbol layer.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsGradientFillSymbolLayer using the specified properties map containing symbol propert...
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsHashedLineSymbolLayer, using the settings serialized in the properties map (correspo...
static QgsSymbolLayer * create(const QVariantMap &properties)
Creates the symbol layer.
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsLinePatternFillSymbolLayer from a SLD element.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsLinePatternFillSymbolLayer from a properties map.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsLinearReferencingSymbolLayer, using the specified properties.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsLineburstSymbolLayer, using the settings serialized in the properties map (correspon...
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsMarkerLineSymbolLayer, using the settings serialized in the properties map (correspo...
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsMarkerLineSymbolLayer from an SLD XML DOM element.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Create a new QgsMaskMarkerSymbolLayer.
Resolves relative paths into absolute paths and vice versa.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsPointPatternFillSymbolLayer using the specified properties map containing symbol pro...
static QgsSymbolLayer * createFromSld(QDomElement &element)
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsRandomMarkerFillSymbolLayer using the specified properties map containing symbol pro...
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsRasterFillSymbolLayer from a SLD element.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsRasterFillSymbolLayer from a properties map.
static void resolvePaths(QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving)
Turns relative paths in properties map to absolute when reading and vice versa when writing.
static void resolvePaths(QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving)
Turns relative paths in properties map to absolute when reading and vice versa when writing.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsRasterLineSymbolLayer, using the settings serialized in the properties map (correspo...
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsRasterMarkerSymbolLayer from an SLD XML element.
static void resolvePaths(QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving)
Turns relative paths in properties map to absolute when reading and vice versa when writing.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a raster marker symbol layer from a string map of properties.
A container for the context for various read/write operations on objects.
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsSVGFillSymbolLayer from a SLD element.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsSVGFillSymbolLayer from a properties map.
static void resolvePaths(QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving)
Turns relative paths in properties map to absolute when reading and vice versa when writing.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsShapeburstFillSymbolLayer using the specified properties map containing symbol prope...
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsSimpleFillSymbolLayer using the specified properties map containing symbol propertie...
static QgsSymbolLayer * createFromSld(QDomElement &element)
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsSimpleLineSymbolLayer, using the settings serialized in the properties map (correspo...
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsSimpleLineSymbolLayer from an SLD XML DOM element.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsSimpleMarkerSymbolLayer.
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsSimpleMarkerSymbolLayer from an SLD XML element.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates the symbol.
static QgsSymbolLayer * createFromSld(QDomElement &element)
static void resolvePaths(QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving)
Turns relative paths in properties map to absolute when reading and vice versa when writing.
Stores metadata about one symbol layer class.
Convenience metadata class that uses static functions to create symbol layer and its widget.
std::unique_ptr< QgsSymbolLayer > createSymbolLayerFromSld(const QString &name, QDomElement &element) const
create a new instance of symbol layer given symbol layer name and SLD
static std::unique_ptr< QgsSymbolLayer > defaultSymbolLayer(Qgis::SymbolType type)
create a new instance of symbol layer for specified symbol type with default settings
bool addSymbolLayerType(QgsSymbolLayerAbstractMetadata *metadata)
Registers a new symbol layer type. Takes ownership of the metadata instance.
QStringList symbolLayersForType(Qgis::SymbolType type)
Returns a list of available symbol layers for a specified symbol type.
void resolvePaths(const QString &name, QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving) const
Resolve paths in properties of a particular symbol layer.
void resolveFonts(const QString &name, QVariantMap &properties, const QgsReadWriteContext &context) const
Resolve fonts from the properties of a particular symbol layer.
QgsSymbolLayerAbstractMetadata * symbolLayerMetadata(const QString &name) const
Returns metadata for specified symbol layer. Returns nullptr if not found.
bool removeSymbolLayerType(QgsSymbolLayerAbstractMetadata *metadata)
Removes a symbol layer type.
std::unique_ptr< QgsSymbolLayer > createSymbolLayer(const QString &name, const QVariantMap &properties=QVariantMap()) const
create a new instance of symbol layer given symbol layer name and properties
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates the symbol layer.