From 4a50badb57efd7725fa540ea7bb13f1e334cb83c Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 5 Oct 2020 10:12:12 +0200 Subject: cleanup: use std::vector in struct device_table Since we converted from QString to std::string, let's also use std::vector instead of QVector. We don't need COW semantics and all the rigmarole. Let's try to keep Qt data structures out of the core. Signed-off-by: Berthold Stoeger --- core/device.cpp | 4 ++-- core/device.h | 4 ++-- qt-models/divecomputermodel.cpp | 8 ++++---- qt-models/divecomputermodel.h | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/device.cpp b/core/device.cpp index 39b3bc61b..21a53e2f6 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -213,7 +213,7 @@ bool device::operator<(const device &a) const return std::tie(deviceId, model) < std::tie(a.deviceId, a.model); } -static const device *getDCExact(const QVector &dcs, const divecomputer *dc) +static const device *getDCExact(const std::vector &dcs, const divecomputer *dc) { auto it = std::lower_bound(dcs.begin(), dcs.end(), device{dc->model, dc->deviceid, {}, {}, {}}); return it != dcs.end() && it->model == dc->model && it->deviceId == dc->deviceid ? &*it : NULL; @@ -258,7 +258,7 @@ void device::showchanges(const std::string &n, const std::string &s, const std:: qDebug("new firmware version %s for DC model %s deviceId 0x%x", f.c_str(), model.c_str(), deviceId); } -static void addDC(QVector &dcs, const std::string &m, uint32_t d, const std::string &n, const std::string &s, const std::string &f) +static void addDC(std::vector &dcs, const std::string &m, uint32_t d, const std::string &n, const std::string &s, const std::string &f) { if (m.empty() || d == 0) return; diff --git a/core/device.h b/core/device.h index 90d67bb5e..28ad696bb 100644 --- a/core/device.h +++ b/core/device.h @@ -26,7 +26,7 @@ const char *get_dc_nickname(const struct divecomputer *dc); #ifdef __cplusplus #include -#include +#include struct device { bool operator==(const device &a) const; bool operator!=(const device &a) const; @@ -41,7 +41,7 @@ struct device { struct device_table { // Keep the dive computers in a vector sorted by (model, deviceId) - QVector devices; + std::vector devices; }; extern struct device_table device_table; diff --git a/qt-models/divecomputermodel.cpp b/qt-models/divecomputermodel.cpp index c675ad641..d0b9f7637 100644 --- a/qt-models/divecomputermodel.cpp +++ b/qt-models/divecomputermodel.cpp @@ -11,7 +11,7 @@ DiveComputerModel::DiveComputerModel(QObject *parent) : CleanerTableModel(parent QVariant DiveComputerModel::data(const QModelIndex &index, int role) const { - if (index.row() < 0 || index.row() >= dcs.size()) + if (index.row() < 0 || index.row() >= (int)dcs.size()) return QVariant(); const device &node = dcs[index.row()]; @@ -55,7 +55,7 @@ Qt::ItemFlags DiveComputerModel::flags(const QModelIndex &index) const bool DiveComputerModel::setData(const QModelIndex &index, const QVariant &value, int) { // We should test if the role == Qt::EditRole - if (index.row() < 0 || index.row() >= dcs.size()) + if (index.row() < 0 || index.row() >= (int)dcs.size()) return false; device &node = dcs[index.row()]; @@ -66,10 +66,10 @@ bool DiveComputerModel::setData(const QModelIndex &index, const QVariant &value, void DiveComputerModel::remove(const QModelIndex &index) { - if (index.row() < 0 || index.row() >= dcs.size()) + if (index.row() < 0 || index.row() >= (int)dcs.size()) return; beginRemoveRows(QModelIndex(), index.row(), index.row()); - dcs.remove(index.row()); + dcs.erase(dcs.begin() + index.row()); endRemoveRows(); } diff --git a/qt-models/divecomputermodel.h b/qt-models/divecomputermodel.h index d50e1cd96..b21eadcc9 100644 --- a/qt-models/divecomputermodel.h +++ b/qt-models/divecomputermodel.h @@ -27,7 +27,7 @@ slots: void remove(const QModelIndex &index); private: - QVector dcs; + std::vector dcs; }; class DiveComputerSortedModel : public QSortFilterProxyModel { -- cgit v1.2.3-70-g09d2