Skip to content
Permalink
Browse files

fix scientific notation in scale notation that led to wrong interpret…

…ation (due to separator character)

(cherry picked from commit f68f730)
  • Loading branch information
speillet authored and nyalldawson committed Jun 3, 2020
1 parent d054393 commit f4d7c46809ed486dfeade16b57d149dc83a3ffe8
@@ -368,7 +368,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 );
@@ -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
@@ -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 ) );
}
}

@@ -41,6 +41,7 @@ class TestQgsScaleComboBox : public QObject
void toString();
void toDouble();
void allowNull();
void testLocale();

private:
void enterScale( const QString &scale );
@@ -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 f4d7c46

Please sign in to comment.
You can’t perform that action at this time.