on 7e71b7d help sign in
unity8/modules/Unity/Indicators/indicatorsmodel.h
91 lines 2.7 kB history raw
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 *
16 * Authors:
17 * Renato Araujo Oliveira Filho <renato@canonical.com>
18 * Nick Dedekind <nick.dedekind@canonical.com>
19 */
21#ifndef INDICATORSMODEL_H
22#define INDICATORSMODEL_H
24#include "indicator.h"
26#include <QAbstractListModel>
27#include <QQmlEngine>
29class IndicatorsManager;
31class IndicatorsModel : public QAbstractListModel
33 Q_OBJECT
34 Q_ENUMS(Roles)
35 Q_PROPERTY(int count READ count NOTIFY countChanged)
36 Q_PROPERTY(QVariant indicatorData READ indicatorData WRITE setIndicatorData NOTIFY indicatorDataChanged)
38public:
39 enum Roles {
40 Identifier = 0,
41 Priority,
42 Title,
43 Description,
44 WidgetSource,
45 PageSource,
46 IndicatorProperties,
47 IsValid
48 };
50 IndicatorsModel(QObject *parent=0);
51 ~IndicatorsModel();
53 Q_INVOKABLE void load();
54 Q_INVOKABLE void unload();
56 Q_INVOKABLE QVariant data(int row, int role = Qt::DisplayRole) const;
58 /* QAbstractItemModel */
59 QHash<int, QByteArray> roleNames() const;
60 int columnCount(const QModelIndex &parent = QModelIndex()) const;
61 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
62 QModelIndex parent (const QModelIndex &index) const;
63 int rowCount(const QModelIndex &parent = QModelIndex()) const;
65 void setIndicatorData(const QVariant& data);
66 QVariant indicatorData() const;
68Q_SIGNALS:
69 void countChanged();
70 void indicatorDataChanged(const QVariant& data);
72private Q_SLOTS:
73 void onIdentifierChanged();
74 void onIndicatorPropertiesChanged();
75 void onIndicatorLoaded(const QString& indicator);
76 void onIndicatorAboutToBeUnloaded(const QString& indicator);
78private:
79 IndicatorsManager *m_manager;
81 QList<Indicator::Ptr> m_indicators;
82 QVariant m_indicator_data;
83 QMap<QString, QVariantMap> m_parsed_indicator_data;
85 void notifyDataChanged(QObject *sender, int role);
86 int count() const;
87 QVariant indicatorData(const Indicator::Ptr& plugin, int role) const;
88 static QVariant defaultData(Indicator::Ptr plugin, int role);
89};
91#endif // INDICATORSMODEL_H