Merge branch 'main' into 'feature/validateBtn'
# Conflicts: # mainwindow.h # mainwindow.ui # path.cpp
This commit is contained in:
+86
-23
@@ -8,6 +8,13 @@
|
||||
#include <QLineEdit>
|
||||
#include <QTimer>
|
||||
|
||||
|
||||
#include <QFile>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
@@ -15,7 +22,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
, Clipboard(QGuiApplication::clipboard())
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
currentPath = new Path();
|
||||
|
||||
connect(ui->titleEdit, &QLineEdit::editingFinished, this, [this]() {
|
||||
static QString previousText;
|
||||
@@ -88,6 +95,7 @@ void MainWindow::loadNewPath()
|
||||
currentPath = p;
|
||||
path.append(p);
|
||||
loadPath(p);
|
||||
currentFile = fileName;
|
||||
|
||||
int pathCount = path.length();
|
||||
ui->pathNumber->setMaximum(pathCount);
|
||||
@@ -106,8 +114,10 @@ void MainWindow::loadPath(Path* p) {
|
||||
ui->lengthSpin->setValue(p->getLength());
|
||||
ui->durationSpin->setValue(p->getDuration());
|
||||
ui->imagePath->setText(p->getImage());
|
||||
ui->depSpin->setValue(p->getDepartement());
|
||||
loadImage(p->getImage());
|
||||
|
||||
|
||||
ui->dialogEdit->clear();
|
||||
|
||||
if(!steps.isEmpty()) {
|
||||
@@ -155,36 +165,35 @@ void MainWindow::exportHTMLMap()
|
||||
}
|
||||
|
||||
void MainWindow::loadImage(QString fileName) {
|
||||
|
||||
QString ext[] = {"png", "jpeg", "jpg"};
|
||||
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::ReadOnly | QFile::Text)) {
|
||||
QMessageBox::warning(this, "Warning", "Cannot open file: " +
|
||||
QMessageBox::warning(this, "Warning", "Cannot open image: " +
|
||||
file.errorString());
|
||||
return;
|
||||
}
|
||||
QString text = file.fileName();
|
||||
|
||||
bool acceptedExt = false;
|
||||
for(QString e : ext) {
|
||||
if(text.endsWith(e)) acceptedExt = true;
|
||||
}else{
|
||||
QString text = file.fileName();
|
||||
bool acceptedExt = false;
|
||||
for(QString e : ext) {
|
||||
if(text.endsWith(e)) acceptedExt = true;
|
||||
}
|
||||
if(!acceptedExt) {
|
||||
QMessageBox::warning(this, "Warning", "Format de fichier incorrect");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ui->imagePath->setText(text);
|
||||
|
||||
|
||||
QPixmap px(fileName);
|
||||
|
||||
ui->imageLbl->setPixmap(px);
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
if(!acceptedExt) {
|
||||
QMessageBox::warning(this, "Warning", "Format de fichier incorrect");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ui->imagePath->setText(text);
|
||||
|
||||
|
||||
QPixmap px(fileName);
|
||||
|
||||
ui->imageLbl->setPixmap(px);
|
||||
|
||||
file.close();
|
||||
|
||||
}
|
||||
|
||||
@@ -209,6 +218,60 @@ void MainWindow::on_toolButton_clicked()
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::saveFile(){
|
||||
QString fileName;
|
||||
if (currentFile.isEmpty()) {
|
||||
fileName = QFileDialog::getSaveFileName(this, "Save");
|
||||
currentFile = fileName;
|
||||
} else {
|
||||
fileName = currentFile;
|
||||
}
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::WriteOnly | QFile::Text)) {
|
||||
QMessageBox::warning(this, "Warning", "Cannot save file: " + file.errorString());
|
||||
return;
|
||||
}
|
||||
setWindowTitle(fileName);
|
||||
QJsonObject json;
|
||||
json["name"] = ui->titleEdit->text();
|
||||
json["city"] =ui->locEdit->text();
|
||||
json["departement"] = ui->depSpin->text();
|
||||
json["difficulty"] = ui->diffSpin->value();
|
||||
json["duration"] = ui->durationSpin->value();
|
||||
json["length"] = ui->lengthSpin->value();
|
||||
json["image"] = ui->imagePath->text();
|
||||
|
||||
QJsonArray steps;
|
||||
int cpt=0;
|
||||
for(Step step: currentPath->getStep()){
|
||||
cpt++;
|
||||
QJsonObject stepObject;
|
||||
stepObject["numero"] = cpt;
|
||||
stepObject["title"] = step.getTitle();
|
||||
stepObject["GPS"] = step.toGPSFormat();
|
||||
stepObject["reponse"] = step.getResponse();
|
||||
QJsonArray dialogues;
|
||||
for(int i=0; i<step.getTexte().size(); i++){
|
||||
QJsonObject dialogueObject;
|
||||
dialogueObject["personnage"] = step.getPersonnage()[i];
|
||||
dialogueObject["texte"] = step.getTexte()[i];
|
||||
dialogues.append(dialogueObject);
|
||||
}
|
||||
stepObject["dialogue"] = dialogues;
|
||||
steps.append(stepObject);
|
||||
}
|
||||
json["steps"] = steps;
|
||||
QJsonDocument doc(json);
|
||||
file.write(doc.toJson());
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionSave_triggered()
|
||||
{
|
||||
this->saveFile();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionopenFile_triggered()
|
||||
{
|
||||
this->loadNewPath();
|
||||
|
||||
Reference in New Issue
Block a user