QGIS API Documentation  2.13.0-Master
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 ), 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;
60  { Q_UNUSED( layer ); Q_UNUSED( style ); Q_UNUSED( oldRenderer ); return nullptr; }
61 
63  { Q_UNUSED( elem ); Q_UNUSED( geomType ); return nullptr; }
64 
65  protected:
72 };
73 
74 
75 typedef QgsFeatureRendererV2*( *QgsRendererV2CreateFunc )( QDomElement& );
76 typedef QgsRendererV2Widget*( *QgsRendererV2WidgetFunc )( QgsVectorLayer*, QgsStyleV2*, QgsFeatureRendererV2* );
77 typedef QgsFeatureRendererV2*( *QgsRendererV2CreateFromSldFunc )( QDomElement&, QGis::GeometryType geomType );
78 
83 {
84  public:
85 
87  QgsRendererV2Metadata( const QString& name,
89  const QString& visibleName,
90  QgsRendererV2CreateFunc pfCreate,
91  const QIcon& icon = QIcon(),
92  QgsRendererV2WidgetFunc pfWidget = nullptr )
93  : QgsRendererV2AbstractMetadata( name, visibleName, icon )
94  , mCreateFunc( pfCreate )
95  , mWidgetFunc( pfWidget )
96  , mCreateFromSldFunc( nullptr )
97  {}
98 
101  const QString& visibleName,
102  QgsRendererV2CreateFunc pfCreate,
103  QgsRendererV2CreateFromSldFunc pfCreateFromSld,
104  const QIcon& icon = QIcon(),
105  QgsRendererV2WidgetFunc pfWidget = nullptr )
106  : QgsRendererV2AbstractMetadata( name, visibleName, icon )
107  , mCreateFunc( pfCreate )
108  , mWidgetFunc( pfWidget )
109  , mCreateFromSldFunc( pfCreateFromSld )
110  {}
111 
112  virtual ~QgsRendererV2Metadata();
113 
114  virtual QgsFeatureRendererV2* createRenderer( QDomElement& elem ) override { return mCreateFunc ? mCreateFunc( elem ) : nullptr; }
115  virtual QgsRendererV2Widget* createRendererWidget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer ) override
116  { return mWidgetFunc ? mWidgetFunc( layer, style, renderer ) : nullptr; }
117  virtual QgsFeatureRendererV2* createRendererFromSld( QDomElement& elem, QGis::GeometryType geomType ) override
118  { return mCreateFromSldFunc ? mCreateFromSldFunc( elem, geomType ) : nullptr; }
119 
121  QgsRendererV2CreateFunc createFunction() const { return mCreateFunc; }
123  QgsRendererV2WidgetFunc widgetFunction() const { return mWidgetFunc; }
125  QgsRendererV2CreateFromSldFunc createFromSldFunction() const { return mCreateFromSldFunc; }
126 
128  void setWidgetFunction( QgsRendererV2WidgetFunc f ) { mWidgetFunc = f; }
129 
130  protected:
137 };
138 
144 class CORE_EXPORT QgsRendererV2Registry
145 {
146  public:
147 
148  static QgsRendererV2Registry* instance();
149 
151  bool addRenderer( QgsRendererV2AbstractMetadata* metadata );
152 
154  bool removeRenderer( const QString& rendererName );
155 
157  QgsRendererV2AbstractMetadata* rendererMetadata( const QString& rendererName );
158 
160  QStringList renderersList();
161 
162  protected:
166 
168 
171 
172  private:
174  QgsRendererV2Registry& operator=( const QgsRendererV2Registry& rh );
175 };
176 
177 #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