Josef Rokos 9 years ago
commit 726da24de9

@ -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<CommodityData>;
m_ui = grid;
((CommodityGrid *) m_ui)->setForm(form);
m_settingsUi = new CommoditySettingsForm();
}
QIcon Commodity::pluginIcon()

@ -22,6 +22,8 @@ protected:
// IPlugin interface
public:
virtual QIcon pluginIcon();
};
#endif // COMMODITY_H

@ -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

@ -0,0 +1,61 @@
#include "commoditysettingsform.h"
#include "ui_commoditysettingsform.h"
#include <service.h>
#include "commodity-odb.hxx"
CommoditySettingsForm::CommoditySettingsForm(QWidget *parent) :
IForm(parent),
ui(new Ui::CommoditySettingsForm)
{
ui->setupUi(this);
m_table = new AutoTableModel<CommodityTypeData>();
m_table->setEditableCols(QList<int>() << 0);
ui->commodityTypesTable->setModel(m_table);
}
CommoditySettingsForm::~CommoditySettingsForm()
{
delete ui;
}
void CommoditySettingsForm::loadEntity()
{
Service<CommodityTypeData> commodityService;
m_table->setData(commodityService.all());
}
bool CommoditySettingsForm::saveRecord()
{
Service<CommodityTypeData> commodityService;
foreach (QSharedPointer<CommodityTypeData> item, m_table->list())
{
if(item->id() == 0)
{
commodityService.save(item);
}
else
{
commodityService.update(item);
}
}
foreach (QSharedPointer<CommodityTypeData> item, m_delCommodityTypes)
{
commodityService.erase(item);
}
}
void CommoditySettingsForm::on_addCommodityType_clicked()
{
m_table->addRow(QSharedPointer<CommodityTypeData>(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());
}

@ -0,0 +1,37 @@
#ifndef COMMODITYSETTINGSFORM_H
#define COMMODITYSETTINGSFORM_H
#include <QWidget>
#include <iform.h>
#include "data/commoditytypedata.h"
#include <autotablemodel.h>
namespace Ui {
class CommoditySettingsForm;
}
class CommoditySettingsForm : public IForm
{
Q_OBJECT
public:
explicit CommoditySettingsForm(QWidget *parent = 0);
~CommoditySettingsForm();
private:
Ui::CommoditySettingsForm *ui;
AutoTableModel<CommodityTypeData> *m_table;
QList<QSharedPointer<CommodityTypeData> > m_delCommodityTypes;
// IForm interface
public:
void loadEntity();
public slots:
bool saveRecord();
private slots:
void on_addCommodityType_clicked();
void on_delCommodityType_clicked();
};
#endif // COMMODITYSETTINGSFORM_H

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CommoditySettingsForm</class>
<widget class="QWidget" name="CommoditySettingsForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="1">
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="addCommodityType">
<property name="text">
<string>+</string>
</property>
<property name="icon">
<iconset resource="../core/rc.qrc">
<normaloff>:/icons/new.svg</normaloff>:/icons/new.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="delCommodityType">
<property name="text">
<string>-</string>
</property>
<property name="icon">
<iconset resource="../core/rc.qrc">
<normaloff>:/icons/remove.svg</normaloff>:/icons/remove.svg</iconset>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="1">
<widget class="QTableView" name="commodityTypesTable"/>
</item>
</layout>
</widget>
<resources>
<include location="../core/rc.qrc"/>
</resources>
<connections/>
</ui>

@ -3,6 +3,7 @@
CommodityTypeData::CommodityTypeData(QObject *parent)
:ComboItem(parent)
{
m_id = 0;
}
int CommodityTypeData::id() const
{

Loading…
Cancel
Save