-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocumentsmodel.cpp
63 lines (52 loc) · 1.42 KB
/
documentsmodel.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
#include "documentsmodel.h"
DocumentsModel::DocumentsModel(QObject *parent) :
QAbstractListModel(parent),
m_docList(0)
{
QHash<int, QByteArray> roles = roleNames();
roles[UrlRole] = "url";
roles[TypeRole] = "type";
roles[AuthorRole] = "author";
setRoleNames(roles);
}
void DocumentsModel::setDocumentsList(QList<GoogleDocument *> *docList)
{
beginResetModel();
m_docList = docList;
endResetModel();
}
int DocumentsModel::rowCount(const QModelIndex &parent) const
{
if (m_docList)
return m_docList->count();
else
return 0;
}
QVariant DocumentsModel::data(const QModelIndex &index, int role) const
{
if (!m_docList || index.row() >= rowCount())
return QVariant();
switch (role) {
case Qt::DisplayRole:
return m_docList->at(index.row())->title();
case UrlRole:
return m_docList->at(index.row())->documentUrl();
case TypeRole:
return m_docList->at(index.row())->documentType();
case AuthorRole:
return m_docList->at(index.row())->author();
}
return QVariant();
}
int DocumentsModel::count() const
{
return m_docList ? m_docList->count() : 0;
}
QVariantMap DocumentsModel::get(int index) const
{
QVariantMap listElement;
if (index < 0 || !m_docList || index > m_docList->count())
return listElement;
listElement["type"] = m_docList->at(index)->documentType();
return listElement;
}