diff options
Diffstat (limited to 'framework')
-rw-r--r-- | framework/mail/maillistmodel.cpp | 15 | ||||
-rw-r--r-- | framework/mail/maillistmodel.h | 14 |
2 files changed, 18 insertions, 11 deletions
diff --git a/framework/mail/maillistmodel.cpp b/framework/mail/maillistmodel.cpp index f18861c4..5ffcec0f 100644 --- a/framework/mail/maillistmodel.cpp +++ b/framework/mail/maillistmodel.cpp | |||
@@ -1,12 +1,19 @@ | |||
1 | #include "maillistmodel.h" | 1 | #include "maillistmodel.h" |
2 | #include <akonadi2common/clientapi.h> | ||
2 | 3 | ||
3 | MailListModel::MailListModel(QObject *parent) : ListModelResult<Akonadi2::ApplicationDomain::Mail::Ptr>(QList<QByteArray>() << "subject" << "uid") | 4 | |
5 | MailListModel::MailListModel(QObject *parent) | ||
6 | : QIdentityProxyModel() | ||
4 | { | 7 | { |
5 | Akonadi2::Query query; | 8 | Akonadi2::Query query; |
6 | query.syncOnDemand = false; | 9 | query.syncOnDemand = false; |
7 | query.processAll = false; | 10 | query.processAll = false; |
8 | query.liveQuery = true; | 11 | query.liveQuery = true; |
9 | setEmitter(Akonadi2::Store::load<Akonadi2::ApplicationDomain::Mail>(query)); | 12 | QList<QByteArray> requestedProperties; |
13 | requestedProperties << "subject"; | ||
14 | query.requestedProperties = requestedProperties.toSet(); | ||
15 | mModel = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Mail>(query); | ||
16 | setSourceModel(mModel.data()); | ||
10 | } | 17 | } |
11 | 18 | ||
12 | MailListModel::~MailListModel() | 19 | MailListModel::~MailListModel() |
@@ -27,9 +34,9 @@ QVariant MailListModel::data(const QModelIndex &idx, int role) const | |||
27 | { | 34 | { |
28 | switch (role) { | 35 | switch (role) { |
29 | case Subject: | 36 | case Subject: |
30 | return ListModelResult<Akonadi2::ApplicationDomain::Mail::Ptr>::data(index(idx.row(), 0, idx.parent()), Qt::DisplayRole); | 37 | return mapToSource(idx).data(Qt::DisplayRole).toString(); |
31 | } | 38 | } |
32 | return QVariant(); | 39 | return QIdentityProxyModel::data(idx, role); |
33 | } | 40 | } |
34 | 41 | ||
35 | void MailListModel::runQuery(const QString& query) | 42 | void MailListModel::runQuery(const QString& query) |
diff --git a/framework/mail/maillistmodel.h b/framework/mail/maillistmodel.h index b0a153a5..4e360d96 100644 --- a/framework/mail/maillistmodel.h +++ b/framework/mail/maillistmodel.h | |||
@@ -1,13 +1,10 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | 2 | ||
3 | #include <QAbstractListModel> | 3 | #include <QIdentityProxyModel> |
4 | #include <QSharedPointer> | ||
4 | #include <QStringList> | 5 | #include <QStringList> |
5 | 6 | ||
6 | #include <akonadi2common/clientapi.h> | 7 | class MailListModel : public QIdentityProxyModel |
7 | #include <akonadi2common/query.h> | ||
8 | #include <akonadi2common/listmodelresult.h> | ||
9 | |||
10 | class MailListModel : public ListModelResult<Akonadi2::ApplicationDomain::Mail::Ptr> | ||
11 | { | 8 | { |
12 | Q_OBJECT | 9 | Q_OBJECT |
13 | 10 | ||
@@ -15,12 +12,15 @@ public: | |||
15 | MailListModel(QObject *parent = Q_NULLPTR); | 12 | MailListModel(QObject *parent = Q_NULLPTR); |
16 | ~MailListModel(); | 13 | ~MailListModel(); |
17 | 14 | ||
15 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | ||
16 | |||
18 | enum Roles { | 17 | enum Roles { |
19 | Subject = Qt::UserRole + 1 | 18 | Subject = Qt::UserRole + 1 |
20 | }; | 19 | }; |
21 | 20 | ||
22 | QHash<int, QByteArray> roleNames() const; | 21 | QHash<int, QByteArray> roleNames() const; |
23 | QVariant data(const QModelIndex &index, int role) const; | ||
24 | 22 | ||
25 | void runQuery(const QString &query); | 23 | void runQuery(const QString &query); |
24 | private: | ||
25 | QSharedPointer<QAbstractItemModel> mModel; | ||
26 | }; | 26 | }; |