QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgssymbollayerv2registry.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbollayerv2registry.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 "qgsmarkersymbollayerv2.h"
21 #include "qgslinesymbollayerv2.h"
22 #include "qgsfillsymbollayerv2.h"
25 
27 {
28  // init registry with known symbol layers
29  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "SimpleLine", QObject::tr( "Simple line" ), QgsSymbolV2::Line,
31  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "MarkerLine", QObject::tr( "Marker line" ), QgsSymbolV2::Line,
34 
35  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "SimpleMarker", QObject::tr( "Simple marker" ), QgsSymbolV2::Marker,
37  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "FilledMarker", QObject::tr( "Filled marker" ), QgsSymbolV2::Marker,
41  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "FontMarker", QObject::tr( "Font marker" ), QgsSymbolV2::Marker,
43  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "EllipseMarker", QObject::tr( "Ellipse marker" ), QgsSymbolV2::Marker,
45  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "VectorField", QObject::tr( "Vector field marker" ), QgsSymbolV2::Marker,
47 
48  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "SimpleFill", QObject::tr( "Simple fill" ), QgsSymbolV2::Fill,
50  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "GradientFill", QObject::tr( "Gradient fill" ), QgsSymbolV2::Fill,
52  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "ShapeburstFill", QObject::tr( "Shapeburst fill" ), QgsSymbolV2::Fill,
54  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "RasterFill", QObject::tr( "Raster image fill" ), QgsSymbolV2::Fill,
58  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "CentroidFill", QObject::tr( "Centroid fill" ), QgsSymbolV2::Fill,
60  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "LinePatternFill", QObject::tr( "Line pattern fill" ), QgsSymbolV2::Fill,
62  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "PointPatternFill", QObject::tr( "Point pattern fill" ), QgsSymbolV2::Fill,
64 
65  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "GeometryGenerator", QObject::tr( "Geometry generator" ), QgsSymbolV2::Hybrid,
67 }
68 
70 {
71  qDeleteAll( mMetadata );
72 }
73 
75 {
76  if ( !metadata || mMetadata.contains( metadata->name() ) )
77  return false;
78 
79  mMetadata[metadata->name()] = metadata;
80  return true;
81 }
82 
83 
85 {
86  return mMetadata.value( name );
87 }
88 
90 {
91  static QgsSymbolLayerV2Registry mInstance;
92  return &mInstance;
93 }
94 
96 {
97  switch ( type )
98  {
101 
102  case QgsSymbolV2::Line:
104 
105  case QgsSymbolV2::Fill:
107 
108  case QgsSymbolV2::Hybrid:
109  return nullptr;
110  }
111 
112  return nullptr;
113 }
114 
115 
117 {
118  if ( !mMetadata.contains( name ) )
119  return nullptr;
120 
121  return mMetadata[name]->createSymbolLayer( properties );
122 }
123 
125 {
126  if ( !mMetadata.contains( name ) )
127  return nullptr;
128 
129  return mMetadata[name]->createSymbolLayerFromSld( element );
130 }
131 
133 {
134  QStringList lst;
136  for ( ; it != mMetadata.constEnd(); ++it )
137  {
138  if ( it.value()->type() == type || it.value()->type() == QgsSymbolV2::Hybrid )
139  lst.append( it.key() );
140  }
141  return lst;
142 }
static QgsSymbolLayerV2 * create(const QgsStringMap &properties)
static QgsSymbolLayerV2 * defaultSymbolLayer(QgsSymbolV2::SymbolType type)
create a new instance of symbol layer for specified symbol type with default settings ...
bool contains(const Key &key) const
QgsSymbolLayerV2AbstractMetadata * symbolLayerMetadata(const QString &name) const
return metadata for specified symbol layer. Returns NULL if not found
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
const_iterator constBegin() const
Stores metadata about one symbol layer class.
Line symbol.
Definition: qgssymbolv2.h:82
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
static QgsSymbolLayerV2Registry * instance()
return the single instance of this class (instantiate it if not exists)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsSimpleMarkerSymbolLayerV2.
QString tr(const char *sourceText, const char *disambiguation, int n)
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
Creates a new QgsSimpleMarkerSymbolLayerV2 from an SLD XML element.
QMap< QString, QgsSymbolLayerV2AbstractMetadata * > mMetadata
Marker symbol.
Definition: qgssymbolv2.h:81
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
const char * name() const
void append(const T &value)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
Create a new QgsArrowSymbolLayer.
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
const_iterator constEnd() const
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
Create a new MarkerLineSymbolLayerV2 from SLD.
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
Create a new MarkerLineSymbolLayerV2.
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsFilledMarkerSymbolLayer.
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
SymbolType
Type of the symbol.
Definition: qgssymbolv2.h:79
const Key key(const T &value) const
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
Hybrid symbol.
Definition: qgssymbolv2.h:84
QStringList symbolLayersForType(QgsSymbolV2::SymbolType type)
return a list of available symbol layers for a specified symbol type
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
bool addSymbolLayerType(QgsSymbolLayerV2AbstractMetadata *metadata)
register a new symbol layer type. Takes ownership of the metadata instance.
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
Fill symbol.
Definition: qgssymbolv2.h:83
QgsSymbolLayerV2 * createSymbolLayer(const QString &name, const QgsStringMap &properties=QgsStringMap()) const
create a new instance of symbol layer given symbol layer name and properties
QgsSymbolLayerV2 * createSymbolLayerFromSld(const QString &name, QDomElement &element) const
create a new instance of symbol layer given symbol layer name and SLD
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
Registry of available symbol layer classes.
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
Convenience metadata class that uses static functions to create symbol layer and its widget...
const T value(const Key &key) const