Merge branch 'master' of https://git.bukova.info/repos/git/prodejna
commit
726da24de9
@ -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>
|
Loading…
Reference in New Issue