BluezQt

devicesmodel.h
1 /*
2  * BluezQt - Asynchronous BlueZ wrapper library
3  *
4  * SPDX-FileCopyrightText: 2014-2015 David Rosca <[email protected]>
5  *
6  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7  */
8 
9 #ifndef BLUEZQT_DEVICESMODEL_H
10 #define BLUEZQT_DEVICESMODEL_H
11 
12 #include <QAbstractListModel>
13 
14 #include "bluezqt_export.h"
15 #include "types.h"
16 
17 namespace BluezQt
18 {
19 class Manager;
20 class Device;
21 
22 /**
23  * @class BluezQt::DevicesModel devicesmodel.h <BluezQt/DevicesModel>
24  *
25  * Model of all devices.
26  *
27  * This class represents a model of all devices.
28  *
29  * Example use in QML code:
30  * @code
31  * import org.kde.bluezqt 1.0 as BluezQt
32  *
33  * ListView {
34  * model: BluezQt.DevicesModel { }
35  * delegate: Text {
36  * text: "%1 (%2)".arg(Name).arg(Address)
37  * }
38  * }
39  * @endcode
40  */
41 class BLUEZQT_EXPORT DevicesModel : public QAbstractListModel
42 {
43  Q_OBJECT
44 
45 public:
46  /**
47  * Device data roles.
48  */
49  enum DeviceRoles {
50  /** UBI of the device (QString) */
51  UbiRole = Qt::UserRole + 100,
52  /** Address of the device (QString) */
53  AddressRole = Qt::UserRole + 101,
54  /** Name of the device (QString) */
55  NameRole = Qt::UserRole + 102,
56  /** Friendly name of the device (QString) */
57  FriendlyNameRole = Qt::UserRole + 103,
58  /** Remote name of the device (QString) */
59  RemoteNameRole = Qt::UserRole + 104,
60  /** Class of the device (quint32) */
61  ClassRole = Qt::UserRole + 105,
62  /** Type of the device (Device::Type) */
63  TypeRole = Qt::UserRole + 106,
64  /** Appearance of the device (quint16) */
65  AppearanceRole = Qt::UserRole + 107,
66  /** Icon name of the device (QString) */
67  IconRole = Qt::UserRole + 108,
68  /** Indicates whether the device is paired (bool) */
69  PairedRole = Qt::UserRole + 109,
70  /** Indicates whether the device is trusted (bool) */
71  TrustedRole = Qt::UserRole + 110,
72  /** Indicates whether the device is blocked (bool) */
73  BlockedRole = Qt::UserRole + 111,
74  /** Indicates whether the device has legacy pairing (bool) */
75  LegacyPairingRole = Qt::UserRole + 112,
76  /** Received Signal Strength Indicator of the device (qint16) */
77  RssiRole = Qt::UserRole + 113,
78  /** Indicates whether the device is connected (bool) */
79  ConnectedRole = Qt::UserRole + 114,
80  /** UUIDs of supported services by the device (QStringList) */
81  UuidsRole = Qt::UserRole + 115,
82  /** Modalias of the device (QString) */
83  ModaliasRole = Qt::UserRole + 116,
84  /** Name of the associated adapter (QString) */
85  AdapterNameRole = Qt::UserRole + 117,
86  /** Address of the associated adapter (QString) */
87  AdapterAddressRole = Qt::UserRole + 118,
88  /** Indicates whether the associated adapter is powered (bool) */
89  AdapterPoweredRole = Qt::UserRole + 119,
90  /** Indicates whether the associated adapter is discoverable (bool) */
91  AdapterDiscoverableRole = Qt::UserRole + 120,
92  /** Indicates whether the associated adapter is pairable (bool) */
93  AdapterPairableRole = Qt::UserRole + 121,
94  /** Indicates whether the associated adapter is discovering (bool) */
95  AdapterDiscoveringRole = Qt::UserRole + 122,
96  /** UUIDs of supported services by the associated adapter (QStringList) */
97  AdapterUuidsRole = Qt::UserRole + 123,
98  /** Last role used by DevicesModel */
99  LastRole = Qt::UserRole + 124,
100  };
101 
102  /**
103  * Creates a new DevicesModel object.
104  *
105  * @param manager manager to be used
106  * @param parent
107  */
108  explicit DevicesModel(Manager *manager, QObject *parent = nullptr);
109 
110  /**
111  * Destroys a DevicesModel object.
112  */
113  ~DevicesModel() override;
114 
115  /**
116  * Reimplemented from QAbstractListModel::roleNames()
117  */
118  QHash<int, QByteArray> roleNames() const override;
119 
120  /**
121  * Reimplemented from QAbstractListModel::rowCount()
122  */
123  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
124 
125  /**
126  * Reimplemented from QAbstractListModel::data()
127  */
128  QVariant data(const QModelIndex &index, int role) const override;
129 
130  /**
131  * Reimplemented from QAbstractListModel::index()
132  */
133  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
134 
135  /**
136  * Returns a device for specified index.
137  *
138  * @param index index in model
139  * @return device object
140  */
141  DevicePtr device(const QModelIndex &index) const;
142 
143 private:
144  class DevicesModelPrivate *const d;
145 
146  friend class DevicesModelPrivate;
147 };
148 
149 } // namespace BluezQt
150 
151 #endif // BLUEZQT_DEVICESMODEL_H
UserRole
DeviceRoles
Device data roles.
Definition: devicesmodel.h:49
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Sep 25 2022 04:19:10 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.