QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
qgsrendererregistry.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsrendererregistry.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 QGSRENDERERREGISTRY_H
16#define QGSRENDERERREGISTRY_H
17
18#include "qgis_core.h"
19#include "qgis_sip.h"
20#include <QIcon>
21#include <QMap>
22#include <QStringList>
23#include <QDomElement>
24
25// #include "qgis.h"
26#include "qgswkbtypes.h"
27
30class QgsVectorLayer;
31class QgsStyle;
33
42{
43 public:
44
50 {
51 PointLayer = 1,
52 LineLayer = 2,
53 PolygonLayer = 4,
54 All = PointLayer | LineLayer | PolygonLayer,
55 };
56 Q_DECLARE_FLAGS( LayerTypes, LayerType )
57
58
65 QgsRendererAbstractMetadata( const QString &name, const QString &visibleName, const QIcon &icon = QIcon() )
66 : mName( name )
67 , mVisibleName( visibleName )
68 , mIcon( icon )
69 {}
70 virtual ~QgsRendererAbstractMetadata() = default;
71
76 QString name() const { return mName; }
77
82 QString visibleName() const { return mVisibleName; }
83
88 QIcon icon() const { return mIcon; }
89
94 void setIcon( const QIcon &icon ) { mIcon = icon; }
95
100 virtual QgsRendererAbstractMetadata::LayerTypes compatibleLayerTypes() const { return All; }
101
106 virtual QgsFeatureRenderer *createRenderer( QDomElement &elem, const QgsReadWriteContext &context ) = 0 SIP_FACTORY;
107
116 { Q_UNUSED( layer ) Q_UNUSED( style ); Q_UNUSED( oldRenderer ); return nullptr; }
117
122 { Q_UNUSED( elem ) Q_UNUSED( geomType ); return nullptr; }
123
124 protected:
126 QString mName;
130 QIcon mIcon;
131};
132
133
134Q_DECLARE_OPERATORS_FOR_FLAGS( QgsRendererAbstractMetadata::LayerTypes )
135
136
139typedef QgsFeatureRenderer *( *QgsRendererCreateFromSldFunc )( QDomElement &, Qgis::GeometryType geomType ) SIP_SKIP;
140
146{
147 public:
148
153 QgsRendererMetadata( const QString &name,
154 const QString &visibleName,
155 QgsRendererCreateFunc pfCreate,
156 const QIcon &icon = QIcon(),
157 QgsRendererWidgetFunc pfWidget = nullptr,
158 QgsRendererAbstractMetadata::LayerTypes layerTypes = QgsRendererAbstractMetadata::All ) SIP_SKIP
159 : QgsRendererAbstractMetadata( name, visibleName, icon )
160 , mCreateFunc( pfCreate )
161 , mWidgetFunc( pfWidget )
162 , mCreateFromSldFunc( nullptr )
163 , mLayerTypes( layerTypes )
164 {}
165
167 QgsRendererMetadata( const QString &name,
168 const QString &visibleName,
169 QgsRendererCreateFunc pfCreate,
170 QgsRendererCreateFromSldFunc pfCreateFromSld,
171 const QIcon &icon = QIcon(),
172 QgsRendererWidgetFunc pfWidget = nullptr,
173 QgsRendererAbstractMetadata::LayerTypes layerTypes = QgsRendererAbstractMetadata::All ) SIP_SKIP
174 : QgsRendererAbstractMetadata( name, visibleName, icon )
175 , mCreateFunc( pfCreate )
176 , mWidgetFunc( pfWidget )
177 , mCreateFromSldFunc( pfCreateFromSld )
178 , mLayerTypes( layerTypes )
179 {}
180
181 QgsFeatureRenderer *createRenderer( QDomElement &elem, const QgsReadWriteContext &context ) override SIP_FACTORY
182 { return mCreateFunc ? mCreateFunc( elem, context ) : nullptr; }
184 { return mWidgetFunc ? mWidgetFunc( layer, style, renderer ) : nullptr; }
186 { return mCreateFromSldFunc ? mCreateFromSldFunc( elem, geomType ) : nullptr; }
187
189 QgsRendererCreateFunc createFunction() const { return mCreateFunc; } SIP_SKIP
191 QgsRendererWidgetFunc widgetFunction() const { return mWidgetFunc; } SIP_SKIP
193 QgsRendererCreateFromSldFunc createFromSldFunction() const { return mCreateFromSldFunc; } SIP_SKIP
194
196 void setWidgetFunction( QgsRendererWidgetFunc f ) { mWidgetFunc = f; } SIP_SKIP
197
198 QgsRendererAbstractMetadata::LayerTypes compatibleLayerTypes() const override { return mLayerTypes; }
199
200 protected:
207
208 private:
209#ifdef SIP_RUN
211#endif
212
213 QgsRendererAbstractMetadata::LayerTypes mLayerTypes;
214};
215
216
227class CORE_EXPORT QgsRendererRegistry
228{
229 public:
230
233
238
245 bool addRenderer( QgsRendererAbstractMetadata *metadata SIP_TRANSFER );
246
253 bool removeRenderer( const QString &rendererName );
254
259 QgsRendererAbstractMetadata *rendererMetadata( const QString &rendererName );
260
265 QStringList renderersList( QgsRendererAbstractMetadata::LayerTypes layerTypes = QgsRendererAbstractMetadata::All ) const;
266
272 QStringList renderersList( const QgsVectorLayer *layer ) const;
273
274 private:
275#ifdef SIP_RUN
277#endif
278
280 QMap<QString, QgsRendererAbstractMetadata *> mRenderers;
281
283 QStringList mRenderersOrder;
284};
285
286#endif // QGSRENDERERREGISTRY_H
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:54
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition: qgis.h:227
The class is used as a container of context for various read/write operations on other objects.
Stores metadata about one renderer class.
LayerType
Layer types the renderer is compatible with.
@ All
Compatible with all vector layers.
QIcon icon() const
Returns an icon representing the renderer.
virtual ~QgsRendererAbstractMetadata()=default
void setIcon(const QIcon &icon)
Sets an icon representing the renderer.
QString mName
name used within QGIS for identification (the same what renderer's type() returns)
QString mVisibleName
name visible for users (translatable)
virtual QgsFeatureRenderer * createRenderer(QDomElement &elem, const QgsReadWriteContext &context)=0
Returns new instance of the renderer given the DOM element.
virtual QgsRendererAbstractMetadata::LayerTypes compatibleLayerTypes() const
Returns flags indicating the types of layer the renderer is compatible with.
QIcon mIcon
icon to be shown in the renderer properties dialog
QString visibleName() const
Returns a friendly display name of the renderer.
virtual QgsFeatureRenderer * createRendererFromSld(QDomElement &elem, Qgis::GeometryType geomType)
Returns a new instance of the renderer, converted from an SLD XML element.
virtual QgsRendererWidget * createRendererWidget(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *oldRenderer)
Returns new instance of settings widget for the renderer.
QString name() const
Returns the unique name of the renderer.
Convenience metadata class that uses static functions to create renderer and its widget.
QgsFeatureRenderer * createRenderer(QDomElement &elem, const QgsReadWriteContext &context) override
Returns new instance of the renderer given the DOM element.
void setWidgetFunction(QgsRendererWidgetFunc f)
QgsRendererWidget * createRendererWidget(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer) override
Returns new instance of settings widget for the renderer.
QgsRendererAbstractMetadata::LayerTypes compatibleLayerTypes() const override
Returns flags indicating the types of layer the renderer is compatible with.
QgsFeatureRenderer * createRendererFromSld(QDomElement &elem, Qgis::GeometryType geomType) override
Returns a new instance of the renderer, converted from an SLD XML element.
QgsRendererCreateFunc createFunction() const
QgsRendererMetadata(const QString &name, const QString &visibleName, QgsRendererCreateFunc pfCreate, const QIcon &icon=QIcon(), QgsRendererWidgetFunc pfWidget=nullptr, QgsRendererAbstractMetadata::LayerTypes layerTypes=QgsRendererAbstractMetadata::All)
Construct metadata.
QgsRendererCreateFromSldFunc mCreateFromSldFunc
pointer to function that creates an instance of the renderer from SLD
QgsRendererWidgetFunc widgetFunction() const
QgsRendererCreateFunc mCreateFunc
pointer to function that creates an instance of the renderer when loading project / style
QgsRendererMetadata(const QString &name, const QString &visibleName, QgsRendererCreateFunc pfCreate, QgsRendererCreateFromSldFunc pfCreateFromSld, const QIcon &icon=QIcon(), QgsRendererWidgetFunc pfWidget=nullptr, QgsRendererAbstractMetadata::LayerTypes layerTypes=QgsRendererAbstractMetadata::All)
QgsRendererCreateFromSldFunc createFromSldFunction() const
QgsRendererWidgetFunc mWidgetFunc
pointer to function that creates a widget for configuration of renderer's params
Registry of renderers.
QgsRendererRegistry & operator=(const QgsRendererRegistry &rh)=delete
QgsRendererRegistry cannot be copied.
QgsRendererRegistry(const QgsRendererRegistry &rh)=delete
QgsRendererRegistry cannot be copied.
Base class for renderer settings widgets.
Represents a vector layer which manages a vector based data sets.
#define SIP_EXTERNAL
Definition: qgis_sip.h:116
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
QgsFeatureRenderer *(* QgsRendererCreateFromSldFunc)(QDomElement &, Qgis::GeometryType geomType)
QgsRendererWidget *(* QgsRendererWidgetFunc)(QgsVectorLayer *, QgsStyle *, QgsFeatureRenderer *)
QgsFeatureRenderer *(* QgsRendererCreateFunc)(QDomElement &, const QgsReadWriteContext &)