LimeReport/limereport/lrsettingdialog.cpp

210 lines
5.4 KiB
C++
Raw Permalink Normal View History

#include "lrsettingdialog.h"
#include "ui_lrsettingdialog.h"
2019-01-29 23:18:24 +03:00
#include "lrglobal.h"
2017-12-11 16:48:00 +03:00
#include <QFile>
2019-05-26 15:15:06 +03:00
#include <QFileInfo>
namespace LimeReport{
SettingDialog::SettingDialog(QWidget *parent) :
2020-03-19 20:09:35 +03:00
QDialog(parent),
ui(new Ui::SettingDialog), m_settings(0)
{
ui->setupUi(this);
2019-05-26 15:15:06 +03:00
ui->toolBox->setCurrentIndex(0);
2019-01-29 23:18:24 +03:00
ui->indentSize->setRange(0,10);
}
SettingDialog::~SettingDialog()
{
delete ui;
}
int SettingDialog::verticalGridStep()
{
return ui->verticalGridStep->value();
}
int SettingDialog::horizontalGridStep()
{
return ui->horizontalGridStep->value();
}
QFont SettingDialog::defaultFont()
{
QFont result = ui->defaultFont->currentFont();
result.setPointSize(ui->defaultFontSize->value());
return result;
}
2019-01-29 23:18:24 +03:00
QFont SettingDialog::scriptFont()
{
QFont result = ui->scriptFont->currentFont();
result.setPointSize(ui->scriptFontSize->value());
return result;
}
int SettingDialog::tabIndention()
{
return ui->indentSize->value();
}
2019-05-26 15:15:06 +03:00
QString SettingDialog::theme()
2017-12-11 16:48:00 +03:00
{
2019-05-26 15:15:06 +03:00
return ui->cbTheme->currentText();
2017-12-11 16:48:00 +03:00
}
bool SettingDialog::suppressAbsentFieldsAndVarsWarnings()
{
return ui->cbSuppressWarnings->isChecked();
}
2018-04-10 16:28:48 +03:00
QLocale::Language SettingDialog::designerLanguage()
{
foreach (QLocale::Language language, m_aviableLanguages) {
2018-04-10 16:28:48 +03:00
if (ui->designerLanguage->currentText().compare(QLocale::languageToString(language)) == 0)
return language;
}
return QLocale().language();
}
QString SettingDialog::reportUnits()
{
return ui->reportUnits->currentText();
}
int SettingDialog::baseItemPadding()
{
return ui->neBaseItemPadding->value();
}
void SettingDialog::setSuppressAbsentFieldsAndVarsWarnings(bool value){
ui->cbSuppressWarnings->setChecked(value);
}
void SettingDialog::setBaseItemPadding(int value)
{
ui->neBaseItemPadding->setValue(value);
}
void SettingDialog::setHorizontalGridStep(int value)
{
ui->horizontalGridStep->setValue(value);
}
void SettingDialog::setVerticalGridStep(int value)
{
ui->verticalGridStep->setValue(value);
}
void SettingDialog::setDefaultFont(const QFont &value)
{
ui->defaultFont->setCurrentFont(value);
ui->defaultFontSize->setValue(value.pointSize());
}
2019-01-29 23:18:24 +03:00
void SettingDialog::setScriptFont(const QFont& value)
{
ui->scriptFont->setCurrentFont(value);
ui->scriptFontSize->setValue(value.pointSize());
}
void SettingDialog::setScritpTabIndention(int size)
{
ui->indentSize->setValue(size);
}
2019-05-26 15:15:06 +03:00
void SettingDialog::setTheme(const QString &theme)
2017-12-11 16:48:00 +03:00
{
2021-08-23 08:07:08 +03:00
#if QT_VERSION < 0x050000
2019-05-26 15:15:06 +03:00
ui->cbTheme->setCurrentIndex(ui->cbTheme->findText(theme));
#else
ui->cbTheme->setCurrentText(theme);
#endif
2017-12-11 16:48:00 +03:00
}
void SettingDialog::setDesignerLanguages(QList<QLocale::Language> languages, QLocale::Language currentLanguage)
2018-04-10 16:28:48 +03:00
{
m_aviableLanguages = languages;
m_currentLanguage = currentLanguage;
if (languages.isEmpty()) {
ui->designerLanguage->setVisible(false);
ui->lblLanguage->setVisible(false);
return;
}
2018-04-10 16:28:48 +03:00
ui->designerLanguage->addItem(QLocale::languageToString(currentLanguage));
foreach (QLocale::Language language, languages) {
2018-04-10 16:28:48 +03:00
if (language != currentLanguage)
ui->designerLanguage->addItem(QLocale::languageToString(language));
}
2021-08-23 08:07:08 +03:00
#if QT_VERSION < 0x050000
2018-12-11 20:04:44 +03:00
ui->designerLanguage->setCurrentIndex(ui->designerLanguage->findText(QLocale::languageToString(currentLanguage)));
#else
ui->designerLanguage->setCurrentText(QLocale::languageToString(currentLanguage));
2018-12-11 20:04:44 +03:00
#endif
2018-04-10 16:28:48 +03:00
}
2019-05-26 15:15:06 +03:00
void SettingDialog::setDesignerThemes(QList<QString> themes, const QString &currentTheme)
{
ui->cbTheme->clear();
ui->cbTheme->addItems(themes);
2021-08-23 08:07:08 +03:00
#if QT_VERSION < 0x050000
2019-05-26 15:15:06 +03:00
ui->cbTheme->setCurrentIndex(ui->cbTheme->findText(currentTheme));
#else
ui->cbTheme->setCurrentText(currentTheme);
#endif
}
void SettingDialog::setDesignerUnites(QList<QString> unitTypes, const QString currentUnitType)
{
ui->reportUnits->clear();
ui->reportUnits->addItems(unitTypes);
2021-08-23 08:07:08 +03:00
#if QT_VERSION < 0x050000
2021-08-24 08:37:40 +03:00
ui->reportUnits->setCurrentIndex(ui->reportUnits->findText(currentUnitType));
#else
ui->reportUnits->setCurrentText(currentUnitType);
#endif
}
2019-01-29 23:18:24 +03:00
void SettingDialog::setSettings(QSettings* settings){
m_settings = settings;
if (m_settings){
m_settings->beginGroup("ScriptEditor");
QVariant fontName = m_settings->value("DefaultFontName");
if (fontName.isValid()){
QVariant fontSize = m_settings->value("DefaultFontSize");
ui->scriptFont->setCurrentFont(QFont(fontName.toString(),fontSize.toInt()));
ui->scriptFontSize->setValue(fontSize.toInt());
}
QVariant indentSize = m_settings->value("TabIndention");
if (indentSize.isValid()){
ui->indentSize->setValue(indentSize.toInt());
} else {
ui->indentSize->setValue(LimeReport::Const::DEFAULT_TAB_INDENTION);
}
m_settings->endGroup();
}
}
void SettingDialog::on_bbOkCancel_accepted()
{
if (m_settings){
m_settings->beginGroup("ScriptEditor");
m_settings->setValue("DefaultFontName", ui->scriptFont->currentFont().family());
m_settings->setValue("DefaultFontSize", ui->scriptFontSize->value());
m_settings->setValue("TabIndention", ui->indentSize->value());
m_settings->endGroup();
}
}
2019-05-26 15:15:06 +03:00
bool SettingDialog::isFileExists(const QString &path)
{
QFileInfo check_file(path);
return check_file.exists() && check_file.isFile();
}
} // namespace LimeReport
2019-01-29 23:18:24 +03:00