QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
qgssymbollayerregistry.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssymbollayerregistry.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
16#ifndef QGSSYMBOLLAYERREGISTRY_H
17#define QGSSYMBOLLAYERREGISTRY_H
18
19#include "qgis.h"
20#include "qgis_core.h"
21
22class QgsPathResolver;
23class QgsVectorLayer;
25class QgsSymbolLayer;
26class QDomElement;
28
37{
38 public:
39
47 : mName( name )
49 , mType( type )
50 {}
51
53
54 QString name() const { return mName; }
55 QString visibleName() const { return mVisibleName; }
56 Qgis::SymbolType type() const { return mType; }
57
59 virtual QgsSymbolLayer *createSymbolLayer( const QVariantMap &map ) = 0 SIP_FACTORY;
63 virtual QgsSymbolLayer *createSymbolLayerFromSld( QDomElement & ) SIP_FACTORY { return nullptr; }
64
72 virtual void resolvePaths( QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving )
73 {
74 Q_UNUSED( properties )
75 Q_UNUSED( pathResolver )
76 Q_UNUSED( saving )
77 }
78
87 virtual void resolveFonts( const QVariantMap &properties, const QgsReadWriteContext &context )
88 {
89 Q_UNUSED( properties )
90 Q_UNUSED( context )
91 }
92
93 protected:
94 QString mName;
95 QString mVisibleName;
97};
98
99typedef QgsSymbolLayer *( *QgsSymbolLayerCreateFunc )( const QVariantMap & ) SIP_SKIP;
100typedef QgsSymbolLayerWidget *( *QgsSymbolLayerWidgetFunc )( QgsVectorLayer * ) SIP_SKIP;
101typedef QgsSymbolLayer *( *QgsSymbolLayerCreateFromSldFunc )( QDomElement & ) SIP_SKIP;
102typedef void ( *QgsSymbolLayerPathResolverFunc )( QVariantMap &, const QgsPathResolver &, bool ) SIP_SKIP;
103typedef void ( *QgsSymbolLayerFontResolverFunc )( const QVariantMap &, const QgsReadWriteContext & ) SIP_SKIP;
104
110{
111 public:
113 QgsSymbolLayerMetadata( const QString &name, const QString &visibleName,
116 QgsSymbolLayerCreateFromSldFunc pfCreateFromSld = nullptr,
117 QgsSymbolLayerPathResolverFunc pfPathResolver = nullptr,
118 QgsSymbolLayerWidgetFunc pfWidget = nullptr,
119 QgsSymbolLayerFontResolverFunc pfFontResolver = nullptr ) SIP_SKIP
121 , mCreateFunc( pfCreate )
122 , mWidgetFunc( pfWidget )
123 , mCreateFromSldFunc( pfCreateFromSld )
124 , mPathResolverFunc( pfPathResolver )
125 , mFontResolverFunc( pfFontResolver )
126 {}
127
136
139
140 QgsSymbolLayer *createSymbolLayer( const QVariantMap &map ) override SIP_FACTORY { return mCreateFunc ? mCreateFunc( map ) : nullptr; }
142 QgsSymbolLayer *createSymbolLayerFromSld( QDomElement &elem ) override SIP_FACTORY { return mCreateFromSldFunc ? mCreateFromSldFunc( elem ) : nullptr; }
143 void resolvePaths( QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving ) override
144 {
145 if ( mPathResolverFunc )
146 mPathResolverFunc( properties, pathResolver, saving );
147 }
148
149 void resolveFonts( const QVariantMap &properties, const QgsReadWriteContext &context ) override
150 {
151 if ( mFontResolverFunc )
152 mFontResolverFunc( properties, context );
153 }
154
155 protected:
160
167
168 private:
169#ifdef SIP_RUN
171#endif
172};
173
174
182class CORE_EXPORT QgsSymbolLayerRegistry
183{
184 public:
185
188
191
193 QgsSymbolLayerAbstractMetadata *symbolLayerMetadata( const QString &name ) const;
194
197
203
205 std::unique_ptr< QgsSymbolLayer > createSymbolLayer( const QString &name, const QVariantMap &properties = QVariantMap() ) const;
206
208 std::unique_ptr< QgsSymbolLayer > createSymbolLayerFromSld( const QString &name, QDomElement &element ) const;
209
215 void resolvePaths( const QString &name, QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving ) const;
216
225 void resolveFonts( const QString &name, QVariantMap &properties, const QgsReadWriteContext &context ) const;
226
228 QStringList symbolLayersForType( Qgis::SymbolType type );
229
231 static std::unique_ptr< QgsSymbolLayer > defaultSymbolLayer( Qgis::SymbolType type );
232
233 private:
234#ifdef SIP_RUN
236#endif
237
238 QMap<QString, QgsSymbolLayerAbstractMetadata *> mMetadata;
239};
240
241#endif
SymbolType
Symbol types.
Definition qgis.h:610
Resolves relative paths into absolute paths and vice versa.
A container for the context for various read/write operations on objects.
Stores metadata about one symbol layer class.
virtual QgsSymbolLayer * createSymbolLayer(const QVariantMap &map)=0
Create a symbol layer of this type given the map of properties.
virtual void resolveFonts(const QVariantMap &properties, const QgsReadWriteContext &context)
Resolve fonts from the symbol layer's properties.
QgsSymbolLayerAbstractMetadata(const QString &name, const QString &visibleName, Qgis::SymbolType type)
Constructor for QgsSymbolLayerAbstractMetadata.
virtual ~QgsSymbolLayerAbstractMetadata()=default
virtual QgsSymbolLayerWidget * createSymbolLayerWidget(QgsVectorLayer *)
Create widget for symbol layer of this type. Can return nullptr if there's no GUI.
virtual QgsSymbolLayer * createSymbolLayerFromSld(QDomElement &)
Create a symbol layer of this type given the map of properties.
virtual void resolvePaths(QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving)
Resolve paths in symbol layer's properties (if there are any paths).
QgsSymbolLayerCreateFunc mCreateFunc
QgsSymbolLayer * createSymbolLayer(const QVariantMap &map) override
Create a symbol layer of this type given the map of properties.
void resolveFonts(const QVariantMap &properties, const QgsReadWriteContext &context) override
Resolve fonts from the symbol layer's properties.
QgsSymbolLayerCreateFromSldFunc mCreateFromSldFunc
QgsSymbolLayerCreateFromSldFunc createFromSldFunction() const
QgsSymbolLayer * createSymbolLayerFromSld(QDomElement &elem) override
Create a symbol layer of this type given the map of properties.
QgsSymbolLayerPathResolverFunc pathResolverFunction() const
QgsSymbolLayerCreateFunc createFunction() const
void setWidgetFunction(QgsSymbolLayerWidgetFunc f)
QgsSymbolLayerWidgetFunc mWidgetFunc
void resolvePaths(QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving) override
Resolve paths in symbol layer's properties (if there are any paths).
QgsSymbolLayerMetadata(const QString &name, const QString &visibleName, Qgis::SymbolType type, QgsSymbolLayerCreateFunc pfCreate, QgsSymbolLayerCreateFromSldFunc pfCreateFromSld=nullptr, QgsSymbolLayerPathResolverFunc pfPathResolver=nullptr, QgsSymbolLayerWidgetFunc pfWidget=nullptr, QgsSymbolLayerFontResolverFunc pfFontResolver=nullptr)
QgsSymbolLayerWidget * createSymbolLayerWidget(QgsVectorLayer *vl) override
Create widget for symbol layer of this type. Can return nullptr if there's no GUI.
QgsSymbolLayerFontResolverFunc mFontResolverFunc
Font resolver function pointer.
QgsSymbolLayerPathResolverFunc mPathResolverFunc
QgsSymbolLayerWidgetFunc widgetFunction() const
QgsSymbolLayerRegistry(const QgsSymbolLayerRegistry &rh)=delete
std::unique_ptr< QgsSymbolLayer > createSymbolLayerFromSld(const QString &name, QDomElement &element) const
create a new instance of symbol layer given symbol layer name and SLD
static std::unique_ptr< QgsSymbolLayer > defaultSymbolLayer(Qgis::SymbolType type)
create a new instance of symbol layer for specified symbol type with default settings
bool addSymbolLayerType(QgsSymbolLayerAbstractMetadata *metadata)
Registers a new symbol layer type. Takes ownership of the metadata instance.
QgsSymbolLayerRegistry & operator=(const QgsSymbolLayerRegistry &rh)=delete
QStringList symbolLayersForType(Qgis::SymbolType type)
Returns a list of available symbol layers for a specified symbol type.
void resolvePaths(const QString &name, QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving) const
Resolve paths in properties of a particular symbol layer.
void resolveFonts(const QString &name, QVariantMap &properties, const QgsReadWriteContext &context) const
Resolve fonts from the properties of a particular symbol layer.
QgsSymbolLayerAbstractMetadata * symbolLayerMetadata(const QString &name) const
Returns metadata for specified symbol layer. Returns nullptr if not found.
bool removeSymbolLayerType(QgsSymbolLayerAbstractMetadata *metadata)
Removes a symbol layer type.
std::unique_ptr< QgsSymbolLayer > createSymbolLayer(const QString &name, const QVariantMap &properties=QVariantMap()) const
create a new instance of symbol layer given symbol layer name and properties
Abstract base class for widgets used to configure QgsSymbolLayer classes.
Abstract base class for symbol layers.
Represents a vector layer which manages a vector based dataset.
#define SIP_EXTERNAL
Definition qgis_sip.h:124
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:84
void(* QgsSymbolLayerPathResolverFunc)(QVariantMap &, const QgsPathResolver &, bool)
QgsSymbolLayer *(* QgsSymbolLayerCreateFunc)(const QVariantMap &)
QgsSymbolLayer *(* QgsSymbolLayerCreateFromSldFunc)(QDomElement &)
QgsSymbolLayerWidget *(* QgsSymbolLayerWidgetFunc)(QgsVectorLayer *)
void(* QgsSymbolLayerFontResolverFunc)(const QVariantMap &, const QgsReadWriteContext &)