QGIS API Documentation 4.3.0-Master (6313fb5bce0)
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
38 addSymbolLayerType( new QgsSymbolLayerMetadata( u"HashLine"_s, QObject::tr( "Hashed Line" ), Qgis::SymbolType::Line, QgsHashedLineSymbolLayer::create ) );
40 addSymbolLayerType( new QgsSymbolLayerMetadata( u"InterpolatedLine"_s, QObject::tr( "Interpolated Line" ), Qgis::SymbolType::Line, QgsInterpolatedLineSymbolLayer::create ) );
43 );
44 addSymbolLayerType( new QgsSymbolLayerMetadata( u"Lineburst"_s, QObject::tr( "Lineburst" ), Qgis::SymbolType::Line, QgsLineburstSymbolLayer::create ) );
45 addSymbolLayerType( new QgsSymbolLayerMetadata( u"FilledLine"_s, QObject::tr( "Filled Line" ), Qgis::SymbolType::Line, QgsFilledLineSymbolLayer::create ) );
46 addSymbolLayerType( new QgsSymbolLayerMetadata( u"LinearReferencing"_s, QObject::tr( "Linear Referencing" ), Qgis::SymbolType::Line, QgsLinearReferencingSymbolLayer::create ) );
47
50 );
51 addSymbolLayerType( new QgsSymbolLayerMetadata( u"FilledMarker"_s, QObject::tr( "Filled Marker" ), Qgis::SymbolType::Marker, QgsFilledMarkerSymbolLayer::create ) );
54 );
57 );
60 );
63 );
65 addSymbolLayerType( new QgsSymbolLayerMetadata( u"VectorField"_s, QObject::tr( "Vector Field Marker" ), Qgis::SymbolType::Marker, QgsVectorFieldSymbolLayer::create ) );
67
69 addSymbolLayerType( new QgsSymbolLayerMetadata( u"GradientFill"_s, QObject::tr( "Gradient Fill" ), Qgis::SymbolType::Fill, QgsGradientFillSymbolLayer::create ) );
70 addSymbolLayerType( new QgsSymbolLayerMetadata( u"ShapeburstFill"_s, QObject::tr( "Shapeburst Fill" ), Qgis::SymbolType::Fill, QgsShapeburstFillSymbolLayer::create ) );
73 );
76 );
79 );
80 addSymbolLayerType( new QgsSymbolLayerMetadata( u"RandomMarkerFill"_s, QObject::tr( "Random Marker Fill" ), Qgis::SymbolType::Fill, QgsRandomMarkerFillSymbolLayer::create ) );
83 );
86 );
87
88 addSymbolLayerType( new QgsSymbolLayerMetadata( u"GeometryGenerator"_s, QObject::tr( "Geometry Generator" ), Qgis::SymbolType::Hybrid, QgsGeometryGeneratorSymbolLayer::create ) );
89}
90
92{
93 qDeleteAll( mMetadata );
94}
95
97{
98 if ( !metadata || mMetadata.contains( metadata->name() ) )
99 return false;
100
101 mMetadata[metadata->name()] = metadata;
102 return true;
103}
104
106{
107 if ( !metadata || !mMetadata.contains( metadata->name() ) )
108 return false;
109
110 metadata = mMetadata.take( metadata->name() );
111 delete metadata;
112 return true;
113}
114
115
117{
118 return mMetadata.value( name );
119}
120
121std::unique_ptr< QgsSymbolLayer > QgsSymbolLayerRegistry::defaultSymbolLayer( Qgis::SymbolType type )
122{
123 switch ( type )
124 {
126 return std::unique_ptr< QgsSymbolLayer >( QgsSimpleMarkerSymbolLayer::create() );
127
129 return std::unique_ptr< QgsSymbolLayer >( QgsSimpleLineSymbolLayer::create() );
130
132 return std::unique_ptr< QgsSymbolLayer >( QgsSimpleFillSymbolLayer::create() );
133
135 return nullptr;
136 }
137
138 return nullptr;
139}
140
141std::unique_ptr< QgsSymbolLayer > QgsSymbolLayerRegistry::createSymbolLayer( const QString &name, const QVariantMap &properties ) const
142{
143 if ( !mMetadata.contains( name ) )
144 return nullptr;
145
146 return std::unique_ptr< QgsSymbolLayer>( mMetadata[name]->createSymbolLayer( properties ) );
147}
148
149std::unique_ptr< QgsSymbolLayer > QgsSymbolLayerRegistry::createSymbolLayerFromSld( const QString &name, QDomElement &element ) const
150{
151 if ( !mMetadata.contains( name ) )
152 return nullptr;
153
154 return std::unique_ptr< QgsSymbolLayer>( mMetadata[name]->createSymbolLayerFromSld( element ) );
155}
156
157void QgsSymbolLayerRegistry::resolvePaths( const QString &name, QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving ) const
158{
159 if ( !mMetadata.contains( name ) )
160 return;
161
162 mMetadata[name]->resolvePaths( properties, pathResolver, saving );
163}
164
165void QgsSymbolLayerRegistry::resolveFonts( const QString &name, QVariantMap &properties, const QgsReadWriteContext &context ) const
166{
167 if ( !mMetadata.contains( name ) )
168 return;
169
170 mMetadata[name]->resolveFonts( properties, context );
171}
172
174{
175 QStringList lst;
176 QMap<QString, QgsSymbolLayerAbstractMetadata *>::ConstIterator it = mMetadata.constBegin();
177 for ( ; it != mMetadata.constEnd(); ++it )
178 {
179 if ( it.value()->type() == type || it.value()->type() == Qgis::SymbolType::Hybrid )
180 lst.append( it.key() );
181 }
182 return lst;
183}
SymbolType
Symbol types.
Definition qgis.h:651
@ Marker
Marker symbol.
Definition qgis.h:652
@ Line
Line symbol.
Definition qgis.h:653
@ Fill
Fill symbol.
Definition qgis.h:654
@ Hybrid
Hybrid symbol.
Definition qgis.h:655
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates an animated marker symbol layer from a string map of properties.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Create a new QgsArrowSymbolLayer.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsCentroidFillSymbolLayer using the specified properties map containing symbol propert...
static std::unique_ptr< QgsSymbolLayer > createFromSld(QDomElement &element)
static std::unique_ptr< QgsSymbolLayer > createFromSld(QDomElement &element)
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates the symbol layer.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsFilledLineSymbolLayer, using the settings serialized in the properties map (correspo...
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsFilledMarkerSymbolLayer.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsFontMarkerSymbolLayer from a property map (see properties()).
static std::unique_ptr< QgsSymbolLayer > createFromSld(QDomElement &element)
Creates a new QgsFontMarkerSymbolLayer from an SLD XML element.
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 std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties)
Creates the symbol layer.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsGradientFillSymbolLayer using the specified properties map containing symbol propert...
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsHashedLineSymbolLayer, using the settings serialized in the properties map (correspo...
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties)
Creates the symbol layer.
static std::unique_ptr< QgsSymbolLayer > createFromSld(QDomElement &element)
Creates a new QgsLinePatternFillSymbolLayer from a SLD element.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsLinePatternFillSymbolLayer from a properties map.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsLinearReferencingSymbolLayer, using the specified properties.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsLineburstSymbolLayer, using the settings serialized in the properties map (correspon...
static std::unique_ptr< QgsSymbolLayer > createFromSld(QDomElement &element)
Creates a new QgsMarkerLineSymbolLayer from an SLD XML DOM element.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsMarkerLineSymbolLayer, using the settings serialized in the properties map (correspo...
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Create a new QgsMaskMarkerSymbolLayer.
Resolves relative paths into absolute paths and vice versa.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsPointPatternFillSymbolLayer using the specified properties map containing symbol pro...
static std::unique_ptr< QgsSymbolLayer > createFromSld(QDomElement &element)
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsRandomMarkerFillSymbolLayer using the specified properties map containing symbol pro...
static std::unique_ptr< 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 std::unique_ptr< QgsSymbolLayer > createFromSld(QDomElement &element)
Creates a new QgsRasterFillSymbolLayer from a SLD element.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsRasterLineSymbolLayer, using the settings serialized in the properties map (correspo...
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 std::unique_ptr< QgsSymbolLayer > createFromSld(QDomElement &element)
Creates a new QgsRasterMarkerSymbolLayer from an SLD XML element.
static std::unique_ptr< 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 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 std::unique_ptr< QgsSymbolLayer > createFromSld(QDomElement &element)
Creates a new QgsSVGFillSymbolLayer from a SLD element.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsSVGFillSymbolLayer from a properties map.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsShapeburstFillSymbolLayer using the specified properties map containing symbol prope...
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsSimpleFillSymbolLayer using the specified properties map containing symbol propertie...
static std::unique_ptr< QgsSymbolLayer > createFromSld(QDomElement &element)
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsSimpleLineSymbolLayer, using the settings serialized in the properties map (correspo...
static std::unique_ptr< QgsSymbolLayer > createFromSld(QDomElement &element)
Creates a new QgsSimpleLineSymbolLayer from an SLD XML DOM element.
static std::unique_ptr< QgsSymbolLayer > createFromSld(QDomElement &element)
Creates a new QgsSimpleMarkerSymbolLayer from an SLD XML element.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsSimpleMarkerSymbolLayer.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates the symbol.
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 std::unique_ptr< QgsSymbolLayer > createFromSld(QDomElement &element)
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 std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates the symbol layer.