From 8361f90dcecbb2eb0c754dbfc68e48d10e6ca0bf Mon Sep 17 00:00:00 2001 From: shelomentsev Date: Thu, 20 Aug 2020 15:56:37 +0500 Subject: [PATCH 1/4] Delete widgets without parents in CDockAreaLayout. (#241) --- src/DockAreaWidget.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 092f997..1696e1f 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -86,6 +86,18 @@ public: } + /** + * Delete widgets without parents in this layout + */ + ~CDockAreaLayout() + { + for(auto Widget : m_Widgets) + { + if(!Widget->parent()) + delete Widget; + } + } + /** * Returns the number of widgets in this layout */ From a4d281dbb6d5daee746d36a7ccfa971308c2374f Mon Sep 17 00:00:00 2001 From: shelomentsev Date: Thu, 20 Aug 2020 15:58:15 +0500 Subject: [PATCH 2/4] Floating window fixes. (#239) * Don't show a CFloatingDockContainer if all its CDockWidget were hidden before its first shown. * Destroy empty CFloatingDockContainer when removing CDockWidget via removeDockWidget function. --- src/DockAreaWidget.cpp | 8 ++++++++ src/DockManager.cpp | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 1696e1f..a12bcb0 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -478,6 +478,14 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget) ADS_PRINT("Dock Area empty"); DockContainer->removeDockArea(this); this->deleteLater(); + if(DockContainer->dockAreaCount() == 0) + { + if(CFloatingDockContainer* FloatingDockContainer = DockContainer->floatingWidget()) + { + FloatingDockContainer->hide(); + FloatingDockContainer->deleteLater(); + } + } } else if (DockWidget == CurrentDockWidget) { diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 95e4fac..cd109c6 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -653,7 +653,14 @@ void CDockManager::showEvent(QShowEvent *event) for (auto FloatingWidget : d->UninitializedFloatingWidgets) { - FloatingWidget->show(); + for(CDockWidget* DockWidget : FloatingWidget->dockWidgets()) + { + if(!DockWidget->isClosed()) + { + FloatingWidget->show(); + break; + } + } } d->UninitializedFloatingWidgets.clear(); } From 0eca1b0433e0b39fc41b4a7265a3e3478d985ffb Mon Sep 17 00:00:00 2001 From: shelomentsev Date: Fri, 21 Aug 2020 11:08:33 +0500 Subject: [PATCH 3/4] Memory leak (#242) * Delete widgets without parents in CDockAreaLayout. * Fixed the place where dock widgets witout parents are destroyed. --- src/DockManager.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/DockManager.cpp b/src/DockManager.cpp index cd109c6..f75ff71 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -484,6 +484,12 @@ CDockManager::~CDockManager() { delete FloatingWidget; } + auto DockWidgetsMap = d->DockWidgetsMap; + for(auto DockWidget : d->DockWidgetsMap) + { + if(!DockWidget->parent()) + delete DockWidget; + } delete d; } From 703a9b3e1293b5ff89d810cb00fd00f987f38aeb Mon Sep 17 00:00:00 2001 From: shelomentsev Date: Fri, 21 Aug 2020 11:09:13 +0500 Subject: [PATCH 4/4] Update the state of close button on titlebar and tabbar when CDockWidget::DockWidgetClosable changed. (#240) --- src/DockAreaWidget.cpp | 10 ++++++++++ src/DockAreaWidget.h | 1 + src/DockWidget.cpp | 2 ++ src/DockWidgetTab.cpp | 19 ++++++++++++++----- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index a12bcb0..78c4e5e 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -971,6 +971,16 @@ QSize CDockAreaWidget::minimumSizeHint() const { return d->MinSizeHint.isValid() ? d->MinSizeHint : Super::minimumSizeHint(); } + + +//============================================================================ +void CDockAreaWidget::onDockWidgetFeaturesChanged() +{ + if (d->TitleBar) + d->updateTitleBarButtonStates(); +} + + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index 337eac2..55b1a39 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -65,6 +65,7 @@ private: friend class CDockWidget; friend struct DockManagerPrivate; friend class CDockManager; + void onDockWidgetFeaturesChanged(); private slots: void onTabCloseRequested(int Index); diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index 56c697e..83cb613 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -340,6 +340,8 @@ void CDockWidget::setFeatures(DockWidgetFeatures features) d->Features = features; emit featuresChanged(d->Features); d->TabWidget->onDockWidgetFeaturesChanged(); + if(CDockAreaWidget* DockArea = dockAreaWidget()) + DockArea->onDockWidgetFeaturesChanged(); } diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index d8b9a84..6d80b1f 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -134,6 +134,18 @@ struct DockWidgetTabPrivate } } + /** + * Update the close button visibility from current feature/config + */ + void updateCloseButtonVisibility(bool active) + { + bool DockWidgetClosable = DockWidget->features().testFlag(CDockWidget::DockWidgetClosable); + bool ActiveTabHasCloseButton = testConfigFlag(CDockManager::ActiveTabHasCloseButton); + bool AllTabsHaveCloseButton = testConfigFlag(CDockManager::AllTabsHaveCloseButton); + bool TabHasCloseButton = (ActiveTabHasCloseButton && active) | AllTabsHaveCloseButton; + CloseButton->setVisible(DockWidgetClosable && TabHasCloseButton); + } + template IFloatingWidget* createFloatingWidget(T* Widget, bool OpaqueUndocking) { @@ -461,11 +473,7 @@ bool CDockWidgetTab::isActiveTab() const //============================================================================ void CDockWidgetTab::setActiveTab(bool active) { - bool DockWidgetClosable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetClosable); - bool ActiveTabHasCloseButton = d->testConfigFlag(CDockManager::ActiveTabHasCloseButton); - bool AllTabsHaveCloseButton = d->testConfigFlag(CDockManager::AllTabsHaveCloseButton); - bool TabHasCloseButton = (ActiveTabHasCloseButton && active) | AllTabsHaveCloseButton; - d->CloseButton->setVisible(DockWidgetClosable && TabHasCloseButton); + d->updateCloseButtonVisibility(active); // Focus related stuff if (CDockManager::testConfigFlag(CDockManager::FocusHighlighting) && !d->DockWidget->dockManager()->isRestoringState()) @@ -653,6 +661,7 @@ void CDockWidgetTab::onDockWidgetFeaturesChanged() SizePolicy.setRetainSizeWhenHidden(Features.testFlag(CDockWidget::DockWidgetClosable) && d->testConfigFlag(CDockManager::RetainTabSizeWhenCloseButtonHidden)); d->CloseButton->setSizePolicy(SizePolicy); + d->updateCloseButtonVisibility(isActiveTab()); }