diff options
-rw-r--r-- | src/library/sidebarmodel.cpp | 9 | ||||
-rw-r--r-- | src/library/sidebarmodel.h | 4 | ||||
-rw-r--r-- | src/library/trackset/baseplaylistfeature.cpp | 2 | ||||
-rw-r--r-- | src/library/trackset/setlogfeature.cpp | 2 | ||||
-rw-r--r-- | src/widget/wlibrarysidebar.cpp | 24 | ||||
-rw-r--r-- | src/widget/wlibrarysidebar.h | 1 |
6 files changed, 31 insertions, 11 deletions
diff --git a/src/library/sidebarmodel.cpp b/src/library/sidebarmodel.cpp index 697a6a30a2..6ea3fa5096 100644 --- a/src/library/sidebarmodel.cpp +++ b/src/library/sidebarmodel.cpp @@ -374,8 +374,6 @@ bool SidebarModel::dragMoveAccept(const QModelIndex& index, const QUrl& url) { // Translates an index from the child models to an index of the sidebar models QModelIndex SidebarModel::translateSourceIndex(const QModelIndex& index) { - QModelIndex translatedIndex; - /* These method is called from the slot functions below. * QObject::sender() return the object which emitted the signal * handled by the slot functions. @@ -388,6 +386,13 @@ QModelIndex SidebarModel::translateSourceIndex(const QModelIndex& index) { return QModelIndex(); } + return translateIndex(index, model); +} + +QModelIndex SidebarModel::translateIndex( + const QModelIndex& index, const QAbstractItemModel* model) { + QModelIndex translatedIndex; + if (index.isValid()) { TreeItem* item = (TreeItem*)index.internalPointer(); translatedIndex = createIndex(index.row(), index.column(), item); diff --git a/src/library/sidebarmodel.h b/src/library/sidebarmodel.h index 807e893200..2a331785c7 100644 --- a/src/library/sidebarmodel.h +++ b/src/library/sidebarmodel.h @@ -40,6 +40,9 @@ class SidebarModel : public QAbstractItemModel { bool dragMoveAccept(const QModelIndex& index, const QUrl& url); bool hasChildren(const QModelIndex& parent = QModelIndex()) const override; bool hasTrackTable(const QModelIndex& index) const; + QModelIndex translateChildIndex(const QModelIndex& index) { + return translateIndex(index, index.model()); + } public slots: void pressed(const QModelIndex& index); @@ -76,6 +79,7 @@ class SidebarModel : public QAbstractItemModel { private: QModelIndex translateSourceIndex(const QModelIndex& parent); + QModelIndex translateIndex(const QModelIndex& index, const QAbstractItemModel* model); void featureRenamed(LibraryFeature*); QList<LibraryFeature*> m_sFeatures; unsigned int m_iDefaultSelectedIndex; /** Index of the item in the sidebar model to select at startup. */ diff --git a/src/library/trackset/baseplaylistfeature.cpp b/src/library/trackset/baseplaylistfeature.cpp index fc41b58ae1..3a2a7eb243 100644 --- a/src/library/trackset/baseplaylistfeature.cpp +++ b/src/library/trackset/baseplaylistfeature.cpp @@ -359,7 +359,7 @@ void BasePlaylistFeature::slotDeletePlaylist() { if (m_pSidebarWidget) { // FIXME: this does not scroll to the correct position for some reason nextIndex = indexFromPlaylistId(nextId); - m_pSidebarWidget->selectIndex(nextIndex); + m_pSidebarWidget->selectChildIndex(nextIndex); } } } diff --git a/src/library/trackset/setlogfeature.cpp b/src/library/trackset/setlogfeature.cpp index 2dd5291771..4c5741f2d1 100644 --- a/src/library/trackset/setlogfeature.cpp +++ b/src/library/trackset/setlogfeature.cpp @@ -341,7 +341,7 @@ void SetlogFeature::slotJoinWithPrevious() { m_playlistDao.deletePlaylist(currentPlaylistId); reloadChildModel(previousPlaylistId); // For moving selection emit showTrackModel(m_pPlaylistTableModel); - emit activatePlaylist(previousPlaylistId); + activatePlaylist(previousPlaylistId); } } } 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) { diff --git a/src/widget/wlibrarysidebar.h b/src/widget/wlibrarysidebar.h index 8539e8a541..871f8f063e 100644 --- a/src/widget/wlibrarysidebar.h +++ b/src/widget/wlibrarysidebar.h @@ -30,6 +30,7 @@ class WLibrarySidebar : public QTreeView, public WBaseWidget { public slots: void selectIndex(const QModelIndex&); + void selectChildIndex(const QModelIndex&); void slotSetFont(const QFont& font); signals: |