QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
50  virtual QgsSymbolLayer *createSymbolLayer( const QgsStringMap &map ) = 0 SIP_FACTORY;
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 
152  QgsSymbolLayerRegistry( const QgsSymbolLayerRegistry &rh ) = delete;
154  QgsSymbolLayerRegistry &operator=( const QgsSymbolLayerRegistry &rh ) = delete;
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
QgsSymbolLayerCreateFromSldFunc createFromSldFunction() const
Stores metadata about one symbol layer class.
QgsSymbolLayer * createSymbolLayerFromSld(QDomElement &elem) override
Create a symbol layer of this type given the map of properties.
void setWidgetFunction(QgsSymbolLayerWidgetFunc f)
QgsSymbolLayerCreateFunc createFunction() const
QgsSymbolLayer * createSymbolLayer(const QgsStringMap &map) override
Create a symbol layer of this type given the map of properties.
QgsSymbolLayerWidgetFunc mWidgetFunc
QgsSymbolLayerPathResolverFunc pathResolverFunction() const
QMap< QString, QString > QgsStringMap
Definition: qgis.h:577
SymbolType
Type of the symbol.
Definition: qgssymbol.h:83
Convenience metadata class that uses static functions to create symbol layer and its widget...
QgsSymbolLayerCreateFromSldFunc mCreateFromSldFunc
Registry of available symbol layer classes.
#define SIP_SKIP
Definition: qgis_sip.h:119
QgsSymbolLayerAbstractMetadata(const QString &name, const QString &visibleName, QgsSymbol::SymbolType type)
virtual QgsSymbolLayer * createSymbolLayerFromSld(QDomElement &)
Create a symbol layer of this type given the map of properties.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
void(* QgsSymbolLayerPathResolverFunc)(QgsStringMap &, const QgsPathResolver &, bool)
#define SIP_FACTORY
Definition: qgis_sip.h:69
QgsSymbolLayer *(* QgsSymbolLayerCreateFromSldFunc)(QDomElement &)
virtual void resolvePaths(QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving)
Resolve paths in symbol layer&#39;s properties (if there are any paths).
QgsSymbolLayerWidget *(* QgsSymbolLayerWidgetFunc)(QgsVectorLayer *)
QgsSymbol::SymbolType type() const
QgsSymbolLayerCreateFunc mCreateFunc
QgsSymbolLayerPathResolverFunc mPathResolverFunc
QgsSymbolLayerMetadata(const QString &name, const QString &visibleName, QgsSymbol::SymbolType type, QgsSymbolLayerCreateFunc pfCreate, QgsSymbolLayerCreateFromSldFunc pfCreateFromSld=nullptr, QgsSymbolLayerPathResolverFunc pfPathResolver=nullptr, QgsSymbolLayerWidgetFunc pfWidget=nullptr)
QgsSymbolLayerWidgetFunc widgetFunction() const
QgsSymbolLayerWidget * createSymbolLayerWidget(QgsVectorLayer *vl) override
Create widget for symbol layer of this type. Can return NULL if there&#39;s no GUI.
void resolvePaths(QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving) override
Resolve paths in symbol layer&#39;s properties (if there are any paths).
#define SIP_EXTERNAL
Definition: qgis_sip.h:109
QgsSymbolLayer *(* QgsSymbolLayerCreateFunc)(const QgsStringMap &)
Resolves relative paths into absolute paths and vice versa.
Represents a vector layer which manages a vector based data sets.
virtual QgsSymbolLayerWidget * createSymbolLayerWidget(QgsVectorLayer *)
Create widget for symbol layer of this type. Can return NULL if there&#39;s no GUI.