diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-08-14 09:12:21 -0400 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-11 16:22:27 -0700 |
commit | 3c6cdfd8c02e215f98986cbb74b33f58e47fe632 (patch) | |
tree | 206a1eb2bb427df36abe4b08160673dde9bf667b /qt-models | |
parent | b16be29595f09daa422c2c07075d3b8b60e7fad9 (diff) | |
download | subsurface-3c6cdfd8c02e215f98986cbb74b33f58e47fe632.tar.gz |
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>
Diffstat (limited to 'qt-models')
-rw-r--r-- | qt-models/divetripmodel.cpp | 39 | ||||
-rw-r--r-- | qt-models/divetripmodel.h | 2 |
2 files changed, 41 insertions, 0 deletions
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index 7c027e4b4..761a2ffa6 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -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)); + } +} diff --git a/qt-models/divetripmodel.h b/qt-models/divetripmodel.h index 5cd69852c..c8050a6da 100644 --- a/qt-models/divetripmodel.h +++ b/qt-models/divetripmodel.h @@ -118,6 +118,7 @@ signals: // indexes into local indexes according to current sorting/filtering and instructs the QSelectionModel to // perform the appropriate actions. void selectionChanged(const QVector<QModelIndex> &indexes, bool select); + void newCurrentDive(QModelIndex index); private slots: void divesAdded(dive_trip *trip, bool addTrip, const QVector<dive *> &dives); void divesDeleted(dive_trip *trip, bool deleteTrip, const QVector<dive *> &dives); @@ -126,6 +127,7 @@ private slots: void divesMovedBetweenTrips(dive_trip *from, dive_trip *to, bool deleteFrom, bool createTo, const QVector<dive *> &dives); void divesSelected(dive_trip *trip, const QVector<dive *> &dives); void divesDeselected(dive_trip *trip, const QVector<dive *> &dives); + void currentDiveChanged(); private: // The model has up to two levels. At the top level, we have either trips or dives // that do not belong to trips. Such a top-level item is represented by the "Item" |