Skip to content

Commit 1b1c636

Browse files
author
Uwe Kindler
committed
Improved serialization support
1 parent 2277ba3 commit 1b1c636

File tree

8 files changed

+335
-106
lines changed

8 files changed

+335
-106
lines changed

.settings/language.settings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
66
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
77
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="(g?cc)|([gc]\+\+)|(clang)" prefer-non-shared="true"/>
8-
<provider class="org.eclipse.cdt.managedbuilder.internal.language.settings.providers.GCCBuiltinSpecsDetectorMinGW" console="false" env-hash="1111767096691303650" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetectorMinGW" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings MinGW" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
8+
<provider class="org.eclipse.cdt.managedbuilder.internal.language.settings.providers.GCCBuiltinSpecsDetectorMinGW" console="false" env-hash="-797032510223863550" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetectorMinGW" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings MinGW" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
99
<language-scope id="org.eclipse.cdt.core.gcc"/>
1010
<language-scope id="org.eclipse.cdt.core.g++"/>
1111
</provider>

src/DockContainerWidget.cpp

Lines changed: 164 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,28 @@ struct DockContainerWidgetPrivate
122122
void saveChildNodesState(QDataStream& Stream, QWidget* Widget);
123123

124124
/**
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.
126130
*/
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);
128147
}; // struct DockContainerWidgetPrivate
129148

130149

@@ -290,7 +309,7 @@ void DockContainerWidgetPrivate::saveChildNodesState(QDataStream& stream, QWidge
290309
QSplitter* Splitter = dynamic_cast<QSplitter*>(Widget);
291310
if (Splitter)
292311
{
293-
stream << NodeSplitter << Splitter->orientation() << Splitter->count();
312+
stream << internal::SplitterMarker << Splitter->orientation() << Splitter->count();
294313
std::cout << "NodeSplitter orient: " << Splitter->orientation()
295314
<< " WidgetCont: " << Splitter->count() << std::endl;
296315
for (int i = 0; i < Splitter->count(); ++i)
@@ -301,7 +320,7 @@ void DockContainerWidgetPrivate::saveChildNodesState(QDataStream& stream, QWidge
301320
}
302321
else
303322
{
304-
stream << NodeDockArea;
323+
stream << internal::DockAreaMarker;
305324
CDockAreaWidget* DockArea = dynamic_cast<CDockAreaWidget*>(Widget);
306325
if (DockArea)
307326
{
@@ -312,35 +331,43 @@ void DockContainerWidgetPrivate::saveChildNodesState(QDataStream& stream, QWidge
312331

313332

314333
//============================================================================
315-
void DockContainerWidgetPrivate::restoreChildNodes(QDataStream& stream,
316-
QWidget*& CreatedWidget)
334+
bool DockContainerWidgetPrivate::restoreSplitter(QDataStream& stream,
335+
QWidget*& CreatedWidget, bool Testing)
317336
{
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))
330352
{
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;
340359
}
341360

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+
{
344371
if (!Splitter->count())
345372
{
346373
delete Splitter;
@@ -355,43 +382,89 @@ void DockContainerWidgetPrivate::restoreChildNodes(QDataStream& stream,
355382
}
356383
else
357384
{
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+
}
363389

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)
366412
{
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;
385414
}
386415

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)
388424
{
389-
delete DockArea;
390-
DockArea = nullptr;
425+
continue;
391426
}
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;
395468
}
396469
}
397470

@@ -700,6 +773,7 @@ void CDockContainerWidget::saveState(QDataStream& stream) const
700773
{
701774
std::cout << "CDockContainerWidget::saveState isFloating "
702775
<< isFloating() << std::endl;
776+
stream << internal::ContainerMarker;
703777
stream << isFloating();
704778
if (isFloating())
705779
{
@@ -712,30 +786,52 @@ void CDockContainerWidget::saveState(QDataStream& stream) const
712786

713787

714788
//============================================================================
715-
bool CDockContainerWidget::restoreState(QDataStream& stream)
789+
bool CDockContainerWidget::restoreState(QDataStream& stream, bool Testing)
716790
{
717791
bool IsFloating;
792+
int Marker;
793+
stream >> Marker;
794+
if (Marker != internal::ContainerMarker)
795+
{
796+
return false;
797+
}
798+
718799
stream >> IsFloating;
719800
std::cout << "Restore CDockContainerWidget Floating" << IsFloating << std::endl;
720801

721802
QWidget* NewRootSplitter;
722-
d->DockAreas.clear();
723-
if (isFloating())
803+
if (!Testing)
804+
{
805+
d->DockAreas.clear();
806+
}
807+
808+
if (IsFloating)
724809
{
725810
std::cout << "Restore floating widget" << std::endl;
726-
CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(this);
727811
QByteArray Geometry;
728812
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;
731824
}
732825

733-
d->restoreChildNodes(stream, NewRootSplitter);
826+
if (Testing)
827+
{
828+
return true;
829+
}
734830

735831
d->Layout->replaceWidget(d->RootSplitter, NewRootSplitter);
736832
QSplitter* OldRoot = d->RootSplitter;
737833
d->RootSplitter = dynamic_cast<QSplitter*>(NewRootSplitter);
738-
delete OldRoot;
834+
OldRoot->deleteLater();
739835
return true;
740836
}
741837

src/DockContainerWidget.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,12 @@ class CDockContainerWidget : public QFrame
140140
void saveState(QDataStream& Stream) const;
141141

142142
/**
143-
* Restores the state from given stream
143+
* Restores the state from given stream.
144+
* If Testing is true, the function only parses the data from the given
145+
* stream but does not restore anything. You can use this check for
146+
* faulty files before you start restoring the state
144147
*/
145-
bool restoreState(QDataStream& Stream);
148+
bool restoreState(QDataStream& Stream, bool Testing);
146149

147150
signals:
148151
/**

0 commit comments

Comments
 (0)