mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Fix crash on adding / removing a dives from add menu
This patch removes some inconsistencies that were happening on the add dive / cancel actions. a bit of legacy code from the old system was still in, which made things quite... EXPLOSIVE. This fixes restoring the selection only if we have a selection and not deleting the temporary dive twice. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
86d7f6ace0
commit
c3306c39f1
3 changed files with 22 additions and 21 deletions
|
@ -29,7 +29,7 @@
|
||||||
#include "../qthelper.h"
|
#include "../qthelper.h"
|
||||||
|
|
||||||
DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false), sortColumn(0),
|
DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false), sortColumn(0),
|
||||||
currentOrder(Qt::DescendingOrder), searchBox(this), dontEmitDiveChangedSignal(false)
|
currentOrder(Qt::DescendingOrder), searchBox(this), dontEmitDiveChangedSignal(false), selectionSaved(false)
|
||||||
{
|
{
|
||||||
setItemDelegate(new DiveListDelegate(this));
|
setItemDelegate(new DiveListDelegate(this));
|
||||||
setUniformRowHeights(true);
|
setUniformRowHeights(true);
|
||||||
|
@ -147,10 +147,15 @@ void DiveListView::rememberSelection()
|
||||||
if (d)
|
if (d)
|
||||||
selectedDives.insert(d->divetrip, get_divenr(d));
|
selectedDives.insert(d->divetrip, get_divenr(d));
|
||||||
}
|
}
|
||||||
|
selectionSaved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveListView::restoreSelection()
|
void DiveListView::restoreSelection()
|
||||||
{
|
{
|
||||||
|
if (!selectionSaved)
|
||||||
|
return;
|
||||||
|
|
||||||
|
selectionSaved = false;
|
||||||
unselectDives();
|
unselectDives();
|
||||||
Q_FOREACH (dive_trip_t *trip, selectedDives.keys()) {
|
Q_FOREACH (dive_trip_t *trip, selectedDives.keys()) {
|
||||||
QList<int> divesOnTrip = getDivesInTrip(trip);
|
QList<int> divesOnTrip = getDivesInTrip(trip);
|
||||||
|
|
|
@ -65,6 +65,7 @@ private:
|
||||||
QLineEdit searchBox;
|
QLineEdit searchBox;
|
||||||
QModelIndex contextMenuIndex;
|
QModelIndex contextMenuIndex;
|
||||||
bool dontEmitDiveChangedSignal;
|
bool dontEmitDiveChangedSignal;
|
||||||
|
bool selectionSaved;
|
||||||
|
|
||||||
/* if dive_trip_t is null, there's no problem. */
|
/* if dive_trip_t is null, there's no problem. */
|
||||||
QMultiHash<dive_trip_t *, int> selectedDives;
|
QMultiHash<dive_trip_t *, int> selectedDives;
|
||||||
|
|
|
@ -804,24 +804,27 @@ void MainTab::rejectChanges()
|
||||||
if (lastMode == ADD) {
|
if (lastMode == ADD) {
|
||||||
// clean up
|
// clean up
|
||||||
DivePlannerPointsModel::instance()->cancelPlan();
|
DivePlannerPointsModel::instance()->cancelPlan();
|
||||||
|
hideMessage();
|
||||||
|
resetPallete();
|
||||||
|
return;
|
||||||
} else if (lastMode == MANUALLY_ADDED_DIVE) {
|
} else if (lastMode == MANUALLY_ADDED_DIVE) {
|
||||||
// when we tried to edit a manually added dive, we destroyed
|
// when we tried to edit a manually added dive, we destroyed
|
||||||
// the dive we edited, so let's just restore it from backup
|
// the dive we edited, so let's just restore it from backup
|
||||||
DivePlannerPointsModel::instance()->restoreBackupDive();
|
DivePlannerPointsModel::instance()->restoreBackupDive();
|
||||||
}
|
}
|
||||||
struct dive *curr = current_dive;
|
struct dive *curr = current_dive;
|
||||||
ui.notes->setText(notesBackup[curr].notes);
|
|
||||||
ui.location->setText(notesBackup[curr].location);
|
|
||||||
ui.buddy->setText(notesBackup[curr].buddy);
|
|
||||||
ui.suit->setText(notesBackup[curr].suit);
|
|
||||||
ui.divemaster->setText(notesBackup[curr].divemaster);
|
|
||||||
ui.rating->setCurrentStars(notesBackup[curr].rating);
|
|
||||||
ui.visibility->setCurrentStars(notesBackup[curr].visibility);
|
|
||||||
ui.airtemp->setText(notesBackup[curr].airtemp);
|
|
||||||
ui.watertemp->setText(notesBackup[curr].watertemp);
|
|
||||||
ui.tagWidget->setText(notesBackup[curr].tags);
|
|
||||||
// it's a little harder to do the right thing for the date time widget
|
|
||||||
if (curr) {
|
if (curr) {
|
||||||
|
ui.notes->setText(notesBackup[curr].notes);
|
||||||
|
ui.location->setText(notesBackup[curr].location);
|
||||||
|
ui.buddy->setText(notesBackup[curr].buddy);
|
||||||
|
ui.suit->setText(notesBackup[curr].suit);
|
||||||
|
ui.divemaster->setText(notesBackup[curr].divemaster);
|
||||||
|
ui.rating->setCurrentStars(notesBackup[curr].rating);
|
||||||
|
ui.visibility->setCurrentStars(notesBackup[curr].visibility);
|
||||||
|
ui.airtemp->setText(notesBackup[curr].airtemp);
|
||||||
|
ui.watertemp->setText(notesBackup[curr].watertemp);
|
||||||
|
ui.tagWidget->setText(notesBackup[curr].tags);
|
||||||
|
// it's a little harder to do the right thing for the date time widget
|
||||||
ui.dateTimeEdit->setDateTime(QDateTime::fromString(notesBackup[curr].datetime));
|
ui.dateTimeEdit->setDateTime(QDateTime::fromString(notesBackup[curr].datetime));
|
||||||
} else {
|
} else {
|
||||||
QLineEdit *le = ui.dateTimeEdit->findChild<QLineEdit *>();
|
QLineEdit *le = ui.dateTimeEdit->findChild<QLineEdit *>();
|
||||||
|
@ -854,12 +857,6 @@ void MainTab::rejectChanges()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateGpsCoordinates(curr);
|
updateGpsCoordinates(curr);
|
||||||
if (lastMode == ADD) {
|
|
||||||
delete_single_dive(selected_dive);
|
|
||||||
MainWindow::instance()->dive_list()->reload(DiveTripModel::CURRENT);
|
|
||||||
MainWindow::instance()->dive_list()->restoreSelection();
|
|
||||||
emit addDiveFinished();
|
|
||||||
}
|
|
||||||
if (selected_dive >= 0) {
|
if (selected_dive >= 0) {
|
||||||
multiEditEquipmentPlaceholder = *get_dive(selected_dive);
|
multiEditEquipmentPlaceholder = *get_dive(selected_dive);
|
||||||
cylindersModel->setDive(&multiEditEquipmentPlaceholder);
|
cylindersModel->setDive(&multiEditEquipmentPlaceholder);
|
||||||
|
@ -873,17 +870,15 @@ void MainTab::rejectChanges()
|
||||||
|
|
||||||
hideMessage();
|
hideMessage();
|
||||||
MainWindow::instance()->dive_list()->setEnabled(true);
|
MainWindow::instance()->dive_list()->setEnabled(true);
|
||||||
notesBackup.clear();
|
|
||||||
resetPallete();
|
resetPallete();
|
||||||
MainWindow::instance()->globe()->reload();
|
MainWindow::instance()->globe()->reload();
|
||||||
if (lastMode == ADD || lastMode == MANUALLY_ADDED_DIVE) {
|
if (lastMode == MANUALLY_ADDED_DIVE) {
|
||||||
// more clean up
|
// more clean up
|
||||||
updateDiveInfo(selected_dive);
|
updateDiveInfo(selected_dive);
|
||||||
MainWindow::instance()->showProfile();
|
MainWindow::instance()->showProfile();
|
||||||
// we already reloaded the divelist above, so don't recreate it or we'll lose the selection
|
// we already reloaded the divelist above, so don't recreate it or we'll lose the selection
|
||||||
MainWindow::instance()->refreshDisplay(false);
|
MainWindow::instance()->refreshDisplay(false);
|
||||||
}
|
}
|
||||||
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING);
|
|
||||||
MainWindow::instance()->dive_list()->setFocus();
|
MainWindow::instance()->dive_list()->setFocus();
|
||||||
// the user could have edited the location and then canceled the edit
|
// the user could have edited the location and then canceled the edit
|
||||||
// let's get the correct location back in view
|
// let's get the correct location back in view
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue