Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vertex editor locale with Z/R values #41082

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions src/app/vertextool/qgsvertexeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "qgsgeometryutils.h"
#include "qgsproject.h"
#include "qgscoordinatetransform.h"
#include "qgsdoublevalidator.h"

#include <QLabel>
#include <QTableWidget>
Expand Down Expand Up @@ -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() );
Expand All @@ -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" ) );
Expand Down Expand Up @@ -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 );
Expand All @@ -510,7 +505,7 @@ 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', displayDecimalPlaces() ) );
lineEdit->setText( displayText( index.data( ).toDouble( ), QLocale() ) );
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/gui/qgslocaleawarenumericlineeditdelegate.cpp
Original file line number Diff line number Diff line change
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