/*! * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file VBluetooth.h * \author (last) Behrouz NematiPour * \date (last) 8/23/2021 * \author (original) Behrouz NematiPour * \date (original) 8/23/2021 * */ #pragma once // Qt #include // Project #include "main.h" // Doxygen : do not remove #include "VView.h" #include "MAdjustHDSerialNumberResponse.h" #include "MBluetooth.h" #include "MUIBloodPressureData.h" // forward declarations class tst_views; namespace View { /*! * \brief The VBluetooth class * \details View for BluetoothInterface. */ class VBluetooth : public QAbstractListModel { Q_OBJECT // friends friend class ::tst_views; PROPERTY(bool , isInvalid , true ) // chose isInvalid instead of isValid for performance reasons to avoid multi call when it is valid. PROPERTY(QString , notification , "" ) PROPERTY(QString , localName , "" ) PROPERTY(QString , localAddr , "" ) PROPERTY(bool , scanEnabled , false ) PROPERTY(QString , deviceName , "" ) PROPERTY(QString , deviceAddr , "" ) PROPERTY(QString , devicePin , "" ) PROPERTY(quint8 , devicePair , 0 ) PROPERTY(qint16 , error , 0 ) PROPERTY(QString , detailAddr , "" ) 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 BluetoothData &vData ); void onDeviceChange (const BluetoothDeviceData &vDevice); void onDeviceSelect(const QString &vAddr, const QString &vName); QString toText (Model::MBluetooth::InterfaceStates vState) const; void notify (Model::MBluetooth::InterfaceStates vState); public slots: void doScan (); void doConnectToDevice (); void doDiscoverServices (); void doEnableNotify (); void doReadMeasurements (); void doReadInformation (); }; }