diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index af980638e..562c16bde 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -655,7 +655,6 @@ MainWindow::MainWindow(QWidget *parent) connect(MPDConnection::self(), SIGNAL(outputsUpdated(const QList &)), this, SLOT(outputsUpdated(const QList &))); connect(this, SIGNAL(enableOutput(int, bool)), MPDConnection::self(), SLOT(enableOutput(int, bool))); connect(this, SIGNAL(outputs()), MPDConnection::self(), SLOT(outputs())); - connect(this, SIGNAL(removeSongs(const QList &)), MPDConnection::self(), SLOT(removeSongs(const QList &))); connect(this, SIGNAL(pause(bool)), MPDConnection::self(), SLOT(setPause(bool))); connect(this, SIGNAL(play()), MPDConnection::self(), SLOT(play())); connect(this, SIGNAL(stop(bool)), MPDConnection::self(), SLOT(stopPlaying(bool))); @@ -2007,18 +2006,7 @@ void MainWindow::clearPlayQueue() void MainWindow::removeFromPlayQueue() { - const QModelIndexList items = playQueue->selectedIndexes(); - QList toBeRemoved; - - if (items.isEmpty()) { - return; - } - - foreach (const QModelIndex &idx, items) { - toBeRemoved.append(playQueueModel.getIdByRow(playQueueProxyModel.mapToSource(idx).row())); - } - - emit removeSongs(toBeRemoved); + playQueueModel.remove(playQueueProxyModel.mapToSourceRows(playQueue->selectedIndexes())); } void MainWindow::replacePlayQueue() @@ -2339,22 +2327,9 @@ void MainWindow::sidebarModeChanged() } } -// Do this by taking the set off all song id's and subtracting from that the set of selected song id's. Feed that list to emit removeSongs void MainWindow::cropPlayQueue() { - const QModelIndexList items = playQueue->selectedIndexes(); - if (items.isEmpty()) { - return; - } - - QSet songs = playQueueModel.getSongIdSet(); - QSet selected; - - foreach (const QModelIndex &idx, items) { - selected << playQueueModel.getIdByRow(playQueueProxyModel.mapToSource(idx).row()); - } - - emit removeSongs((songs - selected).toList()); + playQueueModel.crop(playQueueProxyModel.mapToSourceRows(playQueue->selectedIndexes())); } void MainWindow::currentTabChanged(int index) diff --git a/gui/mainwindow.h b/gui/mainwindow.h index cee944689..c23f8613e 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -150,7 +150,6 @@ private: Q_SIGNALS: // These are for communicating with MPD object (which is in its own thread, so need to talk via signal/slots) void setDetails(const MPDConnectionDetails &det); - void removeSongs(const QList &); void pause(bool p); void play(); void stop(bool afterCurrent=false); diff --git a/models/playqueuemodel.cpp b/models/playqueuemodel.cpp index 0bbc2f146..a11533ad7 100644 --- a/models/playqueuemodel.cpp +++ b/models/playqueuemodel.cpp @@ -793,7 +793,6 @@ void PlayQueueModel::setStopAfterTrack(qint32 track) void PlayQueueModel::removeCantataStreams() { QList ids; - foreach (const Song &s, songs) { if (s.isCantataStream()) { ids.append(s.id); @@ -805,6 +804,40 @@ void PlayQueueModel::removeCantataStreams() } } +void PlayQueueModel::remove(const QList &rowsToRemove) +{ + QList removeIds; + foreach (const int &r, rowsToRemove) { + if (r>0 && r &rowsToKeep) +{ + QSet allIds; + foreach(const Song &song, songs) { + allIds.insert(song.id); + } + + QSet keepIds; + foreach (const int &r, rowsToKeep) { + if (r>0 && r removeIds=allIds-keepIds; + if (!removeIds.isEmpty()) { + emit removeSongs(removeIds.toList()); + } +} + void PlayQueueModel::stats() { quint32 time = 0; @@ -927,17 +960,6 @@ void PlayQueueModel::updateDetails(const QList &updated) } } -QSet PlayQueueModel::getSongIdSet() -{ - QSet ids; - - foreach(const Song &song, songs) { - ids << song.id; - } - - return ids; -} - QStringList PlayQueueModel::filenames() { QStringList names; diff --git a/models/playqueuemodel.h b/models/playqueuemodel.h index bc17609ea..ad3e11b4d 100644 --- a/models/playqueuemodel.h +++ b/models/playqueuemodel.h @@ -88,7 +88,6 @@ public: QStringList mimeTypes() const; QMimeData *mimeData(const QModelIndexList &indexes) const; bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); - QSet getSongIdSet(); QStringList filenames(); void clear(); qint32 currentSong() const { return currentSongId; } @@ -98,6 +97,8 @@ public: void setStopAfterTrack(qint32 track); void clearStopAfterTrack() { setStopAfterTrack(-1); } void removeCantataStreams(); + void remove(const QList &rowsToRemove); + void crop(const QList &rowsToKeep); public Q_SLOTS: void addItems(const QStringList &items, int row, bool replace, quint8 priority); diff --git a/models/proxymodel.cpp b/models/proxymodel.cpp index d5f2e3113..5c047bb6a 100644 --- a/models/proxymodel.cpp +++ b/models/proxymodel.cpp @@ -130,3 +130,12 @@ void ProxyModel::sort(int column, Qt::SortOrder order) isSorted=true; } } + +QList ProxyModel::mapToSourceRows(const QModelIndexList &list) const +{ + QList rows; + foreach (const QModelIndex &idx, list) { + rows.append(mapToSource(idx).row()); + } + return rows; +} diff --git a/models/proxymodel.h b/models/proxymodel.h index 52fe8fc3b..52489f7cc 100644 --- a/models/proxymodel.h +++ b/models/proxymodel.h @@ -44,6 +44,7 @@ public: const QString & filterText() const { return origFilterText; } void sort() { isSorted=false; sort(0); } void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); + QList mapToSourceRows(const QModelIndexList &list) const; protected: bool matchesFilter(const Song &s) const;