From 5ba2e7752c478a386de6c6cf06adb6f9cf7ee79e Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Wed, 20 Mar 2019 14:22:57 -0700 Subject: libqtappfw: bluetooth: add BluetoothModel support Switch from using single threaded and incorrect QML processing of ListViews to using models provided from libqtappfw Bug-AGL: SPEC-2270 SPEC-2290 Change-Id: I83f02ab104a18ade95dfd172902e32a808c3d897 Signed-off-by: Matt Ranostay --- bluetooth/bluetoothmodel.h | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 bluetooth/bluetoothmodel.h (limited to 'bluetooth/bluetoothmodel.h') 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 +#include +#include +#include +#include + +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 roleNames() const; + + private: + QList 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 -- cgit 1.2.3-korg