Skip to content
Permalink
Browse files

Remove group separator when editing numeric values

Fixes #19695 - Line Edit widgets for integer numbers with thousand separators enabled are hard to edit
  • Loading branch information
elpaso committed Sep 1, 2018
1 parent 7157076 commit ae907878c98feee8d884abe1cfb306f881189100
Showing with 15 additions and 0 deletions.
  1. +9 −0 src/gui/editorwidgets/qgstexteditwrapper.cpp
  2. +6 −0 src/gui/qgsattributeform.cpp
@@ -221,6 +221,15 @@ void QgsTextEditWrapper::setWidgetValue( const QVariant &val )
v = field().displayString( val );
}

// For numbers, remove the group separator that might cause validation errors
// when the user is editing the field value.
// We are checking for editable layer because in the form field context we do not
// want to strip the separator unless the layer is editable
if ( layer() && layer()->isEditable() && ! QLocale().groupSeparator().isNull() && ( field().type() == QVariant::Int || field().type() == QVariant::Double || field().type() == QVariant::LongLong ) )
{
v = v.remove( QLocale().groupSeparator() );
}

if ( mTextEdit )
{
if ( val != value() )
@@ -1463,6 +1463,12 @@ void QgsAttributeForm::init()
connect( mLayer, &QgsVectorLayer::editingStarted, this, &QgsAttributeForm::synchronizeEnabledState );
connect( mLayer, &QgsVectorLayer::editingStopped, this, &QgsAttributeForm::synchronizeEnabledState );

// This triggers a refresh of the form widget and gives a chance to re-format the
// value to those widgets that have a different representation when in edit mode
connect( mLayer, &QgsVectorLayer::editingStarted, this, [ = ] { setFeature( feature() ); } );
connect( mLayer, &QgsVectorLayer::editingStopped, this, [ = ] { setFeature( feature() ); } );


Q_FOREACH ( QgsAttributeFormInterface *iface, mInterfaces )
{
iface->initForm();

0 comments on commit ae90787

Please sign in to comment.
You can’t perform that action at this time.