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

Playlists & Crates: Store selected TrackId instead of TrackPointer #4194

Merged
merged 1 commit into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 8 additions & 9 deletions src/library/trackset/baseplaylistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ void BasePlaylistFeature::initActions() {
connect(m_pLibrary,
&Library::trackSelected,
this,
&BasePlaylistFeature::slotTrackSelected);
[this](const TrackPointer& pTrack) {
const auto trackId = pTrack ? pTrack->getId() : TrackId{};
slotTrackSelected(trackId);
});
connect(m_pLibrary,
&Library::switchToView,
this,
Expand Down Expand Up @@ -726,13 +729,9 @@ QModelIndex BasePlaylistFeature::indexFromPlaylistId(int playlistId) {
return QModelIndex();
}

void BasePlaylistFeature::slotTrackSelected(TrackPointer pTrack) {
m_pSelectedTrack = pTrack;
TrackId trackId;
if (pTrack) {
trackId = pTrack->getId();
}
m_playlistDao.getPlaylistsTrackIsIn(trackId, &m_playlistIdsOfSelectedTrack);
void BasePlaylistFeature::slotTrackSelected(TrackId trackId) {
m_selectedTrackId = trackId;
m_playlistDao.getPlaylistsTrackIsIn(m_selectedTrackId, &m_playlistIdsOfSelectedTrack);

for (int row = 0; row < m_pSidebarModel->rowCount(); ++row) {
QModelIndex index = m_pSidebarModel->index(row, 0);
Expand Down Expand Up @@ -768,5 +767,5 @@ void BasePlaylistFeature::markTreeItem(TreeItem* pTreeItem) {
}

void BasePlaylistFeature::slotResetSelectedTrack() {
slotTrackSelected(TrackPointer());
slotTrackSelected(TrackId{});
}
6 changes: 3 additions & 3 deletions src/library/trackset/baseplaylistfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "library/dao/playlistdao.h"
#include "library/trackset/basetracksetfeature.h"
#include "track/track_decl.h"
#include "track/trackid.h"

class WLibrary;
class KeyboardEventFilter;
Expand Down Expand Up @@ -115,13 +115,13 @@ class BasePlaylistFeature : public BaseTrackSetFeature {
QSet<int> m_playlistIdsOfSelectedTrack;

private slots:
void slotTrackSelected(TrackPointer pTrack);
void slotTrackSelected(TrackId trackId);
void slotResetSelectedTrack();

private:
void initActions();
virtual QString getRootViewHtml() const = 0;
void markTreeItem(TreeItem* pTreeItem);

TrackPointer m_pSelectedTrack;
TrackId m_selectedTrackId;
};
25 changes: 13 additions & 12 deletions src/library/trackset/crate/cratefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ void CrateFeature::connectLibrary(Library* pLibrary) {
connect(pLibrary,
&Library::trackSelected,
this,
&CrateFeature::slotTrackSelected);
[this](const TrackPointer& pTrack) {
const auto trackId = pTrack ? pTrack->getId() : TrackId{};
slotTrackSelected(trackId);
});
connect(pLibrary,
&Library::switchToView,
this,
Expand Down Expand Up @@ -511,7 +514,7 @@ QModelIndex CrateFeature::rebuildChildModel(CrateId selectedCrateId) {
m_pSidebarModel->insertTreeItemRows(modelRows, 0);

// Update rendering of crates depending on the currently selected track
slotTrackSelected(m_pSelectedTrack);
slotTrackSelected(m_selectedTrackId);

if (selectedRow >= 0) {
return m_pSidebarModel->index(selectedRow, 0);
Expand All @@ -536,10 +539,10 @@ void CrateFeature::updateChildModel(const QSet<CrateId>& updatedCrateIds) {
m_pSidebarModel->getItem(index), crateSummary);
m_pSidebarModel->triggerRepaint(index);
}
if (m_pSelectedTrack) {
if (m_selectedTrackId.isValid()) {
// Crates containing the currently selected track might
// have been modified.
slotTrackSelected(m_pSelectedTrack);
slotTrackSelected(m_selectedTrackId);
}
}

Expand Down Expand Up @@ -797,20 +800,18 @@ void CrateFeature::htmlLinkClicked(const QUrl& link) {
}
}

void CrateFeature::slotTrackSelected(TrackPointer pTrack) {
m_pSelectedTrack = std::move(pTrack);
void CrateFeature::slotTrackSelected(TrackId trackId) {
m_selectedTrackId = trackId;

TreeItem* pRootItem = m_pSidebarModel->getRootItem();
VERIFY_OR_DEBUG_ASSERT(pRootItem != nullptr) {
return;
}

TrackId selectedTrackId;
std::vector<CrateId> sortedTrackCrates;
if (m_pSelectedTrack) {
selectedTrackId = m_pSelectedTrack->getId();
if (m_selectedTrackId.isValid()) {
CrateTrackSelectResult trackCratesIter(
m_pTrackCollection->crates().selectTrackCratesSorted(selectedTrackId));
m_pTrackCollection->crates().selectTrackCratesSorted(m_selectedTrackId));
while (trackCratesIter.next()) {
sortedTrackCrates.push_back(trackCratesIter.crateId());
}
Expand All @@ -821,7 +822,7 @@ void CrateFeature::slotTrackSelected(TrackPointer pTrack) {
for (TreeItem* pTreeItem : pRootItem->children()) {
DEBUG_ASSERT(pTreeItem != nullptr);
bool crateContainsSelectedTrack =
selectedTrackId.isValid() &&
m_selectedTrackId.isValid() &&
std::binary_search(
sortedTrackCrates.begin(),
sortedTrackCrates.end(),
Expand All @@ -833,5 +834,5 @@ void CrateFeature::slotTrackSelected(TrackPointer pTrack) {
}

void CrateFeature::slotResetSelectedTrack() {
slotTrackSelected(TrackPointer());
slotTrackSelected(TrackId{});
}
6 changes: 3 additions & 3 deletions src/library/trackset/crate/cratefeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "library/trackset/crate/cratetablemodel.h"
#include "library/treeitemmodel.h"
#include "preferences/usersettings.h"
#include "track/track_decl.h"
#include "track/trackid.h"
#include "util/parented_ptr.h"

// forward declaration(s)
Expand Down Expand Up @@ -69,7 +69,7 @@ class CrateFeature : public BaseTrackSetFeature {
void slotCrateTableChanged(CrateId crateId);
void slotCrateContentChanged(CrateId crateId);
void htmlLinkClicked(const QUrl& link);
void slotTrackSelected(TrackPointer pTrack);
void slotTrackSelected(TrackId trackId);
void slotResetSelectedTrack();
void slotUpdateCrateLabels(const QSet<CrateId>& updatedCrateIds);

Expand Down Expand Up @@ -103,7 +103,7 @@ class CrateFeature : public BaseTrackSetFeature {
CrateTableModel m_crateTableModel;

QModelIndex m_lastRightClickedIndex;
TrackPointer m_pSelectedTrack;
TrackId m_selectedTrackId;

parented_ptr<QAction> m_pCreateCrateAction;
parented_ptr<QAction> m_pDeleteCrateAction;
Expand Down