diff --git a/include/lrreportengine.h b/include/lrreportengine.h index f785713..b8b0d68 100644 --- a/include/lrreportengine.h +++ b/include/lrreportengine.h @@ -109,9 +109,7 @@ public: bool isBusy(); void setPassPharse(QString& passPharse); - QList aviableLanguages(); - bool addTranslationLanguage(QLocale::Language language); bool setReportLanguage(QLocale::Language language); signals: diff --git a/limereport/limereport.pri b/limereport/limereport.pri index 2f91286..69af57f 100644 --- a/limereport/limereport.pri +++ b/limereport/limereport.pri @@ -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 \ diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index 33fec2a..50d1d48 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -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 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); diff --git a/limereport/lrreportengine.h b/limereport/lrreportengine.h index f785713..b8b0d68 100644 --- a/limereport/lrreportengine.h +++ b/limereport/lrreportengine.h @@ -109,9 +109,7 @@ public: bool isBusy(); void setPassPharse(QString& passPharse); - QList aviableLanguages(); - bool addTranslationLanguage(QLocale::Language language); bool setReportLanguage(QLocale::Language language); signals: diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index 23c53cc..c8d6307 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -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 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); }; } diff --git a/limereport/lrreporttranslation.h b/limereport/lrreporttranslation.h index cae7622..3c7b376 100644 --- a/limereport/lrreporttranslation.h +++ b/limereport/lrreporttranslation.h @@ -66,8 +66,12 @@ typedef QMap 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 aviableLanguages() = 0; }; } // namespace LimeReport diff --git a/limereport/translationeditor/languageselectdialog.cpp b/limereport/translationeditor/languageselectdialog.cpp new file mode 100644 index 0000000..f52be35 --- /dev/null +++ b/limereport/translationeditor/languageselectdialog.cpp @@ -0,0 +1,26 @@ +#include "languageselectdialog.h" +#include "ui_languageselectdialog.h" +#include +#include +#include + +LanguageSelectDialog::LanguageSelectDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::LanguageSelectDialog) +{ + ui->setupUi(this); + for (int i = 2; icomboBox->addItem(QLocale::languageToString(static_cast(i)),static_cast(i)); + } + ui->comboBox->setCurrentText(""); +} + +LanguageSelectDialog::~LanguageSelectDialog() +{ + delete ui; +} + +QLocale::Language LanguageSelectDialog::getSelectedLanguage() +{ + return ui->comboBox->itemData(ui->comboBox->currentIndex()).value(); +} diff --git a/limereport/translationeditor/languageselectdialog.h b/limereport/translationeditor/languageselectdialog.h new file mode 100644 index 0000000..3286527 --- /dev/null +++ b/limereport/translationeditor/languageselectdialog.h @@ -0,0 +1,23 @@ +#ifndef LANGUAGESELECTDIALOG_H +#define LANGUAGESELECTDIALOG_H + +#include +#include + +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 diff --git a/limereport/translationeditor/languageselectdialog.ui b/limereport/translationeditor/languageselectdialog.ui new file mode 100644 index 0000000..1575429 --- /dev/null +++ b/limereport/translationeditor/languageselectdialog.ui @@ -0,0 +1,88 @@ + + + LanguageSelectDialog + + + + 0 + 0 + 336 + 109 + + + + Dialog + + + + + + + + + 0 + 0 + + + + Language + + + + + + + true + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + LanguageSelectDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + LanguageSelectDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/limereport/translationeditor/translationeditor.cpp b/limereport/translationeditor/translationeditor.cpp index 6576702..4db0a6a 100644 --- a/limereport/translationeditor/translationeditor.cpp +++ b/limereport/translationeditor/translationeditor.cpp @@ -3,12 +3,15 @@ #include "lrreportengine.h" #include "lrreportengine_p.h" #include "lrreporttranslation.h" +#include "languageselectdialog.h" +#include 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()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 + + + diff --git a/limereport/translationeditor/translationeditor.h b/limereport/translationeditor/translationeditor.h index ca153c3..a270eb4 100644 --- a/limereport/translationeditor/translationeditor.h +++ b/limereport/translationeditor/translationeditor.h @@ -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; diff --git a/limereport/translationeditor/translationeditor.ui b/limereport/translationeditor/translationeditor.ui index aac3734..86f7a2f 100644 --- a/limereport/translationeditor/translationeditor.ui +++ b/limereport/translationeditor/translationeditor.ui @@ -56,7 +56,7 @@ - + ... @@ -64,10 +64,13 @@ :/translationeditor/images/add.png:/translationeditor/images/add.png + + true + - + ... @@ -75,6 +78,9 @@ :/translationeditor/images/remove.png:/translationeditor/images/remove.png + + true +