QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsmaterialregistry.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaterialregistry.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 QGSMATERIALREGISTRY_H
17 #define QGSMATERIALREGISTRY_H
18 
19 #include "qgis_3d.h"
20 #include "qgis_sip.h"
21 
22 #include <QDomElement>
23 #include <QMap>
24 #include <QIcon>
25 
30 
41 {
42  public:
43 
49  QgsMaterialSettingsAbstractMetadata( const QString &type, const QString &visibleName, const QIcon &icon = QIcon() )
50  : mType( type )
51  , mVisibleName( visibleName )
52  , mIcon( icon )
53  {}
54 
56 
60  QString type() const { return mType; }
61 
65  QString visibleName() const { return mVisibleName; }
66 
70  QIcon icon() const { return mIcon; }
71 
78 
82  virtual bool supportsTechnique( QgsMaterialSettingsRenderingTechnique technique ) const = 0;
83 
84 #ifndef SIP_RUN
85 
93  virtual QgsMaterialSettingsWidget *createWidget() SIP_FACTORY { return nullptr; }
94 #endif
95 
96  private:
97  QString mType;
98  QString mVisibleName;
99  QIcon mIcon;
100 };
101 
103 typedef QgsAbstractMaterialSettings *( *QgsMaterialSettingsCreateFunc )() SIP_SKIP;
104 
106 typedef QgsMaterialSettingsWidget *( *QgsMaterialSettingsWidgetFunc )() SIP_SKIP;
107 
110 
111 #ifndef SIP_RUN
112 
122 {
123  public:
124 
133  QgsMaterialSettingsMetadata( const QString &type, const QString &visibleName,
135  QgsMaterialSettingsSupportsTechniqueFunc pfSupportsTechnique,
136  QgsMaterialSettingsWidgetFunc pfWidget = nullptr,
137  const QIcon &icon = QIcon() )
138  : QgsMaterialSettingsAbstractMetadata( type, visibleName, icon )
139  , mCreateFunc( pfCreate )
140  , mSupportsTechniqueFunc( pfSupportsTechnique )
141  , mWidgetFunc( pfWidget )
142  {}
143 
147  QgsMaterialSettingsCreateFunc createFunction() const { return mCreateFunc; }
148 
154  QgsMaterialSettingsWidgetFunc widgetFunction() const { return mWidgetFunc; }
155 
161  void setWidgetFunction( QgsMaterialSettingsWidgetFunc function ) { mWidgetFunc = function; }
162 
163  QgsAbstractMaterialSettings *create() override SIP_FACTORY { return mCreateFunc ? mCreateFunc() : nullptr; }
164  bool supportsTechnique( QgsMaterialSettingsRenderingTechnique technique ) const override { return mSupportsTechniqueFunc ? mSupportsTechniqueFunc( technique ) : true; }
165  QgsMaterialSettingsWidget *createWidget() override SIP_FACTORY { return mWidgetFunc ? mWidgetFunc() : nullptr; }
166 
167  private:
168  QgsMaterialSettingsCreateFunc mCreateFunc;
169  QgsMaterialSettingsSupportsTechniqueFunc mSupportsTechniqueFunc;
170  QgsMaterialSettingsWidgetFunc mWidgetFunc;
171 
172 };
173 #endif
174 
175 
185 class _3D_EXPORT QgsMaterialRegistry
186 {
187  public:
188 
191 
196 
198  QgsMaterialSettingsAbstractMetadata *materialSettingsMetadata( const QString &type ) const;
199 
203  QStringList materialSettingsTypes() const;
204 
206  bool addMaterialSettingsType( QgsMaterialSettingsAbstractMetadata *metadata SIP_TRANSFER );
207 
215  QgsAbstractMaterialSettings *createMaterialSettings( const QString &type ) const SIP_FACTORY;
216 
217  private:
218 #ifdef SIP_RUN
220 #endif
221 
222  QMap<QString, QgsMaterialSettingsAbstractMetadata *> mMetadata;
223 };
224 
225 
226 #endif // QGSMATERIALREGISTRY_H
QgsMaterialSettingsCreateFunc
QgsAbstractMaterialSettings *(* QgsMaterialSettingsCreateFunc)()
Material settings creation function.
Definition: qgsmaterialregistry.h:103
QgsMaterialRegistry::QgsMaterialRegistry
QgsMaterialRegistry(const QgsMaterialRegistry &rh)=delete
QgsMaterialRegistry cannot be copied.
QgsMaterialSettingsMetadata::createWidget
QgsMaterialSettingsWidget * createWidget() override
Create a widget for configuring a material of this type.
Definition: qgsmaterialregistry.h:165
QgsMaterialSettingsAbstractMetadata::icon
QIcon icon() const
Returns an icon representing the material type, if available.
Definition: qgsmaterialregistry.h:70
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsMaterialSettingsAbstractMetadata::create
virtual QgsAbstractMaterialSettings * create()=0
Creates a new instance of this material settings type.
QgsMaterialSettingsAbstractMetadata::QgsMaterialSettingsAbstractMetadata
QgsMaterialSettingsAbstractMetadata(const QString &type, const QString &visibleName, const QIcon &icon=QIcon())
Constructor for QgsMaterialSettingsAbstractMetadata, with the specified type and visibleName.
Definition: qgsmaterialregistry.h:49
QgsMaterialSettingsMetadata::setWidgetFunction
void setWidgetFunction(QgsMaterialSettingsWidgetFunc function)
Sets the material settings's widget creation function.
Definition: qgsmaterialregistry.h:161
QgsMaterialSettingsAbstractMetadata::type
QString type() const
Returns the unique material type string.
Definition: qgsmaterialregistry.h:60
QgsMaterialSettingsAbstractMetadata
Stores metadata about one 3D material settings class.
Definition: qgsmaterialregistry.h:41
QgsMaterialRegistry
Registry of available 3d material settings classes.
Definition: qgsmaterialregistry.h:186
QgsMaterialSettingsAbstractMetadata::visibleName
QString visibleName() const
Returns the material's visible (translated) name.
Definition: qgsmaterialregistry.h:65
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsMaterialSettingsMetadata
Convenience metadata class that uses static functions to create a 3D material settings object and its...
Definition: qgsmaterialregistry.h:122
QgsMaterialSettingsWidget
Base class for 3D material settings widgets.
Definition: qgsmaterialsettingswidget.h:37
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsMaterialSettingsMetadata::supportsTechnique
bool supportsTechnique(QgsMaterialSettingsRenderingTechnique technique) const override
Returns true if the material type supports the specified rendering technique.
Definition: qgsmaterialregistry.h:164
QgsAbstractMaterialSettings
3 Abstract base class for material settings.
Definition: qgsabstractmaterialsettings.h:105
QgsMaterialSettingsSupportsTechniqueFunc
bool(* QgsMaterialSettingsSupportsTechniqueFunc)(QgsMaterialSettingsRenderingTechnique)
Material settings supports technique function.
Definition: qgsmaterialregistry.h:109
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsMaterialSettingsAbstractMetadata::~QgsMaterialSettingsAbstractMetadata
virtual ~QgsMaterialSettingsAbstractMetadata()=default
QgsMaterialSettingsAbstractMetadata::supportsTechnique
virtual bool supportsTechnique(QgsMaterialSettingsRenderingTechnique technique) const =0
Returns true if the material type supports the specified rendering technique.
QgsMaterialSettingsRenderingTechnique
QgsMaterialSettingsRenderingTechnique
Material rendering techniques 3.
Definition: qgsabstractmaterialsettings.h:36
QgsMaterialSettingsMetadata::createFunction
QgsMaterialSettingsCreateFunc createFunction() const
Returns the material setting's creation function.
Definition: qgsmaterialregistry.h:147
QgsMaterialRegistry::operator=
QgsMaterialRegistry & operator=(const QgsMaterialRegistry &rh)=delete
QgsMaterialRegistry cannot be copied.
QgsMaterialSettingsWidgetFunc
QgsMaterialSettingsWidget *(* QgsMaterialSettingsWidgetFunc)()
Material settings widget creation function.
Definition: qgsmaterialregistry.h:106
QgsMaterialSettingsAbstractMetadata::createWidget
virtual QgsMaterialSettingsWidget * createWidget()
Create a widget for configuring a material of this type.
Definition: qgsmaterialregistry.h:93
QgsMaterialSettingsMetadata::widgetFunction
QgsMaterialSettingsWidgetFunc widgetFunction() const
Returns the material settings's widget creation function.
Definition: qgsmaterialregistry.h:154
SIP_EXTERNAL
#define SIP_EXTERNAL
Definition: qgis_sip.h:116
QgsMaterialSettingsMetadata::QgsMaterialSettingsMetadata
QgsMaterialSettingsMetadata(const QString &type, const QString &visibleName, QgsMaterialSettingsCreateFunc pfCreate, QgsMaterialSettingsSupportsTechniqueFunc pfSupportsTechnique, QgsMaterialSettingsWidgetFunc pfWidget=nullptr, const QIcon &icon=QIcon())
Constructor for QgsMaterialSettingsMetadata, with the specified type and visibleName.
Definition: qgsmaterialregistry.h:133
QgsMaterialSettingsMetadata::create
QgsAbstractMaterialSettings * create() override
Creates a new instance of this material settings type.
Definition: qgsmaterialregistry.h:163