0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-23 16:22:58 +03:00

Translation has been finished

This commit is contained in:
Arin Alexander 2017-08-16 01:18:56 +03:00
parent c085944ac9
commit b232b79d8c
12 changed files with 257 additions and 29 deletions

View File

@ -109,9 +109,7 @@ public:
bool isBusy();
void setPassPharse(QString& passPharse);
QList<QLocale::Language> aviableLanguages();
bool addTranslationLanguage(QLocale::Language language);
bool setReportLanguage(QLocale::Language language);
signals:

View File

@ -96,10 +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/lrreporttranslation.cpp
$$REPORT_PATH/lrreporttranslation.cpp \
$$REPORT_PATH/translationeditor/languageselectdialog.cpp
contains(CONFIG, staticlib){
SOURCES += $$REPORT_PATH/lrfactoryinitializer.cpp
@ -209,7 +210,8 @@ HEADERS += \
$$REPORT_PATH/lrcolorindicator.h \
$$REPORT_PATH/items/lrchartitem.h \
$$REPORT_PATH/items/lrchartitemeditor.h \
$$REPORT_PATH/lrreporttranslation.h
$$REPORT_PATH/lrreporttranslation.h \
$$REPORT_PATH/translationeditor/languageselectdialog.h
contains(CONFIG, staticlib){
HEADERS += $$REPORT_PATH/lrfactoryinitializer.h
@ -232,7 +234,8 @@ FORMS += \
$$REPORT_PATH/lrsettingdialog.ui \
$$REPORT_PATH/scriptbrowser/lrscriptbrowser.ui \
$$REPORT_PATH/items/lrchartitemeditor.ui \
$$REPORT_PATH/translationeditor/translationeditor.ui
$$REPORT_PATH/translationeditor/translationeditor.ui \
$$PWD/translationeditor/languageselectdialog.ui
RESOURCES += \
$$REPORT_PATH/objectinspector/lobjectinspector.qrc \

View File

@ -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();
@ -768,7 +768,12 @@ void ReportEnginePrivate::setPassPhrase(const QString &passPhrase)
bool ReportEnginePrivate::addTranslationLanguage(QLocale::Language language)
{
if (!m_translations.keys().contains(language)){
ReportTranslation* translation = new ReportTranslation(language,m_pages);
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 {
@ -777,8 +782,14 @@ bool ReportEnginePrivate::addTranslationLanguage(QLocale::Language language)
}
}
bool ReportEnginePrivate::setReportLanguage(QLocale::Language language){
if (!m_translations.keys().contains(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()){
@ -794,6 +805,12 @@ bool ReportEnginePrivate::setReportLanguage(QLocale::Language language){
}
}
}
}
bool ReportEnginePrivate::setReportLanguage(QLocale::Language language){
m_reportLanguage = language;
if (!m_translations.keys().contains(language)) return false;
// activateLanguage(language);
return true;
}
@ -861,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)));
@ -892,6 +909,7 @@ ReportPages ReportEnginePrivate::renderToPages()
m_reportRender.clear();
m_reportRendering = false;
}
activateLanguage(QLocale::AnyLanguage);
return result;
} else {
return ReportPages();
@ -1009,12 +1027,6 @@ QList<QLocale::Language> ReportEngine::aviableLanguages()
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);

View File

@ -109,9 +109,7 @@ public:
bool isBusy();
void setPassPharse(QString& passPharse);
QList<QLocale::Language> aviableLanguages();
bool addTranslationLanguage(QLocale::Language language);
bool setReportLanguage(QLocale::Language language);
signals:

View File

@ -132,6 +132,7 @@ public:
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);
@ -195,6 +196,8 @@ private:
QString m_passPhrase;
QFileSystemWatcher *m_fileWatcher;
Translations m_translations;
QLocale::Language m_reportLanguage;
void activateLanguage(QLocale::Language language);
};
}

View File

@ -66,8 +66,12 @@ 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

View 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>();
}

View 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

View 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>

View File

@ -3,12 +3,15 @@
#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)
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);
@ -25,6 +28,7 @@ TranslationEditor::TranslationEditor(QWidget *parent) :
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);
}
@ -32,6 +36,10 @@ TranslationEditor::TranslationEditor(QWidget *parent) :
void TranslationEditor::setReportEngine(ITranslationContainer* translationContainer)
{
m_translationContainer = translationContainer;
m_currentReportTranslation = 0;
m_currentPageTranslation = 0;
m_currentPropertyTranslation = 0;
if (m_translationContainer){
m_translationContainer->updateTranslations();
updateUi();
@ -43,10 +51,22 @@ 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){
@ -54,11 +74,12 @@ void TranslationEditor::updateUi()
Q_ASSERT(translations != 0);
if (translations){
foreach(QLocale::Language language, translations->keys()){
ui->lvLanguages->addItem(QLocale::languageToString(language));
if (language != QLocale::AnyLanguage)
ui->lvLanguages->addItem(QLocale::languageToString(language));
}
if (!translations->keys().isEmpty()){
ui->lvLanguages->item(0)->setSelected(true);
activateLanguage(translations->keys().at(0));
activateLanguage(getLanguageByName(ui->lvLanguages->item(0)->text()));
}
}
}
@ -138,18 +159,22 @@ void TranslationEditor::activateTranslation(const QString& itemName, const QStri
void TranslationEditor::on_tbStrings_itemSelectionChanged()
{
activateTranslation(ui->tbStrings->item(ui->tbStrings->currentRow(),1)->text(), ui->tbStrings->item(ui->tbStrings->currentRow(),2)->text());
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()
{
m_currentPropertyTranslation->value = ui->teTranslation->toPlainText();
if (m_currentPropertyTranslation)
m_currentPropertyTranslation->value = ui->teTranslation->toPlainText();
}
void TranslationEditor::on_cbChecked_toggled(bool checked)
{
m_currentPropertyTranslation->checked = checked;
ui->tbStrings->item(ui->tbStrings->currentRow(),0)->setIcon(checked ? QIcon(":/translationeditor/images/checked.png"):QIcon());
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()
@ -159,7 +184,42 @@ void TranslationEditor::on_twPages_itemSelectionChanged()
}
}
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

View File

@ -29,7 +29,14 @@ private slots:
void on_tbStrings_itemSelectionChanged();
void on_teTranslation_textChanged();
void on_cbChecked_toggled(bool checked);
void on_twPages_itemSelectionChanged();
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;

View File

@ -56,7 +56,7 @@
</spacer>
</item>
<item>
<widget class="QToolButton" name="toolButton">
<widget class="QToolButton" name="tbAddLanguage">
<property name="text">
<string>...</string>
</property>
@ -64,10 +64,13 @@
<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="toolButton_2">
<widget class="QToolButton" name="tbDeleteLanguage">
<property name="text">
<string>...</string>
</property>
@ -75,6 +78,9 @@
<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>