#ifndef QBLUETOOTHLEUARTDEVICEMODEL_H #define QBLUETOOTHLEUARTDEVICEMODEL_H #include #include #include /*! * \brief The QBluetoothLeUartDeviceModel class can be used to display available devices in a QML ListView. * * Example implementation: * \code{.qml} * import de.itsblue.bluetoothleuart 1.0 * * QBluetoothLeUartClient { * id: ble * Component.onCompleted: { * ble.startScanningForDevices() * } * } * * ListView { * model: ble.availableDevicesModel * * delegate: ItemDelegate { * width: parent.width * * text: name * * onClicked: backend.bleController.connectToDevice(device) * } * } * \endcode */ class QBluetoothLeUartDeviceModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged) public: friend class QBluetoothLeUartClient; enum QBluetoothLeUartDeviceModelRole { NameRole = Qt::DisplayRole, IdRole, AddressRole, DeviceRole }; Q_ENUM(QBluetoothLeUartDeviceModelRole) int rowCount(const QModelIndex & = QModelIndex()) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QHash roleNames() const; protected: QBluetoothLeUartDeviceModel(QList availableDevices, QObject *parent = nullptr); void append(QBluetoothLeUartDevice* device); void remove(int row); void clear(); private: QList availableDevices; signals: void rowCountChanged(); }; #endif // QBLUETOOTHLEUARTDEVICEMODEL_H