@@ -0,0 +1,113 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Michal Hruby <michal.hruby@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+ */
19+
20+// self
21+#include "fake_resultsmodel.h"
22+
23+ResultsModel::ResultsModel(int result_count, int categoryId, QObject* parent)
24+ : QAbstractListModel(parent)
25+ , m_result_count(result_count)
26+ , m_categoryId(categoryId)
27+{
28+ m_roles[ResultsModel::RoleUri] = "uri";
29+ m_roles[ResultsModel::RoleCategoryId] = "categoryId";
30+ m_roles[ResultsModel::RoleDndUri] = "dndUri";
31+ m_roles[ResultsModel::RoleResult] = "result";
32+ m_roles[ResultsModel::RoleTitle] = "title";
33+ m_roles[ResultsModel::RoleArt] = "art";
34+ m_roles[ResultsModel::RoleSubtitle] = "subtitle";
35+ m_roles[ResultsModel::RoleMascot] = "mascot";
36+ m_roles[ResultsModel::RoleEmblem] = "emblem";
37+ m_roles[ResultsModel::RoleOldPrice] = "oldPrice";
38+ m_roles[ResultsModel::RolePrice] = "price";
39+ m_roles[ResultsModel::RoleAltPrice] = "altPrice";
40+ m_roles[ResultsModel::RoleRating] = "rating";
41+ m_roles[ResultsModel::RoleAltRating] = "altRating";
42+ m_roles[ResultsModel::RoleSummary] = "summary";
43+}
44+
45+QString ResultsModel::categoryId() const
46+{
47+ return QString::number(m_categoryId);
48+}
49+
50+void ResultsModel::setCategoryId(QString const& id)
51+{
52+ qFatal("Calling un-implemented ResultsModel::setCategoryId");
53+}
54+
55+QHash<int, QByteArray>
56+ResultsModel::roleNames() const
57+{
58+ return m_roles;
59+}
60+
61+int ResultsModel::rowCount(const QModelIndex& parent) const
62+{
63+ Q_UNUSED(parent);
64+
65+ return m_result_count;
66+}
67+
68+int ResultsModel::count() const
69+{
70+ return rowCount();
71+}
72+
73+QVariant ResultsModel::get(int row) const
74+{
75+ if (row >= m_result_count || row < 0) return QVariantMap();
76+
77+ QVariantMap result;
78+ QModelIndex modelIndex(index(row));
79+ QHashIterator<int, QByteArray> it(roleNames());
80+ while (it.hasNext()) {
81+ it.next();
82+ QVariant val(data(modelIndex, it.key()));
83+ if (val.isNull()) continue;
84+ result[it.value()] = val;
85+ }
86+
87+ return result;
88+}
89+
90+QVariant
91+ResultsModel::data(const QModelIndex& index, int role) const
92+{
93+ // TODO
94+ switch (role) {
95+ case RoleUri:
96+ case RoleCategoryId:
97+ case RoleDndUri:
98+ case RoleResult:
99+ case RoleTitle:
100+ case RoleArt:
101+ case RoleSubtitle:
102+ case RoleMascot:
103+ case RoleEmblem:
104+ case RoleOldPrice:
105+ case RolePrice:
106+ case RoleAltPrice:
107+ case RoleRating:
108+ case RoleAltRating:
109+ case RoleSummary:
110+ default:
111+ return QVariant();
112+ }
113+}