Extract loadPath function

This commit is contained in:
T'JAMPENS QUENTIN p2406187 2025-06-19 10:41:10 +02:00
parent 29054c76a2
commit e3f79d95b7
2 changed files with 23 additions and 24 deletions

View File

@ -37,9 +37,29 @@ void MainWindow::onTextChanged()
textChanged = true; textChanged = true;
} }
void MainWindow::loadPath(QTextStream &in) void MainWindow::loadPath()
{ {
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", "Fichier non valide" + file.errorString());
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::addNewPath() void MainWindow::addNewPath()
@ -101,28 +121,7 @@ void MainWindow::on_pushButton_clicked()
void MainWindow::on_actionOpen_triggered() void MainWindow::on_actionOpen_triggered()
{ {
this->loadPath();
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", "Fichier non valide" + file.errorString());
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() void MainWindow::on_toolButton_clicked()

View File

@ -21,7 +21,7 @@ public:
void updatePathView(); void updatePathView();
void updateStepView(size_t num); void updateStepView(size_t num);
void onTextChanged(); void onTextChanged();
void loadPath(QTextStream &in); void loadPath();
void addNewPath(); void addNewPath();
void addNewStep(); void addNewStep();
void exportHTMLMap(); void exportHTMLMap();