From a010c2012f103dabb4b9be4126fc18219f24883b Mon Sep 17 00:00:00 2001 From: Arin Alex Date: Wed, 29 Jun 2016 21:22:31 +0300 Subject: [PATCH] QVariant serializator has been added --- .../lrxmlbasetypesserializators.cpp | 20 +++++++++++++++++++ .../lrxmlbasetypesserializators.h | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/limereport/serializators/lrxmlbasetypesserializators.cpp b/limereport/serializators/lrxmlbasetypesserializators.cpp index 3cc6543..ac82079 100644 --- a/limereport/serializators/lrxmlbasetypesserializators.cpp +++ b/limereport/serializators/lrxmlbasetypesserializators.cpp @@ -76,6 +76,10 @@ LimeReport::SerializatorIntf* createQByteArraySerializator(QDomDocument *doc, QD return new LimeReport::XmlQByteArraySerializator(doc,node); } +LimeReport::SerializatorIntf* createQVariantSerializator(QDomDocument *doc, QDomElement *node){ + return new LimeReport::XmlQVariantSerializator(doc,node); +} + bool registredQString = LimeReport::XMLAbstractSerializatorFactory::instance().registerCreator("QString", createQStringSerializator); bool registredInt = LimeReport::XMLAbstractSerializatorFactory::instance().registerCreator("int", createIntSerializator); bool registredEnumAndFlags = LimeReport::XMLAbstractSerializatorFactory::instance().registerCreator("enumAndFlags",createEnumAndFlagsSerializator); @@ -87,6 +91,7 @@ bool registredQReal = LimeReport::XMLAbstractSerializatorFactory::instance().reg bool registerDouble = LimeReport::XMLAbstractSerializatorFactory::instance().registerCreator("double", createQRealSerializator); bool registerQColor = LimeReport::XMLAbstractSerializatorFactory::instance().registerCreator("QColor", createQColorSerializator); bool registerQByteArray = LimeReport::XMLAbstractSerializatorFactory::instance().registerCreator("QByteArray", createQByteArraySerializator); +bool registerQVariant = LimeReport::XMLAbstractSerializatorFactory::instance().registerCreator("QVariant", createQVariantSerializator); } @@ -275,6 +280,21 @@ QVariant XmlQByteArraySerializator::loadValue() return QByteArray::fromBase64(ba); } +void XmlQVariantSerializator::save(const QVariant &value, QString name) +{ + QDomElement _node = doc()->createElement(name); + _node.setAttribute("Type","QVariant"); + _node.setAttribute("Value",QString(value.toByteArray().toBase64())); + node()->appendChild(_node); +} + +QVariant XmlQVariantSerializator::loadValue() +{ + QByteArray ba; + ba.append(node()->attribute("Value").toLatin1()); + return QByteArray::fromBase64(ba); +} + } diff --git a/limereport/serializators/lrxmlbasetypesserializators.h b/limereport/serializators/lrxmlbasetypesserializators.h index 18dfb81..70bd40d 100644 --- a/limereport/serializators/lrxmlbasetypesserializators.h +++ b/limereport/serializators/lrxmlbasetypesserializators.h @@ -137,5 +137,14 @@ private: virtual QVariant loadValue(); }; +class XmlQVariantSerializator : public XmlBaseSerializator +{ +public: + XmlQVariantSerializator(QDomDocument *doc, QDomElement *node):XmlBaseSerializator(doc,node){} +private: + virtual void save(const QVariant &value, QString name); + virtual QVariant loadValue(); +}; + } #endif // LRXMLBASETYPESSERIALIZATORS_H