From 1677e3d105bc03e06a9a4ccd8a5342704f749193 Mon Sep 17 00:00:00 2001 From: Ladislav Michl Date: Sun, 21 Jan 2024 19:17:04 +0100 Subject: [PATCH] Base: Remove StopWatch StopWatch is now used on single place only, remove it in favour of TimeElapsed --- src/Base/Tools.cpp | 60 ------------------------------------------- src/Base/Tools.h | 23 ----------------- src/Gui/AutoSaver.cpp | 7 +++-- 3 files changed, 3 insertions(+), 87 deletions(-) diff --git a/src/Base/Tools.cpp b/src/Base/Tools.cpp index 6875fa8f4f..b164164489 100644 --- a/src/Base/Tools.cpp +++ b/src/Base/Tools.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #endif #include "PyExport.h" @@ -373,62 +372,3 @@ std::string Base::Tools::currentDateTimeString() .toString(Qt::ISODate) .toStdString(); } - -// ---------------------------------------------------------------------------- - -using namespace Base; - -struct StopWatch::Private -{ - QElapsedTimer t; -}; - -StopWatch::StopWatch() - : d(new Private) -{} - -StopWatch::~StopWatch() -{ - delete d; -} - -void StopWatch::start() -{ - d->t.start(); -} - -int StopWatch::restart() -{ - return d->t.restart(); -} - -int StopWatch::elapsed() -{ - return d->t.elapsed(); -} - -std::string StopWatch::toString(int ms) const -{ - int total = ms; - int msec = total % 1000; - total = total / 1000; - int secs = total % 60; - total = total / 60; - int mins = total % 60; - int hour = total / 60; - std::stringstream str; - str << "Needed time: "; - if (hour > 0) { - str << hour << "h " << mins << "m " << secs << "s"; - } - else if (mins > 0) { - str << mins << "m " << secs << "s"; - } - else if (secs > 0) { - str << secs << "s"; - } - else { - str << msec << "ms"; - } - return str.str(); -} diff --git a/src/Base/Tools.h b/src/Base/Tools.h index d45777c962..b17907bbc4 100644 --- a/src/Base/Tools.h +++ b/src/Base/Tools.h @@ -145,29 +145,6 @@ inline T fmod(T numerator, T denominator) // ---------------------------------------------------------------------------- -class BaseExport StopWatch -{ -public: - StopWatch(); - ~StopWatch(); - - void start(); - int restart(); - int elapsed(); - std::string toString(int ms) const; - - StopWatch(const StopWatch&) = delete; - StopWatch(StopWatch&&) = delete; - StopWatch& operator=(const StopWatch&) = delete; - StopWatch& operator=(StopWatch&&) = delete; - -private: - struct Private; - Private* d; -}; - -// ---------------------------------------------------------------------------- - // NOLINTBEGIN template struct FlagToggler diff --git a/src/Gui/AutoSaver.cpp b/src/Gui/AutoSaver.cpp index 9e89ab081b..8ff9a9013f 100644 --- a/src/Gui/AutoSaver.cpp +++ b/src/Gui/AutoSaver.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -171,9 +172,8 @@ void AutoSaver::saveDocument(const std::string& name, AutoSaveProperty& saver) getMainWindow()->showMessage(tr("Please wait until the AutoRecovery file has been saved..."), 5000); //qApp->processEvents(); + Base::TimeElapsed startTime; // open extra scope to close ZipWriter properly - Base::StopWatch watch; - watch.start(); { if (!this->compressed) { RecoveryWriter writer(saver); @@ -220,8 +220,7 @@ void AutoSaver::saveDocument(const std::string& name, AutoSaveProperty& saver) } } - std::string str = watch.toString(watch.elapsed()); - Base::Console().Log("Save AutoRecovery file: %s\n", str.c_str()); + Base::Console().Log("Save AutoRecovery file in %fs\n", Base::TimeElapsed::diffTimeF(startTime,Base::TimeElapsed())); hGrp->SetBool("SaveThumbnail",save); } }