diff --git a/mainwindow.cpp b/mainwindow.cpp index 837a7b4..bee0fdd 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -37,9 +37,29 @@ void MainWindow::onTextChanged() 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() @@ -101,28 +121,7 @@ void MainWindow::on_pushButton_clicked() void MainWindow::on_actionOpen_triggered() { - - 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()); + this->loadPath(); } void MainWindow::on_toolButton_clicked() diff --git a/mainwindow.h b/mainwindow.h index 8757459..24fc256 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -21,7 +21,7 @@ public: void updatePathView(); void updateStepView(size_t num); void onTextChanged(); - void loadPath(QTextStream &in); + void loadPath(); void addNewPath(); void addNewStep(); void exportHTMLMap();