Rename DeviceDiscovery to ThingDiscovery

This commit is contained in:
Michael Zanetti 2021-01-13 12:11:01 +01:00
parent 94483e92c5
commit 9a08e50ae3
4 changed files with 34 additions and 34 deletions

View File

@ -39,7 +39,7 @@
#include "deviceclassesproxy.h" #include "deviceclassesproxy.h"
#include "devicesproxy.h" #include "devicesproxy.h"
#include "pluginsproxy.h" #include "pluginsproxy.h"
#include "devicediscovery.h" #include "thingdiscovery.h"
#include "interfacesmodel.h" #include "interfacesmodel.h"
#include "rulemanager.h" #include "rulemanager.h"
#include "models/rulesfiltermodel.h" #include "models/rulesfiltermodel.h"
@ -199,8 +199,8 @@ void registerQmlTypes() {
qmlRegisterUncreatableType<DeviceClass>(uri, 1, 0, "DeviceClass", "Can't create this in QML. Get it from the DeviceClasses."); qmlRegisterUncreatableType<DeviceClass>(uri, 1, 0, "DeviceClass", "Can't create this in QML. Get it from the DeviceClasses.");
qmlRegisterUncreatableType<DeviceClasses>(uri, 1, 0, "DeviceClasses", "Can't create this in QML. Get it from the DeviceManager."); qmlRegisterUncreatableType<DeviceClasses>(uri, 1, 0, "DeviceClasses", "Can't create this in QML. Get it from the DeviceManager.");
qmlRegisterType<DeviceClassesProxy>(uri, 1, 0, "DeviceClassesProxy"); qmlRegisterType<DeviceClassesProxy>(uri, 1, 0, "DeviceClassesProxy");
qmlRegisterType<DeviceDiscovery>(uri, 1, 0, "DeviceDiscovery"); qmlRegisterType<ThingDiscovery>(uri, 1, 0, "DeviceDiscovery");
qmlRegisterType<DeviceDiscovery>(uri, 1, 0, "ThingDiscovery"); qmlRegisterType<ThingDiscovery>(uri, 1, 0, "ThingDiscovery");
qmlRegisterType<DeviceDiscoveryProxy>(uri, 1, 0, "DeviceDiscoveryProxy"); qmlRegisterType<DeviceDiscoveryProxy>(uri, 1, 0, "DeviceDiscoveryProxy");
qmlRegisterType<DeviceDiscoveryProxy>(uri, 1, 0, "ThingDiscoveryProxy"); qmlRegisterType<DeviceDiscoveryProxy>(uri, 1, 0, "ThingDiscoveryProxy");
qmlRegisterUncreatableType<DeviceDescriptor>(uri, 1, 0, "DeviceDescriptor", "Get it from DeviceDiscovery"); qmlRegisterUncreatableType<DeviceDescriptor>(uri, 1, 0, "DeviceDescriptor", "Get it from DeviceDiscovery");

View File

@ -115,7 +115,7 @@ SOURCES += \
$${PWD}/devicesproxy.cpp \ $${PWD}/devicesproxy.cpp \
$${PWD}/deviceclasses.cpp \ $${PWD}/deviceclasses.cpp \
$${PWD}/deviceclassesproxy.cpp \ $${PWD}/deviceclassesproxy.cpp \
$${PWD}/devicediscovery.cpp \ $${PWD}/thingdiscovery.cpp \
$${PWD}/models/packagesfiltermodel.cpp \ $${PWD}/models/packagesfiltermodel.cpp \
$${PWD}/models/taglistmodel.cpp \ $${PWD}/models/taglistmodel.cpp \
$${PWD}/scripting/codecompletion.cpp \ $${PWD}/scripting/codecompletion.cpp \
@ -260,7 +260,7 @@ HEADERS += \
$${PWD}/devicesproxy.h \ $${PWD}/devicesproxy.h \
$${PWD}/deviceclasses.h \ $${PWD}/deviceclasses.h \
$${PWD}/deviceclassesproxy.h \ $${PWD}/deviceclassesproxy.h \
$${PWD}/devicediscovery.h \ $${PWD}/thingdiscovery.h \
$${PWD}/models/packagesfiltermodel.h \ $${PWD}/models/packagesfiltermodel.h \
$${PWD}/models/taglistmodel.h \ $${PWD}/models/taglistmodel.h \
$${PWD}/scripting/codecompletion.h \ $${PWD}/scripting/codecompletion.h \

View File

@ -28,22 +28,22 @@
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "devicediscovery.h" #include "thingdiscovery.h"
#include "engine.h" #include "engine.h"
DeviceDiscovery::DeviceDiscovery(QObject *parent) : ThingDiscovery::ThingDiscovery(QObject *parent) :
QAbstractListModel(parent) QAbstractListModel(parent)
{ {
} }
int DeviceDiscovery::rowCount(const QModelIndex &parent) const int ThingDiscovery::rowCount(const QModelIndex &parent) const
{ {
Q_UNUSED(parent) Q_UNUSED(parent)
return m_foundDevices.count(); return m_foundDevices.count();
} }
QVariant DeviceDiscovery::data(const QModelIndex &index, int role) const QVariant ThingDiscovery::data(const QModelIndex &index, int role) const
{ {
switch (role) { switch (role) {
case RoleId: case RoleId:
@ -59,7 +59,7 @@ QVariant DeviceDiscovery::data(const QModelIndex &index, int role) const
return QVariant(); return QVariant();
} }
QHash<int, QByteArray> DeviceDiscovery::roleNames() const QHash<int, QByteArray> ThingDiscovery::roleNames() const
{ {
QHash<int, QByteArray> roles; QHash<int, QByteArray> roles;
roles.insert(RoleId, "id"); roles.insert(RoleId, "id");
@ -69,7 +69,7 @@ QHash<int, QByteArray> DeviceDiscovery::roleNames() const
return roles; return roles;
} }
void DeviceDiscovery::discoverDevices(const QUuid &deviceClassId, const QVariantList &discoveryParams) void ThingDiscovery::discoverThings(const QUuid &deviceClassId, const QVariantList &discoveryParams)
{ {
if (m_busy) { if (m_busy) {
qWarning() << "Busy... not restarting discovery"; qWarning() << "Busy... not restarting discovery";
@ -94,13 +94,13 @@ void DeviceDiscovery::discoverDevices(const QUuid &deviceClassId, const QVariant
if (!discoveryParams.isEmpty()) { if (!discoveryParams.isEmpty()) {
params.insert("discoveryParams", discoveryParams); params.insert("discoveryParams", discoveryParams);
} }
m_engine->jsonRpcClient()->sendCommand("Devices.GetDiscoveredDevices", params, this, "discoverDevicesResponse"); m_engine->jsonRpcClient()->sendCommand("Devices.GetDiscoveredDevices", params, this, "discoverThingsResponse");
m_busy = true; m_busy = true;
m_displayMessage.clear(); m_displayMessage.clear();
emit busyChanged(); emit busyChanged();
} }
DeviceDescriptor *DeviceDiscovery::get(int index) const DeviceDescriptor *ThingDiscovery::get(int index) const
{ {
if (index < 0 || index >= m_foundDevices.count()) { if (index < 0 || index >= m_foundDevices.count()) {
return nullptr; return nullptr;
@ -108,12 +108,12 @@ DeviceDescriptor *DeviceDiscovery::get(int index) const
return m_foundDevices.at(index); return m_foundDevices.at(index);
} }
Engine *DeviceDiscovery::engine() const Engine *ThingDiscovery::engine() const
{ {
return m_engine; return m_engine;
} }
void DeviceDiscovery::setEngine(Engine *engine) void ThingDiscovery::setEngine(Engine *engine)
{ {
if (m_engine != engine) { if (m_engine != engine) {
m_engine = engine; m_engine = engine;
@ -121,19 +121,19 @@ void DeviceDiscovery::setEngine(Engine *engine)
} }
} }
bool DeviceDiscovery::busy() const bool ThingDiscovery::busy() const
{ {
return m_busy; return m_busy;
} }
QString DeviceDiscovery::displayMessage() const QString ThingDiscovery::displayMessage() const
{ {
return m_displayMessage; return m_displayMessage;
} }
void DeviceDiscovery::discoverDevicesResponse(int /*commandId*/, const QVariantMap &params) void ThingDiscovery::discoverThingsResponse(int /*commandId*/, const QVariantMap &params)
{ {
// qDebug() << "response received" << params; qDebug() << "response received" << params;
QVariantList descriptors = params.value("deviceDescriptors").toList(); QVariantList descriptors = params.value("deviceDescriptors").toList();
foreach (const QVariant &descriptorVariant, descriptors) { foreach (const QVariant &descriptorVariant, descriptors) {
qDebug() << "Found device. Descriptor:" << descriptorVariant; qDebug() << "Found device. Descriptor:" << descriptorVariant;
@ -159,7 +159,7 @@ void DeviceDiscovery::discoverDevicesResponse(int /*commandId*/, const QVariantM
emit busyChanged(); emit busyChanged();
} }
bool DeviceDiscovery::contains(const QUuid &deviceDescriptorId) const bool ThingDiscovery::contains(const QUuid &deviceDescriptorId) const
{ {
foreach (DeviceDescriptor *descriptor, m_foundDevices) { foreach (DeviceDescriptor *descriptor, m_foundDevices) {
if (descriptor->id() == deviceDescriptorId) { if (descriptor->id() == deviceDescriptorId) {
@ -211,19 +211,19 @@ DeviceDiscoveryProxy::DeviceDiscoveryProxy(QObject *parent):
} }
DeviceDiscovery *DeviceDiscoveryProxy::deviceDiscovery() const ThingDiscovery *DeviceDiscoveryProxy::deviceDiscovery() const
{ {
return m_deviceDiscovery; return m_deviceDiscovery;
} }
void DeviceDiscoveryProxy::setDeviceDiscovery(DeviceDiscovery *deviceDiscovery) void DeviceDiscoveryProxy::setDeviceDiscovery(ThingDiscovery *deviceDiscovery)
{ {
if (m_deviceDiscovery != deviceDiscovery) { if (m_deviceDiscovery != deviceDiscovery) {
m_deviceDiscovery = deviceDiscovery; m_deviceDiscovery = deviceDiscovery;
setSourceModel(deviceDiscovery); setSourceModel(deviceDiscovery);
emit deviceDiscoveryChanged(); emit deviceDiscoveryChanged();
emit countChanged(); emit countChanged();
connect(m_deviceDiscovery, &DeviceDiscovery::countChanged, this, &DeviceDiscoveryProxy::countChanged); connect(m_deviceDiscovery, &ThingDiscovery::countChanged, this, &DeviceDiscoveryProxy::countChanged);
invalidateFilter(); invalidateFilter();
} }
} }

View File

@ -28,8 +28,8 @@
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef DEVICEDISCOVERY_H #ifndef THINGDISCOVERY_H
#define DEVICEDISCOVERY_H #define THINGDISCOVERY_H
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QUuid> #include <QUuid>
@ -60,7 +60,7 @@ private:
Params *m_params = nullptr; Params *m_params = nullptr;
}; };
class DeviceDiscovery : public QAbstractListModel class ThingDiscovery : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(Engine* engine READ engine WRITE setEngine) Q_PROPERTY(Engine* engine READ engine WRITE setEngine)
@ -75,14 +75,14 @@ public:
RoleDescription RoleDescription
}; };
DeviceDiscovery(QObject *parent = nullptr); ThingDiscovery(QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override; QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
Q_INVOKABLE void discoverDevices(const QUuid &deviceClassId, const QVariantList &discoveryParams = {}); Q_INVOKABLE void discoverThings(const QUuid &thingClassId, const QVariantList &discoveryParams = {});
Q_INVOKABLE DeviceDescriptor* get(int index) const; Q_INVOKABLE DeviceDescriptor* get(int index) const;
@ -93,7 +93,7 @@ public:
QString displayMessage() const; QString displayMessage() const;
private slots: private slots:
void discoverDevicesResponse(int commandId, const QVariantMap &params); void discoverThingsResponse(int commandId, const QVariantMap &params);
signals: signals:
void busyChanged(); void busyChanged();
@ -113,7 +113,7 @@ class DeviceDiscoveryProxy: public QSortFilterProxyModel
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(int count READ rowCount NOTIFY countChanged) Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
Q_PROPERTY(DeviceDiscovery* deviceDiscovery READ deviceDiscovery WRITE setDeviceDiscovery NOTIFY deviceDiscoveryChanged) Q_PROPERTY(ThingDiscovery* deviceDiscovery READ deviceDiscovery WRITE setDeviceDiscovery NOTIFY deviceDiscoveryChanged)
Q_PROPERTY(bool showAlreadyAdded READ showAlreadyAdded WRITE setShowAlreadyAdded NOTIFY showAlreadyAddedChanged) Q_PROPERTY(bool showAlreadyAdded READ showAlreadyAdded WRITE setShowAlreadyAdded NOTIFY showAlreadyAddedChanged)
Q_PROPERTY(bool showNew READ showNew WRITE setShowNew NOTIFY showNewChanged) Q_PROPERTY(bool showNew READ showNew WRITE setShowNew NOTIFY showNewChanged)
Q_PROPERTY(QUuid filterDeviceId READ filterDeviceId WRITE setFilterDeviceId NOTIFY filterDeviceIdChanged) Q_PROPERTY(QUuid filterDeviceId READ filterDeviceId WRITE setFilterDeviceId NOTIFY filterDeviceIdChanged)
@ -121,8 +121,8 @@ class DeviceDiscoveryProxy: public QSortFilterProxyModel
public: public:
DeviceDiscoveryProxy(QObject *parent = nullptr); DeviceDiscoveryProxy(QObject *parent = nullptr);
DeviceDiscovery* deviceDiscovery() const; ThingDiscovery* deviceDiscovery() const;
void setDeviceDiscovery(DeviceDiscovery* deviceDiscovery); void setDeviceDiscovery(ThingDiscovery* deviceDiscovery);
bool showAlreadyAdded() const; bool showAlreadyAdded() const;
void setShowAlreadyAdded(bool showAlreadyAdded); void setShowAlreadyAdded(bool showAlreadyAdded);
@ -146,10 +146,10 @@ protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
private: private:
DeviceDiscovery* m_deviceDiscovery = nullptr; ThingDiscovery* m_deviceDiscovery = nullptr;
bool m_showAlreadyAdded = false; bool m_showAlreadyAdded = false;
bool m_showNew = true; bool m_showNew = true;
QUuid m_filterDeviceId; QUuid m_filterDeviceId;
}; };
#endif // DEVICEDISCOVERY_H #endif // THINGDISCOVERY_H