Merge branch 'main' into 'feature/validateBtn'

# Conflicts:
#   mainwindow.h
#   mainwindow.ui
#   path.cpp
This commit is contained in:
T'JAMPENS QUENTIN p2406187 2025-06-20 14:24:44 +00:00
commit 3e9e248f04
6 changed files with 125 additions and 48 deletions

0
data/images/d.json Normal file
View File

View File

@ -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();

View File

@ -28,6 +28,7 @@ public:
void addNewPath();
void addNewStep();
void exportHTMLMap();
void saveFile();
private slots:
void on_pushButton_clicked();
@ -36,6 +37,8 @@ private slots:
void on_toolButton_clicked();
void on_actionSave_triggered();
void on_actionopenFile_triggered();
void on_actionEditCopy_triggered();

View File

@ -62,9 +62,6 @@
<property name="text">
<string>Path information</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
</property>
</widget>
</item>
<item>
@ -82,10 +79,7 @@
</size>
</property>
<property name="frameShape">
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Shadow::Raised</enum>
<enum>QFrame::NoFrame</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
@ -322,9 +316,6 @@
<property name="text">
<string>Step information</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
</property>
</widget>
</item>
<item>
@ -342,10 +333,7 @@
</size>
</property>
<property name="frameShape">
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Shadow::Raised</enum>
<enum>QFrame::NoFrame</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
@ -492,7 +480,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>23</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -561,7 +549,7 @@
<string>New File</string>
</property>
<property name="menuRole">
<enum>QAction::MenuRole::NoRole</enum>
<enum>QAction::NoRole</enum>
</property>
</action>
<action name="actionSaveFile">
@ -573,7 +561,7 @@
<string>Save</string>
</property>
<property name="menuRole">
<enum>QAction::MenuRole::NoRole</enum>
<enum>QAction::NoRole</enum>
</property>
</action>
<action name="actionSaveAsFile">
@ -585,7 +573,7 @@
<string>Save as</string>
</property>
<property name="menuRole">
<enum>QAction::MenuRole::NoRole</enum>
<enum>QAction::NoRole</enum>
</property>
</action>
<action name="actionPrintFile">
@ -597,7 +585,7 @@
<string>Print</string>
</property>
<property name="menuRole">
<enum>QAction::MenuRole::NoRole</enum>
<enum>QAction::NoRole</enum>
</property>
</action>
<action name="actionEditCopy">
@ -609,7 +597,7 @@
<string>Copy</string>
</property>
<property name="menuRole">
<enum>QAction::MenuRole::NoRole</enum>
<enum>QAction::NoRole</enum>
</property>
</action>
<action name="actionEditPaste">
@ -621,7 +609,7 @@
<string>Paste</string>
</property>
<property name="menuRole">
<enum>QAction::MenuRole::NoRole</enum>
<enum>QAction::NoRole</enum>
</property>
</action>
<action name="actionEditCut">
@ -633,7 +621,7 @@
<string>Cut</string>
</property>
<property name="menuRole">
<enum>QAction::MenuRole::NoRole</enum>
<enum>QAction::NoRole</enum>
</property>
</action>
<action name="actionEditUndo">
@ -645,7 +633,7 @@
<string>Undo</string>
</property>
<property name="menuRole">
<enum>QAction::MenuRole::NoRole</enum>
<enum>QAction::NoRole</enum>
</property>
</action>
<action name="actionEditRedo">
@ -657,7 +645,7 @@
<string>Redo</string>
</property>
<property name="menuRole">
<enum>QAction::MenuRole::NoRole</enum>
<enum>QAction::NoRole</enum>
</property>
</action>
<action name="actionopenFile">
@ -669,7 +657,7 @@
<string>Open file</string>
</property>
<property name="menuRole">
<enum>QAction::MenuRole::NoRole</enum>
<enum>QAction::NoRole</enum>
</property>
</action>
</widget>

View File

@ -100,3 +100,25 @@ void Step::setLongitude(int degree, float minute, QChar EW)
if (EW.toUpper() == 'W')
longitude = -longitude;
}
QString Step::toGPSFormat(){
int latDeg = static_cast<int>(latitude);
float latMin = (latitude - latDeg) * 60.0;
QChar latDir = latitude >= 0 ? 'N' : 'S';
latDeg = abs(latDeg);
int lonDeg = static_cast<int>(longitude);
float lonMin = (longitude - lonDeg) * 60.0;
QChar lonDir = longitude >= 0 ? 'E' : 'W';
lonDeg = abs(lonDeg);
QString gpsString = QString("%1 %2 %3 %4 %5 %6")
.arg(latDir)
.arg(latDeg, 2)
.arg(latMin, 5, 'f', 3)
.arg(lonDir)
.arg(lonDeg, 2)
.arg(lonMin, 5, 'f', 3);
return gpsString;
}

1
step.h
View File

@ -26,6 +26,7 @@ public:
float getLatitude() const;
float getLongitude() const;
int getResponse() const;
QString toGPSFormat();
QList<QString> getPersonnage() const;
QList<QString> getTexte() const;
void setTitle(const QString &newTitle);