From 1d76ccb8b9bbcb6e2c98e4faca31ddd5d02050ce Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Tue, 17 Sep 2013 21:50:15 +0200 Subject: [PATCH] Improved handling of latitude and longitude. Coordinates are copied when auto-completing location, they are also displayed and editable in maintab. Signed-off-by: Michael Andreen Signed-off-by: Dirk Hohndel --- info.h | 10 +++++- qt-ui/maintab.cpp | 51 ++++++++++++++++++++++++++-- qt-ui/maintab.h | 4 +++ qt-ui/maintab.ui | 86 +++++++++++++++++++++++++++-------------------- 4 files changed, 111 insertions(+), 40 deletions(-) diff --git a/info.h b/info.h index a27373d89..ac8f42d2b 100644 --- a/info.h +++ b/info.h @@ -6,6 +6,10 @@ #ifndef INFO_H #define INFO_H +#ifdef __cplusplus +extern "C" { +#endif + extern gboolean gps_changed(struct dive *dive, struct dive *master, const char *gps_text); extern void print_gps_coordinates(char *buffer, int len, int lat, int lon); extern void save_equipment_data(struct dive *dive); @@ -13,8 +17,12 @@ extern void update_equipment_data(struct dive *dive, struct dive *master); extern void update_time_depth(struct dive *dive, struct dive *edited); extern const char *get_window_title(struct dive *dive); extern char *evaluate_string_change(const char *newstring, char **textp, const char *master); -extern int text_changed(const char *old, const char *new); +extern int text_changed(const char *old, const char * /*new is a c++ keyword*/); extern gboolean parse_gps_text(const char *gps_text, double *latitude, double *longitude); extern int divename(char *buf, size_t size, struct dive *dive, char *trailer); +#ifdef __cplusplus +} +#endif + #endif diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 42250b42c..cb61db84f 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -9,6 +9,7 @@ #include "mainwindow.h" #include "../helpers.h" #include "../statistics.h" +#include "../info.h" #include "divelistview.h" #include "modeldelegates.h" #include "globe.h" @@ -41,6 +42,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), // we start out with the fields read-only; once things are // filled from a dive, they are made writeable ui->location->setReadOnly(true); + ui->coordinates->setReadOnly(true); ui->divemaster->setReadOnly(true); ui->buddy->setReadOnly(true); ui->suit->setReadOnly(true); @@ -52,6 +54,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), ui->editReset->hide(); ui->location->installEventFilter(this); + ui->coordinates->installEventFilter(this); ui->divemaster->installEventFilter(this); ui->buddy->installEventFilter(this); ui->suit->installEventFilter(this); @@ -169,9 +172,14 @@ void MainTab::updateDiveInfo(int dive) UPDATE_TEXT(d, suit); UPDATE_TEXT(d, divemaster); UPDATE_TEXT(d, buddy); + if (d) { + char buffer[256]; + print_gps_coordinates(buffer, sizeof buffer, d->latitude.udeg, d->longitude.udeg); + ui->coordinates->setText(buffer); if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) { // only use trip relevant fields + ui->coordinates->setVisible(false); ui->divemaster->setVisible(false); ui->DivemasterLabel->setVisible(false); ui->buddy->setVisible(false); @@ -192,11 +200,15 @@ void MainTab::updateDiveInfo(int dive) ui->notes->setText(currentTrip->notes); } else { // make all the fields visible writeable + ui->coordinates->setVisible(true); ui->divemaster->setVisible(true); ui->buddy->setVisible(true); ui->suit->setVisible(true); + ui->SuitLabel->setVisible(true); ui->rating->setVisible(true); + ui->RatingLabel->setVisible(true); ui->visibility->setVisible(true); + ui->visibilityLabel->setVisible(true); ui->BuddyLabel->setVisible(true); ui->DivemasterLabel->setVisible(true); ui->divemaster->setReadOnly(false); @@ -209,6 +221,7 @@ void MainTab::updateDiveInfo(int dive) ui->visibility->setCurrentStars(d->visibility); // reset labels in case we last displayed trip notes ui->location->setReadOnly(false); + ui->coordinates->setReadOnly(false); ui->LocationLabel->setText(tr("Location")); ui->notes->setReadOnly(false); ui->NotesLabel->setText(tr("Notes")); @@ -261,6 +274,7 @@ void MainTab::updateDiveInfo(int dive) } else { /* make the fields read-only */ ui->location->setReadOnly(true); + ui->coordinates->setReadOnly(true); ui->divemaster->setReadOnly(true); ui->buddy->setReadOnly(true); ui->suit->setReadOnly(true); @@ -316,6 +330,7 @@ void MainTab::reload() void MainTab::on_editAccept_clicked(bool edit) { ui->location->setReadOnly(!edit); + ui->coordinates->setReadOnly(!edit); ui->divemaster->setReadOnly(!edit); ui->buddy->setReadOnly(!edit); ui->suit->setReadOnly(!edit); @@ -357,6 +372,9 @@ void MainTab::on_editAccept_clicked(bool edit) notesBackup[mydive].location = QString(mydive->location); notesBackup[mydive].rating = mydive->rating; notesBackup[mydive].visibility = mydive->visibility; + notesBackup[mydive].latitude = mydive->latitude; + notesBackup[mydive].longitude = mydive->longitude; + notesBackup[mydive].coordinates = ui->location->text(); } editMode = DIVE; } @@ -376,12 +394,16 @@ void MainTab::on_editAccept_clicked(bool edit) notesBackup[curr].notes != ui->notes->toPlainText() || notesBackup[curr].divemaster != ui->divemaster->text() || notesBackup[curr].location != ui->location->text() || + notesBackup[curr].coordinates != ui->coordinates->text() || notesBackup[curr].rating != ui->visibility->currentStars() || notesBackup[curr].visibility != ui->rating->currentStars()) mark_divelist_changed(TRUE); - if (notesBackup[curr].location != ui->location->text()) + if (notesBackup[curr].location != ui->location->text() || + notesBackup[curr].coordinates != ui->coordinates->text()) { mainWindow()->globe()->reload(); + mainWindow()->globe()->centerOn(current_dive); + } } editMode = NONE; } @@ -415,6 +437,7 @@ void MainTab::on_editReset_clicked() struct dive *curr = current_dive; ui->notes->setText(notesBackup[curr].notes ); ui->location->setText(notesBackup[curr].location); + ui->coordinates->setText(notesBackup[curr].coordinates); ui->buddy->setText(notesBackup[curr].buddy); ui->suit->setText(notesBackup[curr].suit); ui->divemaster->setText(notesBackup[curr].divemaster); @@ -435,6 +458,8 @@ void MainTab::on_editReset_clicked() EDIT_TEXT2(mydive->notes, notesBackup[mydive].notes); EDIT_TEXT2(mydive->divemaster, notesBackup[mydive].divemaster); EDIT_TEXT2(mydive->location, notesBackup[mydive].location); + mydive->latitude = notesBackup[mydive].latitude; + mydive->longitude = notesBackup[mydive].longitude; mydive->rating = notesBackup[mydive].rating; mydive->visibility = notesBackup[mydive].visibility; } @@ -443,6 +468,7 @@ void MainTab::on_editReset_clicked() ui->diveNotesMessage->animatedHide(); ui->location->setReadOnly(true); + ui->coordinates->setReadOnly(true); ui->divemaster->setReadOnly(true); ui->buddy->setReadOnly(true); ui->suit->setReadOnly(true); @@ -467,10 +493,9 @@ void MainTab::on_editReset_clicked() #define EDIT_SELECTED_DIVES( WHAT ) \ if (editMode == NONE) \ return; \ - struct dive *mydive; \ \ for (int i = 0; i < dive_table.nr; i++) { \ - mydive = get_dive(i); \ + struct dive *mydive = get_dive(i); \ if (!mydive) \ continue; \ if (!mydive->selected) \ @@ -506,6 +531,20 @@ void MainTab::on_location_textChanged(const QString& text) dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin(); EDIT_TEXT(currentTrip->location, text); } else if (editMode == DIVE){ + struct dive* dive; + int i = 0; + for_each_dive(i, dive){ + QString location(dive->location); + if (location == text && + (dive->latitude.udeg || dive->longitude.udeg)){ + EDIT_SELECTED_DIVES( mydive->latitude = dive->latitude ) + EDIT_SELECTED_DIVES( mydive->longitude = dive->longitude ) + char buffer[256]; + print_gps_coordinates(buffer, sizeof buffer, dive->latitude.udeg, dive->longitude.udeg); + ui->coordinates->setText(buffer); + break; + } + } EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->location, text) ) } @@ -534,6 +573,12 @@ void MainTab::on_notes_textChanged() #undef EDIT_TEXT +void MainTab::on_coordinates_textChanged(const QString& text) +{ + QByteArray textByteArray = text.toLocal8Bit(); + EDIT_SELECTED_DIVES(gps_changed(mydive, NULL, textByteArray.data())); +} + void MainTab::on_rating_valueChanged(int value) { EDIT_SELECTED_DIVES(mydive->rating = value ); diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index f9f65a3ff..297f27cf9 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -22,6 +22,9 @@ namespace Ui struct NotesBackup{ QString location; + QString coordinates; + degrees_t latitude; + degrees_t longitude; QString notes; QString buddy; QString suit; @@ -56,6 +59,7 @@ public slots: void on_editAccept_clicked(bool edit); void on_editReset_clicked(); void on_location_textChanged(const QString& text); + void on_coordinates_textChanged(const QString& text); void on_divemaster_textChanged(const QString& text); void on_buddy_textChanged(const QString& text); void on_suit_textChanged(const QString& text); diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui index a1f5a718a..967bf133c 100644 --- a/qt-ui/maintab.ui +++ b/qt-ui/maintab.ui @@ -21,6 +21,20 @@ Dive Notes + + + + true + + + + + + + true + + + @@ -28,6 +42,27 @@ + + + + true + + + + + + + true + + + + + + + true + + + @@ -35,49 +70,21 @@ - + Divemaster - + Buddy - - - - true - - - - - - - true - - - - - - - true - - - - - - - true - - - - + @@ -95,21 +102,21 @@ - + Suit - + Notes - + @@ -119,14 +126,14 @@ - + Undo - + Save @@ -139,6 +146,13 @@ + + + + Coordinates + + +