From e859d444561f3634e1c46edd1d3f82a215dba258 Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Tue, 19 Jan 2021 17:11:40 +0100 Subject: [PATCH] Fix vertex editor locale with Z/R values Fixes #29682 --- src/app/vertextool/qgsvertexeditor.cpp | 17 ++++++----------- .../qgslocaleawarenumericlineeditdelegate.cpp | 10 ++++++---- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/app/vertextool/qgsvertexeditor.cpp b/src/app/vertextool/qgsvertexeditor.cpp index 112353937aad..4f23aff1a5d1 100644 --- a/src/app/vertextool/qgsvertexeditor.cpp +++ b/src/app/vertextool/qgsvertexeditor.cpp @@ -25,6 +25,7 @@ #include "qgsgeometryutils.h" #include "qgsproject.h" #include "qgscoordinatetransform.h" +#include "qgsdoublevalidator.h" #include #include @@ -237,13 +238,7 @@ bool QgsVertexEditorModel::setData( const QModelIndex &index, const QVariant &va } // Get double value wrt current locale. - bool ok; - double doubleValue = QLocale().toDouble( value.toString(), &ok ); - // If not valid and locale's decimal point is not '.' let's try with english locale - if ( ! ok && QLocale().decimalPoint() != '.' ) - { - doubleValue = QLocale( QLocale::English ).toDouble( value.toString() ); - } + const double doubleValue { QgsDoubleValidator::toDouble( value.toString() ) }; double x = ( index.column() == 0 ? doubleValue : mLockedFeature->vertexMap().at( index.row() )->point().x() ); double y = ( index.column() == 1 ? doubleValue : mLockedFeature->vertexMap().at( index.row() )->point().y() ); @@ -267,8 +262,8 @@ bool QgsVertexEditorModel::setData( const QModelIndex &index, const QVariant &va y = result.y(); } } - double z = ( index.column() == mZCol ? value.toDouble() : mLockedFeature->vertexMap().at( index.row() )->point().z() ); - double m = ( index.column() == mMCol ? value.toDouble() : mLockedFeature->vertexMap().at( index.row() )->point().m() ); + double z = ( index.column() == mZCol ? doubleValue : mLockedFeature->vertexMap().at( index.row() )->point().z() ); + double m = ( index.column() == mMCol ? doubleValue : mLockedFeature->vertexMap().at( index.row() )->point().m() ); QgsPoint p( QgsWkbTypes::PointZM, x, y, z, m ); mLockedFeature->layer()->beginEditCommand( QObject::tr( "Moved vertices" ) ); @@ -489,7 +484,7 @@ QString CoordinateItemDelegate::displayText( const QVariant &value, const QLocal QWidget *CoordinateItemDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index ) const { QLineEdit *lineEdit = new QLineEdit( parent ); - QDoubleValidator *validator = new QDoubleValidator(); + QgsDoubleValidator *validator = new QgsDoubleValidator( lineEdit ); if ( !index.data( MIN_RADIUS_ROLE ).isNull() ) validator->setBottom( index.data( MIN_RADIUS_ROLE ).toDouble() ); lineEdit->setValidator( validator ); @@ -510,7 +505,7 @@ void CoordinateItemDelegate::setEditorData( QWidget *editor, const QModelIndex & QLineEdit *lineEdit = qobject_cast( editor ); if ( lineEdit && index.isValid() ) { - lineEdit->setText( QLocale().toString( index.data( ).toDouble( ), 'f', displayDecimalPlaces() ) ); + lineEdit->setText( displayText( index.data( ).toDouble( ), QLocale() ) ); } } diff --git a/src/gui/qgslocaleawarenumericlineeditdelegate.cpp b/src/gui/qgslocaleawarenumericlineeditdelegate.cpp index c89eda247aeb..953404a3934b 100644 --- a/src/gui/qgslocaleawarenumericlineeditdelegate.cpp +++ b/src/gui/qgslocaleawarenumericlineeditdelegate.cpp @@ -40,13 +40,15 @@ QWidget *QgsLocaleAwareNumericLineEditDelegate::createEditor( QWidget *parent, c void QgsLocaleAwareNumericLineEditDelegate::setEditorData( QWidget *editor, const QModelIndex &index ) const { QLineEdit *lineEdit { qobject_cast( editor ) }; - if ( ! lineEdit ) + if ( lineEdit ) + { + const QVariant value { index.data( ) }; + lineEdit->setText( displayText( value, QLocale() ) ); + } + else { QStyledItemDelegate::setEditorData( editor, index ); } - - const QVariant value { index.data( ) }; - return lineEdit->setText( displayText( value, QLocale() ) ); } void QgsLocaleAwareNumericLineEditDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const