on bc2a7bd help sign in
unity8/plugins/Unity/categoryresults.cpp
87 lines 2.5 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * Michał Sawicz <michal.sawicz@canonical.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
20// self
21#include "categoryresults.h"
23CategoryResults::CategoryResults(QObject* parent)
24 : DeeListModel(parent)
25 , m_category_index(-1)
27 m_roles[CategoryResults::RoleUri] = "uri";
28 m_roles[CategoryResults::RoleIconHint] = "icon";
29 m_roles[CategoryResults::RoleCategory] = "category";
30 m_roles[CategoryResults::RoleMimetype] = "mimetype";
31 m_roles[CategoryResults::RoleTitle] = "title";
32 m_roles[CategoryResults::RoleComment] = "comment";
33 m_roles[CategoryResults::RoleDndUri] = "dnd_uri";
34 m_roles[CategoryResults::RoleMetadata] = "metadata";
37CategoryResults::~CategoryResults()
41int CategoryResults::categoryIndex() const
43 return m_category_index;
46void CategoryResults::setCategoryIndex(int index)
48 if (m_category_index != index) {
49 m_category_index = index;
50 Q_EMIT categoryIndexChanged(m_category_index);
51 }
54QHash<int, QByteArray>
55CategoryResults::roleNames() const
57 return m_roles;
60QVariant
61CategoryResults::data(const QModelIndex& index, int role) const
63 if (!index.isValid()) {
64 return QVariant();
65 }
67 switch (role) {
68 case RoleUri:
69 return DeeListModel::data(index, 0);
70 case RoleIconHint:
71 return DeeListModel::data(index, 1);
72 case RoleCategory:
73 return DeeListModel::data(index, 2);
74 case RoleMimetype:
75 return DeeListModel::data(index, 4);
76 case RoleTitle:
77 return DeeListModel::data(index, 5);
78 case RoleComment:
79 return DeeListModel::data(index, 6);
80 case RoleDndUri:
81 return DeeListModel::data(index, 7);
82 case RoleMetadata:
83 return DeeListModel::data(index, 8);
84 default:
85 return QVariant();
86 }