on xenial help sign in
review comments
ea0f6a5Nick Dedekind
Panel/Indicators/client/IndicatorsPage.qml+5−4
@@ -15,6 +15,7 @@
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 */
19
20
20import QtQuick 2.0
21import QtQuick 2.0
@@ -26,7 +27,7 @@ Page {
26
27
27 title: indicatorProperties && indicatorProperties.title ? indicatorProperties.title : ""
28 title: indicatorProperties && indicatorProperties.title ? indicatorProperties.title : ""
28 property variant indicatorProperties
29 property variant indicatorProperties
29− property string pageSource : page_loader.source
30+ property string pageSource : pageLoader.source
30
31
31 anchors.fill: parent
32 anchors.fill: parent
32
33
@@ -40,8 +41,8 @@ Page {
40 }
41 }
41
42
42 Loader {
43 Loader {
43− id: page_loader
44+ id: pageLoader
44− objectName: "page_loader"
45+ objectName: "pageLoader"
45
46
46 anchors {
47 anchors {
47 top: visualCheckItem.bottom
48 top: visualCheckItem.bottom
@@ -87,7 +88,7 @@ Page {
87 right: parent.right
88 right: parent.right
88 }
89 }
89 text: "Refresh"
90 text: "Refresh"
90− onClicked: page_loader.item.refresh()
91+ onClicked: pageLoader.item.refresh()
91 }
92 }
92 }
93 }
93}
94}
Panel/Indicators/client/IndicatorsTree.qml+2−7
@@ -14,7 +14,7 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
15 *
16 * Authors:
16 * Authors:
17− * Nick Dedekind <nick.dededkind@canonical.com
17+ * Nick Dedekind <nick.dededkind@canonical.com>
18 */
18 */
19
19
20import QtQuick 2.0
20import QtQuick 2.0
@@ -39,10 +39,6 @@ Page {
39 menuModel.start();
39 menuModel.start();
40 }
40 }
41
41
42− function refresh() {
43− all_data.text = printer.getString();
44− }
45−
46 QDBusMenuModel {
42 QDBusMenuModel {
47 id: menuModel
43 id: menuModel
48 objectPath: page.deviceMenuObjectPath
44 objectPath: page.deviceMenuObjectPath
@@ -51,8 +47,6 @@ Page {
51 Indicators.ModelPrinter {
47 Indicators.ModelPrinter {
52 id: printer
48 id: printer
53 model: menuModel
49 model: menuModel
54−
55− onSourceChanged: page.refresh()
56 }
50 }
57
51
58 Flickable {
52 Flickable {
@@ -62,6 +56,7 @@ Page {
62 Text {
56 Text {
63 id: all_data
57 id: all_data
64 color: "white"
58 color: "white"
59+ text: printer.text
65 }
60 }
66 }
61 }
67}
62}
plugins/Unity/Indicators/modelprinter.cpp+38−19
@@ -1,24 +1,27 @@
1/*
1/*
2− * Copyright (C) 2012 Canonical, Ltd.
2+ * Copyright 2013 Canonical Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
5+ * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
6 * the Free Software Foundation; version 3.
7 *
7 *
8 * This program is distributed in the hope that it will be useful,
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
11+ * GNU Lesser General Public License for more details.
12 *
12 *
13− * You should have received a copy of the GNU General Public License
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/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors:
17+ * Nick Dedekind <nick.dedekind@canonical.com>
15 */
18 */
16
19
17// self
20// self
18#include "modelprinter.h"
21#include "modelprinter.h"
19
22
20// Qt
23// Qt
21−#include <QDebug>
24+#include <QTextStream>
22
25
23ModelPrinter::ModelPrinter(QObject *parent)
26ModelPrinter::ModelPrinter(QObject *parent)
24 : QObject(parent)
27 : QObject(parent)
@@ -29,19 +32,17 @@ ModelPrinter::ModelPrinter(QObject *parent)
29void ModelPrinter::setSourceModel(QAbstractItemModel * sourceModel)
32void ModelPrinter::setSourceModel(QAbstractItemModel * sourceModel)
30{
33{
31 if (m_model != NULL) {
34 if (m_model != NULL) {
32− disconnect(m_model, SIGNAL(modelReset()), this, SIGNAL(sourceChanged()));
35+ disconnect(m_model);
33− disconnect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SIGNAL(sourceChanged()));
34− disconnect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SIGNAL(sourceChanged()));
35 }
36 }
36 if (m_model != sourceModel) {
37 if (m_model != sourceModel) {
37 m_model = sourceModel;
38 m_model = sourceModel;
38 Q_EMIT modelChanged();
39 Q_EMIT modelChanged();
39− Q_EMIT sourceChanged();
40+ Q_EMIT textChanged();
40 }
41 }
41 if (m_model != NULL) {
42 if (m_model != NULL) {
42− connect(m_model, SIGNAL(modelReset()), this, SIGNAL(sourceChanged()));
43+ connect(m_model, SIGNAL(modelReset()), this, SIGNAL(textChanged()));
43− connect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SIGNAL(sourceChanged()));
44+ connect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SIGNAL(textChanged()));
44− connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SIGNAL(sourceChanged()));
45+ connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SIGNAL(textChanged()));
45 }
46 }
46}
47}
47
48
@@ -50,9 +51,9 @@ QAbstractItemModel* ModelPrinter::sourceModel() const
50 return m_model;
51 return m_model;
51}
52}
52
53
53−QString ModelPrinter::getString(const QModelIndex& index) const
54+QString ModelPrinter::text(const QModelIndex& index) const
54{
55{
55− return recurse_string(index, 0);
56+ return recurseString(index, 0);
56}
57}
57
58
58QString tabify(int level) { QString str;
59QString tabify(int level) { QString str;
@@ -62,8 +63,11 @@ QString tabify(int level) { QString str;
62 return str;
63 return str;
63}
64}
64
65
65−QString ModelPrinter::recurse_string(const QModelIndex& index, int level) const
66+QString ModelPrinter::recurseString(const QModelIndex& index, int level) const
66{
67{
68+ if (!m_model)
69+ return "";
70+
67 QString str;
71 QString str;
68 QTextStream stream(&str);
72 QTextStream stream(&str);
69
73
@@ -76,19 +80,34 @@ QString ModelPrinter::recurse_string(const QModelIndex& index, int level) const
76 QMapIterator<QString, QVariant> iter(vData.toMap());
80 QMapIterator<QString, QVariant> iter(vData.toMap());
77 while (iter.hasNext()) {
81 while (iter.hasNext()) {
78 iter.next();
82 iter.next();
79− stream << tabify(level) << roleNames[role] << "." << iter.key() << ": " << iter.value().toString() << endl;
83+ stream << tabify(level)
84+ << roleNames[role]
85+ << "."
86+ << iter.key()
87+ << ": "
88+ << iter.value().toString()
89+ << endl;
80 }
90 }
81 }
91 }
82 else {
92 else {
83− stream << tabify(level) << roleNames[role] << ": " << vData.toString() << endl;
93+ stream << tabify(level)
94+ << roleNames[role]
95+ << ": "
96+ << vData.toString()
97+ << endl;
84 }
98 }
85 }
99 }
86
100
87 int rowCount = m_model->rowCount(index);
101 int rowCount = m_model->rowCount(index);
88− stream << tabify(level) << "child count" << ": " << rowCount << endl;
102+ stream << tabify(level)
103+ << "child count"
104+ << ": "
105+ << rowCount
106+ << endl;
107+
89 for (int i = 0; i < rowCount; i++) {
108 for (int i = 0; i < rowCount; i++) {
90 QModelIndex child = m_model->index(i, 0, index);
109 QModelIndex child = m_model->index(i, 0, index);
91− str += recurse_string(child, level+1);
110+ str += recurseString(child, level+1);
92 }
111 }
93 return str;
112 return str;
94}
113}
plugins/Unity/Indicators/modelprinter.h+5−4
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright 2012 Canonical Ltd.
2+ * Copyright 2013 Canonical Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5 * it under the terms of the GNU Lesser General Public License as published by
@@ -29,20 +29,21 @@ class ModelPrinter : public QObject
29 Q_OBJECT
29 Q_OBJECT
30
30
31 Q_PROPERTY(QAbstractItemModel* model READ sourceModel WRITE setSourceModel NOTIFY modelChanged)
31 Q_PROPERTY(QAbstractItemModel* model READ sourceModel WRITE setSourceModel NOTIFY modelChanged)
32+ Q_PROPERTY(QString text READ text NOTIFY textChanged)
32public:
33public:
33 ModelPrinter(QObject* parent=0);
34 ModelPrinter(QObject* parent=0);
34
35
35 void setSourceModel(QAbstractItemModel* sourceModel);
36 void setSourceModel(QAbstractItemModel* sourceModel);
36 QAbstractItemModel* sourceModel() const;
37 QAbstractItemModel* sourceModel() const;
37
38
38− Q_INVOKABLE QString getString(const QModelIndex& index = QModelIndex()) const;
39+ Q_INVOKABLE QString text(const QModelIndex& index = QModelIndex()) const;
39
40
40Q_SIGNALS:
41Q_SIGNALS:
41− void sourceChanged();
42 void modelChanged();
42 void modelChanged();
43+ void textChanged();
43
44
44private:
45private:
45− QString recurse_string(const QModelIndex& index, int level) const;
46+ QString recurseString(const QModelIndex& index, int level) const;
46 QAbstractItemModel* m_model;
47 QAbstractItemModel* m_model;
47};
48};
48
49
tests/autopilot/unity8/indicators_client/tests/test_battery.py+1−1
@@ -26,7 +26,7 @@ class TestDisplayMenus(IndicatorsTestCase):
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()
28
28
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)))