summaryrefslogtreecommitdiffstats
path: root/src/widget/wlibrarysidebar.cpp
diff options
context:
space:
mode:
authorDaniel Poelzleithner <git@poelzi.org>2020-11-26 00:58:57 +0100
committerDaniel Poelzleithner <git@poelzi.org>2020-11-27 01:08:33 +0100
commit7e0069421733981bf7f2f3283858c3d047ad6409 (patch)
treecdeecee186cd56dda53cd5e0f40bc0bf8c91bb92 /src/widget/wlibrarysidebar.cpp
parentf9d3f02e6863ce57738cd234612a870afcb34312 (diff)
Add functions to scroll to the correct child on the sidebar
Use new utility functions to scroll to the next item after the deleted one.
Diffstat (limited to 'src/widget/wlibrarysidebar.cpp')
-rw-r--r--src/widget/wlibrarysidebar.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/widget/wlibrarysidebar.cpp b/src/widget/wlibrarysidebar.cpp
index f080437598..781f9d344c 100644
--- a/src/widget/wlibrarysidebar.cpp
+++ b/src/widget/wlibrarysidebar.cpp
@@ -215,17 +215,27 @@ void WLibrarySidebar::selectIndex(const QModelIndex& index) {
pModel->select(index, QItemSelectionModel::Select);
setSelectionModel(pModel);
-//FIXME(XXX): use expandRecursively when
-#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
- QModelIndex parentIndex = index.parent();
+ scrollTo(index);
+}
+
+/// Selects a child index from a feature and ensures visibility
+void WLibrarySidebar::selectChildIndex(const QModelIndex& index) {
+ auto pModel = new QItemSelectionModel(model());
+ SidebarModel* sidebarModel = qobject_cast<SidebarModel*>(model());
+ VERIFY_OR_DEBUG_ASSERT(sidebarModel) {
+ qDebug() << "model() is not SidebarModel";
+ return;
+ }
+ QModelIndex translated = sidebarModel->translateChildIndex(index);
+ pModel->select(index, QItemSelectionModel::Select);
+ setSelectionModel(pModel);
+
+ QModelIndex parentIndex = translated.parent();
if (parentIndex.isValid()) {
expand(parentIndex);
parentIndex = parentIndex.parent();
}
-#else
- expandRecursively(index);
-#endif
- scrollTo(index);
+ scrollTo(translated, PositionAtCenter);
}
bool WLibrarySidebar::event(QEvent* pEvent) {