From 0350acf6dc2f8b7ccf40700904b786f21ae6396f Mon Sep 17 00:00:00 2001
From: Matthias Puchner <github@mpuchner.de>
Date: Mon, 20 Dec 2021 11:57:21 +0100
Subject: [PATCH] cleanup serialization code

---
 GUI/Model/Session/Serializer.cpp |  2 +-
 GUI/Model/Session/Serializer.h   | 13 -------
 GUI/Model/Session/SessionXML.cpp | 61 +++++---------------------------
 GUI/Model/Session/SessionXML.h   | 11 ------
 4 files changed, 9 insertions(+), 78 deletions(-)

diff --git a/GUI/Model/Session/Serializer.cpp b/GUI/Model/Session/Serializer.cpp
index 435ae8db123..08d674c2448 100644
--- a/GUI/Model/Session/Serializer.cpp
+++ b/GUI/Model/Session/Serializer.cpp
@@ -162,7 +162,7 @@ void Serializer::assertCurrentTag(const QString& expectedTag) const
 
     if (m_r->name() != expectedTag) {
 #ifdef _DEBUG
-        // to simplify debbugging: what is the current tag
+        // to simplify debugging: what is the current tag
         QString foundTag = m_r->name().toString();
         Q_UNUSED(foundTag);
 #endif
diff --git a/GUI/Model/Session/Serializer.h b/GUI/Model/Session/Serializer.h
index de4365e6999..b2716c72d9f 100644
--- a/GUI/Model/Session/Serializer.h
+++ b/GUI/Model/Session/Serializer.h
@@ -104,19 +104,6 @@ public:
             read<Catalog>(d.persistentTag(), p);
             d.set(p);
         }
-
-        //         if (m_w) {
-        //             m_w->writeStartElement(d.persistentTag());
-        //             m_w->writeAttribute(Tags::Type,
-        //             QString::number((uint8_t)Catalog::type(d.get()))); if (d.get() != nullptr)
-        //                 d->serialize(*this);
-        //             m_w->writeEndElement();
-        //         } else {
-        //             m_r->readNextStartElement();
-        //             assertCurrentTag(d.persistentTag());
-        //             // #baSerialize ++ implement
-        //             goToEndElementOfTag(d.persistentTag());
-        //         }
     }
 
     template <typename Catalog> void write(const QString& tag, typename Catalog::CatalogedType*& p)
diff --git a/GUI/Model/Session/SessionXML.cpp b/GUI/Model/Session/SessionXML.cpp
index 654d57194e3..50fdd049b14 100644
--- a/GUI/Model/Session/SessionXML.cpp
+++ b/GUI/Model/Session/SessionXML.cpp
@@ -12,14 +12,10 @@
 //
 //  ************************************************************************************************
 
-#include "../Types/DoubleProperty.h"
-#include "../Types/UIntProperty.h"
-#include "../Types/VectorProperty.h"
 #include "GUI/Model/Group/GroupItem.h"
 #include "GUI/Model/Material/MaterialItem.h"
 #include "GUI/Model/Session/SessionItemTags.h"
 #include "GUI/Model/Session/SessionModel.h"
-#include "GUI/Model/Types/DoubleDescriptor.h"
 #include "GUI/Util/ComboProperty.h"
 #include "GUI/Util/DeserializationException.h"
 #include "GUI/Util/Error.h"
@@ -31,11 +27,7 @@
 namespace {
 
 namespace Tags {
-const QString DoubleDescriptor("DoubleDescriptor");
-const QString VectorDescriptor("VectorDescriptor");
 const QString Id("id");
-const QString Value("value");
-const QString Decimals("decimals");
 } // namespace Tags
 
 void report_error(MessageService* messageService, SessionItem* item, const QString& message)
@@ -189,12 +181,6 @@ void GUI::Session::XML::writeUid(QXmlStreamWriter* writer, const QString& id)
     writer->writeAttribute(Tags::Id, id);
 }
 
-void GUI::Session::XML::writeDescriptors(QXmlStreamWriter* writer, const DoubleDescriptors& ds)
-{
-    for (auto d : ds)
-        writeDescriptor(writer, d);
-}
-
 void GUI::Session::XML::writeUid(QXmlStreamWriter* writer, const QUuid& id)
 {
     writer->writeAttribute(Tags::Id, id.toString());
@@ -213,38 +199,6 @@ void GUI::Session::XML::writeVariant(QXmlStreamWriter* writer, QVariant variant,
     }
 }
 
