Merge PR #482: Add more "by name" thing methods and c++11 list_initializers for lists
This commit is contained in:
commit
b8e58511b9
@ -225,6 +225,12 @@ QVariant Thing::paramValue(const ParamTypeId ¶mTypeId) const
|
|||||||
return QVariant();
|
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. */
|
/*! Sets the \a value of the \l{Param} with the given \a paramTypeId. */
|
||||||
void Thing::setParamValue(const ParamTypeId ¶mTypeId, const QVariant &value)
|
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;
|
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
|
ParamList Thing::settings() const
|
||||||
{
|
{
|
||||||
return m_settings;
|
return m_settings;
|
||||||
@ -321,7 +333,7 @@ void Thing::setStates(const States &states)
|
|||||||
m_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
|
bool Thing::hasState(const StateTypeId &stateTypeId) const
|
||||||
{
|
{
|
||||||
foreach (const State &state, m_states) {
|
foreach (const State &state, m_states) {
|
||||||
@ -332,6 +344,13 @@ bool Thing::hasState(const StateTypeId &stateTypeId) const
|
|||||||
return false;
|
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. */
|
/*! Finds the \l{State} matching the given \a stateTypeId in this thing and returns the current value. */
|
||||||
QVariant Thing::stateValue(const StateTypeId &stateTypeId) const
|
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));
|
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) */
|
/*! Returns true if this thing has been auto-created (not created by the user) */
|
||||||
bool Thing::autoCreated() const
|
bool Thing::autoCreated() const
|
||||||
{
|
{
|
||||||
|
|||||||
@ -119,7 +119,9 @@ public:
|
|||||||
void setParams(const ParamList ¶ms);
|
void setParams(const ParamList ¶ms);
|
||||||
|
|
||||||
QVariant paramValue(const ParamTypeId ¶mTypeId) const;
|
QVariant paramValue(const ParamTypeId ¶mTypeId) const;
|
||||||
|
QVariant paramValue(const QString ¶mName) const;
|
||||||
void setParamValue(const ParamTypeId ¶mName, const QVariant &value);
|
void setParamValue(const ParamTypeId ¶mName, const QVariant &value);
|
||||||
|
void setParamValue(const QString ¶mName, const QVariant &value);
|
||||||
|
|
||||||
Q_INVOKABLE ParamList settings() const;
|
Q_INVOKABLE ParamList settings() const;
|
||||||
Q_INVOKABLE bool hasSetting(const ParamTypeId ¶mTypeId) const;
|
Q_INVOKABLE bool hasSetting(const ParamTypeId ¶mTypeId) const;
|
||||||
@ -132,6 +134,7 @@ public:
|
|||||||
|
|
||||||
States states() const;
|
States states() const;
|
||||||
bool hasState(const StateTypeId &stateTypeId) const;
|
bool hasState(const StateTypeId &stateTypeId) const;
|
||||||
|
bool hasState(const QString &stateName) const;
|
||||||
void setStates(const States &states);
|
void setStates(const States &states);
|
||||||
|
|
||||||
Q_INVOKABLE QVariant stateValue(const StateTypeId &stateTypeId) const;
|
Q_INVOKABLE QVariant stateValue(const StateTypeId &stateTypeId) const;
|
||||||
@ -163,6 +166,7 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void emitEvent(const EventTypeId &eventTypeId, const ParamList ¶ms = ParamList());
|
void emitEvent(const EventTypeId &eventTypeId, const ParamList ¶ms = ParamList());
|
||||||
|
void emitEvent(const QString &eventName, const ParamList ¶ms = ParamList());
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void stateValueChanged(const StateTypeId &stateTypeId, const QVariant &value, const QVariant &minValue, const QVariant &maxValue);
|
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:
|
public:
|
||||||
Interfaces() = default;
|
Interfaces() = default;
|
||||||
Interfaces(const QList<Interface> &other);
|
Interfaces(const QList<Interface> &other);
|
||||||
|
Interfaces(std::initializer_list<Interface> args):QList(args) {}
|
||||||
Interface findByName(const QString &name);
|
Interface findByName(const QString &name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -68,6 +68,7 @@ class LIBNYMEA_EXPORT ParamList: public QList<Param>
|
|||||||
public:
|
public:
|
||||||
ParamList();
|
ParamList();
|
||||||
ParamList(const QList<Param> &other);
|
ParamList(const QList<Param> &other);
|
||||||
|
ParamList(std::initializer_list<Param> args):QList(args) {}
|
||||||
Q_INVOKABLE QVariant get(int index);
|
Q_INVOKABLE QVariant get(int index);
|
||||||
Q_INVOKABLE void put(const QVariant &variant);
|
Q_INVOKABLE void put(const QVariant &variant);
|
||||||
bool hasParam(const ParamTypeId ¶mTypeId) const;
|
bool hasParam(const ParamTypeId ¶mTypeId) const;
|
||||||
|
|||||||
@ -84,6 +84,7 @@ class States: public QList<State>
|
|||||||
public:
|
public:
|
||||||
States();
|
States();
|
||||||
States(const QList<State> &other);
|
States(const QList<State> &other);
|
||||||
|
States(std::initializer_list<State> args):QList(args) {}
|
||||||
Q_INVOKABLE QVariant get(int index) const;
|
Q_INVOKABLE QVariant get(int index) const;
|
||||||
Q_INVOKABLE void put(const QVariant &variant);
|
Q_INVOKABLE void put(const QVariant &variant);
|
||||||
Q_INVOKABLE QVariant stateValue(const StateTypeId &stateTypeId);
|
Q_INVOKABLE QVariant stateValue(const StateTypeId &stateTypeId);
|
||||||
|
|||||||
Reference in New Issue
Block a user