File: MirSurfaceListInterface.h

package info (click to toggle)
lomiri-api 0.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,248 kB
  • sloc: cpp: 6,415; python: 264; ansic: 96; makefile: 29; sh: 17
file content (103 lines) | stat: -rw-r--r-- 2,822 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * Copyright (C) 2016 Canonical, Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef LOMIRI_SHELL_APPLICATION_MIRSURFACELISTINTERFACE_H
#define LOMIRI_SHELL_APPLICATION_MIRSURFACELISTINTERFACE_H

#include <QAbstractListModel>

namespace lomiri {
namespace shell {
namespace application {

class MirSurfaceInterface;

/**
 * @brief Interface for a list model of MirSurfaces
 */
class MirSurfaceListInterface : public QAbstractListModel
{

    Q_OBJECT

    /**
     * @brief Number of surfaces in this model
     *
     * This is the same as rowCount, added in order to keep compatibility with QML ListModels.
     */
    Q_PROPERTY(int count READ count NOTIFY countChanged)

    /**
     * @brief The first (index 0) surface in this model
     *
     * Will always match the result of get(0). But being a property, it's more appropriate
     * for use in qml bindinds (JS expression gets reevaluated when it changes)
     */
    Q_PROPERTY(lomiri::shell::application::MirSurfaceInterface* first READ first NOTIFY firstChanged)
public:
    /**
     * @brief The Roles supported by the model
     *
     * SurfaceRole - A MirSurfaceInterface.
     */
    enum Roles {
        SurfaceRole = Qt::UserRole,
    };

    /// @cond
    MirSurfaceListInterface(QObject *parent = 0) : QAbstractListModel(parent) {}
    virtual ~MirSurfaceListInterface() {}
    /// @endcond

    /**
     * @brief Returns the surface at the specified index
     *
     */
    Q_INVOKABLE virtual MirSurfaceInterface *get(int index) = 0;

    /// @cond
    // QAbstractItemModel methods
    QHash<int, QByteArray> roleNames() const override {
        QHash<int, QByteArray> roleNames;
        roleNames.insert(SurfaceRole, "surface");
        return roleNames;
    }

    int count() const { return rowCount(); }

    MirSurfaceInterface *first() {
        if (rowCount() > 0) {
            return get(0);
        } else {
            return nullptr;
        }
    }
    /// @endcond

Q_SIGNALS:
    /// @cond
    void countChanged(int count);
    void firstChanged();
    /// @endcond
};

} // namespace application
} // namespace shell
} // namespace lomiri

Q_DECLARE_METATYPE(lomiri::shell::application::MirSurfaceListInterface*)

#endif // LOMIRI_SHELL_APPLICATION_MIRSURFACELISTINTERFACE_H