QGIS API Documentation 3.41.0-Master (cea29feecf2)
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
51 // connect
52 connect( mScalarRecalculateMinMaxButton, &QPushButton::clicked, this, &QgsMeshRendererScalarSettingsWidget::recalculateMinMaxButtonClicked );
53 connect( mScalarMinSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, [=]( double ) { minMaxChanged(); } );
54 connect( mScalarMaxSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, [=]( double ) { minMaxChanged(); } );
55 connect( mScalarEdgeStrokeWidthVariableRadioButton, &QRadioButton::toggled, this, &QgsMeshRendererScalarSettingsWidget::onEdgeStrokeWidthMethodChanged );
56
59 connect( mScalarInterpolationTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsMeshRendererScalarSettingsWidget::widgetChanged );
60
61 connect( mScalarEdgeStrokeWidthUnitSelectionWidget, &QgsUnitSelectionWidget::changed, this, &QgsMeshRendererScalarSettingsWidget::widgetChanged );
62 connect( mScalarEdgeStrokeWidthSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, &QgsMeshRendererScalarSettingsWidget::widgetChanged );
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
69{
70 mMeshLayer = layer;
71 mScalarInterpolationTypeComboBox->setEnabled( !dataIsDefinedOnEdges() );
72}
73
75{
76 mActiveDatasetGroup = groupIndex;
77 mScalarInterpolationTypeComboBox->setEnabled( !dataIsDefinedOnEdges() );
78}
79
81{
83 settings.setColorRampShader( mScalarColorRampShaderWidget->shader() );
84 settings.setClassificationMinimumMaximum( spinBoxValue( mScalarMinSpinBox ), spinBoxValue( mScalarMaxSpinBox ) );
85 settings.setOpacity( mOpacityWidget->opacity() );
86 settings.setDataResamplingMethod( dataIntepolationMethod() );
87
88 const bool hasEdges = ( mMeshLayer->contains( QgsMesh::ElementType::Edge ) );
89 if ( hasEdges )
90 {
91 QgsInterpolatedLineWidth edgeStrokeWidth = mScalarEdgeStrokeWidthVariablePushButton->variableStrokeWidth();
92 edgeStrokeWidth.setIsVariableWidth( mScalarEdgeStrokeWidthVariableRadioButton->isChecked() );
93 edgeStrokeWidth.setFixedStrokeWidth( mScalarEdgeStrokeWidthSpinBox->value() );
94 settings.setEdgeStrokeWidth( edgeStrokeWidth );
95 settings.setEdgeStrokeWidthUnit( mScalarEdgeStrokeWidthUnitSelectionWidget->unit() );
96 }
97
98 return settings;
99}
100
102{
103 if ( !mMeshLayer )
104 return;
105
106 if ( mActiveDatasetGroup < 0 )
107 return;
108
109 const QgsMeshRendererSettings rendererSettings = mMeshLayer->rendererSettings();
110 const QgsMeshRendererScalarSettings settings = rendererSettings.scalarSettings( mActiveDatasetGroup );
112 const double min = settings.classificationMinimum();
113 const double max = settings.classificationMaximum();
114
115 whileBlocking( mScalarMinSpinBox )->setValue( min );
116 whileBlocking( mScalarMaxSpinBox )->setValue( max );
117 whileBlocking( mScalarColorRampShaderWidget )->setFromShader( shader );
118 whileBlocking( mScalarColorRampShaderWidget )->setMinimumMaximum( min, max );
119 whileBlocking( mOpacityWidget )->setOpacity( settings.opacity() );
120 const int index = mScalarInterpolationTypeComboBox->findData( settings.dataResamplingMethod() );
121 whileBlocking( mScalarInterpolationTypeComboBox )->setCurrentIndex( index );
122
123 const bool hasEdges = ( mMeshLayer->contains( QgsMesh::ElementType::Edge ) );
124 const bool hasFaces = ( mMeshLayer->contains( QgsMesh::ElementType::Face ) );
125
126 mScalarResamplingWidget->setVisible( hasFaces );
127
128 mEdgeWidthGroupBox->setVisible( hasEdges );
129
130 if ( hasEdges )
131 {
132 const QgsInterpolatedLineWidth edgeStrokeWidth = settings.edgeStrokeWidth();
133 whileBlocking( mScalarEdgeStrokeWidthVariablePushButton )->setVariableStrokeWidth( edgeStrokeWidth );
134 whileBlocking( mScalarEdgeStrokeWidthSpinBox )->setValue( edgeStrokeWidth.fixedStrokeWidth() );
135 whileBlocking( mScalarEdgeStrokeWidthVariableRadioButton )->setChecked( edgeStrokeWidth.isVariableWidth() );
136 whileBlocking( mScalarEdgeStrokeWidthUnitSelectionWidget )->setUnit( settings.edgeStrokeWidthUnit() );
137 if ( !hasFaces )
138 mOpacityContainerWidget->setVisible( false );
139
140 const QgsMeshDatasetGroupMetadata metadata = mMeshLayer->datasetGroupMetadata( mActiveDatasetGroup );
141 const double min = metadata.minimum();
142 const double max = metadata.maximum();
143 mScalarEdgeStrokeWidthVariablePushButton->setDefaultMinMaxValue( min, max );
144 }
145
146 onEdgeStrokeWidthMethodChanged();
147}
148
149double QgsMeshRendererScalarSettingsWidget::spinBoxValue( const QgsDoubleSpinBox *spinBox ) const
150{
151 if ( spinBox->value() == spinBox->clearValue() )
152 {
153 return std::numeric_limits<double>::quiet_NaN();
154 }
155
156 return spinBox->value();
157}
158
159void QgsMeshRendererScalarSettingsWidget::minMaxChanged()
160{
161 const double min = spinBoxValue( mScalarMinSpinBox );
162 const double max = spinBoxValue( mScalarMaxSpinBox );
163 mScalarColorRampShaderWidget->setMinimumMaximumAndClassify( min, max );
164}
165
166void QgsMeshRendererScalarSettingsWidget::recalculateMinMaxButtonClicked()
167{
168 const QgsMeshDatasetGroupMetadata metadata = mMeshLayer->datasetGroupMetadata( mActiveDatasetGroup );
169 const double min = metadata.minimum();
170 const double max = metadata.maximum();
171 whileBlocking( mScalarMinSpinBox )->setValue( min );
172 whileBlocking( mScalarMaxSpinBox )->setValue( max );
173 mScalarColorRampShaderWidget->setMinimumMaximumAndClassify( min, max );
174}
175
176void QgsMeshRendererScalarSettingsWidget::onEdgeStrokeWidthMethodChanged()
177{
178 const bool variableWidth = mScalarEdgeStrokeWidthVariableRadioButton->isChecked();
179 mScalarEdgeStrokeWidthVariablePushButton->setVisible( variableWidth );
180 mScalarEdgeStrokeWidthSpinBox->setVisible( !variableWidth );
181}
182
183QgsMeshRendererScalarSettings::DataResamplingMethod QgsMeshRendererScalarSettingsWidget::dataIntepolationMethod() const
184{
185 const int data = mScalarInterpolationTypeComboBox->currentData().toInt();
187 return method;
188}
189
190bool QgsMeshRendererScalarSettingsWidget::dataIsDefinedOnFaces() const
191{
192 if ( !mMeshLayer )
193 return false;
194
195 if ( mActiveDatasetGroup < 0 )
196 return false;
197
198 const QgsMeshDatasetGroupMetadata meta = mMeshLayer->datasetGroupMetadata( mActiveDatasetGroup );
199 const bool onFaces = ( meta.dataType() == QgsMeshDatasetGroupMetadata::DataOnFaces );
200 return onFaces;
201}
202
203bool QgsMeshRendererScalarSettingsWidget::dataIsDefinedOnEdges() const
204{
205 if ( !mMeshLayer )
206 return false;
207
208 if ( mActiveDatasetGroup < 0 )
209 return false;
210
211 const QgsMeshDatasetGroupMetadata meta = mMeshLayer->datasetGroupMetadata( mActiveDatasetGroup );
212 const bool onEdges = ( meta.dataType() == QgsMeshDatasetGroupMetadata::DataOnEdges );
213 return onEdges;
214}
@ 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:5928