From f46197740dbb297bb1c2383b0c14ed601e67d402 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 16 Apr 2024 11:47:13 +0300 Subject: [PATCH] Refactoring. Switch to using std::chrono. --- .../dialogs/configpages/preferencesconfigurationpage.cpp | 3 ++- src/app/valentina/dialogs/vwidgetdetails.cpp | 1 - src/app/valentina/mainwindow.cpp | 2 +- src/app/valentina/mainwindowsnogui.cpp | 3 ++- src/libs/vganalytics/vganalytics.cpp | 3 +-- src/libs/vtools/dialogs/dialogtoolbox.h | 3 ++- src/libs/vtools/dialogs/tools/piece/dialogplacelabel.cpp | 6 +++--- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp index ae2bcb1ec..0c8c9f918 100644 --- a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp @@ -214,7 +214,8 @@ auto PreferencesConfigurationPage::Apply() -> QStringList QTimer *autoSaveTimer = VApplication::VApp()->getAutoSaveTimer(); SCASSERT(autoSaveTimer) - ui->autoSaveCheck->isChecked() ? autoSaveTimer->start(ui->autoTime->value() * 60000) : autoSaveTimer->stop(); + ui->autoSaveCheck->isChecked() ? autoSaveTimer->start(std::chrono::minutes{ui->autoTime->value()}) + : autoSaveTimer->stop(); settings->SetOsSeparator(ui->osOptionCheck->isChecked()); settings->SetToolBarStyle(ui->toolBarStyleCheck->isChecked()); diff --git a/src/app/valentina/dialogs/vwidgetdetails.cpp b/src/app/valentina/dialogs/vwidgetdetails.cpp index bfcb48154..fcb39fd0f 100644 --- a/src/app/valentina/dialogs/vwidgetdetails.cpp +++ b/src/app/valentina/dialogs/vwidgetdetails.cpp @@ -38,7 +38,6 @@ #include #include #include -#include using namespace std::chrono_literals; diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 9729b890b..b510999e0 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -6256,7 +6256,7 @@ void MainWindow::InitAutoSave() if (VAbstractValApplication::VApp()->ValentinaSettings()->GetAutosaveState()) { const qint32 autoTime = VAbstractValApplication::VApp()->ValentinaSettings()->GetAutosaveTime(); - m_autoSaveTimer->start(autoTime * 60000); + m_autoSaveTimer->start(std::chrono::minutes{autoTime}); qCDebug(vMainWindow, "Autosaving each %d minutes.", autoTime); } VApplication::VApp()->setAutoSaveTimer(m_autoSaveTimer); diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 2716851c5..101fbbb5d 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -76,6 +76,7 @@ #include #endif +using namespace std::chrono_literals; using namespace Qt::Literals::StringLiterals; QT_WARNING_PUSH @@ -234,7 +235,7 @@ auto MainWindowsNoGUI::GenerateLayout(VLayoutGenerator &lGenerator) -> bool progressTimer->deleteLater(); } }); - progressTimer->start(1000); + progressTimer->start(1s); } LayoutErrors nestingState = LayoutErrors::NoError; diff --git a/src/libs/vganalytics/vganalytics.cpp b/src/libs/vganalytics/vganalytics.cpp index 3c746f4c7..703c60dee 100644 --- a/src/libs/vganalytics/vganalytics.cpp +++ b/src/libs/vganalytics/vganalytics.cpp @@ -301,9 +301,8 @@ void VGAnalytics::SendAppCloseEvent(qint64 engagementTimeMsec) if (QNetworkReply *reply = d->SendAnalytics()) { QTimer timer; - const int timeoutSeconds = 3; // Wait for 3 seconds timer.setSingleShot(true); - timer.start(timeoutSeconds * 1000); + timer.start(3s); QEventLoop loop; connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit); diff --git a/src/libs/vtools/dialogs/dialogtoolbox.h b/src/libs/vtools/dialogs/dialogtoolbox.h index c76e9d06e..77b0102e5 100644 --- a/src/libs/vtools/dialogs/dialogtoolbox.h +++ b/src/libs/vtools/dialogs/dialogtoolbox.h @@ -31,6 +31,7 @@ #include #include #include +#include #include "../vgeometry/vgeometrydef.h" #include "../vmisc/typedef.h" @@ -50,7 +51,7 @@ class QListWidget; class VPieceNode; class QDialogButtonBox; -constexpr int formulaTimerTimeout = 300; +constexpr std::chrono::milliseconds formulaTimerTimeout = std::chrono::milliseconds(300); extern const QColor errorColor; diff --git a/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.cpp b/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.cpp index cbe2195be..e6022c0ff 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.cpp @@ -257,9 +257,9 @@ void DialogPlaceLabel::ChosenObject(quint32 id, const SceneObject &type) CheckPoint(); prepare = true; - timerWidth->setSingleShot(formulaTimerTimeout); - timerHeight->setSingleShot(formulaTimerTimeout); - timerAngle->setSingleShot(formulaTimerTimeout); + timerWidth->setSingleShot(formulaTimerTimeout.count()); + timerHeight->setSingleShot(formulaTimerTimeout.count()); + timerAngle->setSingleShot(formulaTimerTimeout.count()); this->setModal(true); this->show();