-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexsqlrelationaltablemodel.cpp
More file actions
79 lines (66 loc) · 2.24 KB
/
Copy pathexsqlrelationaltablemodel.cpp
File metadata and controls
79 lines (66 loc) · 2.24 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
/*
* subclass QSqlRelationalTableModel, reimplementing Qt::ItemFlags flags(const QModelIndex & index) const
* default Qt::ItemFlags QAbstractTableModel::flags(const QModelIndex &index) const return ItemIsEnabled and ItemIsSelectable
* now this project want the special column can be edit. So, more return ItemIsEditable.
* Then, can press F2 to edit the special column.
*/
#include "exsqlrelationaltablemodel.h"
ExSqlRelationalTableModel::ExSqlRelationalTableModel(QObject *parent)
:QSqlRelationalTableModel(parent)
{
}
Qt::ItemFlags ExSqlRelationalTableModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags flags = QSqlTableModel::flags(index);
if (index.column() == 1)
flags |= Qt::ItemIsEditable;
return flags;
}
ExSqlRelationalTableModel::~ExSqlRelationalTableModel()
{
}
QVariant ExSqlRelationalTableModel::data(const QModelIndex &index, int role) const
{
QVariant ret;
if (!index.isValid())
return QVariant();
QSqlRelationalTableModel *tmp = (QSqlRelationalTableModel *)index.model();
QModelIndex itemIndex = tmp->index(index.row(), tmp->fieldIndex("finprj"), QModelIndex());
if (Qt::BackgroundColorRole == role)
{
if (!itemIndex.data().toString().isEmpty())
{
return QSqlRelationalTableModel::data(index, role);
}
if (tmp->fieldIndex("deadline") == index.column())
{
QString timestring = index.data(Qt::DisplayRole).toString();
if (timestring.isEmpty())
{
return QColor(Qt::magenta);
}
QDate time = QDate::fromString(timestring, "yyyyMMdd");
QDate Curtime =QDate::currentDate();
if (Curtime > time)
{
return QColor(Qt::red);
}
else if (Curtime >= time.addDays(-2))
{
return QColor(Qt::yellow);
}
else
{
return QColor(Qt::green);
}
}
else
{
return QSqlRelationalTableModel::data(index, role);
}
}
else
{
return QSqlRelationalTableModel::data(index, role);
}
}