From bf8490797e14bbdded699646a2407661facf0563 Mon Sep 17 00:00:00 2001
From: Jordan Aurey <aurejordan@gmail.com>
Date: Mon, 25 Mar 2019 10:14:26 +0100
Subject: [PATCH] =?UTF-8?q?classe=20impl=C3=A9mentant=20le=20model?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/elementslistmodel.cpp | 44 +++++++++++++++++++++++++++++++++++++++
 app/elementslistmodel.h   | 33 +++++++++++++++++++++++++++++
 app/mainwindow.cpp        | 12 +++++------
 app/mainwindow.ui         | 18 +++++++++++++---
 4 files changed, 98 insertions(+), 9 deletions(-)
 create mode 100644 app/elementslistmodel.cpp
 create mode 100644 app/elementslistmodel.h

diff --git a/app/elementslistmodel.cpp b/app/elementslistmodel.cpp
new file mode 100644
index 0000000..1a9c8bd
--- /dev/null
+++ b/app/elementslistmodel.cpp
@@ -0,0 +1,44 @@
+#include "elementslistmodel.h"
+
+ElementsListModel::ElementsListModel(QObject *parent)
+    : QAbstractListModel(parent)
+{
+}
+
+QVariant ElementsListModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+    // FIXME: Implement me!
+}
+
+int ElementsListModel::rowCount(const QModelIndex &parent) const
+{
+    // For list models only the root node (an invalid parent) should return the list's size. For all
+    // other (valid) parents, rowCount() should return 0 so that it does not become a tree model.
+    if (parent.isValid())
+        return 0;
+
+    // FIXME: Implement me!
+}
+
+QVariant ElementsListModel::data(const QModelIndex &index, int role) const
+{
+    if (!index.isValid())
+        return QVariant();
+
+    // FIXME: Implement me!
+    return QVariant();
+}
+
+bool ElementsListModel::insertRows(int row, int count, const QModelIndex &parent)
+{
+    beginInsertRows(parent, row, row + count - 1);
+    // FIXME: Implement me!
+    endInsertRows();
+}
+
+bool ElementsListModel::removeRows(int row, int count, const QModelIndex &parent)
+{
+    beginRemoveRows(parent, row, row + count - 1);
+    // FIXME: Implement me!
+    endRemoveRows();
+}
diff --git a/app/elementslistmodel.h b/app/elementslistmodel.h
new file mode 100644
index 0000000..ea4e4d1
--- /dev/null
+++ b/app/elementslistmodel.h
@@ -0,0 +1,33 @@
+#ifndef ELEMENTSLISTMODEL_H
+#define ELEMENTSLISTMODEL_H
+
+#include <QAbstractListModel>
+#include "task.h"
+
+class ElementsListModel : public QAbstractListModel
+{
+    Q_OBJECT
+
+public:
+    explicit ElementsListModel(QObject *parent = nullptr);
+
+    // Header:
+    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
+
+    // Basic functionality:
+    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
+
+    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
+
+    // Add data:
+    bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
+
+    // Remove data:
+    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
+
+private:
+    QVector<Task> taskVector;
+
+};
+
+#endif // ELEMENTSLISTMODEL_H
diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp
index 79351e3..bfa364f 100644
--- a/app/mainwindow.cpp
+++ b/app/mainwindow.cpp
@@ -8,8 +8,8 @@ MainWindow::MainWindow(QWidget *parent) :
     ui->setupUi(this);
 
     // on affiche d'abord la TreeView
-    ui->groupBox->show();
-    ui->groupBox_2->hide();
+    ui->treeWidget->show();
+    ui->listWidget->hide();
 
 }
 
@@ -38,13 +38,13 @@ void MainWindow::update_status(GeneralStatus &genStatus)
 void MainWindow::on_comboBox_currentTextChanged(const QString &arg1)
 {
     if (arg1 == "Tree"){
-        ui->groupBox->show();
-        ui->groupBox_2->hide();
+        ui->treeWidget->show();
+        ui->listWidget->hide();
 
     }
     else if (arg1 == "List"){
-        ui->groupBox_2->show();
-        ui->groupBox ->hide();
+        ui->listWidget->show();
+        ui->treeWidget->hide();
 
     }
     else {
diff --git a/app/mainwindow.ui b/app/mainwindow.ui
index 0dbcf2d..5bf7ea8 100644
--- a/app/mainwindow.ui
+++ b/app/mainwindow.ui
@@ -124,10 +124,22 @@
            </layout>
           </item>
           <item>
-           <widget class="QListWidget" name="listWidget"/>
+           <widget class="QListWidget" name="listWidget">
+            <item>
+             <property name="text">
+              <string>ListView</string>
+             </property>
+            </item>
+           </widget>
           </item>
           <item>
-           <widget class="QTreeView" name="treeView"/>
+           <widget class="QTreeWidget" name="treeWidget">
+            <column>
+             <property name="text">
+              <string notr="true">1</string>
+             </property>
+            </column>
+           </widget>
           </item>
          </layout>
         </item>
@@ -180,7 +192,7 @@
            </layout>
           </item>
           <item>
-           <widget class="QListView" name="listView"/>
+           <widget class="QListWidget" name="listWidget_2"/>
           </item>
          </layout>
         </item>
-- 
GitLab