summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-08-01 17:33:03 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-08-01 17:33:03 +0200
commit3a4adb790b4d3bef746f5ad88ef073ef821053fa (patch)
tree93e43200989c3f2a44073851139e3d144c0ea4c3
parent8d5f8e5fd00d092941c55ffcc5b50c84dbd635f2 (diff)
downloadkube-3a4adb790b4d3bef746f5ad88ef073ef821053fa.tar.gz
kube-3a4adb790b4d3bef746f5ad88ef073ef821053fa.zip
Query for the list of calendars
-rw-r--r--framework/src/CMakeLists.txt1
-rw-r--r--framework/src/entitymodel.cpp142
-rw-r--r--framework/src/entitymodel.h74
-rw-r--r--framework/src/frameworkplugin.cpp2
-rw-r--r--views/calendar/qml/View.qml7
5 files changed, 224 insertions, 2 deletions
diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt
index 46ec3105..86bbf598 100644
--- a/framework/src/CMakeLists.txt
+++ b/framework/src/CMakeLists.txt
@@ -54,6 +54,7 @@ add_library(kubeframework SHARED
54 viewhighlighter.cpp 54 viewhighlighter.cpp
55 file.cpp 55 file.cpp
56 logmodel.cpp 56 logmodel.cpp
57 entitymodel.cpp
57 ) 58 )
58generate_export_header(kubeframework BASE_NAME Kube EXPORT_FILE_NAME kube_export.h) 59generate_export_header(kubeframework BASE_NAME Kube EXPORT_FILE_NAME kube_export.h)
59set_target_properties(kubeframework PROPERTIES 60set_target_properties(kubeframework PROPERTIES
diff --git a/framework/src/entitymodel.cpp b/framework/src/entitymodel.cpp
new file mode 100644
index 00000000..5d8ac83e
--- /dev/null
+++ b/framework/src/entitymodel.cpp
@@ -0,0 +1,142 @@
1/*
2 Copyright (c) 2018 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "entitymodel.h"
21
22#include <sink/store.h>
23#include <sink/log.h>
24
25using namespace Sink;
26using namespace Sink::ApplicationDomain;
27
28EntityModel::EntityModel(QObject *parent) : QSortFilterProxyModel(parent)
29{
30 setDynamicSortFilter(true);
31 sort(0, Qt::AscendingOrder);
32}
33
34EntityModel::~EntityModel()
35{
36
37}
38
39QHash< int, QByteArray > EntityModel::roleNames() const
40{
41 return mRoleNames;
42}
43
44QVariant EntityModel::data(const QModelIndex &idx, int role) const
45{
46 auto srcIdx = mapToSource(idx);
47 auto entity = srcIdx.data(Sink::Store::DomainObjectBaseRole).value<Sink::ApplicationDomain::ApplicationDomainType::Ptr>();
48
49 const auto roleName = mRoleNames.value(role);
50 qWarning() << "Fetch data" << idx << role << roleName;
51 if (roleName == "identifier") {
52 return entity->identifier();
53 } else if (roleName == "object") {
54 return QVariant::fromValue(entity);
55 } else {
56 return entity->getProperty(roleName);
57 }
58}
59
60void EntityModel::runQuery(const Query &query)
61{
62 if (mType == "calendar") {
63 mModel = Store::loadModel<Calendar>(query);
64 } else {
65 qWarning() << "Type not supported " << mType;
66 }
67 setSourceModel(mModel.data());
68}
69
70void EntityModel::updateQuery()
71{
72 if (mType.isEmpty() || mRoles.isEmpty()) {
73 return;
74 }
75
76 Query query;
77 if (!mAccountId.isEmpty()) {
78 query.resourceFilter<SinkResource::Account>(mAccountId.toUtf8());
79 }
80 query.setFlags(Sink::Query::LiveQuery | Sink::Query::UpdateStatus);
81
82 for (const auto &property: mRoles.keys()) {
83 query.requestedProperties << property;
84 }
85 runQuery(query);
86}
87
88void EntityModel::setAccountId(const QString &accountId)
89{
90
91 //Get all folders of an account
92 mAccountId = accountId;
93 updateQuery();
94}
95
96QString EntityModel::accountId() const
97{
98 return {};
99}
100
101void EntityModel::setType(const QString &type)
102{
103 mType = type;
104 updateQuery();
105}
106
107QString EntityModel::type() const
108{
109 return {};
110}
111
112void EntityModel::setRoles(const QStringList &roles)
113{
114 mRoleNames.clear();
115 int role = Qt::UserRole + 1;
116 mRoleNames.insert(role++, "identifier");
117 mRoleNames.insert(role++, "object");
118 for (int i = 0; i < roles.size(); i++) {
119 mRoleNames.insert(role++, roles.at(i).toLatin1());
120 }
121 mRoles.clear();
122 for (const auto &r : mRoleNames.keys()) {
123 mRoles.insert(mRoleNames.value(r), r);
124 }
125 updateQuery();
126}
127
128QStringList EntityModel::roles() const
129{
130 // return mRoleNames.values();
131 return {};
132}
133
134void EntityModel::setFilter(const QVariantMap &)
135{
136 //TODO
137}
138
139QVariantMap EntityModel::filter() const
140{
141 return {};
142}
diff --git a/framework/src/entitymodel.h b/framework/src/entitymodel.h
new file mode 100644
index 00000000..b8a0417e
--- /dev/null
+++ b/framework/src/entitymodel.h
@@ -0,0 +1,74 @@
1/*
2 Copyright (c) 2018 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#pragma once
21#include "kube_export.h"
22#include <QSharedPointer>
23#include <QSortFilterProxyModel>
24
25namespace Sink {
26 class Query;
27}
28
29class KUBE_EXPORT EntityModel : public QSortFilterProxyModel
30{
31 Q_OBJECT
32
33 Q_PROPERTY (QString accountId READ accountId WRITE setAccountId)
34 Q_PROPERTY (QString type READ type WRITE setType)
35 Q_PROPERTY (QStringList roles READ roles WRITE setRoles)
36 Q_PROPERTY (QVariantMap filter READ filter WRITE setFilter)
37
38public:
39 enum Status {
40 NoStatus,
41 InProgressStatus,
42 ErrorStatus,
43 SuccessStatus,
44 };
45 Q_ENUMS(Status)
46
47 EntityModel(QObject *parent = Q_NULLPTR);
48 ~EntityModel();
49
50 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
51
52 QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
53
54 void setAccountId(const QString &);
55 QString accountId() const;
56
57 void setType(const QString &);
58 QString type() const;
59
60 void setRoles(const QStringList &);
61 QStringList roles() const;
62
63 void setFilter(const QVariantMap &);
64 QVariantMap filter() const;
65
66private:
67 void runQuery(const Sink::Query &query);
68 void updateQuery();
69 QSharedPointer<QAbstractItemModel> mModel;
70 QHash<int, QByteArray> mRoleNames;
71 QHash<QByteArray, int> mRoles;
72 QString mAccountId;
73 QString mType;
74};
diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp
index 72e9730b..5fc4eb27 100644
--- a/framework/src/frameworkplugin.cpp
+++ b/framework/src/frameworkplugin.cpp
@@ -46,6 +46,7 @@
46#include "viewhighlighter.h" 46#include "viewhighlighter.h"
47#include "file.h" 47#include "file.h"
48#include "logmodel.h" 48#include "logmodel.h"
49#include "entitymodel.h"
49 50
50#include <QtQml> 51#include <QtQml>
51#include <QQuickImageProvider> 52#include <QQuickImageProvider>
@@ -172,6 +173,7 @@ void FrameworkPlugin::registerTypes (const char *uri)
172 qmlRegisterType<PeopleModel>(uri, 1, 0,"PeopleModel"); 173 qmlRegisterType<PeopleModel>(uri, 1, 0,"PeopleModel");
173 qmlRegisterType<TextDocumentHandler>(uri, 1, 0, "TextDocumentHandler"); 174 qmlRegisterType<TextDocumentHandler>(uri, 1, 0, "TextDocumentHandler");
174 qmlRegisterType<LogModel>(uri, 1, 0, "LogModel"); 175 qmlRegisterType<LogModel>(uri, 1, 0, "LogModel");
176 qmlRegisterType<EntityModel>(uri, 1, 0, "EntityModel");
175 177
176 qmlRegisterType<AccountFactory>(uri, 1, 0, "AccountFactory"); 178 qmlRegisterType<AccountFactory>(uri, 1, 0, "AccountFactory");
177 qmlRegisterType<AccountsModel>(uri, 1, 0, "AccountsModel"); 179 qmlRegisterType<AccountsModel>(uri, 1, 0, "AccountsModel");
diff --git a/views/calendar/qml/View.qml b/views/calendar/qml/View.qml
index 8a166c47..505c6754 100644
--- a/views/calendar/qml/View.qml
+++ b/views/calendar/qml/View.qml
@@ -95,14 +95,17 @@ RowLayout {
95 spacing: Kube.Units.smallSpacing 95 spacing: Kube.Units.smallSpacing
96 96
97 Repeater { 97 Repeater {
98 model: ["calendar_1","calendar_2","calendar_3"] 98 model: Kube.EntityModel {
99 type: "calendar"
100 roles: ["name"]
101 }
99 delegate: Row { 102 delegate: Row {
100 spacing: Kube.Units.smallSpacing 103 spacing: Kube.Units.smallSpacing
101 Kube.CheckBox { 104 Kube.CheckBox {
102 opacity: 0.9 105 opacity: 0.9
103 } 106 }
104 Kube.Label { 107 Kube.Label {
105 text: modelData 108 text: model.name
106 color: Kube.Colors.highlightedTextColor 109 color: Kube.Colors.highlightedTextColor
107 } 110 }
108 } 111 }