Index: sources/view/settings/VBluetooth.h =================================================================== diff -u -raa8f2c87c14c68d1fda6da2540d47144990a596c -rb252cd2777aadbce2d04aa32cc275f193de0cf52 --- sources/view/settings/VBluetooth.h (.../VBluetooth.h) (revision aa8f2c87c14c68d1fda6da2540d47144990a596c) +++ sources/view/settings/VBluetooth.h (.../VBluetooth.h) (revision b252cd2777aadbce2d04aa32cc275f193de0cf52) @@ -15,7 +15,7 @@ #pragma once // Qt -#include +#include // Project #include "main.h" // Doxygen : do not remove @@ -33,7 +33,7 @@ * \brief The VBluetooth class * \details View for BluetoothInterface. */ -class VBluetooth : public QObject { +class VBluetooth : public QAbstractListModel { Q_OBJECT // friends @@ -58,14 +58,57 @@ PROPERTY(QString , detailName , "" ) PROPERTY(QString , detailValue , "" ) + + // List Model +public: + enum DataRole { + ToStringRole = Qt::DisplayRole , + AddrRole = Qt::UserRole , + NameRole , + PairRole , + }; + Q_ENUM(DataRole) + +private: + BluetoothDeviceListData _devices {}; + int rowCount(const QModelIndex & = QModelIndex()) const; + void reset(); + QVariant data(const QModelIndex &index, int role) const + { + if (index.row() < rowCount()) + switch (role) { + case ToStringRole : return _devices.at(index.row()).toString(); + case AddrRole : return _devices.at(index.row()).addr; + case NameRole : return _devices.at(index.row()).name; + case PairRole : return _devices.at(index.row()).pair; + default: return QVariant(); + } + return QVariant(); + } + + QHash roleNames() const + { + static const QHash roles { + { ToStringRole, "toString" }, + { AddrRole, "addr" }, + { NameRole, "name" }, + { PairRole, "pair" } + }; + return roles; + } + VIEW_DEC_CLASS(VBluetooth) signals: + void didDeviceSelect(const QString &vAddr, const QString &vName); private slots: - void onStateChange (const Model::MBluetooth &vData); + void onStateChange (const BluetoothData &vData ); + void onDeviceChange (const BluetoothDeviceData &vDevice); - QString toText ( Model::MBluetooth::InterfaceStates vState) const; + void onDeviceSelect(const QString &vAddr, const QString &vName); + + QString toText (Model::MBluetooth::InterfaceStates vState) const; void notify (Model::MBluetooth::InterfaceStates vState); public slots: