|
|
|
@ -10,8 +10,8 @@
|
|
|
|
|
#include "autotablemodel.h"
|
|
|
|
|
#include "context.h"
|
|
|
|
|
#include "iplugin.h"
|
|
|
|
|
|
|
|
|
|
#include "igridform.h"
|
|
|
|
|
#include "iservice.h"
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
class GridForm : public IGridForm
|
|
|
|
@ -20,14 +20,15 @@ class GridForm : public IGridForm
|
|
|
|
|
public:
|
|
|
|
|
explicit GridForm(QWidget *parent = 0) :
|
|
|
|
|
IGridForm(parent)
|
|
|
|
|
{
|
|
|
|
|
m_form = NULL;
|
|
|
|
|
{
|
|
|
|
|
m_serviceConnected = false;
|
|
|
|
|
m_tableModel = NULL;
|
|
|
|
|
m_formHandler = new DefaultFormHandler();
|
|
|
|
|
|
|
|
|
|
m_filterUi = new FilterUi(this, new T);
|
|
|
|
|
filterWidget()->layout()->addWidget(m_filterUi);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual ~GridForm()
|
|
|
|
|
{
|
|
|
|
|
if (m_form != NULL && m_form->parent() == NULL)
|
|
|
|
@ -43,20 +44,26 @@ public:
|
|
|
|
|
delete m_formHandler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setForm(AutoForm<T> *form) {
|
|
|
|
|
void setForm(AutoForm<T> *aForm) {
|
|
|
|
|
Q_ASSERT(m_form == NULL);
|
|
|
|
|
|
|
|
|
|
m_form = form;
|
|
|
|
|
m_form = aForm;
|
|
|
|
|
|
|
|
|
|
connect(m_form, &IForm::recordAdded, [this](){
|
|
|
|
|
service()->save(m_form->entity());
|
|
|
|
|
m_tableModel->addRow(m_form->entity());
|
|
|
|
|
//service()->save(form()->entity());
|
|
|
|
|
m_tableModel->addRow(form()->entity());
|
|
|
|
|
emit dataChanged();
|
|
|
|
|
});
|
|
|
|
|
connect(m_form, &IForm::recordUpdated, [this](){
|
|
|
|
|
service()->update(m_form->entity());
|
|
|
|
|
//service()->update(form()->entity());
|
|
|
|
|
emit dataChanged();
|
|
|
|
|
});
|
|
|
|
|
connect(m_form, &IForm::refreshEntity, [this](){
|
|
|
|
|
if (m_tableModel != NULL) {
|
|
|
|
|
m_tableModel->setItemToIndex(tableView()->currentIndex(),
|
|
|
|
|
service()->reload(m_tableModel->itemFromIndex(tableView()->currentIndex())->id()));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setTableModel(AutoTableModel<T> *tableModel) {
|
|
|
|
@ -79,6 +86,8 @@ public slots:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connectService();
|
|
|
|
|
|
|
|
|
|
m_tableModel->setData(service()->all());
|
|
|
|
|
tableView()->setModel(m_tableModel);
|
|
|
|
|
|
|
|
|
@ -93,7 +102,6 @@ public slots:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
AutoForm<T> *m_form;
|
|
|
|
|
AutoTableModel<T> *m_tableModel;
|
|
|
|
|
IFormHandler *m_formHandler;
|
|
|
|
|
|
|
|
|
@ -113,6 +121,26 @@ private:
|
|
|
|
|
return service;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AutoForm<T> *form() {
|
|
|
|
|
return (AutoForm<T>*)m_form;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void connectService() {
|
|
|
|
|
if (!m_serviceConnected)
|
|
|
|
|
{
|
|
|
|
|
connect(service(), &IService::dbErrorRead, [this](QString msg) {
|
|
|
|
|
QMessageBox::critical(this, tr("Database error"), tr(msg.toStdString().c_str()));
|
|
|
|
|
});
|
|
|
|
|
connect(service(), &IService::dbErrorDelete, [this](QString msg) {
|
|
|
|
|
QMessageBox::critical(this, tr("Database error"), tr(msg.toStdString().c_str()));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
m_serviceConnected = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool m_serviceConnected;
|
|
|
|
|
|
|
|
|
|
// IGridForm interface
|
|
|
|
|
protected:
|
|
|
|
|
void handleNewRecord() override
|
|
|
|
@ -123,8 +151,8 @@ protected:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_form->setEntity(QSharedPointer<T>(new T()));
|
|
|
|
|
m_form->setNewRec(true);
|
|
|
|
|
form()->setEntity(QSharedPointer<T>(new T()));
|
|
|
|
|
form()->setNewRec(true);
|
|
|
|
|
m_formHandler->showForm(m_form);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -136,13 +164,14 @@ protected:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_form->setEntity(m_tableModel->itemFromIndex(tableView()->currentIndex()));
|
|
|
|
|
m_form->setNewRec(false);
|
|
|
|
|
form()->setEntity(m_tableModel->itemFromIndex(tableView()->currentIndex()));
|
|
|
|
|
form()->setNewRec(false);
|
|
|
|
|
m_formHandler->showForm(m_form);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handleDeleteRecord() override
|
|
|
|
|
{
|
|
|
|
|
connectService();
|
|
|
|
|
if (m_form == NULL || m_tableModel == NULL || tableView()->currentIndex().row() < 0)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(false);
|
|
|
|
|