-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpatientsqlmodel.cpp
More file actions
82 lines (74 loc) · 1.92 KB
/
patientsqlmodel.cpp
File metadata and controls
82 lines (74 loc) · 1.92 KB
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
74
75
76
77
78
79
80
81
82
#include "patientsqlmodel.h"
#include <QHash>
#include <QByteArray>
#include <QtSql/QSqlDatabase>
#include <QDebug>
#include <QtSql/QSqlError>
#include <QtSql/QSqlQuery>
#include <QtSql/QSqlDriver>
#include <QtSql/QSqlQueryModel>
const char* PatientSqlModel::COLUMN_NAMES[] = {
"date",
"deviceCode",
"name",
"phone",
"leftEyeSph",
"leftEyeCyl",
"leftEyeAx",
"rightEyeSph",
"rightEyeCyl",
"rightEyeAx",
"lensType",
"detail",
"synced",
NULL
};
#if QT_VERSION > 0x050000
QHash<int, QByteArray> PatientSqlModel::roleNames() const {
QHash<int, QByteArray> roleNames;
int idx = 0;
while( COLUMN_NAMES[idx]) {
roleNames[Qt::UserRole + idx + 1] = COLUMN_NAMES[idx];
idx++;
}
return roleNames;
}
#endif
PatientSqlModel::PatientSqlModel(QObject *parent,QString customerName="",QString customerPhone=""):
QSqlQueryModel(parent) //, patientPhone(tableID)
{
QString where = "1=1"; //By default return all rows
if(!customerName.isEmpty())
where = " name LIKE '%"+customerName+"%'";
if (!customerPhone.isEmpty())
where.append(" OR phone LIKE '%"+customerPhone+"%'");
SQL_SELECT ="SELECT * FROM patientinfo WHERE "+ where;
#if QT_VERSION < 0x050000
int idx = 0;
while( COLUMN_NAMES[idx]) {
roleNames[Qt::UserRole + idx + 1] = COLUMN_NAMES[idx];
idx++;
}
setRoleNames(roleNames);
#endif
reload ();
}
void PatientSqlModel::reload()
{
setQuery(SQL_SELECT );
}
QVariant PatientSqlModel::data(const QModelIndex &index, int role) const
{
QVariant value = QSqlQueryModel::data(index, role);
if(role < Qt::UserRole)
{
value = QSqlQueryModel::data(index, role);
}
else
{
int columnIdx = role - Qt::UserRole - 1;
QModelIndex modelIndex = this->index(index.row(), columnIdx);
value = QSqlQueryModel::data(modelIndex, Qt::DisplayRole);
}
return value;
}