Skip to content

Commit

Permalink
Merge pull request #11574 from ronso0/lib-sidebar-right-click-selecti…
Browse files Browse the repository at this point in the history
…on_fixes

Lib sidebar: right click selection fixes
  • Loading branch information
daschuer committed Jun 5, 2023
2 parents 423589c + a58f192 commit d1b1831
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 112 deletions.
2 changes: 1 addition & 1 deletion src/library/autodj/autodjprocessor.cpp
Expand Up @@ -122,7 +122,7 @@ AutoDJProcessor::AutoDJProcessor(
m_transitionTime(kTransitionPreferenceDefault) {
m_pAutoDJTableModel = new PlaylistTableModel(this, pTrackCollectionManager,
"mixxx.db.model.autodj");
m_pAutoDJTableModel->setTableModel(iAutoDJPlaylistId);
m_pAutoDJTableModel->selectPlaylist(iAutoDJPlaylistId);
m_pAutoDJTableModel->select();

m_pShufflePlaylist = new ControlPushButton(
Expand Down
6 changes: 3 additions & 3 deletions src/library/banshee/bansheefeature.cpp
Expand Up @@ -110,7 +110,7 @@ void BansheeFeature::activate() {
emit featureLoadingFinished(this);
}

m_pBansheePlaylistModel->setTableModel(0); // Gets the master playlist
m_pBansheePlaylistModel->selectPlaylist(0); // Loads the master playlist
emit showTrackModel(m_pBansheePlaylistModel);
emit enableCoverArtDisplay(false);
}
Expand All @@ -120,7 +120,7 @@ void BansheeFeature::activateChild(const QModelIndex& index) {
int playlistID = item->getData().toInt();
if (playlistID > 0) {
qDebug() << "Activating " << item->getLabel();
m_pBansheePlaylistModel->setTableModel(playlistID);
m_pBansheePlaylistModel->selectPlaylist(playlistID);
emit showTrackModel(m_pBansheePlaylistModel);
emit enableCoverArtDisplay(false);
}
Expand All @@ -141,7 +141,7 @@ void BansheeFeature::appendTrackIdsFromRightClickIndex(QList<TrackId>* trackIds,
new BansheePlaylistModel(this,
m_pLibrary->trackCollectionManager(),
&m_connection);
pPlaylistModelToAdd->setTableModel(playlistID);
pPlaylistModelToAdd->selectPlaylist(playlistID);
pPlaylistModelToAdd->select();

// Copy Tracks
Expand Down
4 changes: 2 additions & 2 deletions src/library/banshee/bansheeplaylistmodel.cpp
Expand Up @@ -86,8 +86,8 @@ void BansheePlaylistModel::dropTempTable() {
}
}

void BansheePlaylistModel::setTableModel(int playlistId) {
//qDebug() << "BansheePlaylistModel::setTableModel" << this << playlistId;
void BansheePlaylistModel::selectPlaylist(int playlistId) {
// qDebug() << "BansheePlaylistModel::selectPlaylist" << this << playlistId;
if (m_playlistId == playlistId) {
qDebug() << "Already focused on playlist " << playlistId;
return;
Expand Down
2 changes: 1 addition & 1 deletion src/library/banshee/bansheeplaylistmodel.h
Expand Up @@ -16,7 +16,7 @@ class BansheePlaylistModel final : public BaseSqlTableModel {
BansheePlaylistModel(QObject* pParent, TrackCollectionManager* pTrackCollectionManager, BansheeDbConnection* pConnection);
~BansheePlaylistModel() final;

void setTableModel(int playlistId);
void selectPlaylist(int playlistId);

TrackPointer getTrack(const QModelIndex& index) const final;
TrackId getTrackId(const QModelIndex& index) const final;
Expand Down
4 changes: 2 additions & 2 deletions src/library/playlisttablemodel.cpp
Expand Up @@ -121,8 +121,8 @@ void PlaylistTableModel::initSortColumnMapping() {
}
}

void PlaylistTableModel::setTableModel(int playlistId) {
//qDebug() << "PlaylistTableModel::setTableModel" << playlistId;
void PlaylistTableModel::selectPlaylist(int playlistId) {
// qDebug() << "PlaylistTableModel::selectPlaylist" << playlistId;
if (m_iPlaylistId == playlistId) {
qDebug() << "Already focused on playlist " << playlistId;
return;
Expand Down
2 changes: 1 addition & 1 deletion src/library/playlisttablemodel.h
Expand Up @@ -10,7 +10,7 @@ class PlaylistTableModel final : public TrackSetTableModel {
PlaylistTableModel(QObject* parent, TrackCollectionManager* pTrackCollectionManager, const char* settingsNamespace, bool keepDeletedTracks = false);
~PlaylistTableModel() final = default;

void setTableModel(int playlistId = -1);
void selectPlaylist(int playlistId = -1 /* kInvalidPlaylistId */);
int getPlaylist() const {
return m_iPlaylistId;
}
Expand Down
21 changes: 10 additions & 11 deletions src/library/trackset/baseplaylistfeature.cpp
Expand Up @@ -201,32 +201,30 @@ void BasePlaylistFeature::activateChild(const QModelIndex& index) {
//qDebug() << "BasePlaylistFeature::activateChild()" << index;
int playlistId = playlistIdFromIndex(index);
if (playlistId == kInvalidPlaylistId) {
// This happens if user clicks on group nodes.
// Doesn't apply to YEAR nodes in the history feature, they are linked to
// a dummy playlist.
// may happen during initialization
return;
}
m_lastClickedIndex = index;
m_lastRightClickedIndex = QModelIndex();
emit saveModelState();
m_pPlaylistTableModel->setTableModel(playlistId);
m_pPlaylistTableModel->selectPlaylist(playlistId);
emit showTrackModel(m_pPlaylistTableModel);
emit enableCoverArtDisplay(true);
}

void BasePlaylistFeature::activatePlaylist(int playlistId) {
// qDebug() << "BasePlaylistFeature::activatePlaylist()" << playlistId << index;
VERIFY_OR_DEBUG_ASSERT(playlistId != kInvalidPlaylistId) {
return;
}
QModelIndex index = indexFromPlaylistId(playlistId);
//qDebug() << "BasePlaylistFeature::activatePlaylist()" << playlistId << index;
VERIFY_OR_DEBUG_ASSERT(index.isValid()) {
return;
}
m_lastClickedIndex = index;
m_lastRightClickedIndex = QModelIndex();
emit saveModelState();
m_pPlaylistTableModel->setTableModel(playlistId);
m_pPlaylistTableModel->selectPlaylist(playlistId);
emit showTrackModel(m_pPlaylistTableModel);
emit enableCoverArtDisplay(true);
// Update selection
Expand Down Expand Up @@ -470,13 +468,13 @@ void BasePlaylistFeature::slotImportPlaylistFile(const QString& playlistFile,

// Create a temporary PlaylistTableModel for the Playlist the entries shall be imported to.
// This is used as a proxy object to write to the database.
// We cannot use m_pPlaylistTableModel since it might have another playlist selected which
// We cannot use m_pPlaylistTableModel since it might have another playlist selected which
// is not the playlist that received the right-click.
QScopedPointer<PlaylistTableModel> pPlaylistTableModel(
new PlaylistTableModel(this,
m_pLibrary->trackCollectionManager(),
"mixxx.db.model.playlist_export"));
pPlaylistTableModel->setTableModel(playlistId);
pPlaylistTableModel->selectPlaylist(playlistId);
pPlaylistTableModel->setSort(
pPlaylistTableModel->fieldIndex(
ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION),
Expand Down Expand Up @@ -585,7 +583,7 @@ void BasePlaylistFeature::slotExportPlaylist() {
"mixxx.db.model.playlist_export"));

emit saveModelState();
pPlaylistTableModel->setTableModel(playlistId);
pPlaylistTableModel->selectPlaylist(playlistId);
pPlaylistTableModel->setSort(
pPlaylistTableModel->fieldIndex(
ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION),
Expand Down Expand Up @@ -631,7 +629,7 @@ void BasePlaylistFeature::slotExportTrackFiles() {
"mixxx.db.model.playlist_export"));

emit saveModelState();
pPlaylistTableModel->setTableModel(playlistId);
pPlaylistTableModel->selectPlaylist(playlistId);
pPlaylistTableModel->setSort(pPlaylistTableModel->fieldIndex(
ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION),
Qt::AscendingOrder);
Expand Down Expand Up @@ -720,7 +718,8 @@ void BasePlaylistFeature::htmlLinkClicked(const QUrl& link) {
}

void BasePlaylistFeature::updateChildModel(const QSet<int>& playlistIds) {
// qDebug() << "BasePlaylistFeature::updateChildModel";
// qDebug() << "BasePlaylistFeature::updateChildModel() for"
// << playlistIds.count() << "playlist(s)";
if (playlistIds.isEmpty()) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/library/trackset/playlistfeature.cpp
Expand Up @@ -296,7 +296,7 @@ void PlaylistFeature::slotPlaylistTableChanged(int playlistId) {

clearChildModel();
QModelIndex newIndex = constructChildModel(selectedPlaylistId);
if (newIndex.isValid()) {
if (selectedPlaylistId != kInvalidPlaylistId && newIndex.isValid()) {
// If a child index was selected and we got a new valid index select that.
// Else (root item was selected or for some reason no index could be created)
// there's nothing to do: either no child was selected earlier, or the root
Expand Down

0 comments on commit d1b1831

Please sign in to comment.