From 68f1084bf0f38cf1bcb0eaa97a52947eecafff75 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Mon, 27 Nov 2023 21:48:14 +0100 Subject: [PATCH] Added parentSplitter() fucntion to DockArea and removed dead code from DockContainerWidget --- src/DockAreaWidget.cpp | 9 ++++++++- src/DockAreaWidget.h | 6 ++++++ src/DockContainerWidget.cpp | 23 +++++++---------------- src/DockContainerWidget.h | 3 ++- src/DockManager.cpp | 4 ++-- src/DockWidget.cpp | 4 ++-- src/ads_globals.h | 2 +- 7 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index a47aa5b..662aca8 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -464,6 +464,13 @@ CAutoHideDockContainer* CDockAreaWidget::autoHideDockContainer() const return d->AutoHideDockContainer; } + +//============================================================================ +CDockSplitter* CDockAreaWidget::parentSplitter() const +{ + return internal::findParent(this); +} + //============================================================================ bool CDockAreaWidget::isAutoHide() const { @@ -600,7 +607,7 @@ void CDockAreaWidget::hideAreaWithNoVisibleContent() this->toggleView(false); // Hide empty parent splitters - auto Splitter = internal::findParent(this); + auto Splitter = parentSplitter(); internal::hideEmptyParentSplitters(Splitter); //Hide empty floating widget diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index e88153e..30701fb 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -47,6 +47,7 @@ class CDockContainerWidget; class DockContainerWidgetPrivate; class CDockAreaTitleBar; class CDockingStateReader; +class CDockSplitter; /** @@ -216,6 +217,11 @@ public: */ CAutoHideDockContainer* autoHideDockContainer() const; + /** + * Returns the parent splitter that contains this dock area + */ + CDockSplitter* parentSplitter() const; + /** * Returns true if the dock area is in an auto hide container */ diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index 85ce8ea..7abf7ae 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -587,16 +587,7 @@ void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* Floatin auto InsertParam = internal::dockAreaInsertParameters(area); auto NewDockAreas = FloatingContainer->findChildren( QString(), Qt::FindChildrenRecursively); - QSplitter* TargetAreaSplitter = internal::findParent(TargetArea); - - if (!TargetAreaSplitter) - { - QSplitter* Splitter = newSplitter(InsertParam.orientation()); - Layout->replaceWidget(TargetArea, Splitter); - Splitter->addWidget(TargetArea); - updateSplitterHandles(Splitter); - TargetAreaSplitter = Splitter; - } + auto TargetAreaSplitter = TargetArea->parentSplitter(); int AreaIndex = TargetAreaSplitter->indexOf(TargetArea); auto FloatingSplitter = FloatingContainer->rootSplitter(); if (TargetAreaSplitter->orientation() == InsertParam.orientation()) @@ -742,7 +733,7 @@ void DockContainerWidgetPrivate::moveToNewSection(QWidget* Widget, CDockAreaWidg } auto InsertParam = internal::dockAreaInsertParameters(area); - QSplitter* TargetAreaSplitter = internal::findParent(TargetArea); + auto TargetAreaSplitter = TargetArea->parentSplitter(); int AreaIndex = TargetAreaSplitter->indexOf(TargetArea); auto Sizes = TargetAreaSplitter->sizes(); if (TargetAreaSplitter->orientation() == InsertParam.orientation()) @@ -877,7 +868,7 @@ void DockContainerWidgetPrivate::moveToContainer(QWidget* Widget, DockWidgetArea // it already has and do nothing, if it is the same place. It would // also work without this check, but it looks nicer with the check // because there will be no layout updates - auto Splitter = internal::findParent(DroppedDockArea); + auto Splitter = DroppedDockArea->parentSplitter(); auto InsertParam = internal::dockAreaInsertParameters(area); if (Splitter == RootSplitter && InsertParam.orientation() == Splitter->orientation()) { @@ -1364,7 +1355,7 @@ CDockAreaWidget* DockContainerWidgetPrivate::addDockWidgetToDockArea(DockWidgetA NewDockArea->addDockWidget(Dockwidget); auto InsertParam = internal::dockAreaInsertParameters(area); - QSplitter* TargetAreaSplitter = internal::findParent(TargetDockArea); + auto TargetAreaSplitter = TargetDockArea->parentSplitter(); int index = TargetAreaSplitter ->indexOf(TargetDockArea); if (TargetAreaSplitter->orientation() == InsertParam.orientation()) { @@ -1381,7 +1372,7 @@ CDockAreaWidget* DockContainerWidgetPrivate::addDockWidgetToDockArea(DockWidgetA { ADS_PRINT("TargetAreaSplitter->orientation() != InsertParam.orientation()"); auto TargetAreaSizes = TargetAreaSplitter->sizes(); - QSplitter* NewSplitter = newSplitter(InsertParam.orientation()); + auto NewSplitter = newSplitter(InsertParam.orientation()); NewSplitter->addWidget(TargetDockArea); insertWidgetIntoSplitter(NewSplitter, NewDockArea, InsertParam.append()); @@ -1572,7 +1563,7 @@ void CDockContainerWidget::removeDockArea(CDockAreaWidget* area) area->disconnect(this); d->DockAreas.removeAll(area); - CDockSplitter* Splitter = internal::findParent(area); + auto Splitter = area->parentSplitter(); // Remove are from parent splitter and recursively hide tree of parent // splitters if it has no visible content @@ -1943,7 +1934,7 @@ bool CDockContainerWidget::restoreState(CDockingStateReader& s, bool Testing) //============================================================================ -QSplitter* CDockContainerWidget::rootSplitter() const +CDockSplitter* CDockContainerWidget::rootSplitter() const { return d->RootSplitter; } diff --git a/src/DockContainerWidget.h b/src/DockContainerWidget.h index 8f15f2e..3dd5243 100644 --- a/src/DockContainerWidget.h +++ b/src/DockContainerWidget.h @@ -53,6 +53,7 @@ struct FloatingDragPreviewPrivate; class CDockingStateReader; class CAutoHideSideBar; class CAutoHideTab; +class CDockSplitter; struct AutoHideTabPrivate; struct AutoHideDockContainerPrivate; @@ -94,7 +95,7 @@ protected: /** * Access function for the internal root splitter */ - QSplitter* rootSplitter() const; + CDockSplitter* rootSplitter() const; /** * Creates and initializes a dockwidget auto hide container into the given area. diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 9948202..8549a13 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -1318,7 +1318,7 @@ QList CDockManager::splitterSizes(CDockAreaWidget *ContainedArea) const { if (ContainedArea) { - auto Splitter = internal::findParent(ContainedArea); + auto Splitter = ContainedArea->parentSplitter(); if (Splitter) { return Splitter->sizes(); @@ -1335,7 +1335,7 @@ void CDockManager::setSplitterSizes(CDockAreaWidget *ContainedArea, const QList< return; } - auto Splitter = internal::findParent(ContainedArea); + auto Splitter = ContainedArea->parentSplitter(); if (Splitter && Splitter->count() == sizes.count()) { Splitter->setSizes(sizes); diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index 4298af6..8e2ba7e 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -184,11 +184,11 @@ void DockWidgetPrivate::showDockWidget() DockArea->setCurrentDockWidget(_this); DockArea->toggleView(true); TabWidget->show(); - QSplitter* Splitter = internal::findParent(DockArea); + auto Splitter = DockArea->parentSplitter(); while (Splitter && !Splitter->isVisible() && !DockArea->isAutoHide()) { Splitter->show(); - Splitter = internal::findParent(Splitter); + Splitter = internal::findParent(Splitter); } CDockContainerWidget* Container = DockArea->dockContainer(); diff --git a/src/ads_globals.h b/src/ads_globals.h index af8f078..d3558aa 100644 --- a/src/ads_globals.h +++ b/src/ads_globals.h @@ -268,7 +268,7 @@ T findParent(const QWidget* w) } parentWidget = parentWidget->parentWidget(); } - return 0; + return nullptr; } /**