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, SIGNAL(indicatorLoaded(const QString&)), this, SLOT(onIndicatorLoaded(const QString&)));
58 QObject::connect(m_manager, SIGNAL(indicatorAboutToBeUnloaded(const QString&)), this, SLOT(onIndicatorAboutToBeUnloaded(const QString&)));
60 QObject::connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
61 QObject::connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
62 QObject::connect(this, SIGNAL(modelReset()), this, SIGNAL(countChanged()));
66IndicatorsModel::~IndicatorsModel()
68 disconnect(m_manager, 0, 0, 0);
69 m_manager->deleteLater();
73 \qmlproperty IndicatorsModel::count
74 The number of data entries in the model.
76 \b Note: methods should only be called after the Component has completed.
78int IndicatorsModel::count() const
84 \qmlmethod IndicatorsModel::unload()
88void IndicatorsModel::load(const QString& profile)
91 m_manager->load(profile);
95 \qmlmethod IndicatorsModel::unload()
97 Unload all indicators.
99void IndicatorsModel::unload()
105void IndicatorsModel::onIndicatorLoaded(const QString& indicator_name)
107 Indicator::Ptr indicator = m_manager->indicator(indicator_name);
113 if (m_indicators.indexOf(indicator) >= 0)
118 // find the insert position
120 while (pos < count())
122 // keep going while the existing position is greater. (put lower position on end)
123 if (indicator->position() >= data(index(pos), IndicatorsModelRole::Position).toInt())
128 QObject::connect(indicator.data(), SIGNAL(identifierChanged(const QString&)), this, SLOT(onIdentifierChanged()));
129 QObject::connect(indicator.data(), SIGNAL(indicatorPropertiesChanged(const QVariant&)), this, SLOT(onIndicatorPropertiesChanged()));
131 beginInsertRows(QModelIndex(), pos, pos);
133 m_indicators.insert(pos, indicator);
138void IndicatorsModel::onIndicatorAboutToBeUnloaded(const QString& indicator_name)
140 Indicator::Ptr indicator = m_manager->indicator(indicator_name);
147 QMutableListIterator<Indicator::Ptr> iter(m_indicators);
148 while(iter.hasNext())
150 if (indicator == iter.next())
152 beginRemoveRows(QModelIndex(), i, i);
163void IndicatorsModel::onIdentifierChanged()
165 notifyDataChanged(QObject::sender(), IndicatorsModelRole::Identifier);
169void IndicatorsModel::onIndicatorPropertiesChanged()
171 notifyDataChanged(QObject::sender(), IndicatorsModelRole::IndicatorProperties);
175void IndicatorsModel::notifyDataChanged(QObject *sender, int role)
177 Indicator* indicator = qobject_cast<Indicator*>(sender);
184 QMutableListIterator<Indicator::Ptr> iter(m_indicators);
185 while(iter.hasNext())
187 if (indicator == iter.next())
189 QModelIndex changedIndex = this->index(index);
190 dataChanged(changedIndex, changedIndex, QVector<int>() << role);
198QHash<int, QByteArray> IndicatorsModel::roleNames() const
200 static QHash<int, QByteArray> roles;
203 roles[IndicatorsModelRole::Identifier] = "identifier";
204 roles[IndicatorsModelRole::Position] = "position";
205 roles[IndicatorsModelRole::WidgetSource] = "widgetSource";
206 roles[IndicatorsModelRole::PageSource] = "pageSource";
207 roles[IndicatorsModelRole::IndicatorProperties] = "indicatorProperties";
213int IndicatorsModel::columnCount(const QModelIndex &) const
218Q_INVOKABLE QVariant IndicatorsModel::data(int row, int role) const
220 return data(index(row, 0), role);
224QVariant IndicatorsModel::data(const QModelIndex &index, int role) const
226 if (!index.isValid() || index.row() >= m_indicators.size())
229 Indicator::Ptr indicator = m_indicators[index.row()];
233 case IndicatorsModelRole::Identifier:
236 return QVariant(indicator->identifier());
239 case IndicatorsModelRole::Position:
242 return QVariant(indicator->position());
245 case IndicatorsModelRole::IndicatorProperties:
248 return QVariant(indicator->indicatorProperties());
251 case IndicatorsModelRole::WidgetSource:
252 return qmlDirectory()+"/Panel/Indicators/DefaultIndicatorWidget.qml";
253 case IndicatorsModelRole::PageSource:
254 return qmlDirectory()+"/Panel/Indicators/DefaultIndicatorPage.qml";
262QModelIndex IndicatorsModel::parent(const QModelIndex&) const
264 return QModelIndex();
268int IndicatorsModel::rowCount(const QModelIndex&) const
270 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