QGIS API Documentation 4.1.0-Master (3b8ef1f72a3)
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"
27
28#include <QString>
29
30using namespace Qt::StringLiterals;
31
34
36{
37 qDeleteAll( mMetadata );
38}
39
41{
42 if ( !mMetadata.empty() )
43 return false;
44
46 new QgsMaterialSettingsMetadata( u"null"_s, QObject::tr( "Embedded Textures" ), QgsNullMaterialSettings::create, QgsNullMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( u"/mIconPhongTexturedMaterial.svg"_s ) )
47 );
49 new QgsMaterialSettingsMetadata( u"phong"_s, QObject::tr( "Realistic (Phong)" ), QgsPhongMaterialSettings::create, QgsPhongMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( u"/mIconPhongMaterial.svg"_s ) )
50 );
52 new QgsMaterialSettingsMetadata( u"phongtextured"_s, QObject::tr( "Realistic with Textures (Phong)" ), QgsPhongTexturedMaterialSettings::create, QgsPhongTexturedMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( u"/mIconPhongTexturedMaterial.svg"_s ) )
53 );
55 new QgsMaterialSettingsMetadata( u"simpleline"_s, QObject::tr( "Single Color (Unlit)" ), QgsSimpleLineMaterialSettings::create, QgsSimpleLineMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( u"/mIconSimpleLineMaterial.svg"_s ) )
56 );
58 new QgsMaterialSettingsMetadata( u"gooch"_s, QObject::tr( "CAD (Gooch)" ), QgsGoochMaterialSettings::create, QgsGoochMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( u"/mIconGoochMaterial.svg"_s ) )
59 );
61 new QgsMaterialSettingsMetadata( u"metalrough"_s, QObject::tr( "Physically Based" ), QgsMetalRoughMaterialSettings::create, QgsMetalRoughMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( u"/mIconGoochMaterial.svg"_s ) )
62 );
64 u"metalroughtextured"_s,
65 QObject::tr( "Physically Based with Textures" ),
68 nullptr,
69 QgsApplication::getThemeIcon( u"/mIconPhongTexturedMaterial.svg"_s )
70 ) );
71 return true;
72}
73
75{
76 if ( !metadata || mMetadata.contains( metadata->type() ) )
77 return false;
78
79 mMetadata[metadata->type()] = metadata;
80 mMaterialsOrder << metadata->type();
81 return true;
82}
83
84std::unique_ptr< QgsAbstractMaterialSettings > QgsMaterialRegistry::createMaterialSettings( const QString &type ) const
85{
86 if ( !mMetadata.contains( type ) )
87 return nullptr;
88
89 return std::unique_ptr< QgsAbstractMaterialSettings >( mMetadata[type]->create() );
90}
91
93{
94 return mMetadata.value( type );
95}
96
98{
99 QStringList types;
100 for ( const QString &material : mMaterialsOrder )
101 {
102 if ( mMetadata.value( material ) )
103 types << material;
104 }
105 return types;
106}
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 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...
static 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 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 QgsAbstractMaterialSettings * create()
Returns a new instance of QgsNullMaterialSettings.
static bool supportsTechnique(Qgis::MaterialRenderingTechnique technique)
Returns true if the specified technique is supported by the material.
static bool supportsTechnique(Qgis::MaterialRenderingTechnique technique)
Returns true if the specified technique is supported by the Phong material.
static 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 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 QgsAbstractMaterialSettings * create()
Returns a new instance of QgsSimpleLineMaterialSettings.