2017-04-27 18:25:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "core/units.h"
|
|
|
|
#include "qt-models/divelocationmodel.h"
|
2020-02-03 18:33:06 +00:00
|
|
|
#include "core/subsurface-qt/divelistnotifier.h"
|
2024-03-12 07:52:21 +00:00
|
|
|
#include "core/errorhelper.h"
|
2019-03-04 22:20:29 +00:00
|
|
|
#include "core/divesite.h"
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
#include "core/divelog.h"
|
2019-03-09 21:32:16 +00:00
|
|
|
#include "core/metrics.h"
|
2019-03-12 21:35:43 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2019-03-16 10:35:44 +00:00
|
|
|
#include "cleanertablemodel.h" // for trashIcon() and editIcon()
|
2019-11-13 14:08:40 +00:00
|
|
|
#include "commands/command.h"
|
2019-03-12 21:35:43 +00:00
|
|
|
#endif
|
2015-07-14 21:43:47 +00:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QIcon>
|
2017-04-25 21:16:46 +00:00
|
|
|
#include <core/gettextfromc.h>
|
2015-05-30 00:19:44 +00:00
|
|
|
|
2015-05-30 01:22:24 +00:00
|
|
|
LocationInformationModel *LocationInformationModel::instance()
|
|
|
|
{
|
|
|
|
static LocationInformationModel *self = new LocationInformationModel();
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2018-10-09 07:18:08 +00:00
|
|
|
LocationInformationModel::LocationInformationModel(QObject *obj) : QAbstractTableModel(obj)
|
2015-05-30 00:19:44 +00:00
|
|
|
{
|
2019-03-10 15:03:39 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::diveSiteDiveCountChanged, this, &LocationInformationModel::diveSiteDiveCountChanged);
|
2019-03-11 23:25:31 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::diveSiteAdded, this, &LocationInformationModel::diveSiteAdded);
|
|
|
|
connect(&diveListNotifier, &DiveListNotifier::diveSiteDeleted, this, &LocationInformationModel::diveSiteDeleted);
|
2019-03-12 22:51:39 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::diveSiteChanged, this, &LocationInformationModel::diveSiteChanged);
|
2019-03-20 20:46:58 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::diveSiteDivesChanged, this, &LocationInformationModel::diveSiteDivesChanged);
|
cleanup: invert control-flow when resetting the core structures
To reset the core data structures, the mobile and desktop UIs
were calling into the dive-list models, which then reset the
core data structures, themselves and the unrelated
locationinformation model. The UI code then reset various other
things, such as the TankInformation model or the map. . This was
unsatisfying from a control-flow perspective, as the models should
display the core data, not act on it. Moreover, this meant lots
of intricate intermodule-dependencies.
Thus, straighten up the control flow: give the C core the
possibility to send a "all data reset" event. And do that
in those functions that reset the core data structures.
Let each module react to this event by itself. This removes
inter-module dependencies. For example, the MainWindow now
doesn't have to reset the TankInfoModel or the MapWidget.
Then, to reset the core data structures, let the UI code
simply directly call the respective core functions.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-04 22:12:36 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::dataReset, this, &LocationInformationModel::update);
|
2015-05-30 00:19:44 +00:00
|
|
|
}
|
|
|
|
|
2019-03-09 21:32:16 +00:00
|
|
|
int LocationInformationModel::columnCount(const QModelIndex &) const
|
2015-07-01 21:46:27 +00:00
|
|
|
{
|
|
|
|
return COLUMNS;
|
|
|
|
}
|
|
|
|
|
2019-03-09 21:32:16 +00:00
|
|
|
int LocationInformationModel::rowCount(const QModelIndex &) const
|
2015-05-30 00:19:44 +00:00
|
|
|
{
|
2024-06-08 14:30:24 +00:00
|
|
|
return (int)divelog.sites.size();
|
2015-07-16 21:08:08 +00:00
|
|
|
}
|
|
|
|
|
2019-03-09 21:32:16 +00:00
|
|
|
QVariant LocationInformationModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
if (orientation == Qt::Vertical)
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
switch (role) {
|
|
|
|
case Qt::TextAlignmentRole:
|
|
|
|
return int(Qt::AlignLeft | Qt::AlignVCenter);
|
|
|
|
case Qt::FontRole:
|
|
|
|
return defaultModelFont();
|
|
|
|
case Qt::InitialSortOrderRole:
|
|
|
|
// By default, sort number of dives descending, everything else ascending.
|
|
|
|
return section == NUM_DIVES ? Qt::DescendingOrder : Qt::AscendingOrder;
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
case Qt::ToolTipRole:
|
|
|
|
switch (section) {
|
|
|
|
case NAME:
|
|
|
|
return tr("Name");
|
|
|
|
case DESCRIPTION:
|
|
|
|
return tr("Description");
|
|
|
|
case NUM_DIVES:
|
|
|
|
return tr("# of dives");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::ItemFlags LocationInformationModel::flags(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
switch (index.column()) {
|
|
|
|
case REMOVE:
|
|
|
|
return Qt::ItemIsEnabled;
|
|
|
|
case NAME:
|
|
|
|
case DESCRIPTION:
|
|
|
|
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
|
|
|
}
|
|
|
|
return QAbstractItemModel::flags(index);
|
|
|
|
}
|
|
|
|
|
2024-05-11 09:47:45 +00:00
|
|
|
QVariant LocationInformationModel::getDiveSiteData(const struct dive_site &ds, int column, int role)
|
2015-05-30 00:19:44 +00:00
|
|
|
{
|
|
|
|
switch(role) {
|
2015-07-14 21:43:47 +00:00
|
|
|
case Qt::EditRole:
|
2019-03-09 21:32:16 +00:00
|
|
|
case Qt::DisplayRole:
|
2018-10-09 10:26:58 +00:00
|
|
|
switch(column) {
|
2024-05-11 09:47:45 +00:00
|
|
|
case DIVESITE: return QVariant::fromValue<dive_site *>((dive_site *)&ds); // Not nice: casting away const
|
|
|
|
case NAME: return QString::fromStdString(ds.name);
|
|
|
|
case NUM_DIVES: return static_cast<int>(ds.dives.size());
|
2019-03-14 21:07:48 +00:00
|
|
|
case LOCATION: return "TODO";
|
2024-05-11 09:47:45 +00:00
|
|
|
case DESCRIPTION: return QString::fromStdString(ds.description);
|
|
|
|
case NOTES: return QString::fromStdString(ds.notes);
|
2019-03-14 07:26:50 +00:00
|
|
|
case TAXONOMY: return "TODO";
|
2015-07-01 21:46:27 +00:00
|
|
|
}
|
|
|
|
break;
|
2019-03-09 21:32:16 +00:00
|
|
|
case Qt::ToolTipRole:
|
|
|
|
switch(column) {
|
2019-03-16 10:35:44 +00:00
|
|
|
case EDIT: return tr("Click here to edit the divesite.");
|
2019-03-09 21:32:16 +00:00
|
|
|
case REMOVE: return tr("Clicking here will remove this divesite.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Qt::DecorationRole:
|
|
|
|
switch(column) {
|
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2019-03-16 10:35:44 +00:00
|
|
|
case EDIT: return editIcon();
|
2019-03-09 21:32:16 +00:00
|
|
|
case REMOVE: return trashIcon();
|
|
|
|
#endif
|
2024-06-30 15:38:36 +00:00
|
|
|
case NAME: return ds.has_gps_location() ? QIcon(":geotag-icon") : QVariant();
|
2019-03-09 21:32:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-10-24 14:34:43 +00:00
|
|
|
case DIVESITE_ROLE:
|
2024-05-11 09:47:45 +00:00
|
|
|
return QVariant::fromValue<dive_site *>((dive_site *)&ds); // Not nice: casting away const
|
2015-05-30 00:19:44 +00:00
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2018-10-09 10:26:58 +00:00
|
|
|
QVariant LocationInformationModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
2024-06-08 14:30:24 +00:00
|
|
|
if (!index.isValid() || index.row() >= (int)divelog.sites.size())
|
2018-10-09 10:26:58 +00:00
|
|
|
return QVariant();
|
|
|
|
|
2024-06-08 14:30:24 +00:00
|
|
|
const auto &ds = (divelog.sites)[index.row()].get();
|
2024-05-11 09:47:45 +00:00
|
|
|
return getDiveSiteData(*ds, index.column(), role);
|
2018-10-09 10:26:58 +00:00
|
|
|
}
|
|
|
|
|
2015-05-30 00:19:44 +00:00
|
|
|
void LocationInformationModel::update()
|
|
|
|
{
|
2015-06-02 02:13:51 +00:00
|
|
|
beginResetModel();
|
|
|
|
endResetModel();
|
2015-05-30 00:19:44 +00:00
|
|
|
}
|
2015-06-01 19:58:23 +00:00
|
|
|
|
2019-03-10 15:03:39 +00:00
|
|
|
void LocationInformationModel::diveSiteDiveCountChanged(dive_site *ds)
|
|
|
|
{
|
2024-06-08 14:30:24 +00:00
|
|
|
size_t idx = divelog.sites.get_idx(ds);
|
2024-05-11 12:22:33 +00:00
|
|
|
if (idx != std::string::npos)
|
2019-03-10 15:03:39 +00:00
|
|
|
dataChanged(createIndex(idx, NUM_DIVES), createIndex(idx, NUM_DIVES));
|
|
|
|
}
|
|
|
|
|
2019-03-11 23:25:31 +00:00
|
|
|
void LocationInformationModel::diveSiteAdded(struct dive_site *, int idx)
|
|
|
|
{
|
|
|
|
if (idx < 0)
|
|
|
|
return;
|
|
|
|
beginInsertRows(QModelIndex(), idx, idx);
|
|
|
|
// Row has already been added by Undo-Command.
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationInformationModel::diveSiteDeleted(struct dive_site *, int idx)
|
|
|
|
{
|
|
|
|
if (idx < 0)
|
|
|
|
return;
|
|
|
|
beginRemoveRows(QModelIndex(), idx, idx);
|
|
|
|
// Row has already been added by Undo-Command.
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|
2019-03-12 22:51:39 +00:00
|
|
|
void LocationInformationModel::diveSiteChanged(struct dive_site *ds, int field)
|
|
|
|
{
|
2024-06-08 14:30:24 +00:00
|
|
|
size_t idx = divelog.sites.get_idx(ds);
|
2024-05-11 12:22:33 +00:00
|
|
|
if (idx == std::string::npos)
|
2019-03-12 22:51:39 +00:00
|
|
|
return;
|
|
|
|
dataChanged(createIndex(idx, field), createIndex(idx, field));
|
|
|
|
}
|
|
|
|
|
2019-03-20 20:46:58 +00:00
|
|
|
void LocationInformationModel::diveSiteDivesChanged(struct dive_site *ds)
|
|
|
|
{
|
2024-06-08 14:30:24 +00:00
|
|
|
size_t idx = divelog.sites.get_idx(ds);
|
2024-05-11 12:22:33 +00:00
|
|
|
if (idx == std::string::npos)
|
2019-03-20 20:46:58 +00:00
|
|
|
return;
|
|
|
|
dataChanged(createIndex(idx, NUM_DIVES), createIndex(idx, NUM_DIVES));
|
|
|
|
}
|
|
|
|
|
2019-03-12 16:28:43 +00:00
|
|
|
bool DiveSiteSortedModel::filterAcceptsRow(int sourceRow, const QModelIndex &source_parent) const
|
|
|
|
{
|
2019-03-24 16:11:29 +00:00
|
|
|
if (fullText.isEmpty())
|
|
|
|
return true;
|
|
|
|
|
2024-06-08 14:30:24 +00:00
|
|
|
if (sourceRow < 0 || sourceRow > (int)divelog.sites.size())
|
2019-03-24 16:11:29 +00:00
|
|
|
return false;
|
2024-06-08 14:30:24 +00:00
|
|
|
const auto &ds = (divelog.sites)[sourceRow];
|
2024-05-04 15:18:08 +00:00
|
|
|
QString text = QString::fromStdString(ds->name + ds->description + ds->notes);
|
2019-03-24 16:11:29 +00:00
|
|
|
return text.contains(fullText, Qt::CaseInsensitive);
|
2019-03-12 16:28:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DiveSiteSortedModel::lessThan(const QModelIndex &i1, const QModelIndex &i2) const
|
|
|
|
{
|
|
|
|
// The source indices correspond to indices in the global dive site table.
|
|
|
|
// Let's access them directly without going via the source model.
|
|
|
|
// Kind of dirty, but less effort.
|
2024-05-11 09:47:45 +00:00
|
|
|
|
|
|
|
// Be careful to respect proper ordering when sites are invalid.
|
2024-06-08 14:30:24 +00:00
|
|
|
bool valid1 = i1.row() >= 0 && i1.row() < (int)divelog.sites.size();
|
|
|
|
bool valid2 = i2.row() >= 0 && i2.row() < (int)divelog.sites.size();
|
2024-05-11 09:47:45 +00:00
|
|
|
if (!valid1 || !valid2)
|
|
|
|
return valid1 < valid2;
|
|
|
|
|
2024-06-08 14:30:24 +00:00
|
|
|
const auto &ds1 = (divelog.sites)[i1.row()];
|
|
|
|
const auto &ds2 = (divelog.sites)[i2.row()];
|
2019-03-12 16:28:43 +00:00
|
|
|
switch (i1.column()) {
|
|
|
|
case LocationInformationModel::NAME:
|
|
|
|
default:
|
2024-05-04 15:18:08 +00:00
|
|
|
return QString::localeAwareCompare(QString::fromStdString(ds1->name), QString::fromStdString(ds2->name)) < 0; // TODO: avoid copy
|
2019-03-12 16:28:43 +00:00
|
|
|
case LocationInformationModel::DESCRIPTION: {
|
2024-05-04 15:18:08 +00:00
|
|
|
int cmp = QString::localeAwareCompare(QString::fromStdString(ds1->description), QString::fromStdString(ds2->description)); // TODO: avoid copy
|
2019-03-12 16:28:43 +00:00
|
|
|
return cmp != 0 ? cmp < 0 :
|
2024-05-04 15:18:08 +00:00
|
|
|
QString::localeAwareCompare(QString::fromStdString(ds1->name), QString::fromStdString(ds2->name)) < 0; // TODO: avoid copy
|
2019-03-12 16:28:43 +00:00
|
|
|
}
|
|
|
|
case LocationInformationModel::NUM_DIVES: {
|
2024-05-04 12:41:04 +00:00
|
|
|
int cmp = static_cast<int>(ds1->dives.size()) - static_cast<int>(ds2->dives.size());
|
2019-03-12 16:28:43 +00:00
|
|
|
// Since by default nr dives is descending, invert sort direction of names, such that
|
|
|
|
// the names are listed as ascending.
|
|
|
|
return cmp != 0 ? cmp < 0 :
|
2024-05-04 15:18:08 +00:00
|
|
|
QString::localeAwareCompare(QString::fromStdString(ds1->name), QString::fromStdString(ds2->name)) < 0; // TODO: avoid copy
|
2019-03-12 16:28:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
desktop: fix saving of column-widths of device and site tables
Qt's memory management scheme is completely broken and messes
with common expectations.
QObjects are organized as a tree. The children are destroyed
in the destructor of QObject. This means that they are destructed
after the destructor of the parent object has run and its
sub-object were destructed. Obviously, this makes no sense as
the child objects should be able to access their parent at
any time.
To restore the commonly expected deterministic order of
construction and destruction, one might simply do away with
Qt's silly object tree and organise things using classical
subobjects. However, that breaks with the Qt-generated UI
classes: The objects generated by these classes are *not*
destructed with the UI class. Instead, they are attached
to the widget's QObject tree. Thus these are again destructed
*after* the widget! Who comes up with such a scheme?
In our case this means that we cannot have models used for
TableViews as subobjects, because the TableView needs the
model to save the column widths in the destructor. Which,
as detailed above is called *after* the desctructor of the
widget! Thus, turn these models into heap-allocated objects
and add them to the QObject tree.
Funilly, this exposes another insanity of Qt's QObject tree:
Children are destructed in order of construction! One would
expect that if objects are constructed in the sequence
A, B, C one can expect that C can, at any time, access B and A.
Not so in Qt: The destruction order is likewise A, B, C!
Thus, take care to init the widgets before the model. Jeez.
Finally, print a warning in the column-saving code of
TableWidget, so that these kind of subtleties are caught
in the future.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-11-07 12:20:46 +00:00
|
|
|
DiveSiteSortedModel::DiveSiteSortedModel(QObject *parent) : QSortFilterProxyModel(parent)
|
2019-03-12 16:28:43 +00:00
|
|
|
{
|
|
|
|
setSourceModel(LocationInformationModel::instance());
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList DiveSiteSortedModel::allSiteNames() const
|
|
|
|
{
|
|
|
|
QStringList locationNames;
|
|
|
|
int num = rowCount();
|
|
|
|
for (int i = 0; i < num; i++) {
|
|
|
|
int idx = mapToSource(index(i, 0)).row();
|
2019-08-10 15:28:24 +00:00
|
|
|
// This shouldn't happen, but if model and core get out of sync,
|
|
|
|
// (more precisely: the core has more sites than the model is aware of),
|
|
|
|
// we might get an invalid index.
|
2024-06-08 14:30:24 +00:00
|
|
|
if (idx < 0 || idx > (int)divelog.sites.size()) {
|
2024-03-12 08:25:39 +00:00
|
|
|
report_info("DiveSiteSortedModel::allSiteNames(): invalid index");
|
2019-08-10 15:28:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2024-06-08 14:30:24 +00:00
|
|
|
locationNames << QString::fromStdString((divelog.sites)[idx]->name);
|
2019-03-12 16:28:43 +00:00
|
|
|
}
|
|
|
|
return locationNames;
|
|
|
|
}
|
|
|
|
|
2024-05-11 09:47:45 +00:00
|
|
|
struct dive_site *DiveSiteSortedModel::getDiveSite(const QModelIndex &idx_source)
|
2019-03-12 22:51:39 +00:00
|
|
|
{
|
2024-05-11 09:47:45 +00:00
|
|
|
auto idx = mapToSource(idx_source).row();
|
2024-06-08 14:30:24 +00:00
|
|
|
return idx >= 0 && idx < (int)divelog.sites.size() ? (divelog.sites)[idx].get() : NULL;
|
2019-03-12 22:51:39 +00:00
|
|
|
}
|
|
|
|
|
2019-03-12 21:35:43 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2019-03-12 22:51:39 +00:00
|
|
|
bool DiveSiteSortedModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
|
|
{
|
|
|
|
struct dive_site *ds = getDiveSite(index);
|
|
|
|
if (!ds || value.isNull())
|
|
|
|
return false;
|
|
|
|
switch (index.column()) {
|
|
|
|
case LocationInformationModel::NAME:
|
|
|
|
Command::editDiveSiteName(ds, value.toString());
|
|
|
|
return true;
|
2019-03-13 19:10:22 +00:00
|
|
|
case LocationInformationModel::DESCRIPTION:
|
|
|
|
Command::editDiveSiteDescription(ds, value.toString());
|
|
|
|
return true;
|
2019-03-12 22:51:39 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SUBSURFACE_MOBILE
|
2019-03-12 21:35:43 +00:00
|
|
|
|
2019-03-24 16:11:29 +00:00
|
|
|
void DiveSiteSortedModel::setFilter(const QString &text)
|
|
|
|
{
|
|
|
|
fullText = text.trimmed();
|
|
|
|
invalidateFilter();
|
|
|
|
}
|
|
|
|
|
2018-10-25 06:02:06 +00:00
|
|
|
GeoReferencingOptionsModel *GeoReferencingOptionsModel::instance()
|
|
|
|
{
|
2015-06-22 20:24:15 +00:00
|
|
|
static GeoReferencingOptionsModel *self = new GeoReferencingOptionsModel();
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
GeoReferencingOptionsModel::GeoReferencingOptionsModel(QObject *parent) : QStringListModel(parent)
|
|
|
|
{
|
|
|
|
QStringList list;
|
2015-07-01 19:32:46 +00:00
|
|
|
int i;
|
2015-07-02 17:21:35 +00:00
|
|
|
for (i = 0; i < TC_NR_CATEGORIES; i++)
|
2018-06-17 19:03:16 +00:00
|
|
|
list << gettextFromC::tr(taxonomy_category_names[i]);
|
2015-06-22 20:24:15 +00:00
|
|
|
setStringList(list);
|
|
|
|
}
|
2015-08-31 23:37:49 +00:00
|
|
|
|
2018-10-08 17:01:45 +00:00
|
|
|
bool GPSLocationInformationModel::filterAcceptsRow(int sourceRow, const QModelIndex &parent) const
|
2015-08-31 23:37:49 +00:00
|
|
|
{
|
2020-02-03 09:08:44 +00:00
|
|
|
if (!has_location(&location))
|
|
|
|
return false;
|
|
|
|
|
2018-10-28 20:16:42 +00:00
|
|
|
struct dive_site *ds = sourceModel()->index(sourceRow, LocationInformationModel::DIVESITE, parent).data().value<dive_site *>();
|
2020-02-03 09:08:44 +00:00
|
|
|
if (!ds || ds == ignoreDs || ds == RECENTLY_ADDED_DIVESITE || !has_location(&ds->location))
|
2018-10-08 17:01:45 +00:00
|
|
|
return false;
|
2015-08-31 23:59:13 +00:00
|
|
|
|
2024-05-04 21:20:53 +00:00
|
|
|
return distance <= 0 ? ds->location == location
|
2024-05-11 13:18:37 +00:00
|
|
|
: (int64_t)get_distance(ds->location, location) * 1000 <= distance; // We need 64 bit to represent distances in mm
|
2018-10-08 17:01:45 +00:00
|
|
|
}
|
2015-08-31 23:59:13 +00:00
|
|
|
|
2018-10-08 17:01:45 +00:00
|
|
|
GPSLocationInformationModel::GPSLocationInformationModel(QObject *parent) : QSortFilterProxyModel(parent),
|
2018-10-25 06:02:06 +00:00
|
|
|
ignoreDs(nullptr),
|
2019-03-25 21:18:32 +00:00
|
|
|
location({{0},{0}}),
|
|
|
|
distance(0)
|
2018-10-08 17:01:45 +00:00
|
|
|
{
|
|
|
|
setSourceModel(LocationInformationModel::instance());
|
|
|
|
}
|
2015-08-31 23:37:49 +00:00
|
|
|
|
2018-10-25 06:02:06 +00:00
|
|
|
void GPSLocationInformationModel::set(const struct dive_site *ignoreDsIn, const location_t &locationIn)
|
2018-10-08 17:01:45 +00:00
|
|
|
{
|
2018-10-25 06:02:06 +00:00
|
|
|
ignoreDs = ignoreDsIn;
|
2018-10-20 18:12:15 +00:00
|
|
|
location = locationIn;
|
2018-10-08 17:01:45 +00:00
|
|
|
invalidate();
|
|
|
|
}
|
2015-10-09 17:33:31 +00:00
|
|
|
|
2018-10-20 18:12:15 +00:00
|
|
|
void GPSLocationInformationModel::setCoordinates(const location_t &locationIn)
|
2018-10-08 17:01:45 +00:00
|
|
|
{
|
2018-10-20 18:12:15 +00:00
|
|
|
location = locationIn;
|
2018-10-08 17:01:45 +00:00
|
|
|
invalidate();
|
2015-11-07 20:56:55 +00:00
|
|
|
}
|
2019-03-25 21:18:32 +00:00
|
|
|
|
|
|
|
void GPSLocationInformationModel::setDistance(int64_t dist)
|
|
|
|
{
|
|
|
|
distance = dist;
|
|
|
|
invalidate();
|
|
|
|
}
|