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),
27 QObject::connect(this, &FakeIndicatorsModel::rowsInserted, this, &FakeIndicatorsModel::countChanged);
28 QObject::connect(this, &FakeIndicatorsModel::rowsRemoved, this, &FakeIndicatorsModel::countChanged);
29 QObject::connect(this, &FakeIndicatorsModel::modelReset, this, &FakeIndicatorsModel::countChanged);
33FakeIndicatorsModel::~FakeIndicatorsModel()
37int FakeIndicatorsModel::count() const
42QString FakeIndicatorsModel::profile() const
47void FakeIndicatorsModel::setProfile(const QString& profile)
50 Q_EMIT profileChanged();
53void FakeIndicatorsModel::load(const QString&)
57void FakeIndicatorsModel::unload()
62 Q_EMIT modelDataChanged();
68void FakeIndicatorsModel::append(const QVariantMap& data)
70 QList<QVariant> allData = m_modelData.toList();
71 beginInsertRows(QModelIndex(), allData.count(), allData.count());
74 m_modelData = allData;
75 Q_EMIT modelDataChanged();
80void FakeIndicatorsModel::insert(int row, const QVariantMap& data)
82 QList<QVariant> allData = m_modelData.toList();
83 row = qMax(0, qMin(row, allData.count()));
85 beginInsertRows(QModelIndex(), row, row);
87 allData.insert(row, data);
88 m_modelData = allData;
89 Q_EMIT modelDataChanged();
94void FakeIndicatorsModel::remove(int row)
96 QList<QVariant> allData = m_modelData.toList();
97 row = qMax(0, qMin(row, allData.count()));
99 beginRemoveRows(QModelIndex(), row, row);
101 allData.removeAt(row);
102 m_modelData = allData;
103 Q_EMIT modelDataChanged();
108void FakeIndicatorsModel::setModelData(const QVariant& modelData)
112 m_modelData = modelData;
113 Q_EMIT modelDataChanged();
118QHash<int, QByteArray> FakeIndicatorsModel::roleNames() const
120 static QHash<int, QByteArray> roles;
123 roles[IndicatorsModelRole::Identifier] = "identifier";
124 roles[IndicatorsModelRole::Position] = "position";
125 roles[IndicatorsModelRole::IndicatorProperties] = "indicatorProperties";
130int FakeIndicatorsModel::columnCount(const QModelIndex &) const
135QVariant FakeIndicatorsModel::data(int row, int role) const
137 return data(index(row, 0), role);
140QVariant FakeIndicatorsModel::data(const QModelIndex &index, int role) const
142 QList<QVariant> dataList = m_modelData.toList();
143 if (!index.isValid() || index.row() >= dataList.size())
146 return dataList[index.row()].toMap()[roleNames()[role]];
149QModelIndex FakeIndicatorsModel::parent(const QModelIndex&) const
151 return QModelIndex();
154int FakeIndicatorsModel::rowCount(const QModelIndex&) const
156 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