@@ -122,9 +122,28 @@ struct DockContainerWidgetPrivate
122
122
void saveChildNodesState (QDataStream& Stream, QWidget* Widget);
123
123
124
124
/* *
125
- * Restore state of child nodes
125
+ * Restore state of child nodes.
126
+ * \param[in] Stream The data stream that contains the serialized state
127
+ * \param[out] CreatedWidget The widget created from parsed data
128
+ * \param[in] Testing If Testing is true, only the stream data is
129
+ * parsed without modifiying anything.
126
130
*/
127
- void restoreChildNodes (QDataStream& Stream, QWidget*& CreatedWidget);
131
+ bool restoreChildNodes (QDataStream& Stream, QWidget*& CreatedWidget,
132
+ bool Testing);
133
+
134
+ /* *
135
+ * Restores a splitter.
136
+ * \see restoreChildNodes() for details
137
+ */
138
+ bool restoreSplitter (QDataStream& Stream, QWidget*& CreatedWidget,
139
+ bool Testing);
140
+
141
+ /* *
142
+ * Restores a dock area.
143
+ * \see restoreChildNodes() for details
144
+ */
145
+ bool restoreDockArea (QDataStream& Stream, QWidget*& CreatedWidget,
146
+ bool Testing);
128
147
}; // struct DockContainerWidgetPrivate
129
148
130
149
@@ -290,7 +309,7 @@ void DockContainerWidgetPrivate::saveChildNodesState(QDataStream& stream, QWidge
290
309
QSplitter* Splitter = dynamic_cast <QSplitter*>(Widget);
291
310
if (Splitter)
292
311
{
293
- stream << NodeSplitter << Splitter->orientation () << Splitter->count ();
312
+ stream << internal::SplitterMarker << Splitter->orientation () << Splitter->count ();
294
313
std::cout << " NodeSplitter orient: " << Splitter->orientation ()
295
314
<< " WidgetCont: " << Splitter->count () << std::endl;
296
315
for (int i = 0 ; i < Splitter->count (); ++i)
@@ -301,7 +320,7 @@ void DockContainerWidgetPrivate::saveChildNodesState(QDataStream& stream, QWidge
301
320
}
302
321
else
303
322
{
304
- stream << NodeDockArea ;
323
+ stream << internal::DockAreaMarker ;
305
324
CDockAreaWidget* DockArea = dynamic_cast <CDockAreaWidget*>(Widget);
306
325
if (DockArea)
307
326
{
@@ -312,35 +331,43 @@ void DockContainerWidgetPrivate::saveChildNodesState(QDataStream& stream, QWidge
312
331
313
332
314
333
// ============================================================================
315
- void DockContainerWidgetPrivate::restoreChildNodes (QDataStream& stream,
316
- QWidget*& CreatedWidget)
334
+ bool DockContainerWidgetPrivate::restoreSplitter (QDataStream& stream,
335
+ QWidget*& CreatedWidget, bool Testing )
317
336
{
318
- int NodeType;
319
- stream >> NodeType;
320
- if (NodeSplitter == NodeType)
321
- {
322
- int Orientation;
323
- int WidgetCount;
324
- stream >> Orientation >> WidgetCount;
325
- std::cout << " Restore NodeSplitter Orientation: " << Orientation <<
326
- " WidgetCount: " << WidgetCount << std::endl;
327
- QSplitter* Splitter = internal::newSplitter ((Qt::Orientation)Orientation);
328
- bool Visible = false ;
329
- for (int i = 0 ; i < WidgetCount; ++i)
337
+ int Orientation;
338
+ int WidgetCount;
339
+ stream >> Orientation >> WidgetCount;
340
+ std::cout << " Restore NodeSplitter Orientation: " << Orientation <<
341
+ " WidgetCount: " << WidgetCount << std::endl;
342
+ QSplitter* Splitter = nullptr ;
343
+ if (!Testing)
344
+ {
345
+ Splitter = internal::newSplitter ((Qt::Orientation)Orientation);
346
+ }
347
+ bool Visible = false ;
348
+ for (int i = 0 ; i < WidgetCount; ++i)
349
+ {
350
+ QWidget* ChildNode;
351
+ if (!restoreChildNodes (stream, ChildNode, Testing))
330
352
{
331
- QWidget* ChildNode;
332
- restoreChildNodes (stream, ChildNode);
333
- if (ChildNode)
334
- {
335
- Splitter->addWidget (ChildNode);
336
- }
337
- std::cout << " ChildNode isVisible " << ChildNode->isVisible ()
338
- << " isVisibleTo " << ChildNode->isVisibleTo (Splitter) << std::endl;
339
- Visible |= ChildNode->isVisibleTo (Splitter);
353
+ return false ;
354
+ }
355
+
356
+ if (Testing)
357
+ {
358
+ continue ;
340
359
}
341
360
342
- QList<int > Sizes;
343
- stream >> Sizes;
361
+ std::cout << " ChildNode isVisible " << ChildNode->isVisible ()
362
+ << " isVisibleTo " << ChildNode->isVisibleTo (Splitter) << std::endl;
363
+ Splitter->addWidget (ChildNode);
364
+ Visible |= ChildNode->isVisibleTo (Splitter);
365
+ }
366
+
367
+ QList<int > Sizes;
368
+ stream >> Sizes;
369
+ if (!Testing)
370
+ {
344
371
if (!Splitter->count ())
345
372
{
346
373
delete Splitter;
@@ -355,43 +382,89 @@ void DockContainerWidgetPrivate::restoreChildNodes(QDataStream& stream,
355
382
}
356
383
else
357
384
{
358
- int Tabs;
359
- int CurrentIndex;
360
- stream >> Tabs >> CurrentIndex;
361
- std::cout << " Restore NodeDockArea Tabs: " << Tabs << " CurrentIndex: "
362
- << CurrentIndex << std::endl;
385
+ CreatedWidget = nullptr ;
386
+ }
387
+ return true ;
388
+ }
363
389
364
- CDockAreaWidget* DockArea = new CDockAreaWidget (DockManager, _this);
365
- for (int i = 0 ; i < Tabs; ++i)
390
+
391
+ // ============================================================================
392
+ bool DockContainerWidgetPrivate::restoreDockArea (QDataStream& stream,
393
+ QWidget*& CreatedWidget, bool Testing)
394
+ {
395
+ int Tabs;
396
+ int CurrentIndex;
397
+ stream >> Tabs >> CurrentIndex;
398
+ std::cout << " Restore NodeDockArea Tabs: " << Tabs << " CurrentIndex: "
399
+ << CurrentIndex << std::endl;
400
+
401
+ CDockAreaWidget* DockArea = nullptr ;
402
+ if (!Testing)
403
+ {
404
+ DockArea = new CDockAreaWidget (DockManager, _this);
405
+ }
406
+
407
+ for (int i = 0 ; i < Tabs; ++i)
408
+ {
409
+ int Marker;
410
+ stream >> Marker;
411
+ if (Marker != internal::DockWidgetMarker)
366
412
{
367
- QString ObjectName;
368
- bool Closed;
369
- stream >> ObjectName >> Closed;
370
- std::cout << " Restore DockWidget " << ObjectName.toStdString () << " Closed: "
371
- << Closed << std::endl;
372
-
373
- CDockWidget* DockWidget = DockManager->findChild <CDockWidget*>(ObjectName);
374
- if (!DockWidget)
375
- {
376
- continue ;
377
- }
378
- else
379
- {
380
- std::cout << " Dock Widget found - parent " << DockWidget->parent ()
381
- << std::endl;
382
- DockArea->addDockWidget (DockWidget);
383
- }
384
- DockWidget->toggleView (!Closed);
413
+ return false ;
385
414
}
386
415
387
- if (!DockArea->count ())
416
+ QString ObjectName;
417
+ bool Closed;
418
+ stream >> ObjectName >> Closed;
419
+ std::cout << " Restore DockWidget " << ObjectName.toStdString () << " Closed: "
420
+ << Closed << std::endl;
421
+
422
+ CDockWidget* DockWidget = DockManager->findDockWidget (ObjectName);
423
+ if (!DockWidget || Testing)
388
424
{
389
- delete DockArea;
390
- DockArea = nullptr ;
425
+ continue ;
391
426
}
392
- CreatedWidget = DockArea;
393
- DockAreas.append (DockArea);
394
- DockArea->setCurrentIndex (CurrentIndex);
427
+
428
+ std::cout << " Dock Widget found - parent " << DockWidget->parent ()
429
+ << std::endl;
430
+ DockArea->addDockWidget (DockWidget);
431
+ DockWidget->toggleView (!Closed);
432
+ }
433
+
434
+ if (Testing)
435
+ {
436
+ return true ;
437
+ }
438
+
439
+ if (!DockArea->count ())
440
+ {
441
+ delete DockArea;
442
+ DockArea = nullptr ;
443
+ }
444
+ CreatedWidget = DockArea;
445
+ DockAreas.append (DockArea);
446
+ DockArea->setCurrentIndex (CurrentIndex);
447
+ return true ;
448
+ }
449
+
450
+
451
+ // ============================================================================
452
+ bool DockContainerWidgetPrivate::restoreChildNodes (QDataStream& stream,
453
+ QWidget*& CreatedWidget, bool Testing)
454
+ {
455
+ int Marker;
456
+ stream >> Marker;
457
+ if (internal::SplitterMarker == Marker)
458
+ {
459
+ return restoreSplitter (stream, CreatedWidget, Testing);
460
+ }
461
+ else if (internal::DockAreaMarker == Marker)
462
+ {
463
+ return restoreDockArea (stream, CreatedWidget, Testing);
464
+ }
465
+ else
466
+ {
467
+ return false ;
395
468
}
396
469
}
397
470
@@ -700,6 +773,7 @@ void CDockContainerWidget::saveState(QDataStream& stream) const
700
773
{
701
774
std::cout << " CDockContainerWidget::saveState isFloating "
702
775
<< isFloating () << std::endl;
776
+ stream << internal::ContainerMarker;
703
777
stream << isFloating ();
704
778
if (isFloating ())
705
779
{
@@ -712,30 +786,52 @@ void CDockContainerWidget::saveState(QDataStream& stream) const
712
786
713
787
714
788
// ============================================================================
715
- bool CDockContainerWidget::restoreState (QDataStream& stream)
789
+ bool CDockContainerWidget::restoreState (QDataStream& stream, bool Testing )
716
790
{
717
791
bool IsFloating;
792
+ int Marker;
793
+ stream >> Marker;
794
+ if (Marker != internal::ContainerMarker)
795
+ {
796
+ return false ;
797
+ }
798
+
718
799
stream >> IsFloating;
719
800
std::cout << " Restore CDockContainerWidget Floating" << IsFloating << std::endl;
720
801
721
802
QWidget* NewRootSplitter;
722
- d->DockAreas .clear ();
723
- if (isFloating ())
803
+ if (!Testing)
804
+ {
805
+ d->DockAreas .clear ();
806
+ }
807
+
808
+ if (IsFloating)
724
809
{
725
810
std::cout << " Restore floating widget" << std::endl;
726
- CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(this );
727
811
QByteArray Geometry;
728
812
stream >> Geometry;
729
- FloatingWidget->restoreGeometry (Geometry);
730
- FloatingWidget->show ();
813
+ if (!Testing)
814
+ {
815
+ CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(this );
816
+ FloatingWidget->restoreGeometry (Geometry);
817
+ FloatingWidget->show ();
818
+ }
819
+ }
820
+
821
+ if (!d->restoreChildNodes (stream, NewRootSplitter, Testing))
822
+ {
823
+ return false ;
731
824
}
732
825
733
- d->restoreChildNodes (stream, NewRootSplitter);
826
+ if (Testing)
827
+ {
828
+ return true ;
829
+ }
734
830
735
831
d->Layout ->replaceWidget (d->RootSplitter , NewRootSplitter);
736
832
QSplitter* OldRoot = d->RootSplitter ;
737
833
d->RootSplitter = dynamic_cast <QSplitter*>(NewRootSplitter);
738
- delete OldRoot;
834
+ OldRoot-> deleteLater () ;
739
835
return true ;
740
836
}
741
837
0 commit comments