modif export + automatisation + fonction qui centralise tout les exports
This commit is contained in:
+142
-32
@@ -6,11 +6,14 @@
|
||||
#include <QMessageBox>
|
||||
#include <fstream>
|
||||
|
||||
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()
|
||||
<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>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 20px;
|
||||
background-color: whitesmoke;
|
||||
}
|
||||
#container {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
}
|
||||
#map {
|
||||
height: 600px;
|
||||
width: 70%;
|
||||
border-radius:8%;
|
||||
width: 60%;
|
||||
border-radius: 5%;
|
||||
border: 1px solid #aaa;
|
||||
}
|
||||
#fiche {
|
||||
padding-right:20px;
|
||||
width: 40%;
|
||||
max-height: 600px;
|
||||
overflow-y: auto;
|
||||
border: 1px solid #aaa;
|
||||
padding: 10px;
|
||||
box-sizing: border-box;
|
||||
background-color:#095228;
|
||||
border-radius: 5%;
|
||||
}
|
||||
#fiche ul {
|
||||
padding-left: 20px;
|
||||
list-style-type: disc;
|
||||
overflow-wrap: break-word;
|
||||
word-wrap: break-word;
|
||||
word-break: break-word;
|
||||
white-space: normal;
|
||||
max-width: 90%;
|
||||
}
|
||||
|
||||
#fiche li {
|
||||
white-space: normal;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
body h1 {
|
||||
display:flex;
|
||||
align-items:center;
|
||||
justify-content:center;
|
||||
text-align: center;
|
||||
color: black;
|
||||
font-style: bold;
|
||||
margin-bottom: 20px;
|
||||
background-color:brown;
|
||||
border-radius:12px;
|
||||
height: 75px;
|
||||
}
|
||||
#fiche h2, #fiche h3, #fiche p, #fiche li {
|
||||
color: white;
|
||||
}
|
||||
#fiche img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
margin-top: 10px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Carte du parcours</h1>
|
||||
<div id="map"></div>
|
||||
<h1>Fiche du parcours</h1>
|
||||
<div id="container">
|
||||
<div id="map"></div>
|
||||
<div id="fiche">
|
||||
)";
|
||||
|
||||
if (currentPath) {
|
||||
Path* p = currentPath;
|
||||
file << "<h2>" << p->getName().toStdString() << "</h2>\n";
|
||||
file << "<p><strong>Ville :</strong> " << p->getCity().toStdString() << "</p>\n";
|
||||
file << "<p><strong>Département :</strong> " << p->getDepartement() << "</p>\n";
|
||||
file << "<p><strong>Difficulté :</strong> " << p->getDifficulty() << "</p>\n";
|
||||
file << "<p><strong>Durée (heures) :</strong> " << p->getDuration() << "</p>\n";
|
||||
file << "<p><strong>Longueur (km) :</strong> " << p->getLength() << "</p>\n";
|
||||
if (!p->getImage().isEmpty()) {
|
||||
file << "<img src=\"" << p->getImage().toStdString() << "\">\n";
|
||||
}
|
||||
int stepNum = 1;
|
||||
for (const Step& s : p->getStep()) {
|
||||
file << "<h3>Étape " << stepNum << "</h3>\n";
|
||||
const QList<QString> persos = s.getPersonnage();
|
||||
const QList<QString> textes = s.getTexte();
|
||||
|
||||
if (!persos.isEmpty()) {
|
||||
file << "<p><strong>Personnages :</strong></p>\n<ul>";
|
||||
for (const QString& pers : persos) {
|
||||
file << "<li>" << pers.toStdString() << "</li>\n";
|
||||
}
|
||||
file << "</ul>\n";
|
||||
}
|
||||
|
||||
if (!textes.isEmpty()) {
|
||||
file << "<p><strong>Dialogues :</strong></p>\n<ul>";
|
||||
for (const QString& txt : textes) {
|
||||
file << "<li>" << txt.toStdString() << "</li>\n";
|
||||
}
|
||||
file << "</ul>\n";
|
||||
}
|
||||
|
||||
stepNum++;
|
||||
}
|
||||
}
|
||||
|
||||
file << R"(
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||
<script>
|
||||
@@ -112,12 +209,6 @@ void MainWindow::exportHTMLMap()
|
||||
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();
|
||||
@@ -125,7 +216,6 @@ void MainWindow::exportHTMLMap()
|
||||
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) {
|
||||
@@ -133,11 +223,20 @@ void MainWindow::exportHTMLMap()
|
||||
}
|
||||
popupHtml += "</ul>";
|
||||
}
|
||||
if (!textes.isEmpty()) {
|
||||
popupHtml += "<b>Textes :</b><ul>";
|
||||
for (const QString& txt : textes) {
|
||||
popupHtml += "<li>" + txt + "</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();
|
||||
@@ -146,26 +245,27 @@ void MainWindow::exportHTMLMap()
|
||||
}
|
||||
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());
|
||||
var polyline = L.polyline(latlngs, {
|
||||
color: 'purple',
|
||||
weight: 2,
|
||||
dashArray: '10, 10',
|
||||
opacity: 0.7
|
||||
}).addTo(map);
|
||||
map.fitBounds(polyline.getBounds());
|
||||
)";
|
||||
}
|
||||
|
||||
file << R"(
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
)";
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user