fix classification of singleband pseudocolor (#43346) (#43455)

fixes #43346
This commit is contained in:
Vincent Cloarec 2021-05-31 17:06:50 -04:00 committed by GitHub
parent 457165d7be
commit 383065d27f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View File

@ -190,6 +190,9 @@ void QgsSingleBandPseudoColorRendererWidget::loadMinMax( int bandNo, double min,
{
QgsDebugMsg( QStringLiteral( "theBandNo = %1 min = %2 max = %3" ).arg( bandNo ).arg( min ).arg( max ) );
const QString oldMinTextvalue = mMinLineEdit->text();
const QString oldMaxTextvalue = mMaxLineEdit->text();
if ( std::isnan( min ) )
{
whileBlocking( mMinLineEdit )->clear();
@ -211,7 +214,7 @@ void QgsSingleBandPseudoColorRendererWidget::loadMinMax( int bandNo, double min,
// We compare old min and new min as text because QString::number keeps a fixed number of significant
// digits (default 6) and so loaded min/max will always differ from current one, which triggers a
// classification, and wipe out every user modification (see https://github.com/qgis/QGIS/issues/36172)
if ( mMinLineEdit->text() != displayValueWithMaxPrecision( min ) || mMaxLineEdit->text() != displayValueWithMaxPrecision( max ) )
if ( mMinLineEdit->text() != oldMinTextvalue || mMaxLineEdit->text() != oldMaxTextvalue )
{
whileBlocking( mColorRampShaderWidget )->setRasterBand( bandNo );
whileBlocking( mColorRampShaderWidget )->setMinimumMaximumAndClassify( min, max );

View File

@ -84,6 +84,7 @@ class GUI_EXPORT QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendere
// Convert min/max to localized display value with maximum precision for the current data type
QString displayValueWithMaxPrecision( const double value );
friend class TestQgsSingleBandPseudoColorRendererWidget;
};
#endif // QGSSINGLEBANDCOLORRENDERERWIDGET_H

View File

@ -112,6 +112,21 @@ void TestQgsSingleBandPseudoColorRendererWidget::testEditLabel()
QList<QgsColorRampShader::ColorRampItem> newColorRampItems = newColorRampShader->colorRampItemList();
QCOMPARE( newColorRampItems.at( 0 ).label, QStringLiteral( "zero" ) );
QCOMPARE( widget.mMinLineEdit->text(), widget.displayValueWithMaxPrecision( widget.mColorRampShaderWidget->minimum() ) );
QCOMPARE( widget.mMaxLineEdit->text(), widget.displayValueWithMaxPrecision( widget.mColorRampShaderWidget->maximum() ) );
QCOMPARE( widget.mMinLineEdit->text(), widget.displayValueWithMaxPrecision( widget.mColorRampShaderWidget->shader().minimumValue() ) );
QCOMPARE( widget.mMaxLineEdit->text(), widget.displayValueWithMaxPrecision( widget.mColorRampShaderWidget->shader().maximumValue() ) );
// change the min/max
widget.loadMinMax( 1, min + 1.0, max - 1.0 );
QCOMPARE( widget.mMinLineEdit->text(), widget.displayValueWithMaxPrecision( min + 1.0 ) );
QCOMPARE( widget.mMaxLineEdit->text(), widget.displayValueWithMaxPrecision( max - 1.0 ) );
QCOMPARE( widget.mMinLineEdit->text(), widget.displayValueWithMaxPrecision( widget.mColorRampShaderWidget->minimum() ) );
QCOMPARE( widget.mMaxLineEdit->text(), widget.displayValueWithMaxPrecision( widget.mColorRampShaderWidget->maximum() ) );
QCOMPARE( widget.mMinLineEdit->text(), widget.displayValueWithMaxPrecision( widget.mColorRampShaderWidget->shader().minimumValue() ) );
QCOMPARE( widget.mMaxLineEdit->text(), widget.displayValueWithMaxPrecision( widget.mColorRampShaderWidget->shader().maximumValue() ) );
}