2 * Copyright 2013 Canonical Ltd.
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.
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.
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/>.
17 * Nick Dedekind <nick.dedekind@canonical.com>
21#include "modelprinter.h"
23#include <unitymenumodel.h>
28ModelPrinter::ModelPrinter(QObject *parent)
34void ModelPrinter::setSourceModel(UnityMenuModel * sourceModel)
36 if (m_model != NULL) {
39 if (m_model != sourceModel) {
40 m_model = sourceModel;
41 Q_EMIT modelChanged();
44 if (m_model != NULL) {
45 connect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), SIGNAL(textChanged()));
46 connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), SIGNAL(textChanged()));
47 connect(m_model, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)), SIGNAL(textChanged()));
51UnityMenuModel* ModelPrinter::sourceModel() const
56QString ModelPrinter::text()
58 return getModelDataString(m_model, 0);
61QString tabify(int level) { QString str;
62 for (int i = 0; i < level; i++) {
68QString ModelPrinter::getModelDataString(UnityMenuModel* sourceModel, int level)
74 QTextStream stream(&str);
76 int rowCount = sourceModel->rowCount();
77 for (int row = 0; row < rowCount; row++) {
79 stream << getRowSring(sourceModel, row, level) << endl;
81 UnityMenuModel* childMenuModel = qobject_cast<UnityMenuModel*>(sourceModel->submenu(row));
84 if (!m_children.contains(childMenuModel)) {
85 m_children << childMenuModel;
86 connect(childMenuModel, SIGNAL(rowsInserted(QModelIndex,int,int)), SIGNAL(textChanged()));
87 connect(childMenuModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), SIGNAL(textChanged()));
88 connect(childMenuModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)), SIGNAL(textChanged()));
90 stream << getModelDataString(childMenuModel, level+1);
96QString ModelPrinter::getRowSring(UnityMenuModel* sourceModel, int row, int depth) const
99 QTextStream stream(&str);
101 // Print out this row
102 QHash<int, QByteArray> roleNames = sourceModel->roleNames();
103 QList<int> roles = roleNames.keys();
106 Q_FOREACH(int role, roles) {
107 const QByteArray& roleName = roleNames[role];
108 stream << tabify(depth) << getVariantString(roleName, sourceModel->get(row, roleName));
113QString ModelPrinter::getVariantString(const QString& roleName, const QVariant vData ) const
116 QTextStream stream(&str);
118 if (vData.canConvert(QMetaType::QVariantMap)) {
119 QMapIterator<QString, QVariant> iter(vData.toMap());
120 while (iter.hasNext()) {
126 << iter.value().toString()
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list