mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: replace dive_site::dives by an std::vector<>
Since this is now in C++, we don't have to use our crazy TABLE_* macros. This contains a logic change: the dives associated to a dive site are now unsorted. The old code was subtly buggy: dives were added in a sorted manner, but when the dive was edited the list was not resorted. Very unlikely that this leads to a serious problem, still not good. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
3f8b4604be
commit
801b5d50b2
12 changed files with 39 additions and 45 deletions
|
@ -92,7 +92,7 @@ QVariant LocationInformationModel::getDiveSiteData(const struct dive_site *ds, i
|
|||
switch(column) {
|
||||
case DIVESITE: return QVariant::fromValue<dive_site *>((dive_site *)ds); // Not nice: casting away const
|
||||
case NAME: return QString(ds->name);
|
||||
case NUM_DIVES: return ds->dives.nr;
|
||||
case NUM_DIVES: return static_cast<int>(ds->dives.size());
|
||||
case LOCATION: return "TODO";
|
||||
case DESCRIPTION: return QString(ds->description);
|
||||
case NOTES: return QString(ds->name);
|
||||
|
@ -207,7 +207,7 @@ bool DiveSiteSortedModel::lessThan(const QModelIndex &i1, const QModelIndex &i2)
|
|||
QString::localeAwareCompare(QString(ds1->name), QString(ds2->name)) < 0; // TODO: avoid copy
|
||||
}
|
||||
case LocationInformationModel::NUM_DIVES: {
|
||||
int cmp = ds1->dives.nr - ds2->dives.nr;
|
||||
int cmp = static_cast<int>(ds1->dives.size()) - static_cast<int>(ds2->dives.size());
|
||||
// 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 :
|
||||
|
|
|
@ -1199,10 +1199,10 @@ void DiveTripModelTree::divesDeletedInternal(dive_trip *trip, bool deleteTrip, c
|
|||
static QVector<dive *> getDivesForSite(struct dive_site *ds)
|
||||
{
|
||||
QVector<dive *> diveSiteDives;
|
||||
diveSiteDives.reserve(ds->dives.nr);
|
||||
diveSiteDives.reserve(ds->dives.size());
|
||||
|
||||
for (int i = 0; i < ds->dives.nr; ++i)
|
||||
diveSiteDives.push_back(ds->dives.dives[i]);
|
||||
for (dive *d: ds->dives)
|
||||
diveSiteDives.push_back(d);
|
||||
|
||||
return diveSiteDives;
|
||||
}
|
||||
|
|
|
@ -120,13 +120,13 @@ const QVector<dive_site *> &MapLocationModel::selectedDs() const
|
|||
|
||||
static bool hasVisibleDive(const dive_site *ds)
|
||||
{
|
||||
return std::any_of(&ds->dives.dives[0], &ds->dives.dives[ds->dives.nr],
|
||||
return std::any_of(ds->dives.begin(), ds->dives.end(),
|
||||
[] (const dive *d) { return !d->hidden_by_filter; });
|
||||
}
|
||||
|
||||
static bool hasSelectedDive(const dive_site *ds)
|
||||
{
|
||||
return std::any_of(&ds->dives.dives[0], &ds->dives.dives[ds->dives.nr],
|
||||
return std::any_of(ds->dives.begin(), ds->dives.end(),
|
||||
[] (const dive *d) { return d->selected; });
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue