From 105f1a6918ccb9ceeb35cbe3f57b81af31f6d5c2 Mon Sep 17 00:00:00 2001 From: p2405951 Date: Fri, 20 Jun 2025 16:08:32 +0200 Subject: [PATCH] modif export + automatisation + fonction qui centralise tout les exports --- data/parcours.html | 100 +++++++++++++++++++++++++ data/parcours1.json | 2 +- data/parcours2.json | 44 +++++++++++ index.html | 53 +++++++++++++ main.cpp | 32 +------- mainwindow.cpp | 174 +++++++++++++++++++++++++++++++++++-------- mainwindow.h | 8 +- pages/parcours1.html | 130 ++++++++++++++++++++++++++++++++ pages/parcours2.html | 130 ++++++++++++++++++++++++++++++++ parcours.html | 44 ----------- path.cpp | 4 +- sae201.pro | 2 + web.cpp | 23 +++--- 13 files changed, 624 insertions(+), 122 deletions(-) create mode 100644 data/parcours.html create mode 100644 data/parcours2.json create mode 100644 index.html create mode 100644 pages/parcours1.html create mode 100644 pages/parcours2.html delete mode 100644 parcours.html diff --git a/data/parcours.html b/data/parcours.html new file mode 100644 index 0000000..325521a --- /dev/null +++ b/data/parcours.html @@ -0,0 +1,100 @@ + + + + + Carte du parcours + + + + + +

Fiche du parcours

+
+
+
+

parcous1

+

Ville : Bourg en bresse

+

Département : 1

+

Difficulté : 2

+

Durée (heures) : 2.3

+

Longueur (km) : 17.3

