summaryrefslogtreecommitdiffstats
path: root/framework/settings/resourcelistmodel.cpp
blob: 7d97f3427461ec75940279a490e09e10d3ca8fe5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "resourcelistmodel.h"

#include <sink/clientapi.h>

ResourceListModel::ResourceListModel(QObject *parent) : QIdentityProxyModel()
{
    Sink::Query query;
    query.syncOnDemand = false;
    query.processAll = false;
    query.liveQuery = true;
    query.requestedProperties << "type";
    m_model = Sink::Store::loadModel<Sink::ApplicationDomain::SinkResource>(query);
}

ResourceListModel::~ResourceListModel()
{

}

QHash< int, QByteArray > ResourceListModel::roleNames() const
{
    QHash<int, QByteArray> 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(Sink::Store::DomainObjectBaseRole).value<Sink::ApplicationDomain::ApplicationDomainType::Ptr>()->identifier();
        case Type:
            return srcIdx.sibling(srcIdx.row(), 0).data(Qt::DisplayRole).toString();
    }

    return QIdentityProxyModel::data(index, role);
}