Skip to content
Snippets Groups Projects
Commit 3a1616e8 authored by Wuttke, Joachim's avatar Wuttke, Joachim Committed by Wuttke, Joachim
Browse files

mv rwSessionItem to SessionItem.h

parent 96597fc9
No related branches found
No related tags found
1 merge request!707Split serializer
......@@ -18,6 +18,7 @@
#include "Base/Util/Assert.h"
#include "Fit/Param/RealLimits.h"
#include "GUI/Model/BaseItem/ModelMapper.h" // no forward declare, used too often
#include "GUI/Model/XML/Serialize.h"
#include "Wrap/WinDllMacros.h"
#include <QStringList>
#include <memory>
......@@ -334,6 +335,20 @@ private:
std::unique_ptr<ModelMapper> m_mapper;
};
// Extends namespace defined in GUI/Model/XML/Serialize.h
namespace Serialize {
//! Only for migration
// #bamigration Remove once the SessionItem migration is done
template <typename type>
void rwSessionItem(Streamer& s, const QString& tag, SessionItem* property);
} // namespace Serialize
// ************************************************************************************************
// Templates implementation
// ************************************************************************************************
template <typename T>
T* SessionItem::item(const QString& tag) const
{
......@@ -408,4 +423,18 @@ bool SessionItem::hasModelType() const
return modelType() == T::M_TYPE;
}
template <typename type>
void Serialize::rwSessionItem(Streamer& s, const QString& tag, SessionItem* property)
{
if (QXmlStreamWriter* w = s.xmlWriter()) {
auto v = property->value().value<type>();
Serialize::rwValue(s, tag, v);
} else if (QXmlStreamReader* r = s.xmlReader()) {
type v;
Serialize::rwValue(s, tag, v);
property->setValue(v);
}
}
#endif // BORNAGAIN_GUI_MODEL_BASEITEM_SESSIONITEM_H
......@@ -126,7 +126,6 @@ private:
};
// Extends namespace defined in GUI/Model/XML/Serialize.h
namespace Serialize {
//! Serializes an item from a catalog.
......
......@@ -16,7 +16,7 @@
#define BORNAGAIN_GUI_MODEL_XML_SERIALIZE_H
#include "GUI/Model/XML/Streamer.h"
#include "GUI/Model/BaseItem/SessionItem.h"
#include <memory>
//! Functions to serialize various data types.
//!
......@@ -60,11 +60,6 @@ template <typename ItemClass, typename... ArgsForConstructor>
void rwOptional(Streamer& s, const QString& tag, std::unique_ptr<ItemClass>& up,
ArgsForConstructor... argsForConstructor);
//! Only for migration
// #bamigration Remove once the SessionItem migration is done
template <typename type>
void rwSessionItem(Streamer& s, const QString& tag, SessionItem* property);
//! Serializes an optional item of known type that needs an initializer.
//!
//! The initializer will be called after creation and before de-serialization
......@@ -165,19 +160,6 @@ void Serialize::rwOptional(Streamer& s, const QString& tag, std::unique_ptr<Item
}
}
template <typename type>
void Serialize::rwSessionItem(Streamer& s, const QString& tag, SessionItem* property)
{
if (QXmlStreamWriter* w = s.xmlWriter()) {
auto v = property->value().value<type>();
Serialize::rwValue(s, tag, v);
} else if (QXmlStreamReader* r = s.xmlReader()) {
type v;
Serialize::rwValue(s, tag, v);
property->setValue(v);
}
}
template <typename ItemClass>
void Serialize::rwInitializable(Streamer& s, const QString& tag, std::unique_ptr<ItemClass>& up,
const std::function<void(ItemClass*)>& initializer)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment