Remember the selected playlist items when switching between playlist tabs. Fixes issue #758

This commit is contained in:
David Sansome 2010-09-25 15:30:47 +00:00
parent 6971f81be4
commit 7a681c1198
3 changed files with 9 additions and 5 deletions

View File

@ -158,6 +158,7 @@ void PlaylistContainer::SetViewModel(Playlist* playlist) {
view()->setModel(playlist->proxy());
view()->SetItemDelegates(manager_->library_backend());
view()->SetPlaylist(playlist);
view()->selectionModel()->select(manager_->current_selection(), QItemSelectionModel::ClearAndSelect);
playlist->IgnoreSorting(false);
connect(view()->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),

View File

@ -223,7 +223,7 @@ void PlaylistManager::UpdateSummaryText() {
int selected = 0;
// Get the length of the selected tracks
foreach (const QItemSelectionRange& range, current_selection_) {
foreach (const QItemSelectionRange& range, playlists_[current_id()].selection) {
if (!range.isValid())
continue;
@ -251,8 +251,8 @@ void PlaylistManager::UpdateSummaryText() {
emit SummaryTextChanged(summary);
}
void PlaylistManager::SelectionChanged(const QItemSelection &selection) {
current_selection_ = selection;
void PlaylistManager::SelectionChanged(const QItemSelection& selection) {
playlists_[current_id()].selection = selection;
UpdateSummaryText();
}

View File

@ -47,6 +47,10 @@ public:
Playlist* current() const { return playlist(current_id()); }
Playlist* active() const { return playlist(active_id()); }
const QItemSelection& selection(int id) const { return playlists_[id].selection; }
const QItemSelection& current_selection() const { return selection(current_id()); }
const QItemSelection& active_selection() const { return selection(active_id()); }
QString name(int index) const { return playlists_[index].name; }
void Init(LibraryBackend* library_backend, PlaylistBackend* playlist_backend,
@ -109,6 +113,7 @@ private:
Data(Playlist* _p = NULL, const QString& _name = QString()) : p(_p), name(_name) {}
Playlist* p;
QString name;
QItemSelection selection;
};
TaskManager* task_manager_;
@ -117,8 +122,6 @@ private:
PlaylistSequence* sequence_;
PlaylistParser* parser_;
QItemSelection current_selection_;
// key = id
QMap<int, Data> playlists_;