From 7d02c7aeceb88ada918455205ec68bb8703a0dde Mon Sep 17 00:00:00 2001
From: Romain DERRE <romain.derre@pc228-14.pedago.ensiie.fr>
Date: Fri, 29 Mar 2019 14:54:35 +0100
Subject: [PATCH] Quit fonctionnel avec free et suppression des fichiers
 temporaires

---
 app/controller.cpp         |  6 ++++++
 app/controller.h           |  2 +-
 app/elementstablemodel.cpp | 10 ++++++++++
 app/elementstablemodel.h   |  2 ++
 app/main.cpp               |  5 ++++-
 app/mainwindow.cpp         |  7 +------
 app/mainwindow.h           |  3 ---
 app/mainwindow.ui          | 10 ----------
 8 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/app/controller.cpp b/app/controller.cpp
index 7c4b9d4..2616248 100644
--- a/app/controller.cpp
+++ b/app/controller.cpp
@@ -36,3 +36,9 @@ void Controller::update(){
     //eltCollection.update();
     //
 }
+
+void Controller::quit()
+{
+    eltCollection.clear();
+    system("rm .listT .nbT .userT");
+}
diff --git a/app/controller.h b/app/controller.h
index 4ce2c7e..afce143 100644
--- a/app/controller.h
+++ b/app/controller.h
@@ -15,8 +15,8 @@ class Controller : public QObject
     Q_OBJECT
 
 public:
-
     Controller(MainWindow*);
+    void quit();
 
 public slots :
     void update();
diff --git a/app/elementstablemodel.cpp b/app/elementstablemodel.cpp
index 302b7dc..8f81ddf 100644
--- a/app/elementstablemodel.cpp
+++ b/app/elementstablemodel.cpp
@@ -120,6 +120,16 @@ void ElementsTableModel::removeTask(Task* task){
     endRemoveRows();
 }
 
+void ElementsTableModel::clear()
+{
+    beginRemoveRows(QModelIndex(), 0, rowCount());
+    for (int i = 0; i < taskVector.size(); ++i) {
+        free(taskVector.value(i));
+        qDebug() << "free";
+    }
+    taskVector.clear();
+    endRemoveRows();
+}
 
 
 bool ElementsTableModel::insertRows(int row, int count, const QModelIndex &parent)
diff --git a/app/elementstablemodel.h b/app/elementstablemodel.h
index b1a4628..cb399e2 100644
--- a/app/elementstablemodel.h
+++ b/app/elementstablemodel.h
@@ -46,6 +46,8 @@ public:
     
     void writeCSV(QFile * file);
 
+    void clear();
+
 private:
 
     //QMap<int, Task> taskMap;
diff --git a/app/main.cpp b/app/main.cpp
index f30c28d..df5b08a 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -14,5 +14,8 @@ int main(int argc, char *argv[])
     Controller * _controller = new Controller(&w);
 
 
-    return a.exec();
+    int ex = a.exec();
+    _controller->quit();
+
+    return ex;
 }
diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp
index 7b93e32..e0a6e93 100644
--- a/app/mainwindow.cpp
+++ b/app/mainwindow.cpp
@@ -126,12 +126,7 @@ void MainWindow::on_comboBox_currentTextChanged(const QString &arg1)
 }
 
 
-void MainWindow::on_actionQuitter_triggered()
-{
-
-}
-
 void MainWindow::on_actionQuit_triggered()
 {
-    on_actionQuitter_triggered();
+    QApplication::quit();
 }
diff --git a/app/mainwindow.h b/app/mainwindow.h
index 1d1107d..cf788c4 100644
--- a/app/mainwindow.h
+++ b/app/mainwindow.h
@@ -38,9 +38,6 @@ private slots:
 
     void on_comboBox_currentTextChanged(const QString &arg1);
 
-
-    void on_actionQuitter_triggered();
-
     void on_actionQuit_triggered();
 
 private:
diff --git a/app/mainwindow.ui b/app/mainwindow.ui
index fb3b528..45fa577 100644
--- a/app/mainwindow.ui
+++ b/app/mainwindow.ui
@@ -366,11 +366,6 @@
    <addaction name="menuLanguage"/>
    <addaction name="menuDisplay_2"/>
   </widget>
-  <action name="actionQuitter">
-   <property name="text">
-    <string>Quitter</string>
-   </property>
-  </action>
   <action name="actionFR">
    <property name="text">
     <string>FR</string>
@@ -401,11 +396,6 @@
     <string>Night Model</string>
    </property>
   </action>
-  <action name="actionCreate_task">
-   <property name="text">
-    <string>Create task</string>
-   </property>
-  </action>
   <action name="actionExport_actual_state">
    <property name="text">
     <string>Export actual state</string>
-- 
GitLab