diff options
author | Eike Ziller <[email protected]> | 2024-01-19 16:17:01 +0100 |
---|---|---|
committer | Eike Ziller <[email protected]> | 2024-01-22 13:50:46 +0000 |
commit | d53c5344ec66e4f72da817206ba81cdc7b869454 (patch) | |
tree | 4e41a6f4cf8d702508ed5fd4a4732fc1a7e53593 /src/plugins | |
parent | 1a84ae038df0757f44d890ad3d5b2e055d5dda7e (diff) |
ProgressManager: Use std::chrono for timed tasks
It is more descriptive than an int.
Change-Id: I129dc931b7dd137846eb97747a5277911b94e06f
Reviewed-by: Jarek Kobus <[email protected]>
Reviewed-by: Qt CI Bot <[email protected]>
Reviewed-by: <[email protected]>
Diffstat (limited to 'src/plugins')
8 files changed, 56 insertions, 28 deletions
diff --git a/src/plugins/coreplugin/progressmanager/processprogress.cpp b/src/plugins/coreplugin/progressmanager/processprogress.cpp index 9ebd5d35b06..c529bb7329e 100644 --- a/src/plugins/coreplugin/progressmanager/processprogress.cpp +++ b/src/plugins/coreplugin/progressmanager/processprogress.cpp @@ -100,8 +100,10 @@ ProcessProgress::ProcessProgress(Process *process) if (d->m_parser) { d->m_futureProgress = ProgressManager::addTask(d->m_futureInterface.future(), name, id); } else { - d->m_futureProgress = ProgressManager::addTimedTask(d->m_futureInterface, name, id, - d->m_expectedDuration.count()); + d->m_futureProgress = ProgressManager::addTimedTask(d->m_futureInterface, + name, + id, + d->m_expectedDuration); } d->m_futureProgress->setKeepOnFinish(d->m_keep); }); diff --git a/src/plugins/coreplugin/progressmanager/progressmanager.cpp b/src/plugins/coreplugin/progressmanager/progressmanager.cpp index 2b60b62f600..ad5e73ef20c 100644 --- a/src/plugins/coreplugin/progressmanager/progressmanager.cpp +++ b/src/plugins/coreplugin/progressmanager/progressmanager.cpp @@ -37,7 +37,7 @@ static const char kSettingsGroup[] = "Progress"; static const char kDetailsPinned[] = "DetailsPinned"; static const bool kDetailsPinnedDefault = true; -static const int TimerInterval = 100; // 100 ms +static const std::chrono::milliseconds TimerInterval{100}; using namespace Core::Internal; using namespace Utils; @@ -47,10 +47,12 @@ namespace Core { class ProgressTimer : public QObject { public: - ProgressTimer(const QFutureInterfaceBase &futureInterface, int expectedSeconds, QObject *parent) - : QObject(parent), - m_futureInterface(futureInterface), - m_expectedTime(expectedSeconds) + ProgressTimer(const QFutureInterfaceBase &futureInterface, + std::chrono::seconds expectedDuration, + QObject *parent) + : QObject(parent) + , m_futureInterface(futureInterface) + , m_expectedDuration(expectedDuration) { m_futureInterface.setProgressRange(0, 100); m_futureInterface.setProgressValue(0); @@ -64,13 +66,13 @@ private: void handleTimeout() { ++m_currentTime; - const int halfLife = qRound(1000.0 * m_expectedTime / TimerInterval); + const int halfLife = m_expectedDuration / TimerInterval; const int progress = MathUtils::interpolateTangential(m_currentTime, halfLife, 0, 100); m_futureInterface.setProgressValue(progress); } QFutureInterfaceBase m_futureInterface; - int m_expectedTime; + std::chrono::seconds m_expectedDuration; int m_currentTime = 0; QTimer m_timer; }; @@ -774,22 +776,28 @@ FutureProgress *ProgressManager::addTask(const QFuture<void> &future, const QStr \sa addTask */ -FutureProgress *ProgressManager::addTimedTask(const QFutureInterface<void> &futureInterface, const QString &title, - Id type, int expectedSeconds, ProgressFlags flags) +FutureProgress *ProgressManager::addTimedTask(const QFutureInterface<void> &futureInterface, + const QString &title, + Id type, + std::chrono::seconds expectedDuration, + ProgressFlags flags) { QFutureInterface<void> dummy(futureInterface); // Need mutable to access .future() FutureProgress *fp = m_instance->doAddTask(dummy.future(), title, type, flags); - (void) new ProgressTimer(futureInterface, expectedSeconds, fp); + (void) new ProgressTimer(futureInterface, expectedDuration, fp); return fp; } -FutureProgress *ProgressManager::addTimedTask(const QFuture<void> &future, const QString &title, - Id type, int expectedSeconds, ProgressFlags flags) +FutureProgress *ProgressManager::addTimedTask(const QFuture<void> &future, + const QString &title, + Id type, + std::chrono::seconds expectedDuration, + ProgressFlags flags) { QFutureInterface<void> dummyFutureInterface; QFuture<void> dummyFuture = dummyFutureInterface.future(); FutureProgress *fp = m_instance->doAddTask(dummyFuture, title, type, flags); - (void) new ProgressTimer(dummyFutureInterface, expectedSeconds, fp); + (void) new ProgressTimer(dummyFutureInterface, expectedDuration, fp); QFutureWatcher<void> *dummyWatcher = new QFutureWatcher<void>(fp); connect(dummyWatcher, &QFutureWatcher<void>::canceled, dummyWatcher, [future] { diff --git a/src/plugins/coreplugin/progressmanager/progressmanager.h b/src/plugins/coreplugin/progressmanager/progressmanager.h index f59fb0562fd..097d28a9482 100644 --- a/src/plugins/coreplugin/progressmanager/progressmanager.h +++ b/src/plugins/coreplugin/progressmanager/progressmanager.h @@ -11,6 +11,8 @@ #include <QFutureInterfaceBase> #include <QObject> +#include <chrono> + namespace Core { class FutureProgress; @@ -36,10 +38,16 @@ public: static FutureProgress *addTask(const QFuture<void> &future, const QString &title, Utils::Id type, ProgressFlags flags = {}); - static FutureProgress *addTimedTask(const QFutureInterface<void> &fi, const QString &title, - Utils::Id type, int expectedSeconds, ProgressFlags flags = {}); - static FutureProgress *addTimedTask(const QFuture<void> &future, const QString &title, - Utils::Id type, int expectedSeconds, ProgressFlags flags = {}); + static FutureProgress *addTimedTask(const QFutureInterface<void> &fi, + const QString &title, + Utils::Id type, + std::chrono::seconds expectedDuration, + ProgressFlags flags = {}); + static FutureProgress *addTimedTask(const QFuture<void> &future, + const QString &title, + Utils::Id type, + std::chrono::seconds expectedDuration, + ProgressFlags flags = {}); static void setApplicationLabel(const QString &text); public slots: diff --git a/src/plugins/cppeditor/cpptypehierarchy.cpp b/src/plugins/cppeditor/cpptypehierarchy.cpp index 9b907c6e439..a46eafd98b0 100644 --- a/src/plugins/cppeditor/cpptypehierarchy.cpp +++ b/src/plugins/cppeditor/cpptypehierarchy.cpp @@ -226,8 +226,11 @@ void CppTypeHierarchyWidget::perform() m_futureWatcher.setFuture(QFuture<void>(m_future)); m_synchronizer.addFuture(m_future); + using namespace std::chrono_literals; Core::ProgressManager::addTimedTask(m_futureWatcher.future(), - Tr::tr("Evaluating Type Hierarchy"), "TypeHierarchy", 2); + Tr::tr("Evaluating Type Hierarchy"), + "TypeHierarchy", + 2s); } void CppTypeHierarchyWidget::performFromExpression(const QString &expression, const FilePath &filePath) diff --git a/src/plugins/perfprofiler/perfdatareader.cpp b/src/plugins/perfprofiler/perfdatareader.cpp index 4ea37251acc..f5b3c15b10a 100644 --- a/src/plugins/perfprofiler/perfdatareader.cpp +++ b/src/plugins/perfprofiler/perfdatareader.cpp @@ -188,9 +188,11 @@ void PerfDataReader::triggerRecordingStateChange(bool recording) qMin(delay(currentTime) / (1000ll * million), static_cast<qint64>(std::numeric_limits<int>::max()))); - Core::FutureProgress *fp = Core::ProgressManager::addTimedTask( - future(), Tr::tr("Skipping Processing Delay"), - Constants::PerfProfilerTaskSkipDelay, seconds); + Core::FutureProgress *fp + = Core::ProgressManager::addTimedTask(future(), + Tr::tr("Skipping Processing Delay"), + Constants::PerfProfilerTaskSkipDelay, + std::chrono::seconds(seconds)); fp->setToolTip(recording ? Tr::tr("Cancel this to ignore the processing delay and immediately " "start recording.") : diff --git a/src/plugins/perfprofiler/perfprofilertracemanager.cpp b/src/plugins/perfprofiler/perfprofilertracemanager.cpp index 7a3643660c1..609112f8232 100644 --- a/src/plugins/perfprofiler/perfprofilertracemanager.cpp +++ b/src/plugins/perfprofiler/perfprofilertracemanager.cpp @@ -605,9 +605,11 @@ void PerfProfilerTraceManager::loadFromPerfData(const FilePath &filePath, const int fileMegabytes = static_cast<int>( qMin(filePath.fileSize() >> 20, static_cast<qint64>(std::numeric_limits<int>::max()))); - Core::FutureProgress *fp = Core::ProgressManager::addTimedTask( - reader->future(), Tr::tr("Loading Trace Data"), Constants::PerfProfilerTaskLoadPerf, - fileMegabytes); + Core::FutureProgress *fp + = Core::ProgressManager::addTimedTask(reader->future(), + Tr::tr("Loading Trace Data"), + Constants::PerfProfilerTaskLoadPerf, + std::chrono::seconds(fileMegabytes)); connect(fp, &Core::FutureProgress::canceled, reader, [reader]() { reader->stopParser(); diff --git a/src/plugins/projectexplorer/kitmanager.cpp b/src/plugins/projectexplorer/kitmanager.cpp index c32742b4754..ae6755fb00b 100644 --- a/src/plugins/projectexplorer/kitmanager.cpp +++ b/src/plugins/projectexplorer/kitmanager.cpp @@ -482,10 +482,11 @@ void KitManager::showLoadingProgress() if (futureInterface.isRunning()) return; futureInterface.reportStarted(); + using namespace std::chrono_literals; Core::ProgressManager::addTimedTask(futureInterface.future(), Tr::tr("Loading Kits"), "LoadingKitsProgress", - 5); + 5s); connect(instance(), &KitManager::kitsLoaded, []() { futureInterface.reportFinished(); }); } diff --git a/src/plugins/valgrind/valgrindengine.cpp b/src/plugins/valgrind/valgrindengine.cpp index c2324887b66..9cf1d6475d0 100644 --- a/src/plugins/valgrind/valgrindengine.cpp +++ b/src/plugins/valgrind/valgrindengine.cpp @@ -56,7 +56,9 @@ void ValgrindToolRunner::start() return; } - FutureProgress *fp = ProgressManager::addTimedTask(m_progress, progressTitle(), "valgrind", 100); + using namespace std::chrono_literals; + FutureProgress *fp + = ProgressManager::addTimedTask(m_progress, progressTitle(), "valgrind", 100s); connect(fp, &FutureProgress::canceled, this, &ValgrindToolRunner::handleProgressCanceled); connect(fp, &FutureProgress::finished, |