2 * Copyright 2012 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 * Renato Araujo Oliveira Filho <renato@canonical.com>
20#include "indicatorsmodel.h"
21#include "indicatorsmanager.h"
23#include "indicators.h"
32 \qmltype IndicatorsModel
33 \inherits QAbstractListModel
35 \brief The IndicatorsModel class defines the list model for indicators
37 \b {This component is under heavy development.}
39 This class expose the available indicators.
49 Component.onCompleted: menuModel.load()
53IndicatorsModel::IndicatorsModel(QObject *parent)
54 : QAbstractListModel(parent)
56 m_manager = new IndicatorsManager(this);
57 QObject::connect(m_manager, &IndicatorsManager::indicatorLoaded, this, &IndicatorsModel::onIndicatorLoaded);
58 QObject::connect(m_manager, &IndicatorsManager::indicatorAboutToBeUnloaded, this, &IndicatorsModel::onIndicatorAboutToBeUnloaded);
59 QObject::connect(m_manager, &IndicatorsManager::profileChanged, this, &IndicatorsModel::profileChanged);
61 QObject::connect(this, &IndicatorsModel::rowsInserted, this, &IndicatorsModel::countChanged);
62 QObject::connect(this, &IndicatorsModel::rowsRemoved, this, &IndicatorsModel::countChanged);
63 QObject::connect(this, &IndicatorsModel::modelReset, this, &IndicatorsModel::countChanged);
67IndicatorsModel::~IndicatorsModel()
69 disconnect(m_manager, 0, 0, 0);
70 m_manager->deleteLater();
74 \qmlproperty IndicatorsModel::count
75 The number of data entries in the model.
77 \b Note: methods should only be called after the Component has completed.
79int IndicatorsModel::count() const
85 \qmlproperty IndicatorsModel::profile
86 The indicator profile to use for the model.
88 \b Note: methods should only be called after the Component has completed.
90QString IndicatorsModel::profile() const
92 return m_manager->profile();
96 \qmlproperty IndicatorsModel::setProfile
97 Set the indicator profile to use for the model.
99 \b Note: methods should only be called after the Component has completed.
101void IndicatorsModel::setProfile(const QString &profile)
103 m_manager->setProfile(profile);
107 \qmlmethod IndicatorsModel::unload()
111void IndicatorsModel::load()
113 m_indicators.clear();
118 \qmlmethod IndicatorsModel::unload()
120 Unload all indicators.
122void IndicatorsModel::unload()
128void IndicatorsModel::onIndicatorLoaded(const QString& indicator_name)
130 Indicator::Ptr indicator = m_manager->indicator(indicator_name);
136 if (m_indicators.indexOf(indicator) >= 0)
141 // find the insert position
143 while (pos < count())
145 // keep going while the existing position is greater. (put lower position on end)
146 if (indicator->position() >= data(index(pos), IndicatorsModelRole::Position).toInt())
151 QObject::connect(indicator.data(), &Indicator::identifierChanged, this, &IndicatorsModel::onIdentifierChanged);
152 QObject::connect(indicator.data(), &Indicator::indicatorPropertiesChanged, this, &IndicatorsModel::onIndicatorPropertiesChanged);
154 beginInsertRows(QModelIndex(), pos, pos);
156 m_indicators.insert(pos, indicator);
161void IndicatorsModel::onIndicatorAboutToBeUnloaded(const QString& indicator_name)
163 Indicator::Ptr indicator = m_manager->indicator(indicator_name);
170 QMutableListIterator<Indicator::Ptr> iter(m_indicators);
171 while(iter.hasNext())
173 if (indicator == iter.next())
175 beginRemoveRows(QModelIndex(), i, i);
186void IndicatorsModel::onIdentifierChanged()
188 notifyDataChanged(QObject::sender(), IndicatorsModelRole::Identifier);
192void IndicatorsModel::onIndicatorPropertiesChanged()
194 notifyDataChanged(QObject::sender(), IndicatorsModelRole::IndicatorProperties);
198void IndicatorsModel::notifyDataChanged(QObject *sender, int role)
200 Indicator* indicator = qobject_cast<Indicator*>(sender);
207 QMutableListIterator<Indicator::Ptr> iter(m_indicators);
208 while(iter.hasNext())
210 if (indicator == iter.next())
212 QModelIndex changedIndex = this->index(index);
213 dataChanged(changedIndex, changedIndex, QVector<int>() << role);
221QHash<int, QByteArray> IndicatorsModel::roleNames() const
223 static QHash<int, QByteArray> roles;
226 roles[IndicatorsModelRole::Identifier] = "identifier";
227 roles[IndicatorsModelRole::Position] = "position";
228 roles[IndicatorsModelRole::IndicatorProperties] = "indicatorProperties";
234int IndicatorsModel::columnCount(const QModelIndex &) const
239QVariant IndicatorsModel::data(int row, int role) const
241 return data(index(row, 0), role);
245QVariant IndicatorsModel::data(const QModelIndex &index, int role) const
247 if (!index.isValid() || index.row() >= m_indicators.size())
250 Indicator::Ptr indicator = m_indicators.at(index.row());
254 case IndicatorsModelRole::Identifier:
257 return indicator->identifier();
260 case IndicatorsModelRole::Position:
263 return indicator->position();
266 case IndicatorsModelRole::IndicatorProperties:
269 return indicator->indicatorProperties();
279QModelIndex IndicatorsModel::parent(const QModelIndex&) const
281 return QModelIndex();
285int IndicatorsModel::rowCount(const QModelIndex&) const
287 return m_indicators.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