Allow walking the dive list with the cursor keys

Figure out what is our first selected element (in case we start out from a
multiple selection) and then move to the next logical element. So the code
traverses an expanded tree (from a trip 'down' to its first dive or 'up'
to the last dive of the previous trip - and similar from a first dive in a
trip 'up' to its trip and from a last dive in a trip 'down' to the next
trip.

This does not take 'shift-cursor-up/down' into account (i.e. manual
selection extension). Instead with just cursor up and down a single dive
(or single trip) is selected.

My guess is that the code will make someone's eyes bleed. Be warned.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-05-12 06:54:34 -07:00
parent a180af3879
commit c729ae92ed
2 changed files with 106 additions and 0 deletions

View file

@ -9,6 +9,7 @@
#include <QMainWindow>
#include <QModelIndex>
#include <QAction>
class QSortFilterProxyModel;
class DiveTripModel;
@ -68,6 +69,10 @@ private Q_SLOTS:
void on_actionAboutSubsurface_triggered();
void on_actionUserManual_triggered();
/* keyboard actions */
void nextDive_triggered();
void previousDive_triggered();
void dive_selection_changed(const QItemSelection& newSelection,
const QItemSelection& oldSelection);
@ -78,6 +83,9 @@ private:
Ui::MainWindow *ui;
DiveTripModel *model;
QSortFilterProxyModel *sortModel;
QAction *actionNextDive;
QAction *actionPreviousDive;
QString filter();
bool askSaveChanges();
void readSettings();