From 2277ba3630058457272b0c34c168c07817a57f97 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Fri, 24 Mar 2017 16:17:55 +0100 Subject: [PATCH] Added initial support for serialization --- demo/mainwindow.cpp | 9 +++-- src/DockContainerWidget.cpp | 81 ++++++++++++++++++++++--------------- src/DockWidget.cpp | 2 +- src/DockWidgetTitleBar.cpp | 2 +- 4 files changed, 55 insertions(+), 39 deletions(-) diff --git a/demo/mainwindow.cpp b/demo/mainwindow.cpp index 32d5383..a565d42 100644 --- a/demo/mainwindow.cpp +++ b/demo/mainwindow.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include "DockManager.h" #include "DockWidget.h" @@ -104,7 +105,7 @@ void MainWindow::createContent() DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false)); m_DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget); m_DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(ViewMenu)); - m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu)); + /*m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu)); auto TopDockArea = m_DockManager->addDockWidget(ads::TopDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu)); DockWidget = createCalendarDockWidget(ViewMenu); DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false)); @@ -115,15 +116,15 @@ void MainWindow::createContent() m_DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea); auto BottomDockArea = m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea); m_DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea); - m_DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea); + m_DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);*/ } void MainWindow::closeEvent(QCloseEvent* event) { - QSettings Settings("Settings.ini", QSettings::IniFormat); + /*QSettings Settings("Settings.ini", QSettings::IniFormat); Settings.setValue("mainWindow/Geometry", saveGeometry()); - Settings.setValue("mainWindow/DockingState", m_DockManager->saveState()); + Settings.setValue("mainWindow/DockingState", m_DockManager->saveState());*/ QMainWindow::closeEvent(event); } diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index a31cbce..45ce63e 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -291,11 +291,13 @@ void DockContainerWidgetPrivate::saveChildNodesState(QDataStream& stream, QWidge if (Splitter) { stream << NodeSplitter << Splitter->orientation() << Splitter->count(); - std::cout << "NodeSplitter " << Splitter->orientation() << std::endl; + std::cout << "NodeSplitter orient: " << Splitter->orientation() + << " WidgetCont: " << Splitter->count() << std::endl; for (int i = 0; i < Splitter->count(); ++i) { saveChildNodesState(stream, Splitter->widget(i)); } + stream << Splitter->sizes(); } else { @@ -322,28 +324,34 @@ void DockContainerWidgetPrivate::restoreChildNodes(QDataStream& stream, stream >> Orientation >> WidgetCount; std::cout << "Restore NodeSplitter Orientation: " << Orientation << " WidgetCount: " << WidgetCount << std::endl; + QSplitter* Splitter = internal::newSplitter((Qt::Orientation)Orientation); + bool Visible = false; for (int i = 0; i < WidgetCount; ++i) { - QWidget* Widget; - restoreChildNodes(stream, CreatedWidget); + QWidget* ChildNode; + restoreChildNodes(stream, ChildNode); + if (ChildNode) + { + Splitter->addWidget(ChildNode); + } + std::cout << "ChildNode isVisible " << ChildNode->isVisible() + << " isVisibleTo " << ChildNode->isVisibleTo(Splitter) << std::endl; + Visible |= ChildNode->isVisibleTo(Splitter); } - - - /*std::cout << "Restore NodeSplitter " << Orientation << std::endl; - QSplitter* Splitter = internal::newSplitter((Qt::Orientation)Orientation); - if (ParentSplitter) + QList Sizes; + stream >> Sizes; + if (!Splitter->count()) { - ParentSplitter->addWidget(Splitter); + delete Splitter; + Splitter = nullptr; } else { - Parent->layout()->addWidget(Splitter); + Splitter->setSizes(Sizes); + Splitter->setVisible(Visible); } - for (int i = 0; i < Count; ++i) - { - restoreChildNodes(stream, Splitter); - }*/ + CreatedWidget = Splitter; } else { @@ -352,6 +360,8 @@ void DockContainerWidgetPrivate::restoreChildNodes(QDataStream& stream, stream >> Tabs >> CurrentIndex; std::cout << "Restore NodeDockArea Tabs: " << Tabs << " CurrentIndex: " << CurrentIndex << std::endl; + + CDockAreaWidget* DockArea = new CDockAreaWidget(DockManager, _this); for (int i = 0; i < Tabs; ++i) { QString ObjectName; @@ -369,11 +379,19 @@ void DockContainerWidgetPrivate::restoreChildNodes(QDataStream& stream, { std::cout << "Dock Widget found - parent " << DockWidget->parent() << std::endl; + DockArea->addDockWidget(DockWidget); } - - CDockAreaWidget* DockArea = new CDockAreaWidget(DockManager, _this); - DockArea->addDockWidget(DockWidget); + DockWidget->toggleView(!Closed); } + + if (!DockArea->count()) + { + delete DockArea; + DockArea = nullptr; + } + CreatedWidget = DockArea; + DockAreas.append(DockArea); + DockArea->setCurrentIndex(CurrentIndex); } } @@ -680,7 +698,8 @@ QList CDockContainerWidget::openedDockAreas() const //============================================================================ void CDockContainerWidget::saveState(QDataStream& stream) const { - std::cout << "CDockContainerWidget::saveState" << std::endl; + std::cout << "CDockContainerWidget::saveState isFloating " + << isFloating() << std::endl; stream << isFloating(); if (isFloating()) { @@ -688,11 +707,7 @@ void CDockContainerWidget::saveState(QDataStream& stream) const stream << FloatingWidget->saveGeometry(); } - QWidget* RootChild = d->Layout->itemAt(0)->widget(); - if (RootChild) - { - d->saveChildNodesState(stream, RootChild); - } + d->saveChildNodesState(stream, d->RootSplitter); } @@ -702,16 +717,10 @@ bool CDockContainerWidget::restoreState(QDataStream& stream) bool IsFloating; stream >> 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()) + QWidget* NewRootSplitter; + d->DockAreas.clear(); + if (isFloating()) { std::cout << "Restore floating widget" << std::endl; CFloatingDockContainer* FloatingWidget = internal::findParent(this); @@ -719,8 +728,14 @@ bool CDockContainerWidget::restoreState(QDataStream& stream) stream >> Geometry; FloatingWidget->restoreGeometry(Geometry); FloatingWidget->show(); - }*/ + } + d->restoreChildNodes(stream, NewRootSplitter); + + d->Layout->replaceWidget(d->RootSplitter, NewRootSplitter); + QSplitter* OldRoot = d->RootSplitter; + d->RootSplitter = dynamic_cast(NewRootSplitter); + delete OldRoot; return true; } diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index 30b82e3..c49daad 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -148,7 +148,7 @@ void DockWidgetPrivate::hideEmptyParentSplitter() for (int i = 0; i < Splitter->count(); ++i) { - if (Splitter->widget(i)->isVisible()) + if (Splitter->widget(i)->isVisibleTo(Splitter)) { return; } diff --git a/src/DockWidgetTitleBar.cpp b/src/DockWidgetTitleBar.cpp index f4a773a..5aa2662 100644 --- a/src/DockWidgetTitleBar.cpp +++ b/src/DockWidgetTitleBar.cpp @@ -187,7 +187,7 @@ bool DockWidgetTitleBarPrivate::startFloating(const QPoint& GlobalPos) { std::cout << "DockWidgetTitleBarPrivate::startFloating DockArea" << std::endl; // If section widget has only one content widget, we can move the complete - // section widget into floating widget + // dock area into floating widget auto splitter = internal::findParent(DockArea); FloatingWidget = new CFloatingDockContainer(DockArea); }