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