My Project
MirSurfaceListInterface.h
1 /*
2  * Copyright (C) 2016 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 UNITY_SHELL_APPLICATION_MIRSURFACELISTINTERFACE_H
18 #define UNITY_SHELL_APPLICATION_MIRSURFACELISTINTERFACE_H
19 
20 #include <QAbstractListModel>
21 
22 namespace unity {
23 namespace shell {
24 namespace application {
25 
26 class MirSurfaceInterface;
27 
31 class MirSurfaceListInterface : public QAbstractListModel
32 {
33 
34  Q_OBJECT
35 
41  Q_PROPERTY(int count READ count NOTIFY countChanged)
42 
43 
49  Q_PROPERTY(unity::shell::application::MirSurfaceInterface* first READ first NOTIFY firstChanged)
50 public:
56  enum Roles {
57  SurfaceRole = Qt::UserRole,
58  };
59 
61  MirSurfaceListInterface(QObject *parent = 0) : QAbstractListModel(parent) {}
62  virtual ~MirSurfaceListInterface() {}
64 
69  Q_INVOKABLE virtual MirSurfaceInterface *get(int index) = 0;
70 
72  // QAbstractItemModel methods
73  QHash<int, QByteArray> roleNames() const {
74  QHash<int, QByteArray> roleNames;
75  roleNames.insert(SurfaceRole, "surface");
76  return roleNames;
77  }
78 
79  int count() const { return rowCount(); }
80 
82  if (rowCount() > 0) {
83  return get(0);
84  } else {
85  return nullptr;
86  }
87  }
89 
90 Q_SIGNALS:
92  void countChanged();
93  void firstChanged();
95 };
96 
97 } // namespace application
98 } // namespace shell
99 } // namespace unity
100 
102 
103 #endif // UNITY_SHELL_APPLICATION_MIRSURFACELISTINTERFACE_H
Roles
The Roles supported by the model.
Definition: MirSurfaceListInterface.h:56
Top-level namespace for all things Unity-related.
Definition: Version.h:37
Interface for a list model of MirSurfaces.
Definition: MirSurfaceListInterface.h:31
unity::shell::application::MirSurfaceInterface first
The first (index 0) surface in this model.
Definition: MirSurfaceListInterface.h:49
int count
Number of surfaces in this model.
Definition: MirSurfaceListInterface.h:41
Holds a Mir surface. Pretty much an opaque class.
Definition: MirSurfaceInterface.h:40