summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2010-06-18 15:52:01 +0200
committerArno <am@disconnect.de>2010-06-18 15:52:01 +0200
commitb153f90a4c7f76a5ce5f4985bdbd687ba1602fdb (patch)
tree7e2bfc14e62e24b56a77b3afd2e40003956fb49d
parenta8bd9a2310bd630dd4e72fe0ff54a8be17e80064 (diff)
downloadSheMov-b153f90a4c7f76a5ce5f4985bdbd687ba1602fdb.tar.gz
SheMov-b153f90a4c7f76a5ce5f4985bdbd687ba1602fdb.tar.bz2
SheMov-b153f90a4c7f76a5ce5f4985bdbd687ba1602fdb.zip
Created frontend for SeriesTreeModel::deleteFromSeries
Implemented frontend for SeriesTreeModel::deleteFromSeries. I hope QPersistentModelIndexes work as advertised. From the qt-sources it seems that a QPersistentModelIndex is automatically updated by QAbstractItemModel when calling begin(Remove|Insert)Rows. Testing worked out fine. While at it I found a bug in SmTreeModel. removeRows has to be called with (i - 1) instead of (i) to remove the correct nodes.
-rw-r--r--seriestreemodel.cpp1
-rw-r--r--seriestreewidget.cpp54
-rw-r--r--shemov.cpp5
-rw-r--r--smtreemodel.cpp2
4 files changed, 59 insertions, 3 deletions
diff --git a/seriestreemodel.cpp b/seriestreemodel.cpp
index b8a4425..846f00c 100644
--- a/seriestreemodel.cpp
+++ b/seriestreemodel.cpp
@@ -196,6 +196,7 @@ bool SeriesTreeModel::deleteFromSeries(const QModelIndex &what){
foreach(QFileInfo fi, files){
QFile::remove(fi.absoluteFilePath());
}
+ removeRows(what.row(), 1, what.parent());
return true;
}
}
diff --git a/seriestreewidget.cpp b/seriestreewidget.cpp
index 071667d..553a534 100644
--- a/seriestreewidget.cpp
+++ b/seriestreewidget.cpp
@@ -15,6 +15,7 @@
#include <QContextMenuEvent>
#include <QMenu>
#include <QAction>
+#include <QMessageBox>
#include "seriestreewidget.h"
#include "smubermodel.h"
@@ -75,7 +76,60 @@ void SeriesTreeWidget::deleteFromSeries(){
if(selected.isEmpty()){
return;
}
+ QList<QPersistentModelIndex> series;
+ QList<QPersistentModelIndex> parts;
+ foreach(QModelIndex s, selected){
+ QModelIndex real = mProxy->mapToSource(s);
+ if(real.data(SeriesTreeModel::TypeRole).toInt() == SeriesTreeModel::Series || real.data(SeriesTreeModel::TypeRole).toInt() == SeriesTreeModel::NewSeries){
+ series << QPersistentModelIndex(real);
+ }
+ if(real.data(SeriesTreeModel::TypeRole).toInt() == SeriesTreeModel::Part){
+ parts << QPersistentModelIndex(real);
+ }
+ }
+ QList<QPersistentModelIndex> removeParts;
+ foreach(QPersistentModelIndex s, parts){
+ if(series.contains(s.parent())){
+ removeParts << s;
+ }
+ }
+ foreach(QPersistentModelIndex s, removeParts){
+ parts.removeAll(s);
+ }
+ QFileInfoList files;
+ foreach(QPersistentModelIndex s, series){
+ files.append(mModel->findFiles(s));
+ }
+ QString message;
+ if(!files.isEmpty()){
+ message = QString(tr("<p>This operation will delete %1 file(s) permanently:</p>")).arg(files.count());
+ message.append(tr("<ul>"));
+ int ctr = 0;
+ foreach(QFileInfo f, files){
+ ++ctr;
+ QString li = QString(tr("<li>%1</li>")).arg(f.absoluteFilePath());
+ message.append(li);
+ if(ctr == 20){
+ QString elide = QString(tr("<li>(%1 more files)</li>")).arg(files.count() - ctr);
+ message.append(elide);
+ break;
+ }
+ }
+ message.append(tr("</ul>"));
+ message.append(tr("<p>Continue?</p>"));
+ }else{
+ message = QString(tr("<p>This operation will delete no files. Continue?</p>"));
+ }
+ int retval = QMessageBox::critical(this, tr("Delete Series"), message, QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
+ if(retval == QMessageBox::Yes){
+ foreach(QPersistentModelIndex s, series){
+ mModel->deleteFromSeries(s);
+ }
+ foreach(QPersistentModelIndex s, parts){
+ mModel->deleteFromSeries(s);
+ }
+ }
}
void SeriesTreeWidget::filter(){
diff --git a/shemov.cpp b/shemov.cpp
index d735ba3..8e5c54c 100644
--- a/shemov.cpp
+++ b/shemov.cpp
@@ -357,11 +357,12 @@ void SheMov::createActions(){
connect(mStatisticsA, SIGNAL(triggered()), this, SLOT(showStatistics()));
//Tree context menu
- mNewSeriesA = new QAction(tr("New series"), this);
+ mNewSeriesA = new QAction(tr("New series..."), this);
mATree->seriesWidget()->seriesTree()->addAction(mNewSeriesA);
connect(mNewSeriesA, SIGNAL(triggered()), mATree->seriesWidget(), SLOT(newSeries()));
- mDeleteFromSeriesA = new QAction(tr("Delete entry..."), this);
+ mDeleteFromSeriesA = new QAction(tr("Delete entries..."), this);
mATree->seriesWidget()->seriesTree()->addAction(mDeleteFromSeriesA);
+ connect(mDeleteFromSeriesA, SIGNAL(triggered()), mATree->seriesWidget(), SLOT(deleteFromSeries()));
// misc
diff --git a/smtreemodel.cpp b/smtreemodel.cpp
index 227c1cb..2a230cc 100644
--- a/smtreemodel.cpp
+++ b/smtreemodel.cpp
@@ -153,7 +153,7 @@ bool SmTreeModel::removeRows(int row, int count, const QModelIndex &parent){
beginRemoveRows(parent, row, row + count - 1);
for(int i = row + count; i > row; --i){
- retval = parentItem->removeChild(i);
+ retval = parentItem->removeChild(i - 1);
}
endRemoveRows();