From f193c2ef08d0edb1f40b6011a205eb8603c6019b Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 25 Oct 2020 14:42:40 -0700 Subject: cleanup: fix deprecated QVector constructor Annoyingly, the replacement has only been available since Qt 5.14. To make the code less messy, implement our own stdToQt conversion helper. Suggested-by: Berthold Stoeger Signed-off-by: Dirk Hohndel --- commands/command_base.h | 11 +++++++++++ commands/command_divelist.cpp | 2 +- commands/command_edit.cpp | 13 ++----------- 3 files changed, 14 insertions(+), 12 deletions(-) (limited to 'commands') diff --git a/commands/command_base.h b/commands/command_base.h index d805610e5..8c905d09a 100644 --- a/commands/command_base.h +++ b/commands/command_base.h @@ -139,6 +139,17 @@ // v.clear(v); // Reset the vector to zero length. If the elements weren't release()d, // // the pointed-to dives are freed with free_dive() +// Qt is making their containers a lot harder to integrate with std::vector +template +QVector stdToQt(const std::vector &v) +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + return QVector(v.begin(), v.end()); +#else + return QVector::fromStdVector(v); +#endif +} + // We put everything in a namespace, so that we can shorten names without polluting the global namespace namespace Command { diff --git a/commands/command_divelist.cpp b/commands/command_divelist.cpp index c5322f709..0917f71e5 100644 --- a/commands/command_divelist.cpp +++ b/commands/command_divelist.cpp @@ -659,7 +659,7 @@ void ShiftTime::redoit() sort_dive_table(&trip->dives); // Keep the trip-table in order // Send signals - QVector dives = QVector::fromStdVector(diveList); + QVector dives = stdToQt(diveList); emit diveListNotifier.divesTimeChanged(timeChanged, dives); emit diveListNotifier.divesChanged(dives, DiveField::DATETIME); diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp index ae97594e4..96678996c 100644 --- a/commands/command_edit.cpp +++ b/commands/command_edit.cpp @@ -155,12 +155,7 @@ void EditBase::undo() // Send signals. DiveField id = fieldId(); -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - emit diveListNotifier.divesChanged(QVector(dives.begin(), dives.end()), id); -#else - emit diveListNotifier.divesChanged(QVector::fromStdVector(dives), id); -#endif - + emit diveListNotifier.divesChanged(stdToQt(dives), id); setSelection(selectedDives, current); } @@ -551,11 +546,7 @@ void EditTagsBase::undo() // Send signals. DiveField id = fieldId(); -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - emit diveListNotifier.divesChanged(QVector(dives.begin(), dives.end()), id); -#else - emit diveListNotifier.divesChanged(QVector::fromStdVector(dives), id); -#endif + emit diveListNotifier.divesChanged(stdToQt(dives), id); setSelection(selectedDives, current); } -- cgit v1.2.3-70-g09d2