QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsrendererv2registry.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrendererv2registry.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 #ifndef QGSRENDERERV2REGISTRY_H
16 #define QGSRENDERERV2REGISTRY_H
17 
18 #include <QIcon>
19 #include <QMap>
20 #include <QStringList>
21 #include <QDomElement>
22 
23 #include "qgis.h"
24 
26 class QgsVectorLayer;
27 class QgsStyleV2;
28 class QgsRendererV2Widget;
29 
37 {
38  public:
39  QgsRendererV2AbstractMetadata( QString name, QString visibleName, QIcon icon = QIcon() )
40  : mName( name ), mVisibleName( visibleName ), mIcon( icon ) {}
42 
43  QString name() const { return mName; }
44  QString visibleName() const { return mVisibleName; }
45 
46  QIcon icon() const { return mIcon; }
47  void setIcon( const QIcon& icon ) { mIcon = icon; }
48 
51  virtual QgsFeatureRendererV2* createRenderer( QDomElement& elem ) = 0;
53  virtual QgsRendererV2Widget* createRendererWidget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer )
54  { Q_UNUSED( layer ); Q_UNUSED( style ); Q_UNUSED( renderer ); return NULL; }
55 
56  virtual QgsFeatureRendererV2* createRendererFromSld( QDomElement& elem, QGis::GeometryType geomType )
57  { Q_UNUSED( elem ); Q_UNUSED( geomType ); return NULL; }
58 
59  protected:
61  QString mName;
63  QString mVisibleName;
65  QIcon mIcon;
66 };
67 
68 
69 typedef QgsFeatureRendererV2*( *QgsRendererV2CreateFunc )( QDomElement& );
70 typedef QgsRendererV2Widget*( *QgsRendererV2WidgetFunc )( QgsVectorLayer*, QgsStyleV2*, QgsFeatureRendererV2* );
71 typedef QgsFeatureRendererV2*( *QgsRendererV2CreateFromSldFunc )( QDomElement&, QGis::GeometryType geomType );
72 
77 {
78  public:
79 
81 
82  QgsRendererV2Metadata( QString name,
83  QString visibleName,
84  QgsRendererV2CreateFunc pfCreate,
85  QIcon icon = QIcon(),
86  QgsRendererV2WidgetFunc pfWidget = NULL )
87  : QgsRendererV2AbstractMetadata( name, visibleName, icon )
88  , mCreateFunc( pfCreate )
89  , mWidgetFunc( pfWidget )
90  , mCreateFromSldFunc( NULL )
91  {}
92 
94  QgsRendererV2Metadata( QString name,
95  QString visibleName,
96  QgsRendererV2CreateFunc pfCreate,
97  QgsRendererV2CreateFromSldFunc pfCreateFromSld,
98  QIcon icon = QIcon(),
99  QgsRendererV2WidgetFunc pfWidget = NULL )
100  : QgsRendererV2AbstractMetadata( name, visibleName, icon )
101  , mCreateFunc( pfCreate )
102  , mWidgetFunc( pfWidget )
103  , mCreateFromSldFunc( pfCreateFromSld )
104  {}
105 
106  virtual QgsFeatureRendererV2* createRenderer( QDomElement& elem ) { return mCreateFunc ? mCreateFunc( elem ) : NULL; }
107  virtual QgsRendererV2Widget* createRendererWidget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer )
108  { return mWidgetFunc ? mWidgetFunc( layer, style, renderer ) : NULL; }
109  virtual QgsFeatureRendererV2* createRendererFromSld( QDomElement& elem, QGis::GeometryType geomType )
110  { return mCreateFromSldFunc ? mCreateFromSldFunc( elem, geomType ) : NULL; }
111 
113  QgsRendererV2CreateFunc createFunction() const { return mCreateFunc; }
115  QgsRendererV2WidgetFunc widgetFunction() const { return mWidgetFunc; }
117  QgsRendererV2CreateFromSldFunc createFromSldFunction() const { return mCreateFromSldFunc; }
118 
120  void setWidgetFunction( QgsRendererV2WidgetFunc f ) { mWidgetFunc = f; }
121 
122  protected:
129 };
130 
136 class CORE_EXPORT QgsRendererV2Registry
137 {
138  public:
139 
140  static QgsRendererV2Registry* instance();
141 
143  bool addRenderer( QgsRendererV2AbstractMetadata* metadata );
144 
146  bool removeRenderer( QString rendererName );
147 
149  QgsRendererV2AbstractMetadata* rendererMetadata( QString rendererName );
150 
152  QStringList renderersList();
153 
154  protected:
158 
160 
161  QMap<QString, QgsRendererV2AbstractMetadata*> mRenderers;
162 
164  QStringList mRenderersOrder;
165 };
166 
167 #endif // QGSRENDERERV2REGISTRY_H