From 1a4a22849c9dfe19fe0bc486ec2cd42b8efdd086 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 8 Sep 2022 21:00:14 +0300 Subject: [PATCH] Qt started to support std::chrono since Qt 5.8. --- src/app/puzzle/vpmainwindow.cpp | 2 +- src/app/tape/tmainwindow.cpp | 2 +- .../valentina/dialogs/dialoglayoutprogress.cpp | 2 +- src/app/valentina/dialogs/vwidgetdetails.cpp | 2 +- src/app/valentina/mainwindow.cpp | 8 ++++---- src/app/valentina/xml/vpattern.cpp | 9 ++++++++- src/libs/vmisc/defglobal.h | 16 ++++++++++++++++ src/libs/vtools/tools/vtoolseamallowance.cpp | 9 ++++++++- src/libs/vwidgets/vlineedit.cpp | 9 +++++++-- 9 files changed, 47 insertions(+), 12 deletions(-) diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 2069cd035..233143f5e 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -391,7 +391,7 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : if (m_cmd->IsGuiEnabled()) { - QTimer::singleShot(SECONDS(1), this, &VPMainWindow::SetDefaultGUILanguage); + QTimer::singleShot(V_SECONDS(1), this, &VPMainWindow::SetDefaultGUILanguage); } } diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 8b3df51b7..aa8b8a32a 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -245,7 +245,7 @@ TMainWindow::TMainWindow(QWidget *parent) if (MApplication::VApp()->IsAppInGUIMode()) { - QTimer::singleShot(SECONDS(1), this, &TMainWindow::SetDefaultGUILanguage); + QTimer::singleShot(V_SECONDS(1), this, &TMainWindow::SetDefaultGUILanguage); } } diff --git a/src/app/valentina/dialogs/dialoglayoutprogress.cpp b/src/app/valentina/dialogs/dialoglayoutprogress.cpp index 1b2778ee5..70acfe90e 100644 --- a/src/app/valentina/dialogs/dialoglayoutprogress.cpp +++ b/src/app/valentina/dialogs/dialoglayoutprogress.cpp @@ -88,7 +88,7 @@ DialogLayoutProgress::DialogLayoutProgress(QElapsedTimer timer, qint64 timeout, m_progressTimer->stop(); } }); - m_progressTimer->start(SECONDS(1)); + m_progressTimer->start(V_SECONDS(1)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/dialogs/vwidgetdetails.cpp b/src/app/valentina/dialogs/vwidgetdetails.cpp index 5c7e3d093..1c41f56f1 100644 --- a/src/app/valentina/dialogs/vwidgetdetails.cpp +++ b/src/app/valentina/dialogs/vwidgetdetails.cpp @@ -96,7 +96,7 @@ void VWidgetDetails::UpdateList() // The filling table is a very expensive operation. This optimization will postpone it. // Each time a new request happen we will wait 800 ms before calling it. If at this time a new request will arrive // we will wait 800 ms more. And so on, until nothing happens within 800ms. - m_updateListTimer->start(MSECONDS(800)); + m_updateListTimer->start(V_MSECONDS(800)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 8d52ff2f6..78af326a1 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -474,7 +474,7 @@ MainWindow::MainWindow(QWidget *parent) if (VApplication::IsGUIMode()) { - QTimer::singleShot(SECONDS(1), this, &MainWindow::SetDefaultGUILanguage); + QTimer::singleShot(V_SECONDS(1), this, &MainWindow::SetDefaultGUILanguage); } } @@ -2139,7 +2139,7 @@ void MainWindow::MeasurementsChanged(const QString &path) { m_mChanges = true; m_mChangesAsked = false; - m_measurementsSyncTimer->start(MSECONDS(1500)); + m_measurementsSyncTimer->start(V_MSECONDS(1500)); } else { @@ -2149,7 +2149,7 @@ void MainWindow::MeasurementsChanged(const QString &path) { m_mChanges = true; m_mChangesAsked = false; - m_measurementsSyncTimer->start(MSECONDS(1500)); + m_measurementsSyncTimer->start(V_MSECONDS(1500)); break; } @@ -6010,7 +6010,7 @@ auto MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile) { /* Collect garbage only after successfully parse. This way wrongly accused items have one more time to restore * a reference. */ - QTimer::singleShot(100, Qt::CoarseTimer, this, [this](){doc->GarbageCollector(true);}); + QTimer::singleShot(V_MSECONDS(100), Qt::CoarseTimer, this, [this](){doc->GarbageCollector(true);}); } m_patternReadOnly = doc->IsReadOnly(); diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index c32d701f2..da331fbea 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -119,6 +119,13 @@ #include #include +#if __cplusplus >= 201402L +using namespace std::chrono_literals; +#else +#include "../vmisc/bpstd/chrono.hpp" +using namespace bpstd::literals::chrono_literals; +#endif + const QString VPattern::AttrReadOnly = QStringLiteral("readOnly"); const QString VPattern::AttrLabelPrefix = QStringLiteral("labelPrefix"); @@ -275,7 +282,7 @@ void VPattern::Parse(const Document &parse) } if (VApplication::IsGUIMode()) { - QTimer::singleShot(1000, Qt::VeryCoarseTimer, this, &VPattern::RefreshPieceGeometry); + QTimer::singleShot(V_SECONDS(1), Qt::VeryCoarseTimer, this, &VPattern::RefreshPieceGeometry); } else if (VApplication::VApp()->CommandLine()->IsTestModeEnabled()) { diff --git a/src/libs/vmisc/defglobal.h b/src/libs/vmisc/defglobal.h index 4fd33b3ba..c093be593 100644 --- a/src/libs/vmisc/defglobal.h +++ b/src/libs/vmisc/defglobal.h @@ -73,4 +73,20 @@ void qAsConst(const T &&) Q_DECL_EQ_DELETE; #define NANOSECONDS(x) SUFFIX_APPEND(x, _ns) // NOLINT(cppcoreguidelines-macro-usage) #endif // __cplusplus >= 201402L +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#define V_HOURS(x) HOURS(x) // NOLINT(cppcoreguidelines-macro-usage) +#define V_MINUTES(x) MINUTES(x) // NOLINT(cppcoreguidelines-macro-usage) +#define V_SECONDS(x) SECONDS(x) // NOLINT(cppcoreguidelines-macro-usage) +#define V_MSECONDS(x) MSECONDS(x) // NOLINT(cppcoreguidelines-macro-usage) +#define V_MICSECONDS(x) MICSECONDS(x) // NOLINT(cppcoreguidelines-macro-usage) +#define V_NANOSECONDS(x) NANOSECONDS(x) // NOLINT(cppcoreguidelines-macro-usage) +#else +#define V_HOURS(x) (x * 3600000) // NOLINT(cppcoreguidelines-macro-usage) +#define V_MINUTES(x) (x * 60000) // NOLINT(cppcoreguidelines-macro-usage) +#define V_SECONDS(x) (x * 1000) // NOLINT(cppcoreguidelines-macro-usage) +#define V_MSECONDS(x) (x) // NOLINT(cppcoreguidelines-macro-usage) +#define V_MICSECONDS(x) (x) // NOLINT(cppcoreguidelines-macro-usage) +#define V_NANOSECONDS(x) (x) // NOLINT(cppcoreguidelines-macro-usage) +#endif + #endif // DEFGLOBAL_H diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index a2da3c084..58774c832 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -74,6 +74,13 @@ #include #include +#if __cplusplus >= 201402L +using namespace std::chrono_literals; +#else +#include "../vmisc/bpstd/chrono.hpp" +using namespace bpstd::literals::chrono_literals; +#endif + // Current version of seam allowance tag need for backward compatibility const quint8 VToolSeamAllowance::pieceVersion = 2; @@ -1435,7 +1442,7 @@ void VToolSeamAllowance::RefreshGeometry(bool updateChildren) if (VAbstractApplication::VApp()->IsAppInGUIMode()) { - QTimer::singleShot(100, Qt::CoarseTimer, this, [this, updateChildren]() + QTimer::singleShot(V_MSECONDS(100), Qt::CoarseTimer, this, [this, updateChildren]() { this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); UpdateDetailLabel(); diff --git a/src/libs/vwidgets/vlineedit.cpp b/src/libs/vwidgets/vlineedit.cpp index 9a85da69d..d161a43ee 100644 --- a/src/libs/vwidgets/vlineedit.cpp +++ b/src/libs/vwidgets/vlineedit.cpp @@ -34,7 +34,12 @@ #include #include -#include "../vmisc/compatibility.h" +#if __cplusplus >= 201402L +using namespace std::chrono_literals; +#else +#include "../vmisc/bpstd/chrono.hpp" +using namespace bpstd::literals::chrono_literals; +#endif namespace { @@ -172,7 +177,7 @@ void VCompleterLineEdit::ShowCompletion() if (text().isEmpty()) { // completion list will be hidden now; we will show it again after a delay - QTimer::singleShot(100, this, &VCompleterLineEdit::CompletionPopup); + QTimer::singleShot(V_MSECONDS(100), this, &VCompleterLineEdit::CompletionPopup); } }