Skip to content
Permalink
Browse files

Fix vertex editor locale with Z/R values

Fixes #29682

Manual backport of master commit e859d44
  • Loading branch information
elpaso authored and nyalldawson committed Feb 19, 2021
1 parent f88729c commit bbe476ad00aa9d2d77ff055c62f16f1b76b1e467
Showing with 12 additions and 15 deletions.
  1. +6 −11 src/app/vertextool/qgsvertexeditor.cpp
  2. +6 −4 src/gui/qgslocaleawarenumericlineeditdelegate.cpp
@@ -24,6 +24,7 @@
#include "qgsgeometryutils.h"
#include "qgsproject.h"
#include "qgscoordinatetransform.h"
#include "qgsdoublevalidator.h"

#include <QLabel>
#include <QTableWidget>
@@ -236,13 +237,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() );
@@ -266,8 +261,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" ) );
@@ -483,7 +478,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 );
@@ -504,6 +499,6 @@ void CoordinateItemDelegate::setEditorData( QWidget *editor, const QModelIndex &
QLineEdit *lineEdit = qobject_cast<QLineEdit *>( editor );
if ( lineEdit && index.isValid() )
{
lineEdit->setText( QLocale().toString( index.data( ).toDouble( ), 'f', 4 ) );
lineEdit->setText( displayText( index.data( ).toDouble( ), QLocale() ) );
}
}
@@ -40,13 +40,15 @@ QWidget *QgsLocaleAwareNumericLineEditDelegate::createEditor( QWidget *parent, c
void QgsLocaleAwareNumericLineEditDelegate::setEditorData( QWidget *editor, const QModelIndex &index ) const
{
QLineEdit *lineEdit { qobject_cast<QLineEdit *>( 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

0 comments on commit bbe476a

Please sign in to comment.