Introduce a device Role

REVIEW: 124067
This commit is contained in:
Aleix Pol 2015-06-11 16:47:53 +02:00
parent b592dc99a0
commit 6ddac08978
2 changed files with 7 additions and 2 deletions

View file

@ -62,6 +62,7 @@ QHash< int, QByteArray > DevicesModel::roleNames() const
QHash<int, QByteArray> 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<QObject*>(device);
default:
return QVariant();
}

View file

@ -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,