mirror of https://github.com/nymea/nymea.git
Merge PR #482: Add more "by name" thing methods and c++11 list_initializers for lists
commit
b8e58511b9
|
|
@ -225,6 +225,12 @@ QVariant Thing::paramValue(const ParamTypeId ¶mTypeId) const
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant Thing::paramValue(const QString ¶mName) const
|
||||
{
|
||||
ParamTypeId paramTypeId = m_thingClass.paramTypes().findByName(paramName).id();
|
||||
return paramValue(paramTypeId);
|
||||
}
|
||||
|
||||
/*! Sets the \a value of the \l{Param} with the given \a paramTypeId. */
|
||||
void Thing::setParamValue(const ParamTypeId ¶mTypeId, const QVariant &value)
|
||||
{
|
||||
|
|
@ -238,6 +244,12 @@ void Thing::setParamValue(const ParamTypeId ¶mTypeId, const QVariant &value)
|
|||
m_params = params;
|
||||
}
|
||||
|
||||
void Thing::setParamValue(const QString ¶mName, const QVariant &value)
|
||||
{
|
||||
ParamTypeId paramTypeId = m_thingClass.paramTypes().findByName(paramName).id();
|
||||
setParamValue(paramTypeId, value);
|
||||
}
|
||||
|
||||
ParamList Thing::settings() const
|
||||
{
|
||||
return m_settings;
|
||||
|
|
@ -321,7 +333,7 @@ void Thing::setStates(const States &states)
|
|||
m_states = states;
|
||||
}
|
||||
|
||||
/*! Returns true, a \l{State} with the given \a stateTypeId exists for this thing. */
|
||||
/*! Returns true, a \l{State} with the state given by \a stateTypeId exists for this thing. */
|
||||
bool Thing::hasState(const StateTypeId &stateTypeId) const
|
||||
{
|
||||
foreach (const State &state, m_states) {
|
||||
|
|
@ -332,6 +344,13 @@ bool Thing::hasState(const StateTypeId &stateTypeId) const
|
|||
return false;
|
||||
}
|
||||
|
||||
/*! Finds the \l{State} matching the given \a stateTypeId in this thing and returns the current value. */
|
||||
bool Thing::hasState(const QString &stateName) const
|
||||
{
|
||||
StateTypeId stateTypeId = m_thingClass.stateTypes().findByName(stateName).id();
|
||||
return hasState(stateTypeId);
|
||||
}
|
||||
|
||||
/*! Finds the \l{State} matching the given \a stateTypeId in this thing and returns the current value. */
|
||||
QVariant Thing::stateValue(const StateTypeId &stateTypeId) const
|
||||
{
|
||||
|
|
@ -604,6 +623,13 @@ void Thing::emitEvent(const EventTypeId &eventTypeId, const ParamList ¶ms)
|
|||
emit eventTriggered(Event(eventTypeId, m_id, params));
|
||||
}
|
||||
|
||||
/*! Emits an event from this thing to the system. */
|
||||
void Thing::emitEvent(const QString &eventName, const ParamList ¶ms)
|
||||
{
|
||||
EventTypeId eventTypeId = m_thingClass.eventTypes().findByName(eventName).id();
|
||||
emit eventTriggered(Event(eventTypeId, m_id, params));
|
||||
}
|
||||
|
||||
/*! Returns true if this thing has been auto-created (not created by the user) */
|
||||
bool Thing::autoCreated() const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -119,7 +119,9 @@ public:
|
|||
void setParams(const ParamList ¶ms);
|
||||
|
||||
QVariant paramValue(const ParamTypeId ¶mTypeId) const;
|
||||
QVariant paramValue(const QString ¶mName) const;
|
||||
void setParamValue(const ParamTypeId ¶mName, const QVariant &value);
|
||||
void setParamValue(const QString ¶mName, const QVariant &value);
|
||||
|
||||
Q_INVOKABLE ParamList settings() const;
|
||||
Q_INVOKABLE bool hasSetting(const ParamTypeId ¶mTypeId) const;
|
||||
|
|
@ -132,6 +134,7 @@ public:
|
|||
|
||||
States states() const;
|
||||
bool hasState(const StateTypeId &stateTypeId) const;
|
||||
bool hasState(const QString &stateName) const;
|
||||
void setStates(const States &states);
|
||||
|
||||
Q_INVOKABLE QVariant stateValue(const StateTypeId &stateTypeId) const;
|
||||
|
|
@ -163,6 +166,7 @@ public:
|
|||
|
||||
public slots:
|
||||
void emitEvent(const EventTypeId &eventTypeId, const ParamList ¶ms = ParamList());
|
||||
void emitEvent(const QString &eventName, const ParamList ¶ms = ParamList());
|
||||
|
||||
signals:
|
||||
void stateValueChanged(const StateTypeId &stateTypeId, const QVariant &value, const QVariant &minValue, const QVariant &maxValue);
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ class LIBNYMEA_EXPORT Interfaces: public QList<Interface>
|
|||
public:
|
||||
Interfaces() = default;
|
||||
Interfaces(const QList<Interface> &other);
|
||||
Interfaces(std::initializer_list<Interface> args):QList(args) {}
|
||||
Interface findByName(const QString &name);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ class LIBNYMEA_EXPORT ParamList: public QList<Param>
|
|||
public:
|
||||
ParamList();
|
||||
ParamList(const QList<Param> &other);
|
||||
ParamList(std::initializer_list<Param> args):QList(args) {}
|
||||
Q_INVOKABLE QVariant get(int index);
|
||||
Q_INVOKABLE void put(const QVariant &variant);
|
||||
bool hasParam(const ParamTypeId ¶mTypeId) const;
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ class States: public QList<State>
|
|||
public:
|
||||
States();
|
||||
States(const QList<State> &other);
|
||||
States(std::initializer_list<State> args):QList(args) {}
|
||||
Q_INVOKABLE QVariant get(int index) const;
|
||||
Q_INVOKABLE void put(const QVariant &variant);
|
||||
Q_INVOKABLE QVariant stateValue(const StateTypeId &stateTypeId);
|
||||
|
|
|
|||
Loading…
Reference in New Issue