Merge lp:~nick-dedekind/unity8/indicators-client-textual-app into lp:unity8

Proposed by Nick Dedekind
Status: Merged
Approved by: Daniel d'Andrada
Approved revision: 101
Merged at revision: 149
Proposed branch: lp:~nick-dedekind/unity8/indicators-client-textual-app
Merge into: lp:unity8
Diff against target: 414 lines (+298/-25)
8 files modified
Panel/Indicators/client/IndicatorsClient.qml (+8/-9)
Panel/Indicators/client/IndicatorsPage.qml (+60/-15)
Panel/Indicators/client/IndicatorsTree.qml (+62/-0)
plugins/Unity/Indicators/CMakeLists.txt (+1/-0)
plugins/Unity/Indicators/modelprinter.cpp (+114/-0)
plugins/Unity/Indicators/modelprinter.h (+50/-0)
plugins/Unity/Indicators/plugin.cpp (+2/-0)
tests/autopilot/unity8/indicators_client/tests/test_battery.py (+1/-1)
To merge this branch: bzr merge lp:~nick-dedekind/unity8/indicators-client-textual-app
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Daniel d'Andrada (community) Approve
Michał Sawicz Needs Fixing
Review via email: mp+175143@code.launchpad.net

Commit message

Added a text tree representation of the qmenumodel to the indicators-client application.

Description of the change

Added a text tree representation of the qmenumodel to the indicators-client application.
Intended for debugging indicator issues.

The new functionality can be seen as a switch ('Enable Visual Representation') at the top of an indicator page in the indicators-client app.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) wrote :

plugins/Unity/Indicators/modelprinter.h: multiple new lines at end of file

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

> plugins/Unity/Indicators/modelprinter.h: multiple new lines at end of file

Removed.

Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

Added back button to the indicators page.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel d'Andrada (dandrader) wrote :

Some unsolved merge conflicts

200 +<<<<<<< TREE
201 menucontentactivator.cpp
202 +=======
203 + modelprinter.cpp
204 +>>>>>>> MERGE-SOURCE

369 +<<<<<<< TREE
370 #include "menucontentactivator.h"
371 +=======
372 +#include "modelprinter.h"
373 +>>>>>>> MERGE-SOURCE

381 +<<<<<<< TREE
382 qmlRegisterType<MenuContentActivator>(uri, 0, 1, "MenuContentActivator");
383 +=======
384 + qmlRegisterType<ModelPrinter>(uri, 0, 1, "ModelPrinter");
385 +>>>>>>> MERGE-SOURCE

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

> Some unsolved merge conflicts
>
> 200 +<<<<<<< TREE
> 201 menucontentactivator.cpp
> 202 +=======
> 203 + modelprinter.cpp
> 204 +>>>>>>> MERGE-SOURCE
>
> 369 +<<<<<<< TREE
> 370 #include "menucontentactivator.h"
> 371 +=======
> 372 +#include "modelprinter.h"
> 373 +>>>>>>> MERGE-SOURCE
>
> 381 +<<<<<<< TREE
> 382 qmlRegisterType<MenuContentActivator>(uri, 0, 1,
> "MenuContentActivator");
> 383 +=======
> 384 + qmlRegisterType<ModelPrinter>(uri, 0, 1, "ModelPrinter");
> 385 +>>>>>>> MERGE-SOURCE

Fixed.

Revision history for this message
Daniel d'Andrada (dandrader) wrote :

Panel/Indicators/client/IndicatorsPage.qml

Please add your name to the "Authors" list in the header

- property alias pageSource : page_loader.source
+ property string pageSource : page_loader.source

Let's take the opportunity to s/page_loader/pageLoader

-----

Panel/Indicators/client/IndicatorsTree.qml

+ * Nick Dedekind <<email address hidden>

Missing the closing ">"

+ Text {
+ id: all_data
+ color: "white"
+ }

s/all_data/allData

+ Indicators.ModelPrinter {
+ id: printer
+ model: menuModel
+
+ onSourceChanged: page.refresh()
+ }

+ function refresh() {
+ all_data.text = printer.getString();
+ }

Couldn't we make it more QMLish by making the string a property of ModelPrinter (and name it "text")?
So code would be simply:

   Text {
      id: allData
      color: "white"
      text: printer.text
   }

----------------

plugins/Unity/Indicators/modelprinter.cpp

