From 5ff9f32fb251ec5c40c10bea2ab125b2eec4301a Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Wed, 7 Jun 2023 13:17:28 +0300 Subject: [PATCH] generic: replace use of QTime as timer with QElapsedTimer Signed-off-by: Ivailo Monev --- gwenview/tests/manual/imageloadbench.cpp | 4 ++-- kdeplasma-addons/applets/bball/bball.cpp | 4 ++-- kdeplasma-addons/applets/bball/bball.h | 3 +-- .../applets/icontasks/abstracttaskitem.h | 10 +++++----- kget/core/transfer.cpp | 17 +++++++++++++---- krdc/main.cpp | 4 ++-- okular/tests/searchtest.cpp | 2 +- okular/ui/pageview.cpp | 3 ++- partitionmanager/src/gui/applyprogressdialog.h | 14 ++++++-------- partitionmanager/src/jobs/job.cpp | 4 ++-- 10 files changed, 36 insertions(+), 29 deletions(-) diff --git a/gwenview/tests/manual/imageloadbench.cpp b/gwenview/tests/manual/imageloadbench.cpp index a3ddc08d..542352b8 100644 --- a/gwenview/tests/manual/imageloadbench.cpp +++ b/gwenview/tests/manual/imageloadbench.cpp @@ -4,14 +4,14 @@ #include #include #include -#include +#include const int ITERATIONS = 2; const QSize SCALED_SIZE(1280, 800); static void bench(QIODevice* device, const QString& outputName) { - QTime chrono; + QElapsedTimer chrono; chrono.start(); for (int iteration = 0; iteration < ITERATIONS; ++iteration) { qDebug() << "Iteration:" << iteration; diff --git a/kdeplasma-addons/applets/bball/bball.cpp b/kdeplasma-addons/applets/bball/bball.cpp index f0afa4b9..4efed619 100644 --- a/kdeplasma-addons/applets/bball/bball.cpp +++ b/kdeplasma-addons/applets/bball/bball.cpp @@ -164,7 +164,7 @@ void bballApplet::mousePressEvent(QGraphicsSceneMouseEvent * event) // reset timing m_timer.stop(); - m_time = QTime(); + m_time.invalidate(); update(); // reset physics @@ -310,7 +310,7 @@ void bballApplet::configChanged() void bballApplet::updatePhysics() { // find out the delta-time since the last call - if (m_time.isNull()) + if (!m_time.isValid()) m_time.start(); qreal dT = qMin((qreal)m_time.restart() / 1000.0, 0.5); diff --git a/kdeplasma-addons/applets/bball/bball.h b/kdeplasma-addons/applets/bball/bball.h index 1d908280..e495453e 100644 --- a/kdeplasma-addons/applets/bball/bball.h +++ b/kdeplasma-addons/applets/bball/bball.h @@ -23,7 +23,6 @@ #include #include -#include #include #include #include @@ -88,7 +87,7 @@ private: // status QBasicTimer m_timer; - QTime m_time; + QElapsedTimer m_time; QRectF m_screenRect; diff --git a/kdeplasma-addons/applets/icontasks/abstracttaskitem.h b/kdeplasma-addons/applets/icontasks/abstracttaskitem.h index 8cad57e7..8418626e 100644 --- a/kdeplasma-addons/applets/icontasks/abstracttaskitem.h +++ b/kdeplasma-addons/applets/icontasks/abstracttaskitem.h @@ -30,10 +30,10 @@ // Own #include "taskmanager/taskgroup.h" -// Qt -#include +// Katie +#include #include -#include +#include #include #include @@ -264,8 +264,8 @@ protected: private: QRectF m_activeRect; - QTime m_lastGeometryUpdate; - QTime m_lastUpdate; + QElapsedTimer m_lastGeometryUpdate; + QElapsedTimer m_lastUpdate; QSize m_lastIconSize; int m_activateTimerId; int m_updateGeometryTimerId; diff --git a/kget/core/transfer.cpp b/kget/core/transfer.cpp index 55c76d49..51e38795 100644 --- a/kget/core/transfer.cpp +++ b/kget/core/transfer.cpp @@ -23,6 +23,15 @@ #include #include +// FIXME: this is jumpy +static int elapsedSecs(const QTime &time) +{ + const int msecs = time.msecsTo(QTime::currentTime()); + if (msecs <= 0) { + return 0; + } + return (msecs / 1000); +} struct StatusStrings { @@ -94,7 +103,7 @@ bool Transfer::setDirectory(const KUrl& newDirectory) int Transfer::elapsedTime() const { if (status() == Job::Running) - return m_runningTime.elapsed() / 1000; + return elapsedSecs(m_runningTime); return m_runningSeconds; } @@ -219,7 +228,7 @@ void Transfer::save(const QDomElement &element) e.setAttribute("UploadedSize", m_uploadedSize); e.setAttribute("DownloadLimit", m_visibleDownloadLimit); e.setAttribute("UploadLimit", m_visibleUploadLimit); - e.setAttribute("ElapsedTime", status() == Job::Running ? m_runningTime.elapsed() / 1000 : m_runningSeconds); + e.setAttribute("ElapsedTime", status() == Job::Running ? elapsedSecs(m_runningTime) : m_runningSeconds); e.setAttribute("Policy", policy() == Job::Start ? "Start" : (policy() == Job::Stop ? "Stop" : "None")); } @@ -290,11 +299,11 @@ void Transfer::setStatus(Job::Status jobStatus, const QString &text, const QPixm if (jobStatus == Job::Running && status() != Job::Running) { - m_runningTime.restart(); + m_runningTime = QTime::currentTime(); m_runningTime.addSecs(m_runningSeconds); } if (jobStatus != Job::Running && status() == Job::Running) - m_runningSeconds = m_runningTime.elapsed() / 1000; + m_runningSeconds = elapsedSecs(m_runningTime); /** * It's important to call job::setStatus AFTER having changed the * icon or the text or whatever. diff --git a/krdc/main.cpp b/krdc/main.cpp index a9d1eedf..8c73b9f8 100644 --- a/krdc/main.cpp +++ b/krdc/main.cpp @@ -30,11 +30,11 @@ #include #include -#include +#include int main(int argc, char **argv) { - QTime startupTimer; + QElapsedTimer startupTimer; startupTimer.start(); KAboutData aboutData("krdc", 0, ki18n("KRDC"), KDE_VERSION_STRING, ki18n("KDE Remote Desktop Client"), KAboutData::License_GPL, diff --git a/okular/tests/searchtest.cpp b/okular/tests/searchtest.cpp index 08648d92..49f852df 100644 --- a/okular/tests/searchtest.cpp +++ b/okular/tests/searchtest.cpp @@ -178,7 +178,7 @@ void SearchTest::test311232() const int searchId = 0; d.searchText(searchId, " i ", true, Qt::CaseSensitive, Okular::Document::NextMatch, false, QColor()); - QTime t; + QElapsedTimer t; t.start(); while (spy.count() != 1 && t.elapsed() < 500) qApp->processEvents(); diff --git a/okular/ui/pageview.cpp b/okular/ui/pageview.cpp index 841925d9..24541c96 100644 --- a/okular/ui/pageview.cpp +++ b/okular/ui/pageview.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -148,7 +149,7 @@ public: // viewport move bool viewportMoveActive; - QTime viewportMoveTime; + QElapsedTimer viewportMoveTime; QPoint viewportMoveDest; int lastSourceLocationViewportPageNumber; double lastSourceLocationViewportNormalizedX; diff --git a/partitionmanager/src/gui/applyprogressdialog.h b/partitionmanager/src/gui/applyprogressdialog.h index 4ab96bf1..d341cd02 100644 --- a/partitionmanager/src/gui/applyprogressdialog.h +++ b/partitionmanager/src/gui/applyprogressdialog.h @@ -24,8 +24,11 @@ #include #include -#include +#include #include +#include +#include +#include class OperationRunner; class Operation; @@ -34,11 +37,6 @@ class ApplyProgressDialogWidget; class ApplyProgressDetailsWidget; class Report; - -#include -#include -#include - /** Show progress. The progress dialog telling the user about the progress of the Operations that are being applied. @@ -104,7 +102,7 @@ class ApplyProgressDialog : public KDialog void allOpsDone(const QString& msg); - QTime& time() { return m_Time; } + QElapsedTimer& time() { return m_Time; } QTimer& timer() { return m_Timer; } const QTimer& timer() const { return m_Timer; } @@ -129,7 +127,7 @@ class ApplyProgressDialog : public KDialog Report* m_Report; QString m_SavedParentTitle; QTimer m_Timer; - QTime m_Time; + QElapsedTimer m_Time; QTreeWidgetItem* m_CurrentOpItem; QTreeWidgetItem* m_CurrentJobItem; int m_LastReportUpdate; diff --git a/partitionmanager/src/jobs/job.cpp b/partitionmanager/src/jobs/job.cpp index c56e2478..55744aed 100644 --- a/partitionmanager/src/jobs/job.cpp +++ b/partitionmanager/src/jobs/job.cpp @@ -28,7 +28,7 @@ #include "util/report.h" #include -#include +#include #include #include @@ -70,7 +70,7 @@ bool Job::copyBlocks(Report& report, CopyTarget& target, CopySource& source) void* buffer = malloc(blockSize * source.sectorSize()); int percent = 0; - QTime t; + QElapsedTimer t; t.start(); while (blocksCopied < blocksToCopy)