@@ -279,6 +279,24 @@ bool DockManagerPrivate::restoreStateFromXml(const QByteArray &state, int versi
279279 int DockContainers = s.attributes ().value (" Containers" ).toInt ();
280280#endif
281281 ADS_PRINT (DockContainers);
282+
283+ const auto CentralWidgetAttribute = s.attributes ().value (" CentralWidget" );
284+ // If we have a central widget but a state without central widget, then
285+ // something is wrong.
286+ if (CentralWidget && CentralWidgetAttribute.isEmpty ())
287+ {
288+ qWarning () << " Dock manager has central widget but saved state does not have central widget." ;
289+ return false ;
290+ }
291+
292+ // If the object name of the central widget does not match the name of the
293+ // saved central widget, the something is wrong
294+ if (CentralWidget->objectName () != CentralWidgetAttribute.toString ())
295+ {
296+ qWarning () << " Object name of central widget does not match name of central widget in saved state." ;
297+ return false ;
298+ }
299+
282300 int DockContainerCount = 0 ;
283301 while (s.readNextStartElement ())
284302 {
@@ -405,7 +423,6 @@ bool DockManagerPrivate::restoreState(const QByteArray& State, int version)
405423 return false ;
406424 }
407425
408- CentralWidget = nullptr ;
409426 // Hide updates of floating widgets from use
410427 hideFloatingWidgets ();
411428 markDockWidgetsDirty ();
@@ -419,6 +436,7 @@ bool DockManagerPrivate::restoreState(const QByteArray& State, int version)
419436 restoreDockWidgetsOpenState ();
420437 restoreDockAreasIndices ();
421438 emitTopLevelEvents ();
439+ _this->dumpLayout ();
422440
423441 return true ;
424442}
@@ -636,6 +654,10 @@ QByteArray CDockManager::saveState(int version) const
636654 s.writeAttribute (" Version" , QString::number (CurrentVersion));
637655 s.writeAttribute (" UserVersion" , QString::number (version));
638656 s.writeAttribute (" Containers" , QString::number (d->Containers .count ()));
657+ if (d->CentralWidget )
658+ {
659+ s.writeAttribute (" CentralWidget" , d->CentralWidget ->objectName ());
660+ }
639661 for (auto Container : d->Containers )
640662 {
641663 Container->saveState (s);
@@ -904,10 +926,20 @@ CDockAreaWidget* CDockManager::setCentralWidget(CDockWidget* widget)
904926 return nullptr ;
905927 }
906928
907- // Setting a new central widget is now allowed if there is alread a central
908- // widget
929+ // Setting a new central widget is now allowed if there is already a central
930+ // widget or if there are already other dock widgets
909931 if (d->CentralWidget )
910932 {
933+ qWarning (" Setting a central widget not possible because there is already a central widget." );
934+ return nullptr ;
935+ }
936+
937+ // Setting a central widget is now allowed if there are already other
938+ // dock widgets.
939+ if (!d->DockWidgetsMap .isEmpty ())
940+ {
941+ qWarning (" Setting a central widget not possible - the central widget need to be the first "
942+ " dock widget that is added to the dock manager." );
911943 return nullptr ;
912944 }
913945
0 commit comments