From d811915a0caee45ec69d33864175210fa2f6e313 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Mon, 29 Jun 2020 22:11:37 +0200 Subject: [PATCH 1/3] Reset DockArea pointer of DockWidget when removing DockWidget from DockArea --- src/DockAreaWidget.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index d762b84..c3e8006 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -453,6 +453,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget) auto TabWidget = DockWidget->tabWidget(); TabWidget->hide(); d->tabBar()->removeTab(TabWidget); + DockWidget->setDockArea(nullptr); CDockContainerWidget* DockContainer = dockContainer(); if (NextOpenDockWidget) { From 0948f73bf84c9e699d4767c087ef007c1ab201cc Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Tue, 30 Jun 2020 11:45:23 +0200 Subject: [PATCH 2/3] Properly reset DockManager pointer when removing DockWidget from DockManager --- src/DockManager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DockManager.cpp b/src/DockManager.cpp index e143a63..95e4fac 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -708,6 +708,7 @@ void CDockManager::removeDockWidget(CDockWidget* Dockwidget) emit dockWidgetAboutToBeRemoved(Dockwidget); d->DockWidgetsMap.remove(Dockwidget->objectName()); CDockContainerWidget::removeDockWidget(Dockwidget); + Dockwidget->setDockManager(nullptr); emit dockWidgetRemoved(Dockwidget); } From 8e621f1f2052b8f7f5051d3918ca95c0289517a6 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Tue, 30 Jun 2020 16:34:59 +0200 Subject: [PATCH 3/3] Properly reparent TabWidget to DockWidget if TabWidget is removed from TabBar --- examples/simple/MainWindow.cpp | 65 ++++++++++++++++++++++++++++++++-- examples/simple/MainWindow.h | 3 +- src/DockAreaWidget.cpp | 1 + 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/examples/simple/MainWindow.cpp b/examples/simple/MainWindow.cpp index aeaea2b..ee25f5e 100644 --- a/examples/simple/MainWindow.cpp +++ b/examples/simple/MainWindow.cpp @@ -3,12 +3,13 @@ #include "ui_MainWindow.h" #include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { - ui->setupUi(this); + /*ui->setupUi(this); // Create the dock manager. Because the parent parameter is a QMainWindow // the dock manager registers itself as the central widget. @@ -31,7 +32,67 @@ MainWindow::MainWindow(QWidget *parent) : ui->menuView->addAction(DockWidget->toggleViewAction()); // Add the dock widget to the top dock widget area - m_DockManager->addDockWidget(ads::TopDockWidgetArea, DockWidget); + m_DockManager->addDockWidget(ads::TopDockWidgetArea, DockWidget);*/ + + ui->setupUi(this); + + // Create the dock manager. Because the parent parameter is a QMainWindow + // the dock manager registers itself as the central widget. + m_DockManager1 = new ads::CDockManager(this); + + // Create example content label - this can be any application specific + // widget + ads::CDockWidget* DockWidget; + { + QLabel* l = new QLabel(); + l->setWordWrap(true); + l->setAlignment(Qt::AlignTop | Qt::AlignLeft); + l->setText("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. "); + + // Create a dock widget with the title Label 1 and set the created label + // as the dock widget content + DockWidget = new ads::CDockWidget("Label 1"); + DockWidget->setWidget(l); + } + + ads::CDockWidget* DockWidget2; + { + QLabel* l = new QLabel(); + l->setWordWrap(true); + l->setAlignment(Qt::AlignTop | Qt::AlignLeft); + l->setText("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. "); + + // Create a dock widget with the title Label 1 and set the created label + // as the dock widget content + DockWidget2 = new ads::CDockWidget("Label 2"); + DockWidget2->setWidget(l); + } + + + // Add the toggleViewAction of the dock widget to the menu to give + // the user the possibility to show the dock widget if it has been closed + ui->menuView->addAction(DockWidget->toggleViewAction()); + + // Add the dock widget to the top dock widget area + m_DockManager1->addDockWidget(ads::TopDockWidgetArea, DockWidget); + + + auto funcRemoveFirstManager = [=]() + { + m_DockManager1->removeDockWidget(DockWidget); + + delete m_DockManager1; + m_DockManager1 = nullptr; + }; + QTimer::singleShot(3000, funcRemoveFirstManager); + + auto funcAddSecondManager = [=]() + { + m_DockManager2 = new ads::CDockManager(this); + + m_DockManager2->addDockWidget(ads::TopDockWidgetArea, DockWidget); + }; + QTimer::singleShot(5000, funcAddSecondManager); } MainWindow::~MainWindow() diff --git a/examples/simple/MainWindow.h b/examples/simple/MainWindow.h index 8d90885..89f514b 100644 --- a/examples/simple/MainWindow.h +++ b/examples/simple/MainWindow.h @@ -20,7 +20,8 @@ public: private: Ui::MainWindow *ui; - ads::CDockManager* m_DockManager; + ads::CDockManager* m_DockManager1; + ads::CDockManager* m_DockManager2; }; #endif // MAINWINDOW_H diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index c3e8006..325cf10 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -453,6 +453,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget) auto TabWidget = DockWidget->tabWidget(); TabWidget->hide(); d->tabBar()->removeTab(TabWidget); + TabWidget->setParent(DockWidget); DockWidget->setDockArea(nullptr); CDockContainerWidget* DockContainer = dockContainer(); if (NextOpenDockWidget)