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>
This commit is contained in:
Dirk Hohndel 2020-10-25 14:42:40 -07:00
parent 1a0cf0bb44
commit f193c2ef08
4 changed files with 19 additions and 17 deletions

View file

@ -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 {

View file

@ -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);

View file

@ -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);
}

View file

@ -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)