From 4a6d2d3514815ebdfd8857e6551919c25d3ea69c Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Wed, 22 Jul 2020 11:28:41 +0200 Subject: [PATCH] Changed demos to delete the dock manager when the main window is closes to ensure that all floating widgets als "closed" (destroyed) --- demo/MainWindow.cpp | 3 +++ examples/deleteonclose/main.cpp | 24 +++++++++++++++++++++++- examples/sidebar/MainWindow.cpp | 10 ++++++++++ examples/sidebar/MainWindow.h | 3 +++ examples/simple/MainWindow.cpp | 15 +++++++++++++++ examples/simple/MainWindow.h | 3 +++ 6 files changed, 57 insertions(+), 1 deletion(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index bff4786..a4cb640 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -634,6 +634,9 @@ CMainWindow::~CMainWindow() void CMainWindow::closeEvent(QCloseEvent* event) { d->saveState(); + // Delete dock manager here to delete all floating widgets. This ensures + // that all top level windows of the dock manager are properly closed + d->DockManager->deleteLater(); QMainWindow::closeEvent(event); } diff --git a/examples/deleteonclose/main.cpp b/examples/deleteonclose/main.cpp index b9a36de..14b0216 100644 --- a/examples/deleteonclose/main.cpp +++ b/examples/deleteonclose/main.cpp @@ -5,14 +5,36 @@ #include #include "DockManager.h" + +class MainWindow : public QMainWindow +{ +private: + ads::CDockManager* m_DockManager = nullptr; + +protected: + virtual void closeEvent(QCloseEvent *event) override + { + QMainWindow::closeEvent(event); + if (m_DockManager) + { + m_DockManager->deleteLater(); + } + } + +public: + void setDockManager(ads::CDockManager* DockManager) {m_DockManager = DockManager;} +}; + + int main(int argc, char *argv[]) { QApplication a(argc, argv); - QMainWindow w; + MainWindow w; ads::CDockManager::setConfigFlag(ads::CDockManager::FocusHighlighting, true); ads::CDockManager::setConfigFlag(ads::CDockManager::AllTabsHaveCloseButton, true); auto dockManager = new ads::CDockManager(&w); + w.setDockManager(dockManager); QObject::connect(dockManager, &ads::CDockManager::focusedDockWidgetChanged, [] (ads::CDockWidget* old, ads::CDockWidget* now) { static int Count = 0; qDebug() << Count++ << " CDockManager::focusedDockWidgetChanged old: " << (old ? old->objectName() : "-") << " now: " << now->objectName() << " visible: " << now->isVisible(); diff --git a/examples/sidebar/MainWindow.cpp b/examples/sidebar/MainWindow.cpp index 82ecd53..2bf7095 100644 --- a/examples/sidebar/MainWindow.cpp +++ b/examples/sidebar/MainWindow.cpp @@ -51,3 +51,13 @@ MainWindow::~MainWindow() { delete ui; } + + +void MainWindow::closeEvent(QCloseEvent *event) +{ + QMainWindow::closeEvent(event); + if (m_DockManager) + { + m_DockManager->deleteLater(); + } +} diff --git a/examples/sidebar/MainWindow.h b/examples/sidebar/MainWindow.h index 5e2cd8c..d371a41 100644 --- a/examples/sidebar/MainWindow.h +++ b/examples/sidebar/MainWindow.h @@ -22,6 +22,9 @@ public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); +protected: + virtual void closeEvent(QCloseEvent *event) override; + private: Ui::MainWindow *ui; ads::CDockManager* m_DockManager; diff --git a/examples/simple/MainWindow.cpp b/examples/simple/MainWindow.cpp index ee25f5e..6779b3a 100644 --- a/examples/simple/MainWindow.cpp +++ b/examples/simple/MainWindow.cpp @@ -99,3 +99,18 @@ MainWindow::~MainWindow() { delete ui; } + + +void MainWindow::closeEvent(QCloseEvent *event) +{ + QMainWindow::closeEvent(event); + if (m_DockManager1) + { + m_DockManager1->deleteLater(); + } + + if (m_DockManager2) + { + m_DockManager2->deleteLater(); + } +} diff --git a/examples/simple/MainWindow.h b/examples/simple/MainWindow.h index 89f514b..e1c6176 100644 --- a/examples/simple/MainWindow.h +++ b/examples/simple/MainWindow.h @@ -18,6 +18,9 @@ public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); +protected: + virtual void closeEvent(QCloseEvent *event) override; + private: Ui::MainWindow *ui; ads::CDockManager* m_DockManager1;