From e56eed0a16d589e62ae4631310d6562bfc553ac6 Mon Sep 17 00:00:00 2001 From: ccolin Date: Sun, 3 Oct 2021 00:24:20 +0200 Subject: [PATCH] fix open button --- src/main.cpp | 14 +++++++++----- src/main_window.cpp | 13 +++++-------- src/main_window.h | 3 --- 3 files changed, 14 insertions(+), 16 deletions(-) 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);