blob: 14219ee257979f0c8f28d2e747745cfea8ddf35a (
plain)
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
|
#include "maillistmodel.h"
#include <QDateTime>
MailListModel::MailListModel(QObject *parent) : QAbstractListModel(parent), m_msgs()
{
}
MailListModel::~MailListModel()
{
}
QHash< int, QByteArray > MailListModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[Subject] = "subject";
return roles;
}
QVariant MailListModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) {
return QVariant();
}
if (index.row() >= m_msgs.count() || index.row() < 0) {
return QVariant();
}
switch (role) {
case Subject:
return m_msgs.at(index.row());
}
return QVariant();
}
int MailListModel::rowCount(const QModelIndex &parent) const
{
return m_msgs.size();
}
bool MailListModel::addMails(const QStringList &items)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount() + items.size() - 1);
m_msgs += items;
endInsertRows();
return true;
}
void MailListModel::clearMails()
{
if (!m_msgs.isEmpty()) {
beginResetModel();
m_msgs.clear();
endResetModel();
}
}
void MailListModel::runQuery(const QString& query)
{
clearMails();
QStringList itemlist;
itemlist << "I feel tiny" << "Big News!" << "[FUN] lets do things";
addMails(itemlist);
}
|