Utils: Fix StringSelectionAspect

Previously the undo state was not updated when the value
was set from the outside before the gui model was setup.

Change-Id: I380916f888edd120f512089bdb94762977c11978
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2023-09-26 08:38:09 +02:00
parent d7ef2f816c
commit a43191497d

View File

@@ -3286,8 +3286,10 @@ QStandardItem *StringSelectionAspect::itemById(const QString &id)
void StringSelectionAspect::bufferToGui() void StringSelectionAspect::bufferToGui()
{ {
if (!m_model) if (!m_model) {
m_undoable.setSilently(m_buffer);
return; return;
}
auto selected = itemById(m_buffer); auto selected = itemById(m_buffer);
if (selected) { if (selected) {
@@ -3302,8 +3304,10 @@ void StringSelectionAspect::bufferToGui()
m_selectionModel->setCurrentIndex(m_model->item(0)->index(), m_selectionModel->setCurrentIndex(m_model->item(0)->index(),
QItemSelectionModel::SelectionFlag::ClearAndSelect); QItemSelectionModel::SelectionFlag::ClearAndSelect);
} else { } else {
m_undoable.setSilently(m_buffer);
m_selectionModel->setCurrentIndex(QModelIndex(), QItemSelectionModel::SelectionFlag::Clear); m_selectionModel->setCurrentIndex(QModelIndex(), QItemSelectionModel::SelectionFlag::Clear);
} }
handleGuiChanged(); handleGuiChanged();
} }