From a8453418ccc346e2dd1b51dabd70f26c08e12ab1 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sat, 21 Nov 2020 20:15:31 +0100 Subject: [PATCH] Add paramValue() convenience functions to be in line with stateValue() api --- libnymea/types/action.cpp | 13 ++++++++++++- libnymea/types/action.h | 1 + libnymea/types/event.cpp | 13 ++++++++++++- libnymea/types/event.h | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/libnymea/types/action.cpp b/libnymea/types/action.cpp index d9c43a2e..b6cb1bd6 100644 --- a/libnymea/types/action.cpp +++ b/libnymea/types/action.cpp @@ -102,7 +102,7 @@ void Action::setParams(const ParamList ¶ms) 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 ¶mTypeId) const { foreach (const Param ¶m, m_params) { @@ -113,6 +113,17 @@ Param Action::param(const ParamTypeId ¶mTypeId) 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 ¶mTypeId) const +{ + foreach (const Param ¶m, 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: diff --git a/libnymea/types/action.h b/libnymea/types/action.h index 6e6cef58..042a34e9 100644 --- a/libnymea/types/action.h +++ b/libnymea/types/action.h @@ -64,6 +64,7 @@ public: ParamList params() const; void setParams(const ParamList ¶ms); Param param(const ParamTypeId ¶mTypeId) const; + QVariant paramValue(const ParamTypeId ¶mTypeId) const; TriggeredBy triggeredBy() const; diff --git a/libnymea/types/event.cpp b/libnymea/types/event.cpp index c38655d5..da3e687f 100644 --- a/libnymea/types/event.cpp +++ b/libnymea/types/event.cpp @@ -98,7 +98,7 @@ void Event::setParams(const ParamList ¶ms) 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 ¶mTypeId) const { foreach (const Param ¶m, m_params) { @@ -109,6 +109,17 @@ Param Event::param(const ParamTypeId ¶mTypeId) 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 ¶mTypeId) const +{ + foreach (const Param ¶m, 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 { diff --git a/libnymea/types/event.h b/libnymea/types/event.h index cb323633..93590b89 100644 --- a/libnymea/types/event.h +++ b/libnymea/types/event.h @@ -59,6 +59,7 @@ public: ParamList params() const; void setParams(const ParamList ¶ms); Param param(const ParamTypeId ¶mTypeId) const; + QVariant paramValue(const ParamTypeId ¶mTypeId) const; bool operator ==(const Event &other) const;