diff --git a/designer/designer.pro b/designer/designer.pro index 4062e6f..d5abd1b 100644 --- a/designer/designer.pro +++ b/designer/designer.pro @@ -8,7 +8,8 @@ contains(CONFIG,release) { } TEMPLATE = app -SOURCES += main.cpp +SOURCES += main.cpp \ + designersettingmanager.cpp INCLUDEPATH += $$PWD/../include DEPENDPATH += $$PWD/../include @@ -61,3 +62,6 @@ win32 { } } +HEADERS += \ + designersettingmanager.h + diff --git a/designer/designersettingmanager.cpp b/designer/designersettingmanager.cpp new file mode 100644 index 0000000..925143f --- /dev/null +++ b/designer/designersettingmanager.cpp @@ -0,0 +1,37 @@ +#include "designersettingmanager.h" + +DesignerSettingManager::DesignerSettingManager(QObject *parent) : QObject(parent) +{ + m_setting = new QSettings("LimeReport",QCoreApplication::applicationName()); +} + +DesignerSettingManager::~DesignerSettingManager() +{ + delete m_setting; +} + +void DesignerSettingManager::getAviableLanguages(QList* languages) +{ + languages->append(QLocale::Russian); + languages->append(QLocale::English); + languages->append(QLocale::Arabic); +} + +QLocale::Language DesignerSettingManager::getCurrentDefaultLanguage() +{ + m_setting->beginGroup("ReportDesigner"); + QVariant v = m_setting->value("DesignerLanguage"); + m_setting->endGroup(); + if (v.isValid()){ + return static_cast(v.toInt()) ; + } else { + return QLocale::system().language(); + } +} + +void DesignerSettingManager::currentDefaulLanguageChanged(QLocale::Language language) +{ + m_setting->beginGroup("ReportDesigner"); + m_setting->setValue("DesignerLanguage", (int)language); + m_setting->endGroup(); +} diff --git a/designer/designersettingmanager.h b/designer/designersettingmanager.h new file mode 100644 index 0000000..2f07d79 --- /dev/null +++ b/designer/designersettingmanager.h @@ -0,0 +1,27 @@ +#ifndef DESIGNERSETTINGMANAGER_H +#define DESIGNERSETTINGMANAGER_H + +#include +#include +#include +#include + +class DesignerSettingManager : public QObject +{ + Q_OBJECT +public: + explicit DesignerSettingManager(QObject *parent = 0); + ~DesignerSettingManager(); + void setApplicationInstance(QApplication* application); +signals: + +public slots: + void getAviableLanguages(QList* languages); + QLocale::Language getCurrentDefaultLanguage(); + void currentDefaulLanguageChanged(QLocale::Language language); +private: + QApplication* m_app; + QSettings* m_setting; +}; + +#endif // DESIGNERSETTINGMANAGER_H diff --git a/designer/main.cpp b/designer/main.cpp index 9132b47..eeadf9b 100644 --- a/designer/main.cpp +++ b/designer/main.cpp @@ -1,25 +1,46 @@ #include #include #include +#include +#include "designersettingmanager.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); + DesignerSettingManager manager; QTranslator limeReportTranslator; QString translationPath = QApplication::applicationDirPath(); translationPath.append("/languages"); - limeReportTranslator.load("limereport_"+QLocale::system().name(),translationPath); + + QString designerTranslation = QLocale(manager.getCurrentDefaultLanguage()).name(); + + limeReportTranslator.load("limereport_"+designerTranslation, translationPath); a.installTranslator(&limeReportTranslator); QTranslator qtTranslator; - qtTranslator.load("qt_" + QLocale::system().name(),translationPath); + qtTranslator.load("qt_" + designerTranslation, translationPath); a.installTranslator(&qtTranslator); + Qt::LayoutDirection layoutDirection = QLocale(manager.getCurrentDefaultLanguage()).textDirection(); + LimeReport::ReportEngine report; + a.setLayoutDirection(layoutDirection); + report.setPreviewLayoutDirection(layoutDirection); + if (a.arguments().count()>1){ report.loadFromFile(a.arguments().at(1)); } + QObject::connect(&report, SIGNAL(getAviableLanguages(QList*)), + &manager, SLOT(getAviableLanguages(QList*))); + + QObject::connect(&report, SIGNAL(getCurrentDefaultLanguage()), + &manager, SLOT(getCurrentDefaultLanguage())); + + QObject::connect(&report, SIGNAL(currentDefaulLanguageChanged(QLocale::Language)), + &manager, SLOT(currentDefaulLanguageChanged(QLocale::Language))); + report.designReport(); return a.exec(); } + diff --git a/include/lrreportengine.h b/include/lrreportengine.h index 97549f5..e6db8d0 100644 --- a/include/lrreportengine.h +++ b/include/lrreportengine.h @@ -113,9 +113,7 @@ public: bool setReportLanguage(QLocale::Language language); Qt::LayoutDirection previewLayoutDirection(); void setPreviewLayoutDirection(const Qt::LayoutDirection& previewLayoutDirection); - void addDesignerLanguage(QLocale::Language language); - void removeDesignerLanguage(QLocale::Language language); - QList* designerLanguages(); + QList designerLanguages(); QLocale::Language currentDesignerLanguage(); signals: void renderStarted(); @@ -124,6 +122,9 @@ signals: void onLoad(bool& loaded); void onSave(); void saveFinished(); + void getAviableLanguages(QList* languages); + void currentDefaulLanguageChanged(QLocale::Language); + QLocale::Language getCurrentDefaultLanguage(); public slots: void cancelRender(); protected: diff --git a/limereport/lrreportdesignwidget.cpp b/limereport/lrreportdesignwidget.cpp index 9fc328d..c32e608 100644 --- a/limereport/lrreportdesignwidget.cpp +++ b/limereport/lrreportdesignwidget.cpp @@ -720,7 +720,9 @@ void ReportDesignWidget::editSetting() m_defaultFont = setting.defaultFont(); m_useDarkTheme = setting.userDarkTheme(); m_report->setSuppressFieldAndVarError(setting.suppressAbsentFieldsAndVarsWarnings()); - m_report->setCurrentDesignerLanguage(setting.designerLanguage()); + if (m_report->currentDesignerLanguage() != setting.designerLanguage() ){ + m_report->setCurrentDesignerLanguage(setting.designerLanguage()); + } applySettings(); } } diff --git a/limereport/lrreportdesignwindow.h b/limereport/lrreportdesignwindow.h index 6f3dba6..1beb45a 100644 --- a/limereport/lrreportdesignwindow.h +++ b/limereport/lrreportdesignwindow.h @@ -71,7 +71,6 @@ public: QSettings* settings(); void restoreSetting(); void setShowProgressDialog(bool value){m_showProgressDialog = value;} - private slots: void slotNewReport(); void slotNewPage(); diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index c9ae526..5d57a65 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -950,40 +950,25 @@ void ReportEnginePrivate::activateLanguage(QLocale::Language language) } } -QString ReportEnginePrivate::getLanguagesDir() const +QList ReportEnginePrivate::designerLanguages() { - return m_languagesDir; -} -void ReportEnginePrivate::setLanguagesDir(const QString& languagesDir) -{ - m_languagesDir = languagesDir; -} - -void ReportEnginePrivate::addDesignerLanguage(QLocale::Language language) -{ - if (!m_designerLanguages.contains(language)) - m_designerLanguages.append(language); -} - -void ReportEnginePrivate::removeDesignerLanguage(QLocale::Language language) -{ - m_designerLanguages.removeAll(language); -} - -QList* ReportEnginePrivate::designerLanguages() -{ - return &m_designerLanguages; + QList result; + emit getAviableLanguages(&result); + return result; } QLocale::Language ReportEnginePrivate::currentDesignerLanguage() { - return m_currentDesignerLanguage; + QLocale::Language result = emit getCurrentDefaultLanguage(); + return result; } void ReportEnginePrivate::setCurrentDesignerLanguage(QLocale::Language language) { m_currentDesignerLanguage = language; + QMessageBox::information(m_designerWindow, tr("Warning") ,tr("The language will change after the application is restarted")); + emit currentDefaulLanguageChanged(language); } QString ReportEnginePrivate::styleSheet() const @@ -1167,6 +1152,12 @@ ReportEngine::ReportEngine(QObject *parent) connect(d, SIGNAL(onSave()), this, SIGNAL(onSave())); connect(d, SIGNAL(onLoad(bool&)), this, SIGNAL(onLoad(bool&))); connect(d, SIGNAL(saveFinished()), this, SIGNAL(saveFinished())); + connect(d, SIGNAL(getAviableLanguages(QList*)), + this, SIGNAL(getAviableLanguages(QList*))); + connect(d, SIGNAL(currentDefaulLanguageChanged(QLocale::Language)), + this, SIGNAL(currentDefaulLanguageChanged(QLocale::Language))); + connect(d, SIGNAL(getCurrentDefaultLanguage()), + this, SIGNAL(getCurrentDefaultLanguage())); } ReportEngine::~ReportEngine() @@ -1273,19 +1264,19 @@ bool ReportEngine::setReportLanguage(QLocale::Language language) return d->setReportLanguage(language); } -void ReportEngine::addDesignerLanguage(QLocale::Language language) +Qt::LayoutDirection ReportEngine::previewLayoutDirection() { Q_D(ReportEngine); - d->addDesignerLanguage(language); + return d->previewLayoutDirection(); } -void ReportEngine::removeDesignerLanguage(QLocale::Language language) +void ReportEngine::setPreviewLayoutDirection(const Qt::LayoutDirection& previewLayoutDirection) { Q_D(ReportEngine); - d->removeDesignerLanguage(language); + d->setPreviewLayoutDirection(previewLayoutDirection); } -QList*ReportEngine::designerLanguages() +QList ReportEngine::designerLanguages() { Q_D(ReportEngine); return d->designerLanguages(); diff --git a/limereport/lrreportengine.h b/limereport/lrreportengine.h index 97549f5..e6db8d0 100644 --- a/limereport/lrreportengine.h +++ b/limereport/lrreportengine.h @@ -113,9 +113,7 @@ public: bool setReportLanguage(QLocale::Language language); Qt::LayoutDirection previewLayoutDirection(); void setPreviewLayoutDirection(const Qt::LayoutDirection& previewLayoutDirection); - void addDesignerLanguage(QLocale::Language language); - void removeDesignerLanguage(QLocale::Language language); - QList* designerLanguages(); + QList designerLanguages(); QLocale::Language currentDesignerLanguage(); signals: void renderStarted(); @@ -124,6 +122,9 @@ signals: void onLoad(bool& loaded); void onSave(); void saveFinished(); + void getAviableLanguages(QList* languages); + void currentDefaulLanguageChanged(QLocale::Language); + QLocale::Language getCurrentDefaultLanguage(); public slots: void cancelRender(); protected: diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index eb4f611..69fa30f 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -84,7 +84,7 @@ public: virtual void setSuppressFieldAndVarError(bool suppressFieldAndVarError) = 0; virtual void setStyleSheet(const QString& styleSheet) = 0; virtual QString styleSheet() const = 0; - virtual QList* designerLanguages() = 0; + virtual QList designerLanguages() = 0; virtual QLocale::Language currentDesignerLanguage() = 0; virtual void setCurrentDesignerLanguage(QLocale::Language language) = 0; }; @@ -182,11 +182,7 @@ public: void setPreviewLayoutDirection(const Qt::LayoutDirection& previewLayoutDirection); QString styleSheet() const; void setStyleSheet(const QString &styleSheet); - QString getLanguagesDir() const; - void setLanguagesDir(const QString& languagesDir); - void addDesignerLanguage(QLocale::Language language); - void removeDesignerLanguage(QLocale::Language language); - QList* designerLanguages(); + QList designerLanguages(); QLocale::Language currentDesignerLanguage(); void setCurrentDesignerLanguage(QLocale::Language language); signals: @@ -199,6 +195,9 @@ signals: void onLoad(bool& loaded); void onSave(); void saveFinished(); + void getAviableLanguages(QList* languages); + void currentDefaulLanguageChanged(QLocale::Language); + QLocale::Language getCurrentDefaultLanguage(); public slots: bool slotLoadFromFile(const QString& fileName); void cancelRender(); @@ -257,8 +256,6 @@ private: Qt::LayoutDirection m_previewLayoutDirection; LimeReportPluginInterface* m_designerFactory; QString m_styleSheet; - QString m_languagesDir; - QList m_designerLanguages; QLocale::Language m_currentDesignerLanguage; }; diff --git a/limereport/lrsettingdialog.cpp b/limereport/lrsettingdialog.cpp index c1272f1..b05fa74 100644 --- a/limereport/lrsettingdialog.cpp +++ b/limereport/lrsettingdialog.cpp @@ -49,7 +49,7 @@ bool SettingDialog::suppressAbsentFieldsAndVarsWarnings() QLocale::Language SettingDialog::designerLanguage() { - foreach (QLocale::Language language, *m_designerLanguages) { + foreach (QLocale::Language language, m_aviableLanguages) { if (ui->designerLanguage->currentText().compare(QLocale::languageToString(language)) == 0) return language; } @@ -81,14 +81,22 @@ void SettingDialog::setUseDarkTheme(bool value) ui->cbbUseDarkTheme->setChecked(value); } -void SettingDialog::setDesignerLanguages(QList* languages, QLocale::Language currentLanguage) +void SettingDialog::setDesignerLanguages(QList languages, QLocale::Language currentLanguage) { - m_designerLanguages = languages; + m_aviableLanguages = languages; + m_currentLanguage = currentLanguage; + + if (languages.isEmpty()) { + ui->designerLanguage->setVisible(false); + ui->lblLanguage->setVisible(false); + return; + } ui->designerLanguage->addItem(QLocale::languageToString(currentLanguage)); - foreach (QLocale::Language language, *languages) { + foreach (QLocale::Language language, languages) { if (language != currentLanguage) ui->designerLanguage->addItem(QLocale::languageToString(language)); } + ui->designerLanguage->setCurrentText(QLocale::languageToString(currentLanguage)); } } // namespace LimeReport diff --git a/limereport/lrsettingdialog.h b/limereport/lrsettingdialog.h index 20bbb0b..d4c89e3 100644 --- a/limereport/lrsettingdialog.h +++ b/limereport/lrsettingdialog.h @@ -28,10 +28,11 @@ public: void setVerticalGridStep(int value); void setDefaultFont(const QFont& value); void setUseDarkTheme(bool value); - void setDesignerLanguages(QList* languages, QLocale::Language currentLanguage); + void setDesignerLanguages(QList languages, QLocale::Language currentLanguage); private: Ui::SettingDialog *ui; - QList* m_designerLanguages; + QList m_aviableLanguages; + QLocale::Language m_currentLanguage; }; } // namespace LimeReport diff --git a/limereport/lrsettingdialog.ui b/limereport/lrsettingdialog.ui index 688ad14..fa7da68 100644 --- a/limereport/lrsettingdialog.ui +++ b/limereport/lrsettingdialog.ui @@ -11,7 +11,7 @@ - + 0 0 @@ -115,9 +115,9 @@ - + - + Language