diff options
author | Michael Bohlender <michael.bohlender@kdemail.net> | 2015-12-20 17:58:44 +0100 |
---|---|---|
committer | Michael Bohlender <michael.bohlender@kdemail.net> | 2015-12-20 17:58:44 +0100 |
commit | cdfb441777b9e1511d598e20aa357fb3a10e2771 (patch) | |
tree | 9c0a287a42c5cf4be344bb35cae453ffe1d2b3a4 | |
parent | de0b8a3d3db2c01f7aa2c1256744ad9df2468507 (diff) | |
download | kube-cdfb441777b9e1511d598e20aa357fb3a10e2771.tar.gz kube-cdfb441777b9e1511d598e20aa357fb3a10e2771.zip |
resources controller and listmodel
-rw-r--r-- | framework/settings/resourcelistmodel.cpp | 42 | ||||
-rw-r--r-- | framework/settings/resourcelistmodel.h | 26 | ||||
-rw-r--r-- | framework/settings/resourcescontroller.cpp | 12 | ||||
-rw-r--r-- | framework/settings/resourcescontroller.h | 20 |
4 files changed, 100 insertions, 0 deletions
diff --git a/framework/settings/resourcelistmodel.cpp b/framework/settings/resourcelistmodel.cpp new file mode 100644 index 00000000..ebeaac32 --- /dev/null +++ b/framework/settings/resourcelistmodel.cpp | |||
@@ -0,0 +1,42 @@ | |||
1 | #include "resourcelistmodel.h" | ||
2 | |||
3 | #include <akonadi2common/clientapi.h> | ||
4 | |||
5 | ResourceListModel::ResourceListModel(QObject *parent) : QIdentityProxyModel() | ||
6 | { | ||
7 | Akonadi2::Query query; | ||
8 | query.syncOnDemand = false; | ||
9 | query.processAll = false; | ||
10 | query.liveQuery = true; | ||
11 | query.requestedProperties << "type"; | ||
12 | m_model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::AkonadiResource>(query); | ||
13 | } | ||
14 | |||
15 | ResourceListModel::~ResourceListModel() | ||
16 | { | ||
17 | |||
18 | } | ||
19 | |||
20 | QHash< int, QByteArray > ResourceListModel::roleNames() const | ||
21 | { | ||
22 | QHash<int, QByteArray> roles; | ||
23 | |||
24 | roles[Type] = "type"; | ||
25 | roles[Id] = "id"; | ||
26 | |||
27 | return roles; | ||
28 | } | ||
29 | |||
30 | QVariant ResourceListModel::data(const QModelIndex& index, int role) const | ||
31 | { | ||
32 | auto srcIdx = mapToSource(index); | ||
33 | switch (role) { | ||
34 | case Id: | ||
35 | return srcIdx.data(Akonadi2::Store::DomainObjectBaseRole).value<Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr>()->identifier(); | ||
36 | case Type: | ||
37 | return srcIdx.sibling(srcIdx.row(), 0).data(Qt::DisplayRole).toString(); | ||
38 | } | ||
39 | |||
40 | return QIdentityProxyModel::data(index, role); | ||
41 | } | ||
42 | |||
diff --git a/framework/settings/resourcelistmodel.h b/framework/settings/resourcelistmodel.h new file mode 100644 index 00000000..de1b5a51 --- /dev/null +++ b/framework/settings/resourcelistmodel.h | |||
@@ -0,0 +1,26 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include <QIdentityProxyModel> | ||
4 | #include <QSharedPointer> | ||
5 | #include <QStringList> | ||
6 | |||
7 | class ResourceListModel : public QIdentityProxyModel | ||
8 | { | ||
9 | Q_OBJECT | ||
10 | |||
11 | public: | ||
12 | ResourceListModel(QObject *parent = Q_NULLPTR); | ||
13 | ~ResourceListModel(); | ||
14 | |||
15 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | ||
16 | |||
17 | enum Roles { | ||
18 | Id = Qt::UserRole + 1, | ||
19 | Type | ||
20 | }; | ||
21 | |||
22 | QHash<int, QByteArray> roleNames() const; | ||
23 | |||
24 | private: | ||
25 | QSharedPointer<QAbstractItemModel> m_model; | ||
26 | }; | ||
diff --git a/framework/settings/resourcescontroller.cpp b/framework/settings/resourcescontroller.cpp new file mode 100644 index 00000000..03016b67 --- /dev/null +++ b/framework/settings/resourcescontroller.cpp | |||
@@ -0,0 +1,12 @@ | |||
1 | #include "resourcescontroller.h" | ||
2 | |||
3 | ResourcesController::ResourcesController(QObject *parent) : QObject(parent), m_model(new ResourceListModel()) | ||
4 | { | ||
5 | |||
6 | } | ||
7 | |||
8 | |||
9 | ResourceListModel* ResourcesController::model() const | ||
10 | { | ||
11 | return m_model.data(); | ||
12 | } | ||
diff --git a/framework/settings/resourcescontroller.h b/framework/settings/resourcescontroller.h new file mode 100644 index 00000000..0e2e89de --- /dev/null +++ b/framework/settings/resourcescontroller.h | |||
@@ -0,0 +1,20 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include "resourcelistmodel.h" | ||
4 | |||
5 | #include <QObject> | ||
6 | #include <QScopedPointer> | ||
7 | |||
8 | class ResourcesController : public QObject | ||
9 | { | ||
10 | Q_OBJECT | ||
11 | Q_PROPERTY (ResourceListModel *model READ model CONSTANT) | ||
12 | |||
13 | public: | ||
14 | explicit ResourcesController(QObject *parent = Q_NULLPTR); | ||
15 | |||
16 | ResourceListModel *model() const; | ||
17 | |||
18 | private: | ||
19 | QScopedPointer<ResourceListModel> m_model; | ||
20 | }; | ||