QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsrenderermeshpropertieswidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsrenderermeshpropertieswidget.cpp
3 -----------------------------------
4 begin : June 2018
5 copyright : (C) 2018 by Peter Petrik
6 email : zilolv 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
18#include "qgis.h"
19#include "qgsmapcanvas.h"
20#include "qgsmeshlayer.h"
21#include "qgsmessagelog.h"
25#include "qgsmeshlayerutils.h"
26#include "qgsproject.h"
27#include "qgsprojectutils.h"
28
30 : QgsMapLayerConfigWidget( layer, canvas, parent )
31 , mMeshLayer( layer )
32{
33 if ( !mMeshLayer )
34 return;
35
36 setupUi( this );
37
38 connect( mMeshLayer,
40 this,
41 &QgsRendererMeshPropertiesWidget::syncToLayerPrivate );
42
43 mMeshRendererActiveDatasetWidget->setLayer( mMeshLayer );
44 mMeshRendererScalarSettingsWidget->setLayer( mMeshLayer );
45 mNativeMeshSettingsWidget->setLayer( mMeshLayer, QgsMeshRendererMeshSettingsWidget::MeshType::Native );
46 mTriangularMeshSettingsWidget->setLayer( mMeshLayer, QgsMeshRendererMeshSettingsWidget::MeshType::Triangular );
47 mEdgeMeshSettingsWidget->setLayer( mMeshLayer, QgsMeshRendererMeshSettingsWidget::MeshType::Edge );
48 mMeshRendererVectorSettingsWidget->setLayer( mMeshLayer );
49 m3dAveragingSettingsWidget->setLayer( mMeshLayer );
50 syncToLayer( mMeshLayer );
51
52 //blend mode
53 mBlendModeComboBox->setShowClippingModes( QgsProjectUtils::layerIsContainedInGroupLayer( QgsProject::instance(), mMeshLayer ) );
54 mBlendModeComboBox->setBlendMode( mMeshLayer->blendMode() );
55 connect( mBlendModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPanelWidget::widgetChanged );
56
57 mOpacityWidget->setOpacity( mMeshLayer->opacity() );
58 connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsPanelWidget::widgetChanged );
59
60 connect( mMeshRendererActiveDatasetWidget, &QgsMeshRendererActiveDatasetWidget::activeScalarGroupChanged,
61 this, &QgsRendererMeshPropertiesWidget::onActiveScalarGroupChanged );
62 connect( mMeshRendererActiveDatasetWidget, &QgsMeshRendererActiveDatasetWidget::activeVectorGroupChanged,
63 this, &QgsRendererMeshPropertiesWidget::onActiveVectorGroupChanged );
64
65 connect( mNativeMeshGroup, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
66 connect( mEdgeMeshGroup, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
67 connect( mTriangularMeshGroup, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
68 connect( mContoursGroupBox, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
69 connect( mVectorsGroupBox, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
70 connect( mMeshRendererActiveDatasetWidget, &QgsMeshRendererActiveDatasetWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
71 connect( mMeshRendererScalarSettingsWidget, &QgsMeshRendererScalarSettingsWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
72 connect( mMeshRendererVectorSettingsWidget, &QgsMeshRendererVectorSettingsWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
73 connect( mNativeMeshSettingsWidget, &QgsMeshRendererMeshSettingsWidget::widgetChanged,
75 connect( mTriangularMeshSettingsWidget, &QgsMeshRendererMeshSettingsWidget::widgetChanged,
77 connect( mEdgeMeshSettingsWidget, &QgsMeshRendererMeshSettingsWidget::widgetChanged,
79 connect( m3dAveragingSettingsWidget, &QgsMeshRenderer3dAveragingWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
80}
81
83{
84 if ( !mMeshLayer )
85 return;
86
87 // 1D EDGE MESH
88 const bool edgeMeshRenderingIsEnabled = mEdgeMeshGroup->isChecked();
89 QgsMeshRendererMeshSettings edgeMeshSettings = mEdgeMeshSettingsWidget->settings();
90 edgeMeshSettings.setEnabled( edgeMeshRenderingIsEnabled );
91
92 // 2D NATIVE MESH
93 const bool nativeMeshRenderingIsEnabled = mNativeMeshGroup->isChecked();
94 QgsMeshRendererMeshSettings nativeMeshSettings = mNativeMeshSettingsWidget->settings();
95 nativeMeshSettings.setEnabled( nativeMeshRenderingIsEnabled );
96
97 // 2D TRIANGULAR MESH
98 const bool triangularMeshRenderingIsEnabled = mTriangularMeshGroup->isChecked();
99 QgsMeshRendererMeshSettings triangularMeshSettings = mTriangularMeshSettingsWidget->settings();
100 triangularMeshSettings.setEnabled( triangularMeshRenderingIsEnabled );
101
102 // SCALAR
103 int activeScalarDatasetGroupIndex = mMeshRendererActiveDatasetWidget->activeScalarDatasetGroup();
104 if ( !mContoursGroupBox->isChecked() )
105 activeScalarDatasetGroupIndex = -1;
106
107 // VECTOR
108 int activeVectorDatasetGroupIndex = mMeshRendererActiveDatasetWidget->activeVectorDatasetGroup();
109 if ( !mVectorsGroupBox->isChecked() )
110 activeVectorDatasetGroupIndex = -1;
111
112 QgsMeshRendererSettings settings = mMeshLayer->rendererSettings();
113 settings.setEdgeMeshSettings( edgeMeshSettings );
114 settings.setNativeMeshSettings( nativeMeshSettings );
115 settings.setTriangularMeshSettings( triangularMeshSettings );
116
117 settings.setActiveScalarDatasetGroup( activeScalarDatasetGroupIndex );
118 if ( activeScalarDatasetGroupIndex > -1 )
119 settings.setScalarSettings( activeScalarDatasetGroupIndex, mMeshRendererScalarSettingsWidget->settings() );
120
121 settings.setActiveVectorDatasetGroup( activeVectorDatasetGroupIndex );
122 if ( activeVectorDatasetGroupIndex > -1 )
123 settings.setVectorSettings( activeVectorDatasetGroupIndex, mMeshRendererVectorSettingsWidget->settings() );
124
125 const QgsMeshDatasetIndex staticScalarDatasetIndex( activeScalarDatasetGroupIndex, mMeshLayer->staticScalarDatasetIndex().dataset() );
126 const QgsMeshDatasetIndex staticVectorDatasetIndex( activeVectorDatasetGroupIndex, mMeshLayer->staticVectorDatasetIndex().dataset() );
127 mMeshLayer->setStaticScalarDatasetIndex( staticScalarDatasetIndex );
128 mMeshLayer->setStaticVectorDatasetIndex( staticVectorDatasetIndex );
129
130 //set the blend mode and opacity for the layer
131 mMeshLayer->setBlendMode( mBlendModeComboBox->blendMode() );
132 mLayer->setOpacity( mOpacityWidget->opacity() );
133 //set the averaging method for the layer
134 const std::unique_ptr<QgsMesh3dAveragingMethod> averagingMethod( m3dAveragingSettingsWidget->averagingMethod() );
135 settings.setAveragingMethod( averagingMethod.get() );
136 mMeshLayer->setRendererSettings( settings );
137 mMeshLayer->triggerRepaint();
138
139 QgsSettings windowsSettings;
140 windowsSettings.setValue( QStringLiteral( "/Windows/RendererMeshProperties/tab" ), mStyleOptionsTab->currentIndex() );
141}
142
144{
145 QgsMeshLayer *ml = qobject_cast<QgsMeshLayer *>( mapLayer );
146 if ( ml )
147 {
148 mLayer = ml;
149 mMeshRendererActiveDatasetWidget->setLayer( ml );
150 mNativeMeshSettingsWidget->setLayer( ml, QgsMeshRendererMeshSettingsWidget::Native );
151 mTriangularMeshSettingsWidget->setLayer( ml, QgsMeshRendererMeshSettingsWidget::Triangular );
152 mEdgeMeshSettingsWidget->setLayer( ml, QgsMeshRendererMeshSettingsWidget::Edge );
153 m3dAveragingSettingsWidget->setLayer( ml );
154 }
155 else
156 return;
157
158 syncToLayerPrivate();
159}
160
161void QgsRendererMeshPropertiesWidget::syncToLayerPrivate()
162{
163 mMeshRendererActiveDatasetWidget->syncToLayer();
164 mNativeMeshSettingsWidget->syncToLayer();
165 mTriangularMeshSettingsWidget->syncToLayer();
166 mEdgeMeshSettingsWidget->syncToLayer();
167 m3dAveragingSettingsWidget->syncToLayer();
168
169 mNativeMeshGroup->setChecked( mMeshLayer ? mMeshLayer->rendererSettings().nativeMeshSettings().isEnabled() : false );
170 mTriangularMeshGroup->setChecked( mMeshLayer ? mMeshLayer->rendererSettings().triangularMeshSettings().isEnabled() : false );
171 mEdgeMeshGroup->setChecked( mMeshLayer ? mMeshLayer->rendererSettings().edgeMeshSettings().isEnabled() : false );
172
173 onActiveScalarGroupChanged( mMeshLayer->rendererSettings().activeScalarDatasetGroup() );
174 onActiveVectorGroupChanged( mMeshLayer->rendererSettings().activeVectorDatasetGroup() );
175
176 const bool hasFaces = ( mMeshLayer->contains( QgsMesh::ElementType::Face ) );
177 mFaceMeshGroupBox->setVisible( hasFaces || !mMeshLayer->isValid() );
178
179 const bool hasEdges = ( mMeshLayer->contains( QgsMesh::ElementType::Edge ) );
180 mEdgeMeshGroupBox->setVisible( hasEdges || !mMeshLayer->isValid() );
181
182 QgsSettings settings;
183 if ( !settings.contains( QStringLiteral( "/Windows/RendererMeshProperties/tab" ) ) )
184 settings.setValue( QStringLiteral( "/Windows/RendererMeshProperties/tab" ), 0 );
185 else
186 mStyleOptionsTab->setCurrentIndex( settings.value( QStringLiteral( "/Windows/RendererMeshProperties/tab" ) ).toInt() );
187}
188
189void QgsRendererMeshPropertiesWidget::onActiveScalarGroupChanged( int groupIndex )
190{
191 mMeshRendererScalarSettingsWidget->setActiveDatasetGroup( groupIndex );
192 mMeshRendererScalarSettingsWidget->syncToLayer();
193 mContoursGroupBox->setChecked( groupIndex >= 0 );
194 mContoursGroupBox->setEnabled( groupIndex >= 0 );
195}
196
197void QgsRendererMeshPropertiesWidget::onActiveVectorGroupChanged( int groupIndex )
198{
199 if ( groupIndex >= 0 && !mMeshLayer->datasetGroupMetadata( groupIndex ).isVector() )
200 groupIndex = -1;
201 mMeshRendererVectorSettingsWidget->setActiveDatasetGroup( groupIndex );
202 mMeshRendererVectorSettingsWidget->syncToLayer();
203 mVectorsGroupBox->setChecked( groupIndex >= 0 );
204 mVectorsGroupBox->setEnabled( groupIndex >= 0 );
205}
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:90
A panel widget that can be shown in the map style dock.
Base class for all map layer types.
Definition: qgsmaplayer.h:73
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
virtual void setOpacity(double opacity)
Sets the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1....
void dataChanged()
Data of layer changed.
bool isValid
Definition: qgsmaplayer.h:81
double opacity
Definition: qgsmaplayer.h:82
bool isVector() const
Returns whether dataset group has vector data.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
int dataset() const
Returns a dataset index within group()
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:100
void setStaticVectorDatasetIndex(const QgsMeshDatasetIndex &staticVectorDatasetIndex)
Sets the static vector dataset index that is rendered if the temporal properties is not active.
void setStaticScalarDatasetIndex(const QgsMeshDatasetIndex &staticScalarDatasetIndex)
Sets the static scalar dataset index that is rendered if the temporal properties is not active.
bool contains(const QgsMesh::ElementType &type) const
Returns whether the mesh contains at mesh elements of given type.
QgsMeshRendererSettings rendererSettings() const
Returns renderer settings.
QgsMeshDatasetIndex staticVectorDatasetIndex() const
Returns the static vector dataset index that is rendered if the temporal properties is not active.
QgsMeshDatasetIndex staticScalarDatasetIndex() const
Returns the static scalar dataset index that is rendered if the temporal properties is not active.
void setRendererSettings(const QgsMeshRendererSettings &settings)
Sets new renderer settings.
QgsMeshDatasetGroupMetadata datasetGroupMetadata(const QgsMeshDatasetIndex &index) const
Returns the dataset groups metadata.
void widgetChanged()
Mesh rendering settings changed.
void widgetChanged()
Emitted when any settings related to rendering changed.
void activeScalarGroupChanged(int groupIndex)
Emitted when the current scalar group gets changed.
void activeVectorGroupChanged(int groupIndex)
Emitted when the current vector group gets changed.
void widgetChanged()
Mesh rendering settings changed.
Represents a mesh renderer settings for mesh object.
void setEnabled(bool enabled)
Sets whether mesh structure rendering is enabled.
bool isEnabled() const
Returns whether mesh structure rendering is enabled.
void widgetChanged()
Mesh rendering settings changed.
Represents all mesh renderer settings.
void setActiveVectorDatasetGroup(int activeVectorDatasetGroup)
Sets the active vector dataset group.
int activeVectorDatasetGroup() const
Returns the active vector dataset group.
void setEdgeMeshSettings(const QgsMeshRendererMeshSettings &settings)
Sets new edge mesh renderer settings.
int activeScalarDatasetGroup() const
Returns the active scalar dataset group.
void setActiveScalarDatasetGroup(int activeScalarDatasetGroup)
Sets the active scalar dataset group.
void setVectorSettings(int groupIndex, const QgsMeshRendererVectorSettings &settings)
Sets new renderer settings.
void setTriangularMeshSettings(const QgsMeshRendererMeshSettings &settings)
Sets new triangular mesh renderer settings.
QgsMeshRendererMeshSettings edgeMeshSettings() const
Returns edge mesh renderer settings.
void setAveragingMethod(QgsMesh3dAveragingMethod *method)
Sets averaging method for conversion of 3d stacked mesh data to 2d data.
QgsMeshRendererMeshSettings nativeMeshSettings() const
Returns native mesh renderer settings.
void setScalarSettings(int groupIndex, const QgsMeshRendererScalarSettings &settings)
Sets new renderer settings.
QgsMeshRendererMeshSettings triangularMeshSettings() const
Returns triangular mesh renderer settings.
void setNativeMeshSettings(const QgsMeshRendererMeshSettings &settings)
Sets new native mesh renderer settings, triggers repaint.
void widgetChanged()
Mesh rendering settings changed.
void opacityChanged(double opacity)
Emitted when the opacity is changed in the widget, where opacity ranges from 0.0 (transparent) to 1....
void widgetChanged()
Emitted when the widget state changes.
static bool layerIsContainedInGroupLayer(QgsProject *project, QgsMapLayer *layer)
Returns true if the specified layer is a child layer from any QgsGroupLayer in the given project.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:477
void apply() override
Applies the settings made in the dialog.
QgsRendererMeshPropertiesWidget(QgsMeshLayer *layer, QgsMapCanvas *canvas, QWidget *parent=nullptr)
A widget to hold the renderer properties for a mesh layer.
void syncToLayer(QgsMapLayer *mapLayer) override
Synchronize widgets state with associated map layer.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:62
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
bool contains(const QString &key, QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.