mirror of https://github.com/nymea/nymea.git
Add a method to filter Devices
parent
7bd863b131
commit
b2228bcf25
|
|
@ -268,3 +268,22 @@ QDebug operator<<(QDebug dbg, Device *device)
|
||||||
dbg.nospace() << ", deviceClassId" << device->deviceClassId() << ")";
|
dbg.nospace() << ", deviceClassId" << device->deviceClassId() << ")";
|
||||||
return dbg.space();
|
return dbg.space();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Filter a Devices list by a parameter. Only Devices having a parameter of the given
|
||||||
|
\a paramTypeId will be returned. If \a value is given and it is not null, only Devices
|
||||||
|
with the given \a paramTypeId and the same \a value will be returned.
|
||||||
|
*/
|
||||||
|
Devices Devices::filterByParam(const ParamTypeId ¶mTypeId, const QVariant &value)
|
||||||
|
{
|
||||||
|
Devices ret;
|
||||||
|
foreach (Device* device, *this) {
|
||||||
|
if (paramTypeId != paramTypeId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!value.isNull() && device->paramValue(paramTypeId) != value) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ret << device;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -96,12 +96,13 @@ private:
|
||||||
|
|
||||||
QDebug operator<<(QDebug dbg, Device *device);
|
QDebug operator<<(QDebug dbg, Device *device);
|
||||||
|
|
||||||
class Devices: public QList<Device*>
|
class LIBNYMEA_EXPORT Devices: public QList<Device*>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Devices() = default;
|
Devices() = default;
|
||||||
Devices(const QList<Device *> &other);
|
Devices(const QList<Device *> &other);
|
||||||
Device* findById(const DeviceId &id);
|
Device* findById(const DeviceId &id);
|
||||||
|
Devices filterByParam(const ParamTypeId ¶mTypeId, const QVariant &value = QVariant());
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue