diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2020-10-25 14:42:40 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-10-26 19:27:03 -0700 |
commit | f193c2ef08d0edb1f40b6011a205eb8603c6019b (patch) | |
tree | 3faddb9bfd5a2c9fe769af04b60ff8bc50a9fa12 | |
parent | 1a0cf0bb4432d97c1f34d53b82631629bcb06b8b (diff) | |
download | subsurface-f193c2ef08d0edb1f40b6011a205eb8603c6019b.tar.gz |
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 <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | commands/command_base.h | 11 | ||||
-rw-r--r-- | commands/command_divelist.cpp | 2 | ||||
-rw-r--r-- | commands/command_edit.cpp | 13 | ||||
-rw-r--r-- | 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<typename T> +QVector<T> stdToQt(const std::vector<T> &v) +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + return QVector<T>(v.begin(), v.end()); +#else + return QVector<T>::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<dive *> dives = QVector<dive *>::fromStdVector(diveList); + QVector<dive *> dives = stdToQt<dive *>(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<T>::undo() // Send signals. DiveField id = fieldId(); -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - emit diveListNotifier.divesChanged(QVector<dive *>(dives.begin(), dives.end()), id); -#else - emit diveListNotifier.divesChanged(QVector<dive *>::fromStdVector(dives), id); -#endif - + emit diveListNotifier.divesChanged(stdToQt<dive *>(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<dive *>(dives.begin(), dives.end()), id); -#else - emit diveListNotifier.divesChanged(QVector<dive *>::fromStdVector(dives), id); -#endif + emit diveListNotifier.divesChanged(stdToQt<dive *>(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 <QMessageBox> #include <QHeaderView> #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<dive *> dives = getDiveSelection(); if (!t || dives.empty()) return; - Command::addDivesToTrip(QVector<dive *>::fromStdVector(dives), t); + Command::addDivesToTrip(stdToQt<dive *>(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<dive *>::fromStdVector(getDiveSelection()), trip); + std::vector<dive *> dives = getDiveSelection(); + Command::addDivesToTrip(stdToQt<dive *>(dives), trip); } void DiveListView::markDiveInvalid() @@ -753,8 +754,7 @@ void DiveListView::deleteDive() struct dive *d = contextMenuIndex.data(DiveTripModelBase::DIVE_ROLE).value<struct dive *>(); if (!d) return; - - Command::deleteDive(QVector<dive *>::fromStdVector(getDiveSelection())); + Command::deleteDive(stdToQt<dive *>(getDiveSelection())); } void DiveListView::contextMenuEvent(QContextMenuEvent *event) |