@@ -279,6 +279,24 @@ bool DockManagerPrivate::restoreStateFromXml(const QByteArray &state, int versi
279
279
int DockContainers = s.attributes ().value (" Containers" ).toInt ();
280
280
#endif
281
281
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
+
282
300
int DockContainerCount = 0 ;
283
301
while (s.readNextStartElement ())
284
302
{
@@ -405,7 +423,6 @@ bool DockManagerPrivate::restoreState(const QByteArray& State, int version)
405
423
return false ;
406
424
}
407
425
408
- CentralWidget = nullptr ;
409
426
// Hide updates of floating widgets from use
410
427
hideFloatingWidgets ();
411
428
markDockWidgetsDirty ();
@@ -419,6 +436,7 @@ bool DockManagerPrivate::restoreState(const QByteArray& State, int version)
419
436
restoreDockWidgetsOpenState ();
420
437
restoreDockAreasIndices ();
421
438
emitTopLevelEvents ();
439
+ _this->dumpLayout ();
422
440
423
441
return true ;
424
442
}
@@ -636,6 +654,10 @@ QByteArray CDockManager::saveState(int version) const
636
654
s.writeAttribute (" Version" , QString::number (CurrentVersion));
637
655
s.writeAttribute (" UserVersion" , QString::number (version));
638
656
s.writeAttribute (" Containers" , QString::number (d->Containers .count ()));
657
+ if (d->CentralWidget )
658
+ {
659
+ s.writeAttribute (" CentralWidget" , d->CentralWidget ->objectName ());
660
+ }
639
661
for (auto Container : d->Containers )
640
662
{
641
663
Container->saveState (s);
@@ -904,10 +926,20 @@ CDockAreaWidget* CDockManager::setCentralWidget(CDockWidget* widget)
904
926
return nullptr ;
905
927
}
906
928
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
909
931
if (d->CentralWidget )
910
932
{
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." );
911
943
return nullptr ;
912
944
}
913
945
0 commit comments