QBluetoothLeUart/qbluetoothleuartdevicemodel.h

66 lines
1.5 KiB
C
Raw Normal View History

#ifndef QBLUETOOTHLEUARTDEVICEMODEL_H
#define QBLUETOOTHLEUARTDEVICEMODEL_H
#include <QAbstractListModel>
#include <QObject>
#include <qbluetoothleuartdevice.h>
/*!
* \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
*
* QBluetoothLeUart {
* 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
public:
friend class QBluetoothLeUart;
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<int, QByteArray> roleNames() const;
protected:
QBluetoothLeUartDeviceModel(QList<QBluetoothLeUartDevice*> availableDevices, QObject *parent = nullptr);
void append(QBluetoothLeUartDevice* device);
void remove(int row);
void clear();
private:
QList<QBluetoothLeUartDevice*> availableDevices;
};
#endif // QBLUETOOTHLEUARTDEVICEMODEL_H