+ * Copyright (C) 2012 Canonical, Ltd.

s/2012/2013

+ QString recurse_string(const QModelIndex& index, int level) const;

s/recurse_string/recurseString

+// Qt
+#include <QDebug>

s/QDebug/QTextStream

+ stream << tabify(level) << roleNames[role] << "." << iter.key() << ": " << iter.value().toString() << endl;

Too long

-------------------

plugins/Unity/Indicators/modelprinter.h

+ * Copyright (C) 2012 Canonical, Ltd.

s/2012/2013

review: Needs Fixing
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

> Panel/Indicators/client/IndicatorsPage.qml
>
> Please add your name to the "Authors" list in the header
>
> - property alias pageSource : page_loader.source
> + property string pageSource : page_loader.source
>
> Let's take the opportunity to s/page_loader/pageLoader
>
> -----
>
> Panel/Indicators/client/IndicatorsTree.qml
>
> + * Nick Dedekind <<email address hidden>
>
> Missing the closing ">"
>
> + Text {
> + id: all_data
> + color: "white"
> + }
>
>
> s/all_data/allData
>
>
> + Indicators.ModelPrinter {
> + id: printer
> + model: menuModel
> +
> + onSourceChanged: page.refresh()
> + }
>
> + function refresh() {
> + all_data.text = printer.getString();
> + }
>
>
> Couldn't we make it more QMLish by making the string a property of
> ModelPrinter (and name it "text")?
> So code would be simply:
>
> Text {
> id: allData
> color: "white"
> text: printer.text
> }
>
> ----------------
>
> plugins/Unity/Indicators/modelprinter.cpp
>
> + * Copyright (C) 2012 Canonical, Ltd.
>
> s/2012/2013
>
> + QString recurse_string(const QModelIndex& index, int level) const;
>
> s/recurse_string/recurseString
>
> +// Qt
> +#include <QDebug>
>
> s/QDebug/QTextStream
>
> + stream << tabify(level) << roleNames[role] << "." <<
> iter.key() << ": " << iter.value().toString() << endl;
>
> Too long
>
> -------------------
>
> plugins/Unity/Indicators/modelprinter.h
>
> + * Copyright (C) 2012 Canonical, Ltd.
>
> s/2012/2013

Thanks. All done.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Daniel d'Andrada (dandrader) wrote :

There's still this one:

Panel/Indicators/client/IndicatorsTree.qml

+ Text {
+ id: all_data
+ color: "white"
+ text: printer.txt
+ }

s/all_data/allData

But since I'll be away for a month, it's not worth holding it up.

