diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index a8d9d50..6adb5be 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index b16a04e..84b428a 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -711,6 +711,8 @@ void CDockAreaWidget::onDockWidgetViewToggled(bool Open) void CDockAreaWidget::saveState(QDataStream& stream) const { stream << d->ContentsLayout->count() << d->ContentsLayout->currentIndex(); + std::cout << "CDockAreaWidget::saveState TabCount: " << d->ContentsLayout->count() + << " CurrentIndex: " << d->ContentsLayout->currentIndex() << std::endl; for (int i = 0; i < d->ContentsLayout->count(); ++i) { dockWidget(i)->saveState(stream); diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index b344ce1..e4c66ef 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -39,6 +39,7 @@ class CDockManager; class CDockContainerWidget; class CDockWidget; + /** * DockAreaWidget manages multiple instances of DckWidgets. * It displays a title tab, which is clickable and will switch to diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index 8cc6fa9..be14d2c 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include "DockManager.h" @@ -43,6 +42,7 @@ #include "DockOverlay.h" #include "DockStateSerialization.h" #include "ads_globals.h" +#include "DockSplitter.h" #include @@ -75,6 +75,7 @@ struct DockContainerWidgetPrivate unsigned int zOrderIndex = 0; QList DockAreas; QGridLayout* Layout = nullptr; + CDockSplitter* RootSplitter; bool isFloating = false; /** @@ -123,7 +124,7 @@ struct DockContainerWidgetPrivate /** * Restore state of child nodes */ - void restoreChildNodes(QDataStream& Stream, QWidget* Parent); + void restoreChildNodes(QDataStream& Stream, QWidget*& CreatedWidget); }; // struct DockContainerWidgetPrivate @@ -310,10 +311,10 @@ void DockContainerWidgetPrivate::saveChildNodesState(QDataStream& stream, QWidge } else { + stream << NodeDockArea; CDockAreaWidget* DockArea = dynamic_cast(Widget); if (DockArea) { - std::cout << "NodeDockArea " << std::endl; DockArea->saveState(stream); } } @@ -321,17 +322,27 @@ void DockContainerWidgetPrivate::saveChildNodesState(QDataStream& stream, QWidge //============================================================================ -void DockContainerWidgetPrivate::restoreChildNodes(QDataStream& stream, QWidget* Parent) +void DockContainerWidgetPrivate::restoreChildNodes(QDataStream& stream, + QWidget*& CreatedWidget) { int NodeType; stream >> NodeType; - QSplitter* ParentSplitter = dynamic_cast(Parent); if (NodeSplitter == NodeType) { int Orientation; - int Count; - stream >> Orientation >> Count; - std::cout << "Restore NodeSplitter " << Orientation << std::endl; + int WidgetCount; + stream >> Orientation >> WidgetCount; + std::cout << "Restore NodeSplitter Orientation: " << Orientation << + " WidgetCount: " << WidgetCount << std::endl; + for (int i = 0; i < WidgetCount; ++i) + { + QWidget* Widget; + restoreChildNodes(stream, CreatedWidget); + } + + + + /*std::cout << "Restore NodeSplitter " << Orientation << std::endl; QSplitter* Splitter = internal::newSplitter((Qt::Orientation)Orientation); if (ParentSplitter) { @@ -344,21 +355,37 @@ void DockContainerWidgetPrivate::restoreChildNodes(QDataStream& stream, QWidget* for (int i = 0; i < Count; ++i) { restoreChildNodes(stream, Splitter); - } + }*/ } else { - std::cout << "Restore NodeDockArea " << std::endl; - CDockAreaWidget* DockArea = new CDockAreaWidget(DockManager, _this); - if (ParentSplitter) + int Tabs; + int CurrentIndex; + stream >> Tabs >> CurrentIndex; + std::cout << "Restore NodeDockArea Tabs: " << Tabs << " CurrentIndex: " + << CurrentIndex << std::endl; + for (int i = 0; i < Tabs; ++i) { - ParentSplitter->addWidget(DockArea); + QString ObjectName; + bool Closed; + stream >> ObjectName >> Closed; + std::cout << "Restore DockWidget " << ObjectName.toStdString() << " Closed: " + << Closed << std::endl; + + CDockWidget* DockWidget = DockManager->findChild(ObjectName); + if (!DockWidget) + { + continue; + } + else + { + std::cout << "Dock Widget found - parent " << DockWidget->parent() + << std::endl; + } + + CDockAreaWidget* DockArea = new CDockAreaWidget(DockManager, _this); + DockArea->addDockWidget(DockWidget); } - else - { - Parent->layout()->addWidget(DockArea); - } - DockAreas.append(DockArea); } } @@ -380,7 +407,10 @@ void DockContainerWidgetPrivate::addDockArea(CDockAreaWidget* NewDockArea, DockW auto InsertParam = internal::dockAreaInsertParameters(area); if (DockAreas.isEmpty()) { - _this->layout()->addWidget(NewDockArea); + QSplitter* Splitter = internal::newSplitter(Qt::Horizontal); + Splitter->addWidget(NewDockArea); + insertWidgetIntoSplitter(Splitter, NewDockArea, InsertParam.append()); + _this->layout()->addWidget(Splitter); } else if (DockAreas.count() == 1) { @@ -707,7 +737,17 @@ bool CDockContainerWidget::restoreState(QDataStream& stream) { bool IsFloating; stream >> IsFloating; - if (isFloating()) + std::cout << "Restore CDockContainerWidget Floating" << IsFloating << std::endl; + QWidget* RootChild = d->Layout->itemAt(0)->widget(); + if (RootChild) + { + d->DockAreas.clear(); + delete RootChild; + } + QWidget* Widget; + d->restoreChildNodes(stream, Widget); + + /*if (isFloating()) { std::cout << "Restore floating widget" << std::endl; CFloatingDockContainer* FloatingWidget = internal::findParent(this); @@ -715,15 +755,8 @@ bool CDockContainerWidget::restoreState(QDataStream& stream) stream >> Geometry; FloatingWidget->restoreGeometry(Geometry); FloatingWidget->show(); - } + }*/ - QWidget* RootChild = d->Layout->itemAt(0)->widget(); - if (RootChild) - { - d->DockAreas.clear(); - delete RootChild; - } - d->restoreChildNodes(stream, this); return true; } diff --git a/src/DockSplitter.cpp b/src/DockSplitter.cpp new file mode 100644 index 0000000..c889080 --- /dev/null +++ b/src/DockSplitter.cpp @@ -0,0 +1,27 @@ +//============================================================================ +/// \file DockSplitter.cpp +/// \author Uwe Kindler +/// \date 24.03.2017 +/// \brief Implementation of CDockSplitter +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include + +#include + +namespace ads +{ + +//============================================================================ +CDockSplitter::~CDockSplitter() +{ + std::cout << "~CDockSplitter" << std::endl; +} + +} // namespace ads + +//--------------------------------------------------------------------------- +// EOF DockSplitter.cpp diff --git a/src/DockSplitter.h b/src/DockSplitter.h new file mode 100644 index 0000000..17383c5 --- /dev/null +++ b/src/DockSplitter.h @@ -0,0 +1,36 @@ +#ifndef DockSplitterH +#define DockSplitterH +//============================================================================ +/// \file DockSplitter.h +/// \author Uwe Kindler +/// \date 24.03.2017 +/// \brief Declaration of CDockSplitter +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include + +namespace ads +{ + +/** + * Splitter used internally instead of QSplitter + */ +class CDockSplitter : public QSplitter +{ + Q_OBJECT +public: + using QSplitter::QSplitter; + + /** + * Prints debug info + */ + virtual ~CDockSplitter(); +}; // class CDockSplitter + +} // namespace ads + +//--------------------------------------------------------------------------- +#endif // DockSplitterH diff --git a/src/ads_globals.cpp b/src/ads_globals.cpp index 7784b2b..cdab7ee 100644 --- a/src/ads_globals.cpp +++ b/src/ads_globals.cpp @@ -28,11 +28,12 @@ //============================================================================ // INCLUDES //============================================================================ -#include #include +#include "DockSplitter.h" #include "ads_globals.h" + namespace ads { @@ -41,7 +42,7 @@ namespace internal //============================================================================ QSplitter* newSplitter(Qt::Orientation orientation, QWidget* parent) { - QSplitter* s = new QSplitter(orientation, parent); + QSplitter* s = new CDockSplitter(orientation, parent); s->setProperty("ads-splitter", QVariant(true)); s->setChildrenCollapsible(false); s->setOpaqueResize(false); diff --git a/src/src.pro b/src/src.pro index bf98889..c1f2f0f 100644 --- a/src/src.pro +++ b/src/src.pro @@ -39,7 +39,8 @@ HEADERS += \ DockWidget.h \ DockWidgetTitleBar.h \ FloatingDockContainer.h \ - DockOverlay.h + DockOverlay.h \ + DockSplitter.h @@ -51,4 +52,5 @@ SOURCES += \ DockWidget.cpp \ DockWidgetTitleBar.cpp \ FloatingDockContainer.cpp \ - DockOverlay.cpp + DockOverlay.cpp \ + DockSplitter.cpp