]> Some of my projects - AniAdd.git/commitdiff
Make Clear all files work and actually delete File's from memory when removing them.
authorAPTX <marek321@gmail.com>
Thu, 25 Aug 2011 17:55:36 +0000 (19:55 +0200)
committerAPTX <marek321@gmail.com>
Thu, 25 Aug 2011 17:55:36 +0000 (19:55 +0200)
filemodel.cpp
filemodel.h
mainwindow.cpp
mainwindow.h

index 202e0e168b35b17f7607da75ef8ff663ab6d3720..e6f437e9ae7a31396286d77d902683b9afea7b1f 100644 (file)
@@ -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)
index f55a440a754b27b99d28f1bb458c14562b5605c9..d665f401b41acca35feb8e81516e067bb5b77b19 100644 (file)
@@ -50,6 +50,8 @@ public slots:
        void removeAt(int index);
        void removeItems(const QModelIndexList &items);
 
+       void clear();
+
        void start();
 
 protected:
index 26dc26a42a8aa3794d5e27a0d55996763535d48d..43b4a186c344c05a2a666ad73da0d1ef417e0944 100644 (file)
@@ -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();
+}
index ad899a44d5ad97989272aed03b740ec710fbb6a5..33657cf1a6c9f6382477b231473e69e69f35eab0 100644 (file)
@@ -34,6 +34,8 @@ private slots:
 
        void on_actionRenameScript_triggered();
 
+       void on_actionClearAllFiles_triggered();
+
 signals:
        void selectedIndexChanged();