mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Add 'location_t' data structure
Instead of having people treat latitude and longitude as separate things, just add a 'location_t' data structure that contains both. Almost all cases want to always act on them together. This is really just prep-work for adding a few more locations that we track: I want to add a entry/exit location to each dive (independent of the dive site) because of how the Garmin Descent gives us the information (and hopefully, some day, other dive computers too). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
c986940630
commit
28e3413ff6
40 changed files with 251 additions and 264 deletions
|
@ -315,8 +315,8 @@ void DiveLogExportDialog::export_TeX(const char *filename, const bool selected_o
|
|||
put_format(&buf, "\\def\\place{%s}\n", site ? site->name : "");
|
||||
put_format(&buf, "\\def\\spot{}\n");
|
||||
put_format(&buf, "\\def\\sitename{%s}\n", site ? site->name : "");
|
||||
site ? put_format(&buf, "\\def\\gpslat{%f}\n", site->latitude.udeg / 1000000.0) : put_format(&buf, "\\def\\gpslat{}\n");
|
||||
site ? put_format(&buf, "\\def\\gpslon{%f}\n", site->longitude.udeg / 1000000.0) : put_format(&buf, "\\def\\gpslon{}\n");
|
||||
site ? put_format(&buf, "\\def\\gpslat{%f}\n", site->location.lat.udeg / 1000000.0) : put_format(&buf, "\\def\\gpslat{}\n");
|
||||
site ? put_format(&buf, "\\def\\gpslon{%f}\n", site->location.lon.udeg / 1000000.0) : put_format(&buf, "\\def\\gpslon{}\n");
|
||||
put_format(&buf, "\\def\\computer{%s}\n", dive->dc.model);
|
||||
put_format(&buf, "\\def\\country{%s}\n", qPrintable(country));
|
||||
put_format(&buf, "\\def\\time{%u:%02u}\n", FRACTION(dive->duration.seconds, 60));
|
||||
|
|
|
@ -116,8 +116,8 @@ void LocationInformationWidget::updateLabels()
|
|||
ui.diveSiteNotes->setPlainText(diveSite->notes);
|
||||
else
|
||||
ui.diveSiteNotes->clear();
|
||||
if (diveSite->latitude.udeg || diveSite->longitude.udeg) {
|
||||
const char *coords = printGPSCoords(diveSite->latitude.udeg, diveSite->longitude.udeg);
|
||||
if (has_location(&diveSite->location)) {
|
||||
const char *coords = printGPSCoords(&diveSite->location);
|
||||
ui.diveSiteCoordinates->setText(coords);
|
||||
free((void *)coords);
|
||||
} else {
|
||||
|
@ -137,12 +137,13 @@ void LocationInformationWidget::clearLabels()
|
|||
ui.locationTags->clear();
|
||||
}
|
||||
|
||||
void LocationInformationWidget::updateGpsCoordinates(degrees_t latitude, degrees_t longitude)
|
||||
void LocationInformationWidget::updateGpsCoordinates(const location_t &location)
|
||||
{
|
||||
QString oldText = ui.diveSiteCoordinates->text();
|
||||
const char *coords = printGPSCoords(latitude.udeg, longitude.udeg);
|
||||
|
||||
const char *coords = printGPSCoords(&location);
|
||||
ui.diveSiteCoordinates->setText(coords);
|
||||
enableLocationButtons(latitude.udeg || longitude.udeg);
|
||||
enableLocationButtons(has_location(&location));
|
||||
free((void *)coords);
|
||||
if (oldText != ui.diveSiteCoordinates->text())
|
||||
markChangedWidget(ui.diveSiteCoordinates);
|
||||
|
@ -150,12 +151,11 @@ void LocationInformationWidget::updateGpsCoordinates(degrees_t latitude, degrees
|
|||
|
||||
// Parse GPS text into latitude and longitude.
|
||||
// On error, false is returned and the output parameters are left unmodified.
|
||||
bool parseGpsText(const QString &text, degrees_t &latitude, degrees_t &longitude)
|
||||
bool parseGpsText(const QString &text, location_t &location)
|
||||
{
|
||||
double lat, lon;
|
||||
if (parseGpsText(text, &lat, &lon)) {
|
||||
latitude.udeg = lrint(lat * 1000000.0);
|
||||
longitude.udeg = lrint(lon * 1000000.0);
|
||||
location = create_location(lat, lon);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -204,7 +204,7 @@ void LocationInformationWidget::acceptChanges()
|
|||
}
|
||||
|
||||
if (!ui.diveSiteCoordinates->text().isEmpty())
|
||||
parseGpsText(ui.diveSiteCoordinates->text(), diveSite->latitude, diveSite->longitude);
|
||||
parseGpsText(ui.diveSiteCoordinates->text(), diveSite->location);
|
||||
if (dive_site_is_empty(diveSite)) {
|
||||
LocationInformationModel::instance()->removeRow(get_divesite_idx(diveSite));
|
||||
displayed_dive.dive_site_uuid = 0;
|
||||
|
@ -224,7 +224,7 @@ void LocationInformationWidget::initFields(dive_site *ds)
|
|||
diveSite = ds;
|
||||
if (ds) {
|
||||
copy_taxonomy(&ds->taxonomy, &taxonomy);
|
||||
filter_model.set(ds->uuid, ds->latitude, ds->longitude);
|
||||
filter_model.set(ds->uuid, ds->location);
|
||||
updateLabels();
|
||||
enableLocationButtons(dive_site_has_gps_location(ds));
|
||||
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(ui.diveSiteListView->model());
|
||||
|
@ -233,7 +233,7 @@ void LocationInformationWidget::initFields(dive_site *ds)
|
|||
m->invalidate();
|
||||
} else {
|
||||
free_taxonomy(&taxonomy);
|
||||
filter_model.set(0, degrees_t{ 0 }, degrees_t{ 0 });
|
||||
filter_model.set(0, location_t { degrees_t{ 0 }, degrees_t{ 0 } });
|
||||
clearLabels();
|
||||
}
|
||||
MapWidget::instance()->prepareForGetDiveCoordinates(ds ? ds->uuid : 0);
|
||||
|
@ -276,14 +276,14 @@ void LocationInformationWidget::on_diveSiteCoordinates_textChanged(const QString
|
|||
{
|
||||
if (!diveSite)
|
||||
return;
|
||||
degrees_t latitude, longitude;
|
||||
bool ok_old = diveSite->latitude.udeg || diveSite->longitude.udeg;
|
||||
bool ok = parseGpsText(text, latitude, longitude);
|
||||
if (ok != ok_old || latitude.udeg != diveSite->latitude.udeg || longitude.udeg != diveSite->longitude.udeg) {
|
||||
location_t location;
|
||||
bool ok_old = has_location(&diveSite->location);
|
||||
bool ok = parseGpsText(text, location);
|
||||
if (ok != ok_old || !same_location(&location, &diveSite->location)) {
|
||||
if (ok) {
|
||||
markChangedWidget(ui.diveSiteCoordinates);
|
||||
enableLocationButtons(true);
|
||||
filter_model.setCoordinates(latitude, longitude);
|
||||
filter_model.setCoordinates(location);
|
||||
} else {
|
||||
enableLocationButtons(false);
|
||||
}
|
||||
|
@ -326,10 +326,10 @@ void LocationInformationWidget::resetPallete()
|
|||
|
||||
void LocationInformationWidget::reverseGeocode()
|
||||
{
|
||||
degrees_t latitude, longitude;
|
||||
if (!parseGpsText(ui.diveSiteCoordinates->text(), latitude, longitude))
|
||||
location_t location;
|
||||
if (!parseGpsText(ui.diveSiteCoordinates->text(), location))
|
||||
return;
|
||||
reverseGeoLookup(latitude, longitude, &taxonomy);
|
||||
reverseGeoLookup(location.lat, location.lon, &taxonomy);
|
||||
ui.locationTags->setText(constructLocationTags(&taxonomy, false));
|
||||
}
|
||||
|
||||
|
@ -337,11 +337,11 @@ void LocationInformationWidget::updateLocationOnMap()
|
|||
{
|
||||
if (!diveSite)
|
||||
return;
|
||||
degrees_t latitude, longitude;
|
||||
if (!parseGpsText(ui.diveSiteCoordinates->text(), latitude, longitude))
|
||||
location_t location;
|
||||
if (!parseGpsText(ui.diveSiteCoordinates->text(), location))
|
||||
return;
|
||||
MapWidget::instance()->updateDiveSiteCoordinates(diveSite->uuid, latitude, longitude);
|
||||
filter_model.setCoordinates(latitude, longitude);
|
||||
MapWidget::instance()->updateDiveSiteCoordinates(diveSite->uuid, location);
|
||||
filter_model.setCoordinates(location);
|
||||
}
|
||||
|
||||
DiveLocationFilterProxyModel::DiveLocationFilterProxyModel(QObject*)
|
||||
|
|
|
@ -24,7 +24,7 @@ protected:
|
|||
public slots:
|
||||
void acceptChanges();
|
||||
void rejectChanges();
|
||||
void updateGpsCoordinates(degrees_t latitude, degrees_t longitude);
|
||||
void updateGpsCoordinates(const location_t &);
|
||||
void markChangedWidget(QWidget *w);
|
||||
void enableEdition();
|
||||
void resetState();
|
||||
|
|
|
@ -109,16 +109,16 @@ void MapWidget::selectedDivesChanged(QList<int> list)
|
|||
skipReload = false;
|
||||
}
|
||||
|
||||
void MapWidget::coordinatesChangedLocal(degrees_t latitude, degrees_t longitude)
|
||||
void MapWidget::coordinatesChangedLocal(const location_t &location)
|
||||
{
|
||||
CHECK_IS_READY_RETURN_VOID();
|
||||
emit coordinatesChanged(latitude, longitude);
|
||||
emit coordinatesChanged(location);
|
||||
}
|
||||
|
||||
void MapWidget::updateDiveSiteCoordinates(uint32_t uuid, degrees_t latitude, degrees_t longitude)
|
||||
void MapWidget::updateDiveSiteCoordinates(uint32_t uuid, const location_t &location)
|
||||
{
|
||||
CHECK_IS_READY_RETURN_VOID();
|
||||
m_mapHelper->updateDiveSiteCoordinates(uuid, latitude, longitude);
|
||||
m_mapHelper->updateDiveSiteCoordinates(uuid, location);
|
||||
}
|
||||
|
||||
MapWidget::~MapWidget()
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
void reload();
|
||||
|
||||
signals:
|
||||
void coordinatesChanged(degrees_t latitude, degrees_t longitude);
|
||||
void coordinatesChanged(const location_t &);
|
||||
|
||||
public slots:
|
||||
void centerOnSelectedDiveSite();
|
||||
|
@ -35,9 +35,9 @@ public slots:
|
|||
void repopulateLabels();
|
||||
void prepareForGetDiveCoordinates(uint32_t uuid);
|
||||
void selectedDivesChanged(QList<int>);
|
||||
void coordinatesChangedLocal(degrees_t latitude, degrees_t longitude);
|
||||
void coordinatesChangedLocal(const location_t &);
|
||||
void doneLoading(QQuickWidget::Status status);
|
||||
void updateDiveSiteCoordinates(uint32_t uuid, degrees_t latitude, degrees_t longitude);
|
||||
void updateDiveSiteCoordinates(uint32_t uuid, const location_t &);
|
||||
|
||||
private:
|
||||
static MapWidget *m_instance;
|
||||
|
|
|
@ -479,7 +479,7 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
|||
}
|
||||
|
||||
if (bottomText.isEmpty()) {
|
||||
const char *gpsCoords = printGPSCoords(ds->latitude.udeg, ds->longitude.udeg);
|
||||
const char *gpsCoords = printGPSCoords(&ds->location);
|
||||
bottomText = QString(gpsCoords);
|
||||
free( (void*) gpsCoords);
|
||||
}
|
||||
|
@ -487,11 +487,10 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
|||
if (dive_site_has_gps_location(ds) && currentDiveSiteHasGPS) {
|
||||
// so we are showing a completion and both the current dive site and the completion
|
||||
// have a GPS fix... so let's show the distance
|
||||
if (ds->latitude.udeg == currentDiveSite->latitude.udeg &&
|
||||
ds->longitude.udeg == currentDiveSite->longitude.udeg) {
|
||||
if (same_location(&ds->location, ¤tDiveSite->location)) {
|
||||
bottomText += tr(" (same GPS fix)");
|
||||
} else {
|
||||
int distanceMeters = get_distance(ds->latitude, ds->longitude, currentDiveSite->latitude, currentDiveSite->longitude);
|
||||
int distanceMeters = get_distance(&ds->location, ¤tDiveSite->location);
|
||||
QString distance = distance_string(distanceMeters);
|
||||
int nr = nr_of_dives_at_dive_site(ds->uuid, false);
|
||||
bottomText += tr(" (~%1 away").arg(distance);
|
||||
|
|
|
@ -204,10 +204,7 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
|
|||
put_format(&mb, "<divelog><divesites><site uuid='%8x' name='", dive->dive_site_uuid);
|
||||
put_quoted(&mb, ds->name, 1, 0);
|
||||
put_format(&mb, "'");
|
||||
if (ds->latitude.udeg || ds->longitude.udeg) {
|
||||
put_degrees(&mb, ds->latitude, " gps='", " ");
|
||||
put_degrees(&mb, ds->longitude, "", "'");
|
||||
}
|
||||
put_location(&mb, &ds->location, " gps='", "'");
|
||||
put_format(&mb, ">\n");
|
||||
if (ds->taxonomy.nr) {
|
||||
for (int j = 0; j < ds->taxonomy.nr; j++) {
|
||||
|
|
|
@ -696,9 +696,8 @@ uint32_t MainTab::updateDiveSite(uint32_t pickedUuid, dive *d)
|
|||
newDs->name = copy_qstring(ui.location->text());
|
||||
newDs->uuid = pickedUuid;
|
||||
qDebug() << "Creating and copying dive site";
|
||||
} else if (newDs->latitude.udeg == 0 && newDs->longitude.udeg == 0) {
|
||||
newDs->latitude.udeg = origDs->latitude.udeg;
|
||||
newDs->longitude.udeg = origDs->longitude.udeg;
|
||||
} else if (!has_location(&newDs->location)) {
|
||||
newDs->location = origDs->location;
|
||||
qDebug() << "Copying GPS information";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue