-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtablemodel.cpp
65 lines (59 loc) · 1.3 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "tablemodel.h"
TableModel::TableModel(QList<ComponentListEntry*> *c, QObject *parent) : QAbstractTableModel(parent)
{
this->cList = c;
}
int TableModel::columnCount(const QModelIndex &parent) const {return NUMCOLS;}
int TableModel::rowCount(const QModelIndex &parent) const {return cList->count();}
QVariant TableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(role == Qt::DisplayRole && orientation == Qt::Horizontal)
{
switch (section) {
case NAME:
return "Name";
case PATH:
return "Path";
case EXCLUDE:
return "Excluded";
default:
break;
}
}
return QVariant();
}
Qt::ItemFlags TableModel::flags(const QModelIndex &index) const
{
switch (index.column()) {
case NAME:
return Qt::ItemIsEnabled;
case PATH:
return Qt::ItemIsEnabled;
case EXCLUDE:
return Qt::ItemIsEnabled;
default:
break;
}
return 0;
}
QVariant TableModel::data(const QModelIndex &index, int role) const
{
if(role == Qt::CheckStateRole && index.column()==EXCLUDE)
{
if(cList->at(index.row())->isExcluded())
return Qt::Checked;
else
return Qt::Unchecked;
}
if(role == Qt::DisplayRole)
{
switch(index.column())
{
case NAME:
return cList->at(index.row())->name();
case PATH:
return cList->at(index.row())->path();
}
}
return QVariant();
}