@@ -1,24 +1,27 @@
2− * Copyright (C) 2012 Canonical, Ltd.
2+ * Copyright 2013 Canonical Ltd.
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.
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.
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/>.
17+ * Nick Dedekind <nick.dedekind@canonical.com>
18#include "modelprinter.h"
21#include "modelprinter.h"
21−#include <QDebug>
24+#include <QTextStream>
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)
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()));
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();
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()));
@@ -50,9 +51,9 @@ QAbstractItemModel* ModelPrinter::sourceModel() const
50 return m_model;
51 return m_model;
53−QString ModelPrinter::getString(const QModelIndex& index) const
54+QString ModelPrinter::text(const QModelIndex& index) const
55− return recurse_string(index, 0);
56+ return recurseString(index, 0);
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;
65−QString ModelPrinter::recurse_string(const QModelIndex& index, int level) const
66+QString ModelPrinter::recurseString(const QModelIndex& index, int level) const
67 QString str;
71 QString str;
68 QTextStream stream(&str);
72 QTextStream stream(&str);
@@ -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)
88+ << iter.value().toString()
83− stream << tabify(level) << roleNames[role] << ": " << vData.toString() << endl;
93+ stream << tabify(level)
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)
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);
93 return str;
112 return str;