Looks good to go.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Panel/Indicators/client/IndicatorsClient.qml'
2--- Panel/Indicators/client/IndicatorsClient.qml 2013-06-18 18:02:29 +0000
3+++ Panel/Indicators/client/IndicatorsClient.qml 2013-07-31 14:12:23 +0000
4@@ -27,16 +27,15 @@
5
6 PageStack {
7 id: pages
8-
9 anchors.fill: parent
10- Component.onCompleted: root.reset()
11- }
12+ Component.onCompleted: reset()
13
14- function reset() {
15- pages.clear();
16- var component = Qt.createComponent("IndicatorsList.qml");
17- var page = component.createObject(pages);
18- console.log(component.errorString());
19- pages.push(page);
20+ function reset() {
21+ clear();
22+ var component = Qt.createComponent("IndicatorsList.qml");
23+ var page = component.createObject(pages);
24+ console.log(component.errorString());
25+ push(page);
26+ }
27 }
28 }
29
30=== modified file 'Panel/Indicators/client/IndicatorsPage.qml'
31--- Panel/Indicators/client/IndicatorsPage.qml 2013-06-18 18:02:29 +0000
32+++ Panel/Indicators/client/IndicatorsPage.qml 2013-07-31 14:12:23 +0000
33@@ -15,35 +15,80 @@
34 *
35 * Authors:
36 * Renato Araujo Oliveira Filho <renato@canonical.com>
37+ * Nick Dedekind <nick.dedekind@canonical.com>
38 */
39
40 import QtQuick 2.0
41 import Ubuntu.Components 0.1
42+import Ubuntu.Components.ListItems 0.1 as ListItem
43
44 Page {
45- id: _page
46+ id: page
47
48 title: indicatorProperties && indicatorProperties.title ? indicatorProperties.title : ""
49 property variant indicatorProperties
50- property alias pageSource : page_loader.source
51+ property string pageSource : pageLoader.source
52
53 anchors.fill: parent
54
55+ ListItem.Standard {
56+ id: visualCheckItem
57+ text: "Enable Visual Representation"
58+ control: Switch {
59+ id: visualCheck
60+ checked: true
61+ }
62+ }
63+
64 Loader {
65- id: page_loader
66- objectName: "page_loader"
67-
68- anchors.fill: parent
69-
70- onStatusChanged: {
71- if (status == Loader.Ready) {
72- for(var pName in indicatorProperties) {
73- if (item.hasOwnProperty(pName)) {
74- item[pName] = indicatorProperties[pName];
75- }
76+ id: pageLoader
77+ objectName: "pageLoader"
78+
79+ anchors {
80+ top: visualCheckItem.bottom
81+ left: parent.left
82+ right: parent.right
83+ bottom: buttons.top
84+ topMargin: units.gu(2)
85+ bottomMargin: units.gu(2)
86+ }
87+ source : visualCheck.checked ? page.pageSource : "IndicatorsTree.qml"
88+
89+ onLoaded: {
90+ for(var pName in indicatorProperties) {
91+ if (item.hasOwnProperty(pName)) {
92+ item[pName] = indicatorProperties[pName];
93 }
94- item.start();
95- }
96+ }
97+ item.start();
98+ }
99+ }
100+
101+ Item {
102+ id: buttons
103+ anchors {
104+ left: parent.left
105+ right: parent.right
106+ bottom: parent.bottom
107+ margins: units.gu(1)
108+ }
109+ height: childrenRect.height
110+
111+ Button {
112+ anchors {
113+ left: parent.left
114+ }
115+ text: "Back"
116+ onClicked: page.pageStack.reset()
117+ }
118+ Button {
119+ id: refresh
120+ visible: !visualCheck.checked
121+ anchors {
122+ right: parent.right
123+ }
124+ text: "Refresh"
125+ onClicked: pageLoader.item.refresh()
126 }
127 }
128 }
129
130=== added file 'Panel/Indicators/client/IndicatorsTree.qml'
131--- Panel/Indicators/client/IndicatorsTree.qml 1970-01-01 00:00:00 +0000
132+++ Panel/Indicators/client/IndicatorsTree.qml 2013-07-31 14:12:23 +0000
133@@ -0,0 +1,62 @@
134+/*
135+ * Copyright 2013 Canonical Ltd.
136+ *
137+ * This program is free software; you can redistribute it and/or modify
138+ * it under the terms of the GNU Lesser General Public License as published by
139+ * the Free Software Foundation; version 3.
140+ *
141+ * This program is distributed in the hope that it will be useful,
142+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
143+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
144+ * GNU Lesser General Public License for more details.
145+ *
146+ * You should have received a copy of the GNU Lesser General Public License
147+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
148+ *
149+ * Authors:
150+ * Nick Dedekind <nick.dededkind@canonical.com>
151+ */
152+
153+import QtQuick 2.0
154+import Ubuntu.Components 0.1
155+import Unity.Indicators 0.1 as Indicators
156+import QMenuModel 0.1
157+import Ubuntu.Components.ListItems 0.1 as ListItem
158+
159+Page {
160+ id: page
161+ anchors.fill: parent
162+
163+ property alias busType: menuModel.busType
164+ property alias busName: menuModel.busName
165+ property string actionsObjectPath
166+ property var menuObjectPaths: undefined
167+ readonly property string device: "phone"
168+
169+ property string deviceMenuObjectPath: menuObjectPaths.hasOwnProperty(device) ? menuObjectPaths[device] : ""
170+
171+ function start() {
172+ menuModel.start();
173+ }
174+
175+ QDBusMenuModel {
176+ id: menuModel
177+ objectPath: page.deviceMenuObjectPath
178+ }
179+
180+ Indicators.ModelPrinter {
181+ id: printer
182+ model: menuModel
183+ }
184+
185+ Flickable {
186+ anchors.fill: parent
187+ contentHeight: all_data.height
188+ clip:true
189+ Text {
190+ id: all_data
191+ color: "white"
192+ text: printer.text
193+ }
194+ }
195+}
196
197=== modified file 'plugins/Unity/Indicators/CMakeLists.txt'
198--- plugins/Unity/Indicators/CMakeLists.txt 2013-07-17 09:11:03 +0000
199+++ plugins/Unity/Indicators/CMakeLists.txt 2013-07-31 14:12:23 +0000
200@@ -24,6 +24,7 @@
201 indicatorsmanager.cpp
202 indicatorsmodel.cpp
203 menucontentactivator.cpp
204+ modelprinter.cpp
205 plugin.cpp
206 )
207 add_definitions(-DUNITYINDICATORS_LIBRARY)
208
209=== added file 'plugins/Unity/Indicators/modelprinter.cpp'
210--- plugins/Unity/Indicators/modelprinter.cpp 1970-01-01 00:00:00 +0000
211+++ plugins/Unity/Indicators/modelprinter.cpp 2013-07-31 14:12:23 +0000
212@@ -0,0 +1,114 @@
213+/*
214+ * Copyright 2013 Canonical Ltd.
215+ *
216+ * This program is free software; you can redistribute it and/or modify
217+ * it under the terms of the GNU Lesser General Public License as published by
218+ * the Free Software Foundation; version 3.
219+ *
220+ * This program is distributed in the hope that it will be useful,
221+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
222+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
223+ * GNU Lesser General Public License for more details.
224+ *
225+ * You should have received a copy of the GNU Lesser General Public License
226+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
227+ *
228+ * Authors:
229+ * Nick Dedekind <nick.dedekind@canonical.com>
230+ */
231+
232+// self
233+#include "modelprinter.h"
234+
235+// Qt
236+#include <QTextStream>
237+
238+ModelPrinter::ModelPrinter(QObject *parent)
239+ : QObject(parent)
240+ , m_model(NULL)
241+{
242+}
243+
244+void ModelPrinter::setSourceModel(QAbstractItemModel * sourceModel)
245+{
246+ if (m_model != NULL) {
247+ disconnect(m_model);
248+ }
249+ if (m_model != sourceModel) {
250+ m_model = sourceModel;
251+ Q_EMIT modelChanged();
252+ Q_EMIT textChanged();
253+ }
254+ if (m_model != NULL) {
255+ connect(m_model, SIGNAL(modelReset()), this, SIGNAL(textChanged()));
256+ connect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SIGNAL(textChanged()));
257+ connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SIGNAL(textChanged()));
258+ }
259+}
260+
261+QAbstractItemModel* ModelPrinter::sourceModel() const
262+{
263+ return m_model;
264+}
265+
266+QString ModelPrinter::text(const QModelIndex& index) const
267+{
268+ return recurseString(index, 0);
269+}
270+
271+QString tabify(int level) { QString str;
272+ for (int i = 0; i < level; i++) {
273+ str += " ";
274+ }
275+ return str;
276+}
277+
278+QString ModelPrinter::recurseString(const QModelIndex& index, int level) const
279+{
280+ if (!m_model)
281+ return "";
282+
283+ QString str;
284+ QTextStream stream(&str);
285+
286+ QHash<int, QByteArray> roleNames = m_model->roleNames();
287+ QList<int> roles = roleNames.keys();
288+ qSort(roles);
289+ Q_FOREACH(int role, roles) {
290+ QVariant vData = m_model->data(index, role);
291+ if (vData.canConvert(QMetaType::QVariantMap)) {
292+ QMapIterator<QString, QVariant> iter(vData.toMap());
293+ while (iter.hasNext()) {
294+ iter.next();
295+ stream << tabify(level)
296+ << roleNames[role]
297+ << "."
298+ << iter.key()
299+ << ": "
300+ << iter.value().toString()
301+ << endl;
302+ }
303+ }
304+ else {
305+ stream << tabify(level)
306+ << roleNames[role]
307+ << ": "
308+ << vData.toString()
309+ << endl;
310+ }
311+ }
312+
313+ int rowCount = m_model->rowCount(index);
314+ stream << tabify(level)
315+ << "child count"
316+ << ": "
317+ << rowCount
318+ << endl
319+ << endl;
320+
321+ for (int i = 0; i < rowCount; i++) {
322+ QModelIndex child = m_model->index(i, 0, index);
323+ str += recurseString(child, level+1);
324+ }
325+ return str;
326+}
327
328=== added file 'plugins/Unity/Indicators/modelprinter.h'
329--- plugins/Unity/Indicators/modelprinter.h 1970-01-01 00:00:00 +0000
330+++ plugins/Unity/Indicators/modelprinter.h 2013-07-31 14:12:23 +0000
331@@ -0,0 +1,50 @@
332+/*
333+ * Copyright 2013 Canonical Ltd.
334+ *
335+ * This program is free software; you can redistribute it and/or modify
336+ * it under the terms of the GNU Lesser General Public License as published by
337+ * the Free Software Foundation; version 3.
338+ *
339+ * This program is distributed in the hope that it will be useful,
340+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
341+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
342+ * GNU Lesser General Public License for more details.
343+ *
344+ * You should have received a copy of the GNU Lesser General Public License
345+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
346+ *
347+ * Authors:
348+ * Nick Dedekind <nick.dedekind@canonical.com>
349+ */
350+
351+#ifndef MODELPRINTER_H
352+#define MODELPRINTER_H
353+
354+#include <QSortFilterProxyModel>
355+
356+// This class acts as a namespace only, with the addition that its enums
357+// are registered to be exposed on the QML side.
358+class ModelPrinter : public QObject
359+{
360+ Q_OBJECT
361+
362+ Q_PROPERTY(QAbstractItemModel* model READ sourceModel WRITE setSourceModel NOTIFY modelChanged)
363+ Q_PROPERTY(QString text READ text NOTIFY textChanged)
364+public:
365+ ModelPrinter(QObject* parent=0);
366+
367+ void setSourceModel(QAbstractItemModel* sourceModel);
368+ QAbstractItemModel* sourceModel() const;
369+
370+ Q_INVOKABLE QString text(const QModelIndex& index = QModelIndex()) const;
371+
372+Q_SIGNALS:
373+ void modelChanged();
374+ void textChanged();
375+
376+private:
377+ QString recurseString(const QModelIndex& index, int level) const;
378+ QAbstractItemModel* m_model;
379+};
380+
381+#endif // MODELPRINTER_H
382
383=== modified file 'plugins/Unity/Indicators/plugin.cpp'
384--- plugins/Unity/Indicators/plugin.cpp 2013-07-17 09:11:03 +0000
385+++ plugins/Unity/Indicators/plugin.cpp 2013-07-31 14:12:23 +0000
386@@ -28,6 +28,7 @@
387 #include "indicatorsmodel.h"
388 #include "indicators.h"
389 #include "menucontentactivator.h"
390+#include "modelprinter.h"
391
392 void IndicatorsPlugin::registerTypes(const char *uri)
393 {
394@@ -36,6 +37,7 @@
395 qmlRegisterType<IndicatorsManager>(uri, 0, 1, "IndicatorsManager");
396 qmlRegisterType<FlatMenuProxyModel>(uri, 0, 1, "FlatMenuProxyModel");
397 qmlRegisterType<IndicatorsModel>(uri, 0, 1, "IndicatorsModel");
398+ qmlRegisterType<ModelPrinter>(uri, 0, 1, "ModelPrinter");
399 qmlRegisterType<MenuContentActivator>(uri, 0, 1, "MenuContentActivator");
400
401 qmlRegisterUncreatableType<MenuContentState>(uri, 0, 1, "MenuContentState", "Can't create MenuContentState class");
402
403=== modified file 'tests/autopilot/unity8/indicators_client/tests/test_battery.py'
404--- tests/autopilot/unity8/indicators_client/tests/test_battery.py 2013-07-24 13:56:28 +0000
405+++ tests/autopilot/unity8/indicators_client/tests/test_battery.py 2013-07-31 14:12:23 +0000
406@@ -26,7 +26,7 @@
407 self.pointing_device.move_to_object(self.main_window.get_battery_menu())
408 self.pointing_device.click()
409
410- fn_loader = lambda: self.app.select_single("IndicatorsPage/QQuickLoader", objectName="page_loader");
411+ fn_loader = lambda: self.app.select_single("IndicatorsPage/QQuickLoader", objectName="pageLoader");
412 self.assertThat(fn_loader, Eventually(NotEquals(None)));
413 page_loader = fn_loader();
414 self.assertThat(page_loader.progress, Eventually(Equals(1.0)))

Subscribers

People subscribed via source and target branches