+ + +
+
+ + + + + diff --git a/data/parcours1.json b/data/parcours1.json index bb5a755..f3bba0a 100644 --- a/data/parcours1.json +++ b/data/parcours1.json @@ -5,7 +5,7 @@ "difficulty": 2, "duration": 2.3, "length": 17.3, - "image": "data/parcours1.png", + "image": "../data/parcours1.png", "steps": [ { "numero": 1, diff --git a/data/parcours2.json b/data/parcours2.json new file mode 100644 index 0000000..08f7f8f --- /dev/null +++ b/data/parcours2.json @@ -0,0 +1,44 @@ +{ + "name": "parcours2", + "city": "Paris", + "departement": 1, + "difficulty": 2, + "duration": 2.3, + "length": 17.3, + "image": "../data/parcours1.png", + "steps": [ + { + "numero": 1, + "title": "Première étape", + "GPS": "N 45 37.199 W 1 2.009", + "reponse": -1, + "dialogue": [ + { + "personnage": "Quentin", + "texte": "ligne de dialogue 1 HJDDDZJJJJJJJJJJJJJJJJJJJDBJBDJZBZJDBJ" + }, + { + "personnage": "Malo", + "texte": "ligne de dialogue 2BDJJHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHBDHDBHBZHVZDHVHVHEDHJVHVDHEDJD" + } + ] + }, + { + "numero": 2, + "title": "Deuxième étape", + "GPS": "S 45 37.199 E 1 2.009", + "reponse": 4156, + "dialogue": [ + { + "personnage": "Antoine", + "texte": "ligne de dialogue 1" + }, + { + "personnage": "Giovanni", + "texte": "ligne de dialogue 2" + } + ] + } + ] + +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..5af9ae0 --- /dev/null +++ b/index.html @@ -0,0 +1,53 @@ + + + + + Liste des parcours + + + +

Liste des parcours

+ + + diff --git a/main.cpp b/main.cpp index 9d75f0f..31154c4 100644 --- a/main.cpp +++ b/main.cpp @@ -9,39 +9,9 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; - QFile file1("data/parcours1.json"); - if (!file1.open(QIODevice::ReadOnly)) { - qWarning() << "Impossible d'ouvrir le fichier data/parcours1.json"; - return -1; - } - Path* p = new Path(&file1); - file1.close(); - - QFile file2("data/parcours1.json"); - if (!file2.open(QIODevice::ReadOnly)) { - qWarning() << "Impossible d'ouvrir le fichier data/parcours2.json"; - delete p; - return -1; - } - Path* p2 = new Path(&file2); - file2.close(); - - QList paths = w.getPath(); - paths.append(p); - paths.append(p2); - w.setPath(paths); - - w.setCurrentPath(p); - w.exportHTMLMap(); - - w.setCurrentPath(p2); - w.exportHTMLMap(); - + w.loadAndExportPaths(); Web u(w.getPath()); u.siteHtml(); - delete p; - delete p2; - return a.exec(); } diff --git a/mainwindow.cpp b/mainwindow.cpp index eb79c08..e95726d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -6,11 +6,14 @@ #include #include +int MainWindow::indexPath = 0; + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); + indexPath++; } MainWindow::~MainWindow() @@ -22,16 +25,11 @@ MainWindow::~MainWindow() delete p; } } - void MainWindow::updatePathView() -{ - -} +{} void MainWindow::updateStepView(size_t num) -{ - -} +{} void MainWindow::onTextChanged() { @@ -65,17 +63,16 @@ void MainWindow::loadPath() void MainWindow::addNewPath() { - + path.append(currentPath); } void MainWindow::addNewStep() { - } - -void MainWindow::exportHTMLMap() +void MainWindow::exportHTMLMap(int index) { - std::ofstream file("parcours.html"); + std::ofstream file("./pages/parcours" + std::to_string(index) + ".html"); + if (!file.is_open()) { QMessageBox::warning(this, "Erreur", "Impossible d'ouvrir le fichier."); return; @@ -89,16 +86,116 @@ void MainWindow::exportHTMLMap() -

Carte du parcours

-
+

Fiche du parcours

+
+
+
+)"; + + if (currentPath) { + Path* p = currentPath; + file << "

" << p->getName().toStdString() << "

\n"; + file << "

Ville : " << p->getCity().toStdString() << "

\n"; + file << "

Département : " << p->getDepartement() << "

\n"; + file << "

Difficulté : " << p->getDifficulty() << "

\n"; + file << "

Durée (heures) : " << p->getDuration() << "

\n"; + file << "

Longueur (km) : " << p->getLength() << "

\n"; + if (!p->getImage().isEmpty()) { + file << "getImage().toStdString() << "\">\n"; + } + int stepNum = 1; + for (const Step& s : p->getStep()) { + file << "

Étape " << stepNum << "

\n"; + const QList persos = s.getPersonnage(); + const QList textes = s.getTexte(); + + if (!persos.isEmpty()) { + file << "

Personnages :

\n
    "; + for (const QString& pers : persos) { + file << "
  • " << pers.toStdString() << "
  • \n"; + } + file << "
\n"; + } + + if (!textes.isEmpty()) { + file << "

Dialogues :

\n
    "; + for (const QString& txt : textes) { + file << "
  • " << txt.toStdString() << "
  • \n"; + } + file << "
\n"; + } + + stepNum++; + } + } + + file << R"( +
+
)"; file.close(); - } + + void MainWindow::loadImage(QString fileName) { QString ext[] = {"png", "jpeg", "jpg"}; @@ -220,6 +320,16 @@ void MainWindow::on_toolButton_clicked() loadImage(fileName); } +int MainWindow::getIndexPath() const +{ + return indexPath; +} + +void MainWindow::setIndexPath(int newIndexPath) +{ + indexPath = newIndexPath; +} + QString MainWindow::getCurrentFile() const { return currentFile; diff --git a/mainwindow.h b/mainwindow.h index 9068a75..abe0783 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -24,8 +24,8 @@ public: void loadPath(); void addNewPath(); void addNewStep(); - void exportHTMLMap(); - + void exportHTMLMap(int index); + void loadAndExportPaths(); QString getCurrentFile() const; void setCurrentFile(const QString &newCurrentFile); QList getPath() const; @@ -33,6 +33,9 @@ public: Path *getCurrentPath() const; void setCurrentPath(Path *newCurrentPath); + int getIndexPath() const; + void setIndexPath(int newIndexPath); + private slots: void on_pushButton_clicked(); @@ -43,6 +46,7 @@ private slots: private: Ui::MainWindow *ui; QString currentFile; + static int indexPath; bool textChanged; QList path; Path* currentPath; diff --git a/pages/parcours1.html b/pages/parcours1.html new file mode 100644 index 0000000..dc728a4 --- /dev/null +++ b/pages/parcours1.html @@ -0,0 +1,130 @@ + + + + + Carte du parcours + + + + + +

Fiche du parcours

+
+
+
+

parcous1

+

Ville : Bourg en bresse

+

Département : 1

+

Difficulté : 2

+

Durée (heures) : 2.3

+

Longueur (km) : 17.3

+ +

Étape 1

+

Personnages :

+
  • Quentin
  • +
  • Malo
  • +
+

Dialogues :

+
  • ligne de dialogue 1
  • +
  • ligne de dialogue 2
  • +
+

Étape 2

+

Personnages :

+
  • Antoine
  • +
  • Giovanni
  • +
+

Dialogues :

+
  • ligne de dialogue 1
  • +
  • ligne de dialogue 2
  • +
+ +
+
+ + + + + diff --git a/pages/parcours2.html b/pages/parcours2.html new file mode 100644 index 0000000..fcc03ee --- /dev/null +++ b/pages/parcours2.html @@ -0,0 +1,130 @@ + + + + + Carte du parcours + + + + + +

Fiche du parcours

+
+
+
+

parcours2

+

Ville : Paris

+

Département : 1

+

Difficulté : 2

+

Durée (heures) : 2.3

+

Longueur (km) : 17.3

+ +

Étape 1

+

Personnages :

+
  • Quentin
  • +
  • Malo
  • +
+

Dialogues :

+
  • ligne de dialogue 1 HJDDDZJJJJJJJJJJJJJJJJJJJDBJBDJZBZJDBJ
  • +
  • ligne de dialogue 2BDJJHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHBDHDBHBZHVZDHVHVHEDHJVHVDHEDJD
  • +
+

Étape 2

+

Personnages :

+
  • Antoine
  • +
  • Giovanni
  • +
+

Dialogues :

+
  • ligne de dialogue 1
  • +
  • ligne de dialogue 2
  • +
+ +
+
+ + + + + diff --git a/parcours.html b/parcours.html deleted file mode 100644 index ed92a87..0000000 --- a/parcours.html +++ /dev/null @@ -1,44 +0,0 @@ - - - - - Carte du parcours - - - - - -

Carte du parcours

-
- - - - - diff --git a/path.cpp b/path.cpp index 6eee8cd..26a2558 100644 --- a/path.cpp +++ b/path.cpp @@ -51,10 +51,10 @@ QList Path::getStep() const } Path::Path(QFile *file){ - /*if (!file->open(QIODevice::ReadOnly)) { + if (!file->open(QIODevice::ReadOnly)) { qWarning() << "Could not open file:" << file->errorString(); return; - }*/ + } QByteArray data = file->readAll(); file->close(); QJsonDocument doc = QJsonDocument::fromJson(data); diff --git a/sae201.pro b/sae201.pro index 8cb9d3f..e43f61e 100644 --- a/sae201.pro +++ b/sae201.pro @@ -13,11 +13,13 @@ SOURCES += \ mainwindow.cpp \ step.cpp \ path.cpp \ + web.cpp HEADERS += \ mainwindow.h \ step.h \ path.h \ + web.h FORMS += \ mainwindow.ui diff --git a/web.cpp b/web.cpp index 488786f..f59a9a0 100644 --- a/web.cpp +++ b/web.cpp @@ -21,15 +21,15 @@ void Web::siteHtml() Liste des parcours