QGIS API Documentation  2.5.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.
Definition: qgsrendererv2registry.h:109
virtual QgsFeatureRendererV2 * createRendererFromSld(QDomElement &elem, QGis::GeometryType geomType)
Definition: qgsrendererv2registry.h:111
QgsRendererV2Metadata(QString name, QString visibleName, QgsRendererV2CreateFunc pfCreate, QgsRendererV2CreateFromSldFunc pfCreateFromSld, QIcon icon=QIcon(), QgsRendererV2WidgetFunc pfWidget=NULL)
Definition: qgsrendererv2registry.h:94
QIcon mIcon
icon to be shown in the renderer properties dialog
Definition: qgsrendererv2registry.h:65
QMap< QString, QgsRendererV2AbstractMetadata * > mRenderers
Definition: qgsrendererv2registry.h:161
QgsRendererV2CreateFromSldFunc mCreateFromSldFunc
pointer to function that creates an instance of the renderer from SLD
Definition: qgsrendererv2registry.h:130
QIcon icon() const
Definition: qgsrendererv2registry.h:46
Stores metadata about one renderer class.
Definition: qgsrendererv2registry.h:36
GeometryType
Definition: qgis.h:155
QString mName
name used within QGIS for identification (the same what renderer's type() returns) ...
Definition: qgsrendererv2registry.h:61
QgsRendererV2CreateFunc mCreateFunc
pointer to function that creates an instance of the renderer when loading project / style ...
Definition: qgsrendererv2registry.h:126
static QIcon icon(QString icon)
Definition: qgsmessagelogviewer.cpp:30
Registry of renderers.
Definition: qgsrendererv2registry.h:138
virtual ~QgsRendererV2AbstractMetadata()
Definition: qgsrendererv2registry.h:41
void setIcon(const QIcon &icon)
Definition: qgsrendererv2registry.h:47
void setWidgetFunction(QgsRendererV2WidgetFunc f)
Definition: qgsrendererv2registry.h:122
QgsRendererV2CreateFromSldFunc createFromSldFunction() const
Definition: qgsrendererv2registry.h:119
QgsFeatureRendererV2 *(* QgsRendererV2CreateFunc)(QDomElement &)
Definition: qgsrendererv2registry.h:69
QgsRendererV2WidgetFunc mWidgetFunc
pointer to function that creates a widget for configuration of renderer's params
Definition: qgsrendererv2registry.h:128
QgsRendererV2AbstractMetadata(QString name, QString visibleName, QIcon icon=QIcon())
Definition: qgsrendererv2registry.h:39
QString visibleName() const
Definition: qgsrendererv2registry.h:44
QString mVisibleName
name visible for users (translatable)
Definition: qgsrendererv2registry.h:63
QgsRendererV2Widget *(* QgsRendererV2WidgetFunc)(QgsVectorLayer *, QgsStyleV2 *, QgsFeatureRendererV2 *)
Definition: qgsrendererv2registry.h:70
QgsRendererV2WidgetFunc widgetFunction() const
Definition: qgsrendererv2registry.h:117
QString name() const
Definition: qgsrendererv2registry.h:43
virtual QgsFeatureRendererV2 * createRenderer(QDomElement &elem)
Return new instance of the renderer given the DOM element.
Definition: qgsrendererv2registry.h:108
QgsFeatureRendererV2 *(* QgsRendererV2CreateFromSldFunc)(QDomElement &, QGis::GeometryType geomType)
Definition: qgsrendererv2registry.h:71
Definition: qgsstylev2.h:66
Convenience metadata class that uses static functions to create renderer and its widget.
Definition: qgsrendererv2registry.h:76
Base class for renderer settings widgets.
Definition: qgsrendererv2widget.h:38
virtual QgsRendererV2Widget * createRendererWidget(QgsVectorLayer *layer, QgsStyleV2 *style, QgsFeatureRendererV2 *renderer)
Return new instance of settings widget for the renderer.
Definition: qgsrendererv2registry.h:53
Definition: qgsrendererv2.h:72
QStringList mRenderersOrder
list to keep order in which renderers have been added
Definition: qgsrendererv2registry.h:164
virtual QgsFeatureRendererV2 * createRendererFromSld(QDomElement &elem, QGis::GeometryType geomType)
Definition: qgsrendererv2registry.h:56
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:470
QgsRendererV2CreateFunc createFunction() const
Definition: qgsrendererv2registry.h:115