Skip to content

Commit 4a8f3b1

Browse files
committed
2D-model: add option --close to close window on exit
1 parent 54e8ad8 commit 4a8f3b1

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

plugins/robots/checker/twoDModelRunner/main.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,20 @@ int main(int argc, char *argv[])
117117
QCommandLineOption speedOption({"s", "speed"}
118118
, QObject::tr("Speed factor, try from 5 to 20, or even 1000 (at your own risk!).")
119119
, "speed", "0");
120-
QCommandLineOption closeOnSuccessOption("close-on-succes"
120+
QCommandLineOption closeOnSuccessOption("close-on-success"
121121
, QObject::tr("Close the window and exit if the diagram/script"\
122122
" finishes without errors."));
123+
QCommandLineOption closeOnFinishOption("close"
124+
, QObject::tr("Close the window and exit after diagram/script"\
125+
" finishes."));
123126
QCommandLineOption showConsoleOption({"c", "console"}, QObject::tr("Shows robot's console."));
124127
parser.addOption(backgroundOption);
125128
parser.addOption(reportOption);
126129
parser.addOption(trajectoryOption);
127130
parser.addOption(inputOption);
128131
parser.addOption(modeOption);
129132
parser.addOption(speedOption);
133+
parser.addOption(closeOnFinishOption);
130134
parser.addOption(closeOnSuccessOption);
131135
parser.addOption(showConsoleOption);
132136

@@ -144,11 +148,13 @@ int main(int argc, char *argv[])
144148
const QString input = parser.isSet(inputOption) ? parser.value(inputOption) : QString();
145149
const QString mode = parser.isSet(modeOption) ? parser.value(modeOption) : QString("diagram");
146150
const bool closeOnSuccessMode = parser.isSet(closeOnSuccessOption);
151+
const bool closeOnFinishMode = backgroundMode || parser.isSet(closeOnFinishOption);
147152
const bool showConsoleMode = parser.isSet(showConsoleOption);
148153
QScopedPointer<twoDModel::Runner> runner(new twoDModel::Runner(report, trajectory, input, mode));
149154

150155
auto speedFactor = parser.value(speedOption).toInt();
151-
if (!runner->interpret(qrsFile, backgroundMode, speedFactor, closeOnSuccessMode, showConsoleMode)) {
156+
if (!runner->interpret(qrsFile, backgroundMode, speedFactor
157+
, closeOnFinishMode, closeOnSuccessMode, showConsoleMode)) {
152158
return 2;
153159
}
154160

plugins/robots/checker/twoDModelRunner/runner.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ Runner::~Runner()
8888
}
8989

9090
bool Runner::interpret(const QString &saveFile, const bool background
91-
, const int customSpeedFactor, const bool closeOnSuccess, const bool showConsole)
91+
, const int customSpeedFactor, bool closeOnFinish
92+
, const bool closeOnSuccess, const bool showConsole)
9293
{
9394
if (!mProjectManager->open(saveFile)) {
9495
return false;
@@ -108,12 +109,12 @@ bool Runner::interpret(const QString &saveFile, const bool background
108109
}
109110

110111
connect(&mPluginFacade->eventsForKitPlugins(), &kitBase::EventsForKitPluginInterface::interpretationStopped
111-
, this, [this, background, closeOnSuccess](qReal::interpretation::StopReason reason) {
112-
if (background || (closeOnSuccess && reason == qReal::interpretation::StopReason::finised))
112+
, this, [this, closeOnFinish, closeOnSuccess](qReal::interpretation::StopReason reason) {
113+
if (closeOnFinish || (closeOnSuccess && reason == qReal::interpretation::StopReason::finised))
113114
QTimer::singleShot(0, this, &Runner::close);
114115
});
115116

116-
if (background) {
117+
if (closeOnFinish) {
117118
connect(&mPluginFacade->eventsForKitPlugins(), &kitBase::EventsForKitPluginInterface::interpretationErrored
118119
, this, [this]() { QTimer::singleShot(0, this, &Runner::close); });
119120
}

plugins/robots/checker/twoDModelRunner/runner.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ class Runner : public QObject
6767
/// @param speedFactor can be used when not in background mode to tune interpretation speed
6868
/// @param closeOnSuccessMode If true then model will be closed if the program finishes without errors.
6969
/// @param showConsole If true then robot's console will be showed.
70-
bool interpret(const QString &saveFile, bool background, int speedFactor, bool closeOnSuccess, bool showConsole);
70+
bool interpret(const QString &saveFile, bool background, int speedFactor
71+
, bool closeOnFinish, bool closeOnSuccess, bool showConsole);
7172

7273
private slots:
7374
void close();

qrtranslations/fr/plugins/robots/twoDModelRunner_fr.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ In background mode the session will be terminated just after the execution ended
5858
<source>Close the window and exit if the diagram/script finishes without errors.</source>
5959
<translation type="unfinished"></translation>
6060
</message>
61+
<message>
62+
<location line="+3"/>
63+
<source>Close the window and exit after diagram/script finishes.</source>
64+
<translation type="unfinished"></translation>
65+
</message>
6166
<message>
6267
<location line="+2"/>
6368
<source>Shows robot&apos;s console.</source>
@@ -67,7 +72,7 @@ In background mode the session will be terminated just after the execution ended
6772
<context>
6873
<name>twoDModel::Runner</name>
6974
<message>
70-
<location filename="../../../../plugins/robots/checker/twoDModelRunner/runner.cpp" line="+202"/>
75+
<location filename="../../../../plugins/robots/checker/twoDModelRunner/runner.cpp" line="+203"/>
7176
<source>Robot console</source>
7277
<translation type="unfinished"></translation>
7378
</message>

qrtranslations/ru/plugins/robots/twoDModelRunner_ru.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ In background mode the session will be terminated just after the execution ended
5656
<source>Close the window and exit if the diagram/script finishes without errors.</source>
5757
<translation>Закрыть окно если диаграмма/скрипт были выполнены без ошибок.</translation>
5858
</message>
59+
<message>
60+
<location line="+3"/>
61+
<source>Close the window and exit after diagram/script finishes.</source>
62+
<translation type="unfinished"></translation>
63+
</message>
5964
<message>
6065
<location line="+2"/>
6166
<source>Shows robot&apos;s console.</source>
@@ -69,7 +74,7 @@ In background mode the session will be terminated just after the execution ended
6974
<context>
7075
<name>twoDModel::Runner</name>
7176
<message>
72-
<location filename="../../../../plugins/robots/checker/twoDModelRunner/runner.cpp" line="+202"/>
77+
<location filename="../../../../plugins/robots/checker/twoDModelRunner/runner.cpp" line="+203"/>
7378
<source>Robot console</source>
7479
<translation>Консоль робота</translation>
7580
</message>

0 commit comments

Comments
 (0)