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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QTIMER_P_H
#define QTIMER_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of the Qt translation tools. This header file may change from version
// to version without notice, or even be removed.
//
// We mean it.
//
#include "qtimer.h"
#include "qchronotimer.h"
#include "qobject_p.h"
#include "qproperty_p.h"
#include "qttypetraits.h"
QT_BEGIN_NAMESPACE
class QTimerPrivate : public QObjectPrivate
{
public:
QTimerPrivate(QTimer *qq)
: q(qq),
isQTimer(true)
{}
QTimerPrivate(std::chrono::nanoseconds nsec, QChronoTimer *qq)
: intervalDuration(nsec),
q(qq)
{
intervalDuration.notify();
}
static constexpr int INV_TIMER = -1; // invalid timer id
void setIntervalDuration(std::chrono::nanoseconds nsec)
{
if (isQTimer) {
const auto msec = std::chrono::ceil<std::chrono::milliseconds>(nsec);
static_cast<QTimer *>(q)->setInterval(msec);
} else {
static_cast<QChronoTimer *>(q)->setInterval(nsec);
}
}
void setInterval(int msec)
{
Q_ASSERT(isQTimer);
static_cast<QTimer *>(q)->setInterval(msec);
}
bool isActive() const { return id > Qt::TimerId::Invalid; }
Qt::TimerId id = Qt::TimerId::Invalid;
Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QTimerPrivate, int, inter, &QTimerPrivate::setInterval, 0)
Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QTimerPrivate, std::chrono::nanoseconds, intervalDuration,
&QTimerPrivate::setIntervalDuration,
std::chrono::nanoseconds{0})
Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QTimerPrivate, bool, single, false)
Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QTimerPrivate, Qt::TimerType, type, Qt::CoarseTimer)
Q_OBJECT_COMPUTED_PROPERTY(QTimerPrivate, bool, isActiveData, &QTimerPrivate::isActive)
QObject *q;
const bool isQTimer = false; // true if q is a QTimer*
};
QT_END_NAMESPACE
#endif // QTIMER_P_H
|