QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgs3dsymbolregistry.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgs3dsymbolregistry.h
3  --------------------------------------
4  Date : July 2020
5  Copyright : (C) 2020 by Nyall Dawson
6  Email : nyall dot dawson 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 QGS3DSYMBOLREGISTRY_H
17 #define QGS3DSYMBOLREGISTRY_H
18 
19 #include "qgis_core.h"
20 #include "qgis_sip.h"
21 #include "qgswkbtypes.h"
22 
23 #include <QDomElement>
24 #include <QMap>
25 
28 class Qgs3DSymbolWidget;
29 class QgsVectorLayer;
30 class QgsFeature3DHandler;
31 
41 class CORE_EXPORT Qgs3DSymbolAbstractMetadata
42 {
43  public:
44 
48  Qgs3DSymbolAbstractMetadata( const QString &type, const QString &visibleName )
49  : mType( type )
50  , mVisibleName( visibleName )
51  {}
52 
53  virtual ~Qgs3DSymbolAbstractMetadata() = default;
54 
58  QString type() const { return mType; }
59 
63  QString visibleName() const { return mVisibleName; }
64 
71 
72 #ifndef SIP_RUN
73 
82 
90  virtual QgsFeature3DHandler *createFeatureHandler( QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol ) SIP_FACTORY { Q_UNUSED( layer ); Q_UNUSED( symbol ); return nullptr; }
91 #endif
92 
93  private:
94  QString mType;
95  QString mVisibleName;
96 };
97 
99 typedef QgsAbstract3DSymbol *( *Qgs3DSymbolCreateFunc )() SIP_SKIP;
100 
102 typedef QgsFeature3DHandler *( *Qgs3DSymbolFeatureHandlerFunc )( QgsVectorLayer *, const QgsAbstract3DSymbol * ) SIP_SKIP;
103 
105 typedef Qgs3DSymbolWidget *( *Qgs3DSymbolWidgetFunc )( QgsVectorLayer * ) SIP_SKIP;
106 
107 #ifndef SIP_RUN
108 
118 {
119  public:
120 
127  Qgs3DSymbolMetadata( const QString &type, const QString &visibleName,
128  Qgs3DSymbolCreateFunc pfCreate,
129  Qgs3DSymbolWidgetFunc pfWidget = nullptr,
130  Qgs3DSymbolFeatureHandlerFunc pfHandler = nullptr ) SIP_SKIP
131  : Qgs3DSymbolAbstractMetadata( type, visibleName )
132  , mCreateFunc( pfCreate )
133  , mWidgetFunc( pfWidget )
134  , mFeatureHandlerFunc( pfHandler )
135  {}
136 
140  Qgs3DSymbolCreateFunc createFunction() const { return mCreateFunc; }
141 
147  Qgs3DSymbolWidgetFunc widgetFunction() const { return mWidgetFunc; }
148 
154  void setWidgetFunction( Qgs3DSymbolWidgetFunc function ) { mWidgetFunc = function; }
155 
159  void setFeatureHandlerFunction( Qgs3DSymbolFeatureHandlerFunc function ) { mFeatureHandlerFunc = function; }
160 
161  QgsAbstract3DSymbol *create() override SIP_FACTORY { return mCreateFunc ? mCreateFunc() : nullptr; }
162  Qgs3DSymbolWidget *createSymbolWidget( QgsVectorLayer *vl ) override SIP_FACTORY { return mWidgetFunc ? mWidgetFunc( vl ) : nullptr; }
163  QgsFeature3DHandler *createFeatureHandler( QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol ) override SIP_FACTORY { return mFeatureHandlerFunc ? mFeatureHandlerFunc( layer, symbol ) : nullptr; }
164 
165  private:
166  Qgs3DSymbolCreateFunc mCreateFunc;
167  Qgs3DSymbolWidgetFunc mWidgetFunc;
168  Qgs3DSymbolFeatureHandlerFunc mFeatureHandlerFunc;
169 
170 };
171 #endif
172 
173 
183 class CORE_EXPORT Qgs3DSymbolRegistry
184 {
185  public:
186 
189 
194 
196  Qgs3DSymbolAbstractMetadata *symbolMetadata( const QString &type ) const;
197 
201  QStringList symbolTypes() const;
202 
204  bool addSymbolType( Qgs3DSymbolAbstractMetadata *metadata SIP_TRANSFER );
205 
213  QgsAbstract3DSymbol *createSymbol( const QString &type ) const SIP_FACTORY;
214 
220  QgsAbstract3DSymbol *defaultSymbolForGeometryType( QgsWkbTypes::GeometryType type ) SIP_FACTORY;
221 
222 #ifndef SIP_RUN
223 
231  QgsFeature3DHandler *createHandlerForSymbol( QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol ) SIP_FACTORY;
232 #endif
233 
234  private:
235 #ifdef SIP_RUN
237 #endif
238 
239  QMap<QString, Qgs3DSymbolAbstractMetadata *> mMetadata;
240 };
241 
242 
243 #endif // QGS3DSYMBOLREGISTRY_H
Stores metadata about one 3D symbol class.
virtual Qgs3DSymbolWidget * createSymbolWidget(QgsVectorLayer *)
Create a widget for configuring a symbol of this type.
virtual ~Qgs3DSymbolAbstractMetadata()=default
QString visibleName() const
Returns the symbol's visible (translated) name.
Qgs3DSymbolAbstractMetadata(const QString &type, const QString &visibleName)
Constructor for Qgs3DSymbolAbstractMetadata, with the specified type and visibleName.
QString type() const
Returns the unique symbol type string.
virtual QgsAbstract3DSymbol * create()=0
Creates a new instance of this symbol type.
virtual QgsFeature3DHandler * createFeatureHandler(QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol)
Creates a feature handler for a symbol of matching type, for the specified vector layer.
Convenience metadata class that uses static functions to create a 3D symbol and its widget.
Qgs3DSymbolWidget * createSymbolWidget(QgsVectorLayer *vl) override
Create a widget for configuring a symbol of this type.
QgsFeature3DHandler * createFeatureHandler(QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol) override
Creates a feature handler for a symbol of matching type, for the specified vector layer.
QgsAbstract3DSymbol * create() override
Creates a new instance of this symbol type.
void setFeatureHandlerFunction(Qgs3DSymbolFeatureHandlerFunc function)
Sets the symbol type's feature handler creation function.
void setWidgetFunction(Qgs3DSymbolWidgetFunc function)
Sets the symbol type's widget creation function.
Qgs3DSymbolCreateFunc createFunction() const
Returns the symbol type's creation function.
Qgs3DSymbolWidgetFunc widgetFunction() const
Returns the symbol type's widget creation function.
Qgs3DSymbolMetadata(const QString &type, const QString &visibleName, Qgs3DSymbolCreateFunc pfCreate, Qgs3DSymbolWidgetFunc pfWidget=nullptr, Qgs3DSymbolFeatureHandlerFunc pfHandler=nullptr)
Constructor for Qgs3DSymbolMetadata, with the specified type and visibleName.
Registry of available 3D symbol classes.
Qgs3DSymbolRegistry & operator=(const Qgs3DSymbolRegistry &rh)=delete
Qgs3DSymbolRegistry cannot be copied.
Qgs3DSymbolRegistry(const Qgs3DSymbolRegistry &rh)=delete
Qgs3DSymbolRegistry cannot be copied.
Base class for 3D symbol configuration widgets.
The class is used as a container of context for various read/write operations on other objects.
Represents a vector layer which manages a vector based data sets.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76
Qgs3DSymbolWidget *(* Qgs3DSymbolWidgetFunc)(QgsVectorLayer *)
3D symbol widget creation function
QgsAbstract3DSymbol *(* Qgs3DSymbolCreateFunc)()
3D symbol creation function
QgsFeature3DHandler *(* Qgs3DSymbolFeatureHandlerFunc)(QgsVectorLayer *, const QgsAbstract3DSymbol *)
3D symbol widget creation function