mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Maintab: fix trip location / notes editing
Reusing the displayed_dive for this caused all kind of odd problems that were hard to reproduce, because the behavior depended on what was in the corresponding fields of the current_dive. Worse: the GPS location handling prevented us from reliably removing the location of a trip. The solution isn't ideal and certainly isn't elegant. Maybe we simply shouldn't reuse the widget here. But I think what I have now works - I tried hard to make it break again and couldn't. Fixes #659 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
aa4cd34032
commit
1a978a0345
2 changed files with 32 additions and 16 deletions
|
@ -33,12 +33,14 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
||||||
weightModel(new WeightModel(this)),
|
weightModel(new WeightModel(this)),
|
||||||
cylindersModel(CylindersModel::instance()),
|
cylindersModel(CylindersModel::instance()),
|
||||||
editMode(NONE),
|
editMode(NONE),
|
||||||
divePictureModel(DivePictureModel::instance())
|
divePictureModel(DivePictureModel::instance()),
|
||||||
|
currentTrip(0)
|
||||||
{
|
{
|
||||||
ui.setupUi(this);
|
ui.setupUi(this);
|
||||||
ui.dateEdit->setDisplayFormat(getDateFormat());
|
ui.dateEdit->setDisplayFormat(getDateFormat());
|
||||||
|
|
||||||
memset(&displayed_dive, 0, sizeof(displayed_dive));
|
memset(&displayed_dive, 0, sizeof(displayed_dive));
|
||||||
|
memset(&displayedTrip, 0, sizeof(displayedTrip));
|
||||||
|
|
||||||
ui.cylinders->setModel(cylindersModel);
|
ui.cylinders->setModel(cylindersModel);
|
||||||
ui.weights->setModel(weightModel);
|
ui.weights->setModel(weightModel);
|
||||||
|
@ -276,8 +278,7 @@ void MainTab::enableEdition(EditMode newEditMode)
|
||||||
if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) {
|
if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) {
|
||||||
// we are editing trip location and notes
|
// we are editing trip location and notes
|
||||||
displayMessage(tr("This trip is being edited."));
|
displayMessage(tr("This trip is being edited."));
|
||||||
displayed_dive.location = copy_string(current_dive->divetrip->location);
|
currentTrip = current_dive->divetrip;
|
||||||
displayed_dive.notes = copy_string(current_dive->divetrip->notes);
|
|
||||||
ui.dateEdit->setEnabled(false);
|
ui.dateEdit->setEnabled(false);
|
||||||
editMode = TRIP;
|
editMode = TRIP;
|
||||||
} else {
|
} else {
|
||||||
|
@ -398,6 +399,7 @@ void MainTab::updateDiveInfo(bool clear)
|
||||||
ui.timeEdit->setTime(localTime.time());
|
ui.timeEdit->setTime(localTime.time());
|
||||||
if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) {
|
if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) {
|
||||||
setTabText(0, tr("Trip notes"));
|
setTabText(0, tr("Trip notes"));
|
||||||
|
currentTrip = *MainWindow::instance()->dive_list()->selectedTrips().begin();
|
||||||
// only use trip relevant fields
|
// only use trip relevant fields
|
||||||
ui.coordinates->setVisible(false);
|
ui.coordinates->setVisible(false);
|
||||||
ui.CoordinatedLabel->setVisible(false);
|
ui.CoordinatedLabel->setVisible(false);
|
||||||
|
@ -418,7 +420,6 @@ void MainTab::updateDiveInfo(bool clear)
|
||||||
ui.waterTempLabel->setVisible(false);
|
ui.waterTempLabel->setVisible(false);
|
||||||
ui.watertemp->setVisible(false);
|
ui.watertemp->setVisible(false);
|
||||||
// rename the remaining fields and fill data from selected trip
|
// rename the remaining fields and fill data from selected trip
|
||||||
dive_trip_t *currentTrip = *MainWindow::instance()->dive_list()->selectedTrips().begin();
|
|
||||||
ui.LocationLabel->setText(tr("Trip location"));
|
ui.LocationLabel->setText(tr("Trip location"));
|
||||||
ui.location->setText(currentTrip->location);
|
ui.location->setText(currentTrip->location);
|
||||||
ui.NotesLabel->setText(tr("Trip notes"));
|
ui.NotesLabel->setText(tr("Trip notes"));
|
||||||
|
@ -427,6 +428,7 @@ void MainTab::updateDiveInfo(bool clear)
|
||||||
ui.equipmentTab->setEnabled(false);
|
ui.equipmentTab->setEnabled(false);
|
||||||
} else {
|
} else {
|
||||||
setTabText(0, tr("Dive notes"));
|
setTabText(0, tr("Dive notes"));
|
||||||
|
currentTrip = NULL;
|
||||||
// make all the fields visible writeable
|
// make all the fields visible writeable
|
||||||
ui.coordinates->setVisible(true);
|
ui.coordinates->setVisible(true);
|
||||||
ui.CoordinatedLabel->setVisible(true);
|
ui.CoordinatedLabel->setVisible(true);
|
||||||
|
@ -651,14 +653,15 @@ void MainTab::acceptChanges()
|
||||||
amount_selected = 1;
|
amount_selected = 1;
|
||||||
} else if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) {
|
} else if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) {
|
||||||
/* now figure out if things have changed */
|
/* now figure out if things have changed */
|
||||||
if (!same_string(displayed_dive.notes, current_dive->divetrip->notes)) {
|
if (!same_string(displayedTrip.notes, currentTrip->notes)) {
|
||||||
current_dive->divetrip->notes = strdup(displayed_dive.notes);
|
currentTrip->notes = strdup(displayedTrip.notes);
|
||||||
mark_divelist_changed(true);
|
mark_divelist_changed(true);
|
||||||
}
|
}
|
||||||
if (!same_string(displayed_dive.location, current_dive->divetrip->location)) {
|
if (!same_string(displayedTrip.location, currentTrip->location)) {
|
||||||
current_dive->divetrip->location = strdup(displayed_dive.location);
|
currentTrip->location = strdup(displayedTrip.location);
|
||||||
mark_divelist_changed(true);
|
mark_divelist_changed(true);
|
||||||
}
|
}
|
||||||
|
currentTrip = NULL;
|
||||||
ui.dateEdit->setEnabled(true);
|
ui.dateEdit->setEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
struct dive *cd = current_dive;
|
struct dive *cd = current_dive;
|
||||||
|
@ -978,15 +981,21 @@ void MainTab::on_location_textChanged(const QString &text)
|
||||||
{
|
{
|
||||||
if (editMode == IGNORE)
|
if (editMode == IGNORE)
|
||||||
return;
|
return;
|
||||||
free(displayed_dive.location);
|
if (currentTrip) {
|
||||||
displayed_dive.location = strdup(ui.location->text().toUtf8().data());
|
free(displayedTrip.location);
|
||||||
|
displayedTrip.location = strdup(ui.location->text().toUtf8().data());
|
||||||
|
} else {
|
||||||
|
free(displayed_dive.location);
|
||||||
|
displayed_dive.location = strdup(ui.location->text().toUtf8().data());
|
||||||
|
}
|
||||||
markChangedWidget(ui.location);
|
markChangedWidget(ui.location);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have GPS data for the location entered, add it.
|
// If we have GPS data for the location entered, add it.
|
||||||
void MainTab::on_location_editingFinished()
|
void MainTab::on_location_editingFinished()
|
||||||
{
|
{
|
||||||
if (!same_string(displayed_dive.location, "") &&
|
if (!currentTrip &&
|
||||||
|
!same_string(displayed_dive.location, "") &&
|
||||||
ui.coordinates->text().trimmed().isEmpty()) {
|
ui.coordinates->text().trimmed().isEmpty()) {
|
||||||
struct dive *dive;
|
struct dive *dive;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -1016,11 +1025,16 @@ void MainTab::on_notes_textChanged()
|
||||||
{
|
{
|
||||||
if (editMode == IGNORE)
|
if (editMode == IGNORE)
|
||||||
return;
|
return;
|
||||||
free(displayed_dive.notes);
|
if (currentTrip) {
|
||||||
if (ui.notes->toHtml().indexOf("<table") != -1)
|
free(displayedTrip.notes);
|
||||||
displayed_dive.notes = strdup(ui.notes->toHtml().toUtf8().data());
|
displayedTrip.notes = strdup(ui.notes->toPlainText().toUtf8().data());
|
||||||
else
|
} else {
|
||||||
displayed_dive.notes = strdup(ui.notes->toPlainText().toUtf8().data());
|
free(displayed_dive.notes);
|
||||||
|
if (ui.notes->toHtml().indexOf("<table") != -1)
|
||||||
|
displayed_dive.notes = strdup(ui.notes->toHtml().toUtf8().data());
|
||||||
|
else
|
||||||
|
displayed_dive.notes = strdup(ui.notes->toPlainText().toUtf8().data());
|
||||||
|
}
|
||||||
markChangedWidget(ui.notes);
|
markChangedWidget(ui.notes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,8 @@ private:
|
||||||
void saveTags();
|
void saveTags();
|
||||||
void updateGpsCoordinates(const struct dive *dive);
|
void updateGpsCoordinates(const struct dive *dive);
|
||||||
void markChangedWidget(QWidget *w);
|
void markChangedWidget(QWidget *w);
|
||||||
|
dive_trip_t *currentTrip;
|
||||||
|
dive_trip_t displayedTrip;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINTAB_H
|
#endif // MAINTAB_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue