diff --git a/commodity/commodity.pro b/commodity/commodity.pro index f7d2267..666db6f 100644 --- a/commodity/commodity.pro +++ b/commodity/commodity.pro @@ -20,7 +20,8 @@ SOURCES += commodity.cpp \ commodityform.cpp \ commoditygrid.cpp \ commoditysettingsform.cpp \ - commodityservice.cpp + commodityservice.cpp \ + settings/commoditysettings.cpp HEADERS += commodity.h\ commodity_global.h \ @@ -31,7 +32,8 @@ HEADERS += commodity.h\ commodityform.h \ commoditygrid.h \ commoditysettingsform.h \ - commodityservice.h + commodityservice.h \ + settings/commoditysettings.h include(../config_plugin.pri) diff --git a/commodity/commodityform.cpp b/commodity/commodityform.cpp index f8c2cba..35811bb 100644 --- a/commodity/commodityform.cpp +++ b/commodity/commodityform.cpp @@ -1,8 +1,12 @@ #include "commodityform.h" #include "ui_commodityform.h" #include +#include +#include +#include + #include -#include +#include #include "data/commoditytypedata.h" CommodityForm::CommodityForm(QWidget *parent) : @@ -21,6 +25,8 @@ CommodityForm::CommodityForm(QWidget *parent) : << ComboData(Enums::SECOND_LOWER,tr("Second Lower")); registerBinding(ui->vat, vt); registerBinding(ui->count); + + m_codeAsNumber = false; } CommodityForm::~CommodityForm() @@ -33,3 +39,19 @@ void CommodityForm::registerCombos() Service srvComTypes; registerBinding(ui->type, ComboData::createComboData(srvComTypes.all())); } + +void CommodityForm::onShow() +{ + SettingsService srv("COMMODITY"); + CommoditySettingsPtr settings = srv.loadSettings(); + + m_codeAsNumber = settings->codeAsNumber(); +} + +void CommodityForm::on_code_textChanged(const QString &text) +{ + if (m_codeAsNumber) + { + ui->code->setText(Helper::replaceByNumbers(text)); + } +} diff --git a/commodity/commodityform.h b/commodity/commodityform.h index 8161ed6..596e21a 100644 --- a/commodity/commodityform.h +++ b/commodity/commodityform.h @@ -21,9 +21,14 @@ public: private: Ui::CommodityForm *ui; + bool m_codeAsNumber; + // FormBinder interface protected: void registerCombos(); + void onShow(); +private slots: + void on_code_textChanged(const QString &text); }; #endif // COMMODITYFORM_H diff --git a/commodity/commoditysettingsform.cpp b/commodity/commoditysettingsform.cpp index ea25466..060e3cf 100644 --- a/commodity/commoditysettingsform.cpp +++ b/commodity/commoditysettingsform.cpp @@ -1,16 +1,21 @@ #include "commoditysettingsform.h" #include "ui_commoditysettingsform.h" #include +#include #include "commodity-odb.hxx" CommoditySettingsForm::CommoditySettingsForm(QWidget *parent) : - IForm(parent), + FormBinder(parent), ui(new Ui::CommoditySettingsForm) { ui->setupUi(this); + + registerBinding(ui->codeAsNumber); + m_table = new AutoTableModel(); m_table->setEditableCols(QList() << 0); ui->commodityTypesTable->setModel(m_table); + ui->commodityTypesTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); } CommoditySettingsForm::~CommoditySettingsForm() @@ -20,12 +25,20 @@ CommoditySettingsForm::~CommoditySettingsForm() void CommoditySettingsForm::loadEntity() { + SettingsService srv("COMMODITY"); + CommoditySettingsPtr settings = srv.loadSettings(); + setEntity(settings); + Service commodityService; m_table->setData(commodityService.all()); } bool CommoditySettingsForm::saveRecord() { + bindToData(); + SettingsService srv("COMMODITY"); + srv.saveSettings(entity()); + Service commodityService; foreach (QSharedPointer item, m_table->list()) { diff --git a/commodity/commoditysettingsform.h b/commodity/commoditysettingsform.h index f75b88c..987d9a6 100644 --- a/commodity/commoditysettingsform.h +++ b/commodity/commoditysettingsform.h @@ -2,15 +2,16 @@ #define COMMODITYSETTINGSFORM_H #include -#include +#include #include "data/commoditytypedata.h" +#include "settings/commoditysettings.h" #include namespace Ui { class CommoditySettingsForm; } -class CommoditySettingsForm : public IForm +class CommoditySettingsForm : public FormBinder { Q_OBJECT diff --git a/commodity/commoditysettingsform.ui b/commodity/commoditysettingsform.ui index 13733a2..540eaa5 100644 --- a/commodity/commoditysettingsform.ui +++ b/commodity/commoditysettingsform.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 550 + 358 @@ -17,36 +17,89 @@ QFormLayout::AllNonFixedFieldsGrow - - - + + + + Commodity types + + - - - + - - - - :/icons/new.svg:/icons/new.svg - + + + + + + Add type + + + + + + + + :/icons/new_24x24.png:/icons/new_24x24.png + + + + 24 + 24 + + + + true + + + + + + + Remove type + + + - + + + + :/icons/remove_24x24.png:/icons/remove_24x24.png + + + + 24 + 24 + + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + - - - - - - - - :/icons/remove.svg:/icons/remove.svg - - + - - + + + + Code is number allways + + diff --git a/commodity/settings/commoditysettings.cpp b/commodity/settings/commoditysettings.cpp new file mode 100644 index 0000000..85a0b04 --- /dev/null +++ b/commodity/settings/commoditysettings.cpp @@ -0,0 +1,16 @@ +#include "commoditysettings.h" + +CommoditySettings::CommoditySettings(QObject *parent) : QObject(parent) +{ + m_codeAsNumber = false; +} + +bool CommoditySettings::codeAsNumber() const +{ + return m_codeAsNumber; +} + +void CommoditySettings::setCodeAsNumber(bool codeAsNumber) +{ + m_codeAsNumber = codeAsNumber; +} diff --git a/commodity/settings/commoditysettings.h b/commodity/settings/commoditysettings.h new file mode 100644 index 0000000..dcd5adf --- /dev/null +++ b/commodity/settings/commoditysettings.h @@ -0,0 +1,24 @@ +#ifndef COMMODITYSETTINGS_H +#define COMMODITYSETTINGS_H + +#include +#include + +class CommoditySettings : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool codeAsNumber READ codeAsNumber WRITE setCodeAsNumber) + +public: + explicit CommoditySettings(QObject *parent = 0); + + bool codeAsNumber() const; + void setCodeAsNumber(bool codeAsNumber); + +private: + bool m_codeAsNumber; +}; + +typedef QSharedPointer CommoditySettingsPtr; + +#endif // COMMODITYSETTINGS_H diff --git a/core/defaultformhandler.cpp b/core/defaultformhandler.cpp index 1ce8aad..d7d6694 100644 --- a/core/defaultformhandler.cpp +++ b/core/defaultformhandler.cpp @@ -16,6 +16,7 @@ DefaultFormHandler::~DefaultFormHandler() void DefaultFormHandler::showForm(IForm *formWidget) { + formWidget->onShow(); m_dialog->setForm(formWidget); m_dialog->setModal(true); m_dialog->move(QApplication::desktop()->screen()->rect().center() - m_dialog->rect().center()); diff --git a/core/iform.h b/core/iform.h index 6600b2e..5a2ec70 100644 --- a/core/iform.h +++ b/core/iform.h @@ -19,6 +19,7 @@ public: QString pluginId() const; void setPluginId(const QString &pluginId); virtual void loadEntity() {} + virtual void onShow() {} signals: void recordAdded();