QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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:
48 QgsMaterialSettingsAbstractMetadata( const QString &type, const QString &visibleName, const QIcon &icon = QIcon() )
49 : mType( type )
50 , mVisibleName( visibleName )
51 , mIcon( icon )
52 {}
53
55
59 QString type() const { return mType; }
60
64 QString visibleName() const { return mVisibleName; }
65
69 QIcon icon() const { return mIcon; }
70
77
81 virtual bool supportsTechnique( QgsMaterialSettingsRenderingTechnique technique ) const = 0;
82
83#ifndef SIP_RUN
84
92 virtual QgsMaterialSettingsWidget *createWidget() SIP_FACTORY { return nullptr; }
93#endif
94
95 private:
96 QString mType;
97 QString mVisibleName;
98 QIcon mIcon;
99};
100
102typedef QgsAbstractMaterialSettings *( *QgsMaterialSettingsCreateFunc )() SIP_SKIP;
103
105typedef QgsMaterialSettingsWidget *( *QgsMaterialSettingsWidgetFunc )() SIP_SKIP;
106
109
110#ifndef SIP_RUN
111
121{
122 public:
131 QgsMaterialSettingsMetadata( const QString &type, const QString &visibleName, QgsMaterialSettingsCreateFunc pfCreate, QgsMaterialSettingsSupportsTechniqueFunc pfSupportsTechnique, QgsMaterialSettingsWidgetFunc pfWidget = nullptr, const QIcon &icon = QIcon() )
132 : QgsMaterialSettingsAbstractMetadata( type, visibleName, icon )
133 , mCreateFunc( pfCreate )
134 , mSupportsTechniqueFunc( pfSupportsTechnique )
135 , mWidgetFunc( pfWidget )
136 {}
137
141 QgsMaterialSettingsCreateFunc createFunction() const { return mCreateFunc; }
142
148 QgsMaterialSettingsWidgetFunc widgetFunction() const { return mWidgetFunc; }
149
155 void setWidgetFunction( QgsMaterialSettingsWidgetFunc function ) { mWidgetFunc = function; }
156
157 QgsAbstractMaterialSettings *create() override SIP_FACTORY { return mCreateFunc ? mCreateFunc() : nullptr; }
158 bool supportsTechnique( QgsMaterialSettingsRenderingTechnique technique ) const override { return mSupportsTechniqueFunc ? mSupportsTechniqueFunc( technique ) : true; }
159 QgsMaterialSettingsWidget *createWidget() override SIP_FACTORY { return mWidgetFunc ? mWidgetFunc() : nullptr; }
160
161 private:
163 QgsMaterialSettingsSupportsTechniqueFunc mSupportsTechniqueFunc;
165};
166#endif
167
168
178class _3D_EXPORT QgsMaterialRegistry
179{
180 public:
183
186
188 QgsMaterialSettingsAbstractMetadata *materialSettingsMetadata( const QString &type ) const;
189
193 QStringList materialSettingsTypes() const;
194
196 bool addMaterialSettingsType( QgsMaterialSettingsAbstractMetadata *metadata SIP_TRANSFER );
197
205 QgsAbstractMaterialSettings *createMaterialSettings( const QString &type ) const SIP_FACTORY;
206
207 private:
208#ifdef SIP_RUN
210#endif
211
212 QMap<QString, QgsMaterialSettingsAbstractMetadata *> mMetadata;
214 QStringList mMaterialsOrder;
215};
216
217
218#endif // QGSMATERIALREGISTRY_H
Registry of available 3d material settings classes.
QgsMaterialRegistry(const QgsMaterialRegistry &rh)=delete
QgsMaterialRegistry & operator=(const QgsMaterialRegistry &rh)=delete
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.