-
Notifications
You must be signed in to change notification settings - Fork 0
/
History.cpp
73 lines (62 loc) · 2.2 KB
/
History.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "History.h"
#include <QSqlRecord>
#include <QDebug>
History::History(QObject *parent, QSqlDatabase database)
: QSqlTableModel(parent, database)
{
setTable(QStringLiteral("history"));
setEditStrategy(QSqlTableModel::OnManualSubmit);
select();
}
QHash<int, QByteArray> History::roleNames() const
{
QHash<int, QByteArray> roles;
for(int i = 0; i < columnCount(); i++){
roles[Qt::UserRole + 1 + i] = headerData(i, Qt::Horizontal).toByteArray();
// qDebug()<<roles[Qt::UserRole + 1 + i];
}
return roles;
}
QVariant History::data(const QModelIndex &index, int role) const
{
if(index.row() < 0 || index.row() > rowCount() || role < 0 || role > (columnCount() + Qt::UserRole + 1))
return QVariant();
if( role < Qt::UserRole)
return (QSqlTableModel::data(index, role));
else
return QSqlTableModel::data(QSqlTableModel::index(index.row(), role - Qt::UserRole - 1), Qt::DisplayRole);
}
QVariant History::roleFromRow(int row, QString roleName)
{
QSqlRecord record = QSqlTableModel::record(row);
return record.value(roleName);
}
void History::removeRow(int row)
{
removeRows(row, 1, QModelIndex());
submitAll();
}
void History::addRow(int row, QString newData)
{
QStringList data = newData.split(";", QString::KeepEmptyParts);
QSqlRecord newRecord = record();
if (row == -1)
newRecord.setGenerated(QStringLiteral("id"), true);
else
newRecord = record(row);
newRecord.setValue(QStringLiteral("message"), data.at(0));
newRecord.setValue(QStringLiteral("time"), data.at(1));
newRecord.setValue(QStringLiteral("type"), data.at(2));
newRecord.setValue(QStringLiteral("wafer_stage"), data.at(3));
newRecord.setValue(QStringLiteral("wafer_clamp"), data.at(4));
newRecord.setValue(QStringLiteral("wafer_mask_gap"), data.at(5));
newRecord.setValue(QStringLiteral("vibration"), data.at(6));
newRecord.setValue(QStringLiteral("duration"), data.at(7));
newRecord.setValue(QStringLiteral("light_intensity"), data.at(8));
if (row == -1)
insertRecord(row, newRecord);
else
setRecord(row, newRecord);
submitAll();
qDebug()<<"Database Updated: " << newRecord;
}