mirror of
https://github.com/fralx/LimeReport.git
synced 2025-11-25 00:18:06 +03:00
Define code style and format all source file using clang-format-14
except those placed in 3rdparty directories.
This commit is contained in:
@@ -27,52 +27,51 @@
|
||||
* 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 "lrdesignelementsfactory.h"
|
||||
#include "lrreporttranslation.h"
|
||||
#include "stdexcept"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#ifdef BUILD_WITH_EASY_PROFILER
|
||||
#include "easy/profiler.h"
|
||||
#else
|
||||
# define EASY_BLOCK(...)
|
||||
# define EASY_END_BLOCK
|
||||
#define EASY_BLOCK(...)
|
||||
#define EASY_END_BLOCK
|
||||
#endif
|
||||
|
||||
namespace LimeReport{
|
||||
namespace LimeReport {
|
||||
|
||||
XMLReader::XMLReader()
|
||||
: m_doc(new QDomDocument){}
|
||||
XMLReader::XMLReader(QSharedPointer<QDomDocument> doc)
|
||||
: m_doc(doc){}
|
||||
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");
|
||||
m_error = QLatin1String("Context not initialized");
|
||||
return false;
|
||||
}
|
||||
|
||||
int XMLReader::firstLevelItemsCount()
|
||||
{
|
||||
if (m_firstNode.childNodes().count()==0) return 0;
|
||||
if (m_firstNode.childNodes().count() == 0)
|
||||
return 0;
|
||||
QDomElement tmpNode = m_firstNode;
|
||||
int res=0;
|
||||
while (!tmpNode.isNull()){
|
||||
int res = 0;
|
||||
while (!tmpNode.isNull()) {
|
||||
res++;
|
||||
tmpNode=tmpNode.nextSiblingElement();
|
||||
tmpNode = tmpNode.nextSiblingElement();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool XMLReader::first()
|
||||
{
|
||||
if (extractFirstNode()){
|
||||
if (extractFirstNode()) {
|
||||
m_curNode = m_firstNode;
|
||||
return !m_curNode.isNull();
|
||||
}
|
||||
@@ -91,98 +90,88 @@ bool XMLReader::prior()
|
||||
return !m_curNode.isNull();
|
||||
}
|
||||
|
||||
QString XMLReader::itemType()
|
||||
{
|
||||
return m_curNode.attribute("Type");
|
||||
}
|
||||
QString XMLReader::itemType() { return m_curNode.attribute("Type"); }
|
||||
|
||||
QString XMLReader::itemClassName()
|
||||
{
|
||||
return m_curNode.attribute("ClassName");
|
||||
}
|
||||
QString XMLReader::itemClassName() { return m_curNode.attribute("ClassName"); }
|
||||
|
||||
bool XMLReader::readItem(QObject *item)
|
||||
bool XMLReader::readItem(QObject* item)
|
||||
{
|
||||
if (!m_curNode.isNull()){
|
||||
readItemFromNode(item,&m_curNode);
|
||||
if (!m_curNode.isNull()) {
|
||||
readItemFromNode(item, &m_curNode);
|
||||
} else {
|
||||
m_error=QString("Object %1 not founded").arg(item->objectName());
|
||||
m_error = QString("Object %1 not founded").arg(item->objectName());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void XMLReader::readItemFromNode(QObject* item,QDomElement *node)
|
||||
void XMLReader::readItemFromNode(QObject* item, QDomElement* node)
|
||||
{
|
||||
EASY_BLOCK("readItemFromNode");
|
||||
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 if (currentNode.attribute("Type")=="Translation"){
|
||||
readTranslation(item,¤tNode);
|
||||
} else readProperty(item,¤tNode);
|
||||
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 if (currentNode.attribute("Type") == "Translation") {
|
||||
readTranslation(item, ¤tNode);
|
||||
} else
|
||||
readProperty(item, ¤tNode);
|
||||
}
|
||||
if (lf) lf->objectLoadFinished();
|
||||
if (lf)
|
||||
lf->objectLoadFinished();
|
||||
|
||||
BaseDesignIntf* baseObj = dynamic_cast<BaseDesignIntf*>(item);
|
||||
if(baseObj) {
|
||||
foreach(QGraphicsItem* childItem,baseObj->childItems()){
|
||||
if (baseObj) {
|
||||
foreach (QGraphicsItem* childItem, baseObj->childItems()) {
|
||||
BaseDesignIntf* baseItem = dynamic_cast<BaseDesignIntf*>(childItem);
|
||||
if (baseItem) baseItem->parentObjectLoadFinished();
|
||||
if (baseItem)
|
||||
baseItem->parentObjectLoadFinished();
|
||||
}
|
||||
}
|
||||
EASY_END_BLOCK;
|
||||
}
|
||||
|
||||
QString XMLReader::lastError()
|
||||
{
|
||||
return m_error;
|
||||
}
|
||||
QString XMLReader::lastError() { return m_error; }
|
||||
|
||||
void XMLReader::setPassPhrase(const QString &passPhrase)
|
||||
{
|
||||
m_passPhrase = passPhrase;
|
||||
}
|
||||
void XMLReader::setPassPhrase(const QString& passPhrase) { m_passPhrase = passPhrase; }
|
||||
|
||||
bool XMLReader::extractFirstNode()
|
||||
{
|
||||
if (m_firstNode.isNull()){
|
||||
if (m_doc->childNodes().count()==0){
|
||||
if (!prepareReader(m_doc.data())) return false;
|
||||
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();
|
||||
m_firstNode = m_firstNode.firstChildElement();
|
||||
}
|
||||
return !m_firstNode.isNull();
|
||||
}
|
||||
|
||||
void XMLReader::readProperty(QObject *item, QDomElement *node)
|
||||
void XMLReader::readProperty(QObject* item, QDomElement* node)
|
||||
{
|
||||
item->setProperty(node->nodeName().toLatin1(),getValue(node));
|
||||
item->setProperty(node->nodeName().toLatin1(), getValue(node));
|
||||
}
|
||||
|
||||
QVariant XMLReader::getValue(QDomElement *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();
|
||||
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));
|
||||
QScopedPointer<SerializatorIntf> serializator(creator(m_doc.data(), node));
|
||||
CryptedSerializator* cs = dynamic_cast<CryptedSerializator*>(serializator.data());
|
||||
if (cs){
|
||||
if (cs) {
|
||||
cs->setPassPhrase(m_passPhrase);
|
||||
}
|
||||
return serializator->loadValue();
|
||||
@@ -195,21 +184,22 @@ void XMLReader::readQObject(QObject* item, QDomElement* node)
|
||||
EASY_BLOCK("readQObject");
|
||||
QObject* childItem = qvariant_cast<QObject*>(item->property(node->nodeName().toLatin1()));
|
||||
if (childItem)
|
||||
readItemFromNode(childItem,node);
|
||||
readItemFromNode(childItem, node);
|
||||
EASY_END_BLOCK;
|
||||
}
|
||||
|
||||
void XMLReader::readCollection(QObject *item, QDomElement *node)
|
||||
void XMLReader::readCollection(QObject* item, QDomElement* node)
|
||||
{
|
||||
EASY_BLOCK("readCollection")
|
||||
ICollectionContainer* collection = dynamic_cast<ICollectionContainer*>(item);
|
||||
if (collection){
|
||||
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"));
|
||||
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);
|
||||
readItemFromNode(obj, ¤tNode);
|
||||
}
|
||||
collection->collectionLoadFinished(collectionName);
|
||||
}
|
||||
@@ -219,70 +209,81 @@ void XMLReader::readCollection(QObject *item, QDomElement *node)
|
||||
void XMLReader::readTranslation(QObject* item, QDomElement* node)
|
||||
{
|
||||
ITranslationContainer* tranclationContainer = dynamic_cast<ITranslationContainer*>(item);
|
||||
if (tranclationContainer){
|
||||
if (tranclationContainer) {
|
||||
Translations* translations = tranclationContainer->translations();
|
||||
for (int langIndex = 0; langIndex<node->childNodes().count(); ++langIndex){
|
||||
for (int langIndex = 0; langIndex < node->childNodes().count(); ++langIndex) {
|
||||
QDomElement languageNode = node->childNodes().at(langIndex).toElement();
|
||||
ReportTranslation* curTranslation = new ReportTranslation((QLocale::Language)(languageNode.attributeNode("Value").value().toInt()));
|
||||
for (int pageIndex = 0; pageIndex < languageNode.childNodes().count(); ++pageIndex){
|
||||
ReportTranslation* curTranslation = new ReportTranslation(
|
||||
(QLocale::Language)(languageNode.attributeNode("Value").value().toInt()));
|
||||
for (int pageIndex = 0; pageIndex < languageNode.childNodes().count(); ++pageIndex) {
|
||||
QDomElement pageNode = languageNode.childNodes().at(pageIndex).toElement();
|
||||
PageTranslation* pageTranslation = curTranslation->createEmptyPageTranslation();
|
||||
pageTranslation->pageName = pageNode.nodeName();
|
||||
for (int itemIndex = 0; itemIndex < pageNode.childNodes().count(); ++itemIndex){
|
||||
for (int itemIndex = 0; itemIndex < pageNode.childNodes().count(); ++itemIndex) {
|
||||
QDomElement itemNode = pageNode.childNodes().at(itemIndex).toElement();
|
||||
ItemTranslation* itemTranslation = new ItemTranslation();
|
||||
itemTranslation->itemName = itemNode.nodeName();
|
||||
for (int propertyIndex = 0; propertyIndex < itemNode.childNodes().count(); ++propertyIndex){
|
||||
QDomElement propertyNode = itemNode.childNodes().at(propertyIndex).toElement();
|
||||
for (int propertyIndex = 0; propertyIndex < itemNode.childNodes().count();
|
||||
++propertyIndex) {
|
||||
QDomElement propertyNode
|
||||
= itemNode.childNodes().at(propertyIndex).toElement();
|
||||
PropertyTranslation* propertyTranslation = new PropertyTranslation;
|
||||
propertyTranslation->propertyName = propertyNode.nodeName();
|
||||
propertyTranslation->value = propertyNode.attribute("Value");
|
||||
propertyTranslation->sourceValue = propertyNode.attribute("SourceValue");
|
||||
propertyTranslation->checked = propertyNode.attribute("Checked").compare("Y") == 0;
|
||||
propertyTranslation->checked
|
||||
= propertyNode.attribute("Checked").compare("Y") == 0;
|
||||
itemTranslation->propertyesTranslation.append(propertyTranslation);
|
||||
}
|
||||
pageTranslation->itemsTranslation.insert(itemTranslation->itemName, itemTranslation);
|
||||
pageTranslation->itemsTranslation.insert(itemTranslation->itemName,
|
||||
itemTranslation);
|
||||
}
|
||||
}
|
||||
translations->insert(curTranslation->language(),curTranslation);
|
||||
translations->insert(curTranslation->language(), curTranslation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FileXMLReader::FileXMLReader(QString fileName)
|
||||
: m_fileName(fileName)
|
||||
{
|
||||
}
|
||||
FileXMLReader::FileXMLReader(QString fileName): m_fileName(fileName) { }
|
||||
|
||||
bool FileXMLReader::prepareReader(QDomDocument *doc)
|
||||
bool FileXMLReader::prepareReader(QDomDocument* doc)
|
||||
{
|
||||
if (!m_fileName.isEmpty()){
|
||||
if (!m_fileName.isEmpty()) {
|
||||
QFile source(m_fileName);
|
||||
if (source.open(QFile::ReadOnly)) {
|
||||
doc->setContent(&source);
|
||||
if (doc->documentElement().nodeName()!="Report") {
|
||||
if (doc->documentElement().nodeName() != "Report") {
|
||||
m_error = QString(QObject::tr("Wrong file format"));
|
||||
return false;
|
||||
}
|
||||
} else {m_error=QString(QObject::tr("File %1 not opened")).arg(m_fileName); return false;}
|
||||
} else {
|
||||
m_error = QString(QObject::tr("File %1 not opened")).arg(m_fileName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StringXMLreader::prepareReader(QDomDocument *doc)
|
||||
bool StringXMLreader::prepareReader(QDomDocument* doc)
|
||||
{
|
||||
if (!m_content.isEmpty()){
|
||||
if (!m_content.isEmpty()) {
|
||||
doc->setContent(m_content);
|
||||
}else {m_error = QString(QObject::tr("Content string is empty")); return false;}
|
||||
} else {
|
||||
m_error = QString(QObject::tr("Content string is empty"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ByteArrayXMLReader::prepareReader(QDomDocument *doc)
|
||||
bool ByteArrayXMLReader::prepareReader(QDomDocument* doc)
|
||||
{
|
||||
if (m_content){
|
||||
if (m_content) {
|
||||
doc->setContent(*m_content);
|
||||
} else {m_error = QString(QObject::tr("Content is empty")); return false;}
|
||||
} else {
|
||||
m_error = QString(QObject::tr("Content is empty"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LimeReport
|
||||
|
||||
Reference in New Issue
Block a user