Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[backport] fix classification of singleband pseudocolor (#43346)
  • Loading branch information
vcloarec authored and nyalldawson committed Jun 7, 2021
1 parent 6c866cc commit 2d194ea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp
Expand Up @@ -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();
Expand All @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/gui/raster/qgssinglebandpseudocolorrendererwidget.h
Expand Up @@ -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
15 changes: 15 additions & 0 deletions tests/src/gui/testqgssinglebandpseudocolorrendererwidget.cpp
Expand Up @@ -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() ) );
}


Expand Down

0 comments on commit 2d194ea

Please sign in to comment.