QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
161 void 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 
189 void QgsRendererMeshPropertiesWidget::onActiveScalarGroupChanged( int groupIndex )
190 {
191  mMeshRendererScalarSettingsWidget->setActiveDatasetGroup( groupIndex );
192  mMeshRendererScalarSettingsWidget->syncToLayer();
193  mContoursGroupBox->setChecked( groupIndex >= 0 );
194  mContoursGroupBox->setEnabled( groupIndex >= 0 );
195 }
196 
197 void 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 }
QgsMeshDatasetIndex::dataset
int dataset() const
Returns a dataset index within group()
Definition: qgsmeshdataset.cpp:32
qgsmeshlayerutils.h
QgsRendererMeshPropertiesWidget::apply
void apply() override
Applies the settings made in the dialog.
Definition: qgsrenderermeshpropertieswidget.cpp:82
QgsOpacityWidget::opacityChanged
void opacityChanged(double opacity)
Emitted when the opacity is changed in the widget, where opacity ranges from 0.0 (transparent) to 1....
QgsProjectUtils::layerIsContainedInGroupLayer
static bool layerIsContainedInGroupLayer(QgsProject *project, QgsMapLayer *layer)
Returns true if the specified layer is a child layer from any QgsGroupLayer in the given project.
Definition: qgsprojectutils.cpp:57
QgsMeshRendererSettings
Represents all mesh renderer settings.
Definition: qgsmeshrenderersettings.h:590
QgsSettings::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Definition: qgssettings.cpp:161
QgsMeshLayer::contains
bool contains(const QgsMesh::ElementType &type) const
Returns whether the mesh contains at mesh elements of given type.
Definition: qgsmeshlayer.cpp:1134
qgsmapcanvas.h
QgsMeshRendererSettings::setActiveVectorDatasetGroup
void setActiveVectorDatasetGroup(int activeVectorDatasetGroup)
Sets the active vector dataset group.
Definition: qgsmeshrenderersettings.cpp:522
QgsMeshRendererMeshSettings
Represents a mesh renderer settings for mesh object.
Definition: qgsmeshrenderersettings.h:41
QgsMapLayer::opacity
double opacity
Definition: qgsmaplayer.h:82
QgsMeshRendererSettings::setVectorSettings
void setVectorSettings(int groupIndex, const QgsMeshRendererVectorSettings &settings)
Sets new renderer settings.
Definition: qgsmeshrenderersettings.h:631
QgsMapLayer::blendMode
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
Definition: qgsmaplayer.cpp:320
QgsMeshRendererSettings::setScalarSettings
void setScalarSettings(int groupIndex, const QgsMeshRendererScalarSettings &settings)
Sets new renderer settings.
Definition: qgsmeshrenderersettings.h:626
QgsMeshRendererMeshSettingsWidget::Triangular
@ Triangular
Definition: qgsmeshrenderermeshsettingswidget.h:46
QgsMeshRendererSettings::setAveragingMethod
void setAveragingMethod(QgsMesh3dAveragingMethod *method)
Sets averaging method for conversion of 3d stacked mesh data to 2d data.
Definition: qgsmeshrenderersettings.cpp:399
QgsRendererMeshPropertiesWidget::syncToLayer
void syncToLayer(QgsMapLayer *mapLayer) override
Synchronize widgets state with associated map layer.
Definition: qgsrenderermeshpropertieswidget.cpp:143
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:89
qgis.h
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:480
QgsMapLayerConfigWidget::mLayer
QgsMapLayer * mLayer
Definition: qgsmaplayerconfigwidget.h:182
QgsSettings
This class is a composition of two QSettings instances:
Definition: qgssettings.h:61
QgsMapLayer::setBlendMode
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
Definition: qgsmaplayer.cpp:310
QgsMeshLayer::setStaticVectorDatasetIndex
void setStaticVectorDatasetIndex(const QgsMeshDatasetIndex &staticVectorDatasetIndex)
Sets the static vector dataset index that is rendered if the temporal properties is not active.
Definition: qgsmeshlayer.cpp:1314
QgsMapLayer::isValid
bool isValid
Definition: qgsmaplayer.h:81
QgsMeshRendererActiveDatasetWidget::widgetChanged
void widgetChanged()
Emitted when any settings related to rendering changed.
QgsMeshRendererSettings::setTriangularMeshSettings
void setTriangularMeshSettings(const QgsMeshRendererMeshSettings &settings)
Sets new triangular mesh renderer settings.
Definition: qgsmeshrenderersettings.h:609
QgsMeshRendererSettings::setEdgeMeshSettings
void setEdgeMeshSettings(const QgsMeshRendererMeshSettings &settings)
Sets new edge mesh renderer settings.
Definition: qgsmeshrenderersettings.h:621
qgsrenderermeshpropertieswidget.h
QgsMapLayerConfigWidget
A panel widget that can be shown in the map style dock.
Definition: qgsmaplayerconfigwidget.h:115
QgsMeshLayer::rendererSettings
QgsMeshRendererSettings rendererSettings() const
Returns renderer settings.
Definition: qgsmeshlayer.cpp:344
qgsprojectutils.h
QgsMapLayer::triggerRepaint
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
Definition: qgsmaplayer.cpp:2114
QgsMeshLayer::staticVectorDatasetIndex
QgsMeshDatasetIndex staticVectorDatasetIndex() const
Returns the static vector dataset index that is rendered if the temporal properties is not active.
Definition: qgsmeshlayer.cpp:795
QgsMeshRendererSettings::activeScalarDatasetGroup
int activeScalarDatasetGroup() const
Returns the active scalar dataset group.
Definition: qgsmeshrenderersettings.cpp:507
QgsMeshRendererMeshSettingsWidget::widgetChanged
void widgetChanged()
Mesh rendering settings changed.
QgsMeshDatasetIndex
QgsMeshDatasetIndex is index that identifies the dataset group (e.g. wind speed) and a dataset in thi...
Definition: qgsmeshdataset.h:48
QgsMeshRendererSettings::activeVectorDatasetGroup
int activeVectorDatasetGroup() const
Returns the active vector dataset group.
Definition: qgsmeshrenderersettings.cpp:517
QgsMeshRendererVectorSettingsWidget::widgetChanged
void widgetChanged()
Mesh rendering settings changed.
QgsMeshLayer
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:98
QgsMapLayer::setOpacity
virtual void setOpacity(double opacity)
Sets the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1....
Definition: qgsmaplayer.cpp:325
QgsRendererMeshPropertiesWidget::QgsRendererMeshPropertiesWidget
QgsRendererMeshPropertiesWidget(QgsMeshLayer *layer, QgsMapCanvas *canvas, QWidget *parent=nullptr)
A widget to hold the renderer properties for a mesh layer.
Definition: qgsrenderermeshpropertieswidget.cpp:29
QgsPanelWidget::widgetChanged
void widgetChanged()
Emitted when the widget state changes.
QgsMeshRendererActiveDatasetWidget::activeScalarGroupChanged
void activeScalarGroupChanged(int groupIndex)
Emitted when the current scalar group gets changed.
QgsMeshRendererSettings::setNativeMeshSettings
void setNativeMeshSettings(const QgsMeshRendererMeshSettings &settings)
Sets new native mesh renderer settings, triggers repaint.
Definition: qgsmeshrenderersettings.h:604
QgsSettings::setValue
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Definition: qgssettings.cpp:279
QgsMeshRendererSettings::nativeMeshSettings
QgsMeshRendererMeshSettings nativeMeshSettings() const
Returns native mesh renderer settings.
Definition: qgsmeshrenderersettings.h:602
QgsMeshRendererSettings::triangularMeshSettings
QgsMeshRendererMeshSettings triangularMeshSettings() const
Returns triangular mesh renderer settings.
Definition: qgsmeshrenderersettings.h:607
QgsMeshRendererActiveDatasetWidget::activeVectorGroupChanged
void activeVectorGroupChanged(int groupIndex)
Emitted when the current vector group gets changed.
qgsmeshlayer.h
QgsMapLayer::dataChanged
void dataChanged()
Data of layer changed.
QgsMeshRendererSettings::edgeMeshSettings
QgsMeshRendererMeshSettings edgeMeshSettings() const
Returns edge mesh renderer settings.
Definition: qgsmeshrenderersettings.h:615
QgsMeshRendererMeshSettings::isEnabled
bool isEnabled() const
Returns whether mesh structure rendering is enabled.
Definition: qgsmeshrenderersettings.cpp:22
QgsMeshRendererScalarSettingsWidget::widgetChanged
void widgetChanged()
Mesh rendering settings changed.
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsMeshRendererMeshSettings::setEnabled
void setEnabled(bool enabled)
Sets whether mesh structure rendering is enabled.
Definition: qgsmeshrenderersettings.cpp:27
QgsMeshLayer::staticScalarDatasetIndex
QgsMeshDatasetIndex staticScalarDatasetIndex() const
Returns the static scalar dataset index that is rendered if the temporal properties is not active.
Definition: qgsmeshlayer.cpp:1309
QgsMeshRendererMeshSettingsWidget::Edge
@ Edge
Definition: qgsmeshrenderermeshsettingswidget.h:47
QgsMeshLayer::datasetGroupMetadata
QgsMeshDatasetGroupMetadata datasetGroupMetadata(const QgsMeshDatasetIndex &index) const
Returns the dataset groups metadata.
Definition: qgsmeshlayer.cpp:404
QgsSettings::contains
bool contains(const QString &key, QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
Definition: qgssettings.cpp:175
QgsMeshRenderer3dAveragingWidget::widgetChanged
void widgetChanged()
Mesh rendering settings changed.
QgsMeshLayer::setStaticScalarDatasetIndex
void setStaticScalarDatasetIndex(const QgsMeshDatasetIndex &staticScalarDatasetIndex)
Sets the static scalar dataset index that is rendered if the temporal properties is not active.
Definition: qgsmeshlayer.cpp:1325
QgsMeshDatasetGroupMetadata::isVector
bool isVector() const
Returns whether dataset group has vector data.
Definition: qgsmeshdataset.cpp:152
qgsmeshrendereractivedatasetwidget.h
QgsMeshLayer::setRendererSettings
void setRendererSettings(const QgsMeshRendererSettings &settings)
Sets new renderer settings.
Definition: qgsmeshlayer.cpp:349
QgsMeshRendererMeshSettingsWidget::Native
@ Native
Definition: qgsmeshrenderermeshsettingswidget.h:45
QgsMeshRendererSettings::setActiveScalarDatasetGroup
void setActiveScalarDatasetGroup(int activeScalarDatasetGroup)
Sets the active scalar dataset group.
Definition: qgsmeshrenderersettings.cpp:512
qgsmeshrendererscalarsettingswidget.h
qgsproject.h
qgsmeshdatasetgrouptreeview.h
qgsmessagelog.h