-
Notifications
You must be signed in to change notification settings - Fork 0
/
bluetoothdevicemodel.cpp
71 lines (56 loc) · 1.56 KB
/
bluetoothdevicemodel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "bluetoothdevicemodel.h"
BluetoothDeviceModel::BluetoothDeviceModel(QObject *parent) :
QAbstractItemModel(parent), m_lastNumLeft(0)
{
}
void BluetoothDeviceModel::nameUpdated(const QString& name, const QString& macAddress, int numLeft)
{
BluetoothDevice device;
device.name = name;
device.macAddress = macAddress;
if (numLeft > m_lastNumLeft)
{
// we have started to find devices again
m_totalDevices = numLeft + 1;
emit maximum(m_totalDevices);
m_devices.clear();
}
m_devices.append(device);
emit layoutChanged();
m_lastNumLeft = numLeft;
emit found(m_totalDevices - numLeft);
if (numLeft == 0)
emit devicesFound();
}
int BluetoothDeviceModel::deviceCount() const
{
return m_devices.count();
}
BluetoothDevice BluetoothDeviceModel::deviceAt(int index) const
{
return m_devices[index];
}
QModelIndex BluetoothDeviceModel::index(int row, int column, const QModelIndex & parent) const
{
return createIndex(row, column);
}
QModelIndex BluetoothDeviceModel::parent ( const QModelIndex & index ) const
{
return QModelIndex();
}
int BluetoothDeviceModel::rowCount ( const QModelIndex & parent ) const
{
return m_devices.count();
}
int BluetoothDeviceModel::columnCount ( const QModelIndex & parent ) const
{
return 1;
}
QVariant BluetoothDeviceModel::data ( const QModelIndex & index, int role) const
{
if (role == Qt::DisplayRole)
{
return m_devices[index.row()].name + " " + m_devices[index.row()].macAddress;
}
return QVariant();
}