QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
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
49 {
50 PointLayer = 1,
51 LineLayer = 2,
52 PolygonLayer = 4,
53 All = PointLayer | LineLayer | PolygonLayer,
54 };
55 Q_DECLARE_FLAGS( LayerTypes, LayerType )
56
57
64 QgsRendererAbstractMetadata( const QString &name, const QString &visibleName, const QIcon &icon = QIcon() )
65 : mName( name )
66 , mVisibleName( visibleName )
67 , mIcon( icon )
68 {}
69 virtual ~QgsRendererAbstractMetadata() = default;
70
75 QString name() const { return mName; }
76
81 QString visibleName() const { return mVisibleName; }
82
87 QIcon icon() const { return mIcon; }
88
93 void setIcon( const QIcon &icon ) { mIcon = icon; }
94
99
104 virtual QgsFeatureRenderer *createRenderer( QDomElement &elem, const QgsReadWriteContext &context ) = 0 SIP_FACTORY;
105
114 { Q_UNUSED( layer ) Q_UNUSED( style ); Q_UNUSED( oldRenderer ); return nullptr; }
115
120 { Q_UNUSED( elem ) Q_UNUSED( geomType ); return nullptr; }
121
122 protected:
124 QString mName;
128 QIcon mIcon;
129};
130
131
133
134
137typedef QgsFeatureRenderer *( *QgsRendererCreateFromSldFunc )( QDomElement &, Qgis::GeometryType geomType ) SIP_SKIP;
138
144{
145 public:
146
151 QgsRendererMetadata( const QString &name,
152 const QString &visibleName,
153 QgsRendererCreateFunc pfCreate,
154 const QIcon &icon = QIcon(),
155 QgsRendererWidgetFunc pfWidget = nullptr,
157 : QgsRendererAbstractMetadata( name, visibleName, icon )
158 , mCreateFunc( pfCreate )
159 , mWidgetFunc( pfWidget )
160 , mCreateFromSldFunc( nullptr )
161 , mLayerTypes( layerTypes )
162 {}
163
165 QgsRendererMetadata( const QString &name,
166 const QString &visibleName,
167 QgsRendererCreateFunc pfCreate,
168 QgsRendererCreateFromSldFunc pfCreateFromSld,
169 const QIcon &icon = QIcon(),
170 QgsRendererWidgetFunc pfWidget = nullptr,
172 : QgsRendererAbstractMetadata( name, visibleName, icon )
173 , mCreateFunc( pfCreate )
174 , mWidgetFunc( pfWidget )
175 , mCreateFromSldFunc( pfCreateFromSld )
176 , mLayerTypes( layerTypes )
177 {}
178
179 QgsFeatureRenderer *createRenderer( QDomElement &elem, const QgsReadWriteContext &context ) override SIP_FACTORY
180 { return mCreateFunc ? mCreateFunc( elem, context ) : nullptr; }
182 { return mWidgetFunc ? mWidgetFunc( layer, style, renderer ) : nullptr; }
184 { return mCreateFromSldFunc ? mCreateFromSldFunc( elem, geomType ) : nullptr; }
185
187 QgsRendererCreateFunc createFunction() const { return mCreateFunc; } SIP_SKIP
189 QgsRendererWidgetFunc widgetFunction() const { return mWidgetFunc; } SIP_SKIP
191 QgsRendererCreateFromSldFunc createFromSldFunction() const { return mCreateFromSldFunc; } SIP_SKIP
192
194 void setWidgetFunction( QgsRendererWidgetFunc f ) { mWidgetFunc = f; } SIP_SKIP
195
196 QgsRendererAbstractMetadata::LayerTypes compatibleLayerTypes() const override { return mLayerTypes; }
197
198 protected:
205
206 private:
207#ifdef SIP_RUN
209#endif
210
212};
213
214
225class CORE_EXPORT QgsRendererRegistry
226{
227 public:
228
231
234
241 bool addRenderer( QgsRendererAbstractMetadata *metadata SIP_TRANSFER );
242
249 bool removeRenderer( const QString &rendererName );
250
255 QgsRendererAbstractMetadata *rendererMetadata( const QString &rendererName );
256
261 QStringList renderersList( QgsRendererAbstractMetadata::LayerTypes layerTypes = QgsRendererAbstractMetadata::All ) const;
262
267 QStringList renderersList( const QgsVectorLayer *layer ) const;
268
269 private:
270#ifdef SIP_RUN
272#endif
273
275 QMap<QString, QgsRendererAbstractMetadata *> mRenderers;
276
278 QStringList mRenderersOrder;
279};
280
281#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:337
Abstract base class for all 2D vector feature renderers.
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(const QgsRendererRegistry &rh)=delete
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_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:76
QgsFeatureRenderer *(* QgsRendererCreateFromSldFunc)(QDomElement &, Qgis::GeometryType geomType)
QgsRendererWidget *(* QgsRendererWidgetFunc)(QgsVectorLayer *, QgsStyle *, QgsFeatureRenderer *)
QgsFeatureRenderer *(* QgsRendererCreateFunc)(QDomElement &, const QgsReadWriteContext &)
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)