From 8902f5090f60dbb3c2bbdfaa8a2ab109369c3f2e Mon Sep 17 00:00:00 2001
From: Yann Boucher <yann.boucher@etu.utc.fr>
Date: Sun, 13 Jun 2021 20:00:56 +0200
Subject: [PATCH] Works on linux with default QT 5.9 packages

---
 README.md                                |  2 +-
 include/property.hpp                     |  1 +
 src/colorlabel.cpp                       |  1 +
 src/gridview.cpp                         |  1 +
 src/interface.cpp                        | 17 +++++++----------
 src/propertyvisitors.cpp                 |  2 +-
 src/src.pro                              |  1 +
 tests/alphabet_test.cpp                  | 12 ++++++------
 tests/arbitraryneighborhoodrule_test.cpp |  2 +-
 tests/factory_tests.cpp                  |  4 ++--
 tests/history_test.cpp                   |  8 ++++----
 tests/property_test.cpp                  |  2 +-
 tests/structure_test.cpp                 |  8 ++++----
 tests/structurereader_tests.cpp          |  8 ++++----
 14 files changed, 35 insertions(+), 34 deletions(-)

diff --git a/README.md b/README.md
index 6aa5750..e6b5e6f 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ Application développée dans le cadre de l’UV LO21 qui permet de répondre à
  - [Auteurs et licence](#auteurs)
 ## Pour commencer
 
-Avoir une version de **Qt** d'au moins 5.12. Projet principalement testé sur Qt 5.15.2.
+Avoir une version de **Qt** d'au moins 5.9. Projet principalement testé sur Qt 5.15.2.
 Le projet a été testé et fonctionne sur Qt 6, mais il est conseillé d'utiliser une version récente de Qt 5.
 
 Testé avec les compilateurs suivants :
diff --git a/include/property.hpp b/include/property.hpp
index 6b183f0..b9d6b52 100644
--- a/include/property.hpp
+++ b/include/property.hpp
@@ -18,6 +18,7 @@ Fichier définissant la classe Property représentant une propriété chargable,
 #include <memory>
 #include <limits>
 #include <exception>
+#include <cassert>
 
 #include <QWidget>
 #include <QLayout>
diff --git a/src/colorlabel.cpp b/src/colorlabel.cpp
index d5dda1b..d34cedf 100644
--- a/src/colorlabel.cpp
+++ b/src/colorlabel.cpp
@@ -6,6 +6,7 @@
 #include "interface.hpp"
 #include <stdlib.h>
 #include <string>
+#include <cassert>
 #include <QListWidget>
 #include <QColorDialog>
 #include <QMessageBox>
diff --git a/src/gridview.cpp b/src/gridview.cpp
index e3f64f9..bac496d 100644
--- a/src/gridview.cpp
+++ b/src/gridview.cpp
@@ -25,6 +25,7 @@ Cette classe représente le widget utilisé pour l'affichage et l'interaction av
 
 #include <vector>
 #include <cstdlib>
+#include <cassert>
 
 #include <qmath.h>
 
diff --git a/src/interface.cpp b/src/interface.cpp
index 4fd3df9..849d8c4 100644
--- a/src/interface.cpp
+++ b/src/interface.cpp
@@ -717,7 +717,6 @@ void MainWindow::play_bad_apple()
 {
     static QJsonArray bad_apple_frame_list;
     static QTimer bad_apple_timer;
-    static bool bad_apple_connected;
 #ifdef BAD_APPLE_AUDIO
     static QMediaPlayer bad_apple_player;
 #endif
@@ -738,9 +737,8 @@ void MainWindow::play_bad_apple()
     bad_apple_timer.stop();
     bad_apple_frame_list = frames["data"].toArray();
 
-    if (!bad_apple_connected)
     {
-        bad_apple_timer.callOnTimeout([this]
+        connect(&bad_apple_timer, &QTimer::timeout, this, [this]
                                       {
 #ifdef BAD_APPLE_AUDIO
                                           unsigned frame_idx;
@@ -775,7 +773,7 @@ void MainWindow::play_bad_apple()
                                           }
 
                                           ui->grid_view->copy_grid(grid);
-                                      });
+                                      }, Qt::UniqueConnection);
     };
 
     // On coupe la simulation si elle est en train de s'exécuter
@@ -788,7 +786,7 @@ void MainWindow::play_bad_apple()
     bad_apple_player.setMedia(QUrl::fromLocalFile("extras/bad-apple.wav"));
     bad_apple_player.play();
 #else
-    QMessageBox::information(this, "", "Music functionnality is only available with Qt 5");
+    QMessageBox::information(this, "", "Music functionnality is only available with Qt Multimedia module (might be unavailable with Qt 6)");
 #endif
 
     bad_apple_elapsed.start();
@@ -801,7 +799,6 @@ void MainWindow::play_snake()
     static QTimer snake_timer;
     static Coord snake_dir;
     static std::list<Coord> snake_body;
-    static bool snake_connected = false;
 
     statusBar()->showMessage("Controls : ZQSD", 60000);
 
@@ -898,9 +895,9 @@ void MainWindow::play_snake()
         on_playPauseButton_clicked();
     }
 
