-
Notifications
You must be signed in to change notification settings - Fork 0
/
tablemodel.cpp
41 lines (34 loc) · 1.14 KB
/
tablemodel.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
#include "tablemodel.h"
bool TableModel::setData( const QModelIndex &index, const QVariant &value, int role )
{
if(!index.isValid())
return false;
if (role == Qt::CheckStateRole && index.column() == 7)
{
check_state_map[index.row()] = (value == Qt::Checked ? Qt::Checked : Qt::Unchecked);
}
return true;
}
QVariant TableModel::data(const QModelIndex & index, int role) const
{
if (!index.isValid())
return QVariant();
if(role== Qt::CheckStateRole)
{
if(index.column() == 7)
{
if (check_state_map.contains(index.row()))
return check_state_map[index.row()] == Qt::Checked ? Qt::Checked : Qt::Unchecked;
return Qt::Unchecked;
}
}
return QSqlQueryModel::data(index,role);
}
Qt::ItemFlags TableModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return 0;
if (index.column() == 7)
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}