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 <harv@ruin.nu>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Michael Andreen 2013-09-17 21:50:15 +02:00 committed by Dirk Hohndel
parent 06dae680e4
commit 1d76ccb8b9
4 changed files with 111 additions and 40 deletions

10
info.h
View file

@ -6,6 +6,10 @@
#ifndef INFO_H #ifndef INFO_H
#define 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 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 print_gps_coordinates(char *buffer, int len, int lat, int lon);
extern void save_equipment_data(struct dive *dive); 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 void update_time_depth(struct dive *dive, struct dive *edited);
extern const char *get_window_title(struct dive *dive); extern const char *get_window_title(struct dive *dive);
extern char *evaluate_string_change(const char *newstring, char **textp, const char *master); 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 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); extern int divename(char *buf, size_t size, struct dive *dive, char *trailer);
#ifdef __cplusplus
}
#endif
#endif #endif

View file

@ -9,6 +9,7 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "../helpers.h" #include "../helpers.h"
#include "../statistics.h" #include "../statistics.h"
#include "../info.h"
#include "divelistview.h" #include "divelistview.h"
#include "modeldelegates.h" #include "modeldelegates.h"
#include "globe.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 // we start out with the fields read-only; once things are
// filled from a dive, they are made writeable // filled from a dive, they are made writeable
ui->location->setReadOnly(true); ui->location->setReadOnly(true);
ui->coordinates->setReadOnly(true);
ui->divemaster->setReadOnly(true); ui->divemaster->setReadOnly(true);
ui->buddy->setReadOnly(true); ui->buddy->setReadOnly(true);
ui->suit->setReadOnly(true); ui->suit->setReadOnly(true);
@ -52,6 +54,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui->editReset->hide(); ui->editReset->hide();
ui->location->installEventFilter(this); ui->location->installEventFilter(this);
ui->coordinates->installEventFilter(this);
ui->divemaster->installEventFilter(this); ui->divemaster->installEventFilter(this);
ui->buddy->installEventFilter(this); ui->buddy->installEventFilter(this);
ui->suit->installEventFilter(this); ui->suit->installEventFilter(this);
@ -169,9 +172,14 @@ void MainTab::updateDiveInfo(int dive)
UPDATE_TEXT(d, suit); UPDATE_TEXT(d, suit);
UPDATE_TEXT(d, divemaster); UPDATE_TEXT(d, divemaster);
UPDATE_TEXT(d, buddy); UPDATE_TEXT(d, buddy);
if (d) { 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) { if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
// only use trip relevant fields // only use trip relevant fields
ui->coordinates->setVisible(false);
ui->divemaster->setVisible(false); ui->divemaster->setVisible(false);
ui->DivemasterLabel->setVisible(false); ui->DivemasterLabel->setVisible(false);
ui->buddy->setVisible(false); ui->buddy->setVisible(false);
@ -192,11 +200,15 @@ void MainTab::updateDiveInfo(int dive)
ui->notes->setText(currentTrip->notes); ui->notes->setText(currentTrip->notes);
} else { } else {
// make all the fields visible writeable // make all the fields visible writeable
ui->coordinates->setVisible(true);
ui->divemaster->setVisible(true); ui->divemaster->setVisible(true);
ui->buddy->setVisible(true); ui->buddy->setVisible(true);
ui->suit->setVisible(true); ui->suit->setVisible(true);
ui->SuitLabel->setVisible(true);
ui->rating->setVisible(true); ui->rating->setVisible(true);
ui->RatingLabel->setVisible(true);
ui->visibility->setVisible(true); ui->visibility->setVisible(true);
ui->visibilityLabel->setVisible(true);
ui->BuddyLabel->setVisible(true); ui->BuddyLabel->setVisible(true);
ui->DivemasterLabel->setVisible(true); ui->DivemasterLabel->setVisible(true);
ui->divemaster->setReadOnly(false); ui->divemaster->setReadOnly(false);
@ -209,6 +221,7 @@ void MainTab::updateDiveInfo(int dive)
ui->visibility->setCurrentStars(d->visibility); ui->visibility->setCurrentStars(d->visibility);
// reset labels in case we last displayed trip notes // reset labels in case we last displayed trip notes
ui->location->setReadOnly(false); ui->location->setReadOnly(false);
ui->coordinates->setReadOnly(false);
ui->LocationLabel->setText(tr("Location")); ui->LocationLabel->setText(tr("Location"));
ui->notes->setReadOnly(false); ui->notes->setReadOnly(false);
ui->NotesLabel->setText(tr("Notes")); ui->NotesLabel->setText(tr("Notes"));
@ -261,6 +274,7 @@ void MainTab::updateDiveInfo(int dive)
} else { } else {
/* make the fields read-only */ /* make the fields read-only */
ui->location->setReadOnly(true); ui->location->setReadOnly(true);
ui->coordinates->setReadOnly(true);
ui->divemaster->setReadOnly(true); ui->divemaster->setReadOnly(true);
ui->buddy->setReadOnly(true); ui->buddy->setReadOnly(true);
ui->suit->setReadOnly(true); ui->suit->setReadOnly(true);
@ -316,6 +330,7 @@ void MainTab::reload()
void MainTab::on_editAccept_clicked(bool edit) void MainTab::on_editAccept_clicked(bool edit)
{ {
ui->location->setReadOnly(!edit); ui->location->setReadOnly(!edit);
ui->coordinates->setReadOnly(!edit);
ui->divemaster->setReadOnly(!edit); ui->divemaster->setReadOnly(!edit);
ui->buddy->setReadOnly(!edit); ui->buddy->setReadOnly(!edit);
ui->suit->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].location = QString(mydive->location);
notesBackup[mydive].rating = mydive->rating; notesBackup[mydive].rating = mydive->rating;
notesBackup[mydive].visibility = mydive->visibility; notesBackup[mydive].visibility = mydive->visibility;
notesBackup[mydive].latitude = mydive->latitude;
notesBackup[mydive].longitude = mydive->longitude;
notesBackup[mydive].coordinates = ui->location->text();
} }
editMode = DIVE; editMode = DIVE;
} }
@ -376,12 +394,16 @@ void MainTab::on_editAccept_clicked(bool edit)
notesBackup[curr].notes != ui->notes->toPlainText() || notesBackup[curr].notes != ui->notes->toPlainText() ||
notesBackup[curr].divemaster != ui->divemaster->text() || notesBackup[curr].divemaster != ui->divemaster->text() ||
notesBackup[curr].location != ui->location->text() || notesBackup[curr].location != ui->location->text() ||
notesBackup[curr].coordinates != ui->coordinates->text() ||
notesBackup[curr].rating != ui->visibility->currentStars() || notesBackup[curr].rating != ui->visibility->currentStars() ||
notesBackup[curr].visibility != ui->rating->currentStars()) notesBackup[curr].visibility != ui->rating->currentStars())
mark_divelist_changed(TRUE); 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()->reload();
mainWindow()->globe()->centerOn(current_dive);
}
} }
editMode = NONE; editMode = NONE;
} }
@ -415,6 +437,7 @@ void MainTab::on_editReset_clicked()
struct dive *curr = current_dive; struct dive *curr = current_dive;
ui->notes->setText(notesBackup[curr].notes ); ui->notes->setText(notesBackup[curr].notes );
ui->location->setText(notesBackup[curr].location); ui->location->setText(notesBackup[curr].location);
ui->coordinates->setText(notesBackup[curr].coordinates);
ui->buddy->setText(notesBackup[curr].buddy); ui->buddy->setText(notesBackup[curr].buddy);
ui->suit->setText(notesBackup[curr].suit); ui->suit->setText(notesBackup[curr].suit);
ui->divemaster->setText(notesBackup[curr].divemaster); 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->notes, notesBackup[mydive].notes);
EDIT_TEXT2(mydive->divemaster, notesBackup[mydive].divemaster); EDIT_TEXT2(mydive->divemaster, notesBackup[mydive].divemaster);
EDIT_TEXT2(mydive->location, notesBackup[mydive].location); EDIT_TEXT2(mydive->location, notesBackup[mydive].location);
mydive->latitude = notesBackup[mydive].latitude;
mydive->longitude = notesBackup[mydive].longitude;
mydive->rating = notesBackup[mydive].rating; mydive->rating = notesBackup[mydive].rating;
mydive->visibility = notesBackup[mydive].visibility; mydive->visibility = notesBackup[mydive].visibility;
} }
@ -443,6 +468,7 @@ void MainTab::on_editReset_clicked()
ui->diveNotesMessage->animatedHide(); ui->diveNotesMessage->animatedHide();
ui->location->setReadOnly(true); ui->location->setReadOnly(true);
ui->coordinates->setReadOnly(true);
ui->divemaster->setReadOnly(true); ui->divemaster->setReadOnly(true);
ui->buddy->setReadOnly(true); ui->buddy->setReadOnly(true);
ui->suit->setReadOnly(true); ui->suit->setReadOnly(true);
@ -467,10 +493,9 @@ void MainTab::on_editReset_clicked()
#define EDIT_SELECTED_DIVES( WHAT ) \ #define EDIT_SELECTED_DIVES( WHAT ) \
if (editMode == NONE) \ if (editMode == NONE) \
return; \ return; \
struct dive *mydive; \
\ \
for (int i = 0; i < dive_table.nr; i++) { \ for (int i = 0; i < dive_table.nr; i++) { \
mydive = get_dive(i); \ struct dive *mydive = get_dive(i); \
if (!mydive) \ if (!mydive) \
continue; \ continue; \
if (!mydive->selected) \ if (!mydive->selected) \
@ -506,6 +531,20 @@ void MainTab::on_location_textChanged(const QString& text)
dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin(); dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
EDIT_TEXT(currentTrip->location, text); EDIT_TEXT(currentTrip->location, text);
} else if (editMode == DIVE){ } 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) ) EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->location, text) )
} }
@ -534,6 +573,12 @@ void MainTab::on_notes_textChanged()
#undef EDIT_TEXT #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) void MainTab::on_rating_valueChanged(int value)
{ {
EDIT_SELECTED_DIVES(mydive->rating = value ); EDIT_SELECTED_DIVES(mydive->rating = value );

View file

@ -22,6 +22,9 @@ namespace Ui
struct NotesBackup{ struct NotesBackup{
QString location; QString location;
QString coordinates;
degrees_t latitude;
degrees_t longitude;
QString notes; QString notes;
QString buddy; QString buddy;
QString suit; QString suit;
@ -56,6 +59,7 @@ public slots:
void on_editAccept_clicked(bool edit); void on_editAccept_clicked(bool edit);
void on_editReset_clicked(); void on_editReset_clicked();
void on_location_textChanged(const QString& text); void on_location_textChanged(const QString& text);
void on_coordinates_textChanged(const QString& text);
void on_divemaster_textChanged(const QString& text); void on_divemaster_textChanged(const QString& text);
void on_buddy_textChanged(const QString& text); void on_buddy_textChanged(const QString& text);
void on_suit_textChanged(const QString& text); void on_suit_textChanged(const QString& text);

View file

@ -21,6 +21,20 @@
<string>Dive Notes</string> <string>Dive Notes</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="4" column="0" colspan="2">
<widget class="QLineEdit" name="coordinates">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<widget class="QTextEdit" name="notes">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="LocationLabel"> <widget class="QLabel" name="LocationLabel">
<property name="text"> <property name="text">
@ -28,6 +42,27 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="0">
<widget class="QLineEdit" name="divemaster">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QLineEdit" name="suit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="buddy">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2"> <item row="2" column="0" colspan="2">
<widget class="QLineEdit" name="location"> <widget class="QLineEdit" name="location">
<property name="readOnly"> <property name="readOnly">
@ -35,49 +70,21 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="5" column="0">
<widget class="QLabel" name="DivemasterLabel"> <widget class="QLabel" name="DivemasterLabel">
<property name="text"> <property name="text">
<string>Divemaster</string> <string>Divemaster</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="5" column="1">
<widget class="QLabel" name="BuddyLabel"> <widget class="QLabel" name="BuddyLabel">
<property name="text"> <property name="text">
<string>Buddy</string> <string>Buddy</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0"> <item row="7" column="0">
<widget class="QLineEdit" name="divemaster">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="suit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="buddy">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<widget class="QTextEdit" name="notes">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<layout class="QHBoxLayout" name="ratingVisibilityLabels"> <layout class="QHBoxLayout" name="ratingVisibilityLabels">
<item> <item>
<widget class="QLabel" name="RatingLabel"> <widget class="QLabel" name="RatingLabel">
@ -95,21 +102,21 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="5" column="1"> <item row="7" column="1">
<widget class="QLabel" name="SuitLabel"> <widget class="QLabel" name="SuitLabel">
<property name="text"> <property name="text">
<string>Suit</string> <string>Suit</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="0"> <item row="9" column="0">
<widget class="QLabel" name="NotesLabel"> <widget class="QLabel" name="NotesLabel">
<property name="text"> <property name="text">
<string>Notes</string> <string>Notes</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="0"> <item row="8" column="0">
<layout class="QHBoxLayout" name="ratingVisibilityWidgets"> <layout class="QHBoxLayout" name="ratingVisibilityWidgets">
<item> <item>
<widget class="StarWidget" name="rating" native="true"/> <widget class="StarWidget" name="rating" native="true"/>
@ -119,14 +126,14 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="10" column="1"> <item row="12" column="1">
<widget class="QPushButton" name="editReset"> <widget class="QPushButton" name="editReset">
<property name="text"> <property name="text">
<string>Undo</string> <string>Undo</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="10" column="0"> <item row="12" column="0">
<widget class="QPushButton" name="editAccept"> <widget class="QPushButton" name="editAccept">
<property name="text"> <property name="text">
<string>Save</string> <string>Save</string>
@ -139,6 +146,13 @@
<item row="0" column="0" colspan="2"> <item row="0" column="0" colspan="2">
<widget class="KMessageWidget" name="diveNotesMessage" native="true"/> <widget class="KMessageWidget" name="diveNotesMessage" native="true"/>
</item> </item>
<item row="3" column="0">
<widget class="QLabel" name="CoordinatedLabel">
<property name="text">
<string>Coordinates</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="equipmentTab"> <widget class="QWidget" name="equipmentTab">