Improved plugin initialization. Added delete feature.
This commit is contained in:
+29
-15
@@ -2,6 +2,7 @@
|
||||
#define GRIDFORM_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "autoform.h"
|
||||
#include "autotablemodel.h"
|
||||
@@ -31,10 +32,16 @@ public:
|
||||
Q_ASSERT(m_form == NULL);
|
||||
|
||||
m_form = form;
|
||||
//m_form->setParent(this);
|
||||
|
||||
connect(m_form, SIGNAL(recordAdded()), this, SLOT(saveNew()));
|
||||
connect(m_form, SIGNAL(recordUpdated()), this, SLOT(saveUpdate()));
|
||||
connect(m_form, &IForm::recordAdded, [this](){
|
||||
service()->save(m_form->entity());
|
||||
m_tableModel->addRow(m_form->entity());
|
||||
emit dataChanged();
|
||||
});
|
||||
connect(m_form, &IForm::recordUpdated, [this](){
|
||||
service()->update(m_form->entity());
|
||||
emit dataChanged();
|
||||
});
|
||||
}
|
||||
|
||||
void setTableModel(AutoTableModel<T> *tableModel) {
|
||||
@@ -59,18 +66,6 @@ public slots:
|
||||
tableView()->setModel(m_tableModel);
|
||||
}
|
||||
|
||||
protected slots:
|
||||
void saveNew() {
|
||||
service()->save(m_form->entity());
|
||||
m_tableModel->addRow(m_form->entity());
|
||||
emit dataChanged();
|
||||
}
|
||||
|
||||
void saveUpdate() {
|
||||
service()->update(m_form->entity());
|
||||
emit dataChanged();
|
||||
}
|
||||
|
||||
private:
|
||||
AutoForm<T> *m_form;
|
||||
AutoTableModel<T> *m_tableModel;
|
||||
@@ -119,6 +114,25 @@ protected:
|
||||
m_form->setNewRec(false);
|
||||
m_formHandler->showForm(m_form);
|
||||
}
|
||||
|
||||
void handleDeleteRecord() override
|
||||
{
|
||||
if (m_form == NULL || m_tableModel == NULL || tableView()->currentIndex().row() < 0)
|
||||
{
|
||||
Q_ASSERT(false);
|
||||
return;
|
||||
}
|
||||
|
||||
QMessageBox::StandardButton reply;
|
||||
reply = QMessageBox::question(this, tr("Delete record"), tr("Realy delete this record?"), QMessageBox::Yes|QMessageBox::No);
|
||||
if (reply == QMessageBox::Yes)
|
||||
{
|
||||
QSharedPointer<T> entity = m_tableModel->itemFromIndex(tableView()->currentIndex());
|
||||
service()->erase(entity);
|
||||
fillData();
|
||||
emit dataChanged();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // GRIDFORM_H
|
||||
|
||||
Reference in New Issue
Block a user