From b2f95da02ce3bbe9791416b264408be2adc5c103 Mon Sep 17 00:00:00 2001 From: p2405951 Date: Thu, 19 Jun 2025 09:51:06 +0200 Subject: [PATCH 1/3] constrcuteur parse json --- .../.qmake.stash | 21 ++++++ data.qrc | 5 ++ ex.txt | 7 ++ main.cpp | 11 ++- sae201.pro | 4 + step.cpp | 73 ++++++++++++++++--- step.h | 13 +++- 7 files changed, 120 insertions(+), 14 deletions(-) create mode 100644 build/Desktop_Qt_6_9_0_MinGW_64_bit-Debug/.qmake.stash create mode 100644 data.qrc create mode 100644 ex.txt diff --git a/build/Desktop_Qt_6_9_0_MinGW_64_bit-Debug/.qmake.stash b/build/Desktop_Qt_6_9_0_MinGW_64_bit-Debug/.qmake.stash new file mode 100644 index 0000000..8e49e8a --- /dev/null +++ b/build/Desktop_Qt_6_9_0_MinGW_64_bit-Debug/.qmake.stash @@ -0,0 +1,21 @@ +QMAKE_CXX.QT_COMPILER_STDCXX = 201703L +QMAKE_CXX.QMAKE_GCC_MAJOR_VERSION = 13 +QMAKE_CXX.QMAKE_GCC_MINOR_VERSION = 1 +QMAKE_CXX.QMAKE_GCC_PATCH_VERSION = 0 +QMAKE_CXX.COMPILER_MACROS = \ + QT_COMPILER_STDCXX \ + QMAKE_GCC_MAJOR_VERSION \ + QMAKE_GCC_MINOR_VERSION \ + QMAKE_GCC_PATCH_VERSION +QMAKE_CXX.INCDIRS = \ + C:/Qt/Tools/mingw1310_64/lib/gcc/x86_64-w64-mingw32/13.1.0/include/c++ \ + C:/Qt/Tools/mingw1310_64/lib/gcc/x86_64-w64-mingw32/13.1.0/include/c++/x86_64-w64-mingw32 \ + C:/Qt/Tools/mingw1310_64/lib/gcc/x86_64-w64-mingw32/13.1.0/include/c++/backward \ + C:/Qt/Tools/mingw1310_64/lib/gcc/x86_64-w64-mingw32/13.1.0/include \ + C:/Qt/Tools/mingw1310_64/lib/gcc/x86_64-w64-mingw32/13.1.0/include-fixed \ + C:/Qt/Tools/mingw1310_64/x86_64-w64-mingw32/include +QMAKE_CXX.LIBDIRS = \ + C:/Qt/Tools/mingw1310_64/lib/gcc/x86_64-w64-mingw32/13.1.0 \ + C:/Qt/Tools/mingw1310_64/lib/gcc \ + C:/Qt/Tools/mingw1310_64/x86_64-w64-mingw32/lib \ + C:/Qt/Tools/mingw1310_64/lib diff --git a/data.qrc b/data.qrc new file mode 100644 index 0000000..2f0a67e --- /dev/null +++ b/data.qrc @@ -0,0 +1,5 @@ + + + ex.txt + + diff --git a/ex.txt b/ex.txt new file mode 100644 index 0000000..563752a --- /dev/null +++ b/ex.txt @@ -0,0 +1,7 @@ +{ + "id": 1, + "texte": "tkt", + "latitude": "N 45 37.199", + "longitude": "W 1 2.009", + "valeur": -1 +} diff --git a/main.cpp b/main.cpp index 4b6acc2..d0f29f9 100644 --- a/main.cpp +++ b/main.cpp @@ -2,13 +2,22 @@ #include #include +#include +using namespace std; int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; - w.show(); + //w.show(); + QFile file(":/data/ex.txt"); + file.open(QIODevice::ReadOnly|QIODevice::Text); + QTextStream in(&file); + Step v(); + /* QString contenu = in.readAll(); + qDebug() << "Contenu lu depuis QTextStream:"; + qDebug().noquote() << contenu;*/ return a.exec(); } diff --git a/sae201.pro b/sae201.pro index 1e37e62..135504b 100644 --- a/sae201.pro +++ b/sae201.pro @@ -24,3 +24,7 @@ FORMS += \ qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target + +RESOURCES += \ + data.qrc + diff --git a/step.cpp b/step.cpp index 17f2edc..ce43ad1 100644 --- a/step.cpp +++ b/step.cpp @@ -1,26 +1,77 @@ #include "step.h" +#include +#include +#include +#include +#include +#include +#include +QString Step::getTitle() const +{ + return title; +} + +float Step::getLatitude() const +{ + return latitude; +} + +float Step::getLongitude() const +{ + return longitude; +} + +int Step::getResponse() const +{ + return response; +} + Step::Step() { latitude = 0.0; longitude = 0.0; response = 0; } -Step::Step(QTextStream &in) + +Step::Step( QJsonObject &in) { - int stepNumber; - in >> stepNumber; - in.readLine(); - title = in.readLine(); - QChar latDir, lonDir; - int latDeg, lonDeg; - float latMin, lonMin; - in >> latDir >> latDeg >> latMin >> lonDir >> lonDeg >> lonMin; + title = in["title"].toString(); + response = in["reponse"].toInt(); + QString gps = in["GPS"].toString(); + QStringList parts = gps.split(" ", Qt::SkipEmptyParts); + + QChar latDir = parts[0][0]; // c'est le premier QChar du QString t'as capté + int latDeg = parts[1].toInt(); + float latMin = parts[2].toFloat(); setLatitude(latDeg, latMin, latDir); + + QChar lonDir = parts[3][0]; + int lonDeg = parts[4].toInt(); + float lonMin = parts[5].toFloat(); setLongitude(lonDeg, lonMin, lonDir); - in >> response; - in.readLine(); + + QJsonArray personnagetab = in["dialogue"].toArray(); + for (const QJsonValue &val : personnagetab) { + if (val.isObject()) { + QJsonObject obj = val.toObject(); + QString personnage = obj["personnage"].toString(); + personnage.append(personnage); + } + } + QJsonArray textetab = in["dialogue"].toArray(); + for (const QJsonValue &val : textetab) { + if (val.isObject()) { + QJsonObject obj = val.toObject(); + QString textes = obj["texte"].toString(); + texte.append(textes); + } + } } + + + + void Step::setLatitude(int degree, float minute, QChar NS) { latitude = degree + minute / 60.0; diff --git a/step.h b/step.h index eb46bbc..8d93c46 100644 --- a/step.h +++ b/step.h @@ -2,6 +2,10 @@ #define STEP_H #include #include +#include +#include +#include +using namespace std; class Step { @@ -9,14 +13,19 @@ private: QString title; float latitude; float longitude; - QString text; int response; + QList personnage; + QList texte; public: Step(); - Step(QTextStream &in); + Step(QJsonObject &in); void setLatitude(int degree,float minute,QChar NS); void setLongitude(int degree,float minute,QChar EW); + QString getTitle() const; + float getLatitude() const; + float getLongitude() const; + int getResponse() const; }; #endif // STEP_H From ae0d443a137454f3b59e23f03b7b745f4c0aa64d Mon Sep 17 00:00:00 2001 From: p2405951 Date: Thu, 19 Jun 2025 10:02:20 +0200 Subject: [PATCH 2/3] modif constr json --- step.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/step.cpp b/step.cpp index ce43ad1..409b5d1 100644 --- a/step.cpp +++ b/step.cpp @@ -57,12 +57,6 @@ Step::Step( QJsonObject &in) QJsonObject obj = val.toObject(); QString personnage = obj["personnage"].toString(); personnage.append(personnage); - } - } - QJsonArray textetab = in["dialogue"].toArray(); - for (const QJsonValue &val : textetab) { - if (val.isObject()) { - QJsonObject obj = val.toObject(); QString textes = obj["texte"].toString(); texte.append(textes); } From 96321942f0bde5406d35053ffca7e8b0c29b7afc Mon Sep 17 00:00:00 2001 From: p2405951 Date: Thu, 19 Jun 2025 10:22:43 +0200 Subject: [PATCH 3/3] final constructeur (copie) step --- main.cpp | 8 -------- path.cpp | 9 ++++++++- path.h | 2 +- step.cpp | 6 ++++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/main.cpp b/main.cpp index cc22cfb..0c0a6eb 100644 --- a/main.cpp +++ b/main.cpp @@ -13,13 +13,5 @@ int main(int argc, char *argv[]) MainWindow w; //w.show(); - QFile file(":/data/ex.txt"); - file.open(QIODevice::ReadOnly|QIODevice::Text); - QTextStream in(&file); - Step v(); - /* QString contenu = in.readAll(); - qDebug() << "Contenu lu depuis QTextStream:"; - qDebug().noquote() << contenu;*/ - return a.exec(); } diff --git a/path.cpp b/path.cpp index 4f4fd97..64a2a09 100644 --- a/path.cpp +++ b/path.cpp @@ -41,4 +41,11 @@ Path::Path(QFile *file){ } -void Path::addStep(int indice){step.insert(indice, Step());} +void Path::addStep(int indice){ + if(indice==-1){ + step.append(Step()); + }else{ + step.insert(indice, Step()); + } + +} diff --git a/path.h b/path.h index b990bbb..f95f24b 100644 --- a/path.h +++ b/path.h @@ -20,7 +20,7 @@ private: public: Path(); Path(QFile *file); - void addStep(int indice=step.size()); + void addStep(int indice=-1); }; #endif // PATH_H diff --git a/step.cpp b/step.cpp index 409b5d1..861f414 100644 --- a/step.cpp +++ b/step.cpp @@ -55,12 +55,14 @@ Step::Step( QJsonObject &in) for (const QJsonValue &val : personnagetab) { if (val.isObject()) { QJsonObject obj = val.toObject(); - QString personnage = obj["personnage"].toString(); - personnage.append(personnage); + QString personnages = obj["personnage"].toString(); + personnage.append(personnages); QString textes = obj["texte"].toString(); texte.append(textes); } } + + }