From e74a307388d1c1f872dc27bb137ae2e7f1e1693f Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 16 Jun 2016 16:06:18 +0300 Subject: Keep tree view scroll position when model is reset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Idf2adb94a1d80edba022545d7d1637c0c4cdd6e5 Reviewed-by: Tomi Korpipää Reviewed-by: Titta Heikkala --- editorlib/qml/EntityTree.qml | 7 +++++++ editorlib/src/editorsceneitemmodel.cpp | 2 ++ editorlib/src/editorsceneitemmodel.h | 1 + 3 files changed, 10 insertions(+) diff --git a/editorlib/qml/EntityTree.qml b/editorlib/qml/EntityTree.qml index b220bad..8a8549e 100644 --- a/editorlib/qml/EntityTree.qml +++ b/editorlib/qml/EntityTree.qml @@ -182,6 +182,7 @@ Item { property bool sceneRootSelected: true property bool cameraSelected: true property bool groupSelected: true + property real preResetContentY: 0 onExpanded: { model.addExpandedItem(index) @@ -200,6 +201,12 @@ Item { entityTreeView.selection.setCurrentIndex(selectIndex, ItemSelectionModel.SelectCurrent) } + onModelAboutToBeReset: { + entityTreeView.preResetContentY = entityTreeView.flickableItem.contentY + } + onResetComplete: { + entityTreeView.flickableItem.contentY = entityTreeView.preResetContentY + } } itemDelegate: FocusScope { diff --git a/editorlib/src/editorsceneitemmodel.cpp b/editorlib/src/editorsceneitemmodel.cpp index c8c2346..ae5a2da 100644 --- a/editorlib/src/editorsceneitemmodel.cpp +++ b/editorlib/src/editorsceneitemmodel.cpp @@ -277,6 +277,8 @@ void EditorSceneItemModel::resetModel() // Select scene root after reset, unless multiselecting if (!m_scene->multiSelection()) emit selectIndex(sceneEntityIndex()); + + emit resetComplete(); } EditorSceneItem *EditorSceneItemModel::editorSceneItemFromIndex(const QModelIndex &index) const diff --git a/editorlib/src/editorsceneitemmodel.h b/editorlib/src/editorsceneitemmodel.h index eee5c68..aef98e9 100644 --- a/editorlib/src/editorsceneitemmodel.h +++ b/editorlib/src/editorsceneitemmodel.h @@ -105,6 +105,7 @@ signals: void expandItems(const QModelIndexList &items); void selectIndex(const QModelIndex &selectIndex); void importEntityInProgressChanged(bool importInProgress); + void resetComplete(); private slots: void handleEntityNameChange(); -- cgit v1.2.3