Skip to content

Commit

Permalink
Add variables to checker messages (#1602)
Browse files Browse the repository at this point in the history
* Add variables in messages from checker
```xml
            <triggers>
                <success/>
		<message text="We have finished! Score: %myvar%" >
			<replace var="myvar">
				<sum> <!-- this expression is like in the 'setter' tag -->
					<variableValue name="total_score"/>
					<int value="2"/>
				</sum>
			</replace>
		</message>
            </triggers>
        </event>
```
Co-authored-by: IKhonakhbeeva <i.khonakhbeeva@gmail.com>
  • Loading branch information
iakov committed Oct 15, 2022
1 parent 4e94577 commit 61b295f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,13 @@ Trigger ConstraintsParser::parseMessageTag(const QDomElement &element)
return mTriggers.doNothing();
}

return mTriggers.message(element.attribute("text"));
QMap<QString, Value> map;
for (QDomElement replace = element.firstChildElement("replace"); !replace.isNull()
; replace = replace.nextSiblingElement("replace")) {
map.insert(replace.attribute("var"), parseValue(replace.firstChildElement()));
}

return mTriggers.message(element.attribute("text"), map);
}

Trigger ConstraintsParser::parseSuccessTag(const QDomElement &element)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ Trigger TriggersFactory::fail(const QString &message) const
return [this, message]() { emit mStatus.fail(message); };
}

Trigger TriggersFactory::message(const QString &messsage) const
Trigger TriggersFactory::message(const QString &message, const QMap<QString, Value> &replaces) const
{
return [this, messsage]() { emit mStatus.message(messsage); };
return [this, message, replaces]() {
auto resMessage = message;
for (const auto &key: replaces.keys()) {
resMessage.replace("%" + key + "%", replaces[key]().toString());
}
emit mStatus.message(resMessage);
};
}

Trigger TriggersFactory::success(bool deferred) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TriggersFactory
Trigger fail(const QString &message) const;

/// Produces new trigger that sends back to the environment message signal.
Trigger message(const QString &message) const;
Trigger message(const QString &message, const QMap<QString, Value> &replaces) const;

/// Produces new trigger that sends back to the environment sucess signal (i.e. that the program worked correctly
/// and all conditions were satisfied).
Expand Down
4 changes: 2 additions & 2 deletions qrtranslations/fr/plugins/robots/twoDModel_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<message>
<location line="+9"/>
<location line="+12"/>
<location filename="../../../../plugins/robots/common/twoDModel/src/engine/constraints/details/triggersFactory.cpp" line="+85"/>
<location filename="../../../../plugins/robots/common/twoDModel/src/engine/constraints/details/triggersFactory.cpp" line="+91"/>
<location line="+12"/>
<source>No such event: %1</source>
<translation>événement inexistant : %1</translation>
Expand Down Expand Up @@ -84,7 +84,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location line="+237"/>
<location line="+243"/>
<source>Unknown value &quot;%1&quot;.</source>
<translation>Valeur inconnue &quot;%1&quot;.</translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions qrtranslations/ru/plugins/robots/twoDModel_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
<translation>В выражении &quot;using&quot; должен иметься тэг &quot;return&quot;.</translation>
</message>
<message>
<location line="+237"/>
<location line="+243"/>
<source>Unknown value &quot;%1&quot;.</source>
<translation>Неизвестное значение &quot;%1&quot;.</translation>
</message>
Expand Down Expand Up @@ -324,7 +324,7 @@
<message>
<location line="+9"/>
<location line="+12"/>
<location filename="../../../../plugins/robots/common/twoDModel/src/engine/constraints/details/triggersFactory.cpp" line="+85"/>
<location filename="../../../../plugins/robots/common/twoDModel/src/engine/constraints/details/triggersFactory.cpp" line="+91"/>
<location line="+12"/>
<source>No such event: %1</source>
<translation>Нет такого события: %1</translation>
Expand Down

0 comments on commit 61b295f

Please sign in to comment.