Merge PR #305: Allow emitting events from things directly
This commit is contained in:
commit
c369bd15aa
@ -647,6 +647,7 @@ ThingPairingInfo *ThingManagerImplementation::confirmPairing(const PairingTransa
|
|||||||
qCDebug(dcThingManager()) << "Thing added:" << info->thing();
|
qCDebug(dcThingManager()) << "Thing added:" << info->thing();
|
||||||
m_configuredThings.insert(info->thing()->id(), info->thing());
|
m_configuredThings.insert(info->thing()->id(), info->thing());
|
||||||
emit thingAdded(info->thing());
|
emit thingAdded(info->thing());
|
||||||
|
connect(info->thing(), &Thing::eventTriggered, this, &ThingManagerImplementation::onEventTriggered);
|
||||||
} else {
|
} else {
|
||||||
emit thingChanged(info->thing());
|
emit thingChanged(info->thing());
|
||||||
}
|
}
|
||||||
@ -728,9 +729,10 @@ ThingSetupInfo* ThingManagerImplementation::addConfiguredThingInternal(const Thi
|
|||||||
qCDebug(dcThingManager) << "Thing setup complete.";
|
qCDebug(dcThingManager) << "Thing setup complete.";
|
||||||
m_configuredThings.insert(info->thing()->id(), info->thing());
|
m_configuredThings.insert(info->thing()->id(), info->thing());
|
||||||
storeConfiguredThings();
|
storeConfiguredThings();
|
||||||
postSetupThing(info->thing());
|
|
||||||
|
|
||||||
emit thingAdded(info->thing());
|
emit thingAdded(info->thing());
|
||||||
|
connect(info->thing(), &Thing::eventTriggered, this, &ThingManagerImplementation::onEventTriggered);
|
||||||
|
postSetupThing(info->thing());
|
||||||
});
|
});
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
@ -1560,6 +1562,8 @@ void ThingManagerImplementation::loadConfiguredThings()
|
|||||||
m_configuredThings.insert(thing->id(), thing);
|
m_configuredThings.insert(thing->id(), thing);
|
||||||
|
|
||||||
emit thingAdded(thing);
|
emit thingAdded(thing);
|
||||||
|
|
||||||
|
connect(thing, &Thing::eventTriggered, this, &ThingManagerImplementation::onEventTriggered);
|
||||||
}
|
}
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
@ -1710,7 +1714,7 @@ void ThingManagerImplementation::onAutoThingsAppeared(const ThingDescriptors &th
|
|||||||
storeConfiguredThings();
|
storeConfiguredThings();
|
||||||
|
|
||||||
emit thingAdded(info->thing());
|
emit thingAdded(info->thing());
|
||||||
|
connect(info->thing(), &Thing::eventTriggered, this, &ThingManagerImplementation::onEventTriggered);
|
||||||
postSetupThing(info->thing());
|
postSetupThing(info->thing());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -385,6 +385,12 @@ QString Thing::setupDisplayMessage() const
|
|||||||
return m_setupDisplayMessage;
|
return m_setupDisplayMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Emits an event from this thing to the system. */
|
||||||
|
void Thing::emitEvent(const EventTypeId &eventTypeId, const ParamList ¶ms)
|
||||||
|
{
|
||||||
|
emit eventTriggered(Event(eventTypeId, m_id, params));
|
||||||
|
}
|
||||||
|
|
||||||
/*! Returns true if this thing has been auto-created (not created by the user) */
|
/*! Returns true if this thing has been auto-created (not created by the user) */
|
||||||
bool Thing::autoCreated() const
|
bool Thing::autoCreated() const
|
||||||
{
|
{
|
||||||
|
|||||||
@ -37,6 +37,7 @@
|
|||||||
#include "types/thingclass.h"
|
#include "types/thingclass.h"
|
||||||
#include "types/state.h"
|
#include "types/state.h"
|
||||||
#include "types/param.h"
|
#include "types/param.h"
|
||||||
|
#include "types/event.h"
|
||||||
#include "types/browseritem.h"
|
#include "types/browseritem.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
@ -127,10 +128,10 @@ public:
|
|||||||
bool hasState(const StateTypeId &stateTypeId) const;
|
bool hasState(const StateTypeId &stateTypeId) const;
|
||||||
void setStates(const States &states);
|
void setStates(const States &states);
|
||||||
|
|
||||||
QVariant stateValue(const StateTypeId &stateTypeId) const;
|
Q_INVOKABLE QVariant stateValue(const StateTypeId &stateTypeId) const;
|
||||||
void setStateValue(const StateTypeId &stateTypeId, const QVariant &value);
|
Q_INVOKABLE void setStateValue(const StateTypeId &stateTypeId, const QVariant &value);
|
||||||
|
|
||||||
State state(const StateTypeId &stateTypeId) const;
|
Q_INVOKABLE State state(const StateTypeId &stateTypeId) const;
|
||||||
|
|
||||||
ThingId parentId() const;
|
ThingId parentId() const;
|
||||||
void setParentId(const ThingId &parentId);
|
void setParentId(const ThingId &parentId);
|
||||||
@ -143,11 +144,15 @@ public:
|
|||||||
ThingError setupError() const;
|
ThingError setupError() const;
|
||||||
QString setupDisplayMessage() const;
|
QString setupDisplayMessage() const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void emitEvent(const EventTypeId &eventTypeId, const ParamList ¶ms = ParamList());
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void stateValueChanged(const StateTypeId &stateTypeId, const QVariant &value);
|
void stateValueChanged(const StateTypeId &stateTypeId, const QVariant &value);
|
||||||
void settingChanged(const ParamTypeId ¶mTypeId, const QVariant &value);
|
void settingChanged(const ParamTypeId ¶mTypeId, const QVariant &value);
|
||||||
void nameChanged();
|
void nameChanged();
|
||||||
void setupStatusChanged();
|
void setupStatusChanged();
|
||||||
|
void eventTriggered(const Event &event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class ThingManager;
|
friend class ThingManager;
|
||||||
|
|||||||
@ -853,10 +853,8 @@ void IntegrationPluginMock::triggerEvent(const EventTypeId &id)
|
|||||||
|
|
||||||
Thing *device = m_daemons.key(daemon);
|
Thing *device = m_daemons.key(daemon);
|
||||||
|
|
||||||
Event event(id, device->id());
|
qCDebug(dcMock) << "Emitting event " << id;
|
||||||
|
device->emitEvent(id);
|
||||||
qCDebug(dcMock) << "Emitting event " << event.eventTypeId();
|
|
||||||
emit emitEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntegrationPluginMock::onDisappear()
|
void IntegrationPluginMock::onDisappear()
|
||||||
|
|||||||
Reference in New Issue
Block a user