Skip to content

Commit 251ebd2

Browse files
elpasonyalldawson
authored andcommittedSep 17, 2021
Fixes custom ellipsoid locale double input
Fixes #45015 Funded by: QGIS Grant 2021
1 parent 6039ded commit 251ebd2

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed
 

‎python/gui/auto_generated/qgsdoublevalidator.sip.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ and ability to be converted in double value.
9393
static double toDouble( const QString &input );
9494
%Docstring
9595
Converts ``input`` string to double value.
96-
It used locale interpretation first
96+
It uses locale interpretation first
9797
and C locale interpretation as fallback
9898
%End
9999

‎src/app/qgsprojectproperties.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "qgssymbolselectordialog.h"
4646
#include "qgsrelationmanagerdialog.h"
4747
#include "qgsrelationmanager.h"
48+
#include "qgsdoublevalidator.h"
4849
#include "qgscolorschemeregistry.h"
4950
#include "qgssymbollayerutils.h"
5051
#include "qgscolordialog.h"
@@ -186,6 +187,9 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
186187
connect( radManual, &QAbstractButton::toggled, spinBoxDP, &QWidget::setEnabled );
187188
connect( radManual, &QAbstractButton::toggled, labelDP, &QWidget::setEnabled );
188189

190+
leSemiMajor->setValidator( new QgsDoubleValidator( leSemiMajor ) );
191+
leSemiMinor->setValidator( new QgsDoubleValidator( leSemiMinor ) );
192+
189193
QgsSettings settings;
190194

191195
///////////////////////////////////////////////////////////
@@ -1137,8 +1141,17 @@ void QgsProjectProperties::apply()
11371141
if ( leSemiMajor->isModified() || leSemiMinor->isModified() )
11381142
{
11391143
QgsDebugMsgLevel( QStringLiteral( "Using parameteric major/minor" ), 4 );
1140-
major = QLocale().toDouble( leSemiMajor->text() );
1141-
minor = QLocale().toDouble( leSemiMinor->text() );
1144+
bool ok;
1145+
double val {QgsDoubleValidator::toDouble( leSemiMajor->text(), &ok )};
1146+
if ( ok )
1147+
{
1148+
major = val;
1149+
}
1150+
val = QgsDoubleValidator::toDouble( leSemiMinor->text(), &ok );
1151+
if ( ok )
1152+
{
1153+
minor = val;
1154+
}
11421155
}
11431156
QgsProject::instance()->setEllipsoid( QStringLiteral( "PARAMETER:%1:%2" )
11441157
.arg( major, 0, 'g', 17 )
@@ -2439,8 +2452,8 @@ void QgsProjectProperties::updateEllipsoidUI( int newIndex )
24392452
if ( leSemiMajor->isModified() || leSemiMinor->isModified() )
24402453
{
24412454
QgsDebugMsgLevel( QStringLiteral( "Saving major/minor" ), 4 );
2442-
mEllipsoidList[ mEllipsoidIndex ].semiMajor = QLocale().toDouble( leSemiMajor->text() );
2443-
mEllipsoidList[ mEllipsoidIndex ].semiMinor = QLocale().toDouble( leSemiMinor->text() );
2455+
mEllipsoidList[ mEllipsoidIndex ].semiMajor = QgsDoubleValidator::toDouble( leSemiMajor->text() );
2456+
mEllipsoidList[ mEllipsoidIndex ].semiMinor = QgsDoubleValidator::toDouble( leSemiMinor->text() );
24442457
}
24452458

24462459
mEllipsoidIndex = newIndex;

‎src/gui/qgsdoublevalidator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ class GUI_EXPORT QgsDoubleValidator : public QRegularExpressionValidator
104104

105105
/**
106106
* Converts \a input string to double value.
107-
* It used locale interpretation first
107+
* It uses locale interpretation first
108108
* and C locale interpretation as fallback
109109
*/
110110
static double toDouble( const QString &input, bool *ok ) SIP_SKIP;
111111

112112
/**
113113
* Converts \a input string to double value.
114-
* It used locale interpretation first
114+
* It uses locale interpretation first
115115
* and C locale interpretation as fallback
116116
*/
117117
static double toDouble( const QString &input );

0 commit comments

Comments
 (0)
Please sign in to comment.