mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
dive models: add helper role to find trip above or below dive
This is only used in the mobile UI where the sort direction is fixed and we refer to dives based on the tree model. So the terms used and the concepts that these rely on should be guaranteed to be valid. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
0cd275af67
commit
ccf5bf6445
4 changed files with 36 additions and 3 deletions
|
@ -964,10 +964,19 @@ QVariant DiveTripModelTree::data(const QModelIndex &index, int role) const
|
||||||
const Item &item = items[index.row()];
|
const Item &item = items[index.row()];
|
||||||
return std::find(item.dives.begin(), item.dives.end(), current_dive) != item.dives.end();
|
return std::find(item.dives.begin(), item.dives.end(), current_dive) != item.dives.end();
|
||||||
}
|
}
|
||||||
if (entry.trip)
|
if (entry.trip) {
|
||||||
return tripData(entry.trip, index.column(), role);
|
return tripData(entry.trip, index.column(), role);
|
||||||
else
|
} else if (entry.dive) {
|
||||||
|
#if defined(SUBSURFACE_MOBILE)
|
||||||
|
if (role == MobileListModel::TripAbove)
|
||||||
|
return tripInDirection(entry.dive, +1);
|
||||||
|
if (role == MobileListModel::TripBelow)
|
||||||
|
return tripInDirection(entry.dive, -1);
|
||||||
|
#endif
|
||||||
return diveData(entry.dive, index.column(), role);
|
return diveData(entry.dive, index.column(), role);
|
||||||
|
} else {
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// After a trip changed, the top level might need to be reordered.
|
// After a trip changed, the top level might need to be reordered.
|
||||||
|
@ -1136,6 +1145,26 @@ static QVector<dive *> visibleDives(const QVector<dive *> &dives)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SUBSURFACE_MOBILE
|
||||||
|
int DiveTripModelTree::tripInDirection(const struct dive *d, int direction) const
|
||||||
|
{
|
||||||
|
for (int i = 0; i < (int)items.size(); ++i) {
|
||||||
|
if (items[i].d_or_t.dive == d || (items[i].d_or_t.trip && findDiveInTrip(i, d) != -1)) {
|
||||||
|
// now walk in the direction given to find a trip
|
||||||
|
int offset = direction;
|
||||||
|
while (i + offset >= 0 && i + offset < (int)items.size()) {
|
||||||
|
if (items[i + offset].d_or_t.trip && (!d->divetrip || items[i + offset].d_or_t.trip->id != d->divetrip->id))
|
||||||
|
// we found a trip (and if the dive is already in a trip, we make sure this is a different trip)
|
||||||
|
return items[i + offset].d_or_t.trip->id;
|
||||||
|
offset += direction;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void DiveTripModelTree::divesAdded(dive_trip *trip, bool newTrip, const QVector<dive *> &divesIn)
|
void DiveTripModelTree::divesAdded(dive_trip *trip, bool newTrip, const QVector<dive *> &divesIn)
|
||||||
{
|
{
|
||||||
QVector <dive *> dives = visibleDives(divesIn);
|
QVector <dive *> dives = visibleDives(divesIn);
|
||||||
|
|
|
@ -77,7 +77,6 @@ public:
|
||||||
// Used for sorting. This is a bit of a layering violation, as sorting should be performed
|
// Used for sorting. This is a bit of a layering violation, as sorting should be performed
|
||||||
// by the higher-up QSortFilterProxyModel, but it makes things so much easier!
|
// by the higher-up QSortFilterProxyModel, but it makes things so much easier!
|
||||||
virtual bool lessThan(const QModelIndex &i1, const QModelIndex &i2) const = 0;
|
virtual bool lessThan(const QModelIndex &i1, const QModelIndex &i2) const = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// The propagation of selection changes is complex.
|
// The propagation of selection changes is complex.
|
||||||
// The control flow of dive-selection goes:
|
// The control flow of dive-selection goes:
|
||||||
|
@ -120,6 +119,7 @@ public slots:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DiveTripModelTree(QObject *parent = nullptr);
|
DiveTripModelTree(QObject *parent = nullptr);
|
||||||
|
int tripInDirection(const struct dive *d, int direction) const;
|
||||||
private:
|
private:
|
||||||
int rowCount(const QModelIndex &parent) const override;
|
int rowCount(const QModelIndex &parent) const override;
|
||||||
void clearData() override;
|
void clearData() override;
|
||||||
|
|
|
@ -47,6 +47,8 @@ QHash<int, QByteArray> MobileListModelBase::roleNames() const
|
||||||
roles[FirstGasRole] = "firstGas";
|
roles[FirstGasRole] = "firstGas";
|
||||||
roles[SelectedRole] = "selected";
|
roles[SelectedRole] = "selected";
|
||||||
roles[DiveInTripRole] = "diveInTrip";
|
roles[DiveInTripRole] = "diveInTrip";
|
||||||
|
roles[TripAbove] = "tripAbove";
|
||||||
|
roles[TripBelow] = "tripBelow";
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,8 @@ public:
|
||||||
FirstGasRole,
|
FirstGasRole,
|
||||||
SelectedRole,
|
SelectedRole,
|
||||||
DiveInTripRole,
|
DiveInTripRole,
|
||||||
|
TripAbove,
|
||||||
|
TripBelow,
|
||||||
};
|
};
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in a new issue