on xenial help sign in
Updated Indicator model roles for fixing test suite.
c042d15Nick Dedekind
Panel/MenuContent.qml+1−1
@@ -184,7 +184,7 @@ Rectangle {
184 if (content.overviewActive)
184 if (content.overviewActive)
185 return i18n.tr("Device");
185 return i18n.tr("Device");
186 if (indicatorsModel && menus.currentIndex >= 0 && menus.currentIndex < indicatorsModel.count)
186 if (indicatorsModel && menus.currentIndex >= 0 && menus.currentIndex < indicatorsModel.count)
187− return indicatorsModel.data(menus.currentIndex, Indicators.IndicatorsModel.Title);
187+ return indicatorsModel.data(menus.currentIndex, Indicators.IndicatorsModelRole.Title);
188 return "";
188 return "";
189 }
189 }
190 opacity: __shown ? 1 : 0
190 opacity: __shown ? 1 : 0
modules/Unity/Indicators/flatmenuproxymodel.h−10
@@ -36,16 +36,6 @@ class FlatMenuProxyModel : public QAbstractProxyModel
36
36
37 Q_ENUMS(Roles)
37 Q_ENUMS(Roles)
38public:
38public:
39− // Because this is a proxy to qmenumodel, it may change.
40− enum Roles {
41− Action = Qt::DisplayRole + 1,
42− Label,
43− Extra,
44− Depth,
45− hasSection,
46− hasSubMenu
47− };
48−
49 FlatMenuProxyModel(QAbstractItemModel *source=0);
39 FlatMenuProxyModel(QAbstractItemModel *source=0);
50 ~FlatMenuProxyModel();
40 ~FlatMenuProxyModel();
51
41
modules/Unity/Indicators/indicators.h+38
@@ -19,6 +19,8 @@
19#ifndef INDICATORS_H
19#ifndef INDICATORS_H
20#define INDICATORS_H
20#define INDICATORS_H
21
21
22+#include <QObject>
23+
22class ActionState : public QObject
24class ActionState : public QObject
23{
25{
24 Q_OBJECT
26 Q_OBJECT
@@ -62,4 +64,40 @@ public:
62 NetworkConnection(QObject*parent=0):QObject(parent) {}
64 NetworkConnection(QObject*parent=0):QObject(parent) {}
63};
65};
64
66
67+class IndicatorsModelRole : public QObject
68+{
69+ Q_OBJECT
70+public:
71+ Q_ENUMS(Roles)
72+ enum Roles {
73+ Identifier = 0,
74+ Priority,
75+ Title,
76+ Description,
77+ WidgetSource,
78+ PageSource,
79+ IndicatorProperties,
80+ IsValid
81+ };
82+
83+ IndicatorsModelRole(QObject*parent=0):QObject(parent) {}
84+};
85+
86+class FlatMenuProxyModelRole : public QObject
87+{
88+ Q_OBJECT
89+public:
90+ Q_ENUMS(Roles)
91+ enum Roles {
92+ Action = Qt::DisplayRole + 1,
93+ Label,
94+ Extra,
95+ Depth,
96+ hasSection,
97+ hasSubMenu
98+ };
99+
100+ FlatMenuProxyModelRole(QObject*parent=0):QObject(parent) {}
101+};
102+
65#endif // INDICATORS_H
103#endif // INDICATORS_H
modules/Unity/Indicators/indicatorsmodel.cpp+25−24
@@ -20,6 +20,7 @@
20#include "indicatorsmodel.h"
20#include "indicatorsmodel.h"
21#include "indicatorsmanager.h"
21#include "indicatorsmanager.h"
22#include "indicator.h"
22#include "indicator.h"
23+#include "indicators.h"
23#include "paths.h"
24#include "paths.h"
24
25
25#include <QQmlContext>
26#include <QQmlContext>
@@ -118,7 +119,7 @@ void IndicatorsModel::onIndicatorLoaded(const QString& indicator_name)
118 while (pos < count())
119 while (pos < count())
119 {
120 {
120 // keep going while the existing priority is less.
121 // keep going while the existing priority is less.
121− if (indicatorData(indicator, Priority).toInt() < data(index(pos), Priority).toInt())
122+ if (indicatorData(indicator, IndicatorsModelRole::Priority).toInt() < data(index(pos), IndicatorsModelRole::Priority).toInt())
122 break;
123 break;
123 pos++;
124 pos++;
124 }
125 }
@@ -160,13 +161,13 @@ void IndicatorsModel::onIndicatorAboutToBeUnloaded(const QString& indicator_name
160/*! \internal */
161/*! \internal */
161void IndicatorsModel::onIdentifierChanged()
162void IndicatorsModel::onIdentifierChanged()
162{
163{
163− notifyDataChanged(QObject::sender(), Identifier);
164+ notifyDataChanged(QObject::sender(), IndicatorsModelRole::Identifier);
164}
165}
165
166
166/*! \internal */
167/*! \internal */
167void IndicatorsModel::onIndicatorPropertiesChanged()
168void IndicatorsModel::onIndicatorPropertiesChanged()
168{
169{
169− notifyDataChanged(QObject::sender(), IndicatorProperties);
170+ notifyDataChanged(QObject::sender(), IndicatorsModelRole::IndicatorProperties);
170}
171}
171
172
172/*! \internal */
173/*! \internal */
@@ -198,14 +199,14 @@ QHash<int, QByteArray> IndicatorsModel::roleNames() const
198 static QHash<int, QByteArray> roles;
199 static QHash<int, QByteArray> roles;
199 if (roles.isEmpty())
200 if (roles.isEmpty())
200 {
201 {
201− roles[Identifier] = "identifier";
202+ roles[IndicatorsModelRole::Identifier] = "identifier";
202− roles[Priority] = "priority";
203+ roles[IndicatorsModelRole::Priority] = "priority";
203− roles[Title] = "title";
204+ roles[IndicatorsModelRole::Title] = "title";
204− roles[Description] = "description";
205+ roles[IndicatorsModelRole::Description] = "description";
205− roles[WidgetSource] = "widgetSource";
206+ roles[IndicatorsModelRole::WidgetSource] = "widgetSource";
206− roles[PageSource] = "pageSource";
207+ roles[IndicatorsModelRole::PageSource] = "pageSource";
207− roles[IndicatorProperties] = "indicatorProperties";
208+ roles[IndicatorsModelRole::IndicatorProperties] = "indicatorProperties";
208− roles[IsValid] = "isValid";
209+ roles[IndicatorsModelRole::IsValid] = "isValid";
209 }
210 }
210 return roles;
211 return roles;
211}
212}
@@ -221,15 +222,15 @@ QVariant IndicatorsModel::defaultData(Indicator::Ptr indicator, int role)
221{
222{
222 switch (role)
223 switch (role)
223 {
224 {
224− case Priority:
225+ case IndicatorsModelRole::Priority:
225 return 0;
226 return 0;
226− case Title:
227+ case IndicatorsModelRole::Title:
227 return indicator ? indicator->identifier() : "Unknown";
228 return indicator ? indicator->identifier() : "Unknown";
228− case Description:
229+ case IndicatorsModelRole::Description:
229 return "";
230 return "";
230− case WidgetSource:
231+ case IndicatorsModelRole::WidgetSource:
231 return shellAppDirectory()+"/Panel/Indicators/DefaultIndicatorWidget.qml";
232 return shellAppDirectory()+"/Panel/Indicators/DefaultIndicatorWidget.qml";
232− case PageSource:
233+ case IndicatorsModelRole::PageSource:
233 return shellAppDirectory()+"/Panel/Indicators/DefaultIndicatorPage.qml";
234 return shellAppDirectory()+"/Panel/Indicators/DefaultIndicatorPage.qml";
234 }
235 }
235 return QVariant();
236 return QVariant();
@@ -250,25 +251,25 @@ QVariant IndicatorsModel::data(const QModelIndex &index, int role) const
250
251
251 switch (role)
252 switch (role)
252 {
253 {
253− case Identifier:
254+ case IndicatorsModelRole::Identifier:
254 if (indicator)
255 if (indicator)
255 {
256 {
256 return QVariant(indicator->identifier());
257 return QVariant(indicator->identifier());
257 }
258 }
258 break;
259 break;
259− case IndicatorProperties:
260+ case IndicatorsModelRole::IndicatorProperties:
260 if (indicator)
261 if (indicator)
261 {
262 {
262 return QVariant(indicator->indicatorProperties());
263 return QVariant(indicator->indicatorProperties());
263 }
264 }
264 break;
265 break;
265− case IsValid:
266+ case IndicatorsModelRole::IsValid:
266 return (indicator ? true : false);
267 return (indicator ? true : false);
267− case Priority:
268+ case IndicatorsModelRole::Priority:
268− case Title:
269+ case IndicatorsModelRole::Title:
269− case Description:
270+ case IndicatorsModelRole::Description:
270− case WidgetSource:
271+ case IndicatorsModelRole::WidgetSource:
271− case PageSource:
272+ case IndicatorsModelRole::PageSource:
272 return indicatorData(indicator, role);
273 return indicatorData(indicator, role);
273 default:
274 default:
274 break;
275 break;
modules/Unity/Indicators/indicatorsmodel.h−10
@@ -36,16 +36,6 @@ class IndicatorsModel : public QAbstractListModel
36 Q_PROPERTY(QVariant indicatorData READ indicatorData WRITE setIndicatorData NOTIFY indicatorDataChanged)
36 Q_PROPERTY(QVariant indicatorData READ indicatorData WRITE setIndicatorData NOTIFY indicatorDataChanged)
37
37
38public:
38public:
39− enum Roles {
40− Identifier = 0,
41− Priority,
42− Title,
43− Description,
44− WidgetSource,
45− PageSource,
46− IndicatorProperties,
47− IsValid
48− };
49
39
50 IndicatorsModel(QObject *parent=0);
40 IndicatorsModel(QObject *parent=0);
51 ~IndicatorsModel();
41 ~IndicatorsModel();
modules/Unity/Indicators/plugin.cpp+3
@@ -35,7 +35,10 @@ void IndicatorsPlugin::registerTypes(const char *uri)
35 qmlRegisterType<IndicatorsManager>(uri, 0, 1, "IndicatorsManager");
35 qmlRegisterType<IndicatorsManager>(uri, 0, 1, "IndicatorsManager");
36 qmlRegisterType<FlatMenuProxyModel>(uri, 0, 1, "FlatMenuProxyModel");
36 qmlRegisterType<FlatMenuProxyModel>(uri, 0, 1, "FlatMenuProxyModel");
37 qmlRegisterType<IndicatorsModel>(uri, 0, 1, "IndicatorsModel");
37 qmlRegisterType<IndicatorsModel>(uri, 0, 1, "IndicatorsModel");
38+
38 qmlRegisterUncreatableType<ActionState>(uri, 0, 1, "ActionState", "Can't create ActionState class");
39 qmlRegisterUncreatableType<ActionState>(uri, 0, 1, "ActionState", "Can't create ActionState class");
39 qmlRegisterUncreatableType<NetworkActionState>(uri, 0, 1, "NetworkActionState", "Can't create NetworkActionState class");
40 qmlRegisterUncreatableType<NetworkActionState>(uri, 0, 1, "NetworkActionState", "Can't create NetworkActionState class");
40 qmlRegisterUncreatableType<NetworkConnection>(uri, 0, 1, "NetworkConnection", "Can't create NetworkConnection class");
41 qmlRegisterUncreatableType<NetworkConnection>(uri, 0, 1, "NetworkConnection", "Can't create NetworkConnection class");
42+ qmlRegisterUncreatableType<IndicatorsModelRole>(uri, 0, 1, "IndicatorsModelRole", "Can't create IndicatorsModelRole class");
43+ qmlRegisterUncreatableType<FlatMenuProxyModelRole>(uri, 0, 1, "FlatMenuProxyModelRole", "Can't create FlatMenuProxyModelRole class");
41}
44}
modules/Unity/Indicators/qml/IndicatorWidget.qml+2−2
@@ -46,7 +46,7 @@ IndicatorBase {
46
46
47
47
48 function update_state() {
48 function update_state() {
49− var extra = proxyModel.data(0, Indicators.FlatMenuProxyModel.Extra);
49+ var extra = proxyModel.data(0, Indicators.FlatMenuProxyModelRole.Extra);
50 if (extra == undefined) {
50 if (extra == undefined) {
51 return;
51 return;
52 }
52 }
@@ -56,7 +56,7 @@ IndicatorBase {
56 }
56 }
57
57
58 if (parseRootElement(extra.canonical_type)) {
58 if (parseRootElement(extra.canonical_type)) {
59− action = actionGroup.action(proxyModel.data(0, Indicators.FlatMenuProxyModel.Action));
59+ action = actionGroup.action(proxyModel.data(0, Indicators.FlatMenuProxyModelRole.Action));
60 }
60 }
61 }
61 }
62
62
tests/modules/Unity/Indicators/indicatorsmodeltest.cpp+13−12
@@ -18,6 +18,7 @@
18 */
18 */
19
19
20#include "indicatorsmodel.h"
20#include "indicatorsmodel.h"
21+#include "indicators.h"
21#include "paths.h"
22#include "paths.h"
22
23
23#include <QtTest>
24#include <QtTest>
@@ -78,21 +79,21 @@ private Q_SLOTS:
78 model.setIndicatorData(map);
79 model.setIndicatorData(map);
79 model.load();
80 model.load();
80
81
81− QCOMPARE(model.data(0, IndicatorsModel::Identifier).toString(), QString("indicator-fake2"));
82+ QCOMPARE(model.data(0, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake2"));
82− QCOMPARE(model.data(0, IndicatorsModel::Title).toString(), QString("fake2"));
83+ QCOMPARE(model.data(0, IndicatorsModelRole::Title).toString(), QString("fake2"));
83− QCOMPARE(model.data(0, IndicatorsModel::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake2"));
84+ QCOMPARE(model.data(0, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake2"));
84
85
85− QCOMPARE(model.data(1, IndicatorsModel::Identifier).toString(), QString("indicator-fake1"));
86+ QCOMPARE(model.data(1, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake1"));
86− QCOMPARE(model.data(1, IndicatorsModel::Title).toString(), QString("fake1"));
87+ QCOMPARE(model.data(1, IndicatorsModelRole::Title).toString(), QString("fake1"));
87− QCOMPARE(model.data(1, IndicatorsModel::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake1"));
88+ QCOMPARE(model.data(1, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake1"));
88
89
89− QCOMPARE(model.data(2, IndicatorsModel::Identifier).toString(), QString("indicator-fake4"));
90+ QCOMPARE(model.data(2, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake4"));
90− QCOMPARE(model.data(2, IndicatorsModel::Title).toString(), QString("fake4"));
91+ QCOMPARE(model.data(2, IndicatorsModelRole::Title).toString(), QString("fake4"));
91− QCOMPARE(model.data(2, IndicatorsModel::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake4"));
92+ QCOMPARE(model.data(2, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake4"));
92
93
93− QCOMPARE(model.data(3, IndicatorsModel::Identifier).toString(), QString("indicator-fake3"));
94+ QCOMPARE(model.data(3, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake3"));
94− QCOMPARE(model.data(3, IndicatorsModel::Title).toString(), QString("fake3"));
95+ QCOMPARE(model.data(3, IndicatorsModelRole::Title).toString(), QString("fake3"));
95− QCOMPARE(model.data(3, IndicatorsModel::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake3"));
96+ QCOMPARE(model.data(3, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake3"));
96 }
97 }
97};
98};
98
99
tests/qmltests/modules/Unity/Indicators/CMakeLists.txt+3−1
@@ -6,10 +6,12 @@ find_package(Qt5Quick REQUIRED)
6include_directories(
6include_directories(
7 ${CMAKE_CURRENT_SOURCE_DIR}
7 ${CMAKE_CURRENT_SOURCE_DIR}
8 ${CMAKE_CURRENT_BINARY_DIR}
8 ${CMAKE_CURRENT_BINARY_DIR}
9+ ${CMAKE_SOURCE_DIR}/modules/Unity/Indicators
9)
10)
10
11
11set(IndicatorsFakeQml_SOURCES
12set(IndicatorsFakeQml_SOURCES
12− plugin.cpp
13+ fakeplugin.cpp
14+ ${CMAKE_SOURCE_DIR}/modules/Unity/Indicators/indicators.h
13)
15)
14
16
15set(IndicatorsFakeQml_RESOURCES
17set(IndicatorsFakeQml_RESOURCES
tests/qmltests/modules/Unity/Indicators/IndicatorsModel.qml+28
@@ -15,6 +15,7 @@
15 */
15 */
16
16
17import QtQuick 2.0
17import QtQuick 2.0
18+import Unity.Indicators 0.1 as Indicators
18
19
19ListModel {
20ListModel {
20
21
@@ -73,4 +74,31 @@ ListModel {
73 isValid: "";
74 isValid: "";
74 }
75 }
75
76
77+ function data(row, role) {
78+ if (role == Indicators.IndicatorsModelRole.Identifier) {
79+ return get(row).identifier;
80+ }
81+ else if (role == Indicators.IndicatorsModelRole.Priority) {
82+ return get(row).priority
83+ }
84+ else if (role == Indicators.IndicatorsModelRole.Title) {
85+ return get(row).title
86+ }
87+ else if (role == Indicators.IndicatorsModelRole.Description) {
88+ return get(row).description
89+ }
90+ else if (role == Indicators.IndicatorsModelRole.WidgetSource) {
91+ return get(row).widgetSource
92+ }
93+ else if (role == Indicators.IndicatorsModelRole.PageSource) {
94+ return get(row).pageSource
95+ }
96+ else if (role == Indicators.IndicatorsModelRole.IndicatorProperties) {
97+ return get(row).indicatorProperties
98+ }
99+ else if (role == Indicators.IndicatorsModelRole.IsValid) {
100+ return get(row).isValid
101+ }
102+ }
103+
76}
104}
tests/qmltests/modules/Unity/Indicators/plugin.cpp → tests/qmltests/modules/Unity/Indicators/fakeplugin.cpprenamed+9−2
@@ -20,11 +20,18 @@
20#include <QtQml>
20#include <QtQml>
21
21
22// self
22// self
23−#include "plugin.h"
23+#include "fakeplugin.h"
24
24
25// local
25// local
26+#include "indicators.h"
26
27
27−void IndicatorsFakePlugin::registerTypes(const char *)
28+void IndicatorsFakePlugin::registerTypes(const char * uri)
28{
29{
29 Q_INIT_RESOURCE(indicators_fake);
30 Q_INIT_RESOURCE(indicators_fake);
31+
32+ qmlRegisterUncreatableType<ActionState>(uri, 0, 1, "ActionState", "Can't create ActionState class");
33+ qmlRegisterUncreatableType<NetworkActionState>(uri, 0, 1, "NetworkActionState", "Can't create NetworkActionState class");
34+ qmlRegisterUncreatableType<NetworkConnection>(uri, 0, 1, "NetworkConnection", "Can't create NetworkConnection class");
35+ qmlRegisterUncreatableType<IndicatorsModelRole>(uri, 0, 1, "IndicatorsModelRole", "Can't create IndicatorsModelRole class");
36+ qmlRegisterUncreatableType<FlatMenuProxyModelRole>(uri, 0, 1, "FlatMenuProxyModelRole", "Can't create FlatMenuProxyModelRole class");
30}
37}
tests/qmltests/modules/Unity/Indicators/plugin.h → tests/qmltests/modules/Unity/Indicators/fakeplugin.hrenamed

The content is the same.