QGIS API Documentation  2.15.0-Master (972fc9f)
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 
42  enum LayerType
43  {
44  PointLayer = 1,
45  LineLayer = 2,
46  PolygonLayer = 4,
47  All = PointLayer | LineLayer | PolygonLayer,
48  };
49  Q_DECLARE_FLAGS( LayerTypes, LayerType )
50 
51  QgsRendererV2AbstractMetadata( const QString& name, const QString& visibleName, const QIcon& icon = QIcon() )
52  : mName( name )
53  , mVisibleName( visibleName )
54  , mIcon( icon )
55  {}
57 
58  QString name() const { return mName; }
59  QString visibleName() const { return mVisibleName; }
60 
61  QIcon icon() const { return mIcon; }
62  void setIcon( const QIcon& icon ) { mIcon = icon; }
63 
67  virtual LayerTypes compatibleLayerTypes() const { return All; }
68 
71  virtual QgsFeatureRendererV2* createRenderer( QDomElement& elem ) = 0;
80  { Q_UNUSED( layer ); Q_UNUSED( style ); Q_UNUSED( oldRenderer ); return nullptr; }
81 
83  { Q_UNUSED( elem ); Q_UNUSED( geomType ); return nullptr; }
84 
85  protected:
92 };
93 
94 
95 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsRendererV2AbstractMetadata::LayerTypes )
96 
97 
100 typedef QgsFeatureRendererV2*( *QgsRendererV2CreateFromSldFunc )( QDomElement&, QGis::GeometryType geomType );
101 
106 {
107  public:
108 
110  QgsRendererV2Metadata( const QString& name,
112  const QString& visibleName,
113  QgsRendererV2CreateFunc pfCreate,
114  const QIcon& icon = QIcon(),
115  QgsRendererV2WidgetFunc pfWidget = nullptr,
116  QgsRendererV2AbstractMetadata::LayerTypes layerTypes = QgsRendererV2AbstractMetadata::All )
117  : QgsRendererV2AbstractMetadata( name, visibleName, icon )
118  , mCreateFunc( pfCreate )
119  , mWidgetFunc( pfWidget )
120  , mCreateFromSldFunc( nullptr )
121  , mLayerTypes( layerTypes )
122  {}
123 
126  const QString& visibleName,
127  QgsRendererV2CreateFunc pfCreate,
128  QgsRendererV2CreateFromSldFunc pfCreateFromSld,
129  const QIcon& icon = QIcon(),
130  QgsRendererV2WidgetFunc pfWidget = nullptr,
131  QgsRendererV2AbstractMetadata::LayerTypes layerTypes = QgsRendererV2AbstractMetadata::All )
132  : QgsRendererV2AbstractMetadata( name, visibleName, icon )
133  , mCreateFunc( pfCreate )
134  , mWidgetFunc( pfWidget )
135  , mCreateFromSldFunc( pfCreateFromSld )
136  , mLayerTypes( layerTypes )
137  {}
138 
139  virtual ~QgsRendererV2Metadata();
140 
141  virtual QgsFeatureRendererV2* createRenderer( QDomElement& elem ) override { return mCreateFunc ? mCreateFunc( elem ) : nullptr; }
142  virtual QgsRendererV2Widget* createRendererWidget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer ) override
143  { return mWidgetFunc ? mWidgetFunc( layer, style, renderer ) : nullptr; }
144  virtual QgsFeatureRendererV2* createRendererFromSld( QDomElement& elem, QGis::GeometryType geomType ) override
145  { return mCreateFromSldFunc ? mCreateFromSldFunc( elem, geomType ) : nullptr; }
146 
148  QgsRendererV2CreateFunc createFunction() const { return mCreateFunc; }
150  QgsRendererV2WidgetFunc widgetFunction() const { return mWidgetFunc; }
152  QgsRendererV2CreateFromSldFunc createFromSldFunction() const { return mCreateFromSldFunc; }
153 
155  void setWidgetFunction( QgsRendererV2WidgetFunc f ) { mWidgetFunc = f; }
156 
157  virtual QgsRendererV2AbstractMetadata::LayerTypes compatibleLayerTypes() const override { return mLayerTypes; }
158 
159  protected:
166 
167  private:
168 
169  QgsRendererV2AbstractMetadata::LayerTypes mLayerTypes;
170 };
171 
172 
180 class CORE_EXPORT QgsRendererV2Registry
181 {
182  public:
183 
185  static QgsRendererV2Registry* instance();
186 
191  bool addRenderer( QgsRendererV2AbstractMetadata* metadata );
192 
197  bool removeRenderer( const QString& rendererName );
198 
201  QgsRendererV2AbstractMetadata* rendererMetadata( const QString& rendererName );
202 
205  QStringList renderersList( QgsRendererV2AbstractMetadata::LayerTypes layerTypes = QgsRendererV2AbstractMetadata::All ) const;
206 
210  QStringList renderersList( const QgsVectorLayer* layer ) const;
211 
212  protected:
216 
219 
222 
223  private:
225  QgsRendererV2Registry& operator=( const QgsRendererV2Registry& rh );
226 };
227 
228 #endif // QGSRENDERERV2REGISTRY_H
QgsFeatureRendererV2 *(* QgsRendererV2CreateFromSldFunc)(QDomElement &, QGis::GeometryType geomType)
GeometryType
Definition: qgis.h:115
QIcon mIcon
icon to be shown in the renderer properties dialog
QMap< QString, QgsRendererV2AbstractMetadata * > mRenderers
Map of name to renderer.
QgsRendererV2CreateFromSldFunc mCreateFromSldFunc
pointer to function that creates an instance of the renderer from SLD
QgsFeatureRendererV2 *(* QgsRendererV2CreateFunc)(QDomElement &)
Stores metadata about one renderer class.
The QGis class provides global constants for use throughout the application.
Definition: qgis.h:40
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.
LayerType
Layer types the renderer is compatible with.
virtual QgsFeatureRendererV2 * createRendererFromSld(QDomElement &elem, QGis::GeometryType geomType) override
void setIcon(const QIcon &icon)
void setWidgetFunction(QgsRendererV2WidgetFunc f)
QgsRendererV2CreateFromSldFunc createFromSldFunction() const
Compatible with all vector layers.
QgsRendererV2WidgetFunc mWidgetFunc
pointer to function that creates a widget for configuration of renderer&#39;s params
QString mVisibleName
name visible for users (translatable)
QgsRendererV2Metadata(const QString &name, const QString &visibleName, QgsRendererV2CreateFunc pfCreate, QgsRendererV2CreateFromSldFunc pfCreateFromSld, const QIcon &icon=QIcon(), QgsRendererV2WidgetFunc pfWidget=nullptr, QgsRendererV2AbstractMetadata::LayerTypes layerTypes=QgsRendererV2AbstractMetadata::All)
virtual QgsFeatureRendererV2 * createRenderer(QDomElement &elem) override
Return new instance of the renderer given the DOM element.
virtual LayerTypes compatibleLayerTypes() const
Returns flags indicating the types of layer the renderer is compatible with.
QgsRendererV2WidgetFunc widgetFunction() const
virtual QgsRendererV2AbstractMetadata::LayerTypes compatibleLayerTypes() const override
Returns flags indicating the types of layer the renderer is compatible with.
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.
Base class for renderer settings widgets.
QStringList mRenderersOrder
List of renderers, maintained in the order that they 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 *)
QgsRendererV2CreateFunc createFunction() const