QGIS API Documentation  2.6.0-Brighton
 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;
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 ~QgsRendererV2Metadata();
107 
108  virtual QgsFeatureRendererV2* createRenderer( QDomElement& elem ) { return mCreateFunc ? mCreateFunc( elem ) : NULL; }
109  virtual QgsRendererV2Widget* createRendererWidget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer )
110  { return mWidgetFunc ? mWidgetFunc( layer, style, renderer ) : NULL; }
111  virtual QgsFeatureRendererV2* createRendererFromSld( QDomElement& elem, QGis::GeometryType geomType )
112  { return mCreateFromSldFunc ? mCreateFromSldFunc( elem, geomType ) : NULL; }
113 
115  QgsRendererV2CreateFunc createFunction() const { return mCreateFunc; }
117  QgsRendererV2WidgetFunc widgetFunction() const { return mWidgetFunc; }
119  QgsRendererV2CreateFromSldFunc createFromSldFunction() const { return mCreateFromSldFunc; }
120 
122  void setWidgetFunction( QgsRendererV2WidgetFunc f ) { mWidgetFunc = f; }
123 
124  protected:
131 };
132 
138 class CORE_EXPORT QgsRendererV2Registry
139 {
140  public:
141 
142  static QgsRendererV2Registry* instance();
143 
145  bool addRenderer( QgsRendererV2AbstractMetadata* metadata );
146 
148  bool removeRenderer( QString rendererName );
149 
151  QgsRendererV2AbstractMetadata* rendererMetadata( QString rendererName );
152 
154  QStringList renderersList();
155 
156  protected:
160 
161  QMap<QString, QgsRendererV2AbstractMetadata*> mRenderers;
162 
164  QStringList mRenderersOrder;
165 };
166 
167 #endif // QGSRENDERERV2REGISTRY_H