QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
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
103typedef QgsAbstractMaterialSettings *( *QgsMaterialSettingsCreateFunc )() SIP_SKIP;
104
106typedef QgsMaterialSettingsWidget *( *QgsMaterialSettingsWidgetFunc )() SIP_SKIP;
107
110
111#ifndef SIP_RUN
112
122{
123 public:
124
133 QgsMaterialSettingsMetadata( const QString &type, const QString &visibleName,
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:
169 QgsMaterialSettingsSupportsTechniqueFunc mSupportsTechniqueFunc;
171
172};
173#endif
174
175
185class _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;
224 QStringList mMaterialsOrder;
225};
226
227
228#endif // QGSMATERIALREGISTRY_H
Registry of available 3d material settings classes.
QgsMaterialRegistry(const QgsMaterialRegistry &rh)=delete
QgsMaterialRegistry cannot be copied.
QgsMaterialRegistry & operator=(const QgsMaterialRegistry &rh)=delete
QgsMaterialRegistry cannot be copied.
Stores metadata about one 3D material settings class.
QString visibleName() const
Returns the material's visible (translated) name.
QString type() const
Returns the unique material type string.
virtual bool supportsTechnique(QgsMaterialSettingsRenderingTechnique technique) const =0
Returns true if the material type supports the specified rendering technique.
virtual ~QgsMaterialSettingsAbstractMetadata()=default
QgsMaterialSettingsAbstractMetadata(const QString &type, const QString &visibleName, const QIcon &icon=QIcon())
Constructor for QgsMaterialSettingsAbstractMetadata, with the specified type and visibleName.
QIcon icon() const
Returns an icon representing the material type, if available.
virtual QgsAbstractMaterialSettings * create()=0
Creates a new instance of this material settings type.
virtual QgsMaterialSettingsWidget * createWidget()
Create a widget for configuring a material of this type.
Convenience metadata class that uses static functions to create a 3D material settings object and its...
QgsAbstractMaterialSettings * create() override
Creates a new instance of this material settings type.
void setWidgetFunction(QgsMaterialSettingsWidgetFunc function)
Sets the material settings's widget creation function.
QgsMaterialSettingsWidgetFunc widgetFunction() const
Returns the material settings's widget creation function.
QgsMaterialSettingsWidget * createWidget() override
Create a widget for configuring a material of this type.
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.
QgsMaterialSettingsCreateFunc createFunction() const
Returns the material setting's creation function.
bool supportsTechnique(QgsMaterialSettingsRenderingTechnique technique) const override
Returns true if the material type supports the specified rendering technique.
Base class for 3D material settings widgets.
The class is used as a container of context for various read/write operations on other objects.
QgsMaterialSettingsRenderingTechnique
Material rendering techniques 3.
#define SIP_EXTERNAL
Definition: qgis_sip.h:116
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsMaterialSettingsWidget *(* QgsMaterialSettingsWidgetFunc)()
Material settings widget creation function.
bool(* QgsMaterialSettingsSupportsTechniqueFunc)(QgsMaterialSettingsRenderingTechnique)
Material settings supports technique function.
QgsAbstractMaterialSettings *(* QgsMaterialSettingsCreateFunc)()
Material settings creation function.