Changeset View
Changeset View
Standalone View
Standalone View
libs/bolt/devicemodel.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (c) 2018 Daniel Vrátil <dvratil@kde.org> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #ifndef DEVICEMODEL_H_ | ||||
22 | #define DEVICEMODEL_H_ | ||||
23 | | ||||
24 | #include <QAbstractListModel> | ||||
25 | | ||||
26 | #include "kbolt_export.h" | ||||
27 | | ||||
28 | namespace Bolt | ||||
29 | { | ||||
30 | | ||||
31 | class Manager; | ||||
32 | class Device; | ||||
33 | class KBOLT_EXPORT DeviceModel : public QAbstractListModel | ||||
34 | { | ||||
35 | Q_OBJECT | ||||
36 | Q_PROPERTY(Bolt::Manager *manager READ manager WRITE setManager NOTIFY managerChanged) | ||||
37 | | ||||
38 | /** Whether to show only peripherals or display hosts as well */ | ||||
39 | Q_PROPERTY(bool showHosts READ showHosts WRITE setShowHosts NOTIFY showHostsChanged) | ||||
40 | public: | ||||
41 | enum Role { | ||||
42 | DeviceRole = Qt::UserRole | ||||
43 | }; | ||||
44 | | ||||
45 | using QAbstractListModel::QAbstractListModel; | ||||
46 | ~DeviceModel() override = default; | ||||
47 | | ||||
48 | Manager *manager() const; | ||||
49 | void setManager(Manager *manager); | ||||
50 | | ||||
51 | bool showHosts() const; | ||||
52 | void setShowHosts(bool showHosts); | ||||
53 | | ||||
54 | QHash<int, QByteArray> roleNames() const override; | ||||
55 | int rowCount(const QModelIndex &parent) const override; | ||||
56 | QVariant data(const QModelIndex &index, int role) const override; | ||||
57 | | ||||
58 | Q_SIGNALS: | ||||
59 | void managerChanged(Bolt::Manager *manager); | ||||
60 | void showHostsChanged(bool showHosts); | ||||
61 | | ||||
62 | private: | ||||
63 | void populateWithoutReset(); | ||||
64 | | ||||
65 | Manager *mManager = nullptr; | ||||
66 | QVector<QSharedPointer<Device>> mDevices; | ||||
67 | bool mShowHosts = true; | ||||
68 | }; | ||||
69 | | ||||
70 | } // namespace Bolt | ||||
71 | | ||||
72 | #endif |