-    if (!snake_connected)
+
     {
-        snake_timer.callOnTimeout([this]
+       connect(&snake_timer, &QTimer::timeout, this, [this]
                                   {
                                       if (m_arrow_key_state[0] && snake_dir != Coord{+1, 0})
                                           snake_dir = {-1, 0};
@@ -911,8 +908,8 @@ void MainWindow::play_snake()
                                       else if (m_arrow_key_state[3] && snake_dir != Coord{0, +1})
                                           snake_dir = {0, -1};
                                       advance_snake(false);
-                                  });
-        snake_connected = true;
+                                  }, Qt::UniqueConnection);
+
     }
     snake_timer.start(100);
 }
diff --git a/src/propertyvisitors.cpp b/src/propertyvisitors.cpp
index 701bc33..a455156 100644
--- a/src/propertyvisitors.cpp
+++ b/src/propertyvisitors.cpp
@@ -120,7 +120,7 @@ QJsonValue PropertyLoaderVisitor::fetch_value(Property &prop)
         return val;
     }
     else
-        return current()[prop.identifier().c_str()];
+        return current().toObject().value(prop.identifier().c_str());
 }
 
 void PropertyLoaderVisitor::visit(StringProperty &prop)
diff --git a/src/src.pro b/src/src.pro
index 33979fb..02ad1d0 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -8,6 +8,7 @@ qtHaveModule(multimedia): QT += multimedia
 
 CONFIG += c++14
 TEMPLATE = app
+TARGET = cellulut
 
 # Optimisations, flag pour garder les infos de debug
 QMAKE_CXXFLAGS += -O3 -g
diff --git a/tests/alphabet_test.cpp b/tests/alphabet_test.cpp
index 9328433..a1fb47b 100644
--- a/tests/alphabet_test.cpp
+++ b/tests/alphabet_test.cpp
@@ -25,17 +25,17 @@ void CellulutTests::test_alphabet(){
     unsigned char cb=sc.getBlue();
     unsigned char cr=sc.getRed();
     unsigned char cg=sc.getGreen();
-    QCOMPARE(cb,126);
-    QCOMPARE(cg,5);
-    QCOMPARE(cr,1);
+    QCOMPARE(cb,(unsigned char)126);
+    QCOMPARE(cg,(unsigned char)5);
+    QCOMPARE(cr,(unsigned char)1);
 
     state test2=a.getState(2);
     stateColor sc2 =test2.getColor();
     unsigned char cb2=sc2.getBlue();
     unsigned char cr2=sc2.getRed();
     unsigned char cg2=sc2.getGreen();
-    QCOMPARE(cb2,74);
-    QCOMPARE(cg2,245);
-    QCOMPARE(cr2,144);
+    QCOMPARE(cb2,(unsigned char)74);
+    QCOMPARE(cg2,(unsigned char)245);
+    QCOMPARE(cr2,(unsigned char)144);
 
 }
diff --git a/tests/arbitraryneighborhoodrule_test.cpp b/tests/arbitraryneighborhoodrule_test.cpp
index 71c5755..a743cd1 100644
--- a/tests/arbitraryneighborhoodrule_test.cpp
+++ b/tests/arbitraryneighborhoodrule_test.cpp
@@ -31,7 +31,7 @@ void CellulutTests::test_arbitrary_neighborhood_rule()
             prop->accept(visit);
     }
 
-    QCOMPARE(rule.getFormats().size(), 1ul);
+    QCOMPARE(rule.getFormats().size(), 1u);
     QCOMPARE(rule.getFormats()[0].positions.size(), coords.size());
 
     auto list = rule.getFormats()[0].positions;
diff --git a/tests/factory_tests.cpp b/tests/factory_tests.cpp
index eb06d95..35f2477 100644
--- a/tests/factory_tests.cpp
+++ b/tests/factory_tests.cpp
@@ -37,11 +37,11 @@ void CellulutTests::test_factory()
 
     std::unique_ptr<Transition> life_trans = Factory<Transition>::make("life-like");
     QVERIFY(life_trans != nullptr);
-    QCOMPARE(life_trans->say_hi(), "Life hi!\n");
+    QCOMPARE(life_trans->say_hi(), std::string("Life hi!\n"));
 
     std::unique_ptr<Transition> gens_trans = Factory<Transition>::make("generations");
     QVERIFY(gens_trans != nullptr);
-    QCOMPARE(gens_trans->say_hi(), "Generations hi!\n");
+    QCOMPARE(gens_trans->say_hi(), std::string("Generations hi!\n"));
 
 
     QVERIFY(nullptr == Factory<Transition>::make("<invalid>"));
diff --git a/tests/history_test.cpp b/tests/history_test.cpp
index a814c31..ac68fd1 100644
--- a/tests/history_test.cpp
+++ b/tests/history_test.cpp
@@ -27,12 +27,12 @@ void CellulutTests::test_history()
 
     // On pop la première grille puis la deuxième
     Grid popGrid = historyTest.popGrid();
