Skip to content

Commit

Permalink
Remove group separator when editing numeric values
Browse files Browse the repository at this point in the history
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 ae90787
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/gui/editorwidgets/qgstexteditwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsattributeform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit ae90787

Please sign in to comment.