summaryrefslogtreecommitdiffstats
path: root/bluetooth/bluetoothmodel.h
diff options
context:
space:
mode:
authorJan-Simon Moeller <jsmoeller@linuxfoundation.org>2019-03-25 13:40:37 +0000
committerGerrit Code Review <gerrit@automotivelinux.org>2019-03-25 13:40:37 +0000
commitf4aad7aee0d23560a9b562057b866ea6762ca3cf (patch)
tree3b55504844060b4c4e69e21b6fbc22cb9f701e91 /bluetooth/bluetoothmodel.h
parent6e0dbd4ae1da3225f62caf17326f08b1a2cb3773 (diff)
parent6a80077e386e8a74940e81268055ff5ea0d97771 (diff)
Merge "libqtappfw: bluetooth: add BluetoothModel support"
Diffstat (limited to 'bluetooth/bluetoothmodel.h')
-rw-r--r--bluetooth/bluetoothmodel.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/bluetooth/bluetoothmodel.h b/bluetooth/bluetoothmodel.h
new file mode 100644
index 0000000..0fc07aa
--- /dev/null
+++ b/bluetooth/bluetoothmodel.h
@@ -0,0 +1,81 @@
+#ifndef BLUETOOTH_MODEL_H
+#define BLUETOOTH_MODEL_H
+
+#include <QAbstractListModel>
+#include <QSortFilterProxyModel>
+#include <QStringList>
+#include <QtQml/QQmlContext>
+#include <QJsonObject>
+
+class BluetoothDevice
+{
+ public:
+ BluetoothDevice(const QString &id,
+ const QString &address,
+ const QString &name,
+ const bool paired,
+ const bool connected);
+ QString id() const;
+ QString address() const;
+ QString name() const;
+ bool paired() const;
+ bool connected() const;
+ void setId(const QString id);
+ void setAddress(const QString address);
+ void setName(const QString name);
+ void setPaired(const bool paired);
+ void setConnected(const bool connected);
+
+ private:
+ QString m_id;
+ QString m_address;
+ QString m_name;
+ bool m_paired;
+ bool m_connected;
+};
+
+class BluetoothModel : public QAbstractListModel
+{
+ Q_OBJECT
+
+ public:
+ enum BluetoothRoles {
+ IdRole = Qt::UserRole + 1,
+ AddressRole,
+ NameRole,
+ PairedRole,
+ ConnectedRole
+ };
+
+ BluetoothModel(QObject *parent = Q_NULLPTR);
+
+ void addDevice(BluetoothDevice *device);
+ void removeDevice(BluetoothDevice *device);
+ void removeAllDevices();
+ BluetoothDevice *getDevice(QString address);
+ BluetoothDevice *updateDeviceProperties(BluetoothDevice *device, QJsonObject data);
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+
+ signals:
+ void propertiesChanged(int connected);
+
+ protected:
+ QHash<int, QByteArray> roleNames() const;
+
+ private:
+ QList<BluetoothDevice *> m_devices;
+ QModelIndex indexOf(BluetoothDevice *device);
+};
+
+class BluetoothModelFilter : public QSortFilterProxyModel
+{
+ Q_OBJECT
+
+ public:
+ BluetoothModelFilter(QObject *parent = nullptr);
+
+ protected:
+ bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
+};
+#endif // BLUETOOTH_MODEL_H