From 4a20dda27259fad1468370860162b8f22ca53072 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 21 Aug 2018 11:11:56 +0200 Subject: Add QBluetoothDeviceDiscoveryAgent::deviceUpdated signal For iBeacons and such, it's normal to keep discovering indefinitely, while the advertisement can sometimes carry changing payload data. This signal helps keep the UI up-to-date. Changed setManufacturerData to return a bool indicating whether the data was really modified or not, to avoid sending deviceUpdated in case it was not changed. For convenience QBluetoothDeviceInfo::manufacturerData() was added. WinRT and Apple platforms do not emit the new signal yet and relevant TODO items were added. Done-with: Shawn Rutledge Task-number: QTBUG-46008 Task-number: QTBUG-69747 Change-Id: I6d6b373f6cc5ee3dd6af2ad05d8640dbd25c5d6a Reviewed-by: Shawn Rutledge Reviewed-by: Oliver Wolff Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothdeviceinfo.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/bluetooth/qbluetoothdeviceinfo.cpp') diff --git a/src/bluetooth/qbluetoothdeviceinfo.cpp b/src/bluetooth/qbluetoothdeviceinfo.cpp index 11a60565..bd3b9c00 100644 --- a/src/bluetooth/qbluetoothdeviceinfo.cpp +++ b/src/bluetooth/qbluetoothdeviceinfo.cpp @@ -71,6 +71,20 @@ QT_BEGIN_NAMESPACE \value UncategorizedDevice A device that does not fit into any of the other device classes. */ +/*! + \enum QBluetoothDeviceInfo::Field + + This enum is used in conjuntion with the \l deviceUpdated() signal and indicates the field + that changed. + + \value None None of the values changed. + \value RSSI The \l rssi() value of the device changed. + \value ManufacturerData The \l manufacturerData() field changed + \value All Matches every possible field. + + \since 5.12 +*/ + /*! \enum QBluetoothDeviceInfo::MinorMiscellaneousClass @@ -598,20 +612,38 @@ QVector QBluetoothDeviceInfo::manufacturerIds() const */ QByteArray QBluetoothDeviceInfo::manufacturerData(quint16 manufacturerId) const { + // TODO Currently not implemented on WinRT Q_D(const QBluetoothDeviceInfo); return d->manufacturerData.value(manufacturerId); } /*! Sets the advertised manufacturer \a data for the given \a manufacturerId. + Returns true if it was inserted or changed, false if it was already known. \sa manufacturerData, \since 5.12 */ -void QBluetoothDeviceInfo::setManufacturerData(quint16 manufacturerId, const QByteArray &data) +bool QBluetoothDeviceInfo::setManufacturerData(quint16 manufacturerId, const QByteArray &data) { Q_D(QBluetoothDeviceInfo); + const auto it = d->manufacturerData.find(manufacturerId); + if (it != d->manufacturerData.end() && *it == data) + return false; d->manufacturerData.insert(manufacturerId, data); + return true; +} + +/*! + Returns the complete set of all manufacturer data. + + \sa setManufacturerData + \since 5.12 +*/ +QHash QBluetoothDeviceInfo::manufacturerData() const +{ + Q_D(const QBluetoothDeviceInfo); + return d->manufacturerData; } /*! -- cgit v1.2.3