summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2020-10-25 14:42:40 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-10-26 19:27:03 -0700
commitf193c2ef08d0edb1f40b6011a205eb8603c6019b (patch)
tree3faddb9bfd5a2c9fe769af04b60ff8bc50a9fa12 /commands
parent1a0cf0bb4432d97c1f34d53b82631629bcb06b8b (diff)
downloadsubsurface-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>
Diffstat (limited to 'commands')
-rw-r--r--commands/command_base.h11
-rw-r--r--commands/command_divelist.cpp2
-rw-r--r--commands/command_edit.cpp13
3 files changed, 14 insertions, 12 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);
}