1// Copyright (C) 2022 The Qt Company Ltd.
2// Copyright (C) 2016 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QSINGLESHOTTIMER_P_H
6#define QSINGLESHOTTIMER_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/qobject.h>
20#include <QtCore/qabstracteventdispatcher.h>
21#include <QtCore/qbasictimer.h>
22#include <QtCore/qcoreevent.h>
23#include <QtCore/qdeadlinetimer.h>
24#include <QtCore/qnamespace.h>
25
26QT_BEGIN_NAMESPACE
27
28namespace QtPrivate {
29class QSlotObjectBase;
30}
31
32class Q_AUTOTEST_EXPORT QSingleShotTimer : public QObject
33{
34 Q_OBJECT
35
36 QBasicTimer timer;
37
38public:
39 // use the same duration type
40 using Duration = QAbstractEventDispatcher::Duration;
41
42 explicit QSingleShotTimer(Duration interval, Qt::TimerType timerType,
43 const QObject *r, const char *member);
44 explicit QSingleShotTimer(Duration interval, Qt::TimerType timerType,
45 const QObject *r, QtPrivate::QSlotObjectBase *slotObj);
46 ~QSingleShotTimer() override;
47
48 void startTimerForReceiver(Duration interval, Qt::TimerType timerType,
49 const QObject *receiver);
50Q_SIGNALS:
51 void timeout();
52
53private:
54 class StartTimerEvent : public QTimerEvent
55 {
56 public:
57 StartTimerEvent(QSingleShotTimer *timer, const QDeadlineTimer &deadline)
58 : QTimerEvent(Qt::TimerId::Invalid), timer(timer), deadline(deadline)
59 {}
60
61 std::unique_ptr<QSingleShotTimer> timer;
62 QDeadlineTimer deadline;
63 };
64
65 void timerFinished();
66 void timerEvent(QTimerEvent *) override;
67};
68
69QT_END_NAMESPACE
70
71#endif // QSINGLESHOTTIMER_P_H
72

source code of qtbase/src/corelib/kernel/qsingleshottimer_p.h