-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtbmodel.cpp
More file actions
82 lines (70 loc) · 2.09 KB
/
tbmodel.cpp
File metadata and controls
82 lines (70 loc) · 2.09 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 "mainwin.h"
// TBModel
void TBModel::update() {
endResetModel();
}
void TBModel::updateCell(int row, int col) {
QModelIndex idx = index(row,col);
emit dataChanged(idx,idx);
}
void TBModel::updateLine(int row) {
QModelIndex bidx = index(row, 0);
QModelIndex eidx = index(row, columnCount() - 1);
emit dataChanged(bidx, eidx);
}
TBModel::TBModel(QObject* p):QAbstractTableModel(p) {}
int TBModel::columnCount(const QModelIndex&) const {
return 5;
}
int TBModel::rowCount(const QModelIndex&) const {
if (curPage == NULL) return 0;
return curPage->text.size();
}
QVariant TBModel::data(const QModelIndex& idx, int role) const {
QVariant res;
if (!idx.isValid()) return res;
if ((idx.row() < 0) || (idx.row() > rowCount(idx))) return res;
if ((idx.column() < 0) || (idx.column() > columnCount(idx))) return res;
switch(role) {
case Qt::DecorationRole:
if ((idx.column() == 0) && !curPage->text.at(idx.row()).bmrkId.isNull())
res = res = QIcon(":/bookmark.png");
break;
case Qt::DisplayRole:
switch (idx.column()) {
case 1: res = curPage->text.at(idx.row()).src.name; break;
case 2: res = curPage->text.at(idx.row()).src.text; break;
case 3: res = curPage->text.at(idx.row()).trn.name; break;
case 4: res = curPage->text.at(idx.row()).trn.text; break;
}
break;
default:
break;
}
return res;
}
void TBModel::insertRow(int row, const QModelIndex& idx) {
emit beginInsertRows(idx,row,row);
emit endInsertRows();
}
void TBModel::removeRow(int row, const QModelIndex& idx) {
emit beginRemoveRows(idx,row,row);
emit endRemoveRows();
}
QVariant TBModel::headerData(int sect,Qt::Orientation orien, int role) const {
if (role != Qt::DisplayRole) return QVariant();
if (orien == Qt::Vertical) return QString::number(sect+1);
QVariant res;
if (orien == Qt::Horizontal) {
switch (sect) {
case 1: res = "Name"; break;
case 2: res = "Text"; break;
case 3: res = "Имя"; break;
case 4: res = "Текст"; break;
}
}
return res;
}
QModelIndex TBModel::index(int row, int column, const QModelIndex&) const {
return createIndex(row, column, (void*)this);
}