mirror of
https://github.com/fralx/LimeReport.git
synced 2025-09-23 08:29:07 +03:00
Change to subforder project model.
This commit is contained in:
44
limereport/serializators/lrserializatorintf.h
Normal file
44
limereport/serializators/lrserializatorintf.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRSERIALIZATORINTF_H
|
||||
#define LRSERIALIZATORINTF_H
|
||||
#include <QObject>
|
||||
namespace LimeReport {
|
||||
|
||||
class SerializatorIntf
|
||||
{
|
||||
public:
|
||||
virtual QVariant loadValue()=0;
|
||||
virtual void save(const QVariant& value,QString name)=0;
|
||||
virtual ~SerializatorIntf(){}
|
||||
};
|
||||
|
||||
}
|
||||
#endif // LRSERIALIZATORINTF_H
|
73
limereport/serializators/lrstorageintf.h
Normal file
73
limereport/serializators/lrstorageintf.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRSTORAGEINTF_H
|
||||
#define LRSTORAGEINTF_H
|
||||
|
||||
#include <QSharedPointer>
|
||||
|
||||
class QString;
|
||||
class QObject;
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
class ObjectLoadingStateIntf{
|
||||
public:
|
||||
virtual bool isLoading()=0;
|
||||
virtual void objectLoadStarted()=0;
|
||||
virtual void objectLoadFinished()=0;
|
||||
};
|
||||
|
||||
class ItemsWriterIntf
|
||||
{
|
||||
public:
|
||||
virtual void putItem(QObject* item)=0;
|
||||
virtual bool saveToFile(QString fileName) = 0;
|
||||
virtual QString saveToString() = 0;
|
||||
virtual QByteArray saveToByteArray() = 0;
|
||||
virtual ~ItemsWriterIntf(){}
|
||||
};
|
||||
|
||||
class ItemsReaderIntf
|
||||
{
|
||||
public:
|
||||
typedef QSharedPointer<ItemsReaderIntf> Ptr;
|
||||
virtual bool first()=0;
|
||||
virtual bool next()=0;
|
||||
virtual bool prior()=0;
|
||||
virtual QString itemType()=0;
|
||||
virtual QString itemClassName()=0;
|
||||
virtual bool readItem(QObject *item)=0;
|
||||
virtual int firstLevelItemsCount()=0;
|
||||
virtual QString lastError()=0;
|
||||
virtual ~ItemsReaderIntf(){}
|
||||
};
|
||||
|
||||
}
|
||||
#endif // LRSTORAGEINTF_H
|
281
limereport/serializators/lrxmlbasetypesserializators.cpp
Normal file
281
limereport/serializators/lrxmlbasetypesserializators.cpp
Normal file
@@ -0,0 +1,281 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "lrxmlbasetypesserializators.h"
|
||||
#include "serializators/lrxmlserializatorsfactory.h"
|
||||
#include "lrsimplecrypt.h"
|
||||
#include <QFont>
|
||||
#include <QImage>
|
||||
#include <QColor>
|
||||
|
||||
namespace{
|
||||
|
||||
LimeReport::SerializatorIntf * createIntSerializator(QDomDocument *doc, QDomElement *node){
|
||||
return new LimeReport::XmlIntSerializator(doc,node);
|
||||
}
|
||||
|
||||
LimeReport::SerializatorIntf * createQRealSerializator(QDomDocument *doc, QDomElement *node){
|
||||
return new LimeReport::XmlQRealSerializator(doc,node);
|
||||
}
|
||||
|
||||
LimeReport::SerializatorIntf * createQStringSerializator(QDomDocument *doc, QDomElement *node){
|
||||
return new LimeReport::XmlQStringSerializator(doc,node);
|
||||
}
|
||||
|
||||
LimeReport::SerializatorIntf * createEnumAndFlagsSerializator(QDomDocument *doc, QDomElement *node){
|
||||
return new LimeReport::XmlEnumAndFlagsSerializator(doc,node);
|
||||
}
|
||||
|
||||
LimeReport::SerializatorIntf * createBoolSerializator(QDomDocument *doc, QDomElement *node){
|
||||
return new LimeReport::XmlBoolSerializator(doc,node);
|
||||
}
|
||||
|
||||
LimeReport::SerializatorIntf * createFontSerializator(QDomDocument *doc, QDomElement *node){
|
||||
return new LimeReport::XmlFontSerializator(doc,node);
|
||||
}
|
||||
|
||||
LimeReport::SerializatorIntf * createQSizeFSerializator(QDomDocument *doc, QDomElement *node){
|
||||
return new LimeReport::XmlQSizeFSerializator(doc,node);
|
||||
}
|
||||
|
||||
LimeReport::SerializatorIntf * createQImageSerializator(QDomDocument *doc, QDomElement *node){
|
||||
return new LimeReport::XmlQImageSerializator(doc,node);
|
||||
}
|
||||
|
||||
LimeReport::SerializatorIntf * createQColorSerializator(QDomDocument *doc, QDomElement *node){
|
||||
return new LimeReport::XmlColorSerializator(doc,node);
|
||||
}
|
||||
|
||||
LimeReport::SerializatorIntf* createQByteArraySerializator(QDomDocument *doc, QDomElement *node){
|
||||
return new LimeReport::XmlQByteArraySerializator(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);
|
||||
bool registredBool = LimeReport::XMLAbstractSerializatorFactory::instance().registerCreator("bool", createBoolSerializator);
|
||||
bool registredQFont = LimeReport::XMLAbstractSerializatorFactory::instance().registerCreator("QFont", createFontSerializator);
|
||||
bool registredQSizeF = LimeReport::XMLAbstractSerializatorFactory::instance().registerCreator("QSizeF", createQSizeFSerializator);
|
||||
bool registredQImage = LimeReport::XMLAbstractSerializatorFactory::instance().registerCreator("QImage", createQImageSerializator);
|
||||
bool registredQReal = LimeReport::XMLAbstractSerializatorFactory::instance().registerCreator("qreal", createQRealSerializator);
|
||||
bool registerDouble = LimeReport::XMLAbstractSerializatorFactory::instance().registerCreator("double", createQRealSerializator);
|
||||
bool registerQColor = LimeReport::XMLAbstractSerializatorFactory::instance().registerCreator("QColor", createQColorSerializator);
|
||||
bool registerQByteArray = LimeReport::XMLAbstractSerializatorFactory::instance().registerCreator("QByteArray", createQByteArraySerializator);
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
void XmlBaseSerializator::saveBool(QDomElement node,QString name, bool value)
|
||||
{
|
||||
if (value) node.setAttribute(name,1);
|
||||
else node.setAttribute(name,0);
|
||||
}
|
||||
|
||||
void XmlQStringSerializator::save(const QVariant &value, QString name)
|
||||
{
|
||||
QDomElement _node = doc()->createElement(name);
|
||||
_node.setAttribute("Type","QString");
|
||||
if (name.compare("password")==0){
|
||||
Chipper chipper;
|
||||
QByteArray ba = chipper.cryptString(value.toString());
|
||||
//ba.append();
|
||||
_node.setAttribute("Value",QString(ba.toBase64()));
|
||||
} else {
|
||||
_node.appendChild(doc()->createTextNode(value.toString()));
|
||||
}
|
||||
node()->appendChild(_node);
|
||||
}
|
||||
|
||||
QVariant XmlQStringSerializator::loadValue()
|
||||
{
|
||||
if (node()->tagName().compare("password")==0){
|
||||
QByteArray ba;
|
||||
Chipper chipper;
|
||||
ba.append(node()->attribute("Value").toLatin1());
|
||||
return chipper.decryptByteArray(QByteArray::fromBase64(ba));
|
||||
} else
|
||||
return node()->text();
|
||||
}
|
||||
|
||||
void XmlIntSerializator::save(const QVariant &value, QString name)
|
||||
{
|
||||
QDomElement _node = doc()->createElement(name);
|
||||
_node.setAttribute("Type","int");
|
||||
_node.setAttribute("Value",value.toInt());
|
||||
node()->appendChild(_node);
|
||||
}
|
||||
|
||||
QVariant XmlIntSerializator::loadValue()
|
||||
{
|
||||
return node()->attribute("Value").toInt();
|
||||
}
|
||||
|
||||
void XmlEnumAndFlagsSerializator::save(const QVariant &value, QString name)
|
||||
{
|
||||
QDomElement _node = doc()->createElement(name);
|
||||
_node.setAttribute("Type","enumAndFlags");
|
||||
_node.setAttribute("Value",value.toInt());
|
||||
node()->appendChild(_node);
|
||||
}
|
||||
|
||||
QVariant XmlEnumAndFlagsSerializator::loadValue()
|
||||
{
|
||||
return node()->attribute("Value").toInt();
|
||||
}
|
||||
|
||||
void XmlBoolSerializator::save(const QVariant &value, QString name)
|
||||
{
|
||||
QDomElement _node = doc()->createElement(name);
|
||||
_node.setAttribute("Type","bool");
|
||||
if (value.toBool())
|
||||
_node.setAttribute("Value",1);
|
||||
else _node.setAttribute("Value",0);
|
||||
|
||||
node()->appendChild(_node);
|
||||
}
|
||||
|
||||
QVariant XmlBoolSerializator::loadValue()
|
||||
{
|
||||
return node()->attribute("Value").toInt();
|
||||
}
|
||||
|
||||
void XmlFontSerializator::save(const QVariant &value, QString name)
|
||||
{
|
||||
|
||||
QFont font = value.value<QFont>();
|
||||
QDomElement _node = doc()->createElement(name);
|
||||
_node.setAttribute("Type","QFont");
|
||||
_node.setAttribute("family",font.family());
|
||||
_node.setAttribute("pointSize",font.pointSize());
|
||||
saveBool(_node,"bold",font.bold());
|
||||
saveBool(_node,"italic",font.italic());
|
||||
saveBool(_node,"underline",font.underline());
|
||||
|
||||
node()->appendChild(_node);
|
||||
}
|
||||
|
||||
QVariant XmlFontSerializator::loadValue()
|
||||
{
|
||||
QFont font;
|
||||
|
||||
font.setFamily(node()->attribute("family"));
|
||||
font.setPointSize(node()->attribute("pointSize").toInt());
|
||||
font.setBold(node()->attribute("bold").toInt());
|
||||
font.setItalic(node()->attribute("italic").toInt());
|
||||
font.setUnderline(node()->attribute("underline").toInt());
|
||||
return font;
|
||||
}
|
||||
|
||||
void XmlQSizeFSerializator::save(const QVariant &value, QString name)
|
||||
{
|
||||
QSizeF size = value.toSizeF();
|
||||
QDomElement _node = doc()->createElement(name);
|
||||
_node.setAttribute("Type","QSizeF");
|
||||
_node.setAttribute("width",QString::number(size.width()));
|
||||
_node.setAttribute("height",QString::number(size.height()));
|
||||
node()->appendChild(_node);
|
||||
}
|
||||
|
||||
QVariant XmlQSizeFSerializator::loadValue()
|
||||
{
|
||||
QSizeF size;
|
||||
size.setWidth(node()->attribute("width").toDouble());
|
||||
size.setHeight(node()->attribute("height").toDouble());
|
||||
return size;
|
||||
}
|
||||
|
||||
void XmlQImageSerializator::save(const QVariant &value, QString name)
|
||||
{
|
||||
QImage image=value.value<QImage>();
|
||||
QByteArray ba;
|
||||
QBuffer buff(&ba);
|
||||
buff.open(QIODevice::WriteOnly);
|
||||
image.save(&buff,"PNG");
|
||||
QDomElement _node = doc()->createElement(name);
|
||||
_node.setAttribute("Type","QImage");
|
||||
_node.appendChild(doc()->createTextNode(ba.toHex()));
|
||||
node()->appendChild(_node);
|
||||
}
|
||||
|
||||
QVariant XmlQImageSerializator::loadValue()
|
||||
{
|
||||
QImage img;
|
||||
img.loadFromData(QByteArray::fromHex(node()->text().toLatin1()),"PNG");
|
||||
return img;
|
||||
}
|
||||
|
||||
void XmlQRealSerializator::save(const QVariant &value, QString name)
|
||||
{
|
||||
QDomElement _node = doc()->createElement(name);
|
||||
_node.setAttribute("Type","qreal");
|
||||
_node.setAttribute("Value",QString::number(value.toDouble()));
|
||||
node()->appendChild(_node);
|
||||
}
|
||||
|
||||
QVariant XmlQRealSerializator::loadValue()
|
||||
{
|
||||
return node()->attribute("Value").toDouble();
|
||||
}
|
||||
|
||||
void XmlColorSerializator::save(const QVariant &value, QString name)
|
||||
{
|
||||
QDomElement _node = doc()->createElement(name);
|
||||
_node.setAttribute("Type","QColor");
|
||||
_node.setAttribute("Value",value.value<QColor>().name());
|
||||
node()->appendChild(_node);
|
||||
}
|
||||
|
||||
QVariant XmlColorSerializator::loadValue()
|
||||
{
|
||||
return QColor(node()->attribute("Value"));
|
||||
}
|
||||
|
||||
void XmlQByteArraySerializator::save(const QVariant &value, QString name)
|
||||
{
|
||||
QDomElement _node = doc()->createElement(name);
|
||||
_node.setAttribute("Type","QByteArray");
|
||||
_node.setAttribute("Value",QString(value.toByteArray().toBase64()));
|
||||
node()->appendChild(_node);
|
||||
}
|
||||
|
||||
QVariant XmlQByteArraySerializator::loadValue()
|
||||
{
|
||||
QByteArray ba;
|
||||
ba.append(node()->attribute("Value").toLatin1());
|
||||
return QByteArray::fromBase64(ba);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
141
limereport/serializators/lrxmlbasetypesserializators.h
Normal file
141
limereport/serializators/lrxmlbasetypesserializators.h
Normal file
@@ -0,0 +1,141 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRXMLBASETYPESSERIALIZATORS_H
|
||||
#define LRXMLBASETYPESSERIALIZATORS_H
|
||||
|
||||
#include "lrserializatorintf.h"
|
||||
#include <QtXml>
|
||||
#include <QDebug>
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
class XmlBaseSerializator : public SerializatorIntf{
|
||||
public:
|
||||
XmlBaseSerializator(QDomDocument *doc, QDomElement *node):m_doc(doc),m_node(node){}
|
||||
protected:
|
||||
QDomDocument* doc() {return m_doc;}
|
||||
QDomElement* node() {if (!m_node) qDebug()<<QLatin1String("Warning node is null"); return m_node;}
|
||||
void saveBool(QDomElement node, QString name, bool value);
|
||||
private:
|
||||
QDomDocument *m_doc;
|
||||
QDomElement *m_node;
|
||||
};
|
||||
|
||||
class XmlQStringSerializator : public XmlBaseSerializator
|
||||
{
|
||||
public:
|
||||
XmlQStringSerializator(QDomDocument *doc, QDomElement *node):XmlBaseSerializator(doc,node){}
|
||||
private:
|
||||
virtual void save(const QVariant &value,QString name);
|
||||
virtual QVariant loadValue();
|
||||
};
|
||||
|
||||
class XmlIntSerializator : public XmlBaseSerializator
|
||||
{
|
||||
public:
|
||||
XmlIntSerializator(QDomDocument *doc, QDomElement *node):XmlBaseSerializator(doc,node){}
|
||||
private:
|
||||
virtual void save(const QVariant &value,QString name);
|
||||
virtual QVariant loadValue();
|
||||
};
|
||||
|
||||
class XmlQRealSerializator : public XmlBaseSerializator
|
||||
{
|
||||
public:
|
||||
XmlQRealSerializator(QDomDocument *doc, QDomElement *node):XmlBaseSerializator(doc,node){}
|
||||
private:
|
||||
virtual void save(const QVariant &value,QString name);
|
||||
virtual QVariant loadValue();
|
||||
};
|
||||
|
||||
class XmlEnumAndFlagsSerializator : public XmlBaseSerializator
|
||||
{
|
||||
public:
|
||||
XmlEnumAndFlagsSerializator(QDomDocument *doc, QDomElement *node):XmlBaseSerializator(doc,node){}
|
||||
private:
|
||||
virtual void save(const QVariant &value, QString name);
|
||||
virtual QVariant loadValue();
|
||||
};
|
||||
|
||||
class XmlBoolSerializator : public XmlBaseSerializator
|
||||
{
|
||||
public:
|
||||
XmlBoolSerializator(QDomDocument *doc, QDomElement *node):XmlBaseSerializator(doc,node){}
|
||||
private:
|
||||
virtual void save(const QVariant &value, QString name);
|
||||
virtual QVariant loadValue();
|
||||
};
|
||||
|
||||
class XmlFontSerializator : public XmlBaseSerializator
|
||||
{
|
||||
public:
|
||||
XmlFontSerializator(QDomDocument *doc, QDomElement *node):XmlBaseSerializator(doc,node){}
|
||||
private:
|
||||
virtual void save(const QVariant &value, QString name);
|
||||
virtual QVariant loadValue();
|
||||
};
|
||||
|
||||
class XmlQSizeFSerializator : public XmlBaseSerializator
|
||||
{
|
||||
public:
|
||||
XmlQSizeFSerializator(QDomDocument *doc, QDomElement *node):XmlBaseSerializator(doc,node){}
|
||||
private:
|
||||
virtual void save(const QVariant &value, QString name);
|
||||
virtual QVariant loadValue();
|
||||
};
|
||||
|
||||
class XmlColorSerializator : public XmlBaseSerializator
|
||||
{
|
||||
public:
|
||||
XmlColorSerializator(QDomDocument *doc, QDomElement *node):XmlBaseSerializator(doc,node){}
|
||||
private:
|
||||
virtual void save(const QVariant &value, QString name);
|
||||
virtual QVariant loadValue();
|
||||
};
|
||||
|
||||
class XmlQImageSerializator : public XmlBaseSerializator
|
||||
{
|
||||
public:
|
||||
XmlQImageSerializator(QDomDocument *doc, QDomElement *node):XmlBaseSerializator(doc,node){}
|
||||
private:
|
||||
virtual void save(const QVariant &value, QString name);
|
||||
virtual QVariant loadValue();
|
||||
};
|
||||
|
||||
class XmlQByteArraySerializator : public XmlBaseSerializator{
|
||||
public:
|
||||
XmlQByteArraySerializator(QDomDocument *doc, QDomElement *node):XmlBaseSerializator(doc,node){}
|
||||
private:
|
||||
virtual void save(const QVariant &value, QString name);
|
||||
virtual QVariant loadValue();
|
||||
};
|
||||
|
||||
}
|
||||
#endif // LRXMLBASETYPESSERIALIZATORS_H
|
104
limereport/serializators/lrxmlqrectserializator.cpp
Normal file
104
limereport/serializators/lrxmlqrectserializator.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "lrxmlqrectserializator.h"
|
||||
#include "lrserializatorintf.h"
|
||||
#include "lrxmlserializatorsfactory.h"
|
||||
|
||||
#include <QRect>
|
||||
#include <QRectF>
|
||||
|
||||
namespace{
|
||||
|
||||
LimeReport::SerializatorIntf * createQRectSerializator(QDomDocument *doc, QDomElement *node){
|
||||
return new LimeReport::XMLQRectSerializator(doc,node);
|
||||
}
|
||||
|
||||
LimeReport::SerializatorIntf * createQRectFSerializator(QDomDocument *doc, QDomElement *node){
|
||||
return new LimeReport::XMLQRectFSerializator(doc,node);
|
||||
}
|
||||
|
||||
bool registredQRect = LimeReport::XMLAbstractSerializatorFactory::instance().registerCreator("QRect", createQRectSerializator);
|
||||
bool registredQRectF = LimeReport::XMLAbstractSerializatorFactory::instance().registerCreator("QRectF", createQRectSerializator);
|
||||
|
||||
}
|
||||
|
||||
QVariant LimeReport::XMLQRectSerializator::loadValue()
|
||||
{
|
||||
QRect rect;
|
||||
//QDomElement geometryNode = m_node->firstChildElement(name);
|
||||
//if (!geometryNode.isNull()){
|
||||
rect = QRect(
|
||||
m_node->attribute("x").toInt(),
|
||||
m_node->attribute("y").toInt(),
|
||||
m_node->attribute("width").toInt(),
|
||||
m_node->attribute("height").toInt()
|
||||
);
|
||||
//}
|
||||
return rect;
|
||||
}
|
||||
|
||||
void LimeReport::XMLQRectSerializator::save(const QVariant &value, QString name)
|
||||
{
|
||||
QDomElement geometryNode = m_doc->createElement(name);
|
||||
geometryNode.setAttribute("Type","QRect");
|
||||
geometryNode.setAttribute("x",value.toRect().x());
|
||||
geometryNode.setAttribute("x",value.toRect().x());
|
||||
geometryNode.setAttribute("y",value.toRect().y());
|
||||
geometryNode.setAttribute("width",value.toRect().width());
|
||||
geometryNode.setAttribute("height",value.toRect().height());
|
||||
m_node->appendChild(geometryNode);
|
||||
}
|
||||
|
||||
void LimeReport::XMLQRectFSerializator::save(const QVariant &value, QString name)
|
||||
{
|
||||
QDomElement geometryNode = m_doc->createElement(name);
|
||||
geometryNode.setAttribute("Type","QRectF");
|
||||
geometryNode.setAttribute("x",value.toRect().x());
|
||||
geometryNode.setAttribute("y",value.toRect().y());
|
||||
geometryNode.setAttribute("width",value.toRect().width());
|
||||
geometryNode.setAttribute("height",value.toRect().height());
|
||||
m_node->appendChild(geometryNode);
|
||||
}
|
||||
|
||||
QVariant LimeReport::XMLQRectFSerializator::loadValue()
|
||||
{
|
||||
QRectF rect;
|
||||
//QDomElement geometryNode = m_node->firstChildElement(name);
|
||||
//if (!geometryNode.isNull()){
|
||||
rect = QRect(
|
||||
m_node->attribute("x").toDouble(),
|
||||
m_node->attribute("y").toDouble(),
|
||||
m_node->attribute("width").toDouble(),
|
||||
m_node->attribute("height").toDouble()
|
||||
);
|
||||
|
||||
//}
|
||||
return rect;
|
||||
}
|
61
limereport/serializators/lrxmlqrectserializator.h
Normal file
61
limereport/serializators/lrxmlqrectserializator.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRXMLQRECTSERIALIZATOR_H
|
||||
#define LRXMLQRECTSERIALIZATOR_H
|
||||
|
||||
#include "lrserializatorintf.h"
|
||||
#include <QtXml>
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
class XMLQRectSerializator : public SerializatorIntf
|
||||
{
|
||||
public:
|
||||
XMLQRectSerializator(QDomDocument *doc, QDomElement *node):m_doc(doc),m_node(node){}
|
||||
virtual void save(const QVariant &value,QString name);
|
||||
virtual QVariant loadValue();
|
||||
private:
|
||||
QDomDocument *m_doc;
|
||||
QDomElement *m_node;
|
||||
};
|
||||
|
||||
class XMLQRectFSerializator : public SerializatorIntf
|
||||
{
|
||||
public:
|
||||
XMLQRectFSerializator(QDomDocument *doc, QDomElement *node):m_doc(doc),m_node(node){}
|
||||
virtual void save(const QVariant &value, QString name);
|
||||
virtual QVariant loadValue();
|
||||
private:
|
||||
QDomDocument *m_doc;
|
||||
QDomElement *m_node;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // LRXMLQRECTSERIALIZATOR_H
|
228
limereport/serializators/lrxmlreader.cpp
Normal file
228
limereport/serializators/lrxmlreader.cpp
Normal file
@@ -0,0 +1,228 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "stdexcept"
|
||||
|
||||
#include "lrxmlreader.h"
|
||||
#include "lrbasedesignintf.h"
|
||||
#include "lrdesignelementsfactory.h"
|
||||
#include "lrcollection.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
XMLReader::XMLReader()
|
||||
: m_doc(new QDomDocument){}
|
||||
XMLReader::XMLReader(QSharedPointer<QDomDocument> doc)
|
||||
: m_doc(doc){}
|
||||
|
||||
bool XMLReader::prepareReader(QDomDocument* doc)
|
||||
{
|
||||
Q_UNUSED(doc);
|
||||
m_error=QLatin1String("Context not initialized");
|
||||
return false;
|
||||
}
|
||||
|
||||
int XMLReader::firstLevelItemsCount()
|
||||
{
|
||||
if (m_firstNode.childNodes().count()==0) return 0;
|
||||
QDomElement tmpNode = m_firstNode;
|
||||
int res=0;
|
||||
while (!tmpNode.isNull()){
|
||||
res++;
|
||||
tmpNode=tmpNode.nextSiblingElement();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool XMLReader::first()
|
||||
{
|
||||
if (extractFirstNode()){
|
||||
m_curNode = m_firstNode;
|
||||
return !m_curNode.isNull();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool XMLReader::next()
|
||||
{
|
||||
m_curNode = m_curNode.nextSiblingElement();
|
||||
return !m_curNode.isNull();
|
||||
}
|
||||
|
||||
bool XMLReader::prior()
|
||||
{
|
||||
m_curNode = m_curNode.previousSiblingElement();
|
||||
return !m_curNode.isNull();
|
||||
}
|
||||
|
||||
QString XMLReader::itemType()
|
||||
{
|
||||
return m_curNode.attribute("Type");
|
||||
}
|
||||
|
||||
QString XMLReader::itemClassName()
|
||||
{
|
||||
return m_curNode.attribute("ClassName");
|
||||
}
|
||||
|
||||
bool XMLReader::readItem(QObject *item)
|
||||
{
|
||||
if (!m_curNode.isNull()){
|
||||
readItemFromNode(item,&m_curNode);
|
||||
} else {
|
||||
m_error=QString("Object %1 not founded").arg(item->objectName());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void XMLReader::readItemFromNode(QObject* item,QDomElement *node)
|
||||
{
|
||||
|
||||
ObjectLoadingStateIntf* lf = dynamic_cast<ObjectLoadingStateIntf*>(item);
|
||||
if(lf) lf->objectLoadStarted();
|
||||
for (int i=0;i<node->childNodes().count();i++){
|
||||
QDomElement currentNode =node->childNodes().at(i).toElement();
|
||||
if (currentNode.attribute("Type")=="Object"){
|
||||
readQObject(item,¤tNode);
|
||||
}else if (currentNode.attribute("Type")=="Collection")
|
||||
{
|
||||
readCollection(item,¤tNode);
|
||||
}
|
||||
else readProperty(item,¤tNode);
|
||||
}
|
||||
if (lf) lf->objectLoadFinished();
|
||||
|
||||
BaseDesignIntf* baseObj = dynamic_cast<BaseDesignIntf*>(item);
|
||||
if(baseObj) {
|
||||
foreach(QGraphicsItem* item,baseObj->childItems()){
|
||||
BaseDesignIntf* baseItem = dynamic_cast<BaseDesignIntf*>(item);
|
||||
if (baseItem) baseItem->parentObjectLoadFinished();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString XMLReader::lastError()
|
||||
{
|
||||
return m_error;
|
||||
}
|
||||
|
||||
bool XMLReader::extractFirstNode()
|
||||
{
|
||||
if (m_firstNode.isNull()){
|
||||
if (m_doc->childNodes().count()==0){
|
||||
if (!prepareReader(m_doc.data())) return false;
|
||||
}
|
||||
m_firstNode = m_doc->documentElement();
|
||||
if (!m_firstNode.hasAttributes())
|
||||
m_firstNode = m_firstNode.firstChildElement();
|
||||
}
|
||||
return !m_firstNode.isNull();
|
||||
}
|
||||
|
||||
void XMLReader::readProperty(QObject *item, QDomElement *node)
|
||||
{
|
||||
item->setProperty(node->nodeName().toLatin1(),getValue(node));
|
||||
}
|
||||
|
||||
QVariant XMLReader::getValue(QDomElement *node)
|
||||
{
|
||||
CreateSerializator creator = 0;
|
||||
try {
|
||||
creator=XMLAbstractSerializatorFactory::instance().objectCreator(
|
||||
node->attribute("Type")
|
||||
);
|
||||
} catch(ReportError &e){
|
||||
qDebug()<<node->attribute("Type")<<e.what();
|
||||
}
|
||||
|
||||
if (creator) {
|
||||
QScopedPointer<SerializatorIntf>serializator(creator(m_doc.data(),node));
|
||||
return serializator->loadValue();
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void XMLReader::readQObject(QObject* item, QDomElement* node)
|
||||
{
|
||||
QObject* childItem = qvariant_cast<QObject*>(item->property(node->nodeName().toLatin1()));
|
||||
if (childItem)
|
||||
readItemFromNode(childItem,node);
|
||||
}
|
||||
|
||||
void XMLReader::readCollection(QObject *item, QDomElement *node)
|
||||
{
|
||||
ICollectionContainer* collection = dynamic_cast<ICollectionContainer*>(item);
|
||||
if (collection){
|
||||
QString collectionName = node->nodeName();
|
||||
for(int i=0;i<node->childNodes().count();i++){
|
||||
QDomElement currentNode =node->childNodes().at(i).toElement();
|
||||
QObject* obj = collection->createElement(collectionName,currentNode.attribute("ClassName"));
|
||||
if (obj)
|
||||
readItemFromNode(obj,¤tNode);
|
||||
}
|
||||
collection->collectionLoadFinished(collectionName);
|
||||
}
|
||||
}
|
||||
|
||||
FileXMLReader::FileXMLReader(QString fileName)
|
||||
: m_fileName(fileName)
|
||||
{
|
||||
}
|
||||
|
||||
bool FileXMLReader::prepareReader(QDomDocument *doc)
|
||||
{
|
||||
if (!m_fileName.isEmpty()){
|
||||
QFile source(m_fileName);
|
||||
if (source.open(QFile::ReadOnly)) {
|
||||
doc->setContent(&source);
|
||||
} else {m_error=QString(QObject::tr("File %1 not opened")).arg(m_fileName); return false;}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StringXMLreader::prepareReader(QDomDocument *doc)
|
||||
{
|
||||
if (!m_content.isEmpty()){
|
||||
doc->setContent(m_content);
|
||||
}else {m_error = QString(QObject::tr("Content string is empty")); return false;}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ByteArrayXMLReader::prepareReader(QDomDocument *doc)
|
||||
{
|
||||
if (m_content){
|
||||
doc->setContent(*m_content);
|
||||
} else {m_error = QString(QObject::tr("Content is empty")); return false;}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
104
limereport/serializators/lrxmlreader.h
Normal file
104
limereport/serializators/lrxmlreader.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRXMLREADER_H
|
||||
#define LRXMLREADER_H
|
||||
|
||||
#include <QString>
|
||||
#include <QtXml>
|
||||
|
||||
#include "serializators/lrxmlwriter.h"
|
||||
#include "lrdesignelementsfactory.h"
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
class XMLReader : public ItemsReaderIntf
|
||||
{
|
||||
public:
|
||||
XMLReader();
|
||||
XMLReader(QSharedPointer<QDomDocument> doc);
|
||||
protected:
|
||||
|
||||
virtual bool first();
|
||||
virtual bool next();
|
||||
virtual bool prior();
|
||||
virtual QString itemType();
|
||||
virtual QString itemClassName();
|
||||
virtual bool readItem(QObject *item);
|
||||
virtual int firstLevelItemsCount();
|
||||
virtual bool prepareReader(QDomDocument *doc);
|
||||
|
||||
void readItemFromNode(QObject *item, QDomElement *node);
|
||||
void readProperty(QObject *item, QDomElement *node);
|
||||
void readQObject(QObject *item, QDomElement *node);
|
||||
void readCollection(QObject *item, QDomElement *node);
|
||||
QVariant getValue(QDomElement *node);
|
||||
|
||||
virtual QString lastError();
|
||||
protected:
|
||||
bool extractFirstNode();
|
||||
QString m_error;
|
||||
private:
|
||||
QSharedPointer<QDomDocument> m_doc;
|
||||
QDomElement m_curNode;
|
||||
QDomElement m_firstNode;
|
||||
};
|
||||
|
||||
class FileXMLReader : public XMLReader{
|
||||
public:
|
||||
static ItemsReaderIntf::Ptr create(QString fileName){ return ItemsReaderIntf::Ptr(new FileXMLReader(fileName));}
|
||||
protected:
|
||||
virtual bool prepareReader(QDomDocument *doc);
|
||||
private:
|
||||
FileXMLReader(QString fileName);
|
||||
QString m_fileName;
|
||||
};
|
||||
|
||||
class StringXMLreader : public XMLReader{
|
||||
public:
|
||||
static ItemsReaderIntf::Ptr create(QString content){ return ItemsReaderIntf::Ptr(new StringXMLreader(content));}
|
||||
protected:
|
||||
virtual bool prepareReader(QDomDocument *doc);
|
||||
private:
|
||||
StringXMLreader(QString content) : m_content(content){}
|
||||
QString m_content;
|
||||
};
|
||||
|
||||
class ByteArrayXMLReader : public XMLReader{
|
||||
public:
|
||||
static ItemsReaderIntf::Ptr create(QByteArray* content){ return ItemsReaderIntf::Ptr(new ByteArrayXMLReader(content));}
|
||||
protected:
|
||||
virtual bool prepareReader(QDomDocument *doc);
|
||||
private:
|
||||
ByteArrayXMLReader(QByteArray* content): m_content(content){}
|
||||
QByteArray* m_content;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // LRXMLREADER_H
|
55
limereport/serializators/lrxmlserializatorsfactory.h
Normal file
55
limereport/serializators/lrxmlserializatorsfactory.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRXMLABSTRACTSERIALIZATORFABRIC_H
|
||||
#define LRXMLABSTRACTSERIALIZATORFABRIC_H
|
||||
|
||||
#include "lrserializatorintf.h"
|
||||
#include "lrsimpleabstractfactory.h"
|
||||
|
||||
#include <QtXml>
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
typedef SerializatorIntf* (*CreateSerializator)(QDomDocument *doc, QDomElement *parentNode);
|
||||
|
||||
class XMLAbstractSerializatorFactory: public SimpleAbstractFactory<SerializatorIntf,QString,CreateSerializator>
|
||||
{
|
||||
private:
|
||||
friend class Singleton<XMLAbstractSerializatorFactory>;
|
||||
public:
|
||||
XMLAbstractSerializatorFactory(){}
|
||||
~XMLAbstractSerializatorFactory(){}
|
||||
XMLAbstractSerializatorFactory(const XMLAbstractSerializatorFactory&){}
|
||||
XMLAbstractSerializatorFactory& operator = (const XMLAbstractSerializatorFactory&){return *this;}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // LRXMLABSTRACTSERIALIZATORFABRIC_H
|
230
limereport/serializators/lrxmlwriter.cpp
Normal file
230
limereport/serializators/lrxmlwriter.cpp
Normal file
@@ -0,0 +1,230 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "lrxmlwriter.h"
|
||||
#include "lrbasedesignintf.h"
|
||||
#include "serializators/lrxmlserializatorsfactory.h"
|
||||
#include "lrcollection.h"
|
||||
#include <QDebug>
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
XMLWriter::XMLWriter() : m_doc(new QDomDocument)
|
||||
{
|
||||
m_rootElement=m_doc->createElement("Report");
|
||||
m_doc->appendChild(m_rootElement);
|
||||
}
|
||||
|
||||
XMLWriter::XMLWriter(QSharedPointer<QDomDocument> doc) : m_doc(doc){
|
||||
m_rootElement=m_doc->createElement("Report");
|
||||
m_doc->appendChild(m_rootElement);
|
||||
}
|
||||
|
||||
void XMLWriter::putItem(QObject *item)
|
||||
{
|
||||
QDomElement node=putQObjectItem(item->metaObject()->className(),item);
|
||||
if (!replaceNode(node,item)) m_rootElement.appendChild(node);
|
||||
}
|
||||
|
||||
QString XMLWriter::extractClassName(QObject *item)
|
||||
{
|
||||
BaseDesignIntf* baseItem = dynamic_cast<BaseDesignIntf*>(item);
|
||||
if(baseItem) return baseItem->storageTypeName();
|
||||
else return item->metaObject()->className();
|
||||
}
|
||||
|
||||
void XMLWriter::putChildQObjectItem(QString name, QObject *item, QDomElement *parentNode)
|
||||
{
|
||||
QDomElement itemNode = m_doc->createElement(name);
|
||||
itemNode.setAttribute("ClassName",extractClassName(item));
|
||||
itemNode.setAttribute("Type","Object");
|
||||
if (parentNode) parentNode->appendChild(itemNode);
|
||||
saveProperties(item,&itemNode);
|
||||
}
|
||||
|
||||
bool XMLWriter::setContent(QString fileName)
|
||||
{
|
||||
QFile xmlFile(fileName);
|
||||
if (xmlFile.open(QFile::ReadOnly)){
|
||||
return m_doc->setContent(&xmlFile);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool XMLWriter::saveToFile(QString fileName)
|
||||
{
|
||||
if ((m_doc->childNodes().count()==0)||fileName.isEmpty()) return false;
|
||||
QFile xmlFile(fileName);
|
||||
if (xmlFile.open(QFile::WriteOnly)) {
|
||||
QTextStream buffer(&xmlFile);
|
||||
m_doc->save(buffer,2);
|
||||
xmlFile.close();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QString XMLWriter::saveToString()
|
||||
{
|
||||
QString res;
|
||||
QTextStream buffer(&res);
|
||||
m_doc->save(buffer,2);
|
||||
return res;
|
||||
}
|
||||
|
||||
QByteArray XMLWriter::saveToByteArray()
|
||||
{
|
||||
QByteArray res;
|
||||
QTextStream buffer(&res);
|
||||
m_doc->save(buffer,2);
|
||||
return res;
|
||||
}
|
||||
|
||||
QDomElement XMLWriter::putQObjectItem(QString name, QObject *item)
|
||||
{
|
||||
Q_UNUSED(name)
|
||||
QDomElement itemNode = m_doc->createElement("object");
|
||||
itemNode.setAttribute("ClassName",extractClassName(item));
|
||||
itemNode.setAttribute("Type","Object");
|
||||
saveProperties(item,&itemNode);
|
||||
return itemNode;
|
||||
}
|
||||
|
||||
void XMLWriter::saveProperty(QString name, QObject* item, QDomElement *node)
|
||||
{
|
||||
CreateSerializator creator=0;
|
||||
|
||||
if (isCollection(name,item)) { saveCollection(name,item,node); return;}
|
||||
if (isQObject(name,item)) {
|
||||
if (qvariant_cast<QObject *>(item->property(name.toLatin1())))
|
||||
putQObjectProperty(name,qvariant_cast<QObject *>(item->property(name.toLatin1())),node);
|
||||
else {
|
||||
qDebug()<<"Warnig property can`t be casted to QObject"<<name;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (enumOrFlag(name,item))
|
||||
creator=XMLAbstractSerializatorFactory::instance().objectCreator(
|
||||
"enumAndFlags"
|
||||
);
|
||||
else
|
||||
try {
|
||||
creator=XMLAbstractSerializatorFactory::instance().objectCreator(
|
||||
item->property(name.toLatin1()).typeName()
|
||||
);
|
||||
} catch (LimeReport::ReportError &exception){
|
||||
qDebug()<<"class name ="<<item->metaObject()->className()
|
||||
<<"property name="<<name<<" property type="<<item->property(name.toLatin1()).typeName()
|
||||
<<exception.what();
|
||||
|
||||
}
|
||||
|
||||
if (creator) {
|
||||
QScopedPointer<SerializatorIntf> serializator(creator(m_doc.data(),node));
|
||||
serializator->save(
|
||||
item->property(name.toLatin1()),
|
||||
name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void XMLWriter::saveProperties(QObject *item, QDomElement *node)
|
||||
{
|
||||
for (int i=0;i<item->metaObject()->propertyCount();i++){
|
||||
saveProperty(item->metaObject()->property(i).name(),item,node);
|
||||
}
|
||||
}
|
||||
|
||||
bool XMLWriter::enumOrFlag(QString name, QObject *item)
|
||||
{
|
||||
return item->metaObject()->property(item->metaObject()->indexOfProperty(name.toLatin1())).isFlagType() ||
|
||||
item->metaObject()->property(item->metaObject()->indexOfProperty(name.toLatin1())).isEnumType();
|
||||
}
|
||||
|
||||
bool XMLWriter::isCollection(QString propertyName, QObject* item)
|
||||
{
|
||||
QMetaProperty prop=item->metaObject()->property(item->metaObject()->indexOfProperty(propertyName.toLatin1()));
|
||||
return QMetaType::type(prop.typeName())==COLLECTION_TYPE_ID;
|
||||
}
|
||||
|
||||
void XMLWriter::saveCollection(QString propertyName, QObject *item, QDomElement *node)
|
||||
{
|
||||
ICollectionContainer * collection=dynamic_cast<ICollectionContainer*>(item);
|
||||
QDomElement collectionNode=m_doc->createElement(propertyName);
|
||||
collectionNode.setAttribute("Type","Collection");
|
||||
|
||||
for(int i=0;i<collection->elementsCount(propertyName);i++){
|
||||
putCollectionItem(collection->elementAt(propertyName,i),&collectionNode);
|
||||
}
|
||||
|
||||
node->appendChild(collectionNode);
|
||||
}
|
||||
|
||||
bool XMLWriter::isQObject(QString propertyName, QObject *item)
|
||||
{
|
||||
QMetaProperty prop=item->metaObject()->property(item->metaObject()->indexOfProperty(propertyName.toLatin1()));
|
||||
return QMetaType::type(prop.typeName())==QMetaType::QObjectStar;
|
||||
}
|
||||
|
||||
bool XMLWriter::replaceNode(QDomElement node, QObject* item)
|
||||
{
|
||||
QDomElement element = m_rootElement.firstChildElement(item->metaObject()->className());
|
||||
while (!element.isNull()){
|
||||
QDomElement objectName = element.firstChildElement(QLatin1String("objectName"));
|
||||
if (!objectName.isNull()&&(objectName.text()==item->objectName())){
|
||||
QDomElement removeElement=element;
|
||||
element=element.nextSiblingElement(item->metaObject()->className());
|
||||
m_rootElement.replaceChild(node,removeElement);
|
||||
return true;
|
||||
}
|
||||
else element=element.nextSiblingElement(item->metaObject()->className());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void XMLWriter::putCollectionItem(QObject *item, QDomElement *parentNode)
|
||||
{
|
||||
putChildQObjectItem("item",item,parentNode);
|
||||
}
|
||||
|
||||
void XMLWriter::putQObjectProperty(QString propertyName, QObject* item, QDomElement* parentNode)
|
||||
{
|
||||
putChildQObjectItem(propertyName,item,parentNode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
73
limereport/serializators/lrxmlwriter.h
Normal file
73
limereport/serializators/lrxmlwriter.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRXMLWRITER_H
|
||||
#define LRXMLWRITER_H
|
||||
|
||||
#include <QtXml>
|
||||
#include "serializators/lrstorageintf.h"
|
||||
#include "serializators/lrxmlserializatorsfactory.h"
|
||||
#include "lrbasedesignintf.h"
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
class XMLWriter : public ItemsWriterIntf
|
||||
{
|
||||
public:
|
||||
XMLWriter();
|
||||
XMLWriter(QSharedPointer<QDomDocument> doc);
|
||||
~XMLWriter() {}
|
||||
private:
|
||||
void putItem(QObject* item);
|
||||
bool saveToFile(QString fileName);
|
||||
QString saveToString();
|
||||
QByteArray saveToByteArray();
|
||||
|
||||
QDomElement putQObjectItem(QString name, QObject* item);
|
||||
void putChildQObjectItem(QString name, QObject* item, QDomElement* parentNode);
|
||||
void putCollectionItem(QObject* item, QDomElement* parentNode=0);
|
||||
void putQObjectProperty(QString propertyName, QObject *item, QDomElement* parentNode=0);
|
||||
void saveProperties(QObject* item, QDomElement* node);
|
||||
bool setContent(QString fileName);
|
||||
void saveProperty(QString name, QObject* item, QDomElement* node);
|
||||
bool enumOrFlag(QString name, QObject* item);
|
||||
QString extractClassName(QObject* item);
|
||||
bool isCollection(QString propertyName, QObject *item);
|
||||
void saveCollection(QString propertyName, QObject *item, QDomElement *node);
|
||||
bool isQObject(QString propertyName, QObject *item);
|
||||
bool replaceNode(QDomElement node, QObject *item);
|
||||
private:
|
||||
QSharedPointer<QDomDocument> m_doc;
|
||||
QString m_fileName;
|
||||
QDomElement m_rootElement;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // LRXMLWRITER_H
|
Reference in New Issue
Block a user