mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-01-26 14:29:02 +08:00
Properly implemented save and restore with central widget
This commit is contained in:
parent
1c261515db
commit
c370875128
@ -279,6 +279,24 @@ bool DockManagerPrivate::restoreStateFromXml(const QByteArray &state, int versi
|
|||||||
int DockContainers = s.attributes().value("Containers").toInt();
|
int DockContainers = s.attributes().value("Containers").toInt();
|
||||||
#endif
|
#endif
|
||||||
ADS_PRINT(DockContainers);
|
ADS_PRINT(DockContainers);
|
||||||
|
|
||||||
|
const auto CentralWidgetAttribute = s.attributes().value("CentralWidget");
|
||||||
|
// If we have a central widget but a state without central widget, then
|
||||||
|
// something is wrong.
|
||||||
|
if (CentralWidget && CentralWidgetAttribute.isEmpty())
|
||||||
|
{
|
||||||
|
qWarning() << "Dock manager has central widget but saved state does not have central widget.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the object name of the central widget does not match the name of the
|
||||||
|
// saved central widget, the something is wrong
|
||||||
|
if (CentralWidget->objectName() != CentralWidgetAttribute.toString())
|
||||||
|
{
|
||||||
|
qWarning() << "Object name of central widget does not match name of central widget in saved state.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int DockContainerCount = 0;
|
int DockContainerCount = 0;
|
||||||
while (s.readNextStartElement())
|
while (s.readNextStartElement())
|
||||||
{
|
{
|
||||||
@ -405,7 +423,6 @@ bool DockManagerPrivate::restoreState(const QByteArray& State, int version)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CentralWidget = nullptr;
|
|
||||||
// Hide updates of floating widgets from use
|
// Hide updates of floating widgets from use
|
||||||
hideFloatingWidgets();
|
hideFloatingWidgets();
|
||||||
markDockWidgetsDirty();
|
markDockWidgetsDirty();
|
||||||
@ -419,6 +436,7 @@ bool DockManagerPrivate::restoreState(const QByteArray& State, int version)
|
|||||||
restoreDockWidgetsOpenState();
|
restoreDockWidgetsOpenState();
|
||||||
restoreDockAreasIndices();
|
restoreDockAreasIndices();
|
||||||
emitTopLevelEvents();
|
emitTopLevelEvents();
|
||||||
|
_this->dumpLayout();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -636,6 +654,10 @@ QByteArray CDockManager::saveState(int version) const
|
|||||||
s.writeAttribute("Version", QString::number(CurrentVersion));
|
s.writeAttribute("Version", QString::number(CurrentVersion));
|
||||||
s.writeAttribute("UserVersion", QString::number(version));
|
s.writeAttribute("UserVersion", QString::number(version));
|
||||||
s.writeAttribute("Containers", QString::number(d->Containers.count()));
|
s.writeAttribute("Containers", QString::number(d->Containers.count()));
|
||||||
|
if (d->CentralWidget)
|
||||||
|
{
|
||||||
|
s.writeAttribute("CentralWidget", d->CentralWidget->objectName());
|
||||||
|
}
|
||||||
for (auto Container : d->Containers)
|
for (auto Container : d->Containers)
|
||||||
{
|
{
|
||||||
Container->saveState(s);
|
Container->saveState(s);
|
||||||
@ -904,10 +926,20 @@ CDockAreaWidget* CDockManager::setCentralWidget(CDockWidget* widget)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setting a new central widget is now allowed if there is alread a central
|
// Setting a new central widget is now allowed if there is already a central
|
||||||
// widget
|
// widget or if there are already other dock widgets
|
||||||
if (d->CentralWidget)
|
if (d->CentralWidget)
|
||||||
{
|
{
|
||||||
|
qWarning("Setting a central widget not possible because there is already a central widget.");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setting a central widget is now allowed if there are already other
|
||||||
|
// dock widgets.
|
||||||
|
if (!d->DockWidgetsMap.isEmpty())
|
||||||
|
{
|
||||||
|
qWarning("Setting a central widget not possible - the central widget need to be the first "
|
||||||
|
"dock widget that is added to the dock manager.");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,9 +398,12 @@ public:
|
|||||||
* movable, floatable or closable and the titlebar of the central
|
* movable, floatable or closable and the titlebar of the central
|
||||||
* dock area is not visible.
|
* dock area is not visible.
|
||||||
* If the given widget could be set as central widget, the function returns
|
* If the given widget could be set as central widget, the function returns
|
||||||
* the created cok area. If the widget could not be set, because there
|
* the created dock area. If the widget could not be set, because there
|
||||||
* is already a central widget, this function returns a nullptr.
|
* is already a central widget, this function returns a nullptr.
|
||||||
* To clear the central widget, pass a nullptr to the function.
|
* To clear the central widget, pass a nullptr to the function.
|
||||||
|
* \note Setting a central widget is only possible if no other dock widgets
|
||||||
|
* have been registered before. That means, this function should be the
|
||||||
|
* first function that you call before you add other dock widgets.
|
||||||
* \retval != 0 The dock area that contains the central widget
|
* \retval != 0 The dock area that contains the central widget
|
||||||
* \retval nullptr Indicates that the given widget can not be set as central
|
* \retval nullptr Indicates that the given widget can not be set as central
|
||||||
* widget because there is already a central widget.
|
* widget because there is already a central widget.
|
||||||
|
Loading…
Reference in New Issue
Block a user