summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qbasictimer.h
diff options
context:
space:
mode:
authorSérgio Martins <sergio.martins@kdab.com>2016-03-05 17:45:44 +0000
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2019-05-25 16:37:08 +0000
commit4965b0ed77c7f6d47d30fd8568695cc71d1f690d (patch)
tree69ccfd370ef78ab4a45778dd429dfa8954f19962 /src/corelib/kernel/qbasictimer.h
parentd2c478243264296824d4713c71a9e2633186b5df (diff)
Don't allow to copy QBasicTimer in Qt 6, it would stop the timer
Fixing this in Qt 5 would be BIC. Although it could be okayish, there are many more classes that shouldn't be copyable. I need to go through clazy's output and fix them, and would rather do this noise for Qt 6 and leave Qt 5 alone and purely BIC free. Added a move-ctor and move-assign, as well as swap(), deprecated copy-ctor and copy-assign. The new copy special member functions warn at runtime if they are called. In order to not pollute client code with the warning strings, lock them away by defining the functions out-of-line. [ChangeLog][QtCore][QBasicTimer] QBasicTimer is now a move-only class. Copying is now deprecated and will be removed in Qt 6. [ChangeLog][QtCore][QBasicTimer] Added swap() member and free function. Change-Id: Ic3e6a26f3989d4c8d125c06e8b0b825411c6e106 Done-with: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/corelib/kernel/qbasictimer.h')
-rw-r--r--src/corelib/kernel/qbasictimer.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/corelib/kernel/qbasictimer.h b/src/corelib/kernel/qbasictimer.h
index bfd6ffd125..d3491b247b 100644
--- a/src/corelib/kernel/qbasictimer.h
+++ b/src/corelib/kernel/qbasictimer.h
@@ -51,10 +51,33 @@ class QObject;
class Q_CORE_EXPORT QBasicTimer
{
int id;
+#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
+ Q_DISABLE_COPY(QBasicTimer)
+#elif QT_DEPRECATED_SINCE(5, 14)
+public:
+ // Just here to preserve BC, we can't remove them yet
+ QT_DEPRECATED_X("copy-construction is unsupported; use move-construction instead")
+ QBasicTimer(const QBasicTimer &);
+ QT_DEPRECATED_X("copy-assignment is unsupported; use move-assignment instead")
+ QBasicTimer &operator=(const QBasicTimer &);
+#endif
+
public:
inline QBasicTimer() : id(0) {}
inline ~QBasicTimer() { if (id) stop(); }
+ QBasicTimer(QBasicTimer &&other) noexcept
+ : id{qExchange(other.id, 0)}
+ {}
+
+ QBasicTimer& operator=(QBasicTimer &&other) noexcept
+ {
+ QBasicTimer{std::move(other)}.swap(*this);
+ return *this;
+ }
+
+ void swap(QBasicTimer &other) noexcept { qSwap(id, other.id); }
+
inline bool isActive() const { return id != 0; }
inline int timerId() const { return id; }
@@ -64,6 +87,8 @@ public:
};
Q_DECLARE_TYPEINFO(QBasicTimer, Q_MOVABLE_TYPE);
+inline void swap(QBasicTimer &lhs, QBasicTimer &rhs) noexcept { lhs.swap(rhs); }
+
QT_END_NAMESPACE
#endif // QBASICTIMER_H