QGIS API Documentation 4.1.0-Master (3b8ef1f72a3)
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.h"
20#include "qgis_core.h"
21#include "qgis_sip.h"
22
23#include <QDomElement>
24#include <QIcon>
25#include <QMap>
26
30#ifndef SIP_RUN
32#endif
33
47{
48 public:
54 QgsMaterialSettingsAbstractMetadata( const QString &type, const QString &visibleName, const QIcon &icon = QIcon() )
55 : mType( type )
56 , mVisibleName( visibleName )
57 , mIcon( icon )
58 {}
59
61
65 QString type() const { return mType; }
66
70 QString visibleName() const { return mVisibleName; }
71
75 QIcon icon() const { return mIcon; }
76
83
87 virtual bool supportsTechnique( Qgis::MaterialRenderingTechnique technique ) const = 0;
88
89#ifndef SIP_RUN
90
98 virtual QgsMaterialSettingsWidget *createWidget() SIP_FACTORY { return nullptr; }
99
105 virtual const QgsAbstractMaterial3DHandler *material3DHandler() { return nullptr; }
106#endif
107
108 private:
109 QString mType;
110 QString mVisibleName;
111 QIcon mIcon;
112};
113
115typedef QgsAbstractMaterialSettings *( *QgsMaterialSettingsCreateFunc )() SIP_SKIP;
116
118typedef QgsMaterialSettingsWidget *( *QgsMaterialSettingsWidgetFunc )() SIP_SKIP;
119
122
123#ifndef SIP_RUN
124
134{
135 public:
145 const QString &type,
146 const QString &visibleName,
149 QgsMaterialSettingsWidgetFunc pfWidget = nullptr,
150 const QIcon &icon = QIcon()
151 )
153 , mCreateFunc( pfCreate )
154 , mSupportsTechniqueFunc( pfSupportsTechnique )
155 , mWidgetFunc( pfWidget )
156 {}
157
161 QgsMaterialSettingsCreateFunc createFunction() const { return mCreateFunc; }
162
168 QgsMaterialSettingsWidgetFunc widgetFunction() const { return mWidgetFunc; }
169
175 void setWidgetFunction( QgsMaterialSettingsWidgetFunc function ) { mWidgetFunc = function; }
176
182 const QgsAbstractMaterial3DHandler *handler() const { return mHandler; }
183
190
191 QgsAbstractMaterialSettings *create() override SIP_FACTORY { return mCreateFunc ? mCreateFunc() : nullptr; }
192 bool supportsTechnique( Qgis::MaterialRenderingTechnique technique ) const override { return mSupportsTechniqueFunc ? mSupportsTechniqueFunc( technique ) : true; }
193 QgsMaterialSettingsWidget *createWidget() override SIP_FACTORY { return mWidgetFunc ? mWidgetFunc() : nullptr; }
194
195 private:
197 QgsMaterialSettingsSupportsTechniqueFunc mSupportsTechniqueFunc;
199 QgsAbstractMaterial3DHandler *mHandler = nullptr;
200};
201#endif
202
203
213class CORE_EXPORT QgsMaterialRegistry
214{
215 public:
218
221
226 bool populate();
227
230
234 QStringList materialSettingsTypes() const;
235
238
246 std::unique_ptr< QgsAbstractMaterialSettings > createMaterialSettings( const QString &type ) const;
247
248 private:
249#ifdef SIP_RUN
251#endif
252
253 QMap<QString, QgsMaterialSettingsAbstractMetadata *> mMetadata;
255 QStringList mMaterialsOrder;
256};
257
258
259#endif // QGSMATERIALREGISTRY_H
MaterialRenderingTechnique
Material rendering techniques.
Definition qgis.h:4327
Abstract base class for material 3D handlers.
Abstract base class for material settings.
QgsMaterialRegistry(const QgsMaterialRegistry &rh)=delete
bool addMaterialSettingsType(QgsMaterialSettingsAbstractMetadata *metadata)
Registers a new material settings type. Takes ownership of the metadata instance.
QgsMaterialSettingsAbstractMetadata * materialSettingsMetadata(const QString &type) const
Returns metadata for specified material settings type. Returns nullptr if not found.
bool populate()
Populates the registry with standard material types.
std::unique_ptr< QgsAbstractMaterialSettings > createMaterialSettings(const QString &type) const
Creates a new instance of the material settings of the specified type.
QStringList materialSettingsTypes() const
Returns a list of all available material settings types.
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 ~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 bool supportsTechnique(Qgis::MaterialRenderingTechnique technique) const =0
Returns true if the material type supports the specified rendering technique.
virtual QgsAbstractMaterialSettings * create()=0
Creates a new instance of this material settings type.
virtual const QgsAbstractMaterial3DHandler * material3DHandler()
Returns 3D handler relating to the material.
virtual QgsMaterialSettingsWidget * createWidget()
Create a widget for configuring a material of this type.
QgsAbstractMaterialSettings * create() override
Creates a new instance of this material settings type.
void setWidgetFunction(QgsMaterialSettingsWidgetFunc function)
Sets the material settings' widget creation function.
bool supportsTechnique(Qgis::MaterialRenderingTechnique technique) const override
Returns true if the material type supports the specified rendering technique.
QgsMaterialSettingsWidgetFunc widgetFunction() const
Returns the material settings' widget creation function.
QgsMaterialSettingsWidget * createWidget() override
Create a widget for configuring a material of this type.
const QgsAbstractMaterial3DHandler * handler() const
Returns the material settings' 3D handler.
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 settings' creation function.
void setHandler(QgsAbstractMaterial3DHandler *handler)
Sets the material settings' 3D handler.
Base class for 3D material settings widgets.
A container for the context for various read/write operations on objects.
#define SIP_EXTERNAL
Definition qgis_sip.h:123
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_FACTORY
Definition qgis_sip.h:83
QgsMaterialSettingsWidget *(* QgsMaterialSettingsWidgetFunc)()
Material settings widget creation function.
bool(* QgsMaterialSettingsSupportsTechniqueFunc)(Qgis::MaterialRenderingTechnique)
Material settings supports technique function.
QgsAbstractMaterialSettings *(* QgsMaterialSettingsCreateFunc)()
Material settings creation function.