blob: a41b6a2d7148b7cdd952c5c2c199aae44c2f8238 (
plain) (
blame)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#include "ThreadModel.h"
ThreadModel::ThreadModel (Message *root, QObject *parent)
: QAbstractItemModel (parent)
{
m_root = root;
}
ThreadModel::~ThreadModel ()
{
}
void
ThreadModel::setRoot (Message *root)
{
m_root = root;
}
int
ThreadModel::columnCount (const QModelIndex &parent) const
{
return 1;
}
Qt::ItemFlags
ThreadModel::flags (const QModelIndex &index) const
{
return Qt::NoItemFlags;
}
QVariant
ThreadModel::data (const QModelIndex &index,
int role) const
{
if (role != Qt::DisplayRole || !index.isValid())
return QVariant ();
Message *msg = static_cast<Message *> (index.internalPointer());
return QVariant::fromValue (msg);
}
QModelIndex
ThreadModel::index (int row, int column,
const QModelIndex &parent) const
{
if (!hasIndex(row, column, parent))
return QModelIndex();
Message *
msg = (parent.isValid ())
? static_cast<Message *> (parent.internalPointer())
: m_root;
Message *child = msg->child (row);
return (child)
? createIndex (row, column, child)
: QModelIndex ();
}
QModelIndex
ThreadModel::parent (const QModelIndex &index) const
{
if (!index.isValid ())
return QModelIndex();
Message *child = static_cast<Message *> (index.internalPointer());
Message *parent = child->parent ();
return (parent == m_root)
? QModelIndex ()
: createIndex (parent->index(), 0, parent);
}
int
ThreadModel::rowCount (const QModelIndex &parent) const
{
if (0 != parent.column ())
return 0;
Message *
msg = (parent.isValid ())
? static_cast<Message *> (parent.internalPointer())
: m_root;
return msg->childrenCount ();
}
|