QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsmeshrendererscalarsettingswidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmeshrendererscalarsettingswidget.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_qgsmeshrendererscalarsettingswidget.cpp"
18
19#include "QDialogButtonBox"
20
21#include "qgis.h"
22#include "qgsmeshlayer.h"
24#include <QPointer>
25
27 : QWidget( parent )
28
29{
30 setupUi( this );
31
32 mScalarMinSpinBox->setClearValueMode( QgsDoubleSpinBox::ClearValueMode::MinimumValue );
33 mScalarMinSpinBox->setSpecialValueText( QString( ) );
34 mScalarMaxSpinBox->setClearValueMode( QgsDoubleSpinBox::ClearValueMode::MinimumValue );
35 mScalarMaxSpinBox->setSpecialValueText( QString( ) );
36
37 // add items to data interpolation combo box
38 mScalarInterpolationTypeComboBox->addItem( tr( "No Resampling" ), QgsMeshRendererScalarSettings::NoResampling );
39 mScalarInterpolationTypeComboBox->addItem( tr( "Neighbour Average" ), QgsMeshRendererScalarSettings::NeighbourAverage );
40 mScalarInterpolationTypeComboBox->setCurrentIndex( 0 );
41
42 mScalarEdgeStrokeWidthUnitSelectionWidget->setUnits(
43 {
48 } );
49
50 // connect
51 connect( mScalarRecalculateMinMaxButton, &QPushButton::clicked, this, &QgsMeshRendererScalarSettingsWidget::recalculateMinMaxButtonClicked );
52 connect( mScalarMinSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, [ = ]( double ) { minMaxChanged(); } );
53 connect( mScalarMaxSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, [ = ]( double ) { minMaxChanged(); } );
54 connect( mScalarEdgeStrokeWidthVariableRadioButton, &QRadioButton::toggled, this, &QgsMeshRendererScalarSettingsWidget::onEdgeStrokeWidthMethodChanged );
55
58 connect( mScalarInterpolationTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsMeshRendererScalarSettingsWidget::widgetChanged );
59
60 connect( mScalarEdgeStrokeWidthUnitSelectionWidget, &QgsUnitSelectionWidget::changed,
62 connect( mScalarEdgeStrokeWidthSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
64 connect( mScalarEdgeStrokeWidthVariableRadioButton, &QCheckBox::toggled, this, &QgsMeshRendererScalarSettingsWidget::widgetChanged );
65 connect( mScalarEdgeStrokeWidthFixedRadioButton, &QCheckBox::toggled, this, &QgsMeshRendererScalarSettingsWidget::widgetChanged );
66 connect( mScalarEdgeStrokeWidthVariablePushButton, &QgsMeshVariableStrokeWidthButton::widgetChanged, this, &QgsMeshRendererScalarSettingsWidget::widgetChanged );
67
68}
69
71{
72 mMeshLayer = layer;
73 mScalarInterpolationTypeComboBox->setEnabled( !dataIsDefinedOnEdges() );
74}
75
77{
78 mActiveDatasetGroup = groupIndex;
79 mScalarInterpolationTypeComboBox->setEnabled( !dataIsDefinedOnEdges() );
80}
81
83{
85 settings.setColorRampShader( mScalarColorRampShaderWidget->shader() );
86 settings.setClassificationMinimumMaximum( spinBoxValue( mScalarMinSpinBox ), spinBoxValue( mScalarMaxSpinBox ) );
87 settings.setOpacity( mOpacityWidget->opacity() );
88 settings.setDataResamplingMethod( dataIntepolationMethod() );
89
90 const bool hasEdges = ( mMeshLayer->contains( QgsMesh::ElementType::Edge ) );
91 if ( hasEdges )
92 {
93
94 QgsInterpolatedLineWidth edgeStrokeWidth = mScalarEdgeStrokeWidthVariablePushButton->variableStrokeWidth();
95 edgeStrokeWidth.setIsVariableWidth( mScalarEdgeStrokeWidthVariableRadioButton->isChecked() );
96 edgeStrokeWidth.setFixedStrokeWidth( mScalarEdgeStrokeWidthSpinBox->value() );
97 settings.setEdgeStrokeWidth( edgeStrokeWidth );
98 settings.setEdgeStrokeWidthUnit( mScalarEdgeStrokeWidthUnitSelectionWidget->unit() );
99 }
100
101 return settings;
102}
103
105{
106 if ( !mMeshLayer )
107 return;
108
109 if ( mActiveDatasetGroup < 0 )
110 return;
111
112 const QgsMeshRendererSettings rendererSettings = mMeshLayer->rendererSettings();
113 const QgsMeshRendererScalarSettings settings = rendererSettings.scalarSettings( mActiveDatasetGroup );
115 const double min = settings.classificationMinimum();
116 const double max = settings.classificationMaximum();
117
118 whileBlocking( mScalarMinSpinBox )->setValue( min );
119 whileBlocking( mScalarMaxSpinBox )->setValue( max );
120 whileBlocking( mScalarColorRampShaderWidget )->setFromShader( shader );
121 whileBlocking( mScalarColorRampShaderWidget )->setMinimumMaximum( min, max );
122 whileBlocking( mOpacityWidget )->setOpacity( settings.opacity() );
123 const int index = mScalarInterpolationTypeComboBox->findData( settings.dataResamplingMethod() );
124 whileBlocking( mScalarInterpolationTypeComboBox )->setCurrentIndex( index );
125
126 const bool hasEdges = ( mMeshLayer->contains( QgsMesh::ElementType::Edge ) );
127 const bool hasFaces = ( mMeshLayer->contains( QgsMesh::ElementType::Face ) );
128
129 mScalarResamplingWidget->setVisible( hasFaces );
130
131 mEdgeWidthGroupBox->setVisible( hasEdges );
132
133 if ( hasEdges )
134 {
135 const QgsInterpolatedLineWidth edgeStrokeWidth = settings.edgeStrokeWidth();
136 whileBlocking( mScalarEdgeStrokeWidthVariablePushButton )->setVariableStrokeWidth( edgeStrokeWidth );
137 whileBlocking( mScalarEdgeStrokeWidthSpinBox )->setValue( edgeStrokeWidth.fixedStrokeWidth() );
138 whileBlocking( mScalarEdgeStrokeWidthVariableRadioButton )->setChecked( edgeStrokeWidth.isVariableWidth() );
139 whileBlocking( mScalarEdgeStrokeWidthUnitSelectionWidget )->setUnit( settings.edgeStrokeWidthUnit() );
140 if ( !hasFaces )
141 mOpacityContainerWidget->setVisible( false );
142
143 const QgsMeshDatasetGroupMetadata metadata = mMeshLayer->datasetGroupMetadata( mActiveDatasetGroup );
144 const double min = metadata.minimum();
145 const double max = metadata.maximum();
146 mScalarEdgeStrokeWidthVariablePushButton->setDefaultMinMaxValue( min, max );
147 }
148
149 onEdgeStrokeWidthMethodChanged();
150}
151
152double QgsMeshRendererScalarSettingsWidget::spinBoxValue( const QgsDoubleSpinBox *spinBox ) const
153{
154 if ( spinBox->value() == spinBox->clearValue() )
155 {
156 return std::numeric_limits<double>::quiet_NaN();
157 }
158
159 return spinBox->value();
160}
161
162void QgsMeshRendererScalarSettingsWidget::minMaxChanged()
163{
164 const double min = spinBoxValue( mScalarMinSpinBox );
165 const double max = spinBoxValue( mScalarMaxSpinBox );
166 mScalarColorRampShaderWidget->setMinimumMaximumAndClassify( min, max );
167}
168
169void QgsMeshRendererScalarSettingsWidget::recalculateMinMaxButtonClicked()
170{
171 const QgsMeshDatasetGroupMetadata metadata = mMeshLayer->datasetGroupMetadata( mActiveDatasetGroup );
172 const double min = metadata.minimum();
173 const double max = metadata.maximum();
174 whileBlocking( mScalarMinSpinBox )->setValue( min );
175 whileBlocking( mScalarMaxSpinBox )->setValue( max );
176 mScalarColorRampShaderWidget->setMinimumMaximumAndClassify( min, max );
177}
178
179void QgsMeshRendererScalarSettingsWidget::onEdgeStrokeWidthMethodChanged()
180{
181 const bool variableWidth = mScalarEdgeStrokeWidthVariableRadioButton->isChecked();
182 mScalarEdgeStrokeWidthVariablePushButton->setVisible( variableWidth );
183 mScalarEdgeStrokeWidthSpinBox->setVisible( !variableWidth );
184}
185
186QgsMeshRendererScalarSettings::DataResamplingMethod QgsMeshRendererScalarSettingsWidget::dataIntepolationMethod() const
187{
188 const int data = mScalarInterpolationTypeComboBox->currentData().toInt();
190 return method;
191}
192
193bool QgsMeshRendererScalarSettingsWidget::dataIsDefinedOnFaces() const
194{
195 if ( !mMeshLayer )
196 return false;
197
198 if ( mActiveDatasetGroup < 0 )
199 return false;
200
201 const QgsMeshDatasetGroupMetadata meta = mMeshLayer->datasetGroupMetadata( mActiveDatasetGroup );
202 const bool onFaces = ( meta.dataType() == QgsMeshDatasetGroupMetadata::DataOnFaces );
203 return onFaces;
204}
205
206bool QgsMeshRendererScalarSettingsWidget::dataIsDefinedOnEdges() const
207{
208 if ( !mMeshLayer )
209 return false;
210
211 if ( mActiveDatasetGroup < 0 )
212 return false;
213
214 const QgsMeshDatasetGroupMetadata meta = mMeshLayer->datasetGroupMetadata( mActiveDatasetGroup );
215 const bool onEdges = ( meta.dataType() == QgsMeshDatasetGroupMetadata::DataOnEdges );
216 return onEdges;
217}
218
219
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes)
@ MetersInMapUnits
Meters value as Map units.
void widgetChanged()
Widget changed.
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
@ MinimumValue
Reset value to minimum()
Represents a width than can vary depending on values.
void setFixedStrokeWidth(double fixedWidth)
Sets the fixed width.
void setIsVariableWidth(bool isVariableWidth)
Returns whether the width is variable.
double fixedStrokeWidth() const
Returns the fixed width.
bool isVariableWidth() const
Returns whether the width is variable.
QgsMeshDatasetGroupMetadata is a collection of dataset group metadata such as whether the data is vec...
DataType dataType() const
Returns whether dataset group data is defined on vertices or faces or volumes.
double minimum() const
Returns minimum scalar value/vector magnitude present for whole dataset group.
double maximum() const
Returns maximum scalar value/vector magnitude present for whole dataset group.
@ DataOnEdges
Data is defined on edges.
@ DataOnFaces
Data is defined on faces.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
bool contains(const QgsMesh::ElementType &type) const
Returns whether the mesh contains at mesh elements of given type.
QgsMeshRendererSettings rendererSettings() const
Returns renderer settings.
QgsMeshDatasetGroupMetadata datasetGroupMetadata(const QgsMeshDatasetIndex &index) const
Returns the dataset groups metadata.
void syncToLayer()
Synchronizes widgets state with associated mesh layer.
void setLayer(QgsMeshLayer *layer)
Associates mesh layer with the widget.
void widgetChanged()
Mesh rendering settings changed.
QgsMeshRendererScalarSettings settings() const
Returns scalar settings.
QgsMeshRendererScalarSettingsWidget(QWidget *parent=nullptr)
A widget to hold the renderer scalar settings for a mesh layer.
void setActiveDatasetGroup(int groupIndex)
Associates a dataset group with the widget (should be set before syncToLayer())
Represents a mesh renderer settings for scalar datasets.
void setClassificationMinimumMaximum(double minimum, double maximum)
Sets min/max values used for creation of the color ramp shader.
double opacity() const
Returns opacity.
void setEdgeStrokeWidthUnit(Qgis::RenderUnit edgeStrokeWidthUnit)
Sets the stroke width unit used to render edges scalar dataset.
void setColorRampShader(const QgsColorRampShader &shader)
Sets color ramp shader function.
QgsColorRampShader colorRampShader() const
Returns color ramp shader function.
double classificationMinimum() const
Returns min value used for creation of the color ramp shader.
void setOpacity(double opacity)
Sets opacity.
DataResamplingMethod
Resampling of value from dataset.
@ NoResampling
Does not use resampling.
@ NeighbourAverage
Does a simple average of values defined for all surrounding faces/vertices.
Qgis::RenderUnit edgeStrokeWidthUnit() const
Returns the stroke width unit used to render edges scalar dataset.
DataResamplingMethod dataResamplingMethod() const
Returns the type of interpolation to use to convert face defined datasets to values on vertices.
void setEdgeStrokeWidth(const QgsInterpolatedLineWidth &strokeWidth)
Sets the stroke width used to render edges scalar dataset.
double classificationMaximum() const
Returns max value used for creation of the color ramp shader.
QgsInterpolatedLineWidth edgeStrokeWidth() const
Returns the stroke width used to render edges scalar dataset.
void setDataResamplingMethod(const DataResamplingMethod &dataResamplingMethod)
Sets data interpolation method.
Represents all mesh renderer settings.
QgsMeshRendererScalarSettings scalarSettings(int groupIndex) const
Returns renderer settings.
void opacityChanged(double opacity)
Emitted when the opacity is changed in the widget, where opacity ranges from 0.0 (transparent) to 1....
void changed()
Emitted when the selected unit is changed, or the definition of the map unit scale is changed.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:5862