diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/listmodelresult.h | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/common/listmodelresult.h b/common/listmodelresult.h index a893fee..62d1c4e 100644 --- a/common/listmodelresult.h +++ b/common/listmodelresult.h | |||
@@ -20,6 +20,7 @@ | |||
20 | 20 | ||
21 | #pragma once | 21 | #pragma once |
22 | #include <QAbstractListModel> | 22 | #include <QAbstractListModel> |
23 | #include <QDebug> | ||
23 | 24 | ||
24 | #include "common/resultprovider.h" | 25 | #include "common/resultprovider.h" |
25 | 26 | ||
@@ -32,12 +33,12 @@ class ListModelResult : public QAbstractListModel | |||
32 | { | 33 | { |
33 | public: | 34 | public: |
34 | 35 | ||
35 | ListModelResult(const QSharedPointer<Akonadi2::ResultEmitter<T> > &emitter, const QByteArray &property) | 36 | ListModelResult(const QSharedPointer<Akonadi2::ResultEmitter<T> > &emitter, const QList<QByteArray> &propertyColumns) |
36 | :QAbstractListModel(), | 37 | :QAbstractListModel(), |
37 | mEmitter(emitter), | 38 | mEmitter(emitter), |
38 | mProperty(property) | 39 | mPropertyColumns(propertyColumns) |
39 | { | 40 | { |
40 | emitter->onAdded([this, property](const T &value) { | 41 | emitter->onAdded([this](const T &value) { |
41 | const auto keys = mEntities.keys(); | 42 | const auto keys = mEntities.keys(); |
42 | int index = 0; | 43 | int index = 0; |
43 | for (; index < keys.size(); index++) { | 44 | for (; index < keys.size(); index++) { |
@@ -49,13 +50,14 @@ public: | |||
49 | mEntities.insert(value->identifier(), value); | 50 | mEntities.insert(value->identifier(), value); |
50 | endInsertRows(); | 51 | endInsertRows(); |
51 | }); | 52 | }); |
52 | emitter->onModified([this, property](const T &value) { | 53 | emitter->onModified([this](const T &value) { |
54 | auto i = mEntities.keys().indexOf(value->identifier()); | ||
53 | mEntities.remove(value->identifier()); | 55 | mEntities.remove(value->identifier()); |
54 | mEntities.insert(value->identifier(), value); | 56 | mEntities.insert(value->identifier(), value); |
55 | //FIXME | 57 | auto idx = index(i, 0, QModelIndex()); |
56 | // emit dataChanged(); | 58 | emit dataChanged(idx, idx); |
57 | }); | 59 | }); |
58 | emitter->onRemoved([this, property](const T &value) { | 60 | emitter->onRemoved([this](const T &value) { |
59 | auto index = mEntities.keys().indexOf(value->identifier()); | 61 | auto index = mEntities.keys().indexOf(value->identifier()); |
60 | beginRemoveRows(QModelIndex(), index, index); | 62 | beginRemoveRows(QModelIndex(), index, index); |
61 | mEntities.remove(value->identifier()); | 63 | mEntities.remove(value->identifier()); |
@@ -64,11 +66,9 @@ public: | |||
64 | emitter->onInitialResultSetComplete([this]() { | 66 | emitter->onInitialResultSetComplete([this]() { |
65 | }); | 67 | }); |
66 | emitter->onComplete([this]() { | 68 | emitter->onComplete([this]() { |
67 | // qDebug() << "COMPLETE"; | ||
68 | mEmitter.clear(); | 69 | mEmitter.clear(); |
69 | }); | 70 | }); |
70 | emitter->onClear([this]() { | 71 | emitter->onClear([this]() { |
71 | // qDebug() << "CLEAR"; | ||
72 | beginResetModel(); | 72 | beginResetModel(); |
73 | mEntities.clear(); | 73 | mEntities.clear(); |
74 | endResetModel(); | 74 | endResetModel(); |
@@ -80,6 +80,11 @@ public: | |||
80 | return mEntities.size(); | 80 | return mEntities.size(); |
81 | } | 81 | } |
82 | 82 | ||
83 | int columnCount(const QModelIndex &parent = QModelIndex()) const | ||
84 | { | ||
85 | return mPropertyColumns.size(); | ||
86 | } | ||
87 | |||
83 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const | 88 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const |
84 | { | 89 | { |
85 | if (index.row() >= mEntities.size()) { | 90 | if (index.row() >= mEntities.size()) { |
@@ -87,8 +92,10 @@ public: | |||
87 | return QVariant(); | 92 | return QVariant(); |
88 | } | 93 | } |
89 | if (role == Qt::DisplayRole) { | 94 | if (role == Qt::DisplayRole) { |
90 | auto entity = mEntities.value(mEntities.keys().at(index.row())); | 95 | if (index.column() < mPropertyColumns.size()) { |
91 | return entity->getProperty(mProperty).toString() + entity->identifier(); | 96 | auto entity = mEntities.value(mEntities.keys().at(index.row())); |
97 | return entity->getProperty(mPropertyColumns.at(index.column())).toString(); | ||
98 | } | ||
92 | } | 99 | } |
93 | if (role == DomainObjectRole) { | 100 | if (role == DomainObjectRole) { |
94 | return QVariant::fromValue(mEntities.value(mEntities.keys().at(index.row()))); | 101 | return QVariant::fromValue(mEntities.value(mEntities.keys().at(index.row()))); |
@@ -99,6 +106,6 @@ public: | |||
99 | private: | 106 | private: |
100 | QSharedPointer<Akonadi2::ResultEmitter<T> > mEmitter; | 107 | QSharedPointer<Akonadi2::ResultEmitter<T> > mEmitter; |
101 | QMap<QByteArray, T> mEntities; | 108 | QMap<QByteArray, T> mEntities; |
102 | QByteArray mProperty; | 109 | QList<QByteArray> mPropertyColumns; |
103 | }; | 110 | }; |
104 | 111 | ||