forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -24,7 +24,7 @@ int interpolateLinear(int x, int x1, int x2, int y1, int y2)
|
|||||||
return y2;
|
return y2;
|
||||||
const int numerator = (y2 - y1) * x + x2 * y1 - x1 * y2;
|
const int numerator = (y2 - y1) * x + x2 * y1 - x1 * y2;
|
||||||
const int denominator = x2 - x1;
|
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;
|
return y1;
|
||||||
if (y1 == y2)
|
if (y1 == y2)
|
||||||
return y1;
|
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;
|
const double result = y1 + (y2 - y1) * angle * 2 / M_PI;
|
||||||
return qRound(result);
|
return qRound(result);
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ int interpolateExponential(int x, int xHalfLife, int y1, int y2)
|
|||||||
return y1;
|
return y1;
|
||||||
if (y1 == y2)
|
if (y1 == y2)
|
||||||
return y1;
|
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);
|
const double result = y1 + (y2 - y1) * (1.0 - exponent);
|
||||||
return qRound(result);
|
return qRound(result);
|
||||||
}
|
}
|
||||||
|
@@ -18,7 +18,7 @@ using namespace Utils;
|
|||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
static const int ProgressResolution = 100; // 100 discrete values
|
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
|
class TaskProgressPrivate : public QObject
|
||||||
{
|
{
|
||||||
@@ -31,7 +31,6 @@ public:
|
|||||||
void updateProgress();
|
void updateProgress();
|
||||||
|
|
||||||
int m_currentTick = 0;
|
int m_currentTick = 0;
|
||||||
int m_expectedTime = 1; // 1 second
|
|
||||||
|
|
||||||
int m_currentProgress = 0; // from TaskTree (max value = task count)
|
int m_currentProgress = 0; // from TaskTree (max value = task count)
|
||||||
|
|
||||||
@@ -40,6 +39,7 @@ public:
|
|||||||
QFutureWatcher<void> m_watcher;
|
QFutureWatcher<void> m_watcher;
|
||||||
QFutureInterface<void> m_futureInterface;
|
QFutureInterface<void> m_futureInterface;
|
||||||
QPointer<FutureProgress> m_futureProgress;
|
QPointer<FutureProgress> m_futureProgress;
|
||||||
|
int m_halfLifeTimePerTask = 1000; // 1000 ms
|
||||||
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;
|
||||||
@@ -60,8 +60,6 @@ TaskProgressPrivate::~TaskProgressPrivate()
|
|||||||
if (m_futureInterface.isRunning()) {
|
if (m_futureInterface.isRunning()) {
|
||||||
m_futureInterface.reportCanceled();
|
m_futureInterface.reportCanceled();
|
||||||
m_futureInterface.reportFinished();
|
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()
|
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 pMin = ProgressResolution * m_currentProgress;
|
||||||
const int pMax = ProgressResolution * (m_currentProgress + 1);
|
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);
|
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)
|
void TaskProgress::setDisplayName(const QString &name)
|
||||||
{
|
{
|
||||||
d->m_displayName = name;
|
d->m_displayName = name;
|
||||||
|
@@ -20,6 +20,7 @@ class CORE_EXPORT TaskProgress : public QObject
|
|||||||
public:
|
public:
|
||||||
TaskProgress(Utils::TaskTree *taskTree); // Makes TaskProgress a child of task tree
|
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 setDisplayName(const QString &name);
|
||||||
void setKeepOnFinish(FutureProgress::KeepOnFinishType keepType);
|
void setKeepOnFinish(FutureProgress::KeepOnFinishType keepType);
|
||||||
void setSubtitleVisibleInStatusBar(bool visible);
|
void setSubtitleVisibleInStatusBar(bool visible);
|
||||||
|
@@ -151,6 +151,7 @@ void UpdateInfoPlugin::startCheckForUpdates()
|
|||||||
});
|
});
|
||||||
connect(d->m_taskTree.get(), &TaskTree::errorOccurred, this, doCleanup);
|
connect(d->m_taskTree.get(), &TaskTree::errorOccurred, this, doCleanup);
|
||||||
d->m_progress = new TaskProgress(d->m_taskTree.get());
|
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->setDisplayName(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);
|
||||||
|
Reference in New Issue
Block a user