Skip to content

Commit 9b6d2eb

Browse files
elpasonyalldawson
authored andcommittedJan 19, 2021
Fix vertex editor locale with Z/R values
Fixes #29682
1 parent 9cba248 commit 9b6d2eb

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed
 

‎src/app/vertextool/qgsvertexeditor.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "qgsgeometryutils.h"
2626
#include "qgsproject.h"
2727
#include "qgscoordinatetransform.h"
28+
#include "qgsdoublevalidator.h"
2829

2930
#include <QLabel>
3031
#include <QTableWidget>
@@ -237,13 +238,7 @@ bool QgsVertexEditorModel::setData( const QModelIndex &index, const QVariant &va
237238
}
238239

239240
// Get double value wrt current locale.
240-
bool ok;
241-
double doubleValue = QLocale().toDouble( value.toString(), &ok );
242-
// If not valid and locale's decimal point is not '.' let's try with english locale
243-
if ( ! ok && QLocale().decimalPoint() != '.' )
244-
{
245-
doubleValue = QLocale( QLocale::English ).toDouble( value.toString() );
246-
}
241+
const double doubleValue { QgsDoubleValidator::toDouble( value.toString() ) };
247242

248243
double x = ( index.column() == 0 ? doubleValue : mLockedFeature->vertexMap().at( index.row() )->point().x() );
249244
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
267262
y = result.y();
268263
}
269264
}
270-
double z = ( index.column() == mZCol ? value.toDouble() : mLockedFeature->vertexMap().at( index.row() )->point().z() );
271-
double m = ( index.column() == mMCol ? value.toDouble() : mLockedFeature->vertexMap().at( index.row() )->point().m() );
265+
double z = ( index.column() == mZCol ? doubleValue : mLockedFeature->vertexMap().at( index.row() )->point().z() );
266+
double m = ( index.column() == mMCol ? doubleValue : mLockedFeature->vertexMap().at( index.row() )->point().m() );
272267
QgsPoint p( QgsWkbTypes::PointZM, x, y, z, m );
273268

274269
mLockedFeature->layer()->beginEditCommand( QObject::tr( "Moved vertices" ) );
@@ -489,7 +484,7 @@ QString CoordinateItemDelegate::displayText( const QVariant &value, const QLocal
489484
QWidget *CoordinateItemDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index ) const
490485
{
491486
QLineEdit *lineEdit = new QLineEdit( parent );
492-
QDoubleValidator *validator = new QDoubleValidator();
487+
QgsDoubleValidator *validator = new QgsDoubleValidator( lineEdit );
493488
if ( !index.data( MIN_RADIUS_ROLE ).isNull() )
494489
validator->setBottom( index.data( MIN_RADIUS_ROLE ).toDouble() );
495490
lineEdit->setValidator( validator );
@@ -510,7 +505,7 @@ void CoordinateItemDelegate::setEditorData( QWidget *editor, const QModelIndex &
510505
QLineEdit *lineEdit = qobject_cast<QLineEdit *>( editor );
511506
if ( lineEdit && index.isValid() )
512507
{
513-
lineEdit->setText( QLocale().toString( index.data( ).toDouble( ), 'f', displayDecimalPlaces() ) );
508+
lineEdit->setText( displayText( index.data( ).toDouble( ), QLocale() ) );
514509
}
515510
}
516511

‎src/gui/qgslocaleawarenumericlineeditdelegate.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ QWidget *QgsLocaleAwareNumericLineEditDelegate::createEditor( QWidget *parent, c
4040
void QgsLocaleAwareNumericLineEditDelegate::setEditorData( QWidget *editor, const QModelIndex &index ) const
4141
{
4242
QLineEdit *lineEdit { qobject_cast<QLineEdit *>( editor ) };
43-
if ( ! lineEdit )
43+
if ( lineEdit )
44+
{
45+
const QVariant value { index.data( ) };
46+
lineEdit->setText( displayText( value, QLocale() ) );
47+
}
48+
else
4449
{
4550
QStyledItemDelegate::setEditorData( editor, index );
4651
}
47-
48-
const QVariant value { index.data( ) };
49-
return lineEdit->setText( displayText( value, QLocale() ) );
5052
}
5153

5254
void QgsLocaleAwareNumericLineEditDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const

0 commit comments

Comments
 (0)
Please sign in to comment.