diff --git a/src/main.cpp b/src/main.cpp index 46736ee..af3bb07 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,11 +31,15 @@ int main(int argc, char *argv[]) { } else if (argc == 2) { mesh_processor = new MeshProcessor(argv[1]); } - // QObject::connect(&main_window, &MainWindow::open, - // [&](const QString &path) { - // if (mesh_processor) delete mesh_processor; - // mesh_processor = new MeshProcessor(path); - // }); + QObject::connect(&main_window, &MainWindow::open, + [&](const QString &path) { + if (mesh_processor) { + mesh_viewer->removeMesh(mesh_processor->mesh); + delete mesh_processor; + } + mesh_processor = new MeshProcessor(path); + mesh_viewer->addMesh(mesh_processor->mesh); + }); main_window.show(); return app.exec(); } diff --git a/src/main_window.cpp b/src/main_window.cpp index cb4c4bf..ff8c68e 100644 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -7,9 +7,11 @@ MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent), - mesh_viewer(this), - toolbar(this) { - connect(&mesh_viewer, &MeshViewer::initialized, this, &MainWindow::meshViewerInitialized); + toolbar(this), + mesh_viewer(this) { + connect(&mesh_viewer, &MeshViewer::initialized, [&]() { + open_action->setEnabled(true); + }); setCentralWidget(&mesh_viewer); addToolBar(Qt::RightToolBarArea, &toolbar); open_action = toolbar.addAction("Ouvrir…", [&](){ @@ -31,8 +33,3 @@ MainWindow::MainWindow(QWidget *parent) a->setEnabled(false); } } - - -void MainWindow::meshViewerInitialized() { - open_action->setEnabled(true); -} diff --git a/src/main_window.h b/src/main_window.h index e1b8666..62a3a9e 100644 --- a/src/main_window.h +++ b/src/main_window.h @@ -15,9 +15,6 @@ class MainWindow : public QMainWindow { QAction *open_action; QList toolbar_actions; -private slots: - void meshViewerInitialized(); - signals: void open(const QString &path);