QGIS API Documentation
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,
39  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "FontMarker", QObject::tr( "Font marker" ), QgsSymbolV2::Marker,
41  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "EllipseMarker", QObject::tr( "Ellipse marker" ), QgsSymbolV2::Marker,
43  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "VectorField", QObject::tr( "Vector Field marker" ), QgsSymbolV2::Marker,
45 
46  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "SimpleFill", QObject::tr( "Simple fill" ), QgsSymbolV2::Fill,
48  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "GradientFill", QObject::tr( "Gradient fill" ), QgsSymbolV2::Fill,
50  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "ShapeburstFill", QObject::tr( "Shapeburst fill" ), QgsSymbolV2::Fill,
52  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "RasterFill", QObject::tr( "Raster image fill" ), QgsSymbolV2::Fill,
56  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "CentroidFill", QObject::tr( "Centroid fill" ), QgsSymbolV2::Fill,
58  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "LinePatternFill", QObject::tr( "Line pattern fill" ), QgsSymbolV2::Fill,
60  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "PointPatternFill", QObject::tr( "Point pattern fill" ), QgsSymbolV2::Fill,
62 
63  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "GeometryGenerator", QObject::tr( "Geometry generator" ), QgsSymbolV2::Hybrid,
65 }
66 
68 {
69  qDeleteAll( mMetadata );
70 }
71 
73 {
74  if ( !metadata || mMetadata.contains( metadata->name() ) )
75  return false;
76 
77  mMetadata[metadata->name()] = metadata;
78  return true;
79 }
80 
81 
83 {
84  return mMetadata.value( name );
85 }
86 
88 {
89  static QgsSymbolLayerV2Registry mInstance;
90  return &mInstance;
91 }
92 
94 {
95  switch ( type )
96  {
99 
100  case QgsSymbolV2::Line:
102 
103  case QgsSymbolV2::Fill:
105 
106  case QgsSymbolV2::Hybrid:
107  return nullptr;
108  }
109 
110  return nullptr;
111 }
112 
113 
115 {
116  if ( !mMetadata.contains( name ) )
117  return nullptr;
118 
119  return mMetadata[name]->createSymbolLayer( properties );
120 }
121 
123 {
124  if ( !mMetadata.contains( name ) )
125  return nullptr;
126 
127  return mMetadata[name]->createSymbolLayerFromSld( element );
128 }
129 
131 {
132  QStringList lst;
134  for ( ; it != mMetadata.constEnd(); ++it )
135  {
136  if ( it.value()->type() == type || it.value()->type() == QgsSymbolV2::Hybrid )
137  lst.append( it.key() );
138  }
139  return lst;
140 }
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
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:79
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())
QString tr(const char *sourceText, const char *disambiguation, int n)
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
QMap< QString, QgsSymbolLayerV2AbstractMetadata * > mMetadata
Marker symbol.
Definition: qgssymbolv2.h:78
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 * 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.
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 * createFromSld(QDomElement &element)
QgsSymbolLayerV2 * createSymbolLayerFromSld(const QString &name, QDomElement &element) const
create a new instance of symbol layer given symbol layer name and SLD
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
SymbolType
Type of the symbol.
Definition: qgssymbolv2.h:76
const Key key(const T &value) const
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
Hybrid symbol.
Definition: qgssymbolv2.h:81
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:80
QgsSymbolLayerV2 * createSymbolLayer(const QString &name, const QgsStringMap &properties=QgsStringMap()) const
create a new instance of symbol layer given symbol layer name and properties
static QgsSymbolLayerV2 * create(const QgsStringMap &properties)
Create a new QgsArrowSymbolLayer.
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