From b3b6d20d962823b53794e0f19fcf9e1887a779ea Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Thu, 11 Oct 2018 08:54:32 +0200 Subject: [PATCH] Added dockWidgets() function to DockContainerWidget.h because invisible dock widgets are no children of a dock area and therefore FindChildrenRecursively() does not work --- demo/MainWindow.cpp | 4 ++-- src/DockAreaTabBar.cpp | 15 +++++++++++++-- src/DockAreaTabBar.h | 8 +++++++- src/DockContainerWidget.cpp | 16 ++++++++++++++-- src/DockContainerWidget.h | 10 ++++++++++ src/FloatingDockContainer.cpp | 6 ++++++ src/FloatingDockContainer.h | 7 +++++++ 7 files changed, 59 insertions(+), 7 deletions(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index b0ee5b2..fc04926 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -235,10 +235,10 @@ void MainWindowPrivate::saveState() //============================================================================ void MainWindowPrivate::restoreState() { - QSettings Settings("Settings.ini", QSettings::IniFormat); + /*QSettings Settings("Settings.ini", QSettings::IniFormat); _this->restoreGeometry(Settings.value("mainWindow/Geometry").toByteArray()); _this->restoreState(Settings.value("mainWindow/State").toByteArray()); - DockManager->restoreState(Settings.value("mainWindow/DockingState").toByteArray()); + DockManager->restoreState(Settings.value("mainWindow/DockingState").toByteArray());*/ } diff --git a/src/DockAreaTabBar.cpp b/src/DockAreaTabBar.cpp index cbb3927..e32cbce 100644 --- a/src/DockAreaTabBar.cpp +++ b/src/DockAreaTabBar.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "FloatingDockContainer.h" #include "DockAreaWidget.h" @@ -38,6 +39,8 @@ struct DockAreaTabBarPrivate QWidget* TabsContainerWidget; QBoxLayout* TabsLayout; int CurrentIndex = -1; + bool MenuOutdated = true; + QMenu* TabsMenu; /** * Private data constructor @@ -102,6 +105,7 @@ void CDockAreaTabBar::wheelEvent(QWheelEvent* Event) //============================================================================ void CDockAreaTabBar::mousePressEvent(QMouseEvent* ev) { + std::cout << "CDockAreaTabBar::mousePressEvent" << std::endl; if (ev->button() == Qt::LeftButton) { ev->accept(); @@ -252,6 +256,7 @@ void CDockAreaTabBar::insertTab(int Index, CDockWidgetTab* Tab) { d->TabsLayout->insertWidget(Index, Tab); connect(Tab, SIGNAL(clicked()), this, SLOT(onTabClicked())); + d->MenuOutdated = true; } @@ -260,6 +265,7 @@ void CDockAreaTabBar::removeTab(CDockWidgetTab* Tab) { d->TabsLayout->removeWidget(Tab); disconnect(Tab, SIGNAL(clicked()), this, SLOT(onTabClicked())); + d->MenuOutdated = true; } @@ -293,9 +299,14 @@ void CDockAreaTabBar::onTabClicked() } -void CDockAreaTabBar::closeTabe(int Index) +//=========================================================================== +void CDockAreaTabBar::closeTab(int Index) { - + if (Index < 0 || Index >= d->TabsLayout->count()) + { + return; + } + emit tabCloseRequested(Index); } } // namespace ads diff --git a/src/DockAreaTabBar.h b/src/DockAreaTabBar.h index 7f0e21a..86a46b8 100644 --- a/src/DockAreaTabBar.h +++ b/src/DockAreaTabBar.h @@ -107,7 +107,7 @@ public slots: * This function will close the tab given in Index param. * Closing a tab means, the tab will be hidden, it will not be removed */ - void closeTabe(int Index); + void closeTab(int Index); signals: /** @@ -126,6 +126,12 @@ signals: * This signal is emitted when user clicks on a tab at an index. */ void tabBarClicked(int index); + + /** + * This signal is emitted when the close button on a tab is clicked. + * The index is the index that should be closed. + */ + void tabCloseRequested(int index); }; // class CDockAreaTabBar } // namespace ads //----------------------------------------------------------------------------- diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index 7071464..dadfe6f 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -254,8 +254,7 @@ void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* Floatin CDockContainerWidget* FloatingContainer = FloatingWidget->dockContainer(); if (area == CenterDockWidgetArea) { - auto NewDockWidgets = FloatingContainer->findChildren( - QString(), Qt::FindChildrenRecursively); + auto NewDockWidgets = FloatingContainer->dockWidgets(); for (auto DockWidget : NewDockWidgets) { TargetArea->insertDockWidget(0, DockWidget, false); @@ -1141,6 +1140,19 @@ CDockWidget* CDockContainerWidget::topLevelDockWidget() const } +//============================================================================ +QList CDockContainerWidget::dockWidgets() const +{ + QList Result; + for (const auto DockArea : d->DockAreas) + { + Result.append(DockArea->dockWidgets()); + } + + return Result; +} + + } // namespace ads diff --git a/src/DockContainerWidget.h b/src/DockContainerWidget.h index 592dbe0..b73a079 100644 --- a/src/DockContainerWidget.h +++ b/src/DockContainerWidget.h @@ -126,6 +126,16 @@ protected: */ CDockWidget* topLevelDockWidget() const; + /** + * This function returns a list of all dock widgets in this floating widget. + * It may be possible, depending on the implementation, that dock widgets, + * that are not visible to the user have no parent widget. Therefore simply + * calling findChildren() would not work here. Therefore this function + * iterates over all dock areas and creates a list that contains all + * dock widgets returned from all dock areas. + */ + QList dockWidgets() const; + public: /** * Default Constructor diff --git a/src/FloatingDockContainer.cpp b/src/FloatingDockContainer.cpp index 43cae61..0d151f6 100644 --- a/src/FloatingDockContainer.cpp +++ b/src/FloatingDockContainer.cpp @@ -533,6 +533,12 @@ CDockWidget* CFloatingDockContainer::topLevelDockWidget() const return d->DockContainer->topLevelDockWidget(); } +//============================================================================ +QList CFloatingDockContainer::dockWidgets() const +{ + return d->DockContainer->dockWidgets(); +} + } // namespace ads diff --git a/src/FloatingDockContainer.h b/src/FloatingDockContainer.h index e32dc71..dd03ec6 100644 --- a/src/FloatingDockContainer.h +++ b/src/FloatingDockContainer.h @@ -147,6 +147,13 @@ public: * returns this single dock widget. */ CDockWidget* topLevelDockWidget() const; + + /** + * This function returns a list of all dock widget in this floating widget. + * This is a simple convenience function that simply calls the dockWidgets() + * function of the internal container widget. + */ + QList dockWidgets() const; }; // class FloatingDockContainer } // namespace ads