QGIS API Documentation 4.3.0-Master (0cfde48c85b)
Loading...
Searching...
No Matches
qgsmaterialregistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaterialregistry.cpp
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#include "qgsmaterialregistry.h"
17
19#include "qgsapplication.h"
28
29#include <QString>
30
31using namespace Qt::StringLiterals;
32
34{
35 return mCreateFunc ? mCreateFunc().release() : nullptr;
36}
37
40
42{
43 qDeleteAll( mMetadata );
44}
45
47{
48 if ( !mMetadata.empty() )
49 return false;
50
52 new QgsMaterialSettingsMetadata( u"null"_s, QObject::tr( "Embedded Textures" ), QgsNullMaterialSettings::create, QgsNullMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( u"/mIconPhongTexturedMaterial.svg"_s ) )
53 );
55 new QgsMaterialSettingsMetadata( u"metalrough"_s, QObject::tr( "Physically Based" ), QgsMetalRoughMaterialSettings::create, QgsMetalRoughMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( u"/mIconGoochMaterial.svg"_s ) )
56 );
58 u"metalroughtextured"_s,
59 QObject::tr( "Physically Based (with textures)" ),
62 nullptr,
63 QgsApplication::getThemeIcon( u"/mIconPhongTexturedMaterial.svg"_s )
64 ) );
66 new QgsMaterialSettingsMetadata( u"gooch"_s, QObject::tr( "CAD (Gooch)" ), QgsGoochMaterialSettings::create, QgsGoochMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( u"/mIconGoochMaterial.svg"_s ) )
67 );
68
70 new QgsMaterialSettingsMetadata( u"phong"_s, QObject::tr( "Legacy (Phong)" ), QgsPhongMaterialSettings::create, QgsPhongMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( u"/mIconPhongMaterial.svg"_s ) )
71 );
73 new QgsMaterialSettingsMetadata( u"phongtextured"_s, QObject::tr( "Legacy Textured (Phong)" ), QgsPhongTexturedMaterialSettings::create, QgsPhongTexturedMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( u"/mIconPhongTexturedMaterial.svg"_s ) )
74 );
76 new QgsMaterialSettingsMetadata( u"simpleline"_s, QObject::tr( "Single Color Lines (Unlit)" ), QgsSimpleLineMaterialSettings::create, QgsSimpleLineMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( u"/mIconSimpleLineMaterial.svg"_s ) )
77 );
79 new QgsMaterialSettingsMetadata( u"unlit"_s, QObject::tr( "Single Color (Unlit)" ), QgsUnlitMaterialSettings::create, QgsUnlitMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( u"/mIconUnlitMaterial.svg"_s ) )
80 );
81
82 return true;
83}
84
86{
87 if ( !metadata || mMetadata.contains( metadata->type() ) )
88 return false;
89
90 mMetadata[metadata->type()] = metadata;
91 mMaterialsOrder << metadata->type();
92 return true;
93}
94
95std::unique_ptr< QgsAbstractMaterialSettings > QgsMaterialRegistry::createMaterialSettings( const QString &type ) const
96{
97 if ( !mMetadata.contains( type ) )
98 return nullptr;
99
100 return std::unique_ptr< QgsAbstractMaterialSettings >( mMetadata[type]->create() );
101}
102
104{
105 return mMetadata.value( type );
106}
107
109{
110 QStringList types;
111 for ( const QString &material : mMaterialsOrder )
112 {
113 if ( mMetadata.value( material ) )
114 types << material;
115 }
116 return types;
117}
Abstract base class for material settings.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static bool supportsTechnique(Qgis::MaterialRenderingTechnique technique)
Returns true if the specified technique is supported by the Gooch material.
static std::unique_ptr< QgsAbstractMaterialSettings > create()
Returns a new instance of QgsGoochMaterialSettings.
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.
Stores metadata about one 3D material settings class.
QString type() const
Returns the unique material type string.
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.
static std::unique_ptr< QgsAbstractMaterialSettings > create()
Returns a new instance of QgsMetalRoughMaterialSettings.
static bool supportsTechnique(Qgis::MaterialRenderingTechnique technique)
Returns true if the specified technique is supported by the metal rough material.
static std::unique_ptr< QgsAbstractMaterialSettings > create()
Returns a new instance of QgsMetalRoughTexturedMaterialSettings.
static bool supportsTechnique(Qgis::MaterialRenderingTechnique technique)
Returns true if the specified technique is supported by the metal rough material.
static bool supportsTechnique(Qgis::MaterialRenderingTechnique technique)
Returns true if the specified technique is supported by the material.
static std::unique_ptr< QgsAbstractMaterialSettings > create()
Returns a new instance of QgsNullMaterialSettings.
static std::unique_ptr< QgsAbstractMaterialSettings > create()
Returns a new instance of QgsPhongMaterialSettings.
static bool supportsTechnique(Qgis::MaterialRenderingTechnique technique)
Returns true if the specified technique is supported by the Phong material.
static bool supportsTechnique(Qgis::MaterialRenderingTechnique technique)
Returns true if the specified technique is supported by the Phong material.
static std::unique_ptr< QgsAbstractMaterialSettings > create()
Returns a new instance of QgsPhongTexturedMaterialSettings.
static bool supportsTechnique(Qgis::MaterialRenderingTechnique technique)
Returns true if the specified technique is supported by the material.
static std::unique_ptr< QgsAbstractMaterialSettings > create()
Returns a new instance of QgsSimpleLineMaterialSettings.
static std::unique_ptr< QgsAbstractMaterialSettings > create()
Returns a new instance of QgsUnlitMaterialSettings.
static bool supportsTechnique(Qgis::MaterialRenderingTechnique technique)
Returns true if the specified technique is supported by the material.