diff --git a/accommodation/accommodation.pro b/accommodation/accommodation.pro index 905e0d7..3ea824e 100644 --- a/accommodation/accommodation.pro +++ b/accommodation/accommodation.pro @@ -10,7 +10,7 @@ TARGET = accommodation TEMPLATE = lib DEFINES += ACCOMMODATION_LIBRARY\ - _GLIBCXX_USE_CXX11_ABI=0 + _GLIBCXX_USE_CXX11_ABI=1 SOURCES += accommodation.cpp \ data/person.cpp \ diff --git a/accommodation/acform.cpp b/accommodation/acform.cpp index 1a8aaff..a8a9044 100644 --- a/accommodation/acform.cpp +++ b/accommodation/acform.cpp @@ -2,6 +2,9 @@ #include "ui_acform.h" #include +#include +#include + #include "accommodation-odb.hxx" AcForm::AcForm(QWidget *parent) : diff --git a/application/application.pro b/application/application.pro index b41a177..307a02c 100644 --- a/application/application.pro +++ b/application/application.pro @@ -11,7 +11,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = prodejna TEMPLATE = app -DEFINES += _GLIBCXX_USE_CXX11_ABI=0 +DEFINES += _GLIBCXX_USE_CXX11_ABI=1 win32 { INCLUDEPATH += d:/prac/odb/libodb-2.4.0 diff --git a/application/mainwindow.cpp b/application/mainwindow.cpp index 85e65ec..d8134fd 100644 --- a/application/mainwindow.cpp +++ b/application/mainwindow.cpp @@ -121,3 +121,9 @@ void MainWindow::showEvent(QShowEvent *evt) m_loginDialog->show(); } } + +void MainWindow::on_actionSettings_triggered() +{ + SettingsForm *settings = new SettingsForm(this); + settings->show(); +} diff --git a/application/mainwindow.h b/application/mainwindow.h index dd14b47..220ef84 100644 --- a/application/mainwindow.h +++ b/application/mainwindow.h @@ -30,6 +30,8 @@ private slots: void on_actionLogin_triggered(); + void on_actionSettings_triggered(); + private: Ui::MainWindow *ui; LoginDialog *m_loginDialog; diff --git a/application/mainwindow.ui b/application/mainwindow.ui index 35c69a0..f8efb33 100644 --- a/application/mainwindow.ui +++ b/application/mainwindow.ui @@ -56,7 +56,7 @@ 0 0 1000 - 21 + 19 @@ -78,6 +78,7 @@ false + @@ -99,6 +100,14 @@ Login... + + + Settings + + + Settings + + diff --git a/core/autoform.h b/core/autoform.h index 3970c3e..9895c83 100644 --- a/core/autoform.h +++ b/core/autoform.h @@ -2,179 +2,61 @@ #define AUTOFORM_H #include -#include -#include -#include -#include #include -#include #include -#include -#include - -#include "../qdecimal/src/QDecDouble.hh" -#include "iform.h" #include "service.h" -#include "ivalidator.h" #include "iservice.h" #include "iplugin.h" +#include "formbinder.h" #include "combodata.h" template -class AutoForm : public IForm +class AutoForm : public FormBinder { public: - explicit AutoForm(QWidget *parent = 0) : IForm(parent) { + explicit AutoForm(QWidget *parent = 0) : FormBinder(parent) { m_serviceConnected = false; m_saved = false; } - virtual ~AutoForm() { - foreach (IValidator *val, m_validators) { - delete val; - } - m_validators.clear(); - } - - void setEntity(QSharedPointer entity) { - m_entity = entity; - bindToUi(); - } - - QSharedPointer entity() { - return m_entity; - } + virtual ~AutoForm() { } void setNewRec(bool isNew) { - m_newRec = isNew; - } - - void registerBinding(QWidget *widget) { - if (!m_bindWidgets.contains(widget)) { - m_bindWidgets.append(widget); - } - } - - void registerBinding(QComboBox *combo, const QList &values) { - m_bindCombos[combo] = values; - } - - void registerValidator(IValidator *validator) { - m_validators.append(validator); - } - -protected: - virtual void bindOtherToUi() {} - virtual bool bindOtherToData() { return true; } - virtual void registerCombos() {} - -private: - QSharedPointer m_entity; - QList m_bindWidgets; - QList m_validators; - QHash > m_bindCombos; - - void bindToUi() { - registerCombos(); - foreach (QWidget *widget, m_bindWidgets) { - const char* prop = widget->metaObject()->userProperty().name(); - QVariant value = ((QObject*)m_entity.data())->property(widget->objectName().toStdString().c_str()); - if (value.canConvert()) - { - widget->setProperty(prop, value.value().toString()); - } - else - { - widget->setProperty(prop, value); - } - } - - foreach (QComboBox *combo, m_bindCombos.keys()) { - int idx = 0; - QVariant field = ((QObject*)m_entity.data())->property(combo->objectName().toStdString().c_str()); - - combo->clear(); - for (int i = 0; i < m_bindCombos[combo].size(); i++) { - ComboData data = m_bindCombos[combo][i]; - combo->addItem(data.label(), data.index()); - - if (data.index().canConvert()) { - ComboItem* ci = qobject_cast(data.index().value()); - ComboItem* ciField = qobject_cast(field.value()); - if (ci->eq(ciField)) { - idx = i; - } - } - else if (field == data.index()) { - idx = i; - } - } - - combo->setCurrentIndex(idx); - } - - bindOtherToUi(); - } - - bool bindToData() { - foreach (IValidator *val, m_validators) { - if (!val->validate()) { - emit validationError(val->errMessage()); - return false; - } - } - - foreach (QWidget *widget, m_bindWidgets) { - const char* prop = widget->metaObject()->userProperty().name(); - - QVariant val = widget->property(prop); - if (((QObject*)m_entity.data())->property(widget->objectName().toStdString().c_str()).canConvert()) - { - QDecDouble dec(val.toDouble()); - val = QVariant::fromValue(dec); - } - ((QObject*)m_entity.data())->setProperty(widget->objectName().toStdString().c_str(), val); - } - - foreach (QComboBox *combo, m_bindCombos.keys()) { - ((QObject*)m_entity.data())->setProperty(combo->objectName().toStdString().c_str(), combo->currentData()); - } - - return bindOtherToData(); + this->m_newRec = isNew; } public slots: bool saveRecord() { - if (!bindToData()) + if (!this->bindToData()) { return false; } if (!m_serviceConnected) { - connect(service(), &IService::dbError, [this](QString msg) { - QMessageBox::critical(this, tr("Database error"), tr(msg.toStdString().c_str())); + this->connect(service(), &IService::dbError, [this](QString msg) { + QMessageBox::critical(this, "Database error", msg.toStdString().c_str()); m_saved = false; }); - connect(service(), &IService::dataChanged, [this]() { + this->connect(service(), &IService::dataChanged, [this]() { m_saved = true; }); m_serviceConnected = true; } - if (m_newRec) { - service()->save(entity()); + if (this->m_newRec) { + service()->save(this->entity()); if (m_saved) { - emit recordAdded(); + emit this->recordAdded(); } } else { - service()->update(entity()); + service()->update(this->entity()); if (m_saved) { - emit recordUpdated(); + emit this->recordUpdated(); } } @@ -183,7 +65,7 @@ public slots: private: Service *service() { - IPlugin *plugin = Context::instance().plugin(pluginId()); + IPlugin *plugin = Context::instance().plugin(this->pluginId()); if (plugin == NULL) { Q_ASSERT(false); return NULL; diff --git a/core/core.h b/core/core.h index 851755f..cc8ae69 100644 --- a/core/core.h +++ b/core/core.h @@ -9,5 +9,7 @@ #include "gridform.h" #include "permissionservice.h" #include "combodata.h" +#include "settingsservice.h" +#include "settingsform.h" #endif // CORE_H diff --git a/core/core.pro b/core/core.pro index 9478801..370f413 100644 --- a/core/core.pro +++ b/core/core.pro @@ -12,7 +12,7 @@ TARGET = core TEMPLATE = lib DEFINES += CORE_LIBRARY \ - _GLIBCXX_USE_CXX11_ABI=0 + _GLIBCXX_USE_CXX11_ABI=1 SOURCES += \ data/user.cpp \ @@ -45,7 +45,12 @@ SOURCES += \ itablemodel.cpp \ iservice.cpp \ combodata.cpp \ - data/comboitem.cpp + data/comboitem.cpp \ + settingsservice.cpp \ + data/system.cpp \ + settings/globalsettings.cpp \ + settingsform.cpp \ + settings/globalsettingsform.cpp HEADERS += core.h\ core_global.h \ @@ -89,7 +94,13 @@ HEADERS += core.h\ iservice.h \ combodata.h \ data/comboitem.h \ - enums.h + settingsservice.h \ + data/system.h \ + enums.h \ + settings/globalsettings.h \ + settingsform.h \ + settings/globalsettingsform.h \ + formbinder.h unix { target.path = /usr/lib @@ -121,7 +132,9 @@ FORMS += \ roles/rolesform.ui \ filterui.ui \ savefilterdialog.ui \ - filterdialog.ui + filterdialog.ui \ + settingsform.ui \ + settings/globalsettingsform.ui OTHER_FILES += \ users/metaData.json \ diff --git a/core/coreplugin.cpp b/core/coreplugin.cpp index ad7026b..d36d224 100644 --- a/core/coreplugin.cpp +++ b/core/coreplugin.cpp @@ -1,6 +1,7 @@ #include "coreplugin.h" #include #include +#include "settings/globalsettingsform.h" CorePlugin::CorePlugin() { @@ -21,5 +22,6 @@ void CorePlugin::initServiceUi() { m_service = NULL; m_ui = NULL; + m_settingsUi = new GlobalSettingsForm(); } diff --git a/core/data/core-data.h b/core/data/core-data.h index 2401cfd..c1f1e1e 100644 --- a/core/data/core-data.h +++ b/core/data/core-data.h @@ -8,6 +8,7 @@ class Role; #include "user.h" #include "role.h" #include "permission.h" +#include "system.h" #endif // COREDATA_H diff --git a/core/data/system.cpp b/core/data/system.cpp new file mode 100644 index 0000000..9d81f03 --- /dev/null +++ b/core/data/system.cpp @@ -0,0 +1,31 @@ +#include "system.h" + +System::System() +{ + +} + +int System::id() const +{ + return m_id; +} + +void System::setId(int id) +{ + m_id = id; +} + +QString System::pluginId() const +{ + return m_pluginId; +} + +QString System::settings() const +{ + return m_settings; +} + +void System::setSettings(const QString &settings) +{ + m_settings = settings; +} diff --git a/core/data/system.h b/core/data/system.h new file mode 100644 index 0000000..20ce5b5 --- /dev/null +++ b/core/data/system.h @@ -0,0 +1,34 @@ +#ifndef SYSTEM_H +#define SYSTEM_H + +#include + +#include + +#pragma db object +class System +{ +public: + System(); + + int id() const; + void setId(int id); + + QString pluginId() const; + + QString schemaVersion() const; + + QString settings() const; + void setSettings(const QString &settings); + +private: + friend class odb::access; + +#pragma db id auto + int m_id; + QString m_pluginId; + QString m_schemaVersion; + QString m_settings; +}; + +#endif // SYSTEM_H diff --git a/core/formbinder.h b/core/formbinder.h new file mode 100644 index 0000000..dcac7a9 --- /dev/null +++ b/core/formbinder.h @@ -0,0 +1,136 @@ +#ifndef FORMBINDER_H +#define FORMBINDER_H + +#include +#include +#include +#include +#include +#include + +#include "combodata.h" +#include "ivalidator.h" +#include "iform.h" + +#include "../qdecimal/src/QDecDouble.hh" + +template +class FormBinder : public IForm +{ +public: + + explicit FormBinder(QWidget *parent = NULL) : IForm(parent) {} + + virtual ~FormBinder() { + foreach (IValidator *val, m_validators) { + delete val; + } + m_validators.clear(); + } + + void registerBinding(QWidget *widget) { + if (!m_bindWidgets.contains(widget)) { + m_bindWidgets.append(widget); + } + } + + void registerBinding(QComboBox *combo, const QList &values) { + m_bindCombos[combo] = values; + } + + void registerValidator(IValidator *validator) { + m_validators.append(validator); + } + + void setEntity(QSharedPointer entity) { + m_entity = entity; + bindToUi(); + } + + QSharedPointer entity() { + return m_entity; + } + +protected: + QSharedPointer m_entity; + + virtual void bindOtherToUi() {} + virtual bool bindOtherToData() { return true; } + virtual void registerCombos() {} + + void bindToUi() { + registerCombos(); + foreach (QWidget *widget, m_bindWidgets) { + const char* prop = widget->metaObject()->userProperty().name(); + QVariant value = ((QObject*)m_entity.data())->property(widget->objectName().toStdString().c_str()); + if (value.canConvert()) + { + widget->setProperty(prop, value.value().toString()); + } + else + { + widget->setProperty(prop, value); + } + } + + foreach (QComboBox *combo, m_bindCombos.keys()) { + int idx = 0; + QVariant field = ((QObject*)m_entity.data())->property(combo->objectName().toStdString().c_str()); + + combo->clear(); + for (int i = 0; i < m_bindCombos[combo].size(); i++) { + ComboData data = m_bindCombos[combo][i]; + combo->addItem(data.label(), data.index()); + + if (data.index().canConvert()) { + ComboItem* ci = qobject_cast(data.index().value()); + ComboItem* ciField = qobject_cast(field.value()); + if (ci->eq(ciField)) { + idx = i; + } + } + else if (field == data.index()) { + idx = i; + } + } + + combo->setCurrentIndex(idx); + } + + bindOtherToUi(); + } + + bool bindToData() { + foreach (IValidator *val, m_validators) { + if (!val->validate()) { + emit validationError(val->errMessage()); + return false; + } + } + + foreach (QWidget *widget, m_bindWidgets) { + const char* prop = widget->metaObject()->userProperty().name(); + + QVariant val = widget->property(prop); + if (((QObject*)m_entity.data())->property(widget->objectName().toStdString().c_str()).canConvert()) + { + QDecDouble dec(val.toDouble()); + val = QVariant::fromValue(dec); + } + ((QObject*)m_entity.data())->setProperty(widget->objectName().toStdString().c_str(), val); + } + + foreach (QComboBox *combo, m_bindCombos.keys()) { + ((QObject*)m_entity.data())->setProperty(combo->objectName().toStdString().c_str(), combo->currentData()); + } + + return bindOtherToData(); + } + +private: + QList m_bindWidgets; + QHash > m_bindCombos; + QList m_validators; +}; + +#endif // FORMBINDER_H diff --git a/core/iform.h b/core/iform.h index d11a6c1..6600b2e 100644 --- a/core/iform.h +++ b/core/iform.h @@ -3,6 +3,8 @@ #include #include +#include +#include #include "core_global.h" @@ -16,6 +18,7 @@ public: QString pluginId() const; void setPluginId(const QString &pluginId); + virtual void loadEntity() {} signals: void recordAdded(); diff --git a/core/iplugin.h b/core/iplugin.h index 6a1605b..536bc19 100644 --- a/core/iplugin.h +++ b/core/iplugin.h @@ -17,6 +17,7 @@ public: IPlugin() { m_ui = NULL; m_service = NULL; + m_settingsUi = NULL; } virtual ~IPlugin() { @@ -29,6 +30,11 @@ public: { delete m_ui; } + + if (m_settingsUi != NULL && m_settingsUi->parent() == NULL) + { + delete m_settingsUi; + } } virtual QString pluginName() = 0; @@ -51,6 +57,14 @@ public: return m_ui; } + virtual QWidget *settingsUi() { + return m_settingsUi; + } + + virtual QString settingsTabLabel() { + return pluginName(); + } + template Service *service() { return (Service*)m_service; @@ -58,6 +72,7 @@ public: protected: QWidget *m_ui; + QWidget *m_settingsUi; IService *m_service; }; diff --git a/core/service.h b/core/service.h index 9caa514..3476890 100644 --- a/core/service.h +++ b/core/service.h @@ -26,7 +26,7 @@ public: m_pluginId = pluginId; } - QList > all() { + QList > all(const QString &where = "") { odb::database *db = Context::instance().db(); Q_ASSERT(db); @@ -36,7 +36,16 @@ public: try { - odb::result res = db->template query(); + odb::result res; + + if (where.isEmpty()) + { + res = db->template query(); + } + else + { + res = db->template query(where.toStdString()); + } for (typename odb::result::iterator it = res.begin(); it != res.end(); it++) { ret.append(it.load()); diff --git a/core/settings/globalsettings.cpp b/core/settings/globalsettings.cpp new file mode 100644 index 0000000..1e66133 --- /dev/null +++ b/core/settings/globalsettings.cpp @@ -0,0 +1,96 @@ +#include "globalsettings.h" + +GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent) +{ + +} + +QString GlobalSettings::firmName() const +{ + return m_firmName; +} + +void GlobalSettings::setFirmName(const QString &firmName) +{ + m_firmName = firmName; +} + +QString GlobalSettings::street() const +{ + return m_street; +} + +void GlobalSettings::setStreet(const QString &street) +{ + m_street = street; +} + +QString GlobalSettings::houseNumber() const +{ + return m_houseNumber; +} + +void GlobalSettings::setHouseNumber(const QString &houseNumber) +{ + m_houseNumber = houseNumber; +} + +QString GlobalSettings::zipCode() const +{ + return m_zipCode; +} + +void GlobalSettings::setZipCode(const QString &zipCode) +{ + m_zipCode = zipCode; +} + +QString GlobalSettings::city() const +{ + return m_city; +} + +void GlobalSettings::setCity(const QString &city) +{ + m_city = city; +} + +int GlobalSettings::ic() const +{ + return m_ic; +} + +void GlobalSettings::setIc(int IC) +{ + m_ic = IC; +} + +QString GlobalSettings::dic() const +{ + return m_dic; +} + +void GlobalSettings::setDic(const QString &dic) +{ + m_dic = dic; +} + +bool GlobalSettings::vatPayer() const +{ + return m_vatPayer; +} + +void GlobalSettings::setVatPayer(bool vatPayer) +{ + m_vatPayer = vatPayer; +} + +QString GlobalSettings::logoPath() const +{ + return m_logoPath; +} + +void GlobalSettings::setLogoPath(const QString &logoPath) +{ + m_logoPath = logoPath; +} diff --git a/core/settings/globalsettings.h b/core/settings/globalsettings.h new file mode 100644 index 0000000..2a6425e --- /dev/null +++ b/core/settings/globalsettings.h @@ -0,0 +1,66 @@ +#ifndef GLOBALSETTINGS_H +#define GLOBALSETTINGS_H + +#include +#include + +class GlobalSettings : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString firmName READ firmName WRITE setFirmName) + Q_PROPERTY(QString street READ street WRITE setStreet) + Q_PROPERTY(QString houseNumber READ houseNumber WRITE setHouseNumber) + Q_PROPERTY(QString zipCode READ zipCode WRITE setZipCode) + Q_PROPERTY(QString city READ city WRITE setCity) + Q_PROPERTY(int ic READ ic WRITE setIc) + Q_PROPERTY(QString dic READ dic WRITE setDic) + Q_PROPERTY(bool vatPayer READ vatPayer WRITE setVatPayer) + Q_PROPERTY(QString logoPath READ logoPath WRITE setLogoPath) +public: + explicit GlobalSettings(QObject *parent = 0); + + QString firmName() const; + void setFirmName(const QString &firmName); + + QString street() const; + void setStreet(const QString &street); + + QString houseNumber() const; + void setHouseNumber(const QString &houseNumber); + + QString zipCode() const; + void setZipCode(const QString &zipCode); + + QString city() const; + void setCity(const QString &city); + + int ic() const; + void setIc(int ic); + + QString dic() const; + void setDic(const QString &dic); + + bool vatPayer() const; + void setVatPayer(bool vatPayer); + + QString logoPath() const; + void setLogoPath(const QString &logoPath); + +private: + QString m_firmName; + QString m_street; + QString m_houseNumber; + QString m_zipCode; + QString m_city; + int m_ic; + QString m_dic; + bool m_vatPayer; + QString m_logoPath; + +signals: + +public slots: +}; + +#endif // GLOBALSETTINGS_H diff --git a/core/settings/globalsettingsform.cpp b/core/settings/globalsettingsform.cpp new file mode 100644 index 0000000..70e7cc3 --- /dev/null +++ b/core/settings/globalsettingsform.cpp @@ -0,0 +1,42 @@ +#include "globalsettingsform.h" +#include "ui_globalsettingsform.h" + +#include "globalsettings.h" +#include "../settingsservice.h" + +GlobalSettingsForm::GlobalSettingsForm(QWidget *parent) : + FormBinder(parent), + ui(new Ui::GlobalSettingsForm) +{ + ui->setupUi(this); + + registerBinding(ui->firmName); + registerBinding(ui->street); + registerBinding(ui->houseNumber); + registerBinding(ui->zipCode); + registerBinding(ui->city); + registerBinding(ui->ic); + registerBinding(ui->vatPayer); + registerBinding(ui->dic); +} + +GlobalSettingsForm::~GlobalSettingsForm() +{ + delete ui; +} + +bool GlobalSettingsForm::saveRecord() +{ + bindToData(); + SettingsService srv("CORE"); + srv.saveSettings(entity()); + + return true; +} + +void GlobalSettingsForm::loadEntity() +{ + SettingsService srv("CORE"); + QSharedPointer settings = srv.loadSettings(); + setEntity(settings); +} diff --git a/core/settings/globalsettingsform.h b/core/settings/globalsettingsform.h new file mode 100644 index 0000000..472d240 --- /dev/null +++ b/core/settings/globalsettingsform.h @@ -0,0 +1,32 @@ +#ifndef GLOBALSETTINGSFORM_H +#define GLOBALSETTINGSFORM_H + +#include +#include "../formbinder.h" +#include "globalsettings.h" + +namespace Ui { +class GlobalSettingsForm; +} + +class GlobalSettingsForm : public FormBinder +{ + Q_OBJECT + +public: + explicit GlobalSettingsForm(QWidget *parent = 0); + ~GlobalSettingsForm(); + +private: + Ui::GlobalSettingsForm *ui; + + // IForm interface +public slots: + bool saveRecord() override; + + // IForm interface +public: + void loadEntity() override; +}; + +#endif // GLOBALSETTINGSFORM_H diff --git a/core/settings/globalsettingsform.ui b/core/settings/globalsettingsform.ui new file mode 100644 index 0000000..859592e --- /dev/null +++ b/core/settings/globalsettingsform.ui @@ -0,0 +1,139 @@ + + + GlobalSettingsForm + + + + 0 + 0 + 422 + 323 + + + + Form + + + + + + Company info + + + + + + IC + + + + + + + + + + VAT number + + + + + + + + + + VAT payer + + + + + + + + + + Contact + + + + + + Firm Name + + + + + + + + + + Street + + + + + + + + + + House Number + + + + + + + + + + City + + + + + + + + + + ZIP code + + + + + + + + + + + + + Logo + + + + + + Logo + + + + + + + Select file + + + + + + + + + + + diff --git a/core/settingsform.cpp b/core/settingsform.cpp new file mode 100644 index 0000000..3a32235 --- /dev/null +++ b/core/settingsform.cpp @@ -0,0 +1,56 @@ +#include "settingsform.h" +#include "ui_settingsform.h" + +#include "settingsservice.h" +#include "context.h" +#include "iplugin.h" +#include "iform.h" + +SettingsForm::SettingsForm(QWidget *parent) : + QDialog(parent), + ui(new Ui::SettingsForm) +{ + ui->setupUi(this); + + foreach (IPlugin *plugin, Context::instance().plugins()) { + if (plugin->settingsUi() != NULL) + { + SettingsService srv(plugin->pluginId()); + IForm *tab = qobject_cast(plugin->settingsUi()); + + if (tab != NULL) + { + tab->loadEntity(); + ui->tabWidget->addTab(tab, QIcon(), plugin->settingsTabLabel()); + } + } + } +} + +SettingsForm::~SettingsForm() +{ + delete ui; +} + +void SettingsForm::on_buttonBox_accepted() +{ + accept(); +} + +void SettingsForm::accept() +{ + for (int i = 0; i < ui->tabWidget->count(); i++) + { + IForm *tab = qobject_cast(ui->tabWidget->widget(i)); + if (tab != NULL) + { + tab->saveRecord(); + } + } + QDialog::accept(); +} + +void SettingsForm::on_buttonBox_rejected() +{ + reject(); +} diff --git a/core/settingsform.h b/core/settingsform.h new file mode 100644 index 0000000..0dd45ae --- /dev/null +++ b/core/settingsform.h @@ -0,0 +1,32 @@ +#ifndef SETTINGSFORM_H +#define SETTINGSFORM_H + +#include +#include + +namespace Ui { +class SettingsForm; +} + +class SettingsForm : public QDialog +{ + Q_OBJECT + +public: + explicit SettingsForm(QWidget *parent = 0); + ~SettingsForm(); + +private slots: + void on_buttonBox_accepted(); + + void on_buttonBox_rejected(); + +private: + Ui::SettingsForm *ui; + + // QDialog interface +public slots: + void accept() override; +}; + +#endif // SETTINGSFORM_H diff --git a/core/settingsform.ui b/core/settingsform.ui new file mode 100644 index 0000000..f6b41b7 --- /dev/null +++ b/core/settingsform.ui @@ -0,0 +1,44 @@ + + + SettingsForm + + + Qt::ApplicationModal + + + + 0 + 0 + 800 + 600 + + + + Settings + + + + + + QTabWidget::North + + + QTabWidget::Rounded + + + -1 + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + diff --git a/core/settingsservice.cpp b/core/settingsservice.cpp new file mode 100644 index 0000000..6792ca9 --- /dev/null +++ b/core/settingsservice.cpp @@ -0,0 +1,47 @@ +#include "settingsservice.h" + +#include "core-odb.hxx" + +#include +#include + +SettingsService::SettingsService(QObject *parent) + :IService(parent) +{ +} + +SettingsService::SettingsService(const QString &pluginId, QObject *parent) + :IService(parent) +{ + m_pluginId = pluginId; +} + +QSharedPointer SettingsService::loadSystem() +{ + Service srv; + QList > sysObj = srv.all("pluginId = '" + m_pluginId + "'"); + + if (sysObj.isEmpty()) + { + emit dbErrorUpdate("Error loading sys object"); + return QSharedPointer(); + } + + return sysObj[0]; +} + +void SettingsService::saveSystem(const QJsonDocument &doc) +{ + QSharedPointer sysObj = loadSystem(); + + if (sysObj.isNull()) + { + emit dbErrorUpdate("Error loading sys object"); + return; + } + + sysObj->setSettings(QString(doc.toJson())); + + Service srv; + srv.update(sysObj); +} diff --git a/core/settingsservice.h b/core/settingsservice.h new file mode 100644 index 0000000..4015545 --- /dev/null +++ b/core/settingsservice.h @@ -0,0 +1,78 @@ +#ifndef SETTINGSSERVICE_H +#define SETTINGSSERVICE_H + +#include +#include +#include +#include +#include + +#include "data/system.h" +#include "service.h" +#include "core_global.h" + +class CORESHARED_EXPORT SettingsService : public IService +{ +public: + explicit SettingsService(QObject *parent = NULL); + SettingsService(const QString &pluginId, QObject *parent = NULL); + + + template + QSharedPointer loadSettings() { + QSharedPointer sys = loadSystem(); + QObject *objSettings = new T(); + QSharedPointer settingsObj((T*)objSettings); + + if (sys.isNull()) + { + return settingsObj; + } + + QString settingStr = sys->settings(); + QJsonDocument jsonDoc = QJsonDocument::fromJson(settingStr.toUtf8()); + QJsonValue val = jsonDoc.object()["Settings"]; + + if (!val.isObject()) + { + return settingsObj; + } + + for (int i = 0; i < objSettings->metaObject()->propertyCount(); i++) + { + const char *propName = objSettings->metaObject()->property(i).name(); + QVariant varVal = val.toObject()[propName].toVariant(); + objSettings->setProperty(propName, varVal); + } + + return settingsObj; + } + + template + void saveSettings(QSharedPointer objSettings) + { + QObject *objSettingsQo = objSettings.data(); + QJsonDocument jsonDoc; + QJsonObject jsonObj; + + for (int i = 0; i < objSettingsQo->metaObject()->propertyCount(); i++) + { + const char *propName = objSettings->metaObject()->property(i).name(); + jsonObj[propName] = QJsonValue::fromVariant(objSettingsQo->property(propName)); + } + + QJsonObject jsonSettings; + jsonSettings["Settings"] = jsonObj; + jsonDoc.setObject(jsonSettings); + + saveSystem(jsonDoc); + } + +private: + QString m_pluginId; + QSharedPointer m_settings; + QSharedPointer loadSystem(); + void saveSystem(const QJsonDocument &doc); +}; + +#endif // SETTINGSSERVICE_H diff --git a/prodejna.pro b/prodejna.pro index 4624823..67c41f1 100644 --- a/prodejna.pro +++ b/prodejna.pro @@ -1,11 +1,11 @@ TEMPLATE = subdirs SUBDIRS += \ + qdecimal \ core \ application \ accommodation \ - qdecimal \ - services \ - commodity \ - addressbook + services + #commodity \ + #addressbook diff --git a/services/services.pro b/services/services.pro index 331dac1..05b4c7e 100644 --- a/services/services.pro +++ b/services/services.pro @@ -11,7 +11,7 @@ TARGET = services TEMPLATE = lib DEFINES += SERVICES_LIBRARY\ - _GLIBCXX_USE_CXX11_ABI=0 + _GLIBCXX_USE_CXX11_ABI=1 SOURCES += services.cpp \ data/accservice.cpp \