diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-10-22 16:14:27 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-10-22 16:14:27 +0200 |
commit | 2b8d6ef2a469ef1d025f80d9ae3044e21faa983a (patch) | |
tree | e1fb01950dc16dd158925d59d754c7114367bd31 | |
parent | 59753ee27638eecd7869f2160de65bec07bfdd00 (diff) | |
download | sink-2b8d6ef2a469ef1d025f80d9ae3044e21faa983a.tar.gz sink-2b8d6ef2a469ef1d025f80d9ae3044e21faa983a.zip |
Make it possible to set a new emitter on the listresultmodel
-rw-r--r-- | common/listmodelresult.h | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/common/listmodelresult.h b/common/listmodelresult.h index 62d1c4e..a095c2a 100644 --- a/common/listmodelresult.h +++ b/common/listmodelresult.h | |||
@@ -22,7 +22,7 @@ | |||
22 | #include <QAbstractListModel> | 22 | #include <QAbstractListModel> |
23 | #include <QDebug> | 23 | #include <QDebug> |
24 | 24 | ||
25 | #include "common/resultprovider.h" | 25 | #include "resultprovider.h" |
26 | 26 | ||
27 | enum Roles { | 27 | enum Roles { |
28 | DomainObjectRole = Qt::UserRole + 1 | 28 | DomainObjectRole = Qt::UserRole + 1 |
@@ -33,11 +33,24 @@ class ListModelResult : public QAbstractListModel | |||
33 | { | 33 | { |
34 | public: | 34 | public: |
35 | 35 | ||
36 | ListModelResult(const QList<QByteArray> &propertyColumns) | ||
37 | :QAbstractListModel(), | ||
38 | mPropertyColumns(propertyColumns) | ||
39 | { | ||
40 | } | ||
41 | |||
36 | ListModelResult(const QSharedPointer<Akonadi2::ResultEmitter<T> > &emitter, const QList<QByteArray> &propertyColumns) | 42 | ListModelResult(const QSharedPointer<Akonadi2::ResultEmitter<T> > &emitter, const QList<QByteArray> &propertyColumns) |
37 | :QAbstractListModel(), | 43 | :QAbstractListModel(), |
38 | mEmitter(emitter), | ||
39 | mPropertyColumns(propertyColumns) | 44 | mPropertyColumns(propertyColumns) |
40 | { | 45 | { |
46 | setEmitter(emitter); | ||
47 | } | ||
48 | |||
49 | void setEmitter(const QSharedPointer<Akonadi2::ResultEmitter<T> > &emitter) | ||
50 | { | ||
51 | beginResetModel(); | ||
52 | mEntities.clear(); | ||
53 | mEmitter = emitter; | ||
41 | emitter->onAdded([this](const T &value) { | 54 | emitter->onAdded([this](const T &value) { |
42 | const auto keys = mEntities.keys(); | 55 | const auto keys = mEntities.keys(); |
43 | int index = 0; | 56 | int index = 0; |
@@ -73,6 +86,7 @@ public: | |||
73 | mEntities.clear(); | 86 | mEntities.clear(); |
74 | endResetModel(); | 87 | endResetModel(); |
75 | }); | 88 | }); |
89 | endResetModel(); | ||
76 | } | 90 | } |
77 | 91 | ||
78 | int rowCount(const QModelIndex &parent = QModelIndex()) const | 92 | int rowCount(const QModelIndex &parent = QModelIndex()) const |
@@ -85,7 +99,7 @@ public: | |||
85 | return mPropertyColumns.size(); | 99 | return mPropertyColumns.size(); |
86 | } | 100 | } |
87 | 101 | ||
88 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const | 102 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const |
89 | { | 103 | { |
90 | if (index.row() >= mEntities.size()) { | 104 | if (index.row() >= mEntities.size()) { |
91 | qWarning() << "Out of bounds access"; | 105 | qWarning() << "Out of bounds access"; |