From 52fb6f925be46448ebb83083505597c6560356b5 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Fri, 19 Jan 2024 12:26:10 +0100 Subject: [PATCH] Use std::chrono for TaskProgress::setHalfLifeTimePerTask It is more descriptive than an int. Change-Id: I6add6a74850a9976c92509c404edb0c9fc403d21 Reviewed-by: Jarek Kobus Reviewed-by: Qt CI Bot --- src/plugins/autotest/testrunner.cpp | 3 ++- .../coreplugin/progressmanager/taskprogress.cpp | 11 ++++++----- src/plugins/coreplugin/progressmanager/taskprogress.h | 4 +++- src/plugins/updateinfo/updateinfoplugin.cpp | 3 ++- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/plugins/autotest/testrunner.cpp b/src/plugins/autotest/testrunner.cpp index 31aeeccdbcb..d5f96fa4758 100644 --- a/src/plugins/autotest/testrunner.cpp +++ b/src/plugins/autotest/testrunner.cpp @@ -74,7 +74,8 @@ TestRunner::TestRunner() auto progress = new TaskProgress(taskTree); progress->setDisplayName(Tr::tr("Running Tests")); progress->setAutoStopOnCancel(false); - progress->setHalfLifeTimePerTask(10000); // 10 seconds + using namespace std::chrono_literals; + progress->setHalfLifeTimePerTask(10s); connect(progress, &TaskProgress::canceled, this, [this, progress] { // Progress was a child of task tree which is going to be deleted directly. // Unwind properly. diff --git a/src/plugins/coreplugin/progressmanager/taskprogress.cpp b/src/plugins/coreplugin/progressmanager/taskprogress.cpp index 7f9de529033..b903b74dcc5 100644 --- a/src/plugins/coreplugin/progressmanager/taskprogress.cpp +++ b/src/plugins/coreplugin/progressmanager/taskprogress.cpp @@ -21,7 +21,7 @@ using namespace Tasking; namespace Core { static const int ProgressResolution = 100; // 100 discrete values -static const int TimerInterval = 20; // 20 ms = 50 Hz +static const std::chrono::milliseconds TimerInterval{20}; // 20 ms = 50 Hz class TaskProgressPrivate : public QObject { @@ -44,7 +44,7 @@ public: QPointer m_futureProgress; Id m_id; bool m_isAutoStopOnCancel = true; - int m_halfLifeTimePerTask = 1000; // 1000 ms + std::chrono::milliseconds m_halfLifeTimePerTask{1000}; QString m_displayName; FutureProgress::KeepOnFinishType m_keep = FutureProgress::HideOnFinish; bool m_isSubtitleVisibleInStatusBar = false; @@ -83,7 +83,8 @@ void TaskProgressPrivate::advanceProgress(int newValue) void TaskProgressPrivate::updateProgress() { - const int halfLife = qRound(double(m_halfLifeTimePerTask) / TimerInterval); + using double_millis = std::chrono::duration; + const int halfLife = qRound(m_halfLifeTimePerTask / double_millis(TimerInterval)); const int pMin = ProgressResolution * m_currentProgress; const int pMax = ProgressResolution * (m_currentProgress + 1); const int newValue = MathUtils::interpolateExponential(m_currentTick, halfLife, pMin, pMax); @@ -148,9 +149,9 @@ void TaskProgress::setAutoStopOnCancel(bool enable) d->m_isAutoStopOnCancel = enable; } -void TaskProgress::setHalfLifeTimePerTask(int msecs) +void TaskProgress::setHalfLifeTimePerTask(std::chrono::milliseconds duration) { - d->m_halfLifeTimePerTask = msecs; + d->m_halfLifeTimePerTask = duration; } void TaskProgress::setDisplayName(const QString &name) diff --git a/src/plugins/coreplugin/progressmanager/taskprogress.h b/src/plugins/coreplugin/progressmanager/taskprogress.h index d82fc433d5e..fbdb84e9c4f 100644 --- a/src/plugins/coreplugin/progressmanager/taskprogress.h +++ b/src/plugins/coreplugin/progressmanager/taskprogress.h @@ -9,6 +9,8 @@ #include +#include + namespace Tasking { class TaskTree; } namespace Core { @@ -25,7 +27,7 @@ public: void setId(Utils::Id id); void setAutoStopOnCancel(bool enable); // Default is true - void setHalfLifeTimePerTask(int msecs); // Default is 1000 ms + void setHalfLifeTimePerTask(std::chrono::milliseconds duration); // Default is 1000 ms void setDisplayName(const QString &name); void setKeepOnFinish(FutureProgress::KeepOnFinishType keepType); void setSubtitleVisibleInStatusBar(bool visible); diff --git a/src/plugins/updateinfo/updateinfoplugin.cpp b/src/plugins/updateinfo/updateinfoplugin.cpp index 8aa8fae6287..a23d6c7cfc2 100644 --- a/src/plugins/updateinfo/updateinfoplugin.cpp +++ b/src/plugins/updateinfo/updateinfoplugin.cpp @@ -121,7 +121,8 @@ void UpdateInfoPlugin::startCheckForUpdates() const auto onTreeSetup = [this](TaskTree *taskTree) { d->m_progress = new TaskProgress(taskTree); - d->m_progress->setHalfLifeTimePerTask(30000); // 30 seconds + using namespace std::chrono_literals; + d->m_progress->setHalfLifeTimePerTask(30s); d->m_progress->setDisplayName(Tr::tr("Checking for Updates")); d->m_progress->setKeepOnFinish(FutureProgress::KeepOnFinishTillUserInteraction); d->m_progress->setSubtitleVisibleInStatusBar(true);