QDeadlineTimer: make the (Qt::TimerType) ctor explicit

Qt::TimerType is not a faithful representation of a QDeadlineTimer.
It's missing the actual deadline, and so should not be allowed to
participate in implicit conversions.

Consider whether you'd like to see such code:

    foo.setTimeout(Qt::PreciseTimer); // HU???

So split the old (TimerType = CoarseTimer) ctor into an explicit
default ctor (applying NSDMI to make it =default'able) and a new
explicit (TimerType) ctor.

[ChangeLog][Potentially Source-Incompatible Changes][QtCore] The
QDeadlineTimer(Qt::TimerType) constructor is no longer implicit. To
keep old source working, wrap the Qt::TimerType argument in
QDeadlineTimer{}. This is backwards-compatible with older Qt versions.

[ChangeLog][QtCore][QDeadlineTimer] The (Qt::TimerType) constructor is
now explicit (was: implicit).

Found in API-review.

Change-Id: I72aaaad5201bd288a6fd6af398573aaa9d0eda5a
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 17f2b6d2e9379d7edaf5acd17a6547ca46b12f2b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-08-18 20:54:14 +02:00 committed by Qt Cherry-pick Bot
parent 281b5154bf
commit f974ea6f86
2 changed files with 6 additions and 3 deletions

View File

@ -131,10 +131,12 @@ static qint64 add_saturate(qint64 t1, Duration1 dur, Durations... extra)
*/
/*!
\fn QDeadlineTimer::QDeadlineTimer()
\fn QDeadlineTimer::QDeadlineTimer(Qt::TimerType timerType)
Constructs an expired QDeadlineTimer object. For this object,
remainingTime() will return 0.
remainingTime() will return 0. If \a timerType is not set, then the object
will use the \l{Qt::CoarseTimer}{coarse} \l{QDeadlineTimer#Timer types}{timer type}.
The timer type \a timerType may be ignored, since the timer is already
expired. Similarly, for optimization purposes, this function will not

View File

@ -26,7 +26,8 @@ public:
enum class ForeverConstant { Forever };
static constexpr ForeverConstant Forever = ForeverConstant::Forever;
constexpr QDeadlineTimer(Qt::TimerType type_ = Qt::CoarseTimer) noexcept
constexpr QDeadlineTimer() noexcept = default;
constexpr explicit QDeadlineTimer(Qt::TimerType type_) noexcept
: type(type_) {}
constexpr QDeadlineTimer(ForeverConstant, Qt::TimerType type_ = Qt::CoarseTimer) noexcept
: t1((std::numeric_limits<qint64>::max)()), type(type_) {}
@ -142,7 +143,7 @@ private:
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
unsigned t2 = 0;
#endif
unsigned type;
unsigned type = Qt::CoarseTimer;
qint64 rawRemainingTimeNSecs() const noexcept;
};