-
Notifications
You must be signed in to change notification settings - Fork 0
/
watchlistdialog.cpp
39 lines (32 loc) · 1.08 KB
/
watchlistdialog.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
#include "watchlistdialog.h"
#include "qnamespace.h"
#include "ui_watchlistdialog.h"
#include <QSqlError>
#include <QSqlField>
#include <QSqlRecord>
using namespace Qt::Literals::StringLiterals;
WatchListDialog::WatchListDialog(QSqlTableModel* watchlist_model, QWidget* parent)
: QDialog(parent)
, ui(new Ui::WatchListDialog)
, m_watchlist_model(watchlist_model)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, [this]() {
auto record = m_watchlist_model->record();
record.setValue(u"name"_s, ui->name_edit->text());
record.setValue(u"note"_s, ui->note_edit->toPlainText());
record.remove(m_watchlist_model->fieldIndex(u"created_at"_s));
if (m_watchlist_model->insertRecord(-1, record)) {
m_watchlist_model->submitAll();
m_watchlist_model->select();
} else {
qDebug() << "Error saving record: " << m_watchlist_model->lastError();
}
accept();
});
}
WatchListDialog::~WatchListDialog()
{
delete ui;
}