Use std::chrono for TaskProgress::setHalfLifeTimePerTask

It is more descriptive than an int.

Change-Id: I6add6a74850a9976c92509c404edb0c9fc403d21
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Eike Ziller
2024-01-19 12:26:10 +01:00
parent d53c5344ec
commit 52fb6f925b
4 changed files with 13 additions and 8 deletions

View File

@@ -74,7 +74,8 @@ TestRunner::TestRunner()
auto progress = new TaskProgress(taskTree); auto progress = new TaskProgress(taskTree);
progress->setDisplayName(Tr::tr("Running Tests")); progress->setDisplayName(Tr::tr("Running Tests"));
progress->setAutoStopOnCancel(false); progress->setAutoStopOnCancel(false);
progress->setHalfLifeTimePerTask(10000); // 10 seconds using namespace std::chrono_literals;
progress->setHalfLifeTimePerTask(10s);
connect(progress, &TaskProgress::canceled, this, [this, progress] { connect(progress, &TaskProgress::canceled, this, [this, progress] {
// Progress was a child of task tree which is going to be deleted directly. // Progress was a child of task tree which is going to be deleted directly.
// Unwind properly. // Unwind properly.

View File

@@ -21,7 +21,7 @@ using namespace Tasking;
namespace Core { namespace Core {
static const int ProgressResolution = 100; // 100 discrete values 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 class TaskProgressPrivate : public QObject
{ {
@@ -44,7 +44,7 @@ public:
QPointer<FutureProgress> m_futureProgress; QPointer<FutureProgress> m_futureProgress;
Id m_id; Id m_id;
bool m_isAutoStopOnCancel = true; bool m_isAutoStopOnCancel = true;
int m_halfLifeTimePerTask = 1000; // 1000 ms std::chrono::milliseconds m_halfLifeTimePerTask{1000};
QString m_displayName; QString m_displayName;
FutureProgress::KeepOnFinishType m_keep = FutureProgress::HideOnFinish; FutureProgress::KeepOnFinishType m_keep = FutureProgress::HideOnFinish;
bool m_isSubtitleVisibleInStatusBar = false; bool m_isSubtitleVisibleInStatusBar = false;
@@ -83,7 +83,8 @@ void TaskProgressPrivate::advanceProgress(int newValue)
void TaskProgressPrivate::updateProgress() void TaskProgressPrivate::updateProgress()
{ {
const int halfLife = qRound(double(m_halfLifeTimePerTask) / TimerInterval); using double_millis = std::chrono::duration<double, std::milli>;
const int halfLife = qRound(m_halfLifeTimePerTask / double_millis(TimerInterval));
const int pMin = ProgressResolution * m_currentProgress; const int pMin = ProgressResolution * m_currentProgress;
const int pMax = ProgressResolution * (m_currentProgress + 1); const int pMax = ProgressResolution * (m_currentProgress + 1);
const int newValue = MathUtils::interpolateExponential(m_currentTick, halfLife, pMin, pMax); const int newValue = MathUtils::interpolateExponential(m_currentTick, halfLife, pMin, pMax);
@@ -148,9 +149,9 @@ void TaskProgress::setAutoStopOnCancel(bool enable)
d->m_isAutoStopOnCancel = 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) void TaskProgress::setDisplayName(const QString &name)

View File

@@ -9,6 +9,8 @@
#include <QObject> #include <QObject>
#include <chrono>
namespace Tasking { class TaskTree; } namespace Tasking { class TaskTree; }
namespace Core { namespace Core {
@@ -25,7 +27,7 @@ public:
void setId(Utils::Id id); void setId(Utils::Id id);
void setAutoStopOnCancel(bool enable); // Default is true 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 setDisplayName(const QString &name);
void setKeepOnFinish(FutureProgress::KeepOnFinishType keepType); void setKeepOnFinish(FutureProgress::KeepOnFinishType keepType);
void setSubtitleVisibleInStatusBar(bool visible); void setSubtitleVisibleInStatusBar(bool visible);

View File

@@ -121,7 +121,8 @@ void UpdateInfoPlugin::startCheckForUpdates()
const auto onTreeSetup = [this](TaskTree *taskTree) { const auto onTreeSetup = [this](TaskTree *taskTree) {
d->m_progress = new TaskProgress(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->setDisplayName(Tr::tr("Checking for Updates"));
d->m_progress->setKeepOnFinish(FutureProgress::KeepOnFinishTillUserInteraction); d->m_progress->setKeepOnFinish(FutureProgress::KeepOnFinishTillUserInteraction);
d->m_progress->setSubtitleVisibleInStatusBar(true); d->m_progress->setSubtitleVisibleInStatusBar(true);