QGIS API Documentation 3.41.0-Master (cea29feecf2)
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, &QgsMeshLayer::dataChanged, this, &QgsRendererMeshPropertiesWidget::syncToLayerPrivate );
37
38 mMeshRendererActiveDatasetWidget->setLayer( mMeshLayer );
39 mMeshRendererScalarSettingsWidget->setLayer( mMeshLayer );
40 mNativeMeshSettingsWidget->setLayer( mMeshLayer, QgsMeshRendererMeshSettingsWidget::MeshType::Native );
41 mTriangularMeshSettingsWidget->setLayer( mMeshLayer, QgsMeshRendererMeshSettingsWidget::MeshType::Triangular );
42 mEdgeMeshSettingsWidget->setLayer( mMeshLayer, QgsMeshRendererMeshSettingsWidget::MeshType::Edge );
43 mMeshRendererVectorSettingsWidget->setLayer( mMeshLayer );
44 m3dAveragingSettingsWidget->setLayer( mMeshLayer );
45 syncToLayer( mMeshLayer );
46
47 //blend mode
48 mBlendModeComboBox->setShowClippingModes( QgsProjectUtils::layerIsContainedInGroupLayer( QgsProject::instance(), mMeshLayer ) );
49 mBlendModeComboBox->setBlendMode( mMeshLayer->blendMode() );
50 connect( mBlendModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPanelWidget::widgetChanged );
51
52 mOpacityWidget->setOpacity( mMeshLayer->opacity() );
53 connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsPanelWidget::widgetChanged );
54
55 connect( mMeshRendererActiveDatasetWidget, &QgsMeshRendererActiveDatasetWidget::activeScalarGroupChanged, this, &QgsRendererMeshPropertiesWidget::onActiveScalarGroupChanged );
56 connect( mMeshRendererActiveDatasetWidget, &QgsMeshRendererActiveDatasetWidget::activeVectorGroupChanged, this, &QgsRendererMeshPropertiesWidget::onActiveVectorGroupChanged );
57
58 connect( mNativeMeshGroup, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
59 connect( mEdgeMeshGroup, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
60 connect( mTriangularMeshGroup, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
61 connect( mContoursGroupBox, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
62 connect( mVectorsGroupBox, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
63 connect( mMeshRendererActiveDatasetWidget, &QgsMeshRendererActiveDatasetWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
64 connect( mMeshRendererScalarSettingsWidget, &QgsMeshRendererScalarSettingsWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
65 connect( mMeshRendererVectorSettingsWidget, &QgsMeshRendererVectorSettingsWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
66 connect( mNativeMeshSettingsWidget, &QgsMeshRendererMeshSettingsWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
67 connect( mTriangularMeshSettingsWidget, &QgsMeshRendererMeshSettingsWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
69 connect( m3dAveragingSettingsWidget, &QgsMeshRenderer3DAveragingWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
70}
71
73{
74 if ( !mMeshLayer )
75 return;
76
77 // 1D EDGE MESH
78 const bool edgeMeshRenderingIsEnabled = mEdgeMeshGroup->isChecked();
79 QgsMeshRendererMeshSettings edgeMeshSettings = mEdgeMeshSettingsWidget->settings();
80 edgeMeshSettings.setEnabled( edgeMeshRenderingIsEnabled );
81
82 // 2D NATIVE MESH
83 const bool nativeMeshRenderingIsEnabled = mNativeMeshGroup->isChecked();
84 QgsMeshRendererMeshSettings nativeMeshSettings = mNativeMeshSettingsWidget->settings();
85 nativeMeshSettings.setEnabled( nativeMeshRenderingIsEnabled );
86
87 // 2D TRIANGULAR MESH
88 const bool triangularMeshRenderingIsEnabled = mTriangularMeshGroup->isChecked();
89 QgsMeshRendererMeshSettings triangularMeshSettings = mTriangularMeshSettingsWidget->settings();
90 triangularMeshSettings.setEnabled( triangularMeshRenderingIsEnabled );
91
92 // SCALAR
93 int activeScalarDatasetGroupIndex = mMeshRendererActiveDatasetWidget->activeScalarDatasetGroup();
94 if ( !mContoursGroupBox->isChecked() )
95 activeScalarDatasetGroupIndex = -1;
96
97 // VECTOR
98 int activeVectorDatasetGroupIndex = mMeshRendererActiveDatasetWidget->activeVectorDatasetGroup();
99 if ( !mVectorsGroupBox->isChecked() )
100 activeVectorDatasetGroupIndex = -1;
101
102 QgsMeshRendererSettings settings = mMeshLayer->rendererSettings();
103 settings.setEdgeMeshSettings( edgeMeshSettings );
104 settings.setNativeMeshSettings( nativeMeshSettings );
105 settings.setTriangularMeshSettings( triangularMeshSettings );
106
107 settings.setActiveScalarDatasetGroup( activeScalarDatasetGroupIndex );
108 if ( activeScalarDatasetGroupIndex > -1 )
109 settings.setScalarSettings( activeScalarDatasetGroupIndex, mMeshRendererScalarSettingsWidget->settings() );
110
111 settings.setActiveVectorDatasetGroup( activeVectorDatasetGroupIndex );
112 if ( activeVectorDatasetGroupIndex > -1 )
113 settings.setVectorSettings( activeVectorDatasetGroupIndex, mMeshRendererVectorSettingsWidget->settings() );
114
115 const QgsMeshDatasetIndex staticScalarDatasetIndex( activeScalarDatasetGroupIndex, mMeshLayer->staticScalarDatasetIndex().dataset() );
116 const QgsMeshDatasetIndex staticVectorDatasetIndex( activeVectorDatasetGroupIndex, mMeshLayer->staticVectorDatasetIndex().dataset() );
117 mMeshLayer->setStaticScalarDatasetIndex( staticScalarDatasetIndex );
118 mMeshLayer->setStaticVectorDatasetIndex( staticVectorDatasetIndex );
119
120 //set the blend mode and opacity for the layer
121 mMeshLayer->setBlendMode( mBlendModeComboBox->blendMode() );
122 mLayer->setOpacity( mOpacityWidget->opacity() );
123 //set the averaging method for the layer
124 const std::unique_ptr<QgsMesh3DAveragingMethod> averagingMethod( m3dAveragingSettingsWidget->averagingMethod() );
125 settings.setAveragingMethod( averagingMethod.get() );
126 mMeshLayer->setRendererSettings( settings );
127 mMeshLayer->triggerRepaint();
128
129 QgsSettings windowsSettings;
130 windowsSettings.setValue( QStringLiteral( "/Windows/RendererMeshProperties/tab" ), mStyleOptionsTab->currentIndex() );
131}
132
134{
135 QgsMeshLayer *ml = qobject_cast<QgsMeshLayer *>( mapLayer );
136 if ( ml )
137 {
138 mLayer = ml;
139 mMeshRendererActiveDatasetWidget->setLayer( ml );
140 mNativeMeshSettingsWidget->setLayer( ml, QgsMeshRendererMeshSettingsWidget::Native );
141 mTriangularMeshSettingsWidget->setLayer( ml, QgsMeshRendererMeshSettingsWidget::Triangular );
142 mEdgeMeshSettingsWidget->setLayer( ml, QgsMeshRendererMeshSettingsWidget::Edge );
143 m3dAveragingSettingsWidget->setLayer( ml );
144 }
145 else
146 return;
147
148 syncToLayerPrivate();
149}
150
151void QgsRendererMeshPropertiesWidget::syncToLayerPrivate()
152{
153 mMeshRendererActiveDatasetWidget->syncToLayer();
154 mNativeMeshSettingsWidget->syncToLayer();
155 mTriangularMeshSettingsWidget->syncToLayer();
156 mEdgeMeshSettingsWidget->syncToLayer();
157 m3dAveragingSettingsWidget->syncToLayer();
158
159 mNativeMeshGroup->setChecked( mMeshLayer ? mMeshLayer->rendererSettings().nativeMeshSettings().isEnabled() : false );
160 mTriangularMeshGroup->setChecked( mMeshLayer ? mMeshLayer->rendererSettings().triangularMeshSettings().isEnabled() : false );
161 mEdgeMeshGroup->setChecked( mMeshLayer ? mMeshLayer->rendererSettings().edgeMeshSettings().isEnabled() : false );
162
163 onActiveScalarGroupChanged( mMeshLayer->rendererSettings().activeScalarDatasetGroup() );
164 onActiveVectorGroupChanged( mMeshLayer->rendererSettings().activeVectorDatasetGroup() );
165
166 const bool hasFaces = ( mMeshLayer->contains( QgsMesh::ElementType::Face ) );
167 mFaceMeshGroupBox->setVisible( hasFaces || !mMeshLayer->isValid() );
168
169 const bool hasEdges = ( mMeshLayer->contains( QgsMesh::ElementType::Edge ) );
170 mEdgeMeshGroupBox->setVisible( hasEdges || !mMeshLayer->isValid() );
171
172 QgsSettings settings;
173 if ( !settings.contains( QStringLiteral( "/Windows/RendererMeshProperties/tab" ) ) )
174 settings.setValue( QStringLiteral( "/Windows/RendererMeshProperties/tab" ), 0 );
175 else
176 mStyleOptionsTab->setCurrentIndex( settings.value( QStringLiteral( "/Windows/RendererMeshProperties/tab" ) ).toInt() );
177}
178
179void QgsRendererMeshPropertiesWidget::onActiveScalarGroupChanged( int groupIndex )
180{
181 mMeshRendererScalarSettingsWidget->setActiveDatasetGroup( groupIndex );
182 mMeshRendererScalarSettingsWidget->syncToLayer();
183 mContoursGroupBox->setChecked( groupIndex >= 0 );
184 mContoursGroupBox->setEnabled( groupIndex >= 0 );
185}
186
187void QgsRendererMeshPropertiesWidget::onActiveVectorGroupChanged( int groupIndex )
188{
189 if ( groupIndex >= 0 && !mMeshLayer->datasetGroupMetadata( groupIndex ).isVector() )
190 groupIndex = -1;
191 mMeshRendererVectorSettingsWidget->setActiveDatasetGroup( groupIndex );
192 mMeshRendererVectorSettingsWidget->syncToLayer();
193 mVectorsGroupBox->setChecked( groupIndex >= 0 );
194 mVectorsGroupBox->setEnabled( groupIndex >= 0 );
195}
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.