Changed demos to delete the dock manager when the main window is closes to ensure that all floating widgets als "closed" (destroyed)

This commit is contained in:
Uwe Kindler 2020-07-22 11:28:41 +02:00
parent 8443414ae3
commit 4a6d2d3514
6 changed files with 57 additions and 1 deletions

View File

@ -634,6 +634,9 @@ CMainWindow::~CMainWindow()
void CMainWindow::closeEvent(QCloseEvent* event) void CMainWindow::closeEvent(QCloseEvent* event)
{ {
d->saveState(); 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); QMainWindow::closeEvent(event);
} }

View File

@ -5,14 +5,36 @@
#include <QMenuBar> #include <QMenuBar>
#include "DockManager.h" #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[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
QMainWindow w; MainWindow w;
ads::CDockManager::setConfigFlag(ads::CDockManager::FocusHighlighting, true); ads::CDockManager::setConfigFlag(ads::CDockManager::FocusHighlighting, true);
ads::CDockManager::setConfigFlag(ads::CDockManager::AllTabsHaveCloseButton, true); ads::CDockManager::setConfigFlag(ads::CDockManager::AllTabsHaveCloseButton, true);
auto dockManager = new ads::CDockManager(&w); auto dockManager = new ads::CDockManager(&w);
w.setDockManager(dockManager);
QObject::connect(dockManager, &ads::CDockManager::focusedDockWidgetChanged, [] (ads::CDockWidget* old, ads::CDockWidget* now) { QObject::connect(dockManager, &ads::CDockManager::focusedDockWidgetChanged, [] (ads::CDockWidget* old, ads::CDockWidget* now) {
static int Count = 0; static int Count = 0;
qDebug() << Count++ << " CDockManager::focusedDockWidgetChanged old: " << (old ? old->objectName() : "-") << " now: " << now->objectName() << " visible: " << now->isVisible(); qDebug() << Count++ << " CDockManager::focusedDockWidgetChanged old: " << (old ? old->objectName() : "-") << " now: " << now->objectName() << " visible: " << now->isVisible();

View File

@ -51,3 +51,13 @@ MainWindow::~MainWindow()
{ {
delete ui; delete ui;
} }
void MainWindow::closeEvent(QCloseEvent *event)
{
QMainWindow::closeEvent(event);
if (m_DockManager)
{
m_DockManager->deleteLater();
}
}

View File

@ -22,6 +22,9 @@ public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = 0);
~MainWindow(); ~MainWindow();
protected:
virtual void closeEvent(QCloseEvent *event) override;
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
ads::CDockManager* m_DockManager; ads::CDockManager* m_DockManager;

View File

@ -99,3 +99,18 @@ MainWindow::~MainWindow()
{ {
delete ui; delete ui;
} }
void MainWindow::closeEvent(QCloseEvent *event)
{
QMainWindow::closeEvent(event);
if (m_DockManager1)
{
m_DockManager1->deleteLater();
}
if (m_DockManager2)
{
m_DockManager2->deleteLater();
}
}

View File

@ -18,6 +18,9 @@ public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = 0);
~MainWindow(); ~MainWindow();
protected:
virtual void closeEvent(QCloseEvent *event) override;
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
ads::CDockManager* m_DockManager1; ads::CDockManager* m_DockManager1;