From 6ddac08978acf01a97994b6b5ba786014807b7c0 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Thu, 11 Jun 2015 16:47:53 +0200 Subject: [PATCH] Introduce a device Role REVIEW: 124067 --- interfaces/devicesmodel.cpp | 5 ++++- interfaces/devicesmodel.h | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/interfaces/devicesmodel.cpp b/interfaces/devicesmodel.cpp index 90f0b5b0b..4935755fa 100644 --- a/interfaces/devicesmodel.cpp +++ b/interfaces/devicesmodel.cpp @@ -62,6 +62,7 @@ QHash< int, QByteArray > DevicesModel::roleNames() const QHash names = QAbstractItemModel::roleNames(); names.insert(IdModelRole, "deviceId"); names.insert(IconNameRole, "iconName"); + names.insert(DeviceRole, "device"); return names; } @@ -200,7 +201,7 @@ QVariant DevicesModel::data(const QModelIndex& index, int role) const return QVariant(); } - const DeviceDbusInterface* device = m_deviceList[index.row()]; + DeviceDbusInterface* device = m_deviceList[index.row()]; //This function gets called lots of times, producing lots of dbus calls. Add a cache? switch (role) { @@ -228,6 +229,8 @@ QVariant DevicesModel::data(const QModelIndex& index, int role) const } case IconNameRole: return device->statusIconName(); + case DeviceRole: + return QVariant::fromValue(device); default: return QVariant(); } diff --git a/interfaces/devicesmodel.h b/interfaces/devicesmodel.h index e8c1d9e16..d86a35c8d 100644 --- a/interfaces/devicesmodel.h +++ b/interfaces/devicesmodel.h @@ -44,8 +44,10 @@ public: IconModelRole = Qt::DecorationRole, StatusModelRole = Qt::InitialSortOrderRole, IdModelRole = Qt::UserRole, - IconNameRole + IconNameRole, + DeviceRole }; + Q_ENUMS(ModelRoles); enum StatusFlag { StatusUnknown = 0x00, StatusPaired = 0x01,