mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
eebb47ec22
commit
9c253ee6c5
81 changed files with 661 additions and 698 deletions
|
|
@ -4,6 +4,7 @@
|
|||
#include "core/subsurface-qt/divelistnotifier.h"
|
||||
#include "core/qthelper.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/metrics.h"
|
||||
#ifndef SUBSURFACE_MOBILE
|
||||
#include "cleanertablemodel.h" // for trashIcon() and editIcon()
|
||||
|
|
@ -36,7 +37,7 @@ int LocationInformationModel::columnCount(const QModelIndex &) const
|
|||
|
||||
int LocationInformationModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return dive_site_table.nr;
|
||||
return divelog.sites->nr;
|
||||
}
|
||||
|
||||
QVariant LocationInformationModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
|
|
@ -124,7 +125,7 @@ QVariant LocationInformationModel::data(const QModelIndex &index, int role) cons
|
|||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
struct dive_site *ds = get_dive_site(index.row(), &dive_site_table);
|
||||
struct dive_site *ds = get_dive_site(index.row(), divelog.sites);
|
||||
return getDiveSiteData(ds, index.column(), role);
|
||||
}
|
||||
|
||||
|
|
@ -136,7 +137,7 @@ void LocationInformationModel::update()
|
|||
|
||||
void LocationInformationModel::diveSiteDiveCountChanged(dive_site *ds)
|
||||
{
|
||||
int idx = get_divesite_idx(ds, &dive_site_table);
|
||||
int idx = get_divesite_idx(ds, divelog.sites);
|
||||
if (idx >= 0)
|
||||
dataChanged(createIndex(idx, NUM_DIVES), createIndex(idx, NUM_DIVES));
|
||||
}
|
||||
|
|
@ -161,7 +162,7 @@ void LocationInformationModel::diveSiteDeleted(struct dive_site *, int idx)
|
|||
|
||||
void LocationInformationModel::diveSiteChanged(struct dive_site *ds, int field)
|
||||
{
|
||||
int idx = get_divesite_idx(ds, &dive_site_table);
|
||||
int idx = get_divesite_idx(ds, divelog.sites);
|
||||
if (idx < 0)
|
||||
return;
|
||||
dataChanged(createIndex(idx, field), createIndex(idx, field));
|
||||
|
|
@ -169,7 +170,7 @@ void LocationInformationModel::diveSiteChanged(struct dive_site *ds, int field)
|
|||
|
||||
void LocationInformationModel::diveSiteDivesChanged(struct dive_site *ds)
|
||||
{
|
||||
int idx = get_divesite_idx(ds, &dive_site_table);
|
||||
int idx = get_divesite_idx(ds, divelog.sites);
|
||||
if (idx < 0)
|
||||
return;
|
||||
dataChanged(createIndex(idx, NUM_DIVES), createIndex(idx, NUM_DIVES));
|
||||
|
|
@ -180,9 +181,9 @@ bool DiveSiteSortedModel::filterAcceptsRow(int sourceRow, const QModelIndex &sou
|
|||
if (fullText.isEmpty())
|
||||
return true;
|
||||
|
||||
if (sourceRow < 0 || sourceRow > dive_site_table.nr)
|
||||
if (sourceRow < 0 || sourceRow > divelog.sites->nr)
|
||||
return false;
|
||||
struct dive_site *ds = dive_site_table.dive_sites[sourceRow];
|
||||
struct dive_site *ds = divelog.sites->dive_sites[sourceRow];
|
||||
QString text = QString(ds->name) + QString(ds->description) + QString(ds->notes);
|
||||
return text.contains(fullText, Qt::CaseInsensitive);
|
||||
}
|
||||
|
|
@ -192,8 +193,8 @@ bool DiveSiteSortedModel::lessThan(const QModelIndex &i1, const QModelIndex &i2)
|
|||
// 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.
|
||||
struct dive_site *ds1 = get_dive_site(i1.row(), &dive_site_table);
|
||||
struct dive_site *ds2 = get_dive_site(i2.row(), &dive_site_table);
|
||||
struct dive_site *ds1 = get_dive_site(i1.row(), divelog.sites);
|
||||
struct dive_site *ds2 = get_dive_site(i2.row(), divelog.sites);
|
||||
if (!ds1 || !ds2) // Invalid dive sites compare as different
|
||||
return false;
|
||||
switch (i1.column()) {
|
||||
|
|
@ -229,18 +230,18 @@ QStringList DiveSiteSortedModel::allSiteNames() const
|
|||
// 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.
|
||||
if (idx < 0 || idx > dive_site_table.nr) {
|
||||
if (idx < 0 || idx > divelog.sites->nr) {
|
||||
SSRF_INFO("DiveSiteSortedModel::allSiteNames(): invalid index");
|
||||
continue;
|
||||
}
|
||||
locationNames << QString(dive_site_table.dive_sites[idx]->name);
|
||||
locationNames << QString(divelog.sites->dive_sites[idx]->name);
|
||||
}
|
||||
return locationNames;
|
||||
}
|
||||
|
||||
struct dive_site *DiveSiteSortedModel::getDiveSite(const QModelIndex &idx)
|
||||
{
|
||||
return get_dive_site(mapToSource(idx).row(), &dive_site_table);
|
||||
return get_dive_site(mapToSource(idx).row(), divelog.sites);
|
||||
}
|
||||
|
||||
#ifndef SUBSURFACE_MOBILE
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "diveplannermodel.h"
|
||||
#include "core/divelist.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/subsurface-string.h"
|
||||
#include "qt-models/cylindermodel.h"
|
||||
#include "core/planner.h"
|
||||
|
|
@ -93,13 +94,12 @@ void DivePlannerPointsModel::setupStartTime()
|
|||
// if the latest dive is in the future, then start an hour after it ends
|
||||
// otherwise start an hour from now
|
||||
startTime = QDateTime::currentDateTimeUtc().addSecs(3600 + gettimezoneoffset());
|
||||
if (dive_table.nr) {
|
||||
struct dive *d = get_dive(dive_table.nr - 1);
|
||||
if (divelog.dives->nr > 0) {
|
||||
struct dive *d = get_dive(divelog.dives->nr - 1);
|
||||
time_t ends = dive_endtime(d);
|
||||
time_t diff = ends - dateTimeToTimestamp(startTime);
|
||||
if (diff > 0) {
|
||||
if (diff > 0)
|
||||
startTime = startTime.addSecs(diff + 3600);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "divesiteimportmodel.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/qthelper.h"
|
||||
#include "core/taxonomy.h"
|
||||
|
||||
|
|
@ -67,7 +68,7 @@ QVariant DivesiteImportedModel::data(const QModelIndex &index, int role) const
|
|||
// 40075000 is circumference of the earth in meters
|
||||
struct dive_site *nearest_ds =
|
||||
get_dive_site_by_gps_proximity(&ds->location,
|
||||
40075000, &dive_site_table);
|
||||
40075000, divelog.sites);
|
||||
if (nearest_ds)
|
||||
return nearest_ds->name;
|
||||
else
|
||||
|
|
@ -77,7 +78,7 @@ QVariant DivesiteImportedModel::data(const QModelIndex &index, int role) const
|
|||
unsigned int distance = 0;
|
||||
struct dive_site *nearest_ds =
|
||||
get_dive_site_by_gps_proximity(&ds->location,
|
||||
40075000, &dive_site_table);
|
||||
40075000, divelog.sites);
|
||||
if (nearest_ds)
|
||||
distance = get_distance(&ds->location,
|
||||
&nearest_ds->location);
|
||||
|
|
@ -134,7 +135,7 @@ void DivesiteImportedModel::repopulate(struct dive_site_table *sites)
|
|||
lastIndex = importedSitesTable->nr - 1;
|
||||
checkStates.resize(importedSitesTable->nr);
|
||||
for (int row = 0; row < importedSitesTable->nr; row++)
|
||||
if (get_dive_site_by_gps(&importedSitesTable->dive_sites[row]->location, &dive_site_table))
|
||||
if (get_dive_site_by_gps(&importedSitesTable->dive_sites[row]->location, divelog.sites))
|
||||
checkStates[row] = false;
|
||||
else
|
||||
checkStates[row] = true;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "qt-models/divetripmodel.h"
|
||||
#include "core/divefilter.h"
|
||||
#include "core/divelog.h"
|
||||
#ifdef SUBSURFACE_MOBILE
|
||||
#include "qt-models/mobilelistmodel.h"
|
||||
#endif
|
||||
|
|
@ -711,7 +712,7 @@ void DiveTripModelTree::populate()
|
|||
// we want this to be two calls as the second text is overwritten below by the lines starting with "\r"
|
||||
uiNotification(QObject::tr("populate data model"));
|
||||
uiNotification(QObject::tr("start processing"));
|
||||
for (int i = 0; i < dive_table.nr; ++i) {
|
||||
for (int i = 0; i < divelog.dives->nr; ++i) {
|
||||
dive *d = get_dive(i);
|
||||
if (!d) // should never happen
|
||||
continue;
|
||||
|
|
@ -741,7 +742,7 @@ void DiveTripModelTree::populate()
|
|||
|
||||
// Remember the index of the current dive
|
||||
oldCurrent = current_dive;
|
||||
uiNotification(QObject::tr("%1 dives processed").arg(dive_table.nr));
|
||||
uiNotification(QObject::tr("%1 dives processed").arg(divelog.dives->nr));
|
||||
}
|
||||
|
||||
int DiveTripModelTree::rowCount(const QModelIndex &parent) const
|
||||
|
|
@ -1470,8 +1471,8 @@ void DiveTripModelList::populate()
|
|||
DiveFilter::instance()->reset(); // The data was reset - update filter status. TODO: should this really be done here?
|
||||
|
||||
// Fill model
|
||||
items.reserve(dive_table.nr);
|
||||
for (int i = 0; i < dive_table.nr; ++i) {
|
||||
items.reserve(divelog.dives->nr);
|
||||
for (int i = 0; i < divelog.dives->nr; ++i) {
|
||||
dive *d = get_dive(i);
|
||||
if (!d || d->hidden_by_filter)
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "divelocationmodel.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/divefilter.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/settings/qPrefDisplay.h"
|
||||
#if !defined(SUBSURFACE_MOBILE) && !defined(SUBSURFACE_DOWNLOADER)
|
||||
#include "qt-models/filtermodels.h"
|
||||
|
|
@ -161,8 +162,8 @@ void MapLocationModel::reload(QObject *map)
|
|||
if (diveSiteMode)
|
||||
m_selectedDs = DiveFilter::instance()->filteredDiveSites();
|
||||
#endif
|
||||
for (int i = 0; i < dive_site_table.nr; ++i) {
|
||||
struct dive_site *ds = dive_site_table.dive_sites[i];
|
||||
for (int i = 0; i < divelog.sites->nr; ++i) {
|
||||
struct dive_site *ds = divelog.sites->dive_sites[i];
|
||||
QGeoCoordinate dsCoord;
|
||||
|
||||
// Don't show dive sites of hidden dives, unless we're in dive site edit mode.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue