QGIS API Documentation  2.15.0-Master (972fc9f)
qgssymbollayerv2registry.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbollayerv2registry.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 QGSSYMBOLLAYERV2REGISTRY_H
17 #define QGSSYMBOLLAYERV2REGISTRY_H
18 
19 #include "qgssymbolv2.h"
20 #include "qgssymbollayerv2.h"
21 
22 class QgsVectorLayer;
23 
31 {
32  public:
34  : mName( name )
35  , mVisibleName( visibleName )
36  , mType( type )
37  {}
38 
40 
41  QString name() const { return mName; }
42  QString visibleName() const { return mVisibleName; }
43  QgsSymbolV2::SymbolType type() const { return mType; }
44 
46  virtual QgsSymbolLayerV2* createSymbolLayer( const QgsStringMap& map ) = 0;
48  virtual QgsSymbolLayerV2Widget* createSymbolLayerWidget( const QgsVectorLayer * ) { return nullptr; }
50  virtual QgsSymbolLayerV2* createSymbolLayerFromSld( QDomElement & ) { return nullptr; }
51 
52 
53  protected:
57 };
58 
59 typedef QgsSymbolLayerV2*( *QgsSymbolLayerV2CreateFunc )( const QgsStringMap& );
60 typedef QgsSymbolLayerV2Widget*( *QgsSymbolLayerV2WidgetFunc )( const QgsVectorLayer* );
61 typedef QgsSymbolLayerV2*( *QgsSymbolLayerV2CreateFromSldFunc )( QDomElement& );
62 
67 {
68  public:
70  QgsSymbolLayerV2Metadata( const QString& name, const QString& visibleName,
73  QgsSymbolLayerV2WidgetFunc pfWidget = nullptr )
74  : QgsSymbolLayerV2AbstractMetadata( name, visibleName, type )
75  , mCreateFunc( pfCreate )
76  , mWidgetFunc( pfWidget )
77  , mCreateFromSldFunc( nullptr )
78  {}
79 
81  QgsSymbolLayerV2Metadata( const QString& name, const QString& visibleName,
84  QgsSymbolLayerV2CreateFromSldFunc pfCreateFromSld,
85  QgsSymbolLayerV2WidgetFunc pfWidget = nullptr )
86  : QgsSymbolLayerV2AbstractMetadata( name, visibleName, type )
87  , mCreateFunc( pfCreate )
88  , mWidgetFunc( pfWidget )
89  , mCreateFromSldFunc( pfCreateFromSld )
90  {}
91 
93  QgsSymbolLayerV2CreateFunc createFunction() const { return mCreateFunc; }
95  QgsSymbolLayerV2WidgetFunc widgetFunction() const { return mWidgetFunc; }
97  QgsSymbolLayerV2CreateFromSldFunc createFromSldFunction() const { return mCreateFromSldFunc; }
98 
100  void setWidgetFunction( QgsSymbolLayerV2WidgetFunc f ) { mWidgetFunc = f; }
101 
102  virtual QgsSymbolLayerV2* createSymbolLayer( const QgsStringMap& map ) override { return mCreateFunc ? mCreateFunc( map ) : nullptr; }
103  virtual QgsSymbolLayerV2Widget* createSymbolLayerWidget( const QgsVectorLayer* vl ) override { return mWidgetFunc ? mWidgetFunc( vl ) : nullptr; }
104  virtual QgsSymbolLayerV2* createSymbolLayerFromSld( QDomElement& elem ) override { return mCreateFromSldFunc ? mCreateFromSldFunc( elem ) : nullptr; }
105 
106  protected:
110 };
111 
112 
117 class CORE_EXPORT QgsSymbolLayerV2Registry
118 {
119  public:
120 
122  static QgsSymbolLayerV2Registry* instance();
123 
125  QgsSymbolLayerV2AbstractMetadata* symbolLayerMetadata( const QString& name ) const;
126 
128  bool addSymbolLayerType( QgsSymbolLayerV2AbstractMetadata* metadata );
129 
131  QgsSymbolLayerV2* createSymbolLayer( const QString& name, const QgsStringMap& properties = QgsStringMap() ) const;
132 
134  QgsSymbolLayerV2* createSymbolLayerFromSld( const QString& name, QDomElement &element ) const;
135 
137  QStringList symbolLayersForType( QgsSymbolV2::SymbolType type );
138 
140  static QgsSymbolLayerV2* defaultSymbolLayer( QgsSymbolV2::SymbolType type );
141 
142  protected:
145 
147 
148  private:
150  QgsSymbolLayerV2Registry& operator=( const QgsSymbolLayerV2Registry& rh );
151 };
152 
153 #endif
virtual QgsSymbolLayerV2 * createSymbolLayerFromSld(QDomElement &)
Create a symbol layer of this type given the map of properties.
QgsSymbolV2::SymbolType type() const
virtual QgsSymbolLayerV2Widget * createSymbolLayerWidget(const QgsVectorLayer *vl) override
Create widget for symbol layer of this type.
QgsSymbolLayerV2CreateFunc mCreateFunc
virtual QgsSymbolLayerV2 * createSymbolLayer(const QgsStringMap &map) override
Create a symbol layer of this type given the map of properties.
QgsSymbolLayerV2WidgetFunc mWidgetFunc
Stores metadata about one symbol layer class.
QMap< QString, QString > QgsStringMap
Definition: qgis.h:491
QMap< QString, QgsSymbolLayerV2AbstractMetadata * > mMetadata
QgsSymbolLayerV2WidgetFunc widgetFunction() const
QgsSymbolLayerV2AbstractMetadata(const QString &name, const QString &visibleName, QgsSymbolV2::SymbolType type)
QgsSymbolLayerV2 *(* QgsSymbolLayerV2CreateFunc)(const QgsStringMap &)
QgsSymbolLayerV2CreateFromSldFunc createFromSldFunction() const
QgsSymbolLayerV2Metadata(const QString &name, const QString &visibleName, QgsSymbolV2::SymbolType type, QgsSymbolLayerV2CreateFunc pfCreate, QgsSymbolLayerV2CreateFromSldFunc pfCreateFromSld, QgsSymbolLayerV2WidgetFunc pfWidget=nullptr)
virtual QgsSymbolLayerV2Widget * createSymbolLayerWidget(const QgsVectorLayer *)
Create widget for symbol layer of this type.
QgsSymbolLayerV2CreateFromSldFunc mCreateFromSldFunc
QgsSymbolLayerV2CreateFunc createFunction() const
SymbolType
Type of the symbol.
Definition: qgssymbolv2.h:76
QgsSymbolLayerV2Widget *(* QgsSymbolLayerV2WidgetFunc)(const QgsVectorLayer *)
QgsSymbolLayerV2Metadata(const QString &name, const QString &visibleName, QgsSymbolV2::SymbolType type, QgsSymbolLayerV2CreateFunc pfCreate, QgsSymbolLayerV2WidgetFunc pfWidget=nullptr)
QgsSymbolLayerV2 *(* QgsSymbolLayerV2CreateFromSldFunc)(QDomElement &)
void setWidgetFunction(QgsSymbolLayerV2WidgetFunc f)
Represents a vector layer which manages a vector based data sets.
Registry of available symbol layer classes.
Convenience metadata class that uses static functions to create symbol layer and its widget...
virtual QgsSymbolLayerV2 * createSymbolLayerFromSld(QDomElement &elem) override
Create a symbol layer of this type given the map of properties.