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