-void GUI::Session::XML::writeDescriptor(QXmlStreamWriter* writer, const DoubleDescriptor& d)
-{
-    // #baSerialize ++ implement writeProperty
-    //     ASSERT(d.path);
-    //     writer->writeStartElement(Tags::DoubleDescriptor);
-    //     writeAttribute(writer, Tags::Value, d.get());
-    //     writeId(writer, d.path());
-    //     writeAttribute(writer, Tags::Value, d.get());
-    //     writer->writeEndElement();
-}
-
-void GUI::Session::XML::writeProperty(QXmlStreamWriter* writer, const DoubleProperty& d)
-{
-    writer->writeStartElement(d.persistentTag());
-    writeAttribute(writer, Tags::Value, d.get());
-    writeUid(writer, d.uid());
-    if (d.decimals() != 3) // don't write the default
-        writeAttribute(writer, Tags::Decimals, d.decimals());
-    writer->writeEndElement();
-}
-
-void GUI::Session::XML::writeProperty(QXmlStreamWriter* writer, const VectorProperty& d)
-{
-    // #baSerialize ++ implement writeProperty
-}
-
-void GUI::Session::XML::writeProperty(QXmlStreamWriter* writer, const UIntProperty& d)
-{
-    // #baSerialize ++ implement writeProperty
-}
-
-
 void GUI::Session::XML::readItems(QXmlStreamReader* reader, SessionItem* parent, QString topTag,
                                   MessageService* messageService)
 {
@@ -431,7 +385,7 @@ void GUI::Session::XML::readAttribute(QXmlStreamReader* reader, const QString& a
 void GUI::Session::XML::readAttribute(QXmlStreamReader* reader, const QString& attributeName,
                                       QColor* c)
 {
-    QString parameter_value = reader->attributes().value(attributeName).toString();
+    const QString parameter_value = reader->attributes().value(attributeName).toString();
     *c = QColor(parameter_value);
 }
 
@@ -463,11 +417,12 @@ void GUI::Session::XML::readAttribute(QXmlStreamReader* reader, const QString& a
 
 void GUI::Session::XML::assertExpectedTag(QXmlStreamReader* reader, const QString& expectedTag)
 {
-    QString foundTag = reader->name().toString();
-    if (foundTag != expectedTag) {
-        // for breakpoints
-        // #baSerialize remove
-        ASSERT(false);
-        // #baSerialize throw!?
+    if (reader->name() != expectedTag) {
+#ifdef _DEBUG
+        // to simplify debugging: what is the current tag
+        QString foundTag = reader->name().toString();
+        Q_UNUSED(foundTag);
+#endif
+        throw DeserializationException::streamError();
     }
 }
diff --git a/GUI/Model/Session/SessionXML.h b/GUI/Model/Session/SessionXML.h
index 7d876f34093..10e7da0a550 100644
--- a/GUI/Model/Session/SessionXML.h
+++ b/GUI/Model/Session/SessionXML.h
@@ -25,11 +25,7 @@
 class QXmlStreamReader;
 class SessionItem;
 class MessageService;
-class VectorDescriptor;
 class QUuid;
-class DoubleProperty;
-class VectorProperty;
-class UIntProperty;
 
 
 namespace GUI::Session::XML {
@@ -79,13 +75,6 @@ void writeAttribute(QXmlStreamWriter* writer, const QString& attributeName, unsi
 void writeAttribute(QXmlStreamWriter* writer, const QString& attributeName, double d);
 void writeAttribute(QXmlStreamWriter* writer, const QString& attributeBaseName, const R3& vec);
 void writeAttribute(QXmlStreamWriter* writer, const QString& attributeBaseName, const complex_t& c);
-void writeDescriptor(QXmlStreamWriter* writer, const DoubleDescriptor& d);
-void writeDescriptor(QXmlStreamWriter* writer, const VectorDescriptor& d);
-void writeDescriptors(QXmlStreamWriter* writer, const DoubleDescriptors& d);
-
-void writeProperty(QXmlStreamWriter* writer, const DoubleProperty& d);
-void writeProperty(QXmlStreamWriter* writer, const VectorProperty& d);
-void writeProperty(QXmlStreamWriter* writer, const UIntProperty& d);
 
 void readItems(QXmlStreamReader* reader, SessionItem* parent, QString topTag = "",
                MessageService* messageService = nullptr);
-- 
GitLab