mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Dive list: propagate current-item to frontend
The command-objects select a current item, but this selection was not propagated to the front-end. The current item is the base for keyboard-navigation through the dive-list and therefore should be set correctly. It took some experimentation to get the flags right: QItemSelectionModel::Current Hopefully, these are the correct flags across all supported Qt versions! Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
b16be29595
commit
3c6cdfd8c0
6 changed files with 74 additions and 5 deletions
|
@ -442,6 +442,7 @@ DiveTripModel::DiveTripModel(QObject *parent) :
|
|||
connect(&diveListNotifier, &DiveListNotifier::divesTimeChanged, this, &DiveTripModel::divesTimeChanged);
|
||||
connect(&diveListNotifier, &DiveListNotifier::divesSelected, this, &DiveTripModel::divesSelected);
|
||||
connect(&diveListNotifier, &DiveListNotifier::divesDeselected, this, &DiveTripModel::divesDeselected);
|
||||
connect(&diveListNotifier, &DiveListNotifier::currentDiveChanged, this, &DiveTripModel::currentDiveChanged);
|
||||
}
|
||||
|
||||
int DiveTripModel::columnCount(const QModelIndex&) const
|
||||
|
@ -1166,3 +1167,41 @@ void DiveTripModel::changeDiveSelection(dive_trip *trip, const QVector<dive *> &
|
|||
|
||||
emit selectionChanged(indexes, select);
|
||||
}
|
||||
|
||||
void DiveTripModel::currentDiveChanged()
|
||||
{
|
||||
// The current dive has changed. Transform the current dive into an index and pass it on to the view.
|
||||
if (!current_dive) {
|
||||
emit newCurrentDive(QModelIndex()); // No current dive -> tell view to clear current index with an invalid index
|
||||
return;
|
||||
}
|
||||
|
||||
dive_trip *trip = current_dive->divetrip;
|
||||
if (!trip || currentLayout == LIST) {
|
||||
// Either this is outside of a trip or we're in list mode.
|
||||
int idx = findDiveIdx(current_dive);
|
||||
if (idx < 0) {
|
||||
// We don't know this dive. Something is wrong. Warn and bail.
|
||||
qWarning() << "DiveTripModel::currentDiveChanged(): unknown top-level dive";
|
||||
emit newCurrentDive(QModelIndex());
|
||||
return;
|
||||
}
|
||||
emit newCurrentDive(createIndex(idx, 0, noParent));
|
||||
} else {
|
||||
int idx = findTripIdx(trip);
|
||||
if (idx < 0) {
|
||||
// We don't know the trip - this shouldn't happen. Warn and bail.
|
||||
qWarning() << "DiveTripModel::currentDiveChanged(): unknown trip";
|
||||
emit newCurrentDive(QModelIndex());
|
||||
return;
|
||||
}
|
||||
int diveIdx = findDiveInTrip(idx, current_dive);
|
||||
if (diveIdx < 0) {
|
||||
// We don't know this dive. Something is wrong. Warn and bail.
|
||||
qWarning() << "DiveTripModel::currentDiveChanged(): unknown top-level dive";
|
||||
emit newCurrentDive(QModelIndex());
|
||||
return;
|
||||
}
|
||||
emit newCurrentDive(createIndex(diveIdx, 0, idx));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue