QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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
18#include "QDialogButtonBox"
19
20#include "qgis.h"
21#include "qgsmeshlayer.h"
23#include <QPointer>
24
26 : QWidget( parent )
27
28{
29 setupUi( this );
30
31 mScalarMinSpinBox->setClearValueMode( QgsDoubleSpinBox::ClearValueMode::MinimumValue );
32 mScalarMinSpinBox->setSpecialValueText( QString( ) );
33 mScalarMaxSpinBox->setClearValueMode( QgsDoubleSpinBox::ClearValueMode::MinimumValue );
34 mScalarMaxSpinBox->setSpecialValueText( QString( ) );
35
36 // add items to data interpolation combo box
37 mScalarInterpolationTypeComboBox->addItem( tr( "No Resampling" ), QgsMeshRendererScalarSettings::NoResampling );
38 mScalarInterpolationTypeComboBox->addItem( tr( "Neighbour Average" ), QgsMeshRendererScalarSettings::NeighbourAverage );
39 mScalarInterpolationTypeComboBox->setCurrentIndex( 0 );
40
41 mScalarEdgeStrokeWidthUnitSelectionWidget->setUnits(
42 {
47 } );
48
49 // connect
50 connect( mScalarRecalculateMinMaxButton, &QPushButton::clicked, this, &QgsMeshRendererScalarSettingsWidget::recalculateMinMaxButtonClicked );
51 connect( mScalarMinSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, [ = ]( double ) { minMaxChanged(); } );
52 connect( mScalarMaxSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, [ = ]( double ) { minMaxChanged(); } );
53 connect( mScalarEdgeStrokeWidthVariableRadioButton, &QRadioButton::toggled, this, &QgsMeshRendererScalarSettingsWidget::onEdgeStrokeWidthMethodChanged );
54
57 connect( mScalarInterpolationTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsMeshRendererScalarSettingsWidget::widgetChanged );
58
59 connect( mScalarEdgeStrokeWidthUnitSelectionWidget, &QgsUnitSelectionWidget::changed,
61 connect( mScalarEdgeStrokeWidthSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
63 connect( mScalarEdgeStrokeWidthVariableRadioButton, &QCheckBox::toggled, this, &QgsMeshRendererScalarSettingsWidget::widgetChanged );
64 connect( mScalarEdgeStrokeWidthFixedRadioButton, &QCheckBox::toggled, this, &QgsMeshRendererScalarSettingsWidget::widgetChanged );
65 connect( mScalarEdgeStrokeWidthVariablePushButton, &QgsMeshVariableStrokeWidthButton::widgetChanged, this, &QgsMeshRendererScalarSettingsWidget::widgetChanged );
66
67}
68
70{
71 mMeshLayer = layer;
72 mScalarInterpolationTypeComboBox->setEnabled( !dataIsDefinedOnEdges() );
73}
74
76{
77 mActiveDatasetGroup = groupIndex;
78 mScalarInterpolationTypeComboBox->setEnabled( !dataIsDefinedOnEdges() );
79}
80
82{
84 settings.setColorRampShader( mScalarColorRampShaderWidget->shader() );
85 settings.setClassificationMinimumMaximum( spinBoxValue( mScalarMinSpinBox ), spinBoxValue( mScalarMaxSpinBox ) );
86 settings.setOpacity( mOpacityWidget->opacity() );
87 settings.setDataResamplingMethod( dataIntepolationMethod() );
88
89 const bool hasEdges = ( mMeshLayer->contains( QgsMesh::ElementType::Edge ) );
90 if ( hasEdges )
91 {
92
93 QgsInterpolatedLineWidth edgeStrokeWidth = mScalarEdgeStrokeWidthVariablePushButton->variableStrokeWidth();
94 edgeStrokeWidth.setIsVariableWidth( mScalarEdgeStrokeWidthVariableRadioButton->isChecked() );
95 edgeStrokeWidth.setFixedStrokeWidth( mScalarEdgeStrokeWidthSpinBox->value() );
96 settings.setEdgeStrokeWidth( edgeStrokeWidth );
97 settings.setEdgeStrokeWidthUnit( mScalarEdgeStrokeWidthUnitSelectionWidget->unit() );
98 }
99
100 return settings;
101}
102
104{
105 if ( !mMeshLayer )
106 return;
107
108 if ( mActiveDatasetGroup < 0 )
109 return;
110
111 const QgsMeshRendererSettings rendererSettings = mMeshLayer->rendererSettings();
112 const QgsMeshRendererScalarSettings settings = rendererSettings.scalarSettings( mActiveDatasetGroup );
114 const double min = settings.classificationMinimum();
115 const double max = settings.classificationMaximum();
116
117 whileBlocking( mScalarMinSpinBox )->setValue( min );
118 whileBlocking( mScalarMaxSpinBox )->setValue( max );
119 whileBlocking( mScalarColorRampShaderWidget )->setFromShader( shader );
120 whileBlocking( mScalarColorRampShaderWidget )->setMinimumMaximum( min, max );
121 whileBlocking( mOpacityWidget )->setOpacity( settings.opacity() );
122 const int index = mScalarInterpolationTypeComboBox->findData( settings.dataResamplingMethod() );
123 whileBlocking( mScalarInterpolationTypeComboBox )->setCurrentIndex( index );
124
125 const bool hasEdges = ( mMeshLayer->contains( QgsMesh::ElementType::Edge ) );
126 const bool hasFaces = ( mMeshLayer->contains( QgsMesh::ElementType::Face ) );
127
128 mScalarResamplingWidget->setVisible( hasFaces );
129
130 mEdgeWidthGroupBox->setVisible( hasEdges );
131
132 if ( hasEdges )
133 {
134 const QgsInterpolatedLineWidth edgeStrokeWidth = settings.edgeStrokeWidth();
135 whileBlocking( mScalarEdgeStrokeWidthVariablePushButton )->setVariableStrokeWidth( edgeStrokeWidth );
136 whileBlocking( mScalarEdgeStrokeWidthSpinBox )->setValue( edgeStrokeWidth.fixedStrokeWidth() );
137 whileBlocking( mScalarEdgeStrokeWidthVariableRadioButton )->setChecked( edgeStrokeWidth.isVariableWidth() );
138 whileBlocking( mScalarEdgeStrokeWidthUnitSelectionWidget )->setUnit( settings.edgeStrokeWidthUnit() );
139 if ( !hasFaces )
140 mOpacityContainerWidget->setVisible( false );
141
142 const QgsMeshDatasetGroupMetadata metadata = mMeshLayer->datasetGroupMetadata( mActiveDatasetGroup );
143 const double min = metadata.minimum();
144 const double max = metadata.maximum();
145 mScalarEdgeStrokeWidthVariablePushButton->setDefaultMinMaxValue( min, max );
146 }
147
148 onEdgeStrokeWidthMethodChanged();
149}
150
151double QgsMeshRendererScalarSettingsWidget::spinBoxValue( const QgsDoubleSpinBox *spinBox ) const
152{
153 if ( spinBox->value() == spinBox->clearValue() )
154 {
155 return std::numeric_limits<double>::quiet_NaN();
156 }
157
158 return spinBox->value();
159}
160
161void QgsMeshRendererScalarSettingsWidget::minMaxChanged()
162{
163 const double min = spinBoxValue( mScalarMinSpinBox );
164 const double max = spinBoxValue( mScalarMaxSpinBox );
165 mScalarColorRampShaderWidget->setMinimumMaximumAndClassify( min, max );
166}
167
168void QgsMeshRendererScalarSettingsWidget::recalculateMinMaxButtonClicked()
169{
170 const QgsMeshDatasetGroupMetadata metadata = mMeshLayer->datasetGroupMetadata( mActiveDatasetGroup );
171 const double min = metadata.minimum();
172 const double max = metadata.maximum();
173 whileBlocking( mScalarMinSpinBox )->setValue( min );
174 whileBlocking( mScalarMaxSpinBox )->setValue( max );
175 mScalarColorRampShaderWidget->setMinimumMaximumAndClassify( min, max );
176}
177
178void QgsMeshRendererScalarSettingsWidget::onEdgeStrokeWidthMethodChanged()
179{
180 const bool variableWidth = mScalarEdgeStrokeWidthVariableRadioButton->isChecked();
181 mScalarEdgeStrokeWidthVariablePushButton->setVisible( variableWidth );
182 mScalarEdgeStrokeWidthSpinBox->setVisible( !variableWidth );
183}
184
185QgsMeshRendererScalarSettings::DataResamplingMethod QgsMeshRendererScalarSettingsWidget::dataIntepolationMethod() const
186{
187 const int data = mScalarInterpolationTypeComboBox->currentData().toInt();
189 return method;
190}
191
192bool QgsMeshRendererScalarSettingsWidget::dataIsDefinedOnFaces() const
193{
194 if ( !mMeshLayer )
195 return false;
196
197 if ( mActiveDatasetGroup < 0 )
198 return false;
199
200 const QgsMeshDatasetGroupMetadata meta = mMeshLayer->datasetGroupMetadata( mActiveDatasetGroup );
201 const bool onFaces = ( meta.dataType() == QgsMeshDatasetGroupMetadata::DataOnFaces );
202 return onFaces;
203}
204
205bool QgsMeshRendererScalarSettingsWidget::dataIsDefinedOnEdges() const
206{
207 if ( !mMeshLayer )
208 return false;
209
210 if ( mActiveDatasetGroup < 0 )
211 return false;
212
213 const QgsMeshDatasetGroupMetadata meta = mMeshLayer->datasetGroupMetadata( mActiveDatasetGroup );
214 const bool onEdges = ( meta.dataType() == QgsMeshDatasetGroupMetadata::DataOnEdges );
215 return onEdges;
216}
217
218
@ 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:5821