Utils: Fix StringAspect ui connection

QLineEdit::textEdited is only called when the user types.
It is not triggered if the text changes due to undo/redo.
QLineEdit::textChanged is triggered for all changes.

We also have to make sure that we don't call
QLineEdit::setTextKeepingActiveCursor unnecessarily
as that would clear the undo/redo stack of the QLineEdit.

Change-Id: I19562d0804e6a34b11f19e86abd256a807e147d6
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2023-09-21 10:05:12 +02:00
parent 4bdc023e32
commit dedfc3dbe7

View File

@@ -1165,7 +1165,7 @@ void StringAspect::addToLayout(LayoutItem &parent)
handleGuiChanged(); handleGuiChanged();
}); });
} else { } else {
connect(lineEditDisplay, &QLineEdit::textEdited, this, [this, lineEditDisplay]() { connect(lineEditDisplay, &QLineEdit::textChanged, this, [this, lineEditDisplay]() {
d->undoable.set(undoStack(), lineEditDisplay->text()); d->undoable.set(undoStack(), lineEditDisplay->text());
handleGuiChanged(); handleGuiChanged();
}); });
@@ -1188,7 +1188,9 @@ void StringAspect::addToLayout(LayoutItem &parent)
&UndoSignaller::changed, &UndoSignaller::changed,
lineEditDisplay, lineEditDisplay,
[this, lineEditDisplay] { [this, lineEditDisplay] {
lineEditDisplay->setTextKeepingActiveCursor(d->undoable.get()); if (lineEditDisplay->text() != d->undoable.get())
lineEditDisplay->setTextKeepingActiveCursor(d->undoable.get());
lineEditDisplay->validate(); lineEditDisplay->validate();
}); });