ajout export html
This commit is contained in:
parent
730d0850f3
commit
213f8e1217
3
data.qrc
3
data.qrc
@ -20,4 +20,7 @@
|
||||
<file>data/images/underline.png</file>
|
||||
<file>data/images/add.png</file>
|
||||
</qresource>
|
||||
<qresource prefix="/data/filejson">
|
||||
<file>data/parcours1.json</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
16
main.cpp
16
main.cpp
@ -1,7 +1,5 @@
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include "path.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <step.h>
|
||||
#include <QFile>
|
||||
@ -11,7 +9,19 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
QFile file("data/parcours1.json");
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qWarning() << "Impossible d'ouvrir le fichier data/parcours1.json";
|
||||
return -1;
|
||||
}
|
||||
Path* p = new Path(&file);
|
||||
file.close();
|
||||
QList<Path*> paths = w.getPath();
|
||||
paths.append(p);
|
||||
w.setPath(paths);
|
||||
w.setCurrentPath(p);
|
||||
w.exportHTMLMap();
|
||||
//w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
119
mainwindow.cpp
119
mainwindow.cpp
@ -4,6 +4,7 @@
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <fstream>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
@ -74,6 +75,94 @@ void MainWindow::addNewStep()
|
||||
|
||||
void MainWindow::exportHTMLMap()
|
||||
{
|
||||
std::ofstream file("parcours.html");
|
||||
if (!file.is_open()) {
|
||||
QMessageBox::warning(this, "Erreur", "Impossible d'ouvrir le fichier.");
|
||||
return;
|
||||
}
|
||||
|
||||
file << R"(<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Carte du parcours</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
|
||||
<style>
|
||||
#map {
|
||||
height: 600px;
|
||||
width: 70%;
|
||||
border-radius:8%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Carte du parcours</h1>
|
||||
<div id="map"></div>
|
||||
|
||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||
<script>
|
||||
var map = L.map('map').setView([45.5, 1.5], 10); // Vue centrée
|
||||
|
||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
attribution: '© OpenStreetMap contributors'
|
||||
}).addTo(map);
|
||||
)";
|
||||
|
||||
if (!path.isEmpty() && path[0]) {
|
||||
Path* p = path[0];
|
||||
int stepNum = 1;
|
||||
// c un test
|
||||
// qDebug() << "Nombre d'étapes dans le path :" << p->getStep().size();
|
||||
for (const Step& s : p->getStep()) {
|
||||
qDebug() << s.getTitle() << s.getLatitude() << s.getLongitude();
|
||||
}
|
||||
|
||||
|
||||
for (const Step& s : p->getStep()) {
|
||||
float lat = s.getLatitude();
|
||||
float lon = s.getLongitude();
|
||||
QList<QString> personnages = s.getPersonnage();
|
||||
QList<QString> textes = s.getTexte();
|
||||
QString popupHtml = "<b>Étape " + QString::number(stepNum) + "</b><br>";
|
||||
// ajout des perso
|
||||
if (!personnages.isEmpty()) {
|
||||
popupHtml += "<b>Personnages :</b><ul>";
|
||||
for (const QString& pers : personnages) {
|
||||
popupHtml += "<li>" + pers + "</li>";
|
||||
}
|
||||
popupHtml += "</ul>";
|
||||
}
|
||||
file << "L.marker([" << lat << ", " << lon << "]).addTo(map)"
|
||||
<< ".bindPopup(\"" << popupHtml.toStdString() << "\");\n";
|
||||
|
||||
++stepNum;
|
||||
}
|
||||
file << "var latlngs = [\n";
|
||||
for (const Step& s : p->getStep()) {
|
||||
float lat = s.getLatitude();
|
||||
float lon = s.getLongitude();
|
||||
file << " [" << lat << ", " << lon << "],\n";
|
||||
}
|
||||
file << "];\n";
|
||||
|
||||
// Ajouter la polyline en pointillés
|
||||
file << R"(
|
||||
var polyline = L.polyline(latlngs, {
|
||||
color: 'purple',
|
||||
weight: 2,
|
||||
dashArray: '10, 10', // ligne en pointillés
|
||||
opacity: 0.7
|
||||
}).addTo(map);
|
||||
map.fitBounds(polyline.getBounds());
|
||||
)";
|
||||
}
|
||||
file << R"(
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
)";
|
||||
file.close();
|
||||
|
||||
}
|
||||
|
||||
@ -131,3 +220,33 @@ void MainWindow::on_toolButton_clicked()
|
||||
loadImage(fileName);
|
||||
}
|
||||
|
||||
QString MainWindow::getCurrentFile() const
|
||||
{
|
||||
return currentFile;
|
||||
}
|
||||
|
||||
void MainWindow::setCurrentFile(const QString &newCurrentFile)
|
||||
{
|
||||
currentFile = newCurrentFile;
|
||||
}
|
||||
|
||||
QList<Path *> MainWindow::getPath() const
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
void MainWindow::setPath(const QList<Path *> &newPath)
|
||||
{
|
||||
path = newPath;
|
||||
}
|
||||
|
||||
Path *MainWindow::getCurrentPath() const
|
||||
{
|
||||
return currentPath;
|
||||
}
|
||||
|
||||
void MainWindow::setCurrentPath(Path *newCurrentPath)
|
||||
{
|
||||
currentPath = newCurrentPath;
|
||||
}
|
||||
|
||||
|
||||
@ -26,6 +26,13 @@ public:
|
||||
void addNewStep();
|
||||
void exportHTMLMap();
|
||||
|
||||
QString getCurrentFile() const;
|
||||
void setCurrentFile(const QString &newCurrentFile);
|
||||
QList<Path *> getPath() const;
|
||||
void setPath(const QList<Path *> &newPath);
|
||||
Path *getCurrentPath() const;
|
||||
void setCurrentPath(Path *newCurrentPath);
|
||||
|
||||
private slots:
|
||||
void on_pushButton_clicked();
|
||||
|
||||
|
||||
44
parcours.html
Normal file
44
parcours.html
Normal file
@ -0,0 +1,44 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Carte du parcours</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
|
||||
<style>
|
||||
#map {
|
||||
height: 600px;
|
||||
width: 70%;
|
||||
border-radius:8%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Carte du parcours</h1>
|
||||
<div id="map"></div>
|
||||
|
||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||
<script>
|
||||
var map = L.map('map').setView([45.5, 1.5], 10); // Vue centrée
|
||||
|
||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
attribution: '© OpenStreetMap contributors'
|
||||
}).addTo(map);
|
||||
L.marker([45.62, -1.03348]).addTo(map).bindPopup("<b>Étape 1</b><br><b>Personnages :</b><ul><li>Quentin</li><li>Malo</li></ul>");
|
||||
L.marker([-45.62, 1.03348]).addTo(map).bindPopup("<b>Étape 2</b><br><b>Personnages :</b><ul><li>Antoine</li><li>Giovanni</li></ul>");
|
||||
var latlngs = [
|
||||
[45.62, -1.03348],
|
||||
[-45.62, 1.03348],
|
||||
];
|
||||
|
||||
var polyline = L.polyline(latlngs, {
|
||||
color: 'purple',
|
||||
weight: 2,
|
||||
dashArray: '10, 10', // ligne en pointillés
|
||||
opacity: 0.7
|
||||
}).addTo(map);
|
||||
map.fitBounds(polyline.getBounds());
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
6
path.cpp
6
path.cpp
@ -51,10 +51,10 @@ QList<Step> 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);
|
||||
@ -75,7 +75,7 @@ Path::Path(QFile *file){
|
||||
QJsonArray stepsArray = json["steps"].toArray();
|
||||
for (const QJsonValue &stepValue : stepsArray) {
|
||||
QJsonObject stepObj = stepValue.toObject();
|
||||
//step.append(Step(stepObj));
|
||||
step.append(Step(stepObj));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
30
step.cpp
30
step.cpp
@ -27,6 +27,36 @@ int Step::getResponse() const
|
||||
return response;
|
||||
}
|
||||
|
||||
QList<QString> Step::getPersonnage() const
|
||||
{
|
||||
return personnage;
|
||||
}
|
||||
|
||||
QList<QString> Step::getTexte() const
|
||||
{
|
||||
return texte;
|
||||
}
|
||||
|
||||
void Step::setTitle(const QString &newTitle)
|
||||
{
|
||||
title = newTitle;
|
||||
}
|
||||
|
||||
void Step::setResponse(int newResponse)
|
||||
{
|
||||
response = newResponse;
|
||||
}
|
||||
|
||||
void Step::setPersonnage(const QList<QString> &newPersonnage)
|
||||
{
|
||||
personnage = newPersonnage;
|
||||
}
|
||||
|
||||
void Step::setTexte(const QList<QString> &newTexte)
|
||||
{
|
||||
texte = newTexte;
|
||||
}
|
||||
|
||||
Step::Step() {
|
||||
latitude = 0.0;
|
||||
longitude = 0.0;
|
||||
|
||||
6
step.h
6
step.h
@ -26,6 +26,12 @@ public:
|
||||
float getLatitude() const;
|
||||
float getLongitude() const;
|
||||
int getResponse() const;
|
||||
QList<QString> getPersonnage() const;
|
||||
QList<QString> getTexte() const;
|
||||
void setTitle(const QString &newTitle);
|
||||
void setResponse(int newResponse);
|
||||
void setPersonnage(const QList<QString> &newPersonnage);
|
||||
void setTexte(const QList<QString> &newTexte);
|
||||
};
|
||||
|
||||
#endif // STEP_H
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user