QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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#include "moc_qgsrenderermeshpropertieswidget.cpp"
18
19#include "qgis.h"
20#include "qgsmapcanvas.h"
21#include "qgsmeshlayer.h"
24#include "qgsproject.h"
25#include "qgsprojectutils.h"
26
28 : QgsMapLayerConfigWidget( layer, canvas, parent )
29 , mMeshLayer( layer )
30{
31 if ( !mMeshLayer )
32 return;
33
34 setupUi( this );
35
36 connect( mMeshLayer,
38 this,
39 &QgsRendererMeshPropertiesWidget::syncToLayerPrivate );
40
41 mMeshRendererActiveDatasetWidget->setLayer( mMeshLayer );
42 mMeshRendererScalarSettingsWidget->setLayer( mMeshLayer );
43 mNativeMeshSettingsWidget->setLayer( mMeshLayer, QgsMeshRendererMeshSettingsWidget::MeshType::Native );
44 mTriangularMeshSettingsWidget->setLayer( mMeshLayer, QgsMeshRendererMeshSettingsWidget::MeshType::Triangular );
45 mEdgeMeshSettingsWidget->setLayer( mMeshLayer, QgsMeshRendererMeshSettingsWidget::MeshType::Edge );
46 mMeshRendererVectorSettingsWidget->setLayer( mMeshLayer );
47 m3dAveragingSettingsWidget->setLayer( mMeshLayer );
48 syncToLayer( mMeshLayer );
49
50 //blend mode
51 mBlendModeComboBox->setShowClippingModes( QgsProjectUtils::layerIsContainedInGroupLayer( QgsProject::instance(), mMeshLayer ) );
52 mBlendModeComboBox->setBlendMode( mMeshLayer->blendMode() );
53 connect( mBlendModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPanelWidget::widgetChanged );
54
55 mOpacityWidget->setOpacity( mMeshLayer->opacity() );
56 connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsPanelWidget::widgetChanged );
57
58 connect( mMeshRendererActiveDatasetWidget, &QgsMeshRendererActiveDatasetWidget::activeScalarGroupChanged,
59 this, &QgsRendererMeshPropertiesWidget::onActiveScalarGroupChanged );
60 connect( mMeshRendererActiveDatasetWidget, &QgsMeshRendererActiveDatasetWidget::activeVectorGroupChanged,
61 this, &QgsRendererMeshPropertiesWidget::onActiveVectorGroupChanged );
62
63 connect( mNativeMeshGroup, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
64 connect( mEdgeMeshGroup, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
65 connect( mTriangularMeshGroup, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
66 connect( mContoursGroupBox, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
67 connect( mVectorsGroupBox, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
68 connect( mMeshRendererActiveDatasetWidget, &QgsMeshRendererActiveDatasetWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
69 connect( mMeshRendererScalarSettingsWidget, &QgsMeshRendererScalarSettingsWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
70 connect( mMeshRendererVectorSettingsWidget, &QgsMeshRendererVectorSettingsWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
71 connect( mNativeMeshSettingsWidget, &QgsMeshRendererMeshSettingsWidget::widgetChanged,
73 connect( mTriangularMeshSettingsWidget, &QgsMeshRendererMeshSettingsWidget::widgetChanged,
75 connect( mEdgeMeshSettingsWidget, &QgsMeshRendererMeshSettingsWidget::widgetChanged,
77 connect( m3dAveragingSettingsWidget, &QgsMeshRenderer3DAveragingWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
78}
79
81{
82 if ( !mMeshLayer )
83 return;
84
85 // 1D EDGE MESH
86 const bool edgeMeshRenderingIsEnabled = mEdgeMeshGroup->isChecked();
87 QgsMeshRendererMeshSettings edgeMeshSettings = mEdgeMeshSettingsWidget->settings();
88 edgeMeshSettings.setEnabled( edgeMeshRenderingIsEnabled );
89
90 // 2D NATIVE MESH
91 const bool nativeMeshRenderingIsEnabled = mNativeMeshGroup->isChecked();
92 QgsMeshRendererMeshSettings nativeMeshSettings = mNativeMeshSettingsWidget->settings();
93 nativeMeshSettings.setEnabled( nativeMeshRenderingIsEnabled );
94
95 // 2D TRIANGULAR MESH
96 const bool triangularMeshRenderingIsEnabled = mTriangularMeshGroup->isChecked();
97 QgsMeshRendererMeshSettings triangularMeshSettings = mTriangularMeshSettingsWidget->settings();
98 triangularMeshSettings.setEnabled( triangularMeshRenderingIsEnabled );
99
100 // SCALAR
101 int activeScalarDatasetGroupIndex = mMeshRendererActiveDatasetWidget->activeScalarDatasetGroup();
102 if ( !mContoursGroupBox->isChecked() )
103 activeScalarDatasetGroupIndex = -1;
104
105 // VECTOR
106 int activeVectorDatasetGroupIndex = mMeshRendererActiveDatasetWidget->activeVectorDatasetGroup();
107 if ( !mVectorsGroupBox->isChecked() )
108 activeVectorDatasetGroupIndex = -1;
109
110 QgsMeshRendererSettings settings = mMeshLayer->rendererSettings();
111 settings.setEdgeMeshSettings( edgeMeshSettings );
112 settings.setNativeMeshSettings( nativeMeshSettings );
113 settings.setTriangularMeshSettings( triangularMeshSettings );
114
115 settings.setActiveScalarDatasetGroup( activeScalarDatasetGroupIndex );
116 if ( activeScalarDatasetGroupIndex > -1 )
117 settings.setScalarSettings( activeScalarDatasetGroupIndex, mMeshRendererScalarSettingsWidget->settings() );
118
119 settings.setActiveVectorDatasetGroup( activeVectorDatasetGroupIndex );
120 if ( activeVectorDatasetGroupIndex > -1 )
121 settings.setVectorSettings( activeVectorDatasetGroupIndex, mMeshRendererVectorSettingsWidget->settings() );
122
123 const QgsMeshDatasetIndex staticScalarDatasetIndex( activeScalarDatasetGroupIndex, mMeshLayer->staticScalarDatasetIndex().dataset() );
124 const QgsMeshDatasetIndex staticVectorDatasetIndex( activeVectorDatasetGroupIndex, mMeshLayer->staticVectorDatasetIndex().dataset() );
125 mMeshLayer->setStaticScalarDatasetIndex( staticScalarDatasetIndex );
126 mMeshLayer->setStaticVectorDatasetIndex( staticVectorDatasetIndex );
127
128 //set the blend mode and opacity for the layer
129 mMeshLayer->setBlendMode( mBlendModeComboBox->blendMode() );
130 mLayer->setOpacity( mOpacityWidget->opacity() );
131 //set the averaging method for the layer
132 const std::unique_ptr<QgsMesh3DAveragingMethod> averagingMethod( m3dAveragingSettingsWidget->averagingMethod() );
133 settings.setAveragingMethod( averagingMethod.get() );
134 mMeshLayer->setRendererSettings( settings );
135 mMeshLayer->triggerRepaint();
136
137 QgsSettings windowsSettings;
138 windowsSettings.setValue( QStringLiteral( "/Windows/RendererMeshProperties/tab" ), mStyleOptionsTab->currentIndex() );
139}
140
142{
143 QgsMeshLayer *ml = qobject_cast<QgsMeshLayer *>( mapLayer );
144 if ( ml )
145 {
146 mLayer = ml;
147 mMeshRendererActiveDatasetWidget->setLayer( ml );
148 mNativeMeshSettingsWidget->setLayer( ml, QgsMeshRendererMeshSettingsWidget::Native );
149 mTriangularMeshSettingsWidget->setLayer( ml, QgsMeshRendererMeshSettingsWidget::Triangular );
150 mEdgeMeshSettingsWidget->setLayer( ml, QgsMeshRendererMeshSettingsWidget::Edge );
151 m3dAveragingSettingsWidget->setLayer( ml );
152 }
153 else
154 return;
155
156 syncToLayerPrivate();
157}
158
159void QgsRendererMeshPropertiesWidget::syncToLayerPrivate()
160{
161 mMeshRendererActiveDatasetWidget->syncToLayer();
162 mNativeMeshSettingsWidget->syncToLayer();
163 mTriangularMeshSettingsWidget->syncToLayer();
164 mEdgeMeshSettingsWidget->syncToLayer();
165 m3dAveragingSettingsWidget->syncToLayer();
166
167 mNativeMeshGroup->setChecked( mMeshLayer ? mMeshLayer->rendererSettings().nativeMeshSettings().isEnabled() : false );
168 mTriangularMeshGroup->setChecked( mMeshLayer ? mMeshLayer->rendererSettings().triangularMeshSettings().isEnabled() : false );
169 mEdgeMeshGroup->setChecked( mMeshLayer ? mMeshLayer->rendererSettings().edgeMeshSettings().isEnabled() : false );
170
171 onActiveScalarGroupChanged( mMeshLayer->rendererSettings().activeScalarDatasetGroup() );
172 onActiveVectorGroupChanged( mMeshLayer->rendererSettings().activeVectorDatasetGroup() );
173
174 const bool hasFaces = ( mMeshLayer->contains( QgsMesh::ElementType::Face ) );
175 mFaceMeshGroupBox->setVisible( hasFaces || !mMeshLayer->isValid() );
176
177 const bool hasEdges = ( mMeshLayer->contains( QgsMesh::ElementType::Edge ) );
178 mEdgeMeshGroupBox->setVisible( hasEdges || !mMeshLayer->isValid() );
179
180 QgsSettings settings;
181 if ( !settings.contains( QStringLiteral( "/Windows/RendererMeshProperties/tab" ) ) )
182 settings.setValue( QStringLiteral( "/Windows/RendererMeshProperties/tab" ), 0 );
183 else
184 mStyleOptionsTab->setCurrentIndex( settings.value( QStringLiteral( "/Windows/RendererMeshProperties/tab" ) ).toInt() );
185}
186
187void QgsRendererMeshPropertiesWidget::onActiveScalarGroupChanged( int groupIndex )
188{
189 mMeshRendererScalarSettingsWidget->setActiveDatasetGroup( groupIndex );
190 mMeshRendererScalarSettingsWidget->syncToLayer();
191 mContoursGroupBox->setChecked( groupIndex >= 0 );
192 mContoursGroupBox->setEnabled( groupIndex >= 0 );
193}
194
195void QgsRendererMeshPropertiesWidget::onActiveVectorGroupChanged( int groupIndex )
196{
197 if ( groupIndex >= 0 && !mMeshLayer->datasetGroupMetadata( groupIndex ).isVector() )
198 groupIndex = -1;
199 mMeshRendererVectorSettingsWidget->setActiveDatasetGroup( groupIndex );
200 mMeshRendererVectorSettingsWidget->syncToLayer();
201 mVectorsGroupBox->setChecked( groupIndex >= 0 );
202 mVectorsGroupBox->setEnabled( groupIndex >= 0 );
203}
Map canvas is a class for displaying all GIS data types on a canvas.
A panel widget that can be shown in the map style dock.
Base class for all map layer types.
Definition qgsmaplayer.h:76
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.
double opacity
Definition qgsmaplayer.h:88
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.
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(int group=-1) const
Returns the static vector dataset index that is rendered if the temporal properties is not active.
void setRendererSettings(const QgsMeshRendererSettings &settings)
Sets new renderer settings.
QgsMeshDatasetIndex staticScalarDatasetIndex(int group=-1) const
Returns the static scalar dataset index that is rendered if the temporal properties is not active.
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 setAveragingMethod(QgsMesh3DAveragingMethod *method)
Sets averaging method for conversion of 3d stacked mesh data to 2d data.
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.
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.
void syncToLayer(QgsMapLayer *mapLayer) final
Synchronize widgets state with associated map layer.
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.
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
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.