Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sidebar item selection fix #4193

Merged
merged 4 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Sidebar: fix item selection after delete, create, rename
  • Loading branch information
ronso0 committed Aug 13, 2021
commit 42d925a94855c5d49657db80b61bd91300a92819
2 changes: 1 addition & 1 deletion src/library/trackset/baseplaylistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ void BasePlaylistFeature::activateChild(const QModelIndex& index) {
}

void BasePlaylistFeature::activatePlaylist(int playlistId) {
// qDebug() << "BasePlaylistFeature::activatePlaylist()" << playlistId;
VERIFY_OR_DEBUG_ASSERT(playlistId != kInvalidPlaylistId) {
return;
}
QModelIndex index = indexFromPlaylistId(playlistId);
//qDebug() << "BasePlaylistFeature::activatePlaylist()" << playlistId << index;
VERIFY_OR_DEBUG_ASSERT(index.isValid()) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/library/trackset/crate/cratefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ void CrateFeature::slotDeleteCrate() {
qWarning() << "Refusing to delete locked crate" << crate;
return;
}
// TODO Store sibling index to restore selection after crate was deleted
// to avoid scroll position reset (to Crate root item)
if (m_pTrackCollection->deleteCrate(crate.getId())) {
qDebug() << "Deleted crate" << crate;
return;
Expand Down
11 changes: 10 additions & 1 deletion src/widget/wlibrarysidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,20 @@ void WLibrarySidebar::keyPressEvent(QKeyEvent* event) {
}

void WLibrarySidebar::selectIndex(const QModelIndex& index) {
//qDebug() << "WLibrarySidebar::selectIndex" << index;
if (!index.isValid()) {
return;
}
auto* pModel = new QItemSelectionModel(model());
pModel->select(index, QItemSelectionModel::Select);
if (selectionModel()) {
selectionModel()->deleteLater();
}
setSelectionModel(pModel);
if (index.parent().isValid()) {
expand(index.parent());
}
setSelectionModel(pModel);
setCurrentIndex(index);
scrollTo(index);
}

Expand All @@ -232,6 +237,9 @@ void WLibrarySidebar::selectChildIndex(const QModelIndex& index, bool selectItem
return;
}
QModelIndex translated = sidebarModel->translateChildIndex(index);
if (!translated.isValid()) {
uklotzde marked this conversation as resolved.
Show resolved Hide resolved
return;
}

if (selectItem) {
auto* pModel = new QItemSelectionModel(sidebarModel);
Expand All @@ -240,6 +248,7 @@ void WLibrarySidebar::selectChildIndex(const QModelIndex& index, bool selectItem
selectionModel()->deleteLater();
}
setSelectionModel(pModel);
setCurrentIndex(translated);
}

QModelIndex parentIndex = translated.parent();
Expand Down