mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-25 04:54:40 +03:00
Some translation functionality has been added
This commit is contained in:
parent
2338c9d8b7
commit
881089fd2f
@ -107,6 +107,12 @@ public:
|
|||||||
bool resultIsEditable();
|
bool resultIsEditable();
|
||||||
bool isBusy();
|
bool isBusy();
|
||||||
void setPassPharse(QString& passPharse);
|
void setPassPharse(QString& passPharse);
|
||||||
|
|
||||||
|
|
||||||
|
QList<QLocale::Language> aviableLanguages();
|
||||||
|
bool addTranslationLanguage(QLocale::Language language);
|
||||||
|
bool setReportLanguage(QLocale::Language language);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void renderStarted();
|
void renderStarted();
|
||||||
void renderFinished();
|
void renderFinished();
|
||||||
|
@ -97,7 +97,8 @@ SOURCES += \
|
|||||||
$$REPORT_PATH/lritemscontainerdesignitf.cpp \
|
$$REPORT_PATH/lritemscontainerdesignitf.cpp \
|
||||||
$$REPORT_PATH/lrcolorindicator.cpp \
|
$$REPORT_PATH/lrcolorindicator.cpp \
|
||||||
$$REPORT_PATH/items/lrchartitem.cpp \
|
$$REPORT_PATH/items/lrchartitem.cpp \
|
||||||
$$REPORT_PATH/items/lrchartitemeditor.cpp
|
$$REPORT_PATH/items/lrchartitemeditor.cpp \
|
||||||
|
$$REPORT_PATH/lrreporttranslation.cpp
|
||||||
|
|
||||||
contains(CONFIG, staticlib){
|
contains(CONFIG, staticlib){
|
||||||
SOURCES += $$REPORT_PATH/lrfactoryinitializer.cpp
|
SOURCES += $$REPORT_PATH/lrfactoryinitializer.cpp
|
||||||
@ -205,7 +206,8 @@ HEADERS += \
|
|||||||
$$REPORT_PATH/lritemscontainerdesignitf.h \
|
$$REPORT_PATH/lritemscontainerdesignitf.h \
|
||||||
$$REPORT_PATH/lrcolorindicator.h \
|
$$REPORT_PATH/lrcolorindicator.h \
|
||||||
$$REPORT_PATH/items/lrchartitem.h \
|
$$REPORT_PATH/items/lrchartitem.h \
|
||||||
$$REPORT_PATH/items/lrchartitemeditor.h
|
$$REPORT_PATH/items/lrchartitemeditor.h \
|
||||||
|
$$REPORT_PATH/lrreporttranslation.h
|
||||||
|
|
||||||
contains(CONFIG, staticlib){
|
contains(CONFIG, staticlib){
|
||||||
HEADERS += $$REPORT_PATH/lrfactoryinitializer.h
|
HEADERS += $$REPORT_PATH/lrfactoryinitializer.h
|
||||||
|
@ -1423,6 +1423,21 @@ QList<BaseDesignIntf *> BaseDesignIntf::childBaseItems()
|
|||||||
return resList;
|
return resList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BaseDesignIntf::addChildItems(QList<BaseDesignIntf*>* list){
|
||||||
|
foreach(BaseDesignIntf* item, childBaseItems()){
|
||||||
|
list->append(item);
|
||||||
|
item->addChildItems(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<BaseDesignIntf*> BaseDesignIntf::allChildBaseItems()
|
||||||
|
{
|
||||||
|
QList<BaseDesignIntf *> resList;
|
||||||
|
addChildItems(&resList);
|
||||||
|
return resList;
|
||||||
|
}
|
||||||
|
|
||||||
BaseDesignIntf *BaseDesignIntf::childByName(const QString &name)
|
BaseDesignIntf *BaseDesignIntf::childByName(const QString &name)
|
||||||
{
|
{
|
||||||
foreach(BaseDesignIntf* item, childBaseItems()){
|
foreach(BaseDesignIntf* item, childBaseItems()){
|
||||||
@ -1539,11 +1554,8 @@ BaseDesignIntf *Marker::object() const
|
|||||||
return m_object;
|
return m_object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMap<QString, QString> BaseDesignIntf::getStringForTranslation(){
|
||||||
|
return QMap<QString,QString>();
|
||||||
|
}
|
||||||
|
|
||||||
} //namespace LimeReport
|
} //namespace LimeReport
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -237,6 +237,7 @@ public:
|
|||||||
virtual void beforeDelete();
|
virtual void beforeDelete();
|
||||||
|
|
||||||
QList<BaseDesignIntf*> childBaseItems();
|
QList<BaseDesignIntf*> childBaseItems();
|
||||||
|
QList<BaseDesignIntf*> allChildBaseItems();
|
||||||
BaseDesignIntf* childByName(const QString& name);
|
BaseDesignIntf* childByName(const QString& name);
|
||||||
|
|
||||||
virtual QWidget *defaultEditor();
|
virtual QWidget *defaultEditor();
|
||||||
@ -274,6 +275,7 @@ public:
|
|||||||
void setPatternName(const QString &patternName);
|
void setPatternName(const QString &patternName);
|
||||||
BaseDesignIntf* patternItem() const;
|
BaseDesignIntf* patternItem() const;
|
||||||
void setPatternItem(BaseDesignIntf* patternItem);
|
void setPatternItem(BaseDesignIntf* patternItem);
|
||||||
|
virtual QMap<QString, QString> getStringForTranslation();
|
||||||
|
|
||||||
Q_INVOKABLE QString setItemWidth(qreal width);
|
Q_INVOKABLE QString setItemWidth(qreal width);
|
||||||
Q_INVOKABLE QString setItemHeight(qreal height);
|
Q_INVOKABLE QString setItemHeight(qreal height);
|
||||||
@ -284,6 +286,7 @@ public:
|
|||||||
Q_INVOKABLE QString setItemPosX(qreal xValue);
|
Q_INVOKABLE QString setItemPosX(qreal xValue);
|
||||||
Q_INVOKABLE QString setItemPosY(qreal yValue);
|
Q_INVOKABLE QString setItemPosY(qreal yValue);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
//ICollectionContainer
|
//ICollectionContainer
|
||||||
@ -344,6 +347,8 @@ protected:
|
|||||||
virtual void preparePopUpMenu(QMenu& menu){Q_UNUSED(menu)}
|
virtual void preparePopUpMenu(QMenu& menu){Q_UNUSED(menu)}
|
||||||
virtual void processPopUpAction(QAction* action){Q_UNUSED(action)}
|
virtual void processPopUpAction(QAction* action){Q_UNUSED(action)}
|
||||||
|
|
||||||
|
void addChildItems(QList<BaseDesignIntf*>* list);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateSelectionMarker();
|
void updateSelectionMarker();
|
||||||
int resizeDirectionFlags(QPointF position);
|
int resizeDirectionFlags(QPointF position);
|
||||||
@ -400,6 +405,7 @@ private:
|
|||||||
ReportSettings* m_reportSettings;
|
ReportSettings* m_reportSettings;
|
||||||
QString m_patternName;
|
QString m_patternName;
|
||||||
BaseDesignIntf* m_patternItem;
|
BaseDesignIntf* m_patternItem;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void geometryChanged(QObject* object, QRectF newGeometry, QRectF oldGeometry);
|
void geometryChanged(QObject* object, QRectF newGeometry, QRectF oldGeometry);
|
||||||
void posChanged(QObject* object, QPointF newPos, QPointF oldPos);
|
void posChanged(QObject* object, QPointF newPos, QPointF oldPos);
|
||||||
|
@ -45,7 +45,7 @@ Q_DECLARE_METATYPE(ACollectionProperty)
|
|||||||
|
|
||||||
namespace LimeReport{
|
namespace LimeReport{
|
||||||
|
|
||||||
const int VARIABLE_IS_NOT_USED COLLECTION_TYPE_ID = qMetaTypeId<ACollectionProperty>();
|
const int COLLECTION_TYPE_ID = qMetaTypeId<ACollectionProperty>();
|
||||||
class ICollectionContainer{
|
class ICollectionContainer{
|
||||||
public:
|
public:
|
||||||
virtual QObject* createElement(const QString& collectionName,const QString& elementType)=0;
|
virtual QObject* createElement(const QString& collectionName,const QString& elementType)=0;
|
||||||
|
@ -116,4 +116,10 @@ void ItemDesignIntf::initFlags()
|
|||||||
Spacer::Spacer(QObject *owner, QGraphicsItem *parent)
|
Spacer::Spacer(QObject *owner, QGraphicsItem *parent)
|
||||||
:ItemDesignIntf("Spacer",owner,parent){}
|
:ItemDesignIntf("Spacer",owner,parent){}
|
||||||
|
|
||||||
|
QMap<QString, QString> ContentItemDesignIntf::getStringForTranslation(){
|
||||||
|
QMap<QString,QString>map;
|
||||||
|
map.insert("content",content());
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
}// namespace LimeReport
|
}// namespace LimeReport
|
||||||
|
@ -75,6 +75,7 @@ public:
|
|||||||
:ItemDesignIntf(xmlTypeName,owner,parent){}
|
:ItemDesignIntf(xmlTypeName,owner,parent){}
|
||||||
virtual QString content() const = 0;
|
virtual QString content() const = 0;
|
||||||
virtual void setContent(const QString& value) = 0;
|
virtual void setContent(const QString& value) = 0;
|
||||||
|
QMap<QString, QString> getStringForTranslation();
|
||||||
};
|
};
|
||||||
|
|
||||||
class LayoutDesignIntf : public ItemDesignIntf{
|
class LayoutDesignIntf : public ItemDesignIntf{
|
||||||
|
@ -90,6 +90,11 @@ ReportEnginePrivate::~ReportEnginePrivate()
|
|||||||
}
|
}
|
||||||
foreach(PageDesignIntf* page,m_pages) delete page;
|
foreach(PageDesignIntf* page,m_pages) delete page;
|
||||||
m_pages.clear();
|
m_pages.clear();
|
||||||
|
|
||||||
|
foreach(ReportTranslation* translation, m_translations)
|
||||||
|
delete translation;
|
||||||
|
m_translations.clear();
|
||||||
|
|
||||||
if (m_ownedSettings&&m_settings) delete m_settings;
|
if (m_ownedSettings&&m_settings) delete m_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,10 +183,14 @@ void ReportEnginePrivate::clearReport()
|
|||||||
{
|
{
|
||||||
foreach(PageDesignIntf* page,m_pages) delete page;
|
foreach(PageDesignIntf* page,m_pages) delete page;
|
||||||
m_pages.clear();
|
m_pages.clear();
|
||||||
|
foreach(ReportTranslation* reportTranslation, m_translations)
|
||||||
|
delete reportTranslation;
|
||||||
|
m_translations.clear();
|
||||||
m_datasources->clear(DataSourceManager::Owned);
|
m_datasources->clear(DataSourceManager::Owned);
|
||||||
m_fileName="";
|
m_fileName="";
|
||||||
m_scriptEngineContext->clear();
|
m_scriptEngineContext->clear();
|
||||||
m_reportSettings.setDefaultValues();
|
m_reportSettings.setDefaultValues();
|
||||||
|
|
||||||
emit cleared();
|
emit cleared();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,7 +388,7 @@ bool ReportEnginePrivate::printToPDF(const QString &fileName)
|
|||||||
|
|
||||||
void ReportEnginePrivate::previewReport(PreviewHints hints)
|
void ReportEnginePrivate::previewReport(PreviewHints hints)
|
||||||
{
|
{
|
||||||
QTime start = QTime::currentTime();
|
// QTime start = QTime::currentTime();
|
||||||
try{
|
try{
|
||||||
dataManager()->setDesignTime(false);
|
dataManager()->setDesignTime(false);
|
||||||
ReportPages pages = renderToPages();
|
ReportPages pages = renderToPages();
|
||||||
@ -733,11 +742,62 @@ QString ReportEnginePrivate::renderToString()
|
|||||||
}else return QString();
|
}else return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PageDesignIntf* ReportEnginePrivate::getPageByName(const QString& pageName)
|
||||||
|
{
|
||||||
|
foreach(PageDesignIntf* page, m_pages){
|
||||||
|
if ( page->objectName().compare(pageName, Qt::CaseInsensitive) == 0)
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void ReportEnginePrivate::setPassPhrase(const QString &passPhrase)
|
void ReportEnginePrivate::setPassPhrase(const QString &passPhrase)
|
||||||
{
|
{
|
||||||
m_passPhrase = passPhrase;
|
m_passPhrase = passPhrase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ReportEnginePrivate::addTranslationLanguage(QLocale::Language language)
|
||||||
|
{
|
||||||
|
if (!m_translations.keys().contains(language)){
|
||||||
|
ReportTranslation* translation = new ReportTranslation(language,m_pages);
|
||||||
|
m_translations.insert(language, translation);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
m_lastError = tr("Language %1 already exists").arg(QLocale::languageToString(language));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ReportEnginePrivate::setReportLanguage(QLocale::Language language){
|
||||||
|
if (!m_translations.keys().contains(language)) return false;
|
||||||
|
ReportTranslation* translation = m_translations.value(language);
|
||||||
|
|
||||||
|
foreach(PageTranslation* pageTranslation, translation->pagesTranslation()){
|
||||||
|
PageDesignIntf* page = getPageByName(pageTranslation->pageName);
|
||||||
|
if (page){
|
||||||
|
foreach(ItemTranslation itemTranslation, pageTranslation->itemsTranslation){
|
||||||
|
BaseDesignIntf* item = page->pageItem()->childByName(itemTranslation.itemName);
|
||||||
|
if (item) {
|
||||||
|
foreach(PropertyTranslation propertyTranslation, itemTranslation.propertyesTranslation){
|
||||||
|
item->setProperty(propertyTranslation.propertyName.toLatin1(),propertyTranslation.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QLocale::Language> ReportEnginePrivate::aviableLanguages()
|
||||||
|
{
|
||||||
|
return m_translations.keys();
|
||||||
|
}
|
||||||
|
|
||||||
|
ReportTranslation*ReportEnginePrivate::reportTranslation(QLocale::Language language)
|
||||||
|
{
|
||||||
|
return m_translations.value(language);
|
||||||
|
}
|
||||||
|
|
||||||
bool ReportEnginePrivate::resultIsEditable() const
|
bool ReportEnginePrivate::resultIsEditable() const
|
||||||
{
|
{
|
||||||
return m_resultIsEditable;
|
return m_resultIsEditable;
|
||||||
@ -934,6 +994,24 @@ void ReportEngine::setPassPharse(QString &passPharse)
|
|||||||
d->setPassPhrase(passPharse);
|
d->setPassPhrase(passPharse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QLocale::Language> ReportEngine::aviableLanguages()
|
||||||
|
{
|
||||||
|
Q_D(ReportEngine);
|
||||||
|
return d->aviableLanguages();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ReportEngine::addTranslationLanguage(QLocale::Language language)
|
||||||
|
{
|
||||||
|
Q_D(ReportEngine);
|
||||||
|
return d->addTranslationLanguage(language);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ReportEngine::setReportLanguage(QLocale::Language language)
|
||||||
|
{
|
||||||
|
Q_D(ReportEngine);
|
||||||
|
return d->setReportLanguage(language);
|
||||||
|
}
|
||||||
|
|
||||||
void ReportEngine::setShowProgressDialog(bool value)
|
void ReportEngine::setShowProgressDialog(bool value)
|
||||||
{
|
{
|
||||||
Q_D(ReportEngine);
|
Q_D(ReportEngine);
|
||||||
@ -1046,6 +1124,5 @@ ReportEngine::ReportEngine(ReportEnginePrivate &dd, QObject *parent)
|
|||||||
connect(d, SIGNAL(renderFinished()), this, SIGNAL(renderFinished()));
|
connect(d, SIGNAL(renderFinished()), this, SIGNAL(renderFinished()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}// namespace LimeReport
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -107,6 +107,12 @@ public:
|
|||||||
bool resultIsEditable();
|
bool resultIsEditable();
|
||||||
bool isBusy();
|
bool isBusy();
|
||||||
void setPassPharse(QString& passPharse);
|
void setPassPharse(QString& passPharse);
|
||||||
|
|
||||||
|
|
||||||
|
QList<QLocale::Language> aviableLanguages();
|
||||||
|
bool addTranslationLanguage(QLocale::Language language);
|
||||||
|
bool setReportLanguage(QLocale::Language language);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void renderStarted();
|
void renderStarted();
|
||||||
void renderFinished();
|
void renderFinished();
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include "lrreportrender.h"
|
#include "lrreportrender.h"
|
||||||
#include "serializators/lrstorageintf.h"
|
#include "serializators/lrstorageintf.h"
|
||||||
#include "lrscriptenginemanager.h"
|
#include "lrscriptenginemanager.h"
|
||||||
|
#include "lrreporttranslation.h"
|
||||||
|
|
||||||
class QFileSystemWatcher;
|
class QFileSystemWatcher;
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ class ReportDesignWindow;
|
|||||||
|
|
||||||
//TODO: Add on render callback
|
//TODO: Add on render callback
|
||||||
|
|
||||||
class ReportEnginePrivate : public QObject, public ICollectionContainer
|
class ReportEnginePrivate : public QObject, public ICollectionContainer, public ITranslationContainer
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_DECLARE_PUBLIC(ReportEngine)
|
Q_DECLARE_PUBLIC(ReportEngine)
|
||||||
@ -60,6 +61,8 @@ class ReportEnginePrivate : public QObject, public ICollectionContainer
|
|||||||
Q_PROPERTY(QObject* datasourcesManager READ dataManager)
|
Q_PROPERTY(QObject* datasourcesManager READ dataManager)
|
||||||
Q_PROPERTY(QObject* scriptContext READ scriptContext)
|
Q_PROPERTY(QObject* scriptContext READ scriptContext)
|
||||||
Q_PROPERTY(bool suppressFieldAndVarError READ suppressFieldAndVarError WRITE setSuppressFieldAndVarError)
|
Q_PROPERTY(bool suppressFieldAndVarError READ suppressFieldAndVarError WRITE setSuppressFieldAndVarError)
|
||||||
|
Q_PROPERTY(ATranslationProperty translation READ fakeTranslationReader)
|
||||||
|
|
||||||
friend class PreviewReportWidget;
|
friend class PreviewReportWidget;
|
||||||
public:
|
public:
|
||||||
static void printReport(ItemsReaderIntf::Ptr reader, QPrinter &printer);
|
static void printReport(ItemsReaderIntf::Ptr reader, QPrinter &printer);
|
||||||
@ -128,6 +131,10 @@ public:
|
|||||||
void setResultEditable(bool value);
|
void setResultEditable(bool value);
|
||||||
|
|
||||||
void setPassPhrase(const QString &passPhrase);
|
void setPassPhrase(const QString &passPhrase);
|
||||||
|
bool addTranslationLanguage(QLocale::Language language);
|
||||||
|
bool setReportLanguage(QLocale::Language language);
|
||||||
|
QList<QLocale::Language> aviableLanguages();
|
||||||
|
ReportTranslation* reportTranslation(QLocale::Language language);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void pagesLoadFinished();
|
void pagesLoadFinished();
|
||||||
@ -157,8 +164,13 @@ private:
|
|||||||
void saveError(QString message);
|
void saveError(QString message);
|
||||||
void showError(QString message);
|
void showError(QString message);
|
||||||
//ICollectionContainer
|
//ICollectionContainer
|
||||||
|
//ITranslationContainer
|
||||||
|
Translations* translations(){ return &m_translations;}
|
||||||
|
//ITranslationContainer
|
||||||
ReportPages renderToPages();
|
ReportPages renderToPages();
|
||||||
QString renderToString();
|
QString renderToString();
|
||||||
|
PageDesignIntf* getPageByName(const QString& pageName);
|
||||||
|
ATranslationProperty fakeTranslationReader(){ return ATranslationProperty();}
|
||||||
private:
|
private:
|
||||||
QList<PageDesignIntf*> m_pages;
|
QList<PageDesignIntf*> m_pages;
|
||||||
DataSourceManager* m_datasources;
|
DataSourceManager* m_datasources;
|
||||||
@ -182,6 +194,7 @@ private:
|
|||||||
bool m_resultIsEditable;
|
bool m_resultIsEditable;
|
||||||
QString m_passPhrase;
|
QString m_passPhrase;
|
||||||
QFileSystemWatcher *m_fileWatcher;
|
QFileSystemWatcher *m_fileWatcher;
|
||||||
|
Translations m_translations;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
70
limereport/lrreporttranslation.cpp
Normal file
70
limereport/lrreporttranslation.cpp
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#include "lrreporttranslation.h"
|
||||||
|
|
||||||
|
#include "lrbasedesignintf.h"
|
||||||
|
#include "lrpagedesignintf.h"
|
||||||
|
|
||||||
|
namespace LimeReport{
|
||||||
|
|
||||||
|
ReportTranslation::ReportTranslation(QLocale::Language language, QList<PageDesignIntf*> pages)
|
||||||
|
: m_language(language)
|
||||||
|
{
|
||||||
|
foreach (PageDesignIntf* page, pages){
|
||||||
|
m_pagesTranslation.append(createPageTranslation(page));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReportTranslation::ReportTranslation(const ReportTranslation& reportTranslation)
|
||||||
|
:m_language(reportTranslation.m_language)
|
||||||
|
{
|
||||||
|
foreach(PageTranslation* pageTranslation, reportTranslation.m_pagesTranslation){
|
||||||
|
m_pagesTranslation.append(pageTranslation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReportTranslation::~ReportTranslation()
|
||||||
|
{
|
||||||
|
foreach(PageTranslation* page, m_pagesTranslation){
|
||||||
|
delete page;
|
||||||
|
}
|
||||||
|
m_pagesTranslation.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
PageTranslation* ReportTranslation::createPageTranslation(PageDesignIntf* page)
|
||||||
|
{
|
||||||
|
PageTranslation* pageTranslation = new PageTranslation;
|
||||||
|
pageTranslation->pageName = page->objectName();
|
||||||
|
foreach(BaseDesignIntf* item, page->pageItem()->allChildBaseItems()){
|
||||||
|
QMap<QString,QString> stringsForTranslation = item->getStringForTranslation();
|
||||||
|
if (!stringsForTranslation.isEmpty()){
|
||||||
|
ItemTranslation itemTranslation;
|
||||||
|
itemTranslation.itemName = item->objectName();
|
||||||
|
foreach(QString propertyName, stringsForTranslation.keys()){
|
||||||
|
PropertyTranslation propertyTranslation;
|
||||||
|
propertyTranslation.propertyName = propertyName;
|
||||||
|
propertyTranslation.value = stringsForTranslation.value(propertyName);
|
||||||
|
itemTranslation.propertyesTranslation.append(propertyTranslation);
|
||||||
|
}
|
||||||
|
pageTranslation->itemsTranslation.append(itemTranslation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pageTranslation;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<PageTranslation*> ReportTranslation::pagesTranslation() const
|
||||||
|
{
|
||||||
|
return m_pagesTranslation;
|
||||||
|
}
|
||||||
|
|
||||||
|
PageTranslation*ReportTranslation::createEmptyPageTranslation()
|
||||||
|
{
|
||||||
|
PageTranslation* pageTranslation = new PageTranslation;
|
||||||
|
m_pagesTranslation.append(pageTranslation);
|
||||||
|
return pageTranslation;
|
||||||
|
}
|
||||||
|
|
||||||
|
QLocale::Language ReportTranslation::language() const
|
||||||
|
{
|
||||||
|
return m_language;
|
||||||
|
}
|
||||||
|
|
||||||
|
} //namespace LimeReport
|
67
limereport/lrreporttranslation.h
Normal file
67
limereport/lrreporttranslation.h
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#ifndef REPORTTRANSLATION_H
|
||||||
|
#define REPORTTRANSLATION_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QList>
|
||||||
|
#include <QLocale>
|
||||||
|
#include <QMetaType>
|
||||||
|
|
||||||
|
#include "lrpagedesignintf.h"
|
||||||
|
|
||||||
|
|
||||||
|
class ATranslationProperty{
|
||||||
|
public:
|
||||||
|
ATranslationProperty(){}
|
||||||
|
ATranslationProperty(const ACollectionProperty& ){}
|
||||||
|
virtual ~ATranslationProperty(){}
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(ATranslationProperty)
|
||||||
|
const int TRANSLATION_TYPE_ID = qMetaTypeId<ATranslationProperty>();
|
||||||
|
|
||||||
|
namespace LimeReport{
|
||||||
|
|
||||||
|
struct PropertyTranslation{
|
||||||
|
QString propertyName;
|
||||||
|
QString value;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ItemTranslation{
|
||||||
|
QString itemName;
|
||||||
|
QList<PropertyTranslation> propertyesTranslation;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PageTranslation{
|
||||||
|
QString pageName;
|
||||||
|
QList<ItemTranslation> itemsTranslation;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ReportTranslation{
|
||||||
|
public:
|
||||||
|
ReportTranslation(QLocale::Language language) :m_language(language){}
|
||||||
|
ReportTranslation(QLocale::Language language, QList<PageDesignIntf*> pages);
|
||||||
|
ReportTranslation(const ReportTranslation& reportTranslation);
|
||||||
|
~ReportTranslation();
|
||||||
|
QLocale::Language language() const;
|
||||||
|
QList<PageTranslation*> pagesTranslation() const;
|
||||||
|
PageTranslation* createEmptyPageTranslation();
|
||||||
|
private:
|
||||||
|
PageTranslation* createPageTranslation(PageDesignIntf* page);
|
||||||
|
private:
|
||||||
|
QLocale::Language m_language;
|
||||||
|
QList<PageTranslation*> m_pagesTranslation;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef QMap<QLocale::Language, ReportTranslation*> Translations;
|
||||||
|
|
||||||
|
class ITranslationContainer{
|
||||||
|
public:
|
||||||
|
virtual Translations* translations() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace LimeReport
|
||||||
|
|
||||||
|
//Q_DECLARE_METATYPE(ReportTranslation)
|
||||||
|
|
||||||
|
#endif // REPORTTRANSLATION_H
|
@ -33,6 +33,7 @@
|
|||||||
#include "lrbasedesignintf.h"
|
#include "lrbasedesignintf.h"
|
||||||
#include "lrdesignelementsfactory.h"
|
#include "lrdesignelementsfactory.h"
|
||||||
#include "lrcollection.h"
|
#include "lrcollection.h"
|
||||||
|
#include "lrreporttranslation.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
@ -112,11 +113,12 @@ void XMLReader::readItemFromNode(QObject* item,QDomElement *node)
|
|||||||
QDomElement currentNode =node->childNodes().at(i).toElement();
|
QDomElement currentNode =node->childNodes().at(i).toElement();
|
||||||
if (currentNode.attribute("Type")=="Object"){
|
if (currentNode.attribute("Type")=="Object"){
|
||||||
readQObject(item,¤tNode);
|
readQObject(item,¤tNode);
|
||||||
}else if (currentNode.attribute("Type")=="Collection")
|
} else if (currentNode.attribute("Type")=="Collection")
|
||||||
{
|
{
|
||||||
readCollection(item,¤tNode);
|
readCollection(item,¤tNode);
|
||||||
}
|
} else if (currentNode.attribute("Type")=="Translation"){
|
||||||
else readProperty(item,¤tNode);
|
readTranslation(item,¤tNode);
|
||||||
|
} else readProperty(item,¤tNode);
|
||||||
}
|
}
|
||||||
if (lf) lf->objectLoadFinished();
|
if (lf) lf->objectLoadFinished();
|
||||||
|
|
||||||
@ -191,7 +193,7 @@ void XMLReader::readCollection(QObject *item, QDomElement *node)
|
|||||||
ICollectionContainer* collection = dynamic_cast<ICollectionContainer*>(item);
|
ICollectionContainer* collection = dynamic_cast<ICollectionContainer*>(item);
|
||||||
if (collection){
|
if (collection){
|
||||||
QString collectionName = node->nodeName();
|
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();
|
QDomElement currentNode =node->childNodes().at(i).toElement();
|
||||||
QObject* obj = collection->createElement(collectionName,currentNode.attribute("ClassName"));
|
QObject* obj = collection->createElement(collectionName,currentNode.attribute("ClassName"));
|
||||||
if (obj)
|
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)
|
FileXMLReader::FileXMLReader(QString fileName)
|
||||||
: m_fileName(fileName)
|
: m_fileName(fileName)
|
||||||
{
|
{
|
||||||
|
@ -61,6 +61,7 @@ protected:
|
|||||||
void readProperty(QObject *item, QDomElement *node);
|
void readProperty(QObject *item, QDomElement *node);
|
||||||
void readQObject(QObject *item, QDomElement *node);
|
void readQObject(QObject *item, QDomElement *node);
|
||||||
void readCollection(QObject *item, QDomElement *node);
|
void readCollection(QObject *item, QDomElement *node);
|
||||||
|
void readTranslation(QObject *item, QDomElement *node);
|
||||||
QVariant getValue(QDomElement *node);
|
QVariant getValue(QDomElement *node);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "lrbasedesignintf.h"
|
#include "lrbasedesignintf.h"
|
||||||
#include "serializators/lrxmlserializatorsfactory.h"
|
#include "serializators/lrxmlserializatorsfactory.h"
|
||||||
#include "lrcollection.h"
|
#include "lrcollection.h"
|
||||||
|
#include "lrreporttranslation.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
namespace LimeReport{
|
namespace LimeReport{
|
||||||
@ -137,7 +138,9 @@ void XMLWriter::saveProperty(QString name, QObject* item, QDomElement *node)
|
|||||||
typeName = item->property(name.toLatin1()).typeName();
|
typeName = item->property(name.toLatin1()).typeName();
|
||||||
|
|
||||||
CreateSerializator creator=0;
|
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 (isQObject(name,item)) {
|
||||||
if (qvariant_cast<QObject *>(item->property(name.toLatin1())))
|
if (qvariant_cast<QObject *>(item->property(name.toLatin1())))
|
||||||
putQObjectProperty(name,qvariant_cast<QObject *>(item->property(name.toLatin1())),node);
|
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;
|
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)
|
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);
|
QDomElement collectionNode=m_doc->createElement(propertyName);
|
||||||
collectionNode.setAttribute("Type","Collection");
|
collectionNode.setAttribute("Type","Collection");
|
||||||
|
|
||||||
@ -206,6 +215,37 @@ void XMLWriter::saveCollection(QString propertyName, QObject *item, QDomElement
|
|||||||
node->appendChild(collectionNode);
|
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)
|
bool XMLWriter::isQObject(QString propertyName, QObject *item)
|
||||||
{
|
{
|
||||||
QMetaProperty prop=item->metaObject()->property(item->metaObject()->indexOfProperty(propertyName.toLatin1()));
|
QMetaProperty prop=item->metaObject()->property(item->metaObject()->indexOfProperty(propertyName.toLatin1()));
|
||||||
|
@ -62,7 +62,9 @@ private:
|
|||||||
bool enumOrFlag(QString name, QObject* item);
|
bool enumOrFlag(QString name, QObject* item);
|
||||||
QString extractClassName(QObject* item);
|
QString extractClassName(QObject* item);
|
||||||
bool isCollection(QString propertyName, QObject *item);
|
bool isCollection(QString propertyName, QObject *item);
|
||||||
|
bool isTranslation(QString propertyName, QObject *item);
|
||||||
void saveCollection(QString propertyName, QObject *item, QDomElement *node);
|
void saveCollection(QString propertyName, QObject *item, QDomElement *node);
|
||||||
|
void saveTranslation(QString propertyName, QObject *item, QDomElement *node);
|
||||||
bool isQObject(QString propertyName, QObject *item);
|
bool isQObject(QString propertyName, QObject *item);
|
||||||
bool replaceNode(QDomElement node, QObject *item);
|
bool replaceNode(QDomElement node, QObject *item);
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user