mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-11-15 13:15:43 +08:00
Added initial support for serialization
This commit is contained in:
parent
5dcd15e2b9
commit
2277ba3630
@ -13,6 +13,7 @@
|
|||||||
#include <QFileSystemModel>
|
#include <QFileSystemModel>
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QDockWidget>
|
||||||
|
|
||||||
#include "DockManager.h"
|
#include "DockManager.h"
|
||||||
#include "DockWidget.h"
|
#include "DockWidget.h"
|
||||||
@ -104,7 +105,7 @@ void MainWindow::createContent()
|
|||||||
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
|
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
|
||||||
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget);
|
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget);
|
||||||
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(ViewMenu));
|
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));
|
auto TopDockArea = m_DockManager->addDockWidget(ads::TopDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
|
||||||
DockWidget = createCalendarDockWidget(ViewMenu);
|
DockWidget = createCalendarDockWidget(ViewMenu);
|
||||||
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
|
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
|
||||||
@ -115,15 +116,15 @@ void MainWindow::createContent()
|
|||||||
m_DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
|
m_DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
|
||||||
auto BottomDockArea = m_DockManager->addDockWidget(ads::BottomDockWidgetArea, 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::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)
|
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/Geometry", saveGeometry());
|
||||||
Settings.setValue("mainWindow/DockingState", m_DockManager->saveState());
|
Settings.setValue("mainWindow/DockingState", m_DockManager->saveState());*/
|
||||||
QMainWindow::closeEvent(event);
|
QMainWindow::closeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,11 +291,13 @@ void DockContainerWidgetPrivate::saveChildNodesState(QDataStream& stream, QWidge
|
|||||||
if (Splitter)
|
if (Splitter)
|
||||||
{
|
{
|
||||||
stream << NodeSplitter << Splitter->orientation() << Splitter->count();
|
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)
|
for (int i = 0; i < Splitter->count(); ++i)
|
||||||
{
|
{
|
||||||
saveChildNodesState(stream, Splitter->widget(i));
|
saveChildNodesState(stream, Splitter->widget(i));
|
||||||
}
|
}
|
||||||
|
stream << Splitter->sizes();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -322,28 +324,34 @@ void DockContainerWidgetPrivate::restoreChildNodes(QDataStream& stream,
|
|||||||
stream >> Orientation >> WidgetCount;
|
stream >> Orientation >> WidgetCount;
|
||||||
std::cout << "Restore NodeSplitter Orientation: " << Orientation <<
|
std::cout << "Restore NodeSplitter Orientation: " << Orientation <<
|
||||||
" WidgetCount: " << WidgetCount << std::endl;
|
" WidgetCount: " << WidgetCount << std::endl;
|
||||||
|
QSplitter* Splitter = internal::newSplitter((Qt::Orientation)Orientation);
|
||||||
|
bool Visible = false;
|
||||||
for (int i = 0; i < WidgetCount; ++i)
|
for (int i = 0; i < WidgetCount; ++i)
|
||||||
{
|
{
|
||||||
QWidget* Widget;
|
QWidget* ChildNode;
|
||||||
restoreChildNodes(stream, CreatedWidget);
|
restoreChildNodes(stream, ChildNode);
|
||||||
|
if (ChildNode)
|
||||||
|
{
|
||||||
|
Splitter->addWidget(ChildNode);
|
||||||
|
}
|
||||||
|
std::cout << "ChildNode isVisible " << ChildNode->isVisible()
|
||||||
|
<< " isVisibleTo " << ChildNode->isVisibleTo(Splitter) << std::endl;
|
||||||
|
Visible |= ChildNode->isVisibleTo(Splitter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<int> Sizes;
|
||||||
|
stream >> Sizes;
|
||||||
/*std::cout << "Restore NodeSplitter " << Orientation << std::endl;
|
if (!Splitter->count())
|
||||||
QSplitter* Splitter = internal::newSplitter((Qt::Orientation)Orientation);
|
|
||||||
if (ParentSplitter)
|
|
||||||
{
|
{
|
||||||
ParentSplitter->addWidget(Splitter);
|
delete Splitter;
|
||||||
|
Splitter = nullptr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Parent->layout()->addWidget(Splitter);
|
Splitter->setSizes(Sizes);
|
||||||
|
Splitter->setVisible(Visible);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < Count; ++i)
|
CreatedWidget = Splitter;
|
||||||
{
|
|
||||||
restoreChildNodes(stream, Splitter);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -352,6 +360,8 @@ void DockContainerWidgetPrivate::restoreChildNodes(QDataStream& stream,
|
|||||||
stream >> Tabs >> CurrentIndex;
|
stream >> Tabs >> CurrentIndex;
|
||||||
std::cout << "Restore NodeDockArea Tabs: " << Tabs << " CurrentIndex: "
|
std::cout << "Restore NodeDockArea Tabs: " << Tabs << " CurrentIndex: "
|
||||||
<< CurrentIndex << std::endl;
|
<< CurrentIndex << std::endl;
|
||||||
|
|
||||||
|
CDockAreaWidget* DockArea = new CDockAreaWidget(DockManager, _this);
|
||||||
for (int i = 0; i < Tabs; ++i)
|
for (int i = 0; i < Tabs; ++i)
|
||||||
{
|
{
|
||||||
QString ObjectName;
|
QString ObjectName;
|
||||||
@ -369,11 +379,19 @@ void DockContainerWidgetPrivate::restoreChildNodes(QDataStream& stream,
|
|||||||
{
|
{
|
||||||
std::cout << "Dock Widget found - parent " << DockWidget->parent()
|
std::cout << "Dock Widget found - parent " << DockWidget->parent()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
|
||||||
|
|
||||||
CDockAreaWidget* DockArea = new CDockAreaWidget(DockManager, _this);
|
|
||||||
DockArea->addDockWidget(DockWidget);
|
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
|
void CDockContainerWidget::saveState(QDataStream& stream) const
|
||||||
{
|
{
|
||||||
std::cout << "CDockContainerWidget::saveState" << std::endl;
|
std::cout << "CDockContainerWidget::saveState isFloating "
|
||||||
|
<< isFloating() << std::endl;
|
||||||
stream << isFloating();
|
stream << isFloating();
|
||||||
if (isFloating())
|
if (isFloating())
|
||||||
{
|
{
|
||||||
@ -688,11 +707,7 @@ void CDockContainerWidget::saveState(QDataStream& stream) const
|
|||||||
stream << FloatingWidget->saveGeometry();
|
stream << FloatingWidget->saveGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* RootChild = d->Layout->itemAt(0)->widget();
|
d->saveChildNodesState(stream, d->RootSplitter);
|
||||||
if (RootChild)
|
|
||||||
{
|
|
||||||
d->saveChildNodesState(stream, RootChild);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -702,16 +717,10 @@ bool CDockContainerWidget::restoreState(QDataStream& stream)
|
|||||||
bool IsFloating;
|
bool IsFloating;
|
||||||
stream >> IsFloating;
|
stream >> IsFloating;
|
||||||
std::cout << "Restore CDockContainerWidget Floating" << IsFloating << std::endl;
|
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;
|
std::cout << "Restore floating widget" << std::endl;
|
||||||
CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(this);
|
CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(this);
|
||||||
@ -719,8 +728,14 @@ bool CDockContainerWidget::restoreState(QDataStream& stream)
|
|||||||
stream >> Geometry;
|
stream >> Geometry;
|
||||||
FloatingWidget->restoreGeometry(Geometry);
|
FloatingWidget->restoreGeometry(Geometry);
|
||||||
FloatingWidget->show();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ void DockWidgetPrivate::hideEmptyParentSplitter()
|
|||||||
|
|
||||||
for (int i = 0; i < Splitter->count(); ++i)
|
for (int i = 0; i < Splitter->count(); ++i)
|
||||||
{
|
{
|
||||||
if (Splitter->widget(i)->isVisible())
|
if (Splitter->widget(i)->isVisibleTo(Splitter))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ bool DockWidgetTitleBarPrivate::startFloating(const QPoint& GlobalPos)
|
|||||||
{
|
{
|
||||||
std::cout << "DockWidgetTitleBarPrivate::startFloating DockArea" << std::endl;
|
std::cout << "DockWidgetTitleBarPrivate::startFloating DockArea" << std::endl;
|
||||||
// If section widget has only one content widget, we can move the complete
|
// 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);
|
auto splitter = internal::findParent<QSplitter*>(DockArea);
|
||||||
FloatingWidget = new CFloatingDockContainer(DockArea);
|
FloatingWidget = new CFloatingDockContainer(DockArea);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user