QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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
Qgs3DSymbolMetadata::Qgs3DSymbolMetadata
Qgs3DSymbolMetadata(const QString &type, const QString &visibleName, Qgs3DSymbolCreateFunc pfCreate, Qgs3DSymbolWidgetFunc pfWidget=nullptr, Qgs3DSymbolFeatureHandlerFunc pfHandler=nullptr)
Constructor for Qgs3DSymbolMetadata, with the specified type and visibleName.
Definition: qgs3dsymbolregistry.h:127
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
Qgs3DSymbolMetadata::createFeatureHandler
QgsFeature3DHandler * createFeatureHandler(QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol) override
Creates a feature handler for a symbol of matching type, for the specified vector layer.
Definition: qgs3dsymbolregistry.h:163
Qgs3DSymbolAbstractMetadata
Stores metadata about one 3D symbol class.
Definition: qgs3dsymbolregistry.h:41
Qgs3DSymbolMetadata::createSymbolWidget
Qgs3DSymbolWidget * createSymbolWidget(QgsVectorLayer *vl) override
Create a widget for configuring a symbol of this type.
Definition: qgs3dsymbolregistry.h:162
Qgs3DSymbolMetadata::createFunction
Qgs3DSymbolCreateFunc createFunction() const
Returns the symbol type's creation function.
Definition: qgs3dsymbolregistry.h:140
Qgs3DSymbolFeatureHandlerFunc
QgsFeature3DHandler *(* Qgs3DSymbolFeatureHandlerFunc)(QgsVectorLayer *, const QgsAbstract3DSymbol *)
3D symbol widget creation function
Definition: qgs3dsymbolregistry.h:102
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
Qgs3DSymbolWidgetFunc
Qgs3DSymbolWidget *(* Qgs3DSymbolWidgetFunc)(QgsVectorLayer *)
3D symbol widget creation function
Definition: qgs3dsymbolregistry.h:105
QgsAbstract3DSymbol
Abstract base class for 3D symbols that are used by VectorLayer3DRenderer objects.
Definition: qgsabstract3dsymbol.h:46
Qgs3DSymbolMetadata::setWidgetFunction
void setWidgetFunction(Qgs3DSymbolWidgetFunc function)
Sets the symbol type's widget creation function.
Definition: qgs3dsymbolregistry.h:154
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
Qgs3DSymbolMetadata::setFeatureHandlerFunction
void setFeatureHandlerFunction(Qgs3DSymbolFeatureHandlerFunc function)
Sets the symbol type's feature handler creation function.
Definition: qgs3dsymbolregistry.h:159
Qgs3DSymbolMetadata::create
QgsAbstract3DSymbol * create() override
Creates a new instance of this symbol type.
Definition: qgs3dsymbolregistry.h:161
Qgs3DSymbolAbstractMetadata::createFeatureHandler
virtual QgsFeature3DHandler * createFeatureHandler(QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol)
Creates a feature handler for a symbol of matching type, for the specified vector layer.
Definition: qgs3dsymbolregistry.h:90
Qgs3DSymbolAbstractMetadata::createSymbolWidget
virtual Qgs3DSymbolWidget * createSymbolWidget(QgsVectorLayer *)
Create a widget for configuring a symbol of this type.
Definition: qgs3dsymbolregistry.h:81
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Qgs3DSymbolAbstractMetadata::Qgs3DSymbolAbstractMetadata
Qgs3DSymbolAbstractMetadata(const QString &type, const QString &visibleName)
Constructor for Qgs3DSymbolAbstractMetadata, with the specified type and visibleName.
Definition: qgs3dsymbolregistry.h:48
Qgs3DSymbolWidget
Base class for 3D symbol configuration widgets.
Definition: qgs3dsymbolwidget.h:34
Qgs3DSymbolAbstractMetadata::visibleName
QString visibleName() const
Returns the symbol's visible (translated) name.
Definition: qgs3dsymbolregistry.h:63
Qgs3DSymbolMetadata::widgetFunction
Qgs3DSymbolWidgetFunc widgetFunction() const
Returns the symbol type's widget creation function.
Definition: qgs3dsymbolregistry.h:147
Qgs3DSymbolCreateFunc
QgsAbstract3DSymbol *(* Qgs3DSymbolCreateFunc)()
3D symbol creation function
Definition: qgs3dsymbolregistry.h:99
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:140
Qgs3DSymbolRegistry
Registry of available 3D symbol classes.
Definition: qgs3dsymbolregistry.h:183
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
qgswkbtypes.h
Qgs3DSymbolAbstractMetadata::type
QString type() const
Returns the unique symbol type string.
Definition: qgs3dsymbolregistry.h:58
Qgs3DSymbolMetadata
Convenience metadata class that uses static functions to create a 3D symbol and its widget.
Definition: qgs3dsymbolregistry.h:117