2 * Copyright 2014 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>
20#include "fakeindicatorsmodel.h"
21#include "indicators.h"
23FakeIndicatorsModel::FakeIndicatorsModel(QObject *parent)
24 : QAbstractListModel(parent)
26 QObject::connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
27 QObject::connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
28 QObject::connect(this, SIGNAL(modelReset()), this, SIGNAL(countChanged()));
32FakeIndicatorsModel::~FakeIndicatorsModel()
36int FakeIndicatorsModel::count() const
41void FakeIndicatorsModel::load(const QString&)
45void FakeIndicatorsModel::unload()
50 Q_EMIT modelDataChanged();
56void FakeIndicatorsModel::append(const QVariantMap& data)
58 QList<QVariant> allData = m_modelData.toList();
59 beginInsertRows(QModelIndex(), allData.count(), allData.count());
62 m_modelData = allData;
63 Q_EMIT modelDataChanged();
68void FakeIndicatorsModel::insert(int row, const QVariantMap& data)
70 QList<QVariant> allData = m_modelData.toList();
71 row = qMax(0, qMin(row, allData.count()));
73 beginInsertRows(QModelIndex(), row, row);
75 allData.insert(row, data);
76 m_modelData = allData;
77 Q_EMIT modelDataChanged();
82void FakeIndicatorsModel::remove(int row)
84 QList<QVariant> allData = m_modelData.toList();
85 row = qMax(0, qMin(row, allData.count()));
87 beginRemoveRows(QModelIndex(), row, row);
89 allData.removeAt(row);
90 m_modelData = allData;
91 Q_EMIT modelDataChanged();
96void FakeIndicatorsModel::setModelData(const QVariant& modelData)
100 m_modelData = modelData;
101 Q_EMIT modelDataChanged();
106QHash<int, QByteArray> FakeIndicatorsModel::roleNames() const
108 static QHash<int, QByteArray> roles;
111 roles[IndicatorsModelRole::Identifier] = "identifier";
112 roles[IndicatorsModelRole::Position] = "position";
113 roles[IndicatorsModelRole::WidgetSource] = "widgetSource";
114 roles[IndicatorsModelRole::PageSource] = "pageSource";
115 roles[IndicatorsModelRole::IndicatorProperties] = "indicatorProperties";
120int FakeIndicatorsModel::columnCount(const QModelIndex &) const
125QVariant FakeIndicatorsModel::data(int row, int role) const
127 return data(index(row, 0), role);
130QVariant FakeIndicatorsModel::data(const QModelIndex &index, int role) const
132 QList<QVariant> dataList = m_modelData.toList();
133 if (!index.isValid() || index.row() >= dataList.size())
136 return dataList[index.row()].toMap()[roleNames()[role]];
139QModelIndex FakeIndicatorsModel::parent(const QModelIndex&) const
141 return QModelIndex();
144int FakeIndicatorsModel::rowCount(const QModelIndex&) const
146 return m_modelData.toList().count();
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