QGIS API Documentation  3.17.0-Master (a84647cf30)
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 
70  virtual QgsAbstract3DSymbol *create() = 0 SIP_FACTORY;
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 
191  Qgs3DSymbolRegistry( const Qgs3DSymbolRegistry &rh ) = delete;
193  Qgs3DSymbolRegistry &operator=( const Qgs3DSymbolRegistry &rh ) = delete;
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
Qgs3DSymbolAbstractMetadata(const QString &type, const QString &visibleName)
Constructor for Qgs3DSymbolAbstractMetadata, with the specified type and visibleName.
The class is used as a container of context for various read/write operations on other objects...
QgsFeature3DHandler *(* Qgs3DSymbolFeatureHandlerFunc)(QgsVectorLayer *, const QgsAbstract3DSymbol *)
3D symbol widget creation function
Qgs3DSymbolWidgetFunc widgetFunction() const
Returns the symbol type&#39;s widget creation function.
Base class for 3D symbol configuration widgets.
Registry of available 3D symbol classes.
Qgs3DSymbolCreateFunc createFunction() const
Returns the symbol type&#39;s creation function.
void setWidgetFunction(Qgs3DSymbolWidgetFunc function)
Sets the symbol type&#39;s widget creation function.
QString visibleName() const
Returns the symbol&#39;s visible (translated) name.
Qgs3DSymbolWidget *(* Qgs3DSymbolWidgetFunc)(QgsVectorLayer *)
3D symbol widget creation function
Stores metadata about one 3D symbol class.
3 Abstract base class for 3D symbols that are used by VectorLayer3DRenderer objects.
virtual QgsFeature3DHandler * createFeatureHandler(QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol)
Creates a feature handler for a symbol of matching type, for the specified vector layer...
QgsFeature3DHandler * createFeatureHandler(QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol) override
Creates a feature handler for a symbol of matching type, for the specified vector layer...
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Convenience metadata class that uses static functions to create a 3D symbol and its widget...
#define SIP_FACTORY
Definition: qgis_sip.h:76
QString type() const
Returns the unique symbol type string.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:140
QgsAbstract3DSymbol * create() override
Creates a new instance of this symbol type.
void setFeatureHandlerFunction(Qgs3DSymbolFeatureHandlerFunc function)
Sets the symbol type&#39;s feature handler creation function.
virtual Qgs3DSymbolWidget * createSymbolWidget(QgsVectorLayer *)
Create a widget for configuring a symbol of this type.
Qgs3DSymbolMetadata(const QString &type, const QString &visibleName, Qgs3DSymbolCreateFunc pfCreate, Qgs3DSymbolWidgetFunc pfWidget=nullptr, Qgs3DSymbolFeatureHandlerFunc pfHandler=nullptr)
Constructor for Qgs3DSymbolMetadata, with the specified type and visibleName.
Qgs3DSymbolWidget * createSymbolWidget(QgsVectorLayer *vl) override
Create a widget for configuring a symbol of this type.
QgsAbstract3DSymbol *(* Qgs3DSymbolCreateFunc)()
3D symbol creation function
Represents a vector layer which manages a vector based data sets.