From 18f54cf1659a8a685233a07bd2d77182a5cd2b3d Mon Sep 17 00:00:00 2001 From: APTX Date: Thu, 25 Aug 2011 19:55:36 +0200 Subject: [PATCH] Make Clear all files work and actually delete File's from memory when removing them. --- filemodel.cpp | 16 ++++++++++++++-- filemodel.h | 2 ++ mainwindow.cpp | 5 +++++ mainwindow.h | 2 ++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/filemodel.cpp b/filemodel.cpp index 202e0e1..e6f437e 100644 --- a/filemodel.cpp +++ b/filemodel.cpp @@ -81,9 +81,10 @@ void FileModel::removeAt(int index) beginRemoveRows(QModelIndex(), index, index); signalMapper->removeMappings(files.at(index)); - files.removeAt(index); + AniDBUdpClient::File *f = files.takeAt(index); remap(index); endRemoveRows(); + f->deleteLater(); } @@ -95,13 +96,24 @@ void FileModel::removeItems(const QModelIndexList &items) for (QModelIndexList::const_iterator i = sorted.constEnd() - 1; i != sorted.constBegin(); --i) { signalMapper->removeMappings(files.at(i->row())); - files.removeAt(i->row()); + AniDBUdpClient::File *f = files.takeAt(i->row()); + f->deleteLater(); } files.removeAt(sorted[0].row()); remap(); reset(); } +void FileModel::clear() +{ + beginRemoveRows(QModelIndex(), 0, rowCount()); + for (int i = 0; i < files.count(); ++i) + signalMapper->removeMappings(files[i]); + qDeleteAll(files); + files.clear(); + endRemoveRows(); +} + void FileModel::start() { foreach (AniDBUdpClient::File *file, files) diff --git a/filemodel.h b/filemodel.h index f55a440..d665f40 100644 --- a/filemodel.h +++ b/filemodel.h @@ -50,6 +50,8 @@ public slots: void removeAt(int index); void removeItems(const QModelIndexList &items); + void clear(); + void start(); protected: diff --git a/mainwindow.cpp b/mainwindow.cpp index 26dc26a..43b4a18 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -123,3 +123,8 @@ void MainWindow::on_actionRenameScript_triggered() qApp->fileModel()->renameEngine()->parse(dialog.renameString()); qApp->setFilterResults(dialog.filterResults()); } + +void MainWindow::on_actionClearAllFiles_triggered() +{ + qApp->fileModel()->clear(); +} diff --git a/mainwindow.h b/mainwindow.h index ad899a4..33657cf 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -34,6 +34,8 @@ private slots: void on_actionRenameScript_triggered(); + void on_actionClearAllFiles_triggered(); + signals: void selectedIndexChanged(); -- 2.52.0