Skip to content

Commit

Permalink
Fix vertex editor locale with Z/R values
Browse files Browse the repository at this point in the history
Fixes #29682

Manual backport of master commit e859d44
  • Loading branch information
elpaso authored and nyalldawson committed Feb 19, 2021
1 parent f88729c commit bbe476a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
17 changes: 6 additions & 11 deletions src/app/vertextool/qgsvertexeditor.cpp
Expand Up @@ -24,6 +24,7 @@
#include "qgsgeometryutils.h"
#include "qgsproject.h"
#include "qgscoordinatetransform.h"
#include "qgsdoublevalidator.h"

#include <QLabel>
#include <QTableWidget>
Expand Down Expand Up @@ -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() );
Expand All @@ -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" ) );
Expand Down Expand Up @@ -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 );
Expand All @@ -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() ) );
}
}
10 changes: 6 additions & 4 deletions src/gui/qgslocaleawarenumericlineeditdelegate.cpp
Expand Up @@ -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
Expand Down

0 comments on commit bbe476a

Please sign in to comment.