Merge PR #355: Add paramValue() methods to Action and Event

pull/175/head
Jenkins nymea 2020-12-21 18:00:48 +01:00
commit 2c94506867
4 changed files with 26 additions and 2 deletions

View File

@ -102,7 +102,7 @@ void Action::setParams(const ParamList &params)
m_params = params;
}
/*! Returns the parameter of this Action with a cetrain \a paramTypeId. */
/*! Returns the parameter for the given \a paramTypeId. The returned \l{Param} will be invalid if this Action does not have such a \l{Param}. */
Param Action::param(const ParamTypeId &paramTypeId) const
{
foreach (const Param &param, m_params) {
@ -113,6 +113,17 @@ Param Action::param(const ParamTypeId &paramTypeId) const
return Param(ParamTypeId(), QString());
}
/*! Returns the parameter value for the given \a paramTypeId. The returned \l{QVariant} will be null if this Action does not have such a \l{Param}. */
QVariant Action::paramValue(const ParamTypeId &paramTypeId) const
{
foreach (const Param &param, m_params) {
if (param.paramTypeId() == paramTypeId) {
return param.value();
}
}
return QVariant();
}
/*! Gives an indication of the origin of this action.
Normally a plugin should treat all actions the same. There might be
rare exceptions tho:

View File

@ -64,6 +64,7 @@ public:
ParamList params() const;
void setParams(const ParamList &params);
Param param(const ParamTypeId &paramTypeId) const;
QVariant paramValue(const ParamTypeId &paramTypeId) const;
TriggeredBy triggeredBy() const;

View File

@ -98,7 +98,7 @@ void Event::setParams(const ParamList &params)
m_params = params;
}
/*! Returns the parameter of this Event with the given \a paramTypeId. */
/*! Returns the parameter for the given \a paramTypeId. The returned \l{Param} will be invalid if this Event does not have such a \l{Param}. */
Param Event::param(const ParamTypeId &paramTypeId) const
{
foreach (const Param &param, m_params) {
@ -109,6 +109,17 @@ Param Event::param(const ParamTypeId &paramTypeId) const
return Param(paramTypeId);
}
/*! Returns the parameter value for the given \a paramTypeId. The returned \l{QVariant} will be null if this Event does not have such a \l{Param}. */
QVariant Event::paramValue(const ParamTypeId &paramTypeId) const
{
foreach (const Param &param, m_params) {
if (param.paramTypeId() == paramTypeId) {
return param.value();
}
}
return QVariant();
}
/*! Returns true if this event is autogenerated by a state change. */
bool Event::isStateChangeEvent() const
{

View File

@ -59,6 +59,7 @@ public:
ParamList params() const;
void setParams(const ParamList &params);
Param param(const ParamTypeId &paramTypeId) const;
QVariant paramValue(const ParamTypeId &paramTypeId) const;
bool operator ==(const Event &other) const;