aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2022-12-04 08:10:55 +0100
committerJarek Kobus <jaroslaw.kobus@qt.io>2022-12-06 06:45:12 +0000
commitb009eff30110397627e4b305ebd43165ea17fae6 (patch)
treefa6152dd6054791716c8866817ec02c90ec2fbef
parent88728a414c823dcd18c5f90866b06d857f0ea96b (diff)
TaskProgress: Add setHalfLifeTimePerTask()
Make it possible to specify expected half-life time per task. Make TaskProgress more fluent (50 Hz). Use exponential interpolation for TaskProgress. Set 30 seconds half-life time for UpdateInfoPlugin. Change-Id: I1b8a147f259caf6a11fbe06afd8cfe6d4606bb02 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: hjk <hjk@qt.io>
-rw-r--r--src/libs/utils/mathutils.cpp6
-rw-r--r--src/plugins/coreplugin/progressmanager/taskprogress.cpp15
-rw-r--r--src/plugins/coreplugin/progressmanager/taskprogress.h1
-rw-r--r--src/plugins/updateinfo/updateinfoplugin.cpp1
4 files changed, 14 insertions, 9 deletions
diff --git a/src/libs/utils/mathutils.cpp b/src/libs/utils/mathutils.cpp
index f1bdc5999c..62882454df 100644
--- a/src/libs/utils/mathutils.cpp
+++ b/src/libs/utils/mathutils.cpp
@@ -24,7 +24,7 @@ int interpolateLinear(int x, int x1, int x2, int y1, int y2)
return y2;
const int numerator = (y2 - y1) * x + x2 * y1 - x1 * y2;
const int denominator = x2 - x1;
- return qRound((double)numerator / denominator);
+ return qRound(double(numerator) / denominator);
}
/*!
@@ -39,7 +39,7 @@ int interpolateTangential(int x, int xHalfLife, int y1, int y2)
return y1;
if (y1 == y2)
return y1;
- const double angle = atan2((double)x, (double)xHalfLife);
+ const double angle = atan2(double(x), double(xHalfLife));
const double result = y1 + (y2 - y1) * angle * 2 / M_PI;
return qRound(result);
}
@@ -56,7 +56,7 @@ int interpolateExponential(int x, int xHalfLife, int y1, int y2)
return y1;
if (y1 == y2)
return y1;
- const double exponent = pow(0.5, (double)x / xHalfLife);
+ const double exponent = pow(0.5, double(x) / xHalfLife);
const double result = y1 + (y2 - y1) * (1.0 - exponent);
return qRound(result);
}
diff --git a/src/plugins/coreplugin/progressmanager/taskprogress.cpp b/src/plugins/coreplugin/progressmanager/taskprogress.cpp
index ba0000a115..2d7509aaab 100644
--- a/src/plugins/coreplugin/progressmanager/taskprogress.cpp
+++ b/src/plugins/coreplugin/progressmanager/taskprogress.cpp
@@ -18,7 +18,7 @@ using namespace Utils;
namespace Core {
static const int ProgressResolution = 100; // 100 discrete values
-static const int TimerInterval = 100; // 100 ms
+static const int TimerInterval = 20; // 20 ms = 50 Hz
class TaskProgressPrivate : public QObject
{
@@ -31,7 +31,6 @@ public:
void updateProgress();
int m_currentTick = 0;
- int m_expectedTime = 1; // 1 second
int m_currentProgress = 0; // from TaskTree (max value = task count)
@@ -40,6 +39,7 @@ public:
QFutureWatcher<void> m_watcher;
QFutureInterface<void> m_futureInterface;
QPointer<FutureProgress> m_futureProgress;
+ int m_halfLifeTimePerTask = 1000; // 1000 ms
QString m_displayName;
FutureProgress::KeepOnFinishType m_keep = FutureProgress::HideOnFinish;
bool m_isSubtitleVisibleInStatusBar = false;
@@ -60,8 +60,6 @@ TaskProgressPrivate::~TaskProgressPrivate()
if (m_futureInterface.isRunning()) {
m_futureInterface.reportCanceled();
m_futureInterface.reportFinished();
- // TODO: should we stop the process? Or just mark the process canceled?
- // What happens to task in progress manager?
}
}
@@ -80,10 +78,10 @@ void TaskProgressPrivate::advanceProgress(int newValue)
void TaskProgressPrivate::updateProgress()
{
- const int halfLife = qRound(1000.0 * m_expectedTime / TimerInterval);
+ const int halfLife = qRound(double(m_halfLifeTimePerTask) / TimerInterval);
const int pMin = ProgressResolution * m_currentProgress;
const int pMax = ProgressResolution * (m_currentProgress + 1);
- const int newValue = MathUtils::interpolateTangential(m_currentTick, halfLife, pMin, pMax);
+ const int newValue = MathUtils::interpolateExponential(m_currentTick, halfLife, pMin, pMax);
m_futureInterface.setProgressValue(newValue);
}
@@ -133,6 +131,11 @@ TaskProgress::TaskProgress(TaskTree *taskTree)
});
}
+void TaskProgress::setHalfLifeTimePerTask(int msecs)
+{
+ d->m_halfLifeTimePerTask = msecs;
+}
+
void TaskProgress::setDisplayName(const QString &name)
{
d->m_displayName = name;
diff --git a/src/plugins/coreplugin/progressmanager/taskprogress.h b/src/plugins/coreplugin/progressmanager/taskprogress.h
index bec4254633..318dc2ab8a 100644
--- a/src/plugins/coreplugin/progressmanager/taskprogress.h
+++ b/src/plugins/coreplugin/progressmanager/taskprogress.h
@@ -20,6 +20,7 @@ class CORE_EXPORT TaskProgress : public QObject
public:
TaskProgress(Utils::TaskTree *taskTree); // Makes TaskProgress a child of task tree
+ void setHalfLifeTimePerTask(int msecs); // 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 83731448cd..bac6122a86 100644
--- a/src/plugins/updateinfo/updateinfoplugin.cpp
+++ b/src/plugins/updateinfo/updateinfoplugin.cpp
@@ -151,6 +151,7 @@ void UpdateInfoPlugin::startCheckForUpdates()
});
connect(d->m_taskTree.get(), &TaskTree::errorOccurred, this, doCleanup);
d->m_progress = new TaskProgress(d->m_taskTree.get());
+ d->m_progress->setHalfLifeTimePerTask(30000); // 30 seconds
d->m_progress->setDisplayName(tr("Checking for Updates"));
d->m_progress->setKeepOnFinish(FutureProgress::KeepOnFinishTillUserInteraction);
d->m_progress->setSubtitleVisibleInStatusBar(true);