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 ++----------- desktop-widgets/divelistview.cpp | 10 +++++----- 4 files changed, 19 insertions(+), 17 deletions(-) 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); } diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index 92638a336..f98b298f4 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -17,6 +17,7 @@ #include #include #include "commands/command.h" +#include "commands/command_base.h" #include "core/errorhelper.h" #include "core/qthelper.h" #include "core/trip.h" @@ -645,7 +646,7 @@ void DiveListView::addDivesToTrip() std::vector dives = getDiveSelection(); if (!t || dives.empty()) return; - Command::addDivesToTrip(QVector::fromStdVector(dives), t); + Command::addDivesToTrip(stdToQt(dives), t); } void DiveListView::renumberDives() @@ -734,8 +735,8 @@ void DiveListView::addToTrip(int delta) if (!trip || !d) // no dive, no trip? get me out of here return; - - Command::addDivesToTrip(QVector::fromStdVector(getDiveSelection()), trip); + std::vector dives = getDiveSelection(); + Command::addDivesToTrip(stdToQt(dives), trip); } void DiveListView::markDiveInvalid() @@ -753,8 +754,7 @@ void DiveListView::deleteDive() struct dive *d = contextMenuIndex.data(DiveTripModelBase::DIVE_ROLE).value(); if (!d) return; - - Command::deleteDive(QVector::fromStdVector(getDiveSelection())); + Command::deleteDive(stdToQt(getDiveSelection())); } void DiveListView::contextMenuEvent(QContextMenuEvent *event) -- cgit v1.2.3-70-g09d2