Navigation Menu

Skip to content

Commit

Permalink
Fixes custom ellipsoid locale double input
Browse files Browse the repository at this point in the history
Fixes #45015

Funded by: QGIS Grant 2021
  • Loading branch information
elpaso authored and nyalldawson committed Sep 17, 2021
1 parent 6039ded commit 251ebd2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion python/gui/auto_generated/qgsdoublevalidator.sip.in
Expand Up @@ -93,7 +93,7 @@ and ability to be converted in double value.
static double toDouble( const QString &input );
%Docstring
Converts ``input`` string to double value.
It used locale interpretation first
It uses locale interpretation first
and C locale interpretation as fallback
%End

Expand Down
21 changes: 17 additions & 4 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -45,6 +45,7 @@
#include "qgssymbolselectordialog.h"
#include "qgsrelationmanagerdialog.h"
#include "qgsrelationmanager.h"
#include "qgsdoublevalidator.h"
#include "qgscolorschemeregistry.h"
#include "qgssymbollayerutils.h"
#include "qgscolordialog.h"
Expand Down Expand Up @@ -186,6 +187,9 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
connect( radManual, &QAbstractButton::toggled, spinBoxDP, &QWidget::setEnabled );
connect( radManual, &QAbstractButton::toggled, labelDP, &QWidget::setEnabled );

leSemiMajor->setValidator( new QgsDoubleValidator( leSemiMajor ) );
leSemiMinor->setValidator( new QgsDoubleValidator( leSemiMinor ) );

QgsSettings settings;

///////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1137,8 +1141,17 @@ void QgsProjectProperties::apply()
if ( leSemiMajor->isModified() || leSemiMinor->isModified() )
{
QgsDebugMsgLevel( QStringLiteral( "Using parameteric major/minor" ), 4 );
major = QLocale().toDouble( leSemiMajor->text() );
minor = QLocale().toDouble( leSemiMinor->text() );
bool ok;
double val {QgsDoubleValidator::toDouble( leSemiMajor->text(), &ok )};
if ( ok )
{
major = val;
}
val = QgsDoubleValidator::toDouble( leSemiMinor->text(), &ok );
if ( ok )
{
minor = val;
}
}
QgsProject::instance()->setEllipsoid( QStringLiteral( "PARAMETER:%1:%2" )
.arg( major, 0, 'g', 17 )
Expand Down Expand Up @@ -2439,8 +2452,8 @@ void QgsProjectProperties::updateEllipsoidUI( int newIndex )
if ( leSemiMajor->isModified() || leSemiMinor->isModified() )
{
QgsDebugMsgLevel( QStringLiteral( "Saving major/minor" ), 4 );
mEllipsoidList[ mEllipsoidIndex ].semiMajor = QLocale().toDouble( leSemiMajor->text() );
mEllipsoidList[ mEllipsoidIndex ].semiMinor = QLocale().toDouble( leSemiMinor->text() );
mEllipsoidList[ mEllipsoidIndex ].semiMajor = QgsDoubleValidator::toDouble( leSemiMajor->text() );
mEllipsoidList[ mEllipsoidIndex ].semiMinor = QgsDoubleValidator::toDouble( leSemiMinor->text() );
}

mEllipsoidIndex = newIndex;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsdoublevalidator.h
Expand Up @@ -104,14 +104,14 @@ class GUI_EXPORT QgsDoubleValidator : public QRegularExpressionValidator

/**
* Converts \a input string to double value.
* It used locale interpretation first
* It uses locale interpretation first
* and C locale interpretation as fallback
*/
static double toDouble( const QString &input, bool *ok ) SIP_SKIP;

/**
* Converts \a input string to double value.
* It used locale interpretation first
* It uses locale interpretation first
* and C locale interpretation as fallback
*/
static double toDouble( const QString &input );
Expand Down

0 comments on commit 251ebd2

Please sign in to comment.