9#include "devicesmodel.h"
16class DevicesModelPrivate :
public QObject
19 explicit DevicesModelPrivate(DevicesModel *qq);
23 void deviceAdded(DevicePtr device);
24 void deviceRemoved(DevicePtr device);
25 void deviceChanged(DevicePtr device);
26 void adapterChanged(AdapterPtr adapter);
33DevicesModelPrivate::DevicesModelPrivate(DevicesModel *qq)
40void DevicesModelPrivate::init()
42 m_devices = m_manager->devices();
44 connect(m_manager, &Manager::deviceAdded,
this, &DevicesModelPrivate::deviceAdded);
45 connect(m_manager, &Manager::deviceRemoved,
this, &DevicesModelPrivate::deviceRemoved);
46 connect(m_manager, &Manager::deviceChanged,
this, &DevicesModelPrivate::deviceChanged);
47 connect(m_manager, &Manager::adapterChanged,
this, &DevicesModelPrivate::adapterChanged);
50void DevicesModelPrivate::deviceAdded(DevicePtr device)
52 q->beginInsertRows(
QModelIndex(), m_devices.size(), m_devices.size());
53 m_devices.append(device);
57void DevicesModelPrivate::deviceRemoved(DevicePtr device)
59 int offset = m_devices.indexOf(device);
60 Q_ASSERT(offset >= 0);
63 m_devices.removeAt(offset);
67void DevicesModelPrivate::deviceChanged(DevicePtr device)
69 int offset = m_devices.indexOf(device);
70 Q_ASSERT(offset >= 0);
73 Q_EMIT q->dataChanged(idx, idx);
76void DevicesModelPrivate::adapterChanged(AdapterPtr adapter)
78 const auto devices = adapter->devices();
79 for (
const DevicePtr &device : devices) {
80 deviceChanged(device);
86 , d(new DevicesModelPrivate(this))
88 d->m_manager = manager;
98 roles[
UbiRole] = QByteArrayLiteral(
"Ubi");
100 roles[
NameRole] = QByteArrayLiteral(
"Name");
103 roles[
ClassRole] = QByteArrayLiteral(
"Class");
104 roles[
TypeRole] = QByteArrayLiteral(
"Type");
106 roles[
IconRole] = QByteArrayLiteral(
"Icon");
107 roles[
PairedRole] = QByteArrayLiteral(
"Paired");
111 roles[
RssiRole] = QByteArrayLiteral(
"Rssi");
113 roles[
UuidsRole] = QByteArrayLiteral(
"Uuids");
131 return d->m_devices.size();
147 return dev->address();
151 return dev->friendlyName();
153 return dev->remoteName();
155 return dev->deviceClass();
159 return dev->appearance();
163 return dev->isPaired();
165 return dev->isTrusted();
167 return dev->isBlocked();
169 return dev->hasLegacyPairing();
173 return dev->isConnected();
177 return dev->modalias();
179 return dev->adapter()->name();
181 return dev->adapter()->address();
183 return dev->adapter()->isPowered();
185 return dev->adapter()->isDiscoverable();
187 return dev->adapter()->isPairable();
189 return dev->adapter()->isDiscovering();
191 return dev->adapter()->uuids();
210 return d->m_devices.at(
index.
row());
215#include "moc_devicesmodel.cpp"
@ AdapterNameRole
Name of the associated adapter (QString)
@ LegacyPairingRole
Indicates whether the device has legacy pairing (bool)
@ NameRole
Name of the device (QString)
@ AdapterDiscoveringRole
Indicates whether the associated adapter is discovering (bool)
@ IconRole
Icon name of the device (QString)
@ AdapterPairableRole
Indicates whether the associated adapter is pairable (bool)
@ FriendlyNameRole
Friendly name of the device (QString)
@ RemoteNameRole
Remote name of the device (QString)
@ AdapterAddressRole
Address of the associated adapter (QString)
@ TypeRole
Type of the device (Device::Type)
@ UbiRole
UBI of the device (QString)
@ RssiRole
Received Signal Strength Indicator of the device (qint16)
@ ConnectedRole
Indicates whether the device is connected (bool)
@ PairedRole
Indicates whether the device is paired (bool)
@ ModaliasRole
Modalias of the device (QString)
@ AdapterDiscoverableRole
Indicates whether the associated adapter is discoverable (bool)
@ ClassRole
Class of the device (quint32)
@ AddressRole
Address of the device (QString)
@ AdapterUuidsRole
UUIDs of supported services by the associated adapter (QStringList)
@ UuidsRole
UUIDs of supported services by the device (QStringList)
@ AdapterPoweredRole
Indicates whether the associated adapter is powered (bool)
@ AppearanceRole
Appearance of the device (quint16)
@ TrustedRole
Indicates whether the device is trusted (bool)
@ BlockedRole
Indicates whether the device is blocked (bool)
~DevicesModel() override
Destroys a DevicesModel object.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Reimplemented from QAbstractListModel::index()
QVariant data(const QModelIndex &index, int role) const override
Reimplemented from QAbstractListModel::data()
QHash< int, QByteArray > roleNames() const override
Reimplemented from QAbstractListModel::roleNames()
DevicePtr device(const QModelIndex &index) const
Returns a device for specified index.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Reimplemented from QAbstractListModel::rowCount()
QModelIndex createIndex(int row, int column, const void *ptr) const const
bool hasIndex(int row, int column, const QModelIndex &parent) const const
virtual QHash< int, QByteArray > roleNames() const const
bool isValid() const const
QObject * parent() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)