mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-24 00:33:02 +03:00
Language settings has been added to designer
This commit is contained in:
parent
3d8588316b
commit
8df8182875
@ -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
|
||||
|
||||
|
37
designer/designersettingmanager.cpp
Normal file
37
designer/designersettingmanager.cpp
Normal file
@ -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<QLocale::Language>* 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<QLocale::Language>(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();
|
||||
}
|
27
designer/designersettingmanager.h
Normal file
27
designer/designersettingmanager.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef DESIGNERSETTINGMANAGER_H
|
||||
#define DESIGNERSETTINGMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QLocale>
|
||||
#include <QApplication>
|
||||
#include <QSettings>
|
||||
|
||||
class DesignerSettingManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DesignerSettingManager(QObject *parent = 0);
|
||||
~DesignerSettingManager();
|
||||
void setApplicationInstance(QApplication* application);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void getAviableLanguages(QList<QLocale::Language>* languages);
|
||||
QLocale::Language getCurrentDefaultLanguage();
|
||||
void currentDefaulLanguageChanged(QLocale::Language language);
|
||||
private:
|
||||
QApplication* m_app;
|
||||
QSettings* m_setting;
|
||||
};
|
||||
|
||||
#endif // DESIGNERSETTINGMANAGER_H
|
@ -1,25 +1,46 @@
|
||||
#include <QApplication>
|
||||
#include <LimeReport>
|
||||
#include <QTranslator>
|
||||
#include <QDebug>
|
||||
#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<QLocale::Language>*)),
|
||||
&manager, SLOT(getAviableLanguages(QList<QLocale::Language>*)));
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -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<QLocale::Language>* designerLanguages();
|
||||
QList<QLocale::Language> designerLanguages();
|
||||
QLocale::Language currentDesignerLanguage();
|
||||
signals:
|
||||
void renderStarted();
|
||||
@ -124,6 +122,9 @@ signals:
|
||||
void onLoad(bool& loaded);
|
||||
void onSave();
|
||||
void saveFinished();
|
||||
void getAviableLanguages(QList<QLocale::Language>* languages);
|
||||
void currentDefaulLanguageChanged(QLocale::Language);
|
||||
QLocale::Language getCurrentDefaultLanguage();
|
||||
public slots:
|
||||
void cancelRender();
|
||||
protected:
|
||||
|
@ -720,7 +720,9 @@ void ReportDesignWidget::editSetting()
|
||||
m_defaultFont = setting.defaultFont();
|
||||
m_useDarkTheme = setting.userDarkTheme();
|
||||
m_report->setSuppressFieldAndVarError(setting.suppressAbsentFieldsAndVarsWarnings());
|
||||
if (m_report->currentDesignerLanguage() != setting.designerLanguage() ){
|
||||
m_report->setCurrentDesignerLanguage(setting.designerLanguage());
|
||||
}
|
||||
applySettings();
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,6 @@ public:
|
||||
QSettings* settings();
|
||||
void restoreSetting();
|
||||
void setShowProgressDialog(bool value){m_showProgressDialog = value;}
|
||||
|
||||
private slots:
|
||||
void slotNewReport();
|
||||
void slotNewPage();
|
||||
|
@ -950,40 +950,25 @@ void ReportEnginePrivate::activateLanguage(QLocale::Language language)
|
||||
}
|
||||
}
|
||||
|
||||
QString ReportEnginePrivate::getLanguagesDir() const
|
||||
QList<QLocale::Language> 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<QLocale::Language>* ReportEnginePrivate::designerLanguages()
|
||||
{
|
||||
return &m_designerLanguages;
|
||||
QList<QLocale::Language> 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<QLocale::Language>*)),
|
||||
this, SIGNAL(getAviableLanguages(QList<QLocale::Language>*)));
|
||||
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<QLocale::Language>*ReportEngine::designerLanguages()
|
||||
QList<QLocale::Language> ReportEngine::designerLanguages()
|
||||
{
|
||||
Q_D(ReportEngine);
|
||||
return d->designerLanguages();
|
||||
|
@ -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<QLocale::Language>* designerLanguages();
|
||||
QList<QLocale::Language> designerLanguages();
|
||||
QLocale::Language currentDesignerLanguage();
|
||||
signals:
|
||||
void renderStarted();
|
||||
@ -124,6 +122,9 @@ signals:
|
||||
void onLoad(bool& loaded);
|
||||
void onSave();
|
||||
void saveFinished();
|
||||
void getAviableLanguages(QList<QLocale::Language>* languages);
|
||||
void currentDefaulLanguageChanged(QLocale::Language);
|
||||
QLocale::Language getCurrentDefaultLanguage();
|
||||
public slots:
|
||||
void cancelRender();
|
||||
protected:
|
||||
|
@ -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<QLocale::Language>* designerLanguages() = 0;
|
||||
virtual QList<QLocale::Language> 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<QLocale::Language>* designerLanguages();
|
||||
QList<QLocale::Language> 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<QLocale::Language>* 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<QLocale::Language> m_designerLanguages;
|
||||
QLocale::Language m_currentDesignerLanguage;
|
||||
};
|
||||
|
||||
|
@ -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<QLocale::Language>* languages, QLocale::Language currentLanguage)
|
||||
void SettingDialog::setDesignerLanguages(QList<QLocale::Language> 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
|
||||
|
@ -28,10 +28,11 @@ public:
|
||||
void setVerticalGridStep(int value);
|
||||
void setDefaultFont(const QFont& value);
|
||||
void setUseDarkTheme(bool value);
|
||||
void setDesignerLanguages(QList<QLocale::Language>* languages, QLocale::Language currentLanguage);
|
||||
void setDesignerLanguages(QList<QLocale::Language> languages, QLocale::Language currentLanguage);
|
||||
private:
|
||||
Ui::SettingDialog *ui;
|
||||
QList<QLocale::Language>* m_designerLanguages;
|
||||
QList<QLocale::Language> m_aviableLanguages;
|
||||
QLocale::Language m_currentLanguage;
|
||||
};
|
||||
} // namespace LimeReport
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
@ -115,9 +115,9 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<layout class="QHBoxLayout" name="hlLanguage">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<widget class="QLabel" name="lblLanguage">
|
||||
<property name="text">
|
||||
<string>Language</string>
|
||||
</property>
|
||||
|
Loading…
Reference in New Issue
Block a user