Skip to content

Commit ae90787

Browse files
committed
Remove group separator when editing numeric values
Fixes #19695 - Line Edit widgets for integer numbers with thousand separators enabled are hard to edit
1 parent 7157076 commit ae90787

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/gui/editorwidgets/qgstexteditwrapper.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,15 @@ void QgsTextEditWrapper::setWidgetValue( const QVariant &val )
221221
v = field().displayString( val );
222222
}
223223

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

src/gui/qgsattributeform.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,12 @@ void QgsAttributeForm::init()
14631463
connect( mLayer, &QgsVectorLayer::editingStarted, this, &QgsAttributeForm::synchronizeEnabledState );
14641464
connect( mLayer, &QgsVectorLayer::editingStopped, this, &QgsAttributeForm::synchronizeEnabledState );
14651465

1466+
// This triggers a refresh of the form widget and gives a chance to re-format the
1467+
// value to those widgets that have a different representation when in edit mode
1468+
connect( mLayer, &QgsVectorLayer::editingStarted, this, [ = ] { setFeature( feature() ); } );
1469+
connect( mLayer, &QgsVectorLayer::editingStopped, this, [ = ] { setFeature( feature() ); } );
1470+
1471+
14661472
Q_FOREACH ( QgsAttributeFormInterface *iface, mInterfaces )
14671473
{
14681474
iface->initForm();

0 commit comments

Comments
 (0)