QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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;
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  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
virtual QgsRendererV2Widget * createRendererWidget(QgsVectorLayer *layer, QgsStyleV2 *style, QgsFeatureRendererV2 *renderer)
Return new instance of settings widget for the renderer.
virtual QgsFeatureRendererV2 * createRendererFromSld(QDomElement &elem, QGis::GeometryType geomType)
QgsRendererV2Metadata(QString name, QString visibleName, QgsRendererV2CreateFunc pfCreate, QgsRendererV2CreateFromSldFunc pfCreateFromSld, QIcon icon=QIcon(), QgsRendererV2WidgetFunc pfWidget=NULL)
QIcon mIcon
icon to be shown in the renderer properties dialog
QMap< QString, QgsRendererV2AbstractMetadata * > mRenderers
QgsRendererV2CreateFromSldFunc mCreateFromSldFunc
pointer to function that creates an instance of the renderer from SLD
Stores metadata about one renderer class.
GeometryType
Definition: qgis.h:155
QString mName
name used within QGIS for identification (the same what renderer's type() returns) ...
QgsRendererV2CreateFunc mCreateFunc
pointer to function that creates an instance of the renderer when loading project / style ...
static QIcon icon(QString icon)
Registry of renderers.
void setIcon(const QIcon &icon)
void setWidgetFunction(QgsRendererV2WidgetFunc f)
QgsRendererV2CreateFromSldFunc createFromSldFunction() const
QgsFeatureRendererV2 *(* QgsRendererV2CreateFunc)(QDomElement &)
QgsRendererV2WidgetFunc mWidgetFunc
pointer to function that creates a widget for configuration of renderer's params
QgsRendererV2AbstractMetadata(QString name, QString visibleName, QIcon icon=QIcon())
QString mVisibleName
name visible for users (translatable)
QgsRendererV2Widget *(* QgsRendererV2WidgetFunc)(QgsVectorLayer *, QgsStyleV2 *, QgsFeatureRendererV2 *)
QgsRendererV2WidgetFunc widgetFunction() const
virtual QgsFeatureRendererV2 * createRenderer(QDomElement &elem)
Return new instance of the renderer given the DOM element.
QgsFeatureRendererV2 *(* QgsRendererV2CreateFromSldFunc)(QDomElement &, QGis::GeometryType geomType)
Convenience metadata class that uses static functions to create renderer and its widget.
Base class for renderer settings widgets.
virtual QgsRendererV2Widget * createRendererWidget(QgsVectorLayer *layer, QgsStyleV2 *style, QgsFeatureRendererV2 *renderer)
Return new instance of settings widget for the renderer.
QStringList mRenderersOrder
list to keep order in which renderers have been added
virtual QgsFeatureRendererV2 * createRendererFromSld(QDomElement &elem, QGis::GeometryType geomType)
Represents a vector layer which manages a vector based data sets.
QgsRendererV2CreateFunc createFunction() const