on xenial help sign in
review comments
commitea0f6a52d3e1483ac365db5ff476f9dfbc512e73 authorNick Dedekind <nicholas.dedekind@gmail.com> dateWed 31 Jul 2013, 09:45 (13 years ago) parentf62e3c8
5 files changed+51−35
Panel/Indicators/client/IndicatorsPage.qml+5−4 Panel/Indicators/client/IndicatorsTree.qml+2−7 plugins/Unity/Indicators/modelprinter.cpp+38−19 plugins/Unity/Indicators/modelprinter.h+5−4 tests/autopilot/unity8/indicators_client/tests/test_battery.py+1−1
Panel/Indicators/client/IndicatorsPage.qml+5−4
@@ -15,6 +15,7 @@
1515 *
1616 * Authors:
1717 * Renato Araujo Oliveira Filho <renato@canonical.com>
18+ * Nick Dedekind <nick.dedekind@canonical.com>
1819 */
1920
2021import QtQuick 2.0
@@ -26,7 +27,7 @@ Page {
2627
2728 title: indicatorProperties && indicatorProperties.title ? indicatorProperties.title : ""
2829 property variant indicatorProperties
29− property string pageSource : page_loader.source
30+ property string pageSource : pageLoader.source
3031
3132 anchors.fill: parent
3233
@@ -40,8 +41,8 @@ Page {
4041 }
4142
4243 Loader {
43− id: page_loader
44− objectName: "page_loader"
44+ id: pageLoader
45+ objectName: "pageLoader"
4546
4647 anchors {
4748 top: visualCheckItem.bottom
@@ -87,7 +88,7 @@ Page {
8788 right: parent.right
8889 }
8990 text: "Refresh"
90− onClicked: page_loader.item.refresh()
91+ onClicked: pageLoader.item.refresh()
9192 }
9293 }
9394}
Panel/Indicators/client/IndicatorsTree.qml+2−7
@@ -14,7 +14,7 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 *
1616 * Authors:
17− * Nick Dedekind <nick.dededkind@canonical.com
17+ * Nick Dedekind <nick.dededkind@canonical.com>
1818 */
1919
2020import QtQuick 2.0
@@ -39,10 +39,6 @@ Page {
3939 menuModel.start();
4040 }
4141
42− function refresh() {
43− all_data.text = printer.getString();
44− }
45−
4642 QDBusMenuModel {
4743 id: menuModel
4844 objectPath: page.deviceMenuObjectPath
@@ -51,8 +47,6 @@ Page {
5147 Indicators.ModelPrinter {
5248 id: printer
5349 model: menuModel
54−
55− onSourceChanged: page.refresh()
5650 }
5751
5852 Flickable {
@@ -62,6 +56,7 @@ Page {
6256 Text {
6357 id: all_data
6458 color: "white"
59+ text: printer.text
6560 }
6661 }
6762}
plugins/Unity/Indicators/modelprinter.cpp+38−19
@@ -1,24 +1,27 @@
11/*
2− * Copyright (C) 2012 Canonical, Ltd.
2+ * Copyright 2013 Canonical Ltd.
33 *
44 * 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
66 * the Free Software Foundation; version 3.
77 *
88 * This program is distributed in the hope that it will be useful,
99 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1010 * 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.
1212 *
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
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors:
17+ * Nick Dedekind <nick.dedekind@canonical.com>
1518 */
1619
1720// self
1821#include "modelprinter.h"
1922
2023// Qt
21−#include <QDebug>
24+#include <QTextStream>
2225
2326ModelPrinter::ModelPrinter(QObject *parent)
2427 : QObject(parent)
@@ -29,19 +32,17 @@ ModelPrinter::ModelPrinter(QObject *parent)
2932void ModelPrinter::setSourceModel(QAbstractItemModel * sourceModel)
3033{
3134 if (m_model != NULL) {
32− disconnect(m_model, SIGNAL(modelReset()), this, SIGNAL(sourceChanged()));
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+ disconnect(m_model);
3536 }
3637 if (m_model != sourceModel) {
3738 m_model = sourceModel;
3839 Q_EMIT modelChanged();
39− Q_EMIT sourceChanged();
40+ Q_EMIT textChanged();
4041 }
4142 if (m_model != NULL) {
42− connect(m_model, SIGNAL(modelReset()), this, SIGNAL(sourceChanged()));
43− connect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SIGNAL(sourceChanged()));
44− connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SIGNAL(sourceChanged()));
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()));
4546 }
4647}
4748
@@ -50,9 +51,9 @@ QAbstractItemModel* ModelPrinter::sourceModel() const
5051 return m_model;
5152}
5253
53−QString ModelPrinter::getString(const QModelIndex& index) const
54+QString ModelPrinter::text(const QModelIndex& index) const
5455{
55− return recurse_string(index, 0);
56+ return recurseString(index, 0);
5657}
5758
5859QString tabify(int level) { QString str;
@@ -62,8 +63,11 @@ QString tabify(int level) { QString str;
6263 return str;
6364}
6465
65−QString ModelPrinter::recurse_string(const QModelIndex& index, int level) const
66+QString ModelPrinter::recurseString(const QModelIndex& index, int level) const
6667{
68+ if (!m_model)
69+ return "";
70+
6771 QString str;
6872 QTextStream stream(&str);
6973
@@ -76,19 +80,34 @@ QString ModelPrinter::recurse_string(const QModelIndex& index, int level) const
7680 QMapIterator<QString, QVariant> iter(vData.toMap());
7781 while (iter.hasNext()) {
7882 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;
8090 }
8191 }
8292 else {
83− stream << tabify(level) << roleNames[role] << ": " << vData.toString() << endl;
93+ stream << tabify(level)
94+ << roleNames[role]
95+ << ": "
96+ << vData.toString()
97+ << endl;
8498 }
8599 }
86100
87101 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+
89108 for (int i = 0; i < rowCount; i++) {
90109 QModelIndex child = m_model->index(i, 0, index);
91− str += recurse_string(child, level+1);
110+ str += recurseString(child, level+1);
92111 }
93112 return str;
94113}
plugins/Unity/Indicators/modelprinter.h+5−4
@@ -1,5 +1,5 @@
11/*
2− * Copyright 2012 Canonical Ltd.
2+ * Copyright 2013 Canonical Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU Lesser General Public License as published by
@@ -29,20 +29,21 @@ class ModelPrinter : public QObject
2929 Q_OBJECT
3030
3131 Q_PROPERTY(QAbstractItemModel* model READ sourceModel WRITE setSourceModel NOTIFY modelChanged)
32+ Q_PROPERTY(QString text READ text NOTIFY textChanged)
3233public:
3334 ModelPrinter(QObject* parent=0);
3435
3536 void setSourceModel(QAbstractItemModel* sourceModel);
3637 QAbstractItemModel* sourceModel() const;
3738
38− Q_INVOKABLE QString getString(const QModelIndex& index = QModelIndex()) const;
39+ Q_INVOKABLE QString text(const QModelIndex& index = QModelIndex()) const;
3940
4041Q_SIGNALS:
41− void sourceChanged();
4242 void modelChanged();
43+ void textChanged();
4344
4445private:
45− QString recurse_string(const QModelIndex& index, int level) const;
46+ QString recurseString(const QModelIndex& index, int level) const;
4647 QAbstractItemModel* m_model;
4748};
4849
tests/autopilot/unity8/indicators_client/tests/test_battery.py+1−1
@@ -26,7 +26,7 @@ class TestDisplayMenus(IndicatorsTestCase):
2626 self.pointing_device.move_to_object(self.main_window.get_battery_menu())
2727 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");
3030 self.assertThat(fn_loader, Eventually(NotEquals(None)));
3131 page_loader = fn_loader();
3232 self.assertThat(page_loader.progress, Eventually(Equals(1.0)))