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