mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2025-01-11 20:31:04 +03:00
Finish Translate
This commit is contained in:
commit
0b0185a7f9
@ -72,6 +72,7 @@ class LIMEREPORT_EXPORT ReportEngine : public QObject{
|
||||
Q_OBJECT
|
||||
friend class ReportDesignWidget;
|
||||
friend class PreviewReportWidget;
|
||||
friend class TranslationEditor;
|
||||
public:
|
||||
static void setSettings(QSettings *value){m_settings=value;}
|
||||
public:
|
||||
@ -107,6 +108,10 @@ public:
|
||||
bool resultIsEditable();
|
||||
bool isBusy();
|
||||
void setPassPharse(QString& passPharse);
|
||||
|
||||
QList<QLocale::Language> aviableLanguages();
|
||||
bool setReportLanguage(QLocale::Language language);
|
||||
|
||||
signals:
|
||||
void renderStarted();
|
||||
void renderFinished();
|
||||
|
@ -72,6 +72,7 @@ SOURCES += \
|
||||
$$REPORT_PATH/items/lrtextitemeditor.cpp \
|
||||
$$REPORT_PATH/items/lrshapeitem.cpp \
|
||||
$$REPORT_PATH/items/lrtextitem.cpp \
|
||||
$$REPORT_PATH/translationeditor/translationeditor.cpp \
|
||||
$$REPORT_PATH/lrbanddesignintf.cpp \
|
||||
$$REPORT_PATH/lrpageitemdesignintf.cpp \
|
||||
$$REPORT_PATH/lrpagedesignintf.cpp \
|
||||
@ -95,9 +96,11 @@ SOURCES += \
|
||||
$$REPORT_PATH/lraboutdialog.cpp \
|
||||
$$REPORT_PATH/lrsettingdialog.cpp \
|
||||
$$REPORT_PATH/lritemscontainerdesignitf.cpp \
|
||||
$$REPORT_PATH/lrcolorindicator.cpp \
|
||||
$$REPORT_PATH/lrcolorindicator.cpp \
|
||||
$$REPORT_PATH/items/lrchartitem.cpp \
|
||||
$$REPORT_PATH/items/lrchartitemeditor.cpp
|
||||
$$REPORT_PATH/items/lrchartitemeditor.cpp \
|
||||
$$REPORT_PATH/lrreporttranslation.cpp \
|
||||
$$REPORT_PATH/translationeditor/languageselectdialog.cpp
|
||||
|
||||
contains(CONFIG, staticlib){
|
||||
SOURCES += $$REPORT_PATH/lrfactoryinitializer.cpp
|
||||
@ -171,6 +174,7 @@ HEADERS += \
|
||||
$$REPORT_PATH/items/lrshapeitem.h \
|
||||
$$REPORT_PATH/items/lrimageitem.h \
|
||||
$$REPORT_PATH/items/lrsimpletagparser.h \
|
||||
$$REPORT_PATH/translationeditor/translationeditor.h \
|
||||
$$REPORT_PATH/lrfactoryinitializer.h \
|
||||
$$REPORT_PATH/lrbanddesignintf.h \
|
||||
$$REPORT_PATH/lrpageitemdesignintf.h \
|
||||
@ -203,9 +207,11 @@ HEADERS += \
|
||||
$$REPORT_PATH/lrsettingdialog.h \
|
||||
$$REPORT_PATH/lrpreviewreportwidget_p.h \
|
||||
$$REPORT_PATH/lritemscontainerdesignitf.h \
|
||||
$$REPORT_PATH/lrcolorindicator.h \
|
||||
$$REPORT_PATH/lrcolorindicator.h \
|
||||
$$REPORT_PATH/items/lrchartitem.h \
|
||||
$$REPORT_PATH/items/lrchartitemeditor.h
|
||||
$$REPORT_PATH/items/lrchartitemeditor.h \
|
||||
$$REPORT_PATH/lrreporttranslation.h \
|
||||
$$REPORT_PATH/translationeditor/languageselectdialog.h
|
||||
|
||||
contains(CONFIG, staticlib){
|
||||
HEADERS += $$REPORT_PATH/lrfactoryinitializer.h
|
||||
@ -227,12 +233,14 @@ FORMS += \
|
||||
$$REPORT_PATH/lraboutdialog.ui \
|
||||
$$REPORT_PATH/lrsettingdialog.ui \
|
||||
$$REPORT_PATH/scriptbrowser/lrscriptbrowser.ui \
|
||||
$$REPORT_PATH/items/lrchartitemeditor.ui
|
||||
$$REPORT_PATH/items/lrchartitemeditor.ui \
|
||||
$$REPORT_PATH/translationeditor/translationeditor.ui \
|
||||
$$PWD/translationeditor/languageselectdialog.ui
|
||||
|
||||
RESOURCES += \
|
||||
$$REPORT_PATH/objectinspector/lobjectinspector.qrc \
|
||||
$$REPORT_PATH/databrowser/lrdatabrowser.qrc \
|
||||
$$REPORT_PATH/report.qrc \
|
||||
$$REPORT_PATH/items/items.qrc \
|
||||
$$REPORT_PATH/scriptbrowser/lrscriptbrowser.qrc
|
||||
|
||||
$$REPORT_PATH/scriptbrowser/lrscriptbrowser.qrc \
|
||||
$$REPORT_PATH/translationeditor/translationeditor.qrc
|
||||
|
@ -86,7 +86,6 @@ contains(CONFIG,zint){
|
||||
}
|
||||
}
|
||||
|
||||
#######
|
||||
####Automatically build required translation files (*.qm)
|
||||
|
||||
contains(CONFIG,build_translations){
|
||||
|
@ -1423,6 +1423,21 @@ QList<BaseDesignIntf *> BaseDesignIntf::childBaseItems()
|
||||
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)
|
||||
{
|
||||
foreach(BaseDesignIntf* item, childBaseItems()){
|
||||
@ -1539,11 +1554,8 @@ BaseDesignIntf *Marker::object() const
|
||||
return m_object;
|
||||
}
|
||||
|
||||
QMap<QString, QString> BaseDesignIntf::getStringForTranslation(){
|
||||
return QMap<QString,QString>();
|
||||
}
|
||||
|
||||
} //namespace LimeReport
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -237,6 +237,7 @@ public:
|
||||
virtual void beforeDelete();
|
||||
|
||||
QList<BaseDesignIntf*> childBaseItems();
|
||||
QList<BaseDesignIntf*> allChildBaseItems();
|
||||
BaseDesignIntf* childByName(const QString& name);
|
||||
|
||||
virtual QWidget *defaultEditor();
|
||||
@ -274,6 +275,7 @@ public:
|
||||
void setPatternName(const QString &patternName);
|
||||
BaseDesignIntf* patternItem() const;
|
||||
void setPatternItem(BaseDesignIntf* patternItem);
|
||||
virtual QMap<QString, QString> getStringForTranslation();
|
||||
|
||||
Q_INVOKABLE QString setItemWidth(qreal width);
|
||||
Q_INVOKABLE QString setItemHeight(qreal height);
|
||||
@ -284,6 +286,7 @@ public:
|
||||
Q_INVOKABLE QString setItemPosX(qreal xValue);
|
||||
Q_INVOKABLE QString setItemPosY(qreal yValue);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
//ICollectionContainer
|
||||
@ -344,6 +347,8 @@ protected:
|
||||
virtual void preparePopUpMenu(QMenu& menu){Q_UNUSED(menu)}
|
||||
virtual void processPopUpAction(QAction* action){Q_UNUSED(action)}
|
||||
|
||||
void addChildItems(QList<BaseDesignIntf*>* list);
|
||||
|
||||
private:
|
||||
void updateSelectionMarker();
|
||||
int resizeDirectionFlags(QPointF position);
|
||||
@ -400,6 +405,7 @@ private:
|
||||
ReportSettings* m_reportSettings;
|
||||
QString m_patternName;
|
||||
BaseDesignIntf* m_patternItem;
|
||||
|
||||
signals:
|
||||
void geometryChanged(QObject* object, QRectF newGeometry, QRectF oldGeometry);
|
||||
void posChanged(QObject* object, QPointF newPos, QPointF oldPos);
|
||||
|
@ -45,7 +45,7 @@ Q_DECLARE_METATYPE(ACollectionProperty)
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
const int VARIABLE_IS_NOT_USED COLLECTION_TYPE_ID = qMetaTypeId<ACollectionProperty>();
|
||||
const int COLLECTION_TYPE_ID = qMetaTypeId<ACollectionProperty>();
|
||||
class ICollectionContainer{
|
||||
public:
|
||||
virtual QObject* createElement(const QString& collectionName,const QString& elementType)=0;
|
||||
|
@ -116,4 +116,10 @@ void ItemDesignIntf::initFlags()
|
||||
Spacer::Spacer(QObject *owner, QGraphicsItem *parent)
|
||||
:ItemDesignIntf("Spacer",owner,parent){}
|
||||
|
||||
QMap<QString, QString> ContentItemDesignIntf::getStringForTranslation(){
|
||||
QMap<QString,QString>map;
|
||||
map.insert("content",content());
|
||||
return map;
|
||||
}
|
||||
|
||||
}// namespace LimeReport
|
||||
|
@ -75,6 +75,7 @@ public:
|
||||
:ItemDesignIntf(xmlTypeName,owner,parent){}
|
||||
virtual QString content() const = 0;
|
||||
virtual void setContent(const QString& value) = 0;
|
||||
QMap<QString, QString> getStringForTranslation();
|
||||
};
|
||||
|
||||
class LayoutDesignIntf : public ItemDesignIntf{
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "lrbasedesignintf.h"
|
||||
#include "lrsettingdialog.h"
|
||||
#include "dialogdesigner/lrdialogdesigner.h"
|
||||
#include "translationeditor/translationeditor.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QObject>
|
||||
@ -137,6 +138,7 @@ ReportDesignWidget::EditorTabType ReportDesignWidget::activeTabType()
|
||||
QString tabType = m_tabWidget->tabWhatsThis(m_tabWidget->currentIndex());
|
||||
if ( tabType.compare("dialog") == 0) return Dialog;
|
||||
if ( tabType.compare("script") == 0) return Script;
|
||||
if ( tabType.compare("translations") == 0) return Translations;
|
||||
return Page;
|
||||
}
|
||||
|
||||
@ -245,10 +247,13 @@ void ReportDesignWidget::createTabs(){
|
||||
dialogDesigner = m_dialogDesignerManager->createFormEditor(dialogDesc->description());
|
||||
pageIndex = m_tabWidget->addTab(dialogDesigner,QIcon(),dialogDesc->name());
|
||||
m_tabWidget->setTabWhatsThis(pageIndex,"dialog");
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
m_traslationEditor = new TranslationEditor(this);
|
||||
pageIndex = m_tabWidget->addTab(m_traslationEditor,QIcon(),tr("Translations"));
|
||||
m_tabWidget->setTabWhatsThis(pageIndex,"translations");
|
||||
|
||||
}
|
||||
|
||||
#ifdef HAVE_QTDESIGNER_INTEGRATION
|
||||
@ -771,6 +776,9 @@ void ReportDesignWidget::slotCurrentTabChanged(int index)
|
||||
}
|
||||
updateDialogs();
|
||||
#endif
|
||||
if (activeTabType() == Translations){
|
||||
m_traslationEditor->setReportEngine(report());
|
||||
}
|
||||
emit activePageChanged();
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,7 @@ class DataBrowser;
|
||||
class ReportDesignWindow;
|
||||
class DialogDesignerManager;
|
||||
class DialogDesigner;
|
||||
class TranslationEditor;
|
||||
|
||||
class ReportDesignWidget : public QWidget
|
||||
{
|
||||
@ -67,7 +68,8 @@ public:
|
||||
enum EditorTabType{
|
||||
Page,
|
||||
Dialog,
|
||||
Script
|
||||
Script,
|
||||
Translations
|
||||
};
|
||||
ReportDesignWidget(ReportEngine* report, QMainWindow *mainWindow, QWidget *parent = 0);
|
||||
~ReportDesignWidget();
|
||||
@ -186,6 +188,7 @@ private:
|
||||
ReportEnginePrivate* m_report;
|
||||
QGraphicsView *m_view;
|
||||
QTextEdit* m_scriptEditor;
|
||||
TranslationEditor* m_traslationEditor;
|
||||
#ifdef HAVE_QTDESIGNER_INTEGRATION
|
||||
DialogDesignerManager* m_dialogDesignerManager;
|
||||
#endif
|
||||
|
@ -64,7 +64,7 @@ ReportEnginePrivate::ReportEnginePrivate(QObject *parent) :
|
||||
m_showProgressDialog(true), m_reportName(""), m_activePreview(0),
|
||||
m_previewWindowIcon(":/report/images/logo32"), m_previewWindowTitle(tr("Preview")),
|
||||
m_reportRendering(false), m_resultIsEditable(true), m_passPhrase("HjccbzHjlbyfCkjy"),
|
||||
m_fileWatcher( new QFileSystemWatcher( this ) )
|
||||
m_fileWatcher( new QFileSystemWatcher( this ) ), m_reportLanguage(QLocale::AnyLanguage)
|
||||
{
|
||||
#ifdef HAVE_STATIC_BUILD
|
||||
initResources();
|
||||
@ -90,6 +90,11 @@ ReportEnginePrivate::~ReportEnginePrivate()
|
||||
}
|
||||
foreach(PageDesignIntf* page,m_pages) delete page;
|
||||
m_pages.clear();
|
||||
|
||||
foreach(ReportTranslation* translation, m_translations)
|
||||
delete translation;
|
||||
m_translations.clear();
|
||||
|
||||
if (m_ownedSettings&&m_settings) delete m_settings;
|
||||
}
|
||||
|
||||
@ -162,6 +167,15 @@ void ReportEnginePrivate::showError(QString message)
|
||||
QMessageBox::critical(0,tr("Error"),message);
|
||||
}
|
||||
|
||||
void ReportEnginePrivate::updateTranslations()
|
||||
{
|
||||
foreach(ReportTranslation* translation, m_translations.values()){
|
||||
foreach(PageDesignIntf* page, m_pages){
|
||||
translation->updatePageTranslation(page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ReportEnginePrivate::slotDataSourceCollectionLoaded(const QString &collectionName)
|
||||
{
|
||||
emit datasourceCollectionLoadFinished(collectionName);
|
||||
@ -178,10 +192,14 @@ void ReportEnginePrivate::clearReport()
|
||||
{
|
||||
foreach(PageDesignIntf* page,m_pages) delete page;
|
||||
m_pages.clear();
|
||||
foreach(ReportTranslation* reportTranslation, m_translations)
|
||||
delete reportTranslation;
|
||||
m_translations.clear();
|
||||
m_datasources->clear(DataSourceManager::Owned);
|
||||
m_fileName="";
|
||||
m_scriptEngineContext->clear();
|
||||
m_reportSettings.setDefaultValues();
|
||||
|
||||
emit cleared();
|
||||
}
|
||||
|
||||
@ -379,7 +397,7 @@ bool ReportEnginePrivate::printToPDF(const QString &fileName)
|
||||
|
||||
void ReportEnginePrivate::previewReport(PreviewHints hints)
|
||||
{
|
||||
QTime start = QTime::currentTime();
|
||||
// QTime start = QTime::currentTime();
|
||||
try{
|
||||
dataManager()->setDesignTime(false);
|
||||
ReportPages pages = renderToPages();
|
||||
@ -733,11 +751,79 @@ QString ReportEnginePrivate::renderToString()
|
||||
}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)
|
||||
{
|
||||
m_passPhrase = passPhrase;
|
||||
}
|
||||
|
||||
bool ReportEnginePrivate::addTranslationLanguage(QLocale::Language language)
|
||||
{
|
||||
if (!m_translations.keys().contains(language)){
|
||||
ReportTranslation* translation = 0;
|
||||
if (!m_translations.contains(QLocale::AnyLanguage)){
|
||||
translation = new ReportTranslation(QLocale::AnyLanguage,m_pages);
|
||||
m_translations.insert(QLocale::AnyLanguage,translation);
|
||||
}
|
||||
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::removeTranslationLanguage(QLocale::Language language)
|
||||
{
|
||||
return m_translations.remove(language) != 0;
|
||||
}
|
||||
|
||||
void ReportEnginePrivate::activateLanguage(QLocale::Language language)
|
||||
{
|
||||
if (!m_translations.keys().contains(language)) return;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ReportEnginePrivate::setReportLanguage(QLocale::Language language){
|
||||
m_reportLanguage = language;
|
||||
if (!m_translations.keys().contains(language)) return false;
|
||||
// activateLanguage(language);
|
||||
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
|
||||
{
|
||||
return m_resultIsEditable;
|
||||
@ -792,7 +878,7 @@ ReportPages ReportEnginePrivate::renderToPages()
|
||||
dataManager()->connectAllDatabases();
|
||||
dataManager()->setDesignTime(false);
|
||||
dataManager()->updateDatasourceModel();
|
||||
|
||||
activateLanguage(m_reportLanguage);
|
||||
connect(m_reportRender.data(),SIGNAL(pageRendered(int)),
|
||||
this, SIGNAL(renderPageFinished(int)));
|
||||
|
||||
@ -823,6 +909,7 @@ ReportPages ReportEnginePrivate::renderToPages()
|
||||
m_reportRender.clear();
|
||||
m_reportRendering = false;
|
||||
}
|
||||
activateLanguage(QLocale::AnyLanguage);
|
||||
return result;
|
||||
} else {
|
||||
return ReportPages();
|
||||
@ -934,6 +1021,18 @@ void ReportEngine::setPassPharse(QString &passPharse)
|
||||
d->setPassPhrase(passPharse);
|
||||
}
|
||||
|
||||
QList<QLocale::Language> ReportEngine::aviableLanguages()
|
||||
{
|
||||
Q_D(ReportEngine);
|
||||
return d->aviableLanguages();
|
||||
}
|
||||
|
||||
bool ReportEngine::setReportLanguage(QLocale::Language language)
|
||||
{
|
||||
Q_D(ReportEngine);
|
||||
return d->setReportLanguage(language);
|
||||
}
|
||||
|
||||
void ReportEngine::setShowProgressDialog(bool value)
|
||||
{
|
||||
Q_D(ReportEngine);
|
||||
@ -1046,6 +1145,5 @@ ReportEngine::ReportEngine(ReportEnginePrivate &dd, QObject *parent)
|
||||
connect(d, SIGNAL(renderFinished()), this, SIGNAL(renderFinished()));
|
||||
}
|
||||
|
||||
}// namespace LimeReport
|
||||
|
||||
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ class LIMEREPORT_EXPORT ReportEngine : public QObject{
|
||||
Q_OBJECT
|
||||
friend class ReportDesignWidget;
|
||||
friend class PreviewReportWidget;
|
||||
friend class TranslationEditor;
|
||||
public:
|
||||
static void setSettings(QSettings *value){m_settings=value;}
|
||||
public:
|
||||
@ -107,6 +108,10 @@ public:
|
||||
bool resultIsEditable();
|
||||
bool isBusy();
|
||||
void setPassPharse(QString& passPharse);
|
||||
|
||||
QList<QLocale::Language> aviableLanguages();
|
||||
bool setReportLanguage(QLocale::Language language);
|
||||
|
||||
signals:
|
||||
void renderStarted();
|
||||
void renderFinished();
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "lrreportrender.h"
|
||||
#include "serializators/lrstorageintf.h"
|
||||
#include "lrscriptenginemanager.h"
|
||||
#include "lrreporttranslation.h"
|
||||
|
||||
class QFileSystemWatcher;
|
||||
|
||||
@ -52,7 +53,7 @@ class ReportDesignWindow;
|
||||
|
||||
//TODO: Add on render callback
|
||||
|
||||
class ReportEnginePrivate : public QObject, public ICollectionContainer
|
||||
class ReportEnginePrivate : public QObject, public ICollectionContainer, public ITranslationContainer
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DECLARE_PUBLIC(ReportEngine)
|
||||
@ -60,6 +61,8 @@ class ReportEnginePrivate : public QObject, public ICollectionContainer
|
||||
Q_PROPERTY(QObject* datasourcesManager READ dataManager)
|
||||
Q_PROPERTY(QObject* scriptContext READ scriptContext)
|
||||
Q_PROPERTY(bool suppressFieldAndVarError READ suppressFieldAndVarError WRITE setSuppressFieldAndVarError)
|
||||
Q_PROPERTY(ATranslationProperty translation READ fakeTranslationReader)
|
||||
|
||||
friend class PreviewReportWidget;
|
||||
public:
|
||||
static void printReport(ItemsReaderIntf::Ptr reader, QPrinter &printer);
|
||||
@ -128,7 +131,11 @@ public:
|
||||
void setResultEditable(bool value);
|
||||
|
||||
void setPassPhrase(const QString &passPhrase);
|
||||
|
||||
bool addTranslationLanguage(QLocale::Language language);
|
||||
bool removeTranslationLanguage(QLocale::Language language);
|
||||
bool setReportLanguage(QLocale::Language language);
|
||||
QList<QLocale::Language> aviableLanguages();
|
||||
ReportTranslation* reportTranslation(QLocale::Language language);
|
||||
signals:
|
||||
void pagesLoadFinished();
|
||||
void datasourceCollectionLoadFinished(const QString& collectionName);
|
||||
@ -157,8 +164,14 @@ private:
|
||||
void saveError(QString message);
|
||||
void showError(QString message);
|
||||
//ICollectionContainer
|
||||
//ITranslationContainer
|
||||
Translations* translations(){ return &m_translations;}
|
||||
void updateTranslations();
|
||||
//ITranslationContainer
|
||||
ReportPages renderToPages();
|
||||
QString renderToString();
|
||||
PageDesignIntf* getPageByName(const QString& pageName);
|
||||
ATranslationProperty fakeTranslationReader(){ return ATranslationProperty();}
|
||||
private:
|
||||
QList<PageDesignIntf*> m_pages;
|
||||
DataSourceManager* m_datasources;
|
||||
@ -182,6 +195,9 @@ private:
|
||||
bool m_resultIsEditable;
|
||||
QString m_passPhrase;
|
||||
QFileSystemWatcher *m_fileWatcher;
|
||||
Translations m_translations;
|
||||
QLocale::Language m_reportLanguage;
|
||||
void activateLanguage(QLocale::Language language);
|
||||
};
|
||||
|
||||
}
|
||||
|
137
limereport/lrreporttranslation.cpp
Normal file
137
limereport/lrreporttranslation.cpp
Normal file
@ -0,0 +1,137 @@
|
||||
#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()){
|
||||
createItemTranslation(item, pageTranslation);
|
||||
}
|
||||
return pageTranslation;
|
||||
}
|
||||
|
||||
void ReportTranslation::createItemTranslation(BaseDesignIntf* item, PageTranslation* pageTranslation){
|
||||
QMap<QString,QString> stringsForTranslation = item->getStringForTranslation();
|
||||
if (!stringsForTranslation.isEmpty()){
|
||||
ItemTranslation* itemTranslation = new ItemTranslation;
|
||||
itemTranslation->itemName = item->objectName();
|
||||
foreach(QString propertyName, stringsForTranslation.keys()){
|
||||
PropertyTranslation* propertyTranslation = new PropertyTranslation;
|
||||
propertyTranslation->propertyName = propertyName;
|
||||
propertyTranslation->value = stringsForTranslation.value(propertyName);
|
||||
propertyTranslation->sourceValue = stringsForTranslation.value(propertyName);
|
||||
propertyTranslation->checked = false;
|
||||
propertyTranslation->sourceHasBeenChanged = false;
|
||||
itemTranslation->propertyesTranslation.append(propertyTranslation);
|
||||
}
|
||||
pageTranslation->itemsTranslation.insert(itemTranslation->itemName, itemTranslation);
|
||||
}
|
||||
}
|
||||
|
||||
PageTranslation* ReportTranslation::findPageTranslation(const QString& page_name)
|
||||
{
|
||||
foreach(PageTranslation* page, m_pagesTranslation){
|
||||
if (page->pageName.compare(page_name) == 0){
|
||||
return page;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ReportTranslation::updatePageTranslation(PageDesignIntf* page)
|
||||
{
|
||||
PageTranslation* pageTranslation = findPageTranslation(page->objectName());
|
||||
if (!pageTranslation){
|
||||
pageTranslation = createPageTranslation(page);
|
||||
m_pagesTranslation.append(pageTranslation);
|
||||
}
|
||||
if (pageTranslation){
|
||||
foreach(BaseDesignIntf* item, page->pageItem()->allChildBaseItems()){
|
||||
QMap<QString,QString> stringsForTranslation = item->getStringForTranslation();
|
||||
if (!stringsForTranslation.isEmpty()){
|
||||
ItemTranslation* itemTranslation = pageTranslation->itemsTranslation.value(item->objectName());
|
||||
if (itemTranslation){
|
||||
foreach(QString propertyName, stringsForTranslation.keys()){
|
||||
PropertyTranslation* propertyTranslation = itemTranslation->findProperty(propertyName);
|
||||
propertyTranslation->sourceValue = stringsForTranslation.value(propertyName);
|
||||
propertyTranslation->sourceHasBeenChanged = propertyTranslation->value != propertyTranslation->sourceValue;
|
||||
}
|
||||
} else {
|
||||
createItemTranslation(item, 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;
|
||||
}
|
||||
|
||||
PropertyTranslation* ItemTranslation::findProperty(const QString& propertyName)
|
||||
{
|
||||
foreach(PropertyTranslation* propertyTranslation, propertyesTranslation){
|
||||
if (propertyTranslation->propertyName.compare(propertyName) == 0){
|
||||
return propertyTranslation;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ItemTranslation::~ItemTranslation()
|
||||
{
|
||||
foreach(PropertyTranslation* property, propertyesTranslation){
|
||||
delete property;
|
||||
}
|
||||
}
|
||||
|
||||
PageTranslation::~PageTranslation()
|
||||
{
|
||||
foreach(ItemTranslation* item, itemsTranslation){
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace LimeReport
|
81
limereport/lrreporttranslation.h
Normal file
81
limereport/lrreporttranslation.h
Normal file
@ -0,0 +1,81 @@
|
||||
#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;
|
||||
QString sourceValue;
|
||||
bool checked;
|
||||
bool sourceHasBeenChanged;
|
||||
};
|
||||
|
||||
struct ItemTranslation{
|
||||
QString itemName;
|
||||
PropertyTranslation* findProperty(const QString& propertyName);
|
||||
~ItemTranslation();
|
||||
QList<PropertyTranslation*> propertyesTranslation;
|
||||
};
|
||||
|
||||
struct PageTranslation{
|
||||
QString pageName;
|
||||
~PageTranslation();
|
||||
QHash<QString,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();
|
||||
void updatePageTranslation(PageDesignIntf* page);
|
||||
PageTranslation* findPageTranslation(const QString& page_name);
|
||||
void createItemTranslation(BaseDesignIntf* item, PageTranslation* pageTranslation);
|
||||
private:
|
||||
PageTranslation* createPageTranslation(PageDesignIntf* page);
|
||||
private:
|
||||
QLocale::Language m_language;
|
||||
QList<PageTranslation*> m_pagesTranslation;
|
||||
};
|
||||
|
||||
|
||||
typedef QMap<QLocale::Language, ReportTranslation*> Translations;
|
||||
|
||||
class ITranslationContainer{
|
||||
public:
|
||||
virtual ~ITranslationContainer(){}
|
||||
virtual Translations* translations() = 0;
|
||||
virtual void updateTranslations() = 0;
|
||||
virtual bool addTranslationLanguage(QLocale::Language language) = 0;
|
||||
virtual bool removeTranslationLanguage(QLocale::Language language) = 0;
|
||||
virtual QList<QLocale::Language> aviableLanguages() = 0;
|
||||
};
|
||||
|
||||
} // namespace LimeReport
|
||||
|
||||
//Q_DECLARE_METATYPE(ReportTranslation)
|
||||
|
||||
#endif // REPORTTRANSLATION_H
|
@ -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,39 @@ 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 = new ItemTranslation();
|
||||
itemTranslation->itemName = itemNode.nodeName();
|
||||
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;
|
||||
itemTranslation->propertyesTranslation.append(propertyTranslation);
|
||||
}
|
||||
pageTranslation->itemsTranslation.insert(itemTranslation->itemName, 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,39 @@ 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);
|
||||
propertyNode.setAttribute("SourceValue", property->sourceValue);
|
||||
propertyNode.setAttribute("Checked", property->checked ? "Y":"N");
|
||||
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:
|
||||
|
BIN
limereport/translationeditor/images/add.png
Normal file
BIN
limereport/translationeditor/images/add.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 655 B |
BIN
limereport/translationeditor/images/checked.png
Normal file
BIN
limereport/translationeditor/images/checked.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 265 B |
BIN
limereport/translationeditor/images/green_check.png
Normal file
BIN
limereport/translationeditor/images/green_check.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
limereport/translationeditor/images/question.png
Normal file
BIN
limereport/translationeditor/images/question.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 542 B |
BIN
limereport/translationeditor/images/remove.png
Normal file
BIN
limereport/translationeditor/images/remove.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 867 B |
26
limereport/translationeditor/languageselectdialog.cpp
Normal file
26
limereport/translationeditor/languageselectdialog.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "languageselectdialog.h"
|
||||
#include "ui_languageselectdialog.h"
|
||||
#include <QLocale>
|
||||
#include <QSet>
|
||||
#include <QDebug>
|
||||
|
||||
LanguageSelectDialog::LanguageSelectDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::LanguageSelectDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
for (int i = 2; i<QLocale::LastLanguage; ++i){
|
||||
ui->comboBox->addItem(QLocale::languageToString(static_cast<QLocale::Language>(i)),static_cast<QLocale::Language>(i));
|
||||
}
|
||||
ui->comboBox->setCurrentText("");
|
||||
}
|
||||
|
||||
LanguageSelectDialog::~LanguageSelectDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QLocale::Language LanguageSelectDialog::getSelectedLanguage()
|
||||
{
|
||||
return ui->comboBox->itemData(ui->comboBox->currentIndex()).value<QLocale::Language>();
|
||||
}
|
23
limereport/translationeditor/languageselectdialog.h
Normal file
23
limereport/translationeditor/languageselectdialog.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef LANGUAGESELECTDIALOG_H
|
||||
#define LANGUAGESELECTDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QLocale>
|
||||
|
||||
namespace Ui {
|
||||
class LanguageSelectDialog;
|
||||
}
|
||||
|
||||
class LanguageSelectDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LanguageSelectDialog(QWidget *parent = 0);
|
||||
~LanguageSelectDialog();
|
||||
QLocale::Language getSelectedLanguage();
|
||||
private:
|
||||
Ui::LanguageSelectDialog *ui;
|
||||
};
|
||||
|
||||
#endif // LANGUAGESELECTDIALOG_H
|
88
limereport/translationeditor/languageselectdialog.ui
Normal file
88
limereport/translationeditor/languageselectdialog.ui
Normal file
@ -0,0 +1,88 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>LanguageSelectDialog</class>
|
||||
<widget class="QDialog" name="LanguageSelectDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>336</width>
|
||||
<height>109</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Language</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox">
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>LanguageSelectDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>LanguageSelectDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
225
limereport/translationeditor/translationeditor.cpp
Normal file
225
limereport/translationeditor/translationeditor.cpp
Normal file
@ -0,0 +1,225 @@
|
||||
#include "translationeditor.h"
|
||||
#include "ui_translationeditor.h"
|
||||
#include "lrreportengine.h"
|
||||
#include "lrreportengine_p.h"
|
||||
#include "lrreporttranslation.h"
|
||||
#include "languageselectdialog.h"
|
||||
#include <QShortcut>
|
||||
|
||||
namespace LimeReport {
|
||||
|
||||
TranslationEditor::TranslationEditor(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::TranslationEditor), m_translationContainer(0),
|
||||
m_currentReportTranslation(0), m_currentPageTranslation(0), m_currentPropertyTranslation(0)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->splitter_3->setStretchFactor(1,10);
|
||||
ui->splitter_3->setStretchFactor(0,2);
|
||||
ui->splitter_2->setStretchFactor(1,2);
|
||||
ui->splitter->setStretchFactor(0,2);
|
||||
QTableWidgetItem* item = new QTableWidgetItem();
|
||||
item->setIcon(QIcon(":/translationeditor/images/checked.png"));
|
||||
ui->tbStrings->setColumnCount(4);
|
||||
ui->tbStrings->setColumnWidth(0,30);
|
||||
ui->tbStrings->setColumnWidth(1,100);
|
||||
ui->tbStrings->setColumnWidth(2,100);
|
||||
ui->tbStrings->setHorizontalHeaderItem(0,item);
|
||||
ui->tbStrings->setHorizontalHeaderItem(1,new QTableWidgetItem(tr("Report Item")));
|
||||
ui->tbStrings->setHorizontalHeaderItem(2,new QTableWidgetItem(tr("Property")));
|
||||
ui->tbStrings->setHorizontalHeaderItem(3,new QTableWidgetItem(tr("Source text")));
|
||||
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Return), this, SLOT(slotItemChecked()));
|
||||
//ui->tbStrings->setSortingEnabled(true);
|
||||
|
||||
}
|
||||
|
||||
void TranslationEditor::setReportEngine(ITranslationContainer* translationContainer)
|
||||
{
|
||||
m_translationContainer = translationContainer;
|
||||
m_currentReportTranslation = 0;
|
||||
m_currentPageTranslation = 0;
|
||||
m_currentPropertyTranslation = 0;
|
||||
|
||||
if (m_translationContainer){
|
||||
m_translationContainer->updateTranslations();
|
||||
updateUi();
|
||||
}
|
||||
}
|
||||
|
||||
TranslationEditor::~TranslationEditor()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QLocale::Language TranslationEditor::getLanguageByName(const QString& languageName){
|
||||
foreach(QLocale::Language language, m_translationContainer->translations()->keys()){
|
||||
if (QLocale::languageToString(language).compare(languageName) == 0){
|
||||
return language;
|
||||
}
|
||||
}
|
||||
return QLocale::AnyLanguage;
|
||||
}
|
||||
|
||||
void TranslationEditor::updateUi()
|
||||
{
|
||||
ui->lvLanguages->clear();
|
||||
ui->twPages->clear();
|
||||
ui->tbStrings->clearContents();
|
||||
ui->teTranslation->setPlainText("");
|
||||
ui->cbChecked->setEnabled(false);
|
||||
|
||||
Q_ASSERT(m_translationContainer != 0);
|
||||
if (m_translationContainer){
|
||||
Translations* translations = m_translationContainer->translations();
|
||||
Q_ASSERT(translations != 0);
|
||||
if (translations){
|
||||
foreach(QLocale::Language language, translations->keys()){
|
||||
if (language != QLocale::AnyLanguage)
|
||||
ui->lvLanguages->addItem(QLocale::languageToString(language));
|
||||
}
|
||||
if (!translations->keys().isEmpty()){
|
||||
ui->lvLanguages->item(0)->setSelected(true);
|
||||
activateLanguage(getLanguageByName(ui->lvLanguages->item(0)->text()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TranslationEditor::activateLanguage(QLocale::Language language)
|
||||
{
|
||||
ui->teTranslation->setEnabled(false);
|
||||
ui->cbChecked->setEnabled(false);
|
||||
ui->twPages->clear();
|
||||
Translations* translations = m_translationContainer->translations();
|
||||
Q_ASSERT(translations != 0);
|
||||
if (translations){
|
||||
m_currentReportTranslation = translations->value(language);
|
||||
Q_ASSERT(m_currentReportTranslation != 0);
|
||||
if (m_currentReportTranslation){
|
||||
foreach(PageTranslation* pageTranslation, m_currentReportTranslation->pagesTranslation()){
|
||||
QTreeWidgetItem* pageItem = new QTreeWidgetItem();
|
||||
pageItem->setText(0,pageTranslation->pageName);
|
||||
ui->twPages->addTopLevelItem(pageItem);
|
||||
}
|
||||
}
|
||||
if (ui->twPages->topLevelItem(0)){
|
||||
ui->twPages->topLevelItem(0)->setSelected(true);
|
||||
activatePage(m_currentReportTranslation->findPageTranslation(ui->twPages->topLevelItem(0)->text(0)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TranslationEditor::activatePage(PageTranslation* pageTranslation)
|
||||
{
|
||||
ui->teTranslation->setEnabled(false);
|
||||
ui->cbChecked->setEnabled(false);
|
||||
Q_ASSERT(pageTranslation != 0);
|
||||
if(pageTranslation){
|
||||
ui->tbStrings->clearContents();
|
||||
ui->tbStrings->setRowCount(0);
|
||||
m_currentPageTranslation = pageTranslation;
|
||||
QStringList items = pageTranslation->itemsTranslation.keys();
|
||||
items.sort();
|
||||
foreach(QString itemName, items){
|
||||
ItemTranslation* itemTranslation = pageTranslation->itemsTranslation.value(itemName);
|
||||
int rowIndex = ui->tbStrings->rowCount();
|
||||
ui->tbStrings->setRowCount(rowIndex+1);
|
||||
foreach(PropertyTranslation* propertyTranslation, itemTranslation->propertyesTranslation){
|
||||
QTableWidgetItem* checkItem = new QTableWidgetItem();
|
||||
if (propertyTranslation->checked)
|
||||
checkItem->setIcon(QIcon(":/translationeditor/images/checked.png"));
|
||||
ui->tbStrings->setItem(rowIndex,0,checkItem);
|
||||
ui->tbStrings->setItem(rowIndex,1,new QTableWidgetItem(itemTranslation->itemName));
|
||||
ui->tbStrings->setItem(rowIndex,2,new QTableWidgetItem(propertyTranslation->propertyName));
|
||||
ui->tbStrings->setItem(rowIndex,3,new QTableWidgetItem(propertyTranslation->sourceValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TranslationEditor::activateTranslation(const QString& itemName, const QString& propertyName)
|
||||
{
|
||||
Q_ASSERT(m_currentPageTranslation != 0);
|
||||
if (m_currentPageTranslation){
|
||||
ItemTranslation* itemTranslation = m_currentPageTranslation->itemsTranslation.value(itemName);
|
||||
Q_ASSERT(itemTranslation !=0 );
|
||||
if (itemTranslation){
|
||||
m_currentPropertyTranslation = m_currentPageTranslation->itemsTranslation.value(itemName)->findProperty(propertyName);
|
||||
Q_ASSERT(m_currentPropertyTranslation != 0);
|
||||
if (m_currentPropertyTranslation){
|
||||
ui->teTranslation->setEnabled(true);
|
||||
ui->cbChecked->setEnabled(true);
|
||||
ui->teTranslation->setText(m_currentPropertyTranslation->value);
|
||||
ui->cbChecked->setChecked(m_currentPropertyTranslation->checked);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TranslationEditor::on_tbStrings_itemSelectionChanged()
|
||||
{
|
||||
if (m_currentPageTranslation)
|
||||
activateTranslation(ui->tbStrings->item(ui->tbStrings->currentRow(),1)->text(), ui->tbStrings->item(ui->tbStrings->currentRow(),2)->text());
|
||||
}
|
||||
|
||||
void TranslationEditor::on_teTranslation_textChanged()
|
||||
{
|
||||
if (m_currentPropertyTranslation)
|
||||
m_currentPropertyTranslation->value = ui->teTranslation->toPlainText();
|
||||
}
|
||||
|
||||
void TranslationEditor::on_cbChecked_toggled(bool checked)
|
||||
{
|
||||
if (m_currentPropertyTranslation){
|
||||
m_currentPropertyTranslation->checked = checked;
|
||||
ui->tbStrings->item(ui->tbStrings->currentRow(),0)->setIcon(checked ? QIcon(":/translationeditor/images/checked.png"):QIcon());
|
||||
}
|
||||
}
|
||||
|
||||
void TranslationEditor::on_twPages_itemSelectionChanged()
|
||||
{
|
||||
if (!ui->twPages->selectedItems().isEmpty()){
|
||||
activatePage(m_currentReportTranslation->findPageTranslation(ui->twPages->selectedItems().at(0)->text(0)));
|
||||
}
|
||||
}
|
||||
|
||||
void TranslationEditor::on_tbAddLanguage_clicked()
|
||||
{
|
||||
LanguageSelectDialog dialog;
|
||||
if (dialog.exec()){
|
||||
m_translationContainer->addTranslationLanguage(dialog.getSelectedLanguage());
|
||||
updateUi();
|
||||
activateLanguage(dialog.getSelectedLanguage());
|
||||
}
|
||||
}
|
||||
|
||||
void TranslationEditor::on_tbDeleteLanguage_clicked()
|
||||
{
|
||||
m_translationContainer->removeTranslationLanguage(m_currentReportTranslation->language());
|
||||
updateUi();
|
||||
}
|
||||
|
||||
void TranslationEditor::slotItemChecked()
|
||||
{
|
||||
if (ui->tbStrings->currentRow()<ui->tbStrings->rowCount()){
|
||||
ui->cbChecked->setChecked(true);
|
||||
ui->tbStrings->selectRow(ui->tbStrings->currentRow()+1);
|
||||
ui->teTranslation->setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
void TranslationEditor::on_lvLanguages_itemSelectionChanged()
|
||||
{
|
||||
if (ui->lvLanguages->currentItem() && m_currentReportTranslation){
|
||||
activateLanguage(getLanguageByName(ui->lvLanguages->currentItem()->text()));
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace LimeReport
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
52
limereport/translationeditor/translationeditor.h
Normal file
52
limereport/translationeditor/translationeditor.h
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef TRANSLATIONEDITOR_H
|
||||
#define TRANSLATIONEDITOR_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLocale>
|
||||
#include <QTreeWidgetItem>
|
||||
#include "lrreporttranslation.h"
|
||||
|
||||
namespace LimeReport {
|
||||
|
||||
namespace Ui {
|
||||
class TranslationEditor;
|
||||
}
|
||||
|
||||
|
||||
class TranslationEditor : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TranslationEditor(QWidget *parent = 0);
|
||||
void setReportEngine(ITranslationContainer* translationContainer);
|
||||
~TranslationEditor();
|
||||
void updateUi();
|
||||
void activateLanguage(QLocale::Language language);
|
||||
void activatePage(PageTranslation* pageTranslation);
|
||||
void activateTranslation(const QString& itemName, const QString& propertyName);
|
||||
private slots:
|
||||
void on_tbStrings_itemSelectionChanged();
|
||||
void on_teTranslation_textChanged();
|
||||
void on_cbChecked_toggled(bool checked);
|
||||
void on_twPages_itemSelectionChanged();
|
||||
void on_tbAddLanguage_clicked();
|
||||
void on_tbDeleteLanguage_clicked();
|
||||
void slotItemChecked();
|
||||
void on_lvLanguages_itemSelectionChanged();
|
||||
|
||||
private:
|
||||
QLocale::Language getLanguageByName(const QString& languageName);
|
||||
private:
|
||||
Ui::TranslationEditor *ui;
|
||||
ITranslationContainer* m_translationContainer;
|
||||
QMap<QString, ReportTranslation*> m_reportTranslations;
|
||||
QMap<QString, PageTranslation> m_pageTranslations;
|
||||
ReportTranslation* m_currentReportTranslation;
|
||||
PageTranslation* m_currentPageTranslation;
|
||||
PropertyTranslation* m_currentPropertyTranslation;
|
||||
};
|
||||
|
||||
} //namespace LimeReport
|
||||
|
||||
#endif // TRANSLATIONEDITOR_H
|
8
limereport/translationeditor/translationeditor.qrc
Normal file
8
limereport/translationeditor/translationeditor.qrc
Normal file
@ -0,0 +1,8 @@
|
||||
<RCC>
|
||||
<qresource prefix="/translationeditor">
|
||||
<file>images/add.png</file>
|
||||
<file>images/remove.png</file>
|
||||
<file>images/checked.png</file>
|
||||
<file>images/question.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
220
limereport/translationeditor/translationeditor.ui
Normal file
220
limereport/translationeditor/translationeditor.ui
Normal file
@ -0,0 +1,220 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>LimeReport::TranslationEditor</class>
|
||||
<widget class="QWidget" name="LimeReport::TranslationEditor">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>873</width>
|
||||
<height>525</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="QFrame" name="frame_2">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Languages</string>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="tbAddLanguage">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="translationeditor.qrc">
|
||||
<normaloff>:/translationeditor/images/add.png</normaloff>:/translationeditor/images/add.png</iconset>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="tbDeleteLanguage">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="translationeditor.qrc">
|
||||
<normaloff>:/translationeditor/images/remove.png</normaloff>:/translationeditor/images/remove.png</iconset>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="lvLanguages"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Pages</string>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="twPages">
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<attribute name="headerVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">1</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="title">
|
||||
<string>Strings</string>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tbStrings">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="columnCount">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Source Text</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QGroupBox" name="groupBox_4">
|
||||
<property name="title">
|
||||
<string>Translation</string>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<widget class="QTextEdit" name="teTranslation"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="cbChecked">
|
||||
<property name="text">
|
||||
<string>Checked</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="translationeditor.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue
Block a user