QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgssimplelinematerialsettings.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssimplelinematerialsettings.cpp
3  --------------------------------------
4  Date : August 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 
17 #include "qgssymbollayerutils.h"
18 #include "qgslinematerial_p.h"
19 #include <Qt3DRender/QTexture>
20 #include <Qt3DRender/QParameter>
21 #include <Qt3DRender/QEffect>
22 #include <QMap>
23 
24 
26 {
27  return QStringLiteral( "simpleline" );
28 }
29 
31 {
32  switch ( technique )
33  {
34  case QgsMaterialSettingsRenderingTechnique::Lines:
35  return true;
36 
37  case QgsMaterialSettingsRenderingTechnique::Triangles:
38  case QgsMaterialSettingsRenderingTechnique::InstancedPoints:
41  return false;
42  }
43  return false;
44 }
45 
47 {
48  return new QgsSimpleLineMaterialSettings();
49 }
50 
52 {
53  return new QgsSimpleLineMaterialSettings( *this );
54 }
55 
56 void QgsSimpleLineMaterialSettings::readXml( const QDomElement &elem, const QgsReadWriteContext & )
57 {
58  mAmbient = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "ambient" ), QStringLiteral( "25,25,25" ) ) );
59 }
60 
61 void QgsSimpleLineMaterialSettings::writeXml( QDomElement &elem, const QgsReadWriteContext & ) const
62 {
63  elem.setAttribute( QStringLiteral( "ambient" ), QgsSymbolLayerUtils::encodeColor( mAmbient ) );
64 }
65 
67 {
68  switch ( technique )
69  {
70  case QgsMaterialSettingsRenderingTechnique::Triangles:
71  case QgsMaterialSettingsRenderingTechnique::InstancedPoints:
74  return nullptr;
75 
76  case QgsMaterialSettingsRenderingTechnique::Lines:
77  {
78  QgsLineMaterial *mat = new QgsLineMaterial;
79  mat->setLineColor( mAmbient );
80  if ( context.isSelected() )
81  {
82  // update the material with selection colors
83  mat->setLineColor( context.selectionColor() );
84  }
85  return mat;
86  }
87  }
88  return nullptr;
89 }
90 
92 {
93  QMap<QString, QString> parameters;
94  parameters[ QStringLiteral( "Ka" ) ] = QStringLiteral( "%1 %2 %3" ).arg( mAmbient.redF() ).arg( mAmbient.greenF() ).arg( mAmbient.blueF() );
95  return parameters;
96 }
97 
98 void QgsSimpleLineMaterialSettings::addParametersToEffect( Qt3DRender::QEffect *effect ) const
99 {
100  Qt3DRender::QParameter *ambientParameter = new Qt3DRender::QParameter( QStringLiteral( "ka" ), QColor::fromRgbF( 0.05f, 0.05f, 0.05f, 1.0f ) );
101  ambientParameter->setValue( mAmbient );
102  effect->addParameter( ambientParameter );
103 }
QgsSymbolLayerUtils::encodeColor
static QString encodeColor(const QColor &color)
Definition: qgssymbollayerutils.cpp:52
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
qgssymbollayerutils.h
QgsSimpleLineMaterialSettings::create
static QgsAbstractMaterialSettings * create()
Returns a new instance of QgsSimpleLineMaterialSettings.
Definition: qgssimplelinematerialsettings.cpp:46
QgsSymbolLayerUtils::decodeColor
static QColor decodeColor(const QString &str)
Definition: qgssymbollayerutils.cpp:57
QgsSimpleLineMaterialSettings::QgsSimpleLineMaterialSettings
QgsSimpleLineMaterialSettings()=default
Constructor for QgsSimpleLineMaterialSettings.
QgsSimpleLineMaterialSettings::supportsTechnique
static bool supportsTechnique(QgsMaterialSettingsRenderingTechnique technique)
Returns true if the specified technique is supported by the material.
Definition: qgssimplelinematerialsettings.cpp:30
QgsMaterialContext::selectionColor
QColor selectionColor() const
Returns the color for representing materials in a selected state.
Definition: qgsabstractmaterialsettings.h:77
QgsMaterialContext
3 Context settings for a material.
Definition: qgsabstractmaterialsettings.h:55
qgslinematerial_p.h
qgssimplelinematerialsettings.h
QgsAbstractMaterialSettings
3 Abstract base class for material settings.
Definition: qgsabstractmaterialsettings.h:105
QgsSimpleLineMaterialSettings::clone
QgsSimpleLineMaterialSettings * clone() const override
Clones the material settings.
Definition: qgssimplelinematerialsettings.cpp:51
QgsSimpleLineMaterialSettings::readXml
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads settings from a DOM element.
Definition: qgssimplelinematerialsettings.cpp:56
QgsMaterialSettingsRenderingTechnique::Triangles
@ Triangles
Triangle based rendering (default)
QgsSimpleLineMaterialSettings::toExportParameters
QMap< QString, QString > toExportParameters() const override
Returns the parameters to be exported to .mtl file.
Definition: qgssimplelinematerialsettings.cpp:91
QgsMaterialSettingsRenderingTechnique
QgsMaterialSettingsRenderingTechnique
Material rendering techniques 3.
Definition: qgsabstractmaterialsettings.h:36
QgsSimpleLineMaterialSettings
3 Basic shading material used for rendering simple lines as solid line components.
Definition: qgssimplelinematerialsettings.h:37
QgsSimpleLineMaterialSettings::addParametersToEffect
void addParametersToEffect(Qt3DRender::QEffect *effect) const override
Adds parameters from the material to a destination effect.
Definition: qgssimplelinematerialsettings.cpp:98
QgsSimpleLineMaterialSettings::writeXml
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes settings to a DOM element.
Definition: qgssimplelinematerialsettings.cpp:61
QgsMaterialSettingsRenderingTechnique::Points
@ Points
Point based rendering, requires point data.
QgsSimpleLineMaterialSettings::type
QString type() const override
Returns the unique type name for the material.
Definition: qgssimplelinematerialsettings.cpp:25
QgsSimpleLineMaterialSettings::toMaterial
Qt3DRender::QMaterial * toMaterial(QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context) const override
Creates a new QMaterial object representing the material settings.
Definition: qgssimplelinematerialsettings.cpp:66
QgsMaterialContext::isSelected
bool isSelected() const
Returns true if the material should represent a selected state.
Definition: qgsabstractmaterialsettings.h:63