From b2a47036e4aff5683c2bb0a21b8e3906c7af8ef7 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 15 Mar 2018 12:28:20 +0100 Subject: [PATCH] QList -> Devices --- libnymea/plugin/device.cpp | 17 +++++++++++++++++ libnymea/plugin/device.h | 8 ++++++++ libnymea/plugin/deviceplugin.cpp | 2 +- libnymea/plugin/deviceplugin.h | 2 +- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/libnymea/plugin/device.cpp b/libnymea/plugin/device.cpp index 8075f0d1..128443f1 100644 --- a/libnymea/plugin/device.cpp +++ b/libnymea/plugin/device.cpp @@ -240,3 +240,20 @@ void Device::setSetupComplete(const bool &complete) { m_setupComplete = complete; } + +Devices::Devices(const QList &other) +{ + foreach (Device* device, other) { + this->append(device); + } +} + +Device *Devices::findById(const DeviceId &id) +{ + foreach (Device *device, *this) { + if (device->id() == id) { + return device; + } + } + return nullptr; +} diff --git a/libnymea/plugin/device.h b/libnymea/plugin/device.h index 5c76b6d8..69c2479b 100644 --- a/libnymea/plugin/device.h +++ b/libnymea/plugin/device.h @@ -93,4 +93,12 @@ private: bool m_autoCreated = false; }; +class Devices: public QList +{ +public: + Devices() = default; + Devices(const QList &other); + Device* findById(const DeviceId &id); +}; + #endif diff --git a/libnymea/plugin/deviceplugin.cpp b/libnymea/plugin/deviceplugin.cpp index 05483782..8b0cc7db 100644 --- a/libnymea/plugin/deviceplugin.cpp +++ b/libnymea/plugin/deviceplugin.cpp @@ -446,7 +446,7 @@ DeviceManager *DevicePlugin::deviceManager() const } /*! Returns a list of all configured devices belonging to this plugin. */ -QList DevicePlugin::myDevices() const +Devices DevicePlugin::myDevices() const { QList myDeviceClassIds; foreach (const DeviceClass &deviceClass, m_supportedDevices) { diff --git a/libnymea/plugin/deviceplugin.h b/libnymea/plugin/deviceplugin.h index bd5cc94b..47d686b3 100644 --- a/libnymea/plugin/deviceplugin.h +++ b/libnymea/plugin/deviceplugin.h @@ -97,7 +97,7 @@ signals: protected: DeviceManager *deviceManager() const; - QList myDevices() const; + Devices myDevices() const; HardwareManager *hardwareManager() const; Device* findDeviceByParams(const ParamList ¶ms) const;