EffectComposer: Preserve expand state of effect node sections

Fixes: QDS-11974
Change-Id: I38d9efb8f05d5b0064fe9e85fdf4b624f5cef11f
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2024-02-19 17:49:13 +02:00
parent fa14c8dfab
commit f926cbaaca
2 changed files with 35 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ ColumnLayout {
property int moveFromIdx: 0
property int moveToIdx: 0
property bool previewAnimationRunning: false
property var expandStates: null
// Invoked after save changes is done
property var onSaveChangesCallback: () => {}
@@ -33,6 +34,28 @@ ColumnLayout {
saveChangesDialog.open()
}
// Invoked from C++ side before resetting the model to store current expanded state of nodes
function storeExpandStates() {
expandStates = new Map()
for (let i = 0; i < repeater.count; ++i) {
var curItem = repeater.itemAt(i)
expandStates.set(curItem.caption, curItem.expanded)
}
}
// Invoked after model has been reset to restore expanded state for nodes
function restoreExpandStates() {
if (expandStates) {
for (let i = 0; i < repeater.count; ++i) {
var curItem = repeater.itemAt(i)
if (expandStates.has(curItem.caption))
curItem.expanded = expandStates.get(curItem.caption)
}
expandStates = null
}
}
Connections {
target: root.backendModel
function onIsEmptyChanged() {
@@ -200,6 +223,13 @@ ColumnLayout {
interactive: !HelperWidgets.Controller.contextMenuOpened
onContentHeightChanged: {
// Expand states are stored before full model reset.
// Content height change indicates the model has been updated after full
// reset, so we restore expand states if any are stored.
root.restoreExpandStates()
// If content height change was because a recent node addition, we want to
// scroll to the end of the content so the newly added item is visible.
if (nodesComboBox.nodeJustAdded && scrollView.contentItem.height > scrollView.height) {
let lastItemH = repeater.itemAt(repeater.count - 1).height
scrollView.contentY = scrollView.contentItem.height - lastItemH

View File

@@ -117,6 +117,11 @@ EffectComposerWidget::EffectComposerWidget(EffectComposerView *view)
}
});
connect(m_effectComposerModel.data(), &EffectComposerModel::modelAboutToBeReset,
this, [this] {
QMetaObject::invokeMethod(quickWidget()->rootObject(), "storeExpandStates");
});
connect(Core::EditorManager::instance(), &Core::EditorManager::aboutToSave, this, [this] {
if (m_effectComposerModel->hasUnsavedChanges()) {
QString compName = m_effectComposerModel->currentComposition();