classe web+ test main
This commit is contained in:
parent
213f8e1217
commit
0ca9c535c5
32
main.cpp
32
main.cpp
@ -3,25 +3,45 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <step.h>
|
#include <step.h>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <web.h>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
QFile file("data/parcours1.json");
|
QFile file1("data/parcours1.json");
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
if (!file1.open(QIODevice::ReadOnly)) {
|
||||||
qWarning() << "Impossible d'ouvrir le fichier data/parcours1.json";
|
qWarning() << "Impossible d'ouvrir le fichier data/parcours1.json";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
Path* p = new Path(&file);
|
Path* p = new Path(&file1);
|
||||||
file.close();
|
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<Path*> paths = w.getPath();
|
QList<Path*> paths = w.getPath();
|
||||||
paths.append(p);
|
paths.append(p);
|
||||||
|
paths.append(p2);
|
||||||
w.setPath(paths);
|
w.setPath(paths);
|
||||||
|
|
||||||
w.setCurrentPath(p);
|
w.setCurrentPath(p);
|
||||||
w.exportHTMLMap();
|
w.exportHTMLMap();
|
||||||
//w.show();
|
|
||||||
|
w.setCurrentPath(p2);
|
||||||
|
w.exportHTMLMap();
|
||||||
|
|
||||||
|
Web u(w.getPath());
|
||||||
|
u.siteHtml();
|
||||||
|
|
||||||
|
delete p;
|
||||||
|
delete p2;
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
82
web.cpp
Normal file
82
web.cpp
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
#include "web.h"
|
||||||
|
#include <fstream>
|
||||||
|
Web::Web()
|
||||||
|
{}
|
||||||
|
|
||||||
|
Web::Web(const QList<Path*>& list) : list(list)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void Web::siteHtml()
|
||||||
|
{
|
||||||
|
std::ofstream file("index.html");
|
||||||
|
if (!file.is_open()) {
|
||||||
|
qWarning("Impossible d'ouvrir le fichier index.html");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
file << R"(<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>Liste des parcours</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
margin: 40px;
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
text-align: center;
|
||||||
|
color: purple;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
ul {
|
||||||
|
max-width: 600px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 0;
|
||||||
|
list-style-type: none;
|
||||||
|
}
|
||||||
|
li {
|
||||||
|
background: white;
|
||||||
|
margin: 10px 0;
|
||||||
|
padding: 15px;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 0 6px rgba(0,0,0,0.1);
|
||||||
|
transition: background-color 0.3s ease;
|
||||||
|
}
|
||||||
|
/*li:hover {
|
||||||
|
background-color: red;
|
||||||
|
}*/
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: purple;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 1.2em;
|
||||||
|
}
|
||||||
|
a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Liste des parcours</h1>
|
||||||
|
<ul>
|
||||||
|
)";
|
||||||
|
|
||||||
|
int index = 1;
|
||||||
|
for (const Path* p : list) {
|
||||||
|
QString fileName = QString("parcours%1.html").arg(index);
|
||||||
|
QString name = p->getName();
|
||||||
|
file << " <li><a href=\"" << fileName.toStdString() << "\">"
|
||||||
|
<< name.toStdString() << "</a></li>\n";
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
|
||||||
|
file << R"( </ul>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
)";
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user