QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
22 class QgsPathResolver;
23 class QgsVectorLayer;
25 class QgsSymbolLayer;
26 class QDomElement;
28 
37 {
38  public:
39 
46  QgsSymbolLayerAbstractMetadata( const QString &name, const QString &visibleName, Qgis::SymbolType type )
47  : mName( name )
48  , mVisibleName( visibleName )
49  , mType( type )
50  {}
51 
52  virtual ~QgsSymbolLayerAbstractMetadata() = default;
53 
54  QString name() const { return mName; }
55  QString visibleName() const { return mVisibleName; }
56  Qgis::SymbolType type() const { return mType; }
57 
59  virtual QgsSymbolLayer *createSymbolLayer( const QVariantMap &map ) = 0 SIP_FACTORY;
63  virtual QgsSymbolLayer *createSymbolLayerFromSld( QDomElement & ) SIP_FACTORY { return nullptr; }
64 
73  virtual void resolvePaths( QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving )
74  {
75  Q_UNUSED( properties )
76  Q_UNUSED( pathResolver )
77  Q_UNUSED( saving )
78  }
79 
88  virtual void resolveFonts( const QVariantMap &properties, const QgsReadWriteContext &context )
89  {
90  Q_UNUSED( properties )
91  Q_UNUSED( context )
92  }
93 
94  protected:
95  QString mName;
96  QString mVisibleName;
98 };
99 
100 typedef QgsSymbolLayer *( *QgsSymbolLayerCreateFunc )( const QVariantMap & ) SIP_SKIP;
101 typedef QgsSymbolLayerWidget *( *QgsSymbolLayerWidgetFunc )( QgsVectorLayer * ) SIP_SKIP;
102 typedef QgsSymbolLayer *( *QgsSymbolLayerCreateFromSldFunc )( QDomElement & ) SIP_SKIP;
103 typedef void ( *QgsSymbolLayerPathResolverFunc )( QVariantMap &, const QgsPathResolver &, bool ) SIP_SKIP;
104 typedef void ( *QgsSymbolLayerFontResolverFunc )( const QVariantMap &, const QgsReadWriteContext & ) SIP_SKIP;
105 
111 {
112  public:
114  QgsSymbolLayerMetadata( const QString &name, const QString &visibleName,
115  Qgis::SymbolType type,
116  QgsSymbolLayerCreateFunc pfCreate,
117  QgsSymbolLayerCreateFromSldFunc pfCreateFromSld = nullptr,
118  QgsSymbolLayerPathResolverFunc pfPathResolver = nullptr,
119  QgsSymbolLayerWidgetFunc pfWidget = nullptr,
120  QgsSymbolLayerFontResolverFunc pfFontResolver = nullptr ) SIP_SKIP
121  : QgsSymbolLayerAbstractMetadata( name, visibleName, type )
122  , mCreateFunc( pfCreate )
123  , mWidgetFunc( pfWidget )
124  , mCreateFromSldFunc( pfCreateFromSld )
125  , mPathResolverFunc( pfPathResolver )
126  , mFontResolverFunc( pfFontResolver )
127  {}
128 
130  QgsSymbolLayerCreateFunc createFunction() const { return mCreateFunc; } SIP_SKIP
132  QgsSymbolLayerWidgetFunc widgetFunction() const { return mWidgetFunc; } SIP_SKIP
134  QgsSymbolLayerCreateFromSldFunc createFromSldFunction() const { return mCreateFromSldFunc; } SIP_SKIP
136  QgsSymbolLayerPathResolverFunc pathResolverFunction() const { return mPathResolverFunc; } SIP_SKIP
137 
139  void setWidgetFunction( QgsSymbolLayerWidgetFunc f ) { mWidgetFunc = f; } SIP_SKIP
140 
141  QgsSymbolLayer *createSymbolLayer( const QVariantMap &map ) override SIP_FACTORY { return mCreateFunc ? mCreateFunc( map ) : nullptr; }
142  QgsSymbolLayerWidget *createSymbolLayerWidget( QgsVectorLayer *vl ) override SIP_FACTORY { return mWidgetFunc ? mWidgetFunc( vl ) : nullptr; }
143  QgsSymbolLayer *createSymbolLayerFromSld( QDomElement &elem ) override SIP_FACTORY { return mCreateFromSldFunc ? mCreateFromSldFunc( elem ) : nullptr; }
144  void resolvePaths( QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving ) override
145  {
146  if ( mPathResolverFunc )
147  mPathResolverFunc( properties, pathResolver, saving );
148  }
149 
150  void resolveFonts( const QVariantMap &properties, const QgsReadWriteContext &context ) override
151  {
152  if ( mFontResolverFunc )
153  mFontResolverFunc( properties, context );
154  }
155 
156  protected:
161 
168 
169  private:
170 #ifdef SIP_RUN
172 #endif
173 };
174 
175 
183 class CORE_EXPORT QgsSymbolLayerRegistry
184 {
185  public:
186 
189 
191  QgsSymbolLayerRegistry( const QgsSymbolLayerRegistry &rh ) = delete;
193  QgsSymbolLayerRegistry &operator=( const QgsSymbolLayerRegistry &rh ) = delete;
194 
196  QgsSymbolLayerAbstractMetadata *symbolLayerMetadata( const QString &name ) const;
197 
199  bool addSymbolLayerType( QgsSymbolLayerAbstractMetadata *metadata SIP_TRANSFER );
200 
205  bool removeSymbolLayerType( QgsSymbolLayerAbstractMetadata *metadata );
206 
208  QgsSymbolLayer *createSymbolLayer( const QString &name, const QVariantMap &properties = QVariantMap() ) const SIP_FACTORY;
209 
211  QgsSymbolLayer *createSymbolLayerFromSld( const QString &name, QDomElement &element ) const SIP_FACTORY;
212 
219  void resolvePaths( const QString &name, QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving ) const;
220 
229  void resolveFonts( const QString &name, QVariantMap &properties, const QgsReadWriteContext &context ) const;
230 
232  QStringList symbolLayersForType( Qgis::SymbolType type );
233 
235  static QgsSymbolLayer *defaultSymbolLayer( Qgis::SymbolType type ) SIP_FACTORY;
236 
237  private:
238 #ifdef SIP_RUN
240 #endif
241 
242  QMap<QString, QgsSymbolLayerAbstractMetadata *> mMetadata;
243 };
244 
245 #endif
QgsSymbolLayerAbstractMetadata::visibleName
QString visibleName() const
Definition: qgssymbollayerregistry.h:55
QgsSymbolLayerAbstractMetadata
Stores metadata about one symbol layer class.
Definition: qgssymbollayerregistry.h:36
QgsSymbolLayerMetadata::createSymbolLayer
QgsSymbolLayer * createSymbolLayer(const QVariantMap &map) override
Create a symbol layer of this type given the map of properties.
Definition: qgssymbollayerregistry.h:141
QgsSymbolLayerPathResolverFunc
void(* QgsSymbolLayerPathResolverFunc)(QVariantMap &, const QgsPathResolver &, bool)
Definition: qgssymbollayerregistry.h:103
QgsSymbolLayerAbstractMetadata::name
QString name() const
Definition: qgssymbollayerregistry.h:54
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsSymbolLayerMetadata::mCreateFunc
QgsSymbolLayerCreateFunc mCreateFunc
Definition: qgssymbollayerregistry.h:157
QgsSymbolLayerAbstractMetadata::QgsSymbolLayerAbstractMetadata
QgsSymbolLayerAbstractMetadata(const QString &name, const QString &visibleName, Qgis::SymbolType type)
Constructor for QgsSymbolLayerAbstractMetadata.
Definition: qgssymbollayerregistry.h:46
QgsSymbolLayerAbstractMetadata::mName
QString mName
Definition: qgssymbollayerregistry.h:95
QgsSymbolLayerWidget
Definition: qgssymbollayerwidget.h:37
QgsSymbolLayerAbstractMetadata::resolvePaths
virtual void resolvePaths(QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving)
Resolve paths in symbol layer's properties (if there are any paths).
Definition: qgssymbollayerregistry.h:73
qgis.h
QgsSymbolLayerRegistry
Registry of available symbol layer classes.
Definition: qgssymbollayerregistry.h:183
QgsSymbolLayerMetadata::createFromSldFunction
QgsSymbolLayerCreateFromSldFunc createFromSldFunction() const
Definition: qgssymbollayerregistry.h:134
QgsSymbolLayerMetadata::widgetFunction
QgsSymbolLayerWidgetFunc widgetFunction() const
Definition: qgssymbollayerregistry.h:132
QgsSymbolLayerAbstractMetadata::createSymbolLayerFromSld
virtual QgsSymbolLayer * createSymbolLayerFromSld(QDomElement &)
Create a symbol layer of this type given the map of properties.
Definition: qgssymbollayerregistry.h:63
QgsSymbolLayerMetadata::mPathResolverFunc
QgsSymbolLayerPathResolverFunc mPathResolverFunc
Definition: qgssymbollayerregistry.h:160
QgsSymbolLayerAbstractMetadata::type
Qgis::SymbolType type() const
Definition: qgssymbollayerregistry.h:56
QgsSymbolLayerMetadata::pathResolverFunction
QgsSymbolLayerPathResolverFunc pathResolverFunction() const
Definition: qgssymbollayerregistry.h:136
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:142
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsSymbolLayerCreateFromSldFunc
QgsSymbolLayer *(* QgsSymbolLayerCreateFromSldFunc)(QDomElement &)
Definition: qgssymbollayerregistry.h:102
QgsSymbolLayerWidgetFunc
QgsSymbolLayerWidget *(* QgsSymbolLayerWidgetFunc)(QgsVectorLayer *)
Definition: qgssymbollayerregistry.h:101
QgsSymbolLayer
Definition: qgssymbollayer.h:54
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
Qgis::SymbolType
SymbolType
Symbol types.
Definition: qgis.h:205
QgsSymbolLayerAbstractMetadata::resolveFonts
virtual void resolveFonts(const QVariantMap &properties, const QgsReadWriteContext &context)
Resolve fonts from the symbol layer's properties.
Definition: qgssymbollayerregistry.h:88
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsSymbolLayerMetadata
Convenience metadata class that uses static functions to create symbol layer and its widget.
Definition: qgssymbollayerregistry.h:110
QgsSymbolLayerMetadata::resolvePaths
void resolvePaths(QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving) override
Resolve paths in symbol layer's properties (if there are any paths).
Definition: qgssymbollayerregistry.h:144
QgsSymbolLayerMetadata::createFunction
QgsSymbolLayerCreateFunc createFunction() const
Definition: qgssymbollayerregistry.h:130
QgsSymbolLayerMetadata::setWidgetFunction
void setWidgetFunction(QgsSymbolLayerWidgetFunc f)
Definition: qgssymbollayerregistry.h:139
QgsSymbolLayerMetadata::createSymbolLayerFromSld
QgsSymbolLayer * createSymbolLayerFromSld(QDomElement &elem) override
Create a symbol layer of this type given the map of properties.
Definition: qgssymbollayerregistry.h:143
QgsSymbolLayerMetadata::mWidgetFunc
QgsSymbolLayerWidgetFunc mWidgetFunc
Definition: qgssymbollayerregistry.h:158
QgsSymbolLayerMetadata::QgsSymbolLayerMetadata
QgsSymbolLayerMetadata(const QString &name, const QString &visibleName, Qgis::SymbolType type, QgsSymbolLayerCreateFunc pfCreate, QgsSymbolLayerCreateFromSldFunc pfCreateFromSld=nullptr, QgsSymbolLayerPathResolverFunc pfPathResolver=nullptr, QgsSymbolLayerWidgetFunc pfWidget=nullptr, QgsSymbolLayerFontResolverFunc pfFontResolver=nullptr)
Definition: qgssymbollayerregistry.h:114
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:61
QgsSymbolLayerMetadata::mFontResolverFunc
QgsSymbolLayerFontResolverFunc mFontResolverFunc
Font resolver function pointer.
Definition: qgssymbollayerregistry.h:167
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsSymbolLayerAbstractMetadata::mVisibleName
QString mVisibleName
Definition: qgssymbollayerregistry.h:96
SIP_EXTERNAL
#define SIP_EXTERNAL
Definition: qgis_sip.h:116
QgsSymbolLayerMetadata::mCreateFromSldFunc
QgsSymbolLayerCreateFromSldFunc mCreateFromSldFunc
Definition: qgssymbollayerregistry.h:159
QgsSymbolLayerMetadata::resolveFonts
void resolveFonts(const QVariantMap &properties, const QgsReadWriteContext &context) override
Resolve fonts from the symbol layer's properties.
Definition: qgssymbollayerregistry.h:150
QgsSymbolLayerCreateFunc
QgsSymbolLayer *(* QgsSymbolLayerCreateFunc)(const QVariantMap &)
Definition: qgssymbollayerregistry.h:100
QgsSymbolLayerFontResolverFunc
void(* QgsSymbolLayerFontResolverFunc)(const QVariantMap &, const QgsReadWriteContext &)
Definition: qgssymbollayerregistry.h:104
QgsPathResolver
Resolves relative paths into absolute paths and vice versa. Used for writing.
Definition: qgspathresolver.h:31
QgsSymbolLayerAbstractMetadata::mType
Qgis::SymbolType mType
Definition: qgssymbollayerregistry.h:97