mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Maintain the selection when aborting "dive add"
We remember what was selected before and restore it. Maybe there's a more "Qt way" of doing this, but my implementation appears to work :-) Also remove unconditional debug output that snuck into an earlier commit. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
179615f3a9
commit
dfd17c7a7f
5 changed files with 40 additions and 9 deletions
|
@ -112,6 +112,30 @@ void DiveListView::fixMessyQtModelBehaviour()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this only remembers dives that were selected, not trips
|
||||||
|
void DiveListView::rememberSelection()
|
||||||
|
{
|
||||||
|
selectedDives.clear();
|
||||||
|
QItemSelection selection = selectionModel()->selection();
|
||||||
|
Q_FOREACH(const QModelIndex& index , selection.indexes()) {
|
||||||
|
if (index.column() != 0) // We only care about the dives, so, let's stick to rows and discard columns.
|
||||||
|
continue;
|
||||||
|
struct dive *d = (struct dive *) index.data(DiveTripModel::DIVE_ROLE).value<void*>();
|
||||||
|
if (d)
|
||||||
|
selectedDives.push_front(get_divenr(d));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiveListView::restoreSelection()
|
||||||
|
{
|
||||||
|
unselectDives();
|
||||||
|
Q_FOREACH(int i, selectedDives) {
|
||||||
|
struct dive *d = get_dive(i);
|
||||||
|
if (d)
|
||||||
|
selectDive(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DiveListView::unselectDives()
|
void DiveListView::unselectDives()
|
||||||
{
|
{
|
||||||
selectionModel()->clearSelection();
|
selectionModel()->clearSelection();
|
||||||
|
|
|
@ -26,6 +26,8 @@ public:
|
||||||
bool eventFilter(QObject* , QEvent* );
|
bool eventFilter(QObject* , QEvent* );
|
||||||
void unselectDives();
|
void unselectDives();
|
||||||
void selectDive(struct dive *, bool scrollto = false, bool toggle = false);
|
void selectDive(struct dive *, bool scrollto = false, bool toggle = false);
|
||||||
|
void rememberSelection();
|
||||||
|
void restoreSelection();
|
||||||
void contextMenuEvent(QContextMenuEvent *event);
|
void contextMenuEvent(QContextMenuEvent *event);
|
||||||
QSet<dive_trip_t *> selectedTrips;
|
QSet<dive_trip_t *> selectedTrips;
|
||||||
|
|
||||||
|
@ -50,6 +52,7 @@ signals:
|
||||||
private:
|
private:
|
||||||
bool mouseClickSelection;
|
bool mouseClickSelection;
|
||||||
QList<int> expandedRows;
|
QList<int> expandedRows;
|
||||||
|
QList<int> selectedDives;
|
||||||
int sortColumn;
|
int sortColumn;
|
||||||
Qt::SortOrder currentOrder;
|
Qt::SortOrder currentOrder;
|
||||||
DiveTripModel::Layout currentLayout;
|
DiveTripModel::Layout currentLayout;
|
||||||
|
|
|
@ -493,7 +493,6 @@ void MainTab::acceptChanges()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
save_dive(stdout, current_dive);
|
|
||||||
if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE) {
|
if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE) {
|
||||||
// clean up the dive data (get duration, depth information from samples)
|
// clean up the dive data (get duration, depth information from samples)
|
||||||
fixup_dive(current_dive);
|
fixup_dive(current_dive);
|
||||||
|
@ -558,7 +557,6 @@ void MainTab::rejectChanges()
|
||||||
if (lastMode == ADD) {
|
if (lastMode == ADD) {
|
||||||
// clean up
|
// clean up
|
||||||
DivePlannerPointsModel::instance()->cancelPlan();
|
DivePlannerPointsModel::instance()->cancelPlan();
|
||||||
delete_single_dive(selected_dive);
|
|
||||||
} else if (lastMode == MANUALLY_ADDED_DIVE ) {
|
} else if (lastMode == MANUALLY_ADDED_DIVE ) {
|
||||||
DivePlannerPointsModel::instance()->undoEdition(); // that's BOGUS... just copy the original dive back and be done with it...
|
DivePlannerPointsModel::instance()->undoEdition(); // that's BOGUS... just copy the original dive back and be done with it...
|
||||||
}
|
}
|
||||||
|
@ -609,6 +607,11 @@ void MainTab::rejectChanges()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateGpsCoordinates(curr);
|
updateGpsCoordinates(curr);
|
||||||
|
if (lastMode == ADD) {
|
||||||
|
delete_single_dive(selected_dive);
|
||||||
|
mainWindow()->dive_list()->reload(DiveTripModel::CURRENT);
|
||||||
|
mainWindow()->dive_list()->restoreSelection();
|
||||||
|
}
|
||||||
if (selected_dive >= 0) {
|
if (selected_dive >= 0) {
|
||||||
multiEditEquipmentPlaceholder = *get_dive(selected_dive);
|
multiEditEquipmentPlaceholder = *get_dive(selected_dive);
|
||||||
cylindersModel->setDive(&multiEditEquipmentPlaceholder);
|
cylindersModel->setDive(&multiEditEquipmentPlaceholder);
|
||||||
|
@ -627,14 +630,15 @@ void MainTab::rejectChanges()
|
||||||
ui.equipmentButtonBox->hide();
|
ui.equipmentButtonBox->hide();
|
||||||
notesBackup.clear();
|
notesBackup.clear();
|
||||||
resetPallete();
|
resetPallete();
|
||||||
|
editMode = NONE;
|
||||||
if (lastMode == ADD || lastMode == MANUALLY_ADDED_DIVE) {
|
if (lastMode == ADD || lastMode == MANUALLY_ADDED_DIVE) {
|
||||||
// more clean up
|
// more clean up
|
||||||
updateDiveInfo(selected_dive);
|
updateDiveInfo(selected_dive);
|
||||||
mainWindow()->showProfile();
|
mainWindow()->showProfile();
|
||||||
mainWindow()->refreshDisplay();
|
// we already reloaded the divelist above, so don't recreate it or we'll lose the selection
|
||||||
|
mainWindow()->refreshDisplay(false);
|
||||||
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING);
|
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING);
|
||||||
}
|
}
|
||||||
editMode = NONE;
|
|
||||||
}
|
}
|
||||||
#undef EDIT_TEXT2
|
#undef EDIT_TEXT2
|
||||||
|
|
||||||
|
|
|
@ -65,12 +65,13 @@ MainWindow::MainWindow() : helpView(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// this gets called after we download dives from a divecomputer
|
// this gets called after we download dives from a divecomputer
|
||||||
void MainWindow::refreshDisplay()
|
void MainWindow::refreshDisplay(bool recreateDiveList)
|
||||||
{
|
{
|
||||||
ui.InfoWidget->reload();
|
ui.InfoWidget->reload();
|
||||||
ui.ProfileWidget->refresh();
|
ui.ProfileWidget->refresh();
|
||||||
ui.globe->reload();
|
ui.globe->reload();
|
||||||
ui.ListWidget->reload(DiveTripModel::CURRENT);
|
if (recreateDiveList)
|
||||||
|
ui.ListWidget->reload(DiveTripModel::CURRENT);
|
||||||
ui.ListWidget->setFocus();
|
ui.ListWidget->setFocus();
|
||||||
WSInfoModel *wsim = WSInfoModel::instance();
|
WSInfoModel *wsim = WSInfoModel::instance();
|
||||||
wsim->updateInfo();
|
wsim->updateInfo();
|
||||||
|
@ -282,8 +283,7 @@ void MainWindow::on_actionAddDive_triggered()
|
||||||
QMessageBox::warning(this, tr("Warning"), "First finish the current edition before trying to do another." );
|
QMessageBox::warning(this, tr("Warning"), "First finish the current edition before trying to do another." );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
dive_list()->rememberSelection();
|
||||||
// clear the selection
|
|
||||||
dive_list()->unselectDives();
|
dive_list()->unselectDives();
|
||||||
disableDcShortcuts();
|
disableDcShortcuts();
|
||||||
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD);
|
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD);
|
||||||
|
|
|
@ -108,7 +108,7 @@ protected:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void readSettings();
|
void readSettings();
|
||||||
void refreshDisplay();
|
void refreshDisplay(bool recreateDiveList = true);
|
||||||
void showProfile();
|
void showProfile();
|
||||||
void editCurrentDive();
|
void editCurrentDive();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue