QGIS API Documentation
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( const QString& name, const QString& visibleName, const QIcon& icon = QIcon() )
40  : mName( name )
41  , mVisibleName( visibleName )
42  , mIcon( icon )
43  {}
45 
46  QString name() const { return mName; }
47  QString visibleName() const { return mVisibleName; }
48 
49  QIcon icon() const { return mIcon; }
50  void setIcon( const QIcon& icon ) { mIcon = icon; }
51 
54  virtual QgsFeatureRendererV2* createRenderer( QDomElement& elem ) = 0;
63  { Q_UNUSED( layer ); Q_UNUSED( style ); Q_UNUSED( oldRenderer ); return nullptr; }
64 
66  { Q_UNUSED( elem ); Q_UNUSED( geomType ); return nullptr; }
67 
68  protected:
75 };
76 
77 
78 typedef QgsFeatureRendererV2*( *QgsRendererV2CreateFunc )( QDomElement& );
79 typedef QgsRendererV2Widget*( *QgsRendererV2WidgetFunc )( QgsVectorLayer*, QgsStyleV2*, QgsFeatureRendererV2* );
80 typedef QgsFeatureRendererV2*( *QgsRendererV2CreateFromSldFunc )( QDomElement&, QGis::GeometryType geomType );
81 
86 {
87  public:
88 
90  QgsRendererV2Metadata( const QString& name,
92  const QString& visibleName,
93  QgsRendererV2CreateFunc pfCreate,
94  const QIcon& icon = QIcon(),
95  QgsRendererV2WidgetFunc pfWidget = nullptr )
96  : QgsRendererV2AbstractMetadata( name, visibleName, icon )
97  , mCreateFunc( pfCreate )
98  , mWidgetFunc( pfWidget )
99  , mCreateFromSldFunc( nullptr )
100  {}
101 
104  const QString& visibleName,
105  QgsRendererV2CreateFunc pfCreate,
106  QgsRendererV2CreateFromSldFunc pfCreateFromSld,
107  const QIcon& icon = QIcon(),
108  QgsRendererV2WidgetFunc pfWidget = nullptr )
109  : QgsRendererV2AbstractMetadata( name, visibleName, icon )
110  , mCreateFunc( pfCreate )
111  , mWidgetFunc( pfWidget )
112  , mCreateFromSldFunc( pfCreateFromSld )
113  {}
114 
115  virtual ~QgsRendererV2Metadata();
116 
117  virtual QgsFeatureRendererV2* createRenderer( QDomElement& elem ) override { return mCreateFunc ? mCreateFunc( elem ) : nullptr; }
118  virtual QgsRendererV2Widget* createRendererWidget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer ) override
119  { return mWidgetFunc ? mWidgetFunc( layer, style, renderer ) : nullptr; }
120  virtual QgsFeatureRendererV2* createRendererFromSld( QDomElement& elem, QGis::GeometryType geomType ) override
121  { return mCreateFromSldFunc ? mCreateFromSldFunc( elem, geomType ) : nullptr; }
122 
124  QgsRendererV2CreateFunc createFunction() const { return mCreateFunc; }
126  QgsRendererV2WidgetFunc widgetFunction() const { return mWidgetFunc; }
128  QgsRendererV2CreateFromSldFunc createFromSldFunction() const { return mCreateFromSldFunc; }
129 
131  void setWidgetFunction( QgsRendererV2WidgetFunc f ) { mWidgetFunc = f; }
132 
133  protected:
140 };
141 
147 class CORE_EXPORT QgsRendererV2Registry
148 {
149  public:
150 
151  static QgsRendererV2Registry* instance();
152 
154  bool addRenderer( QgsRendererV2AbstractMetadata* metadata );
155 
157  bool removeRenderer( const QString& rendererName );
158 
160  QgsRendererV2AbstractMetadata* rendererMetadata( const QString& rendererName );
161 
163  QStringList renderersList();
164 
165  protected:
169 
171 
174 
175  private:
177  QgsRendererV2Registry& operator=( const QgsRendererV2Registry& rh );
178 };
179 
180 #endif // QGSRENDERERV2REGISTRY_H
QgsFeatureRendererV2 *(* QgsRendererV2CreateFromSldFunc)(QDomElement &, QGis::GeometryType geomType)
GeometryType
Definition: qgis.h:111
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
QgsFeatureRendererV2 *(* QgsRendererV2CreateFunc)(QDomElement &)
Stores metadata about one renderer class.
QString mName
name used within QGIS for identification (the same what renderer&#39;s type() returns) ...
QgsRendererV2CreateFunc mCreateFunc
pointer to function that creates an instance of the renderer when loading project / style ...
Registry of renderers.
virtual QgsFeatureRendererV2 * createRendererFromSld(QDomElement &elem, QGis::GeometryType geomType) override
void setIcon(const QIcon &icon)
void setWidgetFunction(QgsRendererV2WidgetFunc f)
QgsRendererV2CreateFromSldFunc createFromSldFunction() const
QgsRendererV2WidgetFunc mWidgetFunc
pointer to function that creates a widget for configuration of renderer&#39;s params
QString mVisibleName
name visible for users (translatable)
virtual QgsFeatureRendererV2 * createRenderer(QDomElement &elem) override
Return new instance of the renderer given the DOM element.
QgsRendererV2WidgetFunc widgetFunction() const
Convenience metadata class that uses static functions to create renderer and its widget.
virtual QgsRendererV2Widget * createRendererWidget(QgsVectorLayer *layer, QgsStyleV2 *style, QgsFeatureRendererV2 *renderer) override
Return new instance of settings widget for the renderer.
virtual QgsRendererV2Widget * createRendererWidget(QgsVectorLayer *layer, QgsStyleV2 *style, QgsFeatureRendererV2 *oldRenderer)
Return new instance of settings widget for the renderer.
QgsRendererV2Metadata(const QString &name, const QString &visibleName, QgsRendererV2CreateFunc pfCreate, QgsRendererV2CreateFromSldFunc pfCreateFromSld, const QIcon &icon=QIcon(), QgsRendererV2WidgetFunc pfWidget=nullptr)
Base class for renderer settings widgets.
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.
QgsRendererV2Widget *(* QgsRendererV2WidgetFunc)(QgsVectorLayer *, QgsStyleV2 *, QgsFeatureRendererV2 *)
QgsRendererV2AbstractMetadata(const QString &name, const QString &visibleName, const QIcon &icon=QIcon())
QgsRendererV2CreateFunc createFunction() const