From cd3c5e4ade561762ca7d113066adf670c0d1106c Mon Sep 17 00:00:00 2001 From: John Preston Date: Sat, 8 Apr 2017 14:25:54 +0300 Subject: [PATCH] Fix build in GCC. GCC doesn't allow using scoped enums in bitfields without warnings. So we use "unsigned" bitfield and a couple of get/set methods. --- Telegram/SourceFiles/base/timer.cpp | 10 +++++----- Telegram/SourceFiles/base/timer.h | 13 ++++++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Telegram/SourceFiles/base/timer.cpp b/Telegram/SourceFiles/base/timer.cpp index a2fe6d764..d7438179e 100644 --- a/Telegram/SourceFiles/base/timer.cpp +++ b/Telegram/SourceFiles/base/timer.cpp @@ -33,8 +33,8 @@ QObject *TimersAdjuster() { Timer::Timer(base::lambda callback) : QObject(nullptr) , _callback(std::move(callback)) , _type(Qt::PreciseTimer) -, _adjusted(false) -, _repeat(Repeat::Interval) { +, _adjusted(false) { + setRepeat(Repeat::Interval); connect(TimersAdjuster(), &QObject::destroyed, this, [this] { adjust(); }, Qt::QueuedConnection); } @@ -42,7 +42,7 @@ void Timer::start(TimeMs timeout, Qt::TimerType type, Repeat repeat) { cancel(); _type = type; - _repeat = repeat; + setRepeat(repeat); _adjusted = false; setTimeout(timeout); _timerId = startTimer(_timeout, _type); @@ -91,9 +91,9 @@ int Timer::timeout() const { } void Timer::timerEvent(QTimerEvent *e) { - if (_repeat == Repeat::Interval) { + if (repeat() == Repeat::Interval) { if (_adjusted) { - start(_timeout, _type, _repeat); + start(_timeout, _type, repeat()); } else { _next = getms(true) + _timeout; } diff --git a/Telegram/SourceFiles/base/timer.h b/Telegram/SourceFiles/base/timer.h index 841182c7f..7835b7faa 100644 --- a/Telegram/SourceFiles/base/timer.h +++ b/Telegram/SourceFiles/base/timer.h @@ -67,7 +67,7 @@ protected: void timerEvent(QTimerEvent *e) override; private: - enum class Repeat { + enum class Repeat : unsigned { Interval = 0, SingleShot = 1, }; @@ -77,6 +77,13 @@ private: void setTimeout(TimeMs timeout); int timeout() const; + void setRepeat(Repeat repeat) { + _repeat = static_cast(repeat); + } + Repeat repeat() const { + return static_cast(_repeat); + } + base::lambda _callback; TimeMs _next = 0; int _timeout = 0; @@ -84,7 +91,7 @@ private: Qt::TimerType _type : 2; bool _adjusted : 1; - Repeat _repeat : 1; + unsigned _repeat : 1; }; @@ -105,4 +112,4 @@ private: }; -} // namespace base \ No newline at end of file +} // namespace base