QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgssymbollayerregistry.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbollayerregistry.h
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 #ifndef QGSSYMBOLLAYERREGISTRY_H
17 #define QGSSYMBOLLAYERREGISTRY_H
18 
19 #include "qgis_core.h"
20 #include "qgis.h"
21 #include "qgssymbol.h"
22 
23 class QgsPathResolver;
24 class QgsVectorLayer;
26 
35 {
36  public:
37  QgsSymbolLayerAbstractMetadata( const QString &name, const QString &visibleName, QgsSymbol::SymbolType type )
38  : mName( name )
39  , mVisibleName( visibleName )
40  , mType( type )
41  {}
42 
43  virtual ~QgsSymbolLayerAbstractMetadata() = default;
44 
45  QString name() const { return mName; }
46  QString visibleName() const { return mVisibleName; }
47  QgsSymbol::SymbolType type() const { return mType; }
48 
54  virtual QgsSymbolLayer *createSymbolLayerFromSld( QDomElement & ) SIP_FACTORY { return nullptr; }
55 
64  virtual void resolvePaths( QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving )
65  {
66  Q_UNUSED( properties )
67  Q_UNUSED( pathResolver )
68  Q_UNUSED( saving )
69  }
70 
71  protected:
72  QString mName;
73  QString mVisibleName;
75 };
76 
77 typedef QgsSymbolLayer *( *QgsSymbolLayerCreateFunc )( const QgsStringMap & ) SIP_SKIP;
78 typedef QgsSymbolLayerWidget *( *QgsSymbolLayerWidgetFunc )( QgsVectorLayer * ) SIP_SKIP;
79 typedef QgsSymbolLayer *( *QgsSymbolLayerCreateFromSldFunc )( QDomElement & ) SIP_SKIP;
81 
87 {
88  public:
90  QgsSymbolLayerMetadata( const QString &name, const QString &visibleName,
92  QgsSymbolLayerCreateFunc pfCreate,
93  QgsSymbolLayerCreateFromSldFunc pfCreateFromSld = nullptr,
94  QgsSymbolLayerPathResolverFunc pfPathResolver = nullptr,
95  QgsSymbolLayerWidgetFunc pfWidget = nullptr ) SIP_SKIP
96  : QgsSymbolLayerAbstractMetadata( name, visibleName, type )
97  , mCreateFunc( pfCreate )
98  , mWidgetFunc( pfWidget )
99  , mCreateFromSldFunc( pfCreateFromSld )
100  , mPathResolverFunc( pfPathResolver )
101  {}
102 
104  QgsSymbolLayerCreateFunc createFunction() const { return mCreateFunc; } SIP_SKIP
106  QgsSymbolLayerWidgetFunc widgetFunction() const { return mWidgetFunc; } SIP_SKIP
108  QgsSymbolLayerCreateFromSldFunc createFromSldFunction() const { return mCreateFromSldFunc; } SIP_SKIP
110  QgsSymbolLayerPathResolverFunc pathResolverFunction() const { return mPathResolverFunc; } SIP_SKIP
111 
113  void setWidgetFunction( QgsSymbolLayerWidgetFunc f ) { mWidgetFunc = f; } SIP_SKIP
114 
115  QgsSymbolLayer *createSymbolLayer( const QgsStringMap &map ) override SIP_FACTORY { return mCreateFunc ? mCreateFunc( map ) : nullptr; }
116  QgsSymbolLayerWidget *createSymbolLayerWidget( QgsVectorLayer *vl ) override SIP_FACTORY { return mWidgetFunc ? mWidgetFunc( vl ) : nullptr; }
117  QgsSymbolLayer *createSymbolLayerFromSld( QDomElement &elem ) override SIP_FACTORY { return mCreateFromSldFunc ? mCreateFromSldFunc( elem ) : nullptr; }
118  void resolvePaths( QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving ) override
119  {
120  if ( mPathResolverFunc )
121  mPathResolverFunc( properties, pathResolver, saving );
122  }
123 
124  protected:
129 
130  private:
131 #ifdef SIP_RUN
133 #endif
134 };
135 
136 
144 class CORE_EXPORT QgsSymbolLayerRegistry
145 {
146  public:
147 
150 
155 
157  QgsSymbolLayerAbstractMetadata *symbolLayerMetadata( const QString &name ) const;
158 
160  bool addSymbolLayerType( QgsSymbolLayerAbstractMetadata *metadata SIP_TRANSFER );
161 
163  QgsSymbolLayer *createSymbolLayer( const QString &name, const QgsStringMap &properties = QgsStringMap() ) const SIP_FACTORY;
164 
166  QgsSymbolLayer *createSymbolLayerFromSld( const QString &name, QDomElement &element ) const SIP_FACTORY;
167 
174  void resolvePaths( const QString &name, QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving ) const;
175 
177  QStringList symbolLayersForType( QgsSymbol::SymbolType type );
178 
180  static QgsSymbolLayer *defaultSymbolLayer( QgsSymbol::SymbolType type ) SIP_FACTORY;
181 
182  private:
183 #ifdef SIP_RUN
185 #endif
186 
187  QMap<QString, QgsSymbolLayerAbstractMetadata *> mMetadata;
188 };
189 
190 #endif
QgsSymbolLayerAbstractMetadata::visibleName
QString visibleName() const
Definition: qgssymbollayerregistry.h:46
QgsSymbolLayerAbstractMetadata
Stores metadata about one symbol layer class.
Definition: qgssymbollayerregistry.h:35
QgsSymbolLayerAbstractMetadata::name
QString name() const
Definition: qgssymbollayerregistry.h:45
QgsSymbolLayerMetadata::mCreateFunc
QgsSymbolLayerCreateFunc mCreateFunc
Definition: qgssymbollayerregistry.h:125
QgsSymbolLayerAbstractMetadata::mName
QString mName
Definition: qgssymbollayerregistry.h:72
QgsSymbolLayerWidget
Definition: qgssymbollayerwidget.h:35
QgsSymbolLayerMetadata::QgsSymbolLayerMetadata
QgsSymbolLayerMetadata(const QString &name, const QString &visibleName, QgsSymbol::SymbolType type, QgsSymbolLayerCreateFunc pfCreate, QgsSymbolLayerCreateFromSldFunc pfCreateFromSld=nullptr, QgsSymbolLayerPathResolverFunc pfPathResolver=nullptr, QgsSymbolLayerWidgetFunc pfWidget=nullptr)
Definition: qgssymbollayerregistry.h:90
QgsSymbolLayerAbstractMetadata::QgsSymbolLayerAbstractMetadata
QgsSymbolLayerAbstractMetadata(const QString &name, const QString &visibleName, QgsSymbol::SymbolType type)
Definition: qgssymbollayerregistry.h:37
qgis.h
QgsSymbolLayerMetadata::resolvePaths
void resolvePaths(QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving) override
Resolve paths in symbol layer's properties (if there are any paths).
Definition: qgssymbollayerregistry.h:118
QgsSymbolLayerRegistry
Registry of available symbol layer classes.
Definition: qgssymbollayerregistry.h:145
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:64
QgsSymbolLayerMetadata::createFromSldFunction
QgsSymbolLayerCreateFromSldFunc createFromSldFunction() const
Definition: qgssymbollayerregistry.h:108
QgsSymbolLayerMetadata::widgetFunction
QgsSymbolLayerWidgetFunc widgetFunction() const
Definition: qgssymbollayerregistry.h:106
QgsSymbolLayerCreateFunc
QgsSymbolLayer *(* QgsSymbolLayerCreateFunc)(const QgsStringMap &)
Definition: qgssymbollayerregistry.h:77
QgsSymbolLayerAbstractMetadata::createSymbolLayerFromSld
virtual QgsSymbolLayer * createSymbolLayerFromSld(QDomElement &)
Create a symbol layer of this type given the map of properties.
Definition: qgssymbollayerregistry.h:54
QgsSymbolLayerMetadata::mPathResolverFunc
QgsSymbolLayerPathResolverFunc mPathResolverFunc
Definition: qgssymbollayerregistry.h:128
QgsSymbolLayerMetadata::pathResolverFunction
QgsSymbolLayerPathResolverFunc pathResolverFunction() const
Definition: qgssymbollayerregistry.h:110
QgsSymbolLayerMetadata::createSymbolLayerWidget
QgsSymbolLayerWidget * createSymbolLayerWidget(QgsVectorLayer *vl) override
Create widget for symbol layer of this type. Can return nullptr if there's no GUI.
Definition: qgssymbollayerregistry.h:116
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsSymbolLayerCreateFromSldFunc
QgsSymbolLayer *(* QgsSymbolLayerCreateFromSldFunc)(QDomElement &)
Definition: qgssymbollayerregistry.h:79
QgsSymbolLayerWidgetFunc
QgsSymbolLayerWidget *(* QgsSymbolLayerWidgetFunc)(QgsVectorLayer *)
Definition: qgssymbollayerregistry.h:78
QgsSymbolLayer
Definition: qgssymbollayer.h:53
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsSymbolLayerRegistry::QgsSymbolLayerRegistry
QgsSymbolLayerRegistry(const QgsSymbolLayerRegistry &rh)=delete
QgsSymbolLayerRegistry cannot be copied.
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsSymbolLayerAbstractMetadata::type
QgsSymbol::SymbolType type() const
Definition: qgssymbollayerregistry.h:47
QgsSymbolLayerMetadata
Convenience metadata class that uses static functions to create symbol layer and its widget.
Definition: qgssymbollayerregistry.h:87
QgsSymbolLayerAbstractMetadata::resolvePaths
virtual void resolvePaths(QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving)
Resolve paths in symbol layer's properties (if there are any paths).
Definition: qgssymbollayerregistry.h:64
QgsSymbolLayerMetadata::createFunction
QgsSymbolLayerCreateFunc createFunction() const
Definition: qgssymbollayerregistry.h:104
QgsSymbolLayerMetadata::setWidgetFunction
void setWidgetFunction(QgsSymbolLayerWidgetFunc f)
Definition: qgssymbollayerregistry.h:113
QgsSymbolLayerMetadata::createSymbolLayerFromSld
QgsSymbolLayer * createSymbolLayerFromSld(QDomElement &elem) override
Create a symbol layer of this type given the map of properties.
Definition: qgssymbollayerregistry.h:117
QgsSymbolLayerAbstractMetadata::~QgsSymbolLayerAbstractMetadata
virtual ~QgsSymbolLayerAbstractMetadata()=default
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:758
QgsSymbolLayerMetadata::mWidgetFunc
QgsSymbolLayerWidgetFunc mWidgetFunc
Definition: qgssymbollayerregistry.h:126
QgsSymbolLayerAbstractMetadata::createSymbolLayerWidget
virtual QgsSymbolLayerWidget * createSymbolLayerWidget(QgsVectorLayer *)
Create widget for symbol layer of this type. Can return nullptr if there's no GUI.
Definition: qgssymbollayerregistry.h:52
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsSymbolLayerAbstractMetadata::mType
QgsSymbol::SymbolType mType
Definition: qgssymbollayerregistry.h:74
QgsSymbolLayerMetadata::createSymbolLayer
QgsSymbolLayer * createSymbolLayer(const QgsStringMap &map) override
Create a symbol layer of this type given the map of properties.
Definition: qgssymbollayerregistry.h:115
QgsSymbolLayerAbstractMetadata::mVisibleName
QString mVisibleName
Definition: qgssymbollayerregistry.h:73
QgsSymbolLayerRegistry::operator=
QgsSymbolLayerRegistry & operator=(const QgsSymbolLayerRegistry &rh)=delete
QgsSymbolLayerRegistry cannot be copied.
SIP_EXTERNAL
#define SIP_EXTERNAL
Definition: qgis_sip.h:116
QgsSymbol::SymbolType
SymbolType
Type of the symbol.
Definition: qgssymbol.h:86
QgsSymbolLayerAbstractMetadata::createSymbolLayer
virtual QgsSymbolLayer * createSymbolLayer(const QgsStringMap &map)=0
Create a symbol layer of this type given the map of properties.
QgsSymbolLayerMetadata::mCreateFromSldFunc
QgsSymbolLayerCreateFromSldFunc mCreateFromSldFunc
Definition: qgssymbollayerregistry.h:127
qgssymbol.h
QgsPathResolver
Resolves relative paths into absolute paths and vice versa.
Definition: qgspathresolver.h:32
QgsSymbolLayerPathResolverFunc
void(* QgsSymbolLayerPathResolverFunc)(QgsStringMap &, const QgsPathResolver &, bool)
Definition: qgssymbollayerregistry.h:80