From 77ec02e4c5248a9d09894ea258098f62a203162c Mon Sep 17 00:00:00 2001 From: Zdenek Jonak Date: Tue, 3 May 2016 22:09:05 +0200 Subject: [PATCH] Commodity settings implementation --- commodity/commodity.cpp | 2 + commodity/commodity.h | 2 + commodity/commodity.pro | 9 ++-- commodity/commoditysettingsform.cpp | 61 ++++++++++++++++++++++++++++ commodity/commoditysettingsform.h | 37 +++++++++++++++++ commodity/commoditysettingsform.ui | 57 ++++++++++++++++++++++++++ commodity/data/commoditytypedata.cpp | 1 + 7 files changed, 166 insertions(+), 3 deletions(-) create mode 100644 commodity/commoditysettingsform.cpp create mode 100644 commodity/commoditysettingsform.h create mode 100644 commodity/commoditysettingsform.ui diff --git a/commodity/commodity.cpp b/commodity/commodity.cpp index 1a3d863..8748662 100644 --- a/commodity/commodity.cpp +++ b/commodity/commodity.cpp @@ -2,6 +2,7 @@ #include "data/commodity-data.h" #include "commodityform.h" #include "commoditygrid.h" +#include "commoditysettingsform.h" Commodity::Commodity() { @@ -15,6 +16,7 @@ void Commodity::initServiceUi() m_service = new Service; m_ui = grid; ((CommodityGrid *) m_ui)->setForm(form); + m_settingsUi = new CommoditySettingsForm(); } QIcon Commodity::pluginIcon() diff --git a/commodity/commodity.h b/commodity/commodity.h index 34c80ec..d10167e 100644 --- a/commodity/commodity.h +++ b/commodity/commodity.h @@ -22,6 +22,8 @@ protected: // IPlugin interface public: virtual QIcon pluginIcon(); + + }; #endif // COMMODITY_H diff --git a/commodity/commodity.pro b/commodity/commodity.pro index f678276..37e126e 100644 --- a/commodity/commodity.pro +++ b/commodity/commodity.pro @@ -19,7 +19,8 @@ SOURCES += commodity.cpp \ data/commoditytypedata.cpp \ commoditytablemodel.cpp \ commodityform.cpp \ - commoditygrid.cpp + commoditygrid.cpp \ + commoditysettingsform.cpp HEADERS += commodity.h\ commodity_global.h \ @@ -28,7 +29,8 @@ HEADERS += commodity.h\ data/commodity-data.h \ commoditytablemodel.h \ commodityform.h \ - commoditygrid.h + commoditygrid.h \ + commoditysettingsform.h unix { target.path = /usr/lib @@ -65,7 +67,8 @@ OTHER_FILES += \ commodity.json FORMS += \ - commodityform.ui + commodityform.ui \ + commoditysettingsform.ui RESOURCES += \ commodityrc.qrc diff --git a/commodity/commoditysettingsform.cpp b/commodity/commoditysettingsform.cpp new file mode 100644 index 0000000..a17e072 --- /dev/null +++ b/commodity/commoditysettingsform.cpp @@ -0,0 +1,61 @@ +#include "commoditysettingsform.h" +#include "ui_commoditysettingsform.h" +#include +#include "commodity-odb.hxx" + +CommoditySettingsForm::CommoditySettingsForm(QWidget *parent) : + IForm(parent), + ui(new Ui::CommoditySettingsForm) +{ + ui->setupUi(this); + m_table = new AutoTableModel(); + m_table->setEditableCols(QList() << 0); + ui->commodityTypesTable->setModel(m_table); +} + +CommoditySettingsForm::~CommoditySettingsForm() +{ + delete ui; +} + +void CommoditySettingsForm::loadEntity() +{ + Service commodityService; + m_table->setData(commodityService.all()); +} + +bool CommoditySettingsForm::saveRecord() +{ + Service commodityService; + foreach (QSharedPointer item, m_table->list()) + { + if(item->id() == 0) + { + commodityService.save(item); + } + else + { + commodityService.update(item); + } + + } + foreach (QSharedPointer item, m_delCommodityTypes) + { + commodityService.erase(item); + + } +} + +void CommoditySettingsForm::on_addCommodityType_clicked() +{ + m_table->addRow(QSharedPointer(new CommodityTypeData)); +} + +void CommoditySettingsForm::on_delCommodityType_clicked() +{ + if(m_table->itemFromIndex(ui->commodityTypesTable->currentIndex())->id() != 0) + { + m_delCommodityTypes.append(m_table->itemFromIndex(ui->commodityTypesTable->currentIndex())); + } + m_table->removeRowAt(ui->commodityTypesTable->currentIndex()); +} diff --git a/commodity/commoditysettingsform.h b/commodity/commoditysettingsform.h new file mode 100644 index 0000000..f75b88c --- /dev/null +++ b/commodity/commoditysettingsform.h @@ -0,0 +1,37 @@ +#ifndef COMMODITYSETTINGSFORM_H +#define COMMODITYSETTINGSFORM_H + +#include +#include +#include "data/commoditytypedata.h" +#include + +namespace Ui { +class CommoditySettingsForm; +} + +class CommoditySettingsForm : public IForm +{ + Q_OBJECT + +public: + explicit CommoditySettingsForm(QWidget *parent = 0); + ~CommoditySettingsForm(); + +private: + Ui::CommoditySettingsForm *ui; + AutoTableModel *m_table; + QList > m_delCommodityTypes; + + // IForm interface +public: + void loadEntity(); + +public slots: + bool saveRecord(); +private slots: + void on_addCommodityType_clicked(); + void on_delCommodityType_clicked(); +}; + +#endif // COMMODITYSETTINGSFORM_H diff --git a/commodity/commoditysettingsform.ui b/commodity/commoditysettingsform.ui new file mode 100644 index 0000000..13733a2 --- /dev/null +++ b/commodity/commoditysettingsform.ui @@ -0,0 +1,57 @@ + + + CommoditySettingsForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + + + + + + + + + :/icons/new.svg:/icons/new.svg + + + + + + + - + + + + :/icons/remove.svg:/icons/remove.svg + + + + + + + + + + + + + + + + diff --git a/commodity/data/commoditytypedata.cpp b/commodity/data/commoditytypedata.cpp index cd4d9f2..b3b3aa4 100644 --- a/commodity/data/commoditytypedata.cpp +++ b/commodity/data/commoditytypedata.cpp @@ -3,6 +3,7 @@ CommodityTypeData::CommodityTypeData(QObject *parent) :ComboItem(parent) { + m_id = 0; } int CommodityTypeData::id() const {