3
3
#include < qcontainerfwd.h>
4
4
#include < qhash.h>
5
5
#include < qobject.h>
6
+ #include < qproperty.h>
6
7
#include < qqmlintegration.h>
7
8
#include < qtmetamacros.h>
8
9
@@ -22,18 +23,21 @@ class Bluez: public QObject {
22
23
public:
23
24
[[nodiscard]] ObjectModel<BluetoothAdapter>* adapters () { return &this ->mAdapters ; }
24
25
[[nodiscard]] ObjectModel<BluetoothDevice>* devices () { return &this ->mDevices ; }
25
- [[nodiscard]] BluetoothAdapter* defaultAdapter () const ;
26
26
27
27
[[nodiscard]] BluetoothAdapter* adapter (const QString& path) {
28
28
return this ->mAdapterMap .value (path);
29
29
}
30
30
31
31
static Bluez* instance ();
32
32
33
+ signals:
34
+ void defaultAdapterChanged ();
35
+
33
36
private slots:
34
37
void
35
38
onInterfacesAdded (const QDBusObjectPath& path, const DBusObjectManagerInterfaces& interfaces);
36
39
void onInterfacesRemoved (const QDBusObjectPath& path, const QStringList& interfaces);
40
+ void updateDefaultAdapter ();
37
41
38
42
private:
39
43
explicit Bluez ();
@@ -44,14 +48,17 @@ private slots:
44
48
QHash<QString, BluetoothDevice*> mDeviceMap ;
45
49
ObjectModel<BluetoothAdapter> mAdapters {this };
46
50
ObjectModel<BluetoothDevice> mDevices {this };
51
+
52
+ public:
53
+ Q_OBJECT_BINDABLE_PROPERTY (Bluez, BluetoothAdapter*, bDefaultAdapter, &Bluez::defaultAdapterChanged);
47
54
};
48
55
49
56
// /! Bluetooth manager
50
57
// / Provides access to bluetooth devices and adapters.
51
58
class BluezQml : public QObject {
52
59
Q_OBJECT;
53
60
// / The default bluetooth adapter. Usually there is only one.
54
- Q_PROPERTY (BluetoothAdapter* defaultAdapter READ defaultAdapter CONSTANT );
61
+ Q_PROPERTY (BluetoothAdapter* defaultAdapter READ default NOTIFY defaultAdapterChanged BINDABLE bindableDefaultAdapter );
55
62
QSDOC_TYPE_OVERRIDE (ObjectModel<qs::bluetooth::BluetoothAdapter>*);
56
63
// / A list of all bluetooth adapters. See @@defaultAdapter for the default.
57
64
Q_PROPERTY (UntypedObjectModel* adapters READ adapters CONSTANT);
@@ -62,8 +69,11 @@ class BluezQml: public QObject {
62
69
QML_NAMED_ELEMENT (Bluetooth);
63
70
QML_SINGLETON;
64
71
72
+ signals:
73
+ void defaultAdapterChanged ();
74
+
65
75
public:
66
- explicit BluezQml (QObject* parent = nullptr ): QObject(parent) {}
76
+ explicit BluezQml ();
67
77
68
78
[[nodiscard]] static ObjectModel<BluetoothAdapter>* adapters () {
69
79
return Bluez::instance ()->adapters ();
@@ -73,8 +83,8 @@ class BluezQml: public QObject {
73
83
return Bluez::instance ()->devices ();
74
84
}
75
85
76
- [[nodiscard]] static BluetoothAdapter* defaultAdapter () {
77
- return Bluez::instance ()->defaultAdapter () ;
86
+ [[nodiscard]] static QBindable< BluetoothAdapter*> bindableDefaultAdapter () {
87
+ return & Bluez::instance ()->bDefaultAdapter ;
78
88
}
79
89
};
80
90
0 commit comments