Navigation Menu

Skip to content

Commit

Permalink
fix scientific notation in scale notation that led to wrong interpret…
Browse files Browse the repository at this point in the history
…ation (due to separator character)
  • Loading branch information
speillet authored and nyalldawson committed Jun 4, 2020
1 parent f747066 commit f68f730
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/app/qgsprojectproperties.cpp
Expand Up @@ -387,7 +387,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
{
for ( double scale : projectScales )
{
addScaleToScaleList( QStringLiteral( "1:%1" ).arg( scale ) );
addScaleToScaleList( QStringLiteral( "1:%1" ).arg( QLocale().toString( scale, 'f', 0 ) ) );
}
}
connect( lstScales, &QListWidget::itemChanged, this, &QgsProjectProperties::scaleItemChanged );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsstatusbarscalewidget.cpp
Expand Up @@ -98,7 +98,7 @@ void QgsStatusBarScaleWidget::updateScales()
QStringList textScales;
textScales.reserve( scales.size() );
for ( double scale : scales )
textScales << QStringLiteral( "1:%1" ).arg( scale );
textScales << QStringLiteral( "1:%1" ).arg( QLocale().toString( scale, 'f', 0 ) );
mScale->updateScales( textScales );
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsscalecombobox.cpp
Expand Up @@ -216,7 +216,7 @@ QString QgsScaleComboBox::toString( double scale )
}
else
{
return QStringLiteral( "1:%1" ).arg( QLocale().toString( static_cast< int >( std::round( scale ) ) ) );
return QStringLiteral( "1:%1" ).arg( QLocale().toString( static_cast< float >( std::round( scale ) ), 'f', 0 ) );
}
}

Expand Down
29 changes: 29 additions & 0 deletions tests/src/gui/testqgsscalecombobox.cpp
Expand Up @@ -41,6 +41,7 @@ class TestQgsScaleComboBox : public QObject
void toString();
void toDouble();
void allowNull();
void testLocale();

private:
void enterScale( const QString &scale );
Expand Down Expand Up @@ -256,5 +257,33 @@ void TestQgsScaleComboBox::cleanup()
delete s;
}

void TestQgsScaleComboBox::testLocale()
{
QLocale::setDefault( QLocale::English );
QCOMPARE( s->toString( 1e8 ), QString( "1:100,000,000" ) );
QLocale customEnglish( QLocale::English );
customEnglish.setNumberOptions( QLocale::NumberOption::OmitGroupSeparator );
QLocale::setDefault( customEnglish );
QCOMPARE( s->toString( 1e8 ), QString( "1:100000000" ) );

QLocale::setDefault( QLocale::French );
#if QT_VERSION >= QT_VERSION_CHECK( 5, 12, 0 )
QCOMPARE( s->toString( 1e8 ), QString( "1:100 000 000" ) );
#else
QCOMPARE( s->toString( 1e8 ), QString( "1:100\u00A0000\u00A0000" ) );
#endif
QLocale customFrench( QLocale::French );
customFrench.setNumberOptions( QLocale::NumberOption::OmitGroupSeparator );
QLocale::setDefault( customFrench );
QCOMPARE( s->toString( 1e8 ), QString( "1:100000000" ) );

QLocale::setDefault( QLocale::German );
QCOMPARE( s->toString( 1e8 ), QString( "1:100.000.000" ) );
QLocale customGerman( QLocale::German );
customFrench.setNumberOptions( QLocale::NumberOption::OmitGroupSeparator );
QLocale::setDefault( customFrench );
QCOMPARE( s->toString( 1e8 ), QString( "1:100000000" ) );
}

QGSTEST_MAIN( TestQgsScaleComboBox )
#include "testqgsscalecombobox.moc"

0 comments on commit f68f730

Please sign in to comment.