QGIS API Documentation  2.2.0-Valmiera
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
33  QgsSymbolLayerV2AbstractMetadata( QString name, QString visibleName, QgsSymbolV2::SymbolType type )
34  : mName( name ), mVisibleName( visibleName ), mType( type ) {}
35 
37 
38  QString name() const { return mName; }
39  QString visibleName() const { return mVisibleName; }
40  QgsSymbolV2::SymbolType type() const { return mType; }
41 
43  virtual QgsSymbolLayerV2* createSymbolLayer( const QgsStringMap& map ) = 0;
45  virtual QgsSymbolLayerV2Widget* createSymbolLayerWidget( const QgsVectorLayer * ) { return NULL; }
47  virtual QgsSymbolLayerV2* createSymbolLayerFromSld( QDomElement & ) { return NULL; }
48 
49 
50  protected:
51  QString mName;
52  QString mVisibleName;
54 };
55 
56 typedef QgsSymbolLayerV2*( *QgsSymbolLayerV2CreateFunc )( const QgsStringMap& );
57 typedef QgsSymbolLayerV2Widget*( *QgsSymbolLayerV2WidgetFunc )( const QgsVectorLayer* );
58 typedef QgsSymbolLayerV2*( *QgsSymbolLayerV2CreateFromSldFunc )( QDomElement& );
59 
64 {
65  public:
67  QgsSymbolLayerV2Metadata( QString name, QString visibleName,
70  QgsSymbolLayerV2WidgetFunc pfWidget = NULL )
71  : QgsSymbolLayerV2AbstractMetadata( name, visibleName, type )
72  , mCreateFunc( pfCreate )
73  , mWidgetFunc( pfWidget )
74  , mCreateFromSldFunc( NULL )
75  {}
76 
78  QgsSymbolLayerV2Metadata( QString name, QString visibleName,
81  QgsSymbolLayerV2CreateFromSldFunc pfCreateFromSld,
82  QgsSymbolLayerV2WidgetFunc pfWidget = NULL )
83  : QgsSymbolLayerV2AbstractMetadata( name, visibleName, type )
84  , mCreateFunc( pfCreate )
85  , mWidgetFunc( pfWidget )
86  , mCreateFromSldFunc( pfCreateFromSld )
87  {}
88 
90  QgsSymbolLayerV2CreateFunc createFunction() const { return mCreateFunc; }
92  QgsSymbolLayerV2WidgetFunc widgetFunction() const { return mWidgetFunc; }
94  QgsSymbolLayerV2CreateFromSldFunc createFromSldFunction() const { return mCreateFromSldFunc; }
95 
97  void setWidgetFunction( QgsSymbolLayerV2WidgetFunc f ) { mWidgetFunc = f; }
98 
99  virtual QgsSymbolLayerV2* createSymbolLayer( const QgsStringMap& map ) { return mCreateFunc ? mCreateFunc( map ) : NULL; }
100  virtual QgsSymbolLayerV2Widget* createSymbolLayerWidget( const QgsVectorLayer* vl ) { return mWidgetFunc ? mWidgetFunc( vl ) : NULL; }
101  virtual QgsSymbolLayerV2* createSymbolLayerFromSld( QDomElement& elem ) { return mCreateFromSldFunc ? mCreateFromSldFunc( elem ) : NULL; }
102 
103  protected:
107 };
108 
109 
114 class CORE_EXPORT QgsSymbolLayerV2Registry
115 {
116  public:
117 
119  static QgsSymbolLayerV2Registry* instance();
120 
122  QgsSymbolLayerV2AbstractMetadata* symbolLayerMetadata( QString name ) const;
123 
125  bool addSymbolLayerType( QgsSymbolLayerV2AbstractMetadata* metadata );
126 
128  QgsSymbolLayerV2* createSymbolLayer( QString name, const QgsStringMap& properties = QgsStringMap() ) const;
129 
131  QgsSymbolLayerV2* createSymbolLayerFromSld( QString name, QDomElement &element ) const;
132 
134  QStringList symbolLayersForType( QgsSymbolV2::SymbolType type );
135 
137  static QgsSymbolLayerV2* defaultSymbolLayer( QgsSymbolV2::SymbolType type );
138 
139  protected:
142 
143  QMap<QString, QgsSymbolLayerV2AbstractMetadata*> mMetadata;
144 
145 };
146 
147 #endif