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 LOMIRI_SHELL_APPLICATION_MIRSURFACELISTINTERFACE_H
18 #define LOMIRI_SHELL_APPLICATION_MIRSURFACELISTINTERFACE_H
19 
20 #include <QAbstractListModel>
21 
22 namespace lomiri {
23 namespace shell {
24 namespace application {
25 
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(lomiri::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 override {
74  QHash<int, QByteArray> roleNames;
75  roleNames.insert(SurfaceRole, "surface");
76  return roleNames;
77  }
78 
79  int count() const { return rowCount(); }
80 
81  MirSurfaceInterface *first() {
82  if (rowCount() > 0) {
83  return get(0);
84  } else {
85  return nullptr;
86  }
87  }
89 
90 Q_SIGNALS:
92  void countChanged(int count);
93  void firstChanged();
95 };
96 
97 } // namespace application
98 } // namespace shell
99 } // namespace lomiri
100 
102 
103 #endif // LOMIRI_SHELL_APPLICATION_MIRSURFACELISTINTERFACE_H
Holds a Mir surface. Pretty much an opaque class.
Definition: MirSurfaceInterface.h:42
Interface for a list model of MirSurfaces.
Definition: MirSurfaceListInterface.h:32
int count
Number of surfaces in this model.
Definition: MirSurfaceListInterface.h:41
Roles
The Roles supported by the model.
Definition: MirSurfaceListInterface.h:56
virtual Q_INVOKABLE MirSurfaceInterface * get(int index)=0
Returns the surface at the specified index.
lomiri::shell::application::MirSurfaceInterface * first
The first (index 0) surface in this model.
Definition: MirSurfaceListInterface.h:49
Top-level namespace for all things Lomiri-related.
Definition: Version.h:38