summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/clientapi.h4
-rw-r--r--common/modelresult.h11
-rw-r--r--examples/client/main.cpp22
3 files changed, 25 insertions, 12 deletions
diff --git a/common/clientapi.h b/common/clientapi.h
index 707e81d..179bb5c 100644
--- a/common/clientapi.h
+++ b/common/clientapi.h
@@ -100,6 +100,10 @@ public:
100 return resultSet->emitter(); 100 return resultSet->emitter();
101 } 101 }
102 102
103 enum Roles {
104 DomainObjectRole = Qt::UserRole + 1 //Must be the same as in ModelResult
105 };
106
103 /** 107 /**
104 * Asynchronusly load a dataset with tree structure information 108 * Asynchronusly load a dataset with tree structure information
105 */ 109 */
diff --git a/common/modelresult.h b/common/modelresult.h
index 8ca6daa..3b45955 100644
--- a/common/modelresult.h
+++ b/common/modelresult.h
@@ -63,11 +63,18 @@ public:
63 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const 63 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const
64 { 64 {
65 if (role == DomainObjectRole) { 65 if (role == DomainObjectRole) {
66 qWarning() << "trying to get entity " << index.internalId();
67 Q_ASSERT(mEntities.contains(index.internalId())); 66 Q_ASSERT(mEntities.contains(index.internalId()));
68 return QVariant::fromValue(mEntities.value(index.internalId())); 67 return QVariant::fromValue(mEntities.value(index.internalId()));
69 } 68 }
70 qDebug() << "Invalid role"; 69 if (role == Qt::DisplayRole) {
70 if (index.column() < mPropertyColumns.size()) {
71 Q_ASSERT(mEntities.contains(index.internalId()));
72 auto entity = mEntities.value(index.internalId());
73 return entity->getProperty(mPropertyColumns.at(index.column())).toString();
74 } else {
75 return "No data available";
76 }
77 }
71 return QVariant(); 78 return QVariant();
72 } 79 }
73 80
diff --git a/examples/client/main.cpp b/examples/client/main.cpp
index 0a1a725..75fcf18 100644
--- a/examples/client/main.cpp
+++ b/examples/client/main.cpp
@@ -23,14 +23,13 @@
23 23
24#include "common/clientapi.h" 24#include "common/clientapi.h"
25#include "common/resource.h" 25#include "common/resource.h"
26#include "common/listmodelresult.h"
27#include "common/storage.h" 26#include "common/storage.h"
28#include "common/domain/event.h" 27#include "common/domain/event.h"
29#include "common/resourceconfig.h" 28#include "common/resourceconfig.h"
30#include "console.h" 29#include "console.h"
31 30
32#include <QWidget> 31#include <QWidget>
33#include <QListView> 32#include <QTreeView>
34#include <QVBoxLayout> 33#include <QVBoxLayout>
35#include <QLabel> 34#include <QLabel>
36#include <QPushButton> 35#include <QPushButton>
@@ -43,8 +42,8 @@ public:
43 View(QAbstractItemModel *model) 42 View(QAbstractItemModel *model)
44 : QWidget() 43 : QWidget()
45 { 44 {
46 auto listView = new QListView(this); 45 auto modelView = new QTreeView(this);
47 listView->setModel(model); 46 modelView->setModel(model);
48 resize(1000, 1500); 47 resize(1000, 1500);
49 48
50 auto topLayout = new QVBoxLayout(this); 49 auto topLayout = new QVBoxLayout(this);
@@ -61,21 +60,23 @@ public:
61 QObject::connect(syncButton, &QPushButton::pressed, []() { 60 QObject::connect(syncButton, &QPushButton::pressed, []() {
62 Akonadi2::Query query; 61 Akonadi2::Query query;
63 query.resources << "org.kde.dummy.instance1"; 62 query.resources << "org.kde.dummy.instance1";
64 Akonadi2::Store::synchronize(query); 63 query.syncOnDemand = true;
64 Akonadi2::Store::synchronize(query).exec();
65 }); 65 });
66 66
67 auto removeButton = new QPushButton(this); 67 auto removeButton = new QPushButton(this);
68 removeButton->setText("Remove"); 68 removeButton->setText("Remove");
69 QObject::connect(removeButton, &QPushButton::pressed, [listView]() { 69 QObject::connect(removeButton, &QPushButton::pressed, [modelView]() {
70 for (auto index :listView->selectionModel()->selectedIndexes()) { 70 for (auto index :modelView->selectionModel()->selectedIndexes()) {
71 auto object = index.data(DomainObjectRole).value<typename T::Ptr>(); 71 auto object = index.data(Akonadi2::Store::DomainObjectRole).value<typename T::Ptr>();
72 Akonadi2::Store::remove(*object).exec(); 72 Akonadi2::Store::remove(*object).exec();
73 } 73 }
74 }); 74 });
75 75
76 topLayout->addWidget(titleLabel); 76 topLayout->addWidget(titleLabel);
77 topLayout->addWidget(syncButton); 77 topLayout->addWidget(syncButton);
78 topLayout->addWidget(listView, 10); 78 topLayout->addWidget(modelView, 10);
79 model->fetchMore(QModelIndex());
79 80
80 show(); 81 show();
81 } 82 }
@@ -123,8 +124,9 @@ int main(int argc, char *argv[])
123 query.syncOnDemand = false; 124 query.syncOnDemand = false;
124 query.processAll = false; 125 query.processAll = false;
125 query.liveQuery = true; 126 query.liveQuery = true;
127 query.requestedProperties << "summary" << "uid";
126 128
127 auto model = QSharedPointer<ListModelResult<Akonadi2::ApplicationDomain::Event::Ptr> >::create(Akonadi2::Store::load<Akonadi2::ApplicationDomain::Event>(query), QList<QByteArray>() << "summary" << "uid"); 129 auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Event>(query);
128 auto view = QSharedPointer<View<Akonadi2::ApplicationDomain::Event> >::create(model.data()); 130 auto view = QSharedPointer<View<Akonadi2::ApplicationDomain::Event> >::create(model.data());
129 131
130 return app.exec(); 132 return app.exec();