mirror of
https://github.com/fralx/LimeReport.git
synced 2025-09-23 08:29:07 +03:00
Some translation functionality has been added
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include "lrbasedesignintf.h"
|
||||
#include "lrdesignelementsfactory.h"
|
||||
#include "lrcollection.h"
|
||||
#include "lrreporttranslation.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
@@ -112,11 +113,12 @@ void XMLReader::readItemFromNode(QObject* item,QDomElement *node)
|
||||
QDomElement currentNode =node->childNodes().at(i).toElement();
|
||||
if (currentNode.attribute("Type")=="Object"){
|
||||
readQObject(item,¤tNode);
|
||||
}else if (currentNode.attribute("Type")=="Collection")
|
||||
} else if (currentNode.attribute("Type")=="Collection")
|
||||
{
|
||||
readCollection(item,¤tNode);
|
||||
}
|
||||
else readProperty(item,¤tNode);
|
||||
} else if (currentNode.attribute("Type")=="Translation"){
|
||||
readTranslation(item,¤tNode);
|
||||
} else readProperty(item,¤tNode);
|
||||
}
|
||||
if (lf) lf->objectLoadFinished();
|
||||
|
||||
@@ -191,7 +193,7 @@ 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++){
|
||||
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)
|
||||
@@ -201,6 +203,37 @@ void XMLReader::readCollection(QObject *item, QDomElement *node)
|
||||
}
|
||||
}
|
||||
|
||||
void XMLReader::readTranslation(QObject* item, QDomElement* node)
|
||||
{
|
||||
ITranslationContainer* tranclationContainer = dynamic_cast<ITranslationContainer*>(item);
|
||||
if (tranclationContainer){
|
||||
Translations* translations = tranclationContainer->translations();
|
||||
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){
|
||||
QDomElement pageNode = languageNode.childNodes().at(pageIndex).toElement();
|
||||
PageTranslation* pageTranslation = curTranslation->createEmptyPageTranslation();
|
||||
pageTranslation->pageName = pageNode.nodeName();
|
||||
for (int itemIndex = 0; itemIndex < pageNode.childNodes().count(); ++itemIndex){
|
||||
QDomElement itemNode = pageNode.childNodes().at(itemIndex).toElement();
|
||||
ItemTranslation itemTranslation;
|
||||
itemTranslation.itemName = itemNode.nodeName();
|
||||
for (int propertyIndex = 0; propertyIndex < itemNode.childNodes().count(); ++propertyIndex){
|
||||
QDomElement propertyNode = itemNode.childNodes().at(propertyIndex).toElement();
|
||||
PropertyTranslation propertyTranslation;
|
||||
propertyTranslation.propertyName = propertyNode.nodeName();
|
||||
propertyTranslation.value = propertyNode.attribute("Value");
|
||||
itemTranslation.propertyesTranslation.append(propertyTranslation);
|
||||
}
|
||||
pageTranslation->itemsTranslation.append(itemTranslation);
|
||||
}
|
||||
}
|
||||
translations->insert(curTranslation->language(),curTranslation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FileXMLReader::FileXMLReader(QString fileName)
|
||||
: m_fileName(fileName)
|
||||
{
|
||||
|
@@ -61,6 +61,7 @@ protected:
|
||||
void readProperty(QObject *item, QDomElement *node);
|
||||
void readQObject(QObject *item, QDomElement *node);
|
||||
void readCollection(QObject *item, QDomElement *node);
|
||||
void readTranslation(QObject *item, QDomElement *node);
|
||||
QVariant getValue(QDomElement *node);
|
||||
|
||||
protected:
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include "lrbasedesignintf.h"
|
||||
#include "serializators/lrxmlserializatorsfactory.h"
|
||||
#include "lrcollection.h"
|
||||
#include "lrreporttranslation.h"
|
||||
#include <QDebug>
|
||||
|
||||
namespace LimeReport{
|
||||
@@ -137,7 +138,9 @@ void XMLWriter::saveProperty(QString name, QObject* item, QDomElement *node)
|
||||
typeName = item->property(name.toLatin1()).typeName();
|
||||
|
||||
CreateSerializator creator=0;
|
||||
if (isCollection(name,item)) { saveCollection(name,item,node); return;}
|
||||
if (isCollection(name, item)) { saveCollection(name,item,node); return; }
|
||||
if (isTranslation(name, item)) { saveTranslation(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);
|
||||
@@ -193,9 +196,15 @@ bool XMLWriter::isCollection(QString propertyName, QObject* item)
|
||||
return QMetaType::type(prop.typeName())==COLLECTION_TYPE_ID;
|
||||
}
|
||||
|
||||
bool XMLWriter::isTranslation(QString propertyName, QObject* item)
|
||||
{
|
||||
QMetaProperty prop=item->metaObject()->property(item->metaObject()->indexOfProperty(propertyName.toLatin1()));
|
||||
return QMetaType::type(prop.typeName())==TRANSLATION_TYPE_ID;
|
||||
}
|
||||
|
||||
void XMLWriter::saveCollection(QString propertyName, QObject *item, QDomElement *node)
|
||||
{
|
||||
ICollectionContainer * collection=dynamic_cast<ICollectionContainer*>(item);
|
||||
ICollectionContainer * collection = dynamic_cast<ICollectionContainer*>(item);
|
||||
QDomElement collectionNode=m_doc->createElement(propertyName);
|
||||
collectionNode.setAttribute("Type","Collection");
|
||||
|
||||
@@ -206,6 +215,37 @@ void XMLWriter::saveCollection(QString propertyName, QObject *item, QDomElement
|
||||
node->appendChild(collectionNode);
|
||||
}
|
||||
|
||||
void XMLWriter::saveTranslation(QString propertyName, QObject* item, QDomElement* node)
|
||||
{
|
||||
ITranslationContainer* translationsContainer = dynamic_cast<ITranslationContainer*>(item);
|
||||
if (translationsContainer){
|
||||
QDomElement translationsNode=m_doc->createElement(propertyName);
|
||||
translationsNode.setAttribute("Type","Translation");
|
||||
Translations* translations = translationsContainer->translations();
|
||||
foreach(QLocale::Language language, translations->keys()){
|
||||
QDomElement languageNode = m_doc->createElement(QLocale::languageToString(language));
|
||||
languageNode.setAttribute("Value",QString::number(language));
|
||||
translationsNode.appendChild(languageNode);
|
||||
ReportTranslation* curTranslation = translations->value(language);
|
||||
foreach(PageTranslation* page, curTranslation->pagesTranslation()){
|
||||
QDomElement pageNode = m_doc->createElement(page->pageName);
|
||||
languageNode.appendChild(pageNode);
|
||||
foreach(ItemTranslation item, page->itemsTranslation){
|
||||
QDomElement itemNode = m_doc->createElement(item.itemName);
|
||||
pageNode.appendChild(itemNode);
|
||||
foreach(PropertyTranslation property, item.propertyesTranslation){
|
||||
QDomElement propertyNode = m_doc->createElement(property.propertyName);
|
||||
propertyNode.setAttribute("Value",property.value);
|
||||
itemNode.appendChild(propertyNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
node->appendChild(translationsNode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool XMLWriter::isQObject(QString propertyName, QObject *item)
|
||||
{
|
||||
QMetaProperty prop=item->metaObject()->property(item->metaObject()->indexOfProperty(propertyName.toLatin1()));
|
||||
|
@@ -62,7 +62,9 @@ private:
|
||||
bool enumOrFlag(QString name, QObject* item);
|
||||
QString extractClassName(QObject* item);
|
||||
bool isCollection(QString propertyName, QObject *item);
|
||||
bool isTranslation(QString propertyName, QObject *item);
|
||||
void saveCollection(QString propertyName, QObject *item, QDomElement *node);
|
||||
void saveTranslation(QString propertyName, QObject *item, QDomElement *node);
|
||||
bool isQObject(QString propertyName, QObject *item);
|
||||
bool replaceNode(QDomElement node, QObject *item);
|
||||
private:
|
||||
|
Reference in New Issue
Block a user