File: dtimedloop.h

package info (click to toggle)
dtkcore 5.7.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,728 kB
  • sloc: cpp: 22,021; ansic: 183; python: 68; xml: 58; makefile: 27; sh: 15
file content (46 lines) | stat: -rw-r--r-- 1,604 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#ifndef DTIMEDLOOP_H
#define DTIMEDLOOP_H
#include <dtkcore_global.h>
#include <DObject>

#include <QEventLoop>

DCORE_BEGIN_NAMESPACE

class DObject;
class DTimedLoopPrivate;
class DTimedLoop : public QEventLoop,  public DObject {
    Q_OBJECT
public:
    explicit DTimedLoop() noexcept;
    explicit DTimedLoop(QObject *parent) noexcept;

    ~DTimedLoop();

    // 如果是 isRunning 则返回从开始到现在的 exec 执行时间,否则返回上次运行的时间
    int runningTime();
    void setTimeDump(bool flag = true);

    void exit(int returnCode = 0);

    // 方式1:不传定时时间,如果不退出就一直执行,配合 exit 使用
    // 方式2:传入durationMs 参数的是定时执行的,也能调用 exit 提前退出
    // 如果传入了 executionName 就会为本次执行设置一个名字,会输出到 log
    // 在执行结束将会打印 exec 的执行时间,可以用 setTimeDump 控制其是否打印
    int exec(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
    int exec(int durationMs, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
    int exec(const QString &executionName, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
    int exec(int durationMs, const QString &executionName, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);

private:
    Q_DISABLE_COPY(DTimedLoop)
    D_DECLARE_PRIVATE(DTimedLoop)
};

DCORE_END_NAMESPACE

#endif // DTIMEDLOOP_H