diff --git a/src/libs/utils/mathutils.cpp b/src/libs/utils/mathutils.cpp index f1bdc5999c8..62882454df1 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 ba0000a115e..2d7509aaab3 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 m_watcher; QFutureInterface m_futureInterface; QPointer 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 bec4254633b..318dc2ab8a3 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 83731448cd0..bac6122a86c 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);