-    QCOMPARE(popGrid.get_state(pos2), 3ul);
+    QCOMPARE(popGrid.get_state(pos2), 3u);
     Grid topGrid = historyTest.topGrid();
     QVERIFY(topGrid.get_state(pos1) == 2);
 
     popGrid = historyTest.popGrid();
-    QCOMPARE(popGrid.get_state(pos1), 2ul);
+    QCOMPARE(popGrid.get_state(pos1), 2u);
     QVERIFY(historyTest.isEmpty() == true);
 
     // Push de trois grille (taille max de la pile de l'history = 2)
@@ -41,11 +41,11 @@ void CellulutTests::test_history()
     historyTest.pushGrid(gridTest3); // La première grille est supprimée
 
     popGrid = historyTest.popGrid();
-    QCOMPARE(popGrid.get_state(pos3), 4ul);
+    QCOMPARE(popGrid.get_state(pos3), 4u);
     topGrid = historyTest.topGrid();
     QVERIFY(topGrid.get_state(pos2) == 3);
 
     popGrid = historyTest.popGrid();
-    QCOMPARE(popGrid.get_state(pos2), 3ul);
+    QCOMPARE(popGrid.get_state(pos2), 3u);
     QVERIFY(historyTest.isEmpty() == true);
 }
diff --git a/tests/property_test.cpp b/tests/property_test.cpp
index 4761801..ac4aaca 100644
--- a/tests/property_test.cpp
+++ b/tests/property_test.cpp
@@ -28,7 +28,7 @@ void CellulutTests::test_property()
 
     test.coords.load_from_neighborhood(n);
 
-    QCOMPARE(test.coords.size(), 3ul);
+    QCOMPARE(test.coords.size(), 3u);
     for (unsigned i = 0; i < test.coords.size(); ++i)
     {
         CoordinateProperty& coord = static_cast<CoordinateProperty&>(test.coords.at(i));
diff --git a/tests/structure_test.cpp b/tests/structure_test.cpp
index 6c95dc6..0f2565a 100644
--- a/tests/structure_test.cpp
+++ b/tests/structure_test.cpp
@@ -24,8 +24,8 @@ void CellulutTests::test_structure()
         QVERIFY(std::is_permutation(normalized_coords.begin(), normalized_coords.end(), s1.begin()));
         QVERIFY(std::is_permutation(normalized_coords.begin(), normalized_coords.end(), s2.begin()));
 
-        QCOMPARE(s1.width(), 3ul);
-        QCOMPARE(s1.height(), 2ul);
+        QCOMPARE(s1.width(), 3u);
+        QCOMPARE(s1.height(), 2u);
 
         s1.load(empty.begin(), empty.end());
         QVERIFY(s1.size() == 0);
@@ -40,8 +40,8 @@ void CellulutTests::test_structure()
         QCOMPARE(s1.size(), coords.size()); // 2 cellules non nulles, on ignore les cellules à zéro qui sont toujours implicites
         QVERIFY(std::is_permutation(normalized_coords.begin(), normalized_coords.end(), s1.begin()));
 
-        QCOMPARE(s1.width(), 3ul);
-        QCOMPARE(s1.height(), 2ul);
+        QCOMPARE(s1.width(), 3u);
+        QCOMPARE(s1.height(), 2u);
     }
 }
 
diff --git a/tests/structurereader_tests.cpp b/tests/structurereader_tests.cpp
index 84b55c2..ae95e67 100644
--- a/tests/structurereader_tests.cpp
+++ b/tests/structurereader_tests.cpp
@@ -39,7 +39,7 @@ void CellulutTests::test_rle_structurereader()
 
         try {
             Structure stru = rle.read_structure();
-            QCOMPARE(stru.size(), 5ul);
+            QCOMPARE(stru.size(), 5u);
             QVERIFY(std::count(stru.begin(), stru.end(), std::make_pair<Coord, unsigned>(Coord{1, 0}, 1)) == 1);
         }
         catch (const std::exception& ex)
@@ -55,7 +55,7 @@ void CellulutTests::test_rle_structurereader()
         try {
 
             Structure stru = rle.read_structure();
-            QCOMPARE(stru.size(), 36ul);
+            QCOMPARE(stru.size(), 36u);
         }
         catch (const std::exception& ex)
         {
@@ -70,7 +70,7 @@ void CellulutTests::test_rle_structurereader()
         try {
 
             Structure stru = rle.read_structure();
-            QCOMPARE(stru.size(), 16ul);
+            QCOMPARE(stru.size(), 16u);
 
             std::map<int, int> state_count;
             for (auto pair : stru)
@@ -96,7 +96,7 @@ void CellulutTests::test_json_structurereader()
 
         try {
             Structure stru = rle.read_structure();
-            QCOMPARE(stru.size(), 2ul);
+            QCOMPARE(stru.size(), 2u);
             QVERIFY(std::count(stru.begin(), stru.end(), std::make_pair<Coord, unsigned>(Coord{0, 0}, 1)) == 1);
             QVERIFY(std::count(stru.begin(), stru.end(), std::make_pair<Coord, unsigned>(Coord{2, 3}, 3)) == 1);
         }
-- 
GitLab