Merge branch 'feature/openFile' into 'main'

Feature/open file

See merge request p2406187/sae201!8
This commit is contained in:
T'JAMPENS QUENTIN p2406187 2025-06-19 08:26:57 +00:00
commit 29054c76a2
5 changed files with 94 additions and 10 deletions

View File

@ -1,5 +1,6 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "path.h"
#include <QFileDialog>
#include <QMessageBox>
@ -56,13 +57,10 @@ void MainWindow::exportHTMLMap()
}
void MainWindow::on_pushButton_clicked()
{
void MainWindow::loadImage(QString fileName) {
QString ext[] = {"png", "jpeg", "jpg"};
QString fileName = QFileDialog::getOpenFileName(this, "Open the file");
if (fileName.isEmpty()) return;
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QFile::Text)) {
QMessageBox::warning(this, "Warning", "Cannot open file: " +
@ -91,7 +89,13 @@ void MainWindow::on_pushButton_clicked()
file.close();
}
void MainWindow::on_pushButton_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, "Open the file");
if (fileName.isEmpty()) return;
this->loadImage(fileName);
}
@ -106,6 +110,25 @@ void MainWindow::on_actionOpen_triggered()
return;
}
file.close();
Path* p = new Path(&file);
currentPath = p;
path.append(p);
ui->titleEdit->setText(p->getName());
ui->locEdit->setText(p->getCity());
ui->diffSpin->setValue(p->getDifficulty());
ui->lengthSpin->setValue(p->getLength());
ui->durationSpin->setValue(p->getDuration());
ui->imagePath->setText(p->getImage());
loadImage(p->getImage());
}
void MainWindow::on_toolButton_clicked()
{
QString fileName = ui->imagePath->text();
if(fileName.isEmpty()) return;
loadImage(fileName);
}

View File

@ -31,11 +31,14 @@ private slots:
void on_actionOpen_triggered();
void on_toolButton_clicked();
private:
Ui::MainWindow *ui;
QString currentFile;
bool textChanged;
QList<Path*> path;
Path* currentPath;
void loadImage(QString fileName);
};
#endif // MAINWINDOW_H

View File

@ -67,7 +67,7 @@
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit">
<widget class="QLineEdit" name="titleEdit">
<property name="geometry">
<rect>
<x>60</x>
@ -101,7 +101,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_2"/>
<widget class="QLineEdit" name="locEdit"/>
</item>
<item>
<widget class="QSpinBox" name="spinBox_2"/>
@ -148,7 +148,7 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_3">
<widget class="QSpinBox" name="diffSpin">
<property name="suffix">
<string>/5</string>
</property>
@ -171,7 +171,7 @@
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBox">
<widget class="QDoubleSpinBox" name="durationSpin">
<property name="suffix">
<string>h</string>
</property>
@ -197,7 +197,7 @@
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBox_2">
<widget class="QDoubleSpinBox" name="lengthSpin">
<property name="suffix">
<string>Km</string>
</property>
@ -243,6 +243,16 @@
<item>
<widget class="QLineEdit" name="imagePath"/>
</item>
<item>
<widget class="QToolButton" name="toolButton">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset theme="QIcon::ThemeIcon::ListAdd"/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">

View File

@ -10,6 +10,46 @@
QString Path::getCity() const
{
return city;
}
int Path::getDepartement() const
{
return departement;
}
QString Path::getName() const
{
return name;
}
unsigned int Path::getDifficulty() const
{
return difficulty;
}
float Path::getDuration() const
{
return duration;
}
float Path::getLength() const
{
return length;
}
QString Path::getImage() const
{
return image;
}
QList<Step> Path::getStep() const
{
return step;
}
Path::Path(QFile *file){
if (!file->open(QIODevice::ReadOnly)) {
qWarning() << "Could not open file:" << file->errorString();
@ -35,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));
}
}

8
path.h
View File

@ -21,6 +21,14 @@ public:
Path();
Path(QFile *file);
void addStep(int indice=-1);
QString getCity() const;
int getDepartement() const;
QString getName() const;
unsigned int getDifficulty() const;
float getDuration() const;
float getLength() const;
QString getImage() const;
QList<Step> getStep() const;
};
#endif // PATH_H