core: sort device-table by id/model instead of model/id

The device table is accessed by core via a callback using
call_for_each_dc(). This sorts the table by device-id. It
is unclear whether this is needed - since currently all it
does is make sure that the devices have a fixed order in XML
and git log files.

In any case, this means that the table had to be copied and
sorted in call_for_each_dc(). Since the frontend now does
its own sorting, we can just keep the core table sorted
as it needs it. This in turn will ultimately make it possible
to replace the callback by a simple loop.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-10-10 12:50:58 +02:00 committed by Dirk Hohndel
parent 215e5a4544
commit c9b8584bd2

View file

@ -210,7 +210,7 @@ bool device::operator!=(const device &a) const
bool device::operator<(const device &a) const
{
return std::tie(model, deviceId) < std::tie(a.model, a.deviceId);
return std::tie(deviceId, model) < std::tie(a.deviceId, a.model);
}
static const device *getDCExact(const QVector<device> &dcs, const divecomputer *dc)
@ -291,17 +291,10 @@ extern "C" void clear_device_nodes()
device_table.devices.clear();
}
static bool compareDCById(const device &a, const device &b)
{
return a.deviceId < b.deviceId;
}
extern "C" void call_for_each_dc (void *f, void (*callback)(void *, const char *, uint32_t, const char *, const char *, const char *),
bool select_only)
{
QVector<device> values = device_table.devices;
std::sort(values.begin(), values.end(), compareDCById);
for (const device &node : values) {
for (const device &node : device_table.devices) {
bool found = false;
if (select_only) {
for (dive *d: getDiveSelection()) {