From 3c4af9c6af7cddbecdb604fd6853c50ce5d87ea9 Mon Sep 17 00:00:00 2001 From: Ben Hetherington Date: Sun, 6 Feb 2022 07:21:43 +0000 Subject: [PATCH] Add method to add dock widget to dock container (#398) This adds a `addDockWidgetToContainer()` method to `CDockManager`, which allows a dock widget to be registered with the dock manager, and added to a specific container, even if that container doesn't currently have any `DockAreaWidget`s. This is pretty much just a clone of `addDockWidget()`, but with the ability to specify a container widget instead of a dock area. --- src/DockManager.cpp | 10 ++++++++++ src/DockManager.h | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/src/DockManager.cpp b/src/DockManager.cpp index f22fa4b..4b9b6c9 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -823,6 +823,16 @@ CDockAreaWidget* CDockManager::addDockWidget(DockWidgetArea area, return AreaOfAddedDockWidget; } +//============================================================================ +CDockAreaWidget* CDockManager::addDockWidgetToContainer(DockWidgetArea area, + CDockWidget* Dockwidget, CDockContainerWidget* DockContainerWidget) +{ + d->DockWidgetsMap.insert(Dockwidget->objectName(), Dockwidget); + auto AreaOfAddedDockWidget = DockContainerWidget->addDockWidget(area, Dockwidget); + Q_EMIT dockWidgetAdded(Dockwidget); + return AreaOfAddedDockWidget; +} + //============================================================================ CDockAreaWidget* CDockManager::addDockWidgetTab(DockWidgetArea area, diff --git a/src/DockManager.h b/src/DockManager.h index 46bcb14..7747d23 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -283,6 +283,15 @@ public: CDockAreaWidget* addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget = nullptr); + /** + * Adds dockwidget into the given container. + * This allows you to place the dock widget into a container, even if that + * container does not yet contain a DockAreaWidget. + * \return Returns the dock area widget that contains the new DockWidget + */ + CDockAreaWidget* addDockWidgetToContainer(DockWidgetArea area, CDockWidget* Dockwidget, + CDockContainerWidget* DockContainerWidget); + /** * This function will add the given Dockwidget to the given dock area as * a new tab.