-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialogeditrecord.cpp
52 lines (41 loc) · 1.34 KB
/
dialogeditrecord.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "dialogeditrecord.h"
#include "ui_dialogeditrecord.h"
DialogEditRecord::DialogEditRecord(int row, QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogEditRecord)
{
ui->setupUi(this);
setupModel();
if(row != -1)
{
mapper->setCurrentModelIndex(model->index(row,0));
}
}
DialogEditRecord::~DialogEditRecord()
{
delete ui;
}
void DialogEditRecord::setupModel()
{
// Инициализируем модель и делаем выборку
model = new QSqlTableModel(this);
model->setTable(TABLE);
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select();
// Инициализируем mapper и привязываем поля данных к объектам LineEdit
mapper = new QDataWidgetMapper();
mapper->setModel(model);
mapper->addMapping(ui->lineEditName, 0);
mapper->addMapping(ui->lineEditValue, 1);
//mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
//connect(ui->previousButton, SIGNAL(clicked()), mapper, SLOT(toPrevious()));
//connect(ui->nextButton, SIGNAL(clicked()), mapper, SLOT(toNext()));
connect(mapper, SIGNAL(currentIndexChanged(int)), this, SLOT(updateButtons(int)));
}
void DialogEditRecord::on_pushButton_clicked()
{
mapper->submit();
model->submitAll();
emit readyToUpdate();
this->close();
}