Debian Codegraph @

tests/mocks/QtMir/Application/ApplicationListModel.h

raw
1 /*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU 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 General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 #ifndef APPLICATION_LIST_MODEL_H
18 #define APPLICATION_LIST_MODEL_H
19
20 #include <QAbstractListModel>
21 #include <QQmlListProperty>
22 #include "ApplicationInfo.h"
23
24 class ApplicationManager;
25
26 class ApplicationListModel : public QAbstractListModel {
27 Q_OBJECT
28
29 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
30 Q_PROPERTY(QQmlListProperty<ApplicationInfo> applications READ applications)
31 Q_CLASSINFO("DefaultProperty", "applications")
32
33 public:
34 explicit ApplicationListModel(QObject* parent = 0);
35 virtual ~ApplicationListModel();
36
37 // QAbstractItemModel methods.
38 int rowCount(const QModelIndex& parent = QModelIndex()) const;
39 QVariant data(const QModelIndex& index, int role) const;
40 QHash<int,QByteArray> roleNames() const { return m_roleNames; }
41 Q_INVOKABLE QVariant get(int index) const;
42 Q_INVOKABLE void move(int from, int to);
43
44 QQmlListProperty<ApplicationInfo> applications();
45
46 Q_INVOKABLE void add(ApplicationInfo* application);
47 Q_INVOKABLE void remove(ApplicationInfo* application);
48 Q_INVOKABLE bool contains(ApplicationInfo* application) const;
49 Q_INVOKABLE void clear();
50
51 Q_SIGNALS:
52 void countChanged();
53
54 private:
55 Q_DISABLE_COPY(ApplicationListModel)
56
57 static void appendApplication(QQmlListProperty<ApplicationInfo> *list,
58 ApplicationInfo *application);
59 static int countApplications(QQmlListProperty<ApplicationInfo> *list);
60 static ApplicationInfo* atApplication(QQmlListProperty<ApplicationInfo> *list, int index);
61 static void clearApplications(QQmlListProperty<ApplicationInfo> *list);
62
63 QHash<int,QByteArray> m_roleNames;
64 QList<ApplicationInfo*> m_applications;
65
66 friend class ApplicationManager;
67 };
68
69 Q_DECLARE_METATYPE(ApplicationListModel*)
70
71 #endif // APPLICATION_LIST_MODEL_H