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
=== modified file 'Panel/Indicators/client/IndicatorsClient.qml'
--- Panel/Indicators/client/IndicatorsClient.qml 2013-06-18 18:02:29 +0000
+++ Panel/Indicators/client/IndicatorsClient.qml 2013-07-31 14:12:23 +0000
@@ -27,16 +27,15 @@
2727
28 PageStack {28 PageStack {
29 id: pages29 id: pages
30
31 anchors.fill: parent30 anchors.fill: parent
32 Component.onCompleted: root.reset()31 Component.onCompleted: reset()
33 }
3432
35 function reset() {33 function reset() {
36 pages.clear();34 clear();
37 var component = Qt.createComponent("IndicatorsList.qml");35 var component = Qt.createComponent("IndicatorsList.qml");
38 var page = component.createObject(pages);36 var page = component.createObject(pages);
39 console.log(component.errorString());37 console.log(component.errorString());
40 pages.push(page);38 push(page);
39 }
41 }40 }
42}41}
4342
=== modified file 'Panel/Indicators/client/IndicatorsPage.qml'
--- Panel/Indicators/client/IndicatorsPage.qml 2013-06-18 18:02:29 +0000
+++ Panel/Indicators/client/IndicatorsPage.qml 2013-07-31 14:12:23 +0000
@@ -15,35 +15,80 @@
15 *15 *
16 * Authors:16 * Authors:
17 * Renato Araujo Oliveira Filho <renato@canonical.com>17 * Renato Araujo Oliveira Filho <renato@canonical.com>
18 * Nick Dedekind <nick.dedekind@canonical.com>
18 */19 */
1920
20import QtQuick 2.021import QtQuick 2.0
21import Ubuntu.Components 0.122import Ubuntu.Components 0.1
23import Ubuntu.Components.ListItems 0.1 as ListItem
2224
23Page {25Page {
24 id: _page26 id: page
2527
26 title: indicatorProperties && indicatorProperties.title ? indicatorProperties.title : ""28 title: indicatorProperties && indicatorProperties.title ? indicatorProperties.title : ""
27 property variant indicatorProperties29 property variant indicatorProperties
28 property alias pageSource : page_loader.source30 property string pageSource : pageLoader.source
2931
30 anchors.fill: parent32 anchors.fill: parent
3133
34 ListItem.Standard {
35 id: visualCheckItem
36 text: "Enable Visual Representation"
37 control: Switch {
38 id: visualCheck
39 checked: true
40 }
41 }
42
32 Loader {43 Loader {
33 id: page_loader44 id: pageLoader
34 objectName: "page_loader"45 objectName: "pageLoader"
3546
36 anchors.fill: parent47 anchors {
3748 top: visualCheckItem.bottom
38 onStatusChanged: {49 left: parent.left
39 if (status == Loader.Ready) {50 right: parent.right
40 for(var pName in indicatorProperties) {51 bottom: buttons.top
41 if (item.hasOwnProperty(pName)) {52 topMargin: units.gu(2)
42 item[pName] = indicatorProperties[pName];53 bottomMargin: units.gu(2)
43 }54 }
55 source : visualCheck.checked ? page.pageSource : "IndicatorsTree.qml"
56
57 onLoaded: {
58 for(var pName in indicatorProperties) {
59 if (item.hasOwnProperty(pName)) {
60 item[pName] = indicatorProperties[pName];
44 }61 }
45 item.start();62 }
46 }63 item.start();
64 }
65 }
66
67 Item {
68 id: buttons
69 anchors {
70 left: parent.left
71 right: parent.right
72 bottom: parent.bottom
73 margins: units.gu(1)
74 }
75 height: childrenRect.height
76
77 Button {
78 anchors {
79 left: parent.left
80 }
81 text: "Back"
82 onClicked: page.pageStack.reset()
83 }
84 Button {
85 id: refresh
86 visible: !visualCheck.checked
87 anchors {
88 right: parent.right
89 }
90 text: "Refresh"
91 onClicked: pageLoader.item.refresh()
47 }92 }
48 }93 }
49}94}
5095
=== added file 'Panel/Indicators/client/IndicatorsTree.qml'
--- Panel/Indicators/client/IndicatorsTree.qml 1970-01-01 00:00:00 +0000
+++ Panel/Indicators/client/IndicatorsTree.qml 2013-07-31 14:12:23 +0000
@@ -0,0 +1,62 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Nick Dedekind <nick.dededkind@canonical.com>
18 */
19
20import QtQuick 2.0
21import Ubuntu.Components 0.1
22import Unity.Indicators 0.1 as Indicators
23import QMenuModel 0.1
24import Ubuntu.Components.ListItems 0.1 as ListItem
25
26Page {
27 id: page
28 anchors.fill: parent
29
30 property alias busType: menuModel.busType
31 property alias busName: menuModel.busName
32 property string actionsObjectPath
33 property var menuObjectPaths: undefined
34 readonly property string device: "phone"
35
36 property string deviceMenuObjectPath: menuObjectPaths.hasOwnProperty(device) ? menuObjectPaths[device] : ""
37
38 function start() {
39 menuModel.start();
40 }
41
42 QDBusMenuModel {
43 id: menuModel
44 objectPath: page.deviceMenuObjectPath
45 }
46
47 Indicators.ModelPrinter {
48 id: printer
49 model: menuModel
50 }
51
52 Flickable {
53 anchors.fill: parent
54 contentHeight: all_data.height
55 clip:true
56 Text {
57 id: all_data
58 color: "white"
59 text: printer.text
60 }
61 }
62}
063
=== modified file 'plugins/Unity/Indicators/CMakeLists.txt'
--- plugins/Unity/Indicators/CMakeLists.txt 2013-07-17 09:11:03 +0000
+++ plugins/Unity/Indicators/CMakeLists.txt 2013-07-31 14:12:23 +0000
@@ -24,6 +24,7 @@
24 indicatorsmanager.cpp24 indicatorsmanager.cpp
25 indicatorsmodel.cpp25 indicatorsmodel.cpp
26 menucontentactivator.cpp26 menucontentactivator.cpp
27 modelprinter.cpp
27 plugin.cpp28 plugin.cpp
28)29)
29add_definitions(-DUNITYINDICATORS_LIBRARY)30add_definitions(-DUNITYINDICATORS_LIBRARY)
3031
=== added file 'plugins/Unity/Indicators/modelprinter.cpp'
--- plugins/Unity/Indicators/modelprinter.cpp 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Indicators/modelprinter.cpp 2013-07-31 14:12:23 +0000
@@ -0,0 +1,114 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Nick Dedekind <nick.dedekind@canonical.com>
18 */
19
20// self
21#include "modelprinter.h"
22
23// Qt
24#include <QTextStream>
25
26ModelPrinter::ModelPrinter(QObject *parent)
27 : QObject(parent)
28 , m_model(NULL)
29{
30}
31
32void ModelPrinter::setSourceModel(QAbstractItemModel * sourceModel)
33{
34 if (m_model != NULL) {
35 disconnect(m_model);
36 }
37 if (m_model != sourceModel) {
38 m_model = sourceModel;
39 Q_EMIT modelChanged();
40 Q_EMIT textChanged();
41 }
42 if (m_model != NULL) {
43 connect(m_model, SIGNAL(modelReset()), this, SIGNAL(textChanged()));
44 connect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SIGNAL(textChanged()));
45 connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SIGNAL(textChanged()));
46 }
47}
48
49QAbstractItemModel* ModelPrinter::sourceModel() const
50{
51 return m_model;
52}
53
54QString ModelPrinter::text(const QModelIndex& index) const
55{
56 return recurseString(index, 0);
57}
58
59QString tabify(int level) { QString str;
60 for (int i = 0; i < level; i++) {
61 str += " ";
62 }
63 return str;
64}
65
66QString ModelPrinter::recurseString(const QModelIndex& index, int level) const
67{
68 if (!m_model)
69 return "";
70
71 QString str;
72 QTextStream stream(&str);
73
74 QHash<int, QByteArray> roleNames = m_model->roleNames();
75 QList<int> roles = roleNames.keys();
76 qSort(roles);
77 Q_FOREACH(int role, roles) {
78 QVariant vData = m_model->data(index, role);
79 if (vData.canConvert(QMetaType::QVariantMap)) {
80 QMapIterator<QString, QVariant> iter(vData.toMap());
81 while (iter.hasNext()) {
82 iter.next();
83 stream << tabify(level)
84 << roleNames[role]
85 << "."
86 << iter.key()
87 << ": "
88 << iter.value().toString()
89 << endl;
90 }
91 }
92 else {
93 stream << tabify(level)
94 << roleNames[role]
95 << ": "
96 << vData.toString()
97 << endl;
98 }
99 }
100
101 int rowCount = m_model->rowCount(index);
102 stream << tabify(level)
103 << "child count"
104 << ": "
105 << rowCount
106 << endl
107 << endl;
108
109 for (int i = 0; i < rowCount; i++) {
110 QModelIndex child = m_model->index(i, 0, index);
111 str += recurseString(child, level+1);
112 }
113 return str;
114}
0115
=== added file 'plugins/Unity/Indicators/modelprinter.h'
--- plugins/Unity/Indicators/modelprinter.h 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Indicators/modelprinter.h 2013-07-31 14:12:23 +0000
@@ -0,0 +1,50 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Nick Dedekind <nick.dedekind@canonical.com>
18 */
19
20#ifndef MODELPRINTER_H
21#define MODELPRINTER_H
22
23#include <QSortFilterProxyModel>
24
25// This class acts as a namespace only, with the addition that its enums
26// are registered to be exposed on the QML side.
27class ModelPrinter : public QObject
28{
29 Q_OBJECT
30
31 Q_PROPERTY(QAbstractItemModel* model READ sourceModel WRITE setSourceModel NOTIFY modelChanged)
32 Q_PROPERTY(QString text READ text NOTIFY textChanged)
33public:
34 ModelPrinter(QObject* parent=0);
35
36 void setSourceModel(QAbstractItemModel* sourceModel);
37 QAbstractItemModel* sourceModel() const;
38
39 Q_INVOKABLE QString text(const QModelIndex& index = QModelIndex()) const;
40
41Q_SIGNALS:
42 void modelChanged();
43 void textChanged();
44
45private:
46 QString recurseString(const QModelIndex& index, int level) const;
47 QAbstractItemModel* m_model;
48};
49
50#endif // MODELPRINTER_H
051
=== modified file 'plugins/Unity/Indicators/plugin.cpp'
--- plugins/Unity/Indicators/plugin.cpp 2013-07-17 09:11:03 +0000
+++ plugins/Unity/Indicators/plugin.cpp 2013-07-31 14:12:23 +0000
@@ -28,6 +28,7 @@
28#include "indicatorsmodel.h"28#include "indicatorsmodel.h"
29#include "indicators.h"29#include "indicators.h"
30#include "menucontentactivator.h"30#include "menucontentactivator.h"
31#include "modelprinter.h"
3132
32void IndicatorsPlugin::registerTypes(const char *uri)33void IndicatorsPlugin::registerTypes(const char *uri)
33{34{
@@ -36,6 +37,7 @@
36 qmlRegisterType<IndicatorsManager>(uri, 0, 1, "IndicatorsManager");37 qmlRegisterType<IndicatorsManager>(uri, 0, 1, "IndicatorsManager");
37 qmlRegisterType<FlatMenuProxyModel>(uri, 0, 1, "FlatMenuProxyModel");38 qmlRegisterType<FlatMenuProxyModel>(uri, 0, 1, "FlatMenuProxyModel");
38 qmlRegisterType<IndicatorsModel>(uri, 0, 1, "IndicatorsModel");39 qmlRegisterType<IndicatorsModel>(uri, 0, 1, "IndicatorsModel");
40 qmlRegisterType<ModelPrinter>(uri, 0, 1, "ModelPrinter");
39 qmlRegisterType<MenuContentActivator>(uri, 0, 1, "MenuContentActivator");41 qmlRegisterType<MenuContentActivator>(uri, 0, 1, "MenuContentActivator");
4042
41 qmlRegisterUncreatableType<MenuContentState>(uri, 0, 1, "MenuContentState", "Can't create MenuContentState class");43 qmlRegisterUncreatableType<MenuContentState>(uri, 0, 1, "MenuContentState", "Can't create MenuContentState class");
4244
=== modified file 'tests/autopilot/unity8/indicators_client/tests/test_battery.py'
--- tests/autopilot/unity8/indicators_client/tests/test_battery.py 2013-07-24 13:56:28 +0000
+++ tests/autopilot/unity8/indicators_client/tests/test_battery.py 2013-07-31 14:12:23 +0000
@@ -26,7 +26,7 @@
26 self.pointing_device.move_to_object(self.main_window.get_battery_menu())26 self.pointing_device.move_to_object(self.main_window.get_battery_menu())
27 self.pointing_device.click()27 self.pointing_device.click()
2828
29 fn_loader = lambda: self.app.select_single("IndicatorsPage/QQuickLoader", objectName="page_loader");29 fn_loader = lambda: self.app.select_single("IndicatorsPage/QQuickLoader", objectName="pageLoader");
30 self.assertThat(fn_loader, Eventually(NotEquals(None)));30 self.assertThat(fn_loader, Eventually(NotEquals(None)));
31 page_loader = fn_loader();31 page_loader = fn_loader();
32 self.assertThat(page_loader.progress, Eventually(Equals(1.0)))32 self.assertThat(page_loader.progress, Eventually(Equals(1.0)))

Subscribers

People subscribed via source and target branches