| 1 |
// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 |
|
| 5 |
#ifndef DTIMEDLOOP_H |
| 6 |
#define DTIMEDLOOP_H |
| 7 |
#include <dtkcore_global.h> |
| 8 |
#include <DObject> |
| 9 |
|
| 10 |
#include <QEventLoop> |
| 11 |
|
| 12 |
DCORE_BEGIN_NAMESPACE |
| 13 |
|
| 14 |
class DObject; |
| 15 |
class DTimedLoopPrivate; |
| 16 |
class DTimedLoop : public QEventLoop, public DObject { |
| 17 |
Q_OBJECT |
| 18 |
public: |
| 19 |
explicit DTimedLoop() noexcept; |
| 20 |
explicit DTimedLoop(QObject *parent) noexcept; |
| 21 |
|
| 22 |
~DTimedLoop(); |
| 23 |
|
| 24 |
// 如果是 isRunning 则返回从开始到现在的 exec 执行时间,否则返回上次运行的时间 |
| 25 |
int runningTime(); |
| 26 |
void setTimeDump(bool flag = true); |
| 27 |
|
| 28 |
void exit(int returnCode = 0); |
| 29 |
|
| 30 |
// 方式1:不传定时时间,如果不退出就一直执行,配合 exit 使用 |
| 31 |
// 方式2:传入durationMs 参数的是定时执行的,也能调用 exit 提前退出 |
| 32 |
// 如果传入了 executionName 就会为本次执行设置一个名字,会输出到 log |
| 33 |
// 在执行结束将会打印 exec 的执行时间,可以用 setTimeDump 控制其是否打印 |
| 34 |
int exec(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); |
| 35 |
int exec(int durationMs, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); |
| 36 |
int exec(const QString &executionName, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); |
| 37 |
int exec(int durationMs, const QString &executionName, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); |
| 38 |
|
| 39 |
private: |
| 40 |
Q_DISABLE_COPY(DTimedLoop) |
| 41 |
D_DECLARE_PRIVATE(DTimedLoop) |
| 42 |
}; |
| 43 |
|
| 44 |
DCORE_END_NAMESPACE |
| 45 |
|
| 46 |
#endif // DTIMEDLOOP_H |