From cdfb441777b9e1511d598e20aa357fb3a10e2771 Mon Sep 17 00:00:00 2001 From: Michael Bohlender Date: Sun, 20 Dec 2015 17:58:44 +0100 Subject: resources controller and listmodel --- framework/settings/resourcelistmodel.cpp | 42 ++++++++++++++++++++++++++++++ framework/settings/resourcelistmodel.h | 26 ++++++++++++++++++ framework/settings/resourcescontroller.cpp | 12 +++++++++ framework/settings/resourcescontroller.h | 20 ++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 framework/settings/resourcelistmodel.cpp create mode 100644 framework/settings/resourcelistmodel.h create mode 100644 framework/settings/resourcescontroller.cpp create mode 100644 framework/settings/resourcescontroller.h (limited to 'framework') 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 @@ +#include "resourcelistmodel.h" + +#include + +ResourceListModel::ResourceListModel(QObject *parent) : QIdentityProxyModel() +{ + Akonadi2::Query query; + query.syncOnDemand = false; + query.processAll = false; + query.liveQuery = true; + query.requestedProperties << "type"; + m_model = Akonadi2::Store::loadModel(query); +} + +ResourceListModel::~ResourceListModel() +{ + +} + +QHash< int, QByteArray > ResourceListModel::roleNames() const +{ + QHash roles; + + roles[Type] = "type"; + roles[Id] = "id"; + + return roles; +} + +QVariant ResourceListModel::data(const QModelIndex& index, int role) const +{ + auto srcIdx = mapToSource(index); + switch (role) { + case Id: + return srcIdx.data(Akonadi2::Store::DomainObjectBaseRole).value()->identifier(); + case Type: + return srcIdx.sibling(srcIdx.row(), 0).data(Qt::DisplayRole).toString(); + } + + return QIdentityProxyModel::data(index, role); +} + 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 @@ +#pragma once + +#include +#include +#include + +class ResourceListModel : public QIdentityProxyModel +{ + Q_OBJECT + +public: + ResourceListModel(QObject *parent = Q_NULLPTR); + ~ResourceListModel(); + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + + enum Roles { + Id = Qt::UserRole + 1, + Type + }; + + QHash roleNames() const; + +private: + QSharedPointer m_model; +}; 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 @@ +#include "resourcescontroller.h" + +ResourcesController::ResourcesController(QObject *parent) : QObject(parent), m_model(new ResourceListModel()) +{ + +} + + +ResourceListModel* ResourcesController::model() const +{ + return m_model.data(); +} 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 @@ +#pragma once + +#include "resourcelistmodel.h" + +#include +#include + +class ResourcesController : public QObject +{ + Q_OBJECT + Q_PROPERTY (ResourceListModel *model READ model CONSTANT) + +public: + explicit ResourcesController(QObject *parent = Q_NULLPTR); + + ResourceListModel *model() const; + +private: + QScopedPointer m_model; +}; -- cgit v1.2.3