summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2017-02-27 00:53:32 +0100
committerArno <arno@disconnect.de>2017-02-27 00:53:32 +0100
commitadd783bf8070a13027224ec5a2f45e557bea1506 (patch)
treedd71174475467fc9e4ccdfdd4ada5ebdfa33faf1
parent423652c3b1e9adabf9c93c48a4eb778eb03b0755 (diff)
downloadBeetPlayer-add783bf8070a13027224ec5a2f45e557bea1506.tar.gz
BeetPlayer-add783bf8070a13027224ec5a2f45e557bea1506.tar.bz2
BeetPlayer-add783bf8070a13027224ec5a2f45e557bea1506.zip
Implement remove from playlist
Isn't as easy as it sounds. We have to convert the QModelIndexes to remove into persistant ones, because the row number changes when the first one is removed.
-rw-r--r--playerwidget.cpp14
-rw-r--r--playerwidget.h1
2 files changed, 14 insertions, 1 deletions
diff --git a/playerwidget.cpp b/playerwidget.cpp
index 2c28d13..ad3d060 100644
--- a/playerwidget.cpp
+++ b/playerwidget.cpp
@@ -89,6 +89,7 @@ void PlayerWidget::setupGui(){
mPlayListView = new BeetView;
mPlayListView->setModel(mPlayListModel);
mPlayListView->setRootIsDecorated(false);
+ mPlayListView->setSelectionMode(QAbstractItemView::ExtendedSelection);
QGroupBox *playListGB = new QGroupBox(tr("Playlist"));
QVBoxLayout *playListL = new QVBoxLayout;
playListL->addWidget(mPlayListView);
@@ -118,12 +119,12 @@ void PlayerWidget::createActions(){
QAction *addToPlayListA = new QAction(QIcon(":/belly_right.png"), tr("Add to playlist"), this);
connect(addToPlayListA, SIGNAL(triggered()), this, SLOT(addToPlayList()));
QAction *removeFromPlayListA = new QAction(QIcon(":/belly_left.png"), tr("Remove from playlist"), this);
+ connect(removeFromPlayListA, SIGNAL(triggered()), this, SLOT(removeFromPlayList()));
QAction *clearPlayListA = new QAction(QIcon(":/delete.png"), tr("Clear Playlist"), this);
QAction *refreshA = new QAction(QIcon(":/refresh.png"), tr("Refresh..."), this);
connect(refreshA, SIGNAL(triggered()), this, SLOT(reindex()));
QAction *configA = Globals::instance()->action(Globals::ConfigAction);
mView->addAction(addToPlayListA);
- mView->addAction(removeFromPlayListA);
mPlayListView->addAction(removeFromPlayListA);
mPlayListView->addAction(clearPlayListA);
QWidget* spacer1 = new QWidget();
@@ -339,3 +340,14 @@ void PlayerWidget::addToPlayList(){
}
}
}
+
+void PlayerWidget::removeFromPlayList(){
+ QModelIndexList sel = mPlayListView->selectionModel()->selectedRows();
+ QList<QPersistentModelIndex> persistent;
+ foreach(QModelIndex i, sel){
+ persistent << QPersistentModelIndex(i);
+ }
+ foreach(QPersistentModelIndex i, persistent){
+ mPlayListModel->removeRow(i.row());
+ }
+}
diff --git a/playerwidget.h b/playerwidget.h
index a6b9373..c16878e 100644
--- a/playerwidget.h
+++ b/playerwidget.h
@@ -27,6 +27,7 @@ class PlayerWidget : public QWidget {
void clearFilter();
void reindex();
void addToPlayList();
+ void removeFromPlayList();
private:
void setupGui();