11
11
#include < QApplication>
12
12
#include < QWidget>
13
13
#include < QtCore/QAbstractEventDispatcher>
14
- #include < QtCore/QThread>
15
14
#include < QtCore/QDir>
15
+ #include < QtCore/QThread>
16
16
17
17
#include " agent_qtmonkey_communication.hpp"
18
18
#include " common.hpp"
24
24
using qt_monkey_agent::Agent;
25
25
using qt_monkey_agent::CustomEventAnalyzer;
26
26
using qt_monkey_agent::PopulateScriptContext;
27
+ using qt_monkey_agent::UserEventsAnalyzer;
27
28
using qt_monkey_agent::Private::CommunicationAgentPart;
28
29
using qt_monkey_agent::Private::PacketTypeForMonkey;
29
30
using qt_monkey_agent::Private::Script;
30
31
using qt_monkey_agent::Private::ScriptRunner;
31
- using qt_monkey_agent::UserEventsAnalyzer;
32
32
using qt_monkey_common::Semaphore;
33
33
34
34
Agent *Agent::gAgent_ = nullptr ;
@@ -57,6 +57,7 @@ class FuncEvent final : public QEvent
57
57
{
58
58
}
59
59
void exec () { func_ (); }
60
+
60
61
private:
61
62
std::function<void ()> func_;
62
63
};
@@ -76,6 +77,7 @@ class EventsReciever final : public QObject
76
77
static_cast <FuncEvent *>(event)->exec ();
77
78
}
78
79
QEvent::Type eventType () const { return eventType_; }
80
+
79
81
private:
80
82
std::atomic<QEvent::Type> eventType_;
81
83
};
@@ -150,14 +152,15 @@ void removeObsolete(const QString &path, unsigned nSteps)
150
152
}
151
153
if (i > nSteps) {
152
154
if (!QFile::remove (entryPath)) {
153
- qWarning (" %s: can not remove '%s'\n " , Q_FUNC_INFO, qPrintable (entryPath));
155
+ qWarning (" %s: can not remove '%s'\n " , Q_FUNC_INFO,
156
+ qPrintable (entryPath));
154
157
}
155
158
} else {
156
159
++i;
157
160
}
158
161
}
159
162
}
160
- }
163
+ } // namespace
161
164
162
165
Agent::Agent (const QKeySequence &showObjectShortcut,
163
166
std::list<CustomEventAnalyzer> customEventAnalyzers,
@@ -221,7 +224,8 @@ void Agent::onRunScriptCommand(const Script &script)
221
224
QString errMsg;
222
225
{
223
226
CurrentScriptContext context (&sr, curScriptRunner_);
224
- DBGPRINT (" %s: scrit file name %s" , Q_FUNC_INFO, qPrintable (script.fileName ()));
227
+ DBGPRINT (" %s: scrit file name %s" , Q_FUNC_INFO,
228
+ qPrintable (script.fileName ()));
225
229
QFileInfo fi (script.fileName ());
226
230
scriptBaseName_ = fi.baseName ();
227
231
sr.runScript (script, errMsg);
@@ -273,12 +277,14 @@ void Agent::scriptCheckPoint()
273
277
if (nSteps > 0 ) {
274
278
removeObsolete (savePath, static_cast <unsigned >(nSteps));
275
279
savePath = QString (" %1%2screenshot_%4_%3.png" )
276
- .arg (savePath).arg (QDir::separator ()).arg (lineno)
277
- .arg (scriptBaseName_);
280
+ .arg (savePath)
281
+ .arg (QDir::separator ())
282
+ .arg (lineno)
283
+ .arg (scriptBaseName_);
278
284
runCodeInGuiThreadSync ([savePath]() -> QString {
279
- saveScreenShot (savePath);
280
- return QString ();
281
- });
285
+ saveScreenShot (savePath);
286
+ return QString ();
287
+ });
282
288
}
283
289
}
284
290
@@ -352,23 +358,23 @@ QString Agent::runCodeInGuiThreadSyncWithTimeout(std::function<QString()> func,
352
358
});
353
359
354
360
for (unsigned int iter = 0 ; nowDialog == wasDialog; ++iter) {
355
- if (waitSem->tryAcquire (
356
- 1 , std::chrono::milliseconds (waitIntervalMsec))) {
361
+ if (waitSem->tryAcquire (1 ,
362
+ std::chrono::milliseconds (waitIntervalMsec))) {
357
363
return *res;
358
364
}
359
365
if ((iter % 10 ) == 0 ) {
360
366
nowDialog = nullptr ;
361
367
runCodeInGuiThreadSync ([&nowDialog] {
362
- nowDialog = qApp->activeModalWidget ();
363
- return QString ();
364
- });
365
- DBGPRINT (" %s: wasDialog %p, nowDialog %p, attempt %d" , Q_FUNC_INFO, wasDialog, nowDialog, attempt);
368
+ nowDialog = qApp->activeModalWidget ();
369
+ return QString ();
370
+ });
371
+ DBGPRINT (" %s: wasDialog %p, nowDialog %p, attempt %d" , Q_FUNC_INFO,
372
+ wasDialog, nowDialog, attempt);
366
373
}
367
374
}
368
375
369
376
for (; attempt < N; ++attempt) {
370
- if (waitSem->tryAcquire (
371
- 1 , std::chrono::milliseconds (waitIntervalMsec)))
377
+ if (waitSem->tryAcquire (1 , std::chrono::milliseconds (waitIntervalMsec)))
372
378
return *res;
373
379
qApp->processEvents (QEventLoop::ExcludeUserInputEvents);
374
380
}
0 commit comments