QVariant NearbyDevicesModel::data(const QModelIndex &index, int role) const
{
- /**if (role == NearbyDevicesModelRoles::name)
+
+ if(!index.isValid() || index.row() < 0)
{
- QString rowData;
- if(index.row() < devices.size())
- {
- rowData = deviceAliasMap[devices[index.row()]];
- }
- return QVariant(rowData);
+ qDebug()<<"invalid index"<<index.row();
+ return QVariant();
}
- else if (role == NearbyDevicesModelRoles::address)
+
+ QString roleName = roleNames()[role];
+ QMetaObject object = NearbyItem::staticMetaObject;
+
+ for(int i=0; i<object.propertyCount(); i++)
{
- QString rowData;
- if(index.row() < devices.size())
+ if(object.property(i).name() == roleName)
{
- rowData = devices[index.row()];
+
+ return object.property(i).read(devices[index.row()]);
+ }
- return QVariant(rowData);
+ }*/
+
+ QString roleName = roleNames()[role];
+ QMetaObject object = NearbyItem::staticMetaObject;
+
+ for(int i=0; i<object.propertyCount(); i++)
+ {
+ if(object.property(i).name() == roleName)
+ {
+ return object.property(i).read(devices[index.row()]);
}
}