From add783bf8070a13027224ec5a2f45e557bea1506 Mon Sep 17 00:00:00 2001 From: Arno Date: Mon, 27 Feb 2017 00:53:32 +0100 Subject: 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. --- playerwidget.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'playerwidget.cpp') 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 persistent; + foreach(QModelIndex i, sel){ + persistent << QPersistentModelIndex(i); + } + foreach(QPersistentModelIndex i, persistent){ + mPlayListModel->removeRow(i.row()); + } +} -- cgit v1.2.3-70-g09d2