QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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"
26 
28 {
29  // init registry with known symbol layers
30  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "SimpleLine" ), QObject::tr( "Simple line" ), QgsSymbol::Line,
32  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "MarkerLine" ), QObject::tr( "Marker line" ), QgsSymbol::Line,
34  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "HashLine" ), QObject::tr( "Hashed line" ), QgsSymbol::Line,
36  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "ArrowLine" ), QObject::tr( "Arrow" ), QgsSymbol::Line, QgsArrowSymbolLayer::create ) );
37 
38  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "SimpleMarker" ), QObject::tr( "Simple marker" ), QgsSymbol::Marker,
40  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "FilledMarker" ), QObject::tr( "Filled marker" ), QgsSymbol::Marker,
42  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "SvgMarker" ), QObject::tr( "SVG marker" ), QgsSymbol::Marker,
44  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "RasterMarker" ), QObject::tr( "Raster image marker" ), QgsSymbol::Marker,
46  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "FontMarker" ), QObject::tr( "Font marker" ), QgsSymbol::Marker,
48  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "EllipseMarker" ), QObject::tr( "Ellipse marker" ), QgsSymbol::Marker,
50  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "VectorField" ), QObject::tr( "Vector field marker" ), QgsSymbol::Marker,
52  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "MaskMarker" ), QObject::tr( "Mask" ), QgsSymbol::Marker,
54 
55  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "SimpleFill" ), QObject::tr( "Simple fill" ), QgsSymbol::Fill,
57  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "GradientFill" ), QObject::tr( "Gradient fill" ), QgsSymbol::Fill,
59  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "ShapeburstFill" ), QObject::tr( "Shapeburst fill" ), QgsSymbol::Fill,
61  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "RasterFill" ), QObject::tr( "Raster image fill" ), QgsSymbol::Fill,
63  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "SVGFill" ), QObject::tr( "SVG fill" ), QgsSymbol::Fill,
65  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "CentroidFill" ), QObject::tr( "Centroid fill" ), QgsSymbol::Fill,
67  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "RandomMarkerFill" ), QObject::tr( "Random marker fill" ), QgsSymbol::Fill,
69  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "LinePatternFill" ), QObject::tr( "Line pattern fill" ), QgsSymbol::Fill,
71  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "PointPatternFill" ), QObject::tr( "Point pattern fill" ), QgsSymbol::Fill,
73 
74  addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "GeometryGenerator" ), QObject::tr( "Geometry generator" ), QgsSymbol::Hybrid,
76 }
77 
79 {
80  qDeleteAll( mMetadata );
81 }
82 
84 {
85  if ( !metadata || mMetadata.contains( metadata->name() ) )
86  return false;
87 
88  mMetadata[metadata->name()] = metadata;
89  return true;
90 }
91 
92 
94 {
95  return mMetadata.value( name );
96 }
97 
99 {
100  switch ( type )
101  {
102  case QgsSymbol::Marker:
104 
105  case QgsSymbol::Line:
107 
108  case QgsSymbol::Fill:
110 
111  case QgsSymbol::Hybrid:
112  return nullptr;
113  }
114 
115  return nullptr;
116 }
117 
118 
119 QgsSymbolLayer *QgsSymbolLayerRegistry::createSymbolLayer( const QString &name, const QgsStringMap &properties ) const
120 {
121  if ( !mMetadata.contains( name ) )
122  return nullptr;
123 
124  return mMetadata[name]->createSymbolLayer( properties );
125 }
126 
127 QgsSymbolLayer *QgsSymbolLayerRegistry::createSymbolLayerFromSld( const QString &name, QDomElement &element ) const
128 {
129  if ( !mMetadata.contains( name ) )
130  return nullptr;
131 
132  return mMetadata[name]->createSymbolLayerFromSld( element );
133 }
134 
135 void QgsSymbolLayerRegistry::resolvePaths( const QString &name, QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving ) const
136 {
137  if ( !mMetadata.contains( name ) )
138  return;
139 
140  mMetadata[name]->resolvePaths( properties, pathResolver, saving );
141 }
142 
144 {
145  QStringList lst;
146  QMap<QString, QgsSymbolLayerAbstractMetadata *>::ConstIterator it = mMetadata.constBegin();
147  for ( ; it != mMetadata.constEnd(); ++it )
148  {
149  if ( it.value()->type() == type || it.value()->type() == QgsSymbol::Hybrid )
150  lst.append( it.key() );
151  }
152  return lst;
153 }
QgsSimpleFillSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Definition: qgsfillsymbollayer.cpp:396
QgsSimpleFillSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsSimpleFillSymbolLayer using the specified properties map containing symbol propertie...
Definition: qgsfillsymbollayer.cpp:150
QgsMarkerLineSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsMarkerLineSymbolLayer from an SLD XML DOM element.
Definition: qgslinesymbollayer.cpp:1898
QgsLinePatternFillSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsLinePatternFillSymbolLayer from a SLD element.
Definition: qgsfillsymbollayer.cpp:2949
QgsSymbolLayerAbstractMetadata
Definition: qgssymbollayerregistry.h:34
QgsArrowSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Create a new QgsArrowSymbolLayer.
Definition: qgsarrowsymbollayer.cpp:39
QgsSymbolLayerAbstractMetadata::name
QString name() const
Definition: qgssymbollayerregistry.h:45
QgsRasterFillSymbolLayer::resolvePaths
static void resolvePaths(QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving)
Turns relative paths in properties map to absolute when reading and vice versa when writing.
Definition: qgsfillsymbollayer.cpp:4003
QgsSimpleLineSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsSimpleLineSymbolLayer, using the settings serialized in the properties map (correspo...
Definition: qgslinesymbollayer.cpp:81
QgsMaskMarkerSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Create a new QgsMaskMarkerSymbolLayer.
Definition: qgsmasksymbollayer.cpp:39
QgsMarkerLineSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsMarkerLineSymbolLayer, using the settings serialized in the properties map (correspo...
Definition: qgslinesymbollayer.cpp:1764
QgsSymbolLayerRegistry::resolvePaths
void resolvePaths(const QString &name, QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving) const
Resolve paths in properties of a particular symbol layer.
Definition: qgssymbollayerregistry.cpp:135
QgsFilledMarkerSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsFilledMarkerSymbolLayer.
Definition: qgsmarkersymbollayer.cpp:1553
QgsRandomMarkerFillSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsRandomMarkerFillSymbolLayer using the specified properties map containing symbol pro...
Definition: qgsfillsymbollayer.cpp:4216
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:127
QgsCentroidFillSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsCentroidFillSymbolLayer using the specified properties map containing symbol propert...
Definition: qgsfillsymbollayer.cpp:3646
QgsSimpleLineSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsSimpleLineSymbolLayer from an SLD XML DOM element.
Definition: qgslinesymbollayer.cpp:468
QgsSimpleMarkerSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsSimpleMarkerSymbolLayer.
Definition: qgsmarkersymbollayer.cpp:715
QgsSymbolLayerRegistry::addSymbolLayerType
bool addSymbolLayerType(QgsSymbolLayerAbstractMetadata *metadata)
register a new symbol layer type. Takes ownership of the metadata instance.
Definition: qgssymbollayerregistry.cpp:83
QgsSvgMarkerSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Definition: qgsmarkersymbollayer.cpp:2353
QgsSVGFillSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsSVGFillSymbolLayer from a properties map.
Definition: qgsfillsymbollayer.cpp:1822
QgsSvgMarkerSymbolLayer::resolvePaths
static void resolvePaths(QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving)
Turns relative paths in properties map to absolute when reading and vice versa when writing.
Definition: qgsmarkersymbollayer.cpp:1895
QgsVectorFieldSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Definition: qgsvectorfieldsymbollayer.cpp:58
QgsSymbolLayer
Definition: qgssymbollayer.h:52
QgsEllipseSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Definition: qgsellipsesymbollayer.cpp:417
qgsarrowsymbollayer.h
QgsFontMarkerSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsFontMarkerSymbolLayer from an SLD XML element.
Definition: qgsmarkersymbollayer.cpp:3444
qgssymbollayerregistry.h
QgsRasterFillSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsRasterFillSymbolLayer from a properties map.
Definition: qgsfillsymbollayer.cpp:3942
QgsSvgMarkerSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Definition: qgsmarkersymbollayer.cpp:1760
qgsmasksymbollayer.h
QgsSymbolLayerMetadata
Definition: qgssymbollayerregistry.h:86
QgsSymbol::Fill
@ Fill
Fill symbol.
Definition: qgssymbol.h:89
qgsfillsymbollayer.h
QgsSymbolLayerRegistry::symbolLayersForType
QStringList symbolLayersForType(QgsSymbol::SymbolType type)
Returns a list of available symbol layers for a specified symbol type.
Definition: qgssymbollayerregistry.cpp:143
qgsvectorfieldsymbollayer.h
QgsSymbolLayerRegistry::createSymbolLayer
QgsSymbolLayer * createSymbolLayer(const QString &name, const QgsStringMap &properties=QgsStringMap()) const
create a new instance of symbol layer given symbol layer name and properties
Definition: qgssymbollayerregistry.cpp:119
QgsSymbolLayerRegistry::defaultSymbolLayer
static QgsSymbolLayer * defaultSymbolLayer(QgsSymbol::SymbolType type)
create a new instance of symbol layer for specified symbol type with default settings
Definition: qgssymbollayerregistry.cpp:98
QgsSimpleMarkerSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsSimpleMarkerSymbolLayer from an SLD XML element.
Definition: qgsmarkersymbollayer.cpp:1194
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:714
QgsFontMarkerSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsFontMarkerSymbolLayer from a property map (see properties())
Definition: qgsmarkersymbollayer.cpp:3009
qgslinesymbollayer.h
QgsSVGFillSymbolLayer::resolvePaths
static void resolvePaths(QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving)
Turns relative paths in properties map to absolute when reading and vice versa when writing.
Definition: qgsfillsymbollayer.cpp:1924
qgsellipsesymbollayer.h
QgsSymbolLayerRegistry::~QgsSymbolLayerRegistry
~QgsSymbolLayerRegistry()
Definition: qgssymbollayerregistry.cpp:78
QgsSymbol::Line
@ Line
Line symbol.
Definition: qgssymbol.h:88
QgsHashedLineSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsHashedLineSymbolLayer, using the settings serialized in the properties map (correspo...
Definition: qgslinesymbollayer.cpp:2068
QgsSymbol::Marker
@ Marker
Marker symbol.
Definition: qgssymbol.h:87
QgsEllipseSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Definition: qgsellipsesymbollayer.cpp:46
QgsGradientFillSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsGradientFillSymbolLayer using the specified properties map containing symbol propert...
Definition: qgsfillsymbollayer.cpp:504
QgsSymbol::SymbolType
SymbolType
Type of the symbol.
Definition: qgssymbol.h:85
QgsSymbolLayerRegistry::QgsSymbolLayerRegistry
QgsSymbolLayerRegistry()
Definition: qgssymbollayerregistry.cpp:27
QgsGeometryGeneratorSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties)
Definition: qgsgeometrygeneratorsymbollayer.cpp:21
qgsgeometrygeneratorsymbollayer.h
QgsSymbol::Hybrid
@ Hybrid
Hybrid symbol.
Definition: qgssymbol.h:90
QgsPointPatternFillSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Definition: qgsfillsymbollayer.cpp:3531
QgsSVGFillSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsSVGFillSymbolLayer from a SLD element.
Definition: qgsfillsymbollayer.cpp:2129
QgsPathResolver
Definition: qgspathresolver.h:31
QgsRasterMarkerSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a raster marker symbol layer from a string map of properties.
Definition: qgsmarkersymbollayer.cpp:2606
QgsCentroidFillSymbolLayer::createFromSld
static QgsSymbolLayer * createFromSld(QDomElement &element)
Definition: qgsfillsymbollayer.cpp:3844
QgsPointPatternFillSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsPointPatternFillSymbolLayer using the specified properties map containing symbol pro...
Definition: qgsfillsymbollayer.cpp:3091
QgsLinePatternFillSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsLinePatternFillSymbolLayer from a properties map.
Definition: qgsfillsymbollayer.cpp:2418
QgsShapeburstFillSymbolLayer::create
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsShapeburstFillSymbolLayer using the specified properties map containing symbol prope...
Definition: qgsfillsymbollayer.cpp:982
QgsSymbolLayerRegistry::symbolLayerMetadata
QgsSymbolLayerAbstractMetadata * symbolLayerMetadata(const QString &name) const
Returns metadata for specified symbol layer. Returns nullptr if not found.
Definition: qgssymbollayerregistry.cpp:93