Added initial support for serialization

This commit is contained in:
Uwe Kindler 2017-03-24 16:17:55 +01:00
parent 5dcd15e2b9
commit 2277ba3630
4 changed files with 55 additions and 39 deletions

View File

@ -13,6 +13,7 @@
#include <QFileSystemModel>
#include <QBoxLayout>
#include <QSettings>
#include <QDockWidget>
#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);
}

View File

@ -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<int> 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<CDockAreaWidget*> 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<CFloatingDockContainer*>(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<QSplitter*>(NewRootSplitter);
delete OldRoot;
return true;
}

View File

@ -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;
}

View File

@ -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<QSplitter*>(DockArea);
FloatingWidget = new CFloatingDockContainer(DockArea);
}