From 6f8107c1cb22938ee4c91d0993dc82e624c7c8de Mon Sep 17 00:00:00 2001 From: Arno Date: Sun, 17 May 2015 09:47:30 +0200 Subject: Fix removing files from NewMovieWizard Removing files didn't work as expected: It removed files more or less at random, because the indexes were from the proxy and weren't mapped back to the source. While at it, make it possible to remove several files at once and change the label of the button to make clear that the files are only removed from the view. --- newmoviewizard.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'newmoviewizard.cpp') diff --git a/newmoviewizard.cpp b/newmoviewizard.cpp index 137f7c2..1989e64 100644 --- a/newmoviewizard.cpp +++ b/newmoviewizard.cpp @@ -308,6 +308,7 @@ void MovieInfoPage::setupGui(){ mFileView->setItemDelegateForColumn(WizardTreeModel::FilePart, new FileNoDelegate(mFileView)); mFileView->setSortingEnabled(true); mFileView->header()->moveSection(1, 3); + mFileView->setSelectionMode(QAbstractItemView::ExtendedSelection); //add + remove files QHBoxLayout *fileButtonLayout = new QHBoxLayout; @@ -318,7 +319,7 @@ void MovieInfoPage::setupGui(){ mAddFile = new QPushButton(tr("Add files...")); fileButtonLayout->addWidget(mAddFile); connect(mAddFile, SIGNAL(clicked()), this, SLOT(addFiles())); - mRemoveFile = new QPushButton(tr("Remove file")); + mRemoveFile = new QPushButton(tr("Remove from list")); fileButtonLayout->addWidget(mRemoveFile); connect(mRemoveFile, SIGNAL(clicked()), this, SLOT(removeFile())); @@ -467,11 +468,20 @@ void MovieInfoPage::addFiles(){ } void MovieInfoPage::removeFile(){ - QModelIndexList selected = mFileView->selectionModel()->selectedRows(); + QModelIndexList selected = mFileView->selectionModel()->selectedRows(); + QList curSel; + foreach(QModelIndex idx, selected){ + curSel << QPersistentModelIndex(idx); + } if(selected.isEmpty()){ return; } - mFileModel->removeRows(selected.at(0).row(), 1, selected.at(0).parent()); + foreach(QPersistentModelIndex pi, curSel){ + QModelIndex cur = mProxy->mapToSource(pi); + if(cur.isValid()){ + mFileModel->removeRow(cur.row(), cur.parent()); + } + } } MovieMappingPage::MovieMappingPage(const QString &table, QWidget *parent) : QWizardPage(parent), mTable(table){ -- cgit v1.2.3-70-g09d2