QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
16 #include "qgssymbollayerregistry.h"
17 
18 #include "qgsarrowsymbollayer.h"
19 #include "qgsellipsesymbollayer.h"
20 #include "qgsmarkersymbollayer.h"
21 #include "qgslinesymbollayer.h"
22 #include "qgsfillsymbollayer.h"
24 #include "qgsmasksymbollayer.h"
27 
29 {
30  // init registry with known symbol layers
31  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "SimpleLine" ), QObject::tr( "Simple Line" ), Qgis::SymbolType::Line,
33  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "MarkerLine" ), QObject::tr( "Marker Line" ), Qgis::SymbolType::Line,
35  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "HashLine" ), QObject::tr( "Hashed Line" ), Qgis::SymbolType::Line,
37  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "ArrowLine" ), QObject::tr( "Arrow" ), Qgis::SymbolType::Line,
39  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "InterpolatedLine" ), QObject::tr( "Interpolated Line" ), Qgis::SymbolType::Line,
41  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "RasterLine" ), QObject::tr( "Raster Line" ), Qgis::SymbolType::Line,
43  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "Lineburst" ), QObject::tr( "Lineburst" ), Qgis::SymbolType::Line,
45 
46  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "SimpleMarker" ), QObject::tr( "Simple Marker" ), Qgis::SymbolType::Marker,
48  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "FilledMarker" ), QObject::tr( "Filled Marker" ), Qgis::SymbolType::Marker,
50  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "SvgMarker" ), QObject::tr( "SVG Marker" ), Qgis::SymbolType::Marker,
52  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "RasterMarker" ), QObject::tr( "Raster Image Marker" ), Qgis::SymbolType::Marker,
54  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "AnimatedMarker" ), QObject::tr( "Animated Marker" ), Qgis::SymbolType::Marker,
56  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "FontMarker" ), QObject::tr( "Font Marker" ), Qgis::SymbolType::Marker,
58  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "EllipseMarker" ), QObject::tr( "Ellipse Marker" ), Qgis::SymbolType::Marker,
60  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "VectorField" ), QObject::tr( "Vector Field Marker" ), Qgis::SymbolType::Marker,
62  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "MaskMarker" ), QObject::tr( "Mask" ), Qgis::SymbolType::Marker,
64 
65  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "SimpleFill" ), QObject::tr( "Simple Fill" ), Qgis::SymbolType::Fill,
67  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "GradientFill" ), QObject::tr( "Gradient Fill" ), Qgis::SymbolType::Fill,
69  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "ShapeburstFill" ), QObject::tr( "Shapeburst Fill" ), Qgis::SymbolType::Fill,
71  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "RasterFill" ), QObject::tr( "Raster Image Fill" ), Qgis::SymbolType::Fill,
73  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "SVGFill" ), QObject::tr( "SVG Fill" ), Qgis::SymbolType::Fill,
75  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "CentroidFill" ), QObject::tr( "Centroid Fill" ), Qgis::SymbolType::Fill,
77  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "RandomMarkerFill" ), QObject::tr( "Random Marker Fill" ), Qgis::SymbolType::Fill,
79  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "LinePatternFill" ), QObject::tr( "Line Pattern Fill" ), Qgis::SymbolType::Fill,
81  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "PointPatternFill" ), QObject::tr( "Point Pattern Fill" ), Qgis::SymbolType::Fill,
83 
84  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "GeometryGenerator" ), QObject::tr( "Geometry Generator" ), Qgis::SymbolType::Hybrid,
86 }
87 
89 {
90  qDeleteAll( mMetadata );
91 }
92 
94 {
95  if ( !metadata || mMetadata.contains( metadata->name() ) )
96  return false;
97 
98  mMetadata[metadata->name()] = metadata;
99  return true;
100 }
101 
103 {
104  if ( !metadata || !mMetadata.contains( metadata->name() ) )
105  return false;
106 
107  metadata = mMetadata.take( metadata->name() );
108  delete metadata;
109  return true;
110 }
111 
112 
114 {
115  return mMetadata.value( name );
116 }
117 
119 {
120  switch ( type )
121  {
124 
127 
130 
132  return nullptr;
133  }
134 
135  return nullptr;
136 }
137 
138 
139 QgsSymbolLayer *QgsSymbolLayerRegistry::createSymbolLayer( const QString &name, const QVariantMap &properties ) const
140 {
141  if ( !mMetadata.contains( name ) )
142  return nullptr;
143 
144  return mMetadata[name]->createSymbolLayer( properties );
145 }
146 
147 QgsSymbolLayer *QgsSymbolLayerRegistry::createSymbolLayerFromSld( const QString &name, QDomElement &element ) const
148 {
149  if ( !mMetadata.contains( name ) )
150  return nullptr;
151 
152  return mMetadata[name]->createSymbolLayerFromSld( element );
153 }
154 
155 void QgsSymbolLayerRegistry::resolvePaths( const QString &name, QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving ) const
156 {
157  if ( !mMetadata.contains( name ) )
158  return;
159 
160  mMetadata[name]->resolvePaths( properties, pathResolver, saving );
161 }
162 
163 void QgsSymbolLayerRegistry::resolveFonts( const QString &name, QVariantMap &properties, const QgsReadWriteContext &context ) const
164 {
165  if ( !mMetadata.contains( name ) )
166  return;
167 
168  mMetadata[name]->resolveFonts( properties, context );
169 }
170 
172 {
173  QStringList lst;
174  QMap<QString, QgsSymbolLayerAbstractMetadata *>::ConstIterator it = mMetadata.constBegin();
175  for ( ; it != mMetadata.constEnd(); ++it )
176  {
177  if ( it.value()->type() == type || it.value()->type() == Qgis::SymbolType::Hybrid )
178  lst.append( it.key() );
179  }
180  return lst;
181 }
QgsFilledMarkerSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsFilledMarkerSymbolLayer.
Definition: qgsmarkersymbollayer.cpp:1733
QgsSimpleFillSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Definition: qgsfillsymbollayer.cpp:435
QgsMarkerLineSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsMarkerLineSymbolLayer from an SLD XML DOM element.
Definition: qgslinesymbollayer.cpp:2552
QgsLinePatternFillSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsLinePatternFillSymbolLayer from a SLD element.
Definition: qgsfillsymbollayer.cpp:3370
QgsSymbolLayerAbstractMetadata
Stores metadata about one symbol layer class.
Definition: qgssymbollayerregistry.h:36
QgsSimpleFillSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsSimpleFillSymbolLayer using the specified properties map containing symbol propertie...
Definition: qgsfillsymbollayer.cpp:171
Qgis::SymbolType::Fill
@ Fill
Fill symbol.
Qgis::SymbolType::Line
@ Line
Line symbol.
QgsSymbolLayerAbstractMetadata::name
QString name() const
Definition: qgssymbollayerregistry.h:54
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsArrowSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Create a new QgsArrowSymbolLayer.
Definition: qgsarrowsymbollayer.cpp:43
QgsAnimatedMarkerSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates an animated marker symbol layer from a string map of properties.
Definition: qgsmarkersymbollayer.cpp:3777
QgsRasterLineSymbolLayer::resolvePaths
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.
Definition: qgslinesymbollayer.cpp:3402
QgsSymbolLayerRegistry::resolvePaths
void resolvePaths(const QString &name, QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving) const
Resolve paths in properties of a particular symbol layer.
Definition: qgssymbollayerregistry.cpp:155
qgsmarkersymbollayer.h
QgsSymbolLayerRegistry::createSymbolLayerFromSld
QgsSymbolLayer * createSymbolLayerFromSld(const QString &name, QDomElement &element) const
create a new instance of symbol layer given symbol layer name and SLD
Definition: qgssymbollayerregistry.cpp:147
QgsRasterFillSymbolLayer::resolvePaths
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.
Definition: qgsfillsymbollayer.cpp:4755
QgsSimpleLineSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsSimpleLineSymbolLayer from an SLD XML DOM element.
Definition: qgslinesymbollayer.cpp:621
QgsSymbolLayerRegistry::addSymbolLayerType
bool addSymbolLayerType(QgsSymbolLayerAbstractMetadata *metadata)
Registers a new symbol layer type. Takes ownership of the metadata instance.
Definition: qgssymbollayerregistry.cpp:93
QgsSvgMarkerSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Definition: qgsmarkersymbollayer.cpp:2536
QgsSimpleLineSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsSimpleLineSymbolLayer, using the settings serialized in the properties map (correspo...
Definition: qgslinesymbollayer.cpp:100
QgsSymbolLayerRegistry::resolveFonts
void resolveFonts(const QString &name, QVariantMap &properties, const QgsReadWriteContext &context) const
Resolve fonts from the properties of a particular symbol layer.
Definition: qgssymbollayerregistry.cpp:163
QgsSimpleMarkerSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsSimpleMarkerSymbolLayer.
Definition: qgsmarkersymbollayer.cpp:851
QgsSymbolLayer
Definition: qgssymbollayer.h:54
QgsEllipseSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Definition: qgsellipsesymbollayer.cpp:482
Qgis::SymbolType
SymbolType
Symbol types.
Definition: qgis.h:205
qgsarrowsymbollayer.h
QgsFontMarkerSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsFontMarkerSymbolLayer from an SLD XML element.
Definition: qgsmarkersymbollayer.cpp:3685
QgsSymbolLayerRegistry::removeSymbolLayerType
bool removeSymbolLayerType(QgsSymbolLayerAbstractMetadata *metadata)
Removes a symbol layer type.
Definition: qgssymbollayerregistry.cpp:102
qgssymbollayerregistry.h
QgsGeometryGeneratorSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties)
Creates the symbol layer.
Definition: qgsgeometrygeneratorsymbollayer.cpp:29
QgsFontMarkerSymbolLayer::resolveFonts
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...
Definition: qgsmarkersymbollayer.cpp:3733
QgsSymbolLayerRegistry::createSymbolLayer
QgsSymbolLayer * createSymbolLayer(const QString &name, const QVariantMap &properties=QVariantMap()) const
create a new instance of symbol layer given symbol layer name and properties
Definition: qgssymbollayerregistry.cpp:139
QgsSVGFillSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsSVGFillSymbolLayer from a properties map.
Definition: qgsfillsymbollayer.cpp:1905
QgsGradientFillSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsGradientFillSymbolLayer using the specified properties map containing symbol propert...
Definition: qgsfillsymbollayer.cpp:545
qgsmasksymbollayer.h
QgsSymbolLayerRegistry::symbolLayersForType
QStringList symbolLayersForType(Qgis::SymbolType type)
Returns a list of available symbol layers for a specified symbol type.
Definition: qgssymbollayerregistry.cpp:171
QgsSymbolLayerMetadata
Convenience metadata class that uses static functions to create symbol layer and its widget.
Definition: qgssymbollayerregistry.h:110
qgsfillsymbollayer.h
QgsRasterMarkerSymbolLayer::resolvePaths
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.
Definition: qgsmarkersymbollayer.cpp:2857
QgsVectorFieldSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates the symbol layer.
Definition: qgsvectorfieldsymbollayer.cpp:63
qgsvectorfieldsymbollayer.h
QgsRasterFillSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsRasterFillSymbolLayer from a properties map.
Definition: qgsfillsymbollayer.cpp:4694
QgsHashedLineSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsHashedLineSymbolLayer, using the settings serialized in the properties map (correspo...
Definition: qgslinesymbollayer.cpp:2745
Qgis::SymbolType::Hybrid
@ Hybrid
Hybrid symbol.
QgsSimpleMarkerSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsSimpleMarkerSymbolLayer from an SLD XML element.
Definition: qgsmarkersymbollayer.cpp:1363
QgsRandomMarkerFillSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsRandomMarkerFillSymbolLayer using the specified properties map containing symbol pro...
Definition: qgsfillsymbollayer.cpp:5002
QgsFontMarkerSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsFontMarkerSymbolLayer from a property map (see properties())
Definition: qgsmarkersymbollayer.cpp:3232
qgslinesymbollayer.h
QgsSvgMarkerSymbolLayer::resolvePaths
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.
Definition: qgsmarkersymbollayer.cpp:2062
QgsInterpolatedLineSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties)
Creates the symbol layer.
Definition: qgsinterpolatedlinerenderer.cpp:822
qgsellipsesymbollayer.h
QgsSymbolLayerRegistry::~QgsSymbolLayerRegistry
~QgsSymbolLayerRegistry()
Definition: qgssymbollayerregistry.cpp:88
QgsEllipseSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates the symbol layer.
Definition: qgsellipsesymbollayer.cpp:47
qgsinterpolatedlinerenderer.h
QgsRasterLineSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsRasterLineSymbolLayer, using the settings serialized in the properties map (correspo...
Definition: qgslinesymbollayer.cpp:3317
QgsLineburstSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsLineburstSymbolLayer, using the settings serialized in the properties map (correspon...
Definition: qgslinesymbollayer.cpp:3556
QgsRasterMarkerSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a raster marker symbol layer from a string map of properties.
Definition: qgsmarkersymbollayer.cpp:2802
QgsSymbolLayerRegistry::QgsSymbolLayerRegistry
QgsSymbolLayerRegistry()
Definition: qgssymbollayerregistry.cpp:28
QgsShapeburstFillSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsShapeburstFillSymbolLayer using the specified properties map containing symbol prope...
Definition: qgsfillsymbollayer.cpp:1049
qgsgeometrygeneratorsymbollayer.h
QgsMarkerLineSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsMarkerLineSymbolLayer, using the settings serialized in the properties map (correspo...
Definition: qgslinesymbollayer.cpp:2422
QgsPointPatternFillSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsPointPatternFillSymbolLayer using the specified properties map containing symbol pro...
Definition: qgsfillsymbollayer.cpp:3537
QgsPointPatternFillSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Definition: qgsfillsymbollayer.cpp:4250
QgsCentroidFillSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsCentroidFillSymbolLayer using the specified properties map containing symbol propert...
Definition: qgsfillsymbollayer.cpp:4371
QgsSymbolLayerRegistry::defaultSymbolLayer
static QgsSymbolLayer * defaultSymbolLayer(Qgis::SymbolType type)
create a new instance of symbol layer for specified symbol type with default settings
Definition: qgssymbollayerregistry.cpp:118
QgsSVGFillSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsSVGFillSymbolLayer from a SLD element.
Definition: qgsfillsymbollayer.cpp:2314
QgsPathResolver
Resolves relative paths into absolute paths and vice versa. Used for writing.
Definition: qgspathresolver.h:31
QgsSVGFillSymbolLayer::resolvePaths
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.
Definition: qgsfillsymbollayer.cpp:2013
QgsSvgMarkerSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates the symbol.
Definition: qgsmarkersymbollayer.cpp:1962
Qgis::SymbolType::Marker
@ Marker
Marker symbol.
QgsLinePatternFillSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsLinePatternFillSymbolLayer from a properties map.
Definition: qgsfillsymbollayer.cpp:2623
QgsCentroidFillSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Definition: qgsfillsymbollayer.cpp:4579
QgsSymbolLayerRegistry::symbolLayerMetadata
QgsSymbolLayerAbstractMetadata * symbolLayerMetadata(const QString &name) const
Returns metadata for specified symbol layer. Returns nullptr if not found.
Definition: qgssymbollayerregistry.cpp:113
QgsMaskMarkerSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Create a new QgsMaskMarkerSymbolLayer.
Definition: qgsmasksymbollayer.cpp:50