-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbmlmodel.cpp
More file actions
50 lines (44 loc) · 1.08 KB
/
bmlmodel.cpp
File metadata and controls
50 lines (44 loc) · 1.08 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
#include "models.h"
#include "base.h"
BMLModel::BMLModel(QObject* p):QAbstractTableModel(p) {}
int BMLModel::columnCount(const QModelIndex&) const {
return 2;
}
int BMLModel::rowCount(const QModelIndex&) const {
return bookmarks.size();
}
QVariant BMLModel::data(const QModelIndex& idx, int role) const {
QVariant res;
if (!idx.isValid()) return res;
int row = idx.row();
int col = idx.column();
if ((row < 0) || (col < 0)) return res;
if (row >= rowCount()) return res;
if (col >= columnCount()) return res;
if (row >= bookmarks.size()) return res;
TBookmark bm = bookmarks.at(row);
TPage* pg = findPage(bm.pgid);
switch (role) {
case Qt::DisplayRole:
switch (col) {
case 0:
res = bm.name;
break;
case 1:
if (pg) res = QString("%0:%1").arg(pg->name).arg(bm.row);
break;
//case 2:
// res = bm.descr;
// break;
}
break;
}
return res;
}
QModelIndex BMLModel::index(int row, int column, const QModelIndex&) const {
QModelIndex res = createIndex(row, column, (void*)this);
return res;
}
void BMLModel::update() {
endResetModel();
}