Moved dock area restore code into CDockAreaWidget

This commit is contained in:
Uwe Kindler 2022-10-30 19:44:33 +01:00
parent 8d670577a9
commit d1d801cf16
10 changed files with 217 additions and 149 deletions

View File

@ -27,14 +27,7 @@
//============================================================================
// INCLUDES
//============================================================================
#include <AutoHideDockContainer.h>
#include "DockManager.h"
#include "DockWidgetSideTab.h"
#include "DockWidgetTab.h"
#include "SideTabBar.h"
#include "DockAreaWidget.h"
#include "DockingStateReader.h"
#include "ResizeHandle.h"
#include "AutoHideDockContainer.h"
#include <QXmlStreamWriter>
#include <QBoxLayout>
@ -43,6 +36,16 @@
#include <QPointer>
#include <QApplication>
#include "DockManager.h"
#include "DockWidgetSideTab.h"
#include "DockWidgetTab.h"
#include "SideTabBar.h"
#include "DockAreaWidget.h"
#include "DockingStateReader.h"
#include "ResizeHandle.h"
#include "DockComponentsFactory.h"
#include <iostream>
namespace ads
@ -174,7 +177,7 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockManager* DockManager, SideBa
d(new AutoHideDockContainerPrivate(this))
{
d->SideTabBarArea = area;
d->SideTab = new CDockWidgetSideTab();
d->SideTab = componentsFactory()->createDockWidgetSideTab(nullptr);
connect(d->SideTab, &CDockWidgetSideTab::pressed, this, &CAutoHideDockContainer::toggleCollapseState);
d->DockArea = new CDockAreaWidget(DockManager, parent);
d->DockArea->setObjectName("autoHideDockArea");
@ -294,14 +297,7 @@ void CAutoHideDockContainer::addDockWidget(CDockWidget* DockWidget)
}
d->DockWidget = DockWidget;
if (!d->SideTab)
{
d->SideTab = DockWidget->sideTabWidget();
}
else
{
d->SideTab->setDockWidget(DockWidget);
}
d->SideTab->setDockWidget(DockWidget);
CDockAreaWidget* OldDockArea = DockWidget->dockAreaWidget();
if (OldDockArea)
{

View File

@ -53,6 +53,7 @@
#include "DockComponentsFactory.h"
#include "DockWidgetTab.h"
#include "DockWidgetSideTab.h"
#include "DockingStateReader.h"
namespace ads
@ -895,6 +896,98 @@ void CDockAreaWidget::saveState(QXmlStreamWriter& s) const
}
//============================================================================
bool CDockAreaWidget::restoreDockArea(CDockingStateReader& s, CDockAreaWidget*& CreatedWidget,
bool Testing, CDockContainerWidget* Container)
{
bool Ok;
#ifdef ADS_DEBUG_PRINT
int Tabs = s.attributes().value("Tabs").toInt(&Ok);
if (!Ok)
{
return false;
}
#endif
QString CurrentDockWidget = s.attributes().value("Current").toString();
ADS_PRINT("Restore NodeDockArea Tabs: " << Tabs << " Current: "
<< CurrentDockWidget);
auto DockManager = Container->dockManager();
CDockAreaWidget* DockArea = nullptr;
if (!Testing)
{
DockArea = new CDockAreaWidget(DockManager, Container);
const auto AllowedAreasAttribute = s.attributes().value("AllowedAreas");
if (!AllowedAreasAttribute.isEmpty())
{
DockArea->setAllowedAreas((DockWidgetArea)AllowedAreasAttribute.toInt(nullptr, 16));
}
const auto FlagsAttribute = s.attributes().value("Flags");
if (!FlagsAttribute.isEmpty())
{
DockArea->setDockAreaFlags((CDockAreaWidget::DockAreaFlags)FlagsAttribute.toInt(nullptr, 16));
}
}
while (s.readNextStartElement())
{
if (s.name() != QLatin1String("Widget"))
{
continue;
}
auto ObjectName = s.attributes().value("Name");
if (ObjectName.isEmpty())
{
return false;
}
bool Closed = s.attributes().value("Closed").toInt(&Ok);
if (!Ok)
{
return false;
}
s.skipCurrentElement();
CDockWidget* DockWidget = DockManager->findDockWidget(ObjectName.toString());
if (!DockWidget || Testing)
{
continue;
}
ADS_PRINT("Dock Widget found - parent " << DockWidget->parent());
// We hide the DockArea here to prevent the short display (the flashing)
// of the dock areas during application startup
DockArea->hide();
DockArea->addDockWidget(DockWidget);
DockWidget->setToggleViewActionChecked(!Closed);
DockWidget->setClosedState(Closed);
DockWidget->setProperty(internal::ClosedProperty, Closed);
DockWidget->setProperty(internal::DirtyProperty, false);
}
if (Testing)
{
return true;
}
if (!DockArea->dockWidgetsCount())
{
delete DockArea;
DockArea = nullptr;
}
else
{
DockArea->setProperty("currentDockWidget", CurrentDockWidget);
}
CreatedWidget = DockArea;
return true;
}
//============================================================================
CDockWidget* CDockAreaWidget::nextOpenDockWidget(CDockWidget* DockWidget) const
{

View File

@ -46,6 +46,7 @@ class CDockManager;
class CDockContainerWidget;
class DockContainerWidgetPrivate;
class CDockAreaTitleBar;
class CDockingStateReader;
/**
@ -296,6 +297,13 @@ public:
*/
void saveState(QXmlStreamWriter& Stream) const;
/**
* Restores a dock area.
* \see restoreChildNodes() for details
*/
static bool restoreDockArea(CDockingStateReader& Stream, CDockAreaWidget*& CreatedWidget,
bool Testing, CDockContainerWidget* Container);
/**
* This functions returns the dock widget features of all dock widget in
* this area.
@ -362,6 +370,7 @@ public:
*/
bool containsCentralWidget() const;
public Q_SLOTS:
/**
* This activates the tab for the given tab index.

View File

@ -910,23 +910,7 @@ void DockContainerWidgetPrivate::saveAutoHideWidgetsState(QXmlStreamWriter& s)
continue;
}
s.writeStartElement("SideBar");
s.writeAttribute("Area", QString::number(sideTabBar->sideTabBarArea()));
s.writeAttribute("Tabs", QString::number(sideTabBar->tabCount()));
for (auto i = 0; i < sideTabBar->tabCount(); ++i)
{
auto Tab = sideTabBar->tabAt(i);
if (!Tab)
{
continue;
}
auto DockArea = Tab->dockWidget()->dockAreaWidget();
DockArea->saveState(s);
}
s.writeEndElement();
sideTabBar->saveState(s);
}
}
@ -1049,6 +1033,11 @@ bool DockContainerWidgetPrivate::restoreSplitter(CDockingStateReader& s,
//============================================================================
bool DockContainerWidgetPrivate::restoreAutoHideDockArea(CDockingStateReader& s, SideBarLocation area, bool Testing)
{
if (!CDockManager::testConfigFlag(CDockManager::AutoHideFeatureEnabled))
{
return false;
}
bool Ok;
#ifdef ADS_DEBUG_PRINT
int Tabs = s.attributes().value("Tabs").toInt(&Ok);
@ -1062,11 +1051,6 @@ bool DockContainerWidgetPrivate::restoreAutoHideDockArea(CDockingStateReader& s,
ADS_PRINT("Restore NodeDockArea Tabs: " << Tabs << " Current: "
<< CurrentDockWidget);
if (!CDockManager::testConfigFlag(CDockManager::AutoHideFeatureEnabled))
{
return false;
}
CDockAreaWidget* DockArea = nullptr;
CAutoHideDockContainer* AutoHideContainer = nullptr;
if (!Testing)
@ -1136,91 +1120,14 @@ bool DockContainerWidgetPrivate::restoreAutoHideDockArea(CDockingStateReader& s,
bool DockContainerWidgetPrivate::restoreDockArea(CDockingStateReader& s,
QWidget*& CreatedWidget, bool Testing)
{
bool Ok;
#ifdef ADS_DEBUG_PRINT
int Tabs = s.attributes().value("Tabs").toInt(&Ok);
if (!Ok)
{
return false;
}
#endif
QString CurrentDockWidget = s.attributes().value("Current").toString();
ADS_PRINT("Restore NodeDockArea Tabs: " << Tabs << " Current: "
<< CurrentDockWidget);
CDockAreaWidget* DockArea = nullptr;
if (!Testing)
auto Result = CDockAreaWidget::restoreDockArea(s, DockArea, Testing, _this);
if (Result && DockArea)
{
DockArea = new CDockAreaWidget(DockManager, _this);
const auto AllowedAreasAttribute = s.attributes().value("AllowedAreas");
if (!AllowedAreasAttribute.isEmpty())
{
DockArea->setAllowedAreas((DockWidgetArea)AllowedAreasAttribute.toInt(nullptr, 16));
}
const auto FlagsAttribute = s.attributes().value("Flags");
if (!FlagsAttribute.isEmpty())
{
DockArea->setDockAreaFlags((CDockAreaWidget::DockAreaFlags)FlagsAttribute.toInt(nullptr, 16));
}
}
while (s.readNextStartElement())
{
if (s.name() != QLatin1String("Widget"))
{
continue;
}
auto ObjectName = s.attributes().value("Name");
if (ObjectName.isEmpty())
{
return false;
}
bool Closed = s.attributes().value("Closed").toInt(&Ok);
if (!Ok)
{
return false;
}
s.skipCurrentElement();
CDockWidget* DockWidget = DockManager->findDockWidget(ObjectName.toString());
if (!DockWidget || Testing)
{
continue;
}
ADS_PRINT("Dock Widget found - parent " << DockWidget->parent());
// We hide the DockArea here to prevent the short display (the flashing)
// of the dock areas during application startup
DockArea->hide();
DockArea->addDockWidget(DockWidget);
DockWidget->setToggleViewActionChecked(!Closed);
DockWidget->setClosedState(Closed);
DockWidget->setProperty(internal::ClosedProperty, Closed);
DockWidget->setProperty(internal::DirtyProperty, false);
}
if (Testing)
{
return true;
}
if (!DockArea->dockWidgetsCount())
{
delete DockArea;
DockArea = nullptr;
}
else
{
DockArea->setProperty("currentDockWidget", CurrentDockWidget);
appendDockAreas({DockArea});
}
CreatedWidget = DockArea;
return true;
return Result;
}
@ -2319,6 +2226,13 @@ QRect CDockContainerWidget::contentRectGlobal() const
}
return internal::globalGeometry(d->RootSplitter);
}
//===========================================================================
CDockManager* CDockContainerWidget::dockManager() const
{
return d->DockManager;
}
} // namespace ads
//---------------------------------------------------------------------------

View File

@ -342,6 +342,11 @@ public:
*/
QRect contentRectGlobal() const;
/**
* Returns the dock manager that owns this container
*/
CDockManager* dockManager() const;
Q_SIGNALS:
/**

View File

@ -325,10 +325,6 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
setObjectName(title);
d->TabWidget = componentsFactory()->createDockWidgetTab(this);
d->SideTabWidget = componentsFactory()->createDockWidgetSideTab(nullptr);
d->SideTabWidget->hide();
connect(d->SideTabWidget, &CDockWidgetSideTab::pressed, this, &CDockWidget::onDockWidgetSideTabClicked);
d->ToggleViewAction = new QAction(title, this);
d->ToggleViewAction->setCheckable(true);
@ -346,10 +342,6 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
CDockWidget::~CDockWidget()
{
ADS_PRINT("~CDockWidget()");
if (d->SideTabWidget)
{
delete d->SideTabWidget;
}
delete d;
}
@ -443,6 +435,8 @@ CDockWidgetTab* CDockWidget::tabWidget() const
return d->TabWidget;
}
//============================================================================
CAutoHideDockContainer* CDockWidget::autoHideDockContainer() const
{
if (!d->DockArea)
@ -534,6 +528,20 @@ CDockWidgetSideTab* CDockWidget::sideTabWidget() const
}
//============================================================================
void CDockWidget::setSideTabWidget(CDockWidgetSideTab* SideTab) const
{
d->SideTabWidget = SideTab;
}
//============================================================================
bool CDockWidget::isAutoHide() const
{
return !d->SideTabWidget.isNull();
}
//============================================================================
bool CDockWidget::isFloating() const
{
@ -741,6 +749,10 @@ bool CDockWidget::event(QEvent *e)
{
d->TabWidget->setText(title);
}
if (d->SideTabWidget)
{
d->SideTabWidget->setText(title);
}
if (d->ToggleViewAction)
{
d->ToggleViewAction->setText(title);
@ -791,7 +803,12 @@ void CDockWidget::setTabToolTip(const QString &text)
void CDockWidget::setIcon(const QIcon& Icon)
{
d->TabWidget->setIcon(Icon);
d->SideTabWidget->setIcon(Icon);
if (d->SideTabWidget)
{
d->SideTabWidget->setIcon(Icon);
}
if (!d->ToggleViewAction->isCheckable())
{
d->ToggleViewAction->setIcon(Icon);
@ -1082,17 +1099,6 @@ void CDockWidget::showNormal()
}
}
//============================================================================
void CDockWidget::onDockWidgetSideTabClicked()
{
const auto autoHideContainer = autoHideDockContainer();
if (!autoHideContainer)
{
return;
}
autoHideContainer->toggleCollapseState();
}
//============================================================================
bool CDockWidget::isFullScreen() const

View File

@ -315,12 +315,6 @@ public:
*/
CDockWidgetTab* tabWidget() const;
/**
* Returns the auto hide dock container of this dock widget
* or 0 if there is none
*/
CAutoHideDockContainer* autoHideDockContainer() const;
/**
* Sets, whether the dock widget is movable, closable, and floatable.
*/
@ -371,6 +365,22 @@ public:
*/
CDockWidgetSideTab* sideTabWidget() const;
/**
* Assign a side tab widget if this dock widget is an auto hide container
*/
void setSideTabWidget(CDockWidgetSideTab* SideTab) const;
/**
* Returns true, if this dock widget is in an auto hide container
*/
bool isAutoHide() const;
/**
* Returns the auto hide dock container of this dock widget
* or 0 if there is none
*/
CAutoHideDockContainer* autoHideDockContainer() const;
/**
* This property holds whether the dock widget is floating.
* A dock widget is only floating, if it is the one and only widget inside
@ -613,10 +623,6 @@ public Q_SLOTS:
*/
void showNormal();
/**
* Toggles the dock auto hide container when the side tab is clicked
*/
void onDockWidgetSideTabClicked();
Q_SIGNALS:
/**

View File

@ -205,6 +205,7 @@ void CDockWidgetSideTab::setDockWidget(CDockWidget* DockWidget)
}
d->DockWidget = DockWidget;
setText(DockWidget->windowTitle());
setIcon(d->DockWidget->icon());
}
}

View File

@ -34,12 +34,14 @@
#include <QBoxLayout>
#include <QStyleOption>
#include <QPainter>
#include <QXmlStreamWriter>
#include "DockContainerWidget.h"
#include "DockWidgetSideTab.h"
#include "DockWidgetTab.h"
#include "DockFocusController.h"
#include "AutoHideDockContainer.h"
#include "DockAreaWidget.h"
namespace ads
{
@ -274,4 +276,31 @@ SideBarLocation CSideTabBar::sideTabBarArea() const
return d->SideTabArea;
}
//============================================================================
void CSideTabBar::saveState(QXmlStreamWriter& s) const
{
if (!tabCount())
{
return;
}
s.writeStartElement("SideBar");
s.writeAttribute("Area", QString::number(sideTabBarArea()));
s.writeAttribute("Tabs", QString::number(tabCount()));
for (auto i = 0; i < tabCount(); ++i)
{
auto Tab = tabAt(i);
if (!Tab)
{
continue;
}
auto DockArea = Tab->dockWidget()->dockAreaWidget();
DockArea->saveState(s);
}
s.writeEndElement();
}
}

View File

@ -33,9 +33,12 @@
#include "DockWidgetSideTab.h"
#include "ads_globals.h"
class QXmlStreamWriter;
namespace ads
{
struct SideTabBarPrivate;
class DockContainerWidgetPrivate;
class CDockContainerWidget;
class CDockWidgetSideTab;
class CAutoHideDockContainer;
@ -57,12 +60,18 @@ private:
SideTabBarPrivate* d; ///< private data (pimpl)
friend struct SideTabBarPrivate;
friend class DockWidgetSideTab;
friend DockContainerWidgetPrivate;
protected:
virtual void paintEvent(QPaintEvent* event) override;
virtual bool event(QEvent* e) override;
virtual bool eventFilter(QObject *watched, QEvent *event) override;
/**
* Saves the state into the given stream
*/
void saveState(QXmlStreamWriter& Stream) const;
public:
using Super = QFrame;