mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Cleanup: provide printGPSCoords in C and C++ versions
printGPSCoords() returned a newly allocated C-style string. Most callers simply made a QString out of it and freed the C-style string. This is paradoxical, as printGPSCoords internally works with QStrings and converts them to C-style on return. Therefore, let printGPSCoords() return a QString and create a printGPSCoordsC() wrapper for the two C-callers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
04593e8ec4
commit
40a3e562b0
11 changed files with 24 additions and 39 deletions
|
@ -137,9 +137,7 @@ QString GpsLocation::currentPosition()
|
||||||
if (delta < 300) {
|
if (delta < 300) {
|
||||||
// we can simply use the last position that we tracked
|
// we can simply use the last position that we tracked
|
||||||
gpsTracker gt = m_trackers.last();
|
gpsTracker gt = m_trackers.last();
|
||||||
char *gps = printGPSCoords(>.location);
|
QString gpsString = printGPSCoords(>.location);
|
||||||
QString gpsString = gps;
|
|
||||||
free(gps);
|
|
||||||
qDebug() << "returning last position" << gpsString;
|
qDebug() << "returning last position" << gpsString;
|
||||||
return gpsString;
|
return gpsString;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -164,7 +164,7 @@ static void parse_dive_gps(char *line, struct membuffer *str, void *_dive)
|
||||||
dive->dive_site = ds;
|
dive->dive_site = ds;
|
||||||
} else {
|
} else {
|
||||||
if (dive_site_has_gps_location(ds) && !same_location(&ds->location, &location)) {
|
if (dive_site_has_gps_location(ds) && !same_location(&ds->location, &location)) {
|
||||||
char *coords = printGPSCoords(&location);
|
char *coords = printGPSCoordsC(&location);
|
||||||
// we have a dive site that already has GPS coordinates
|
// we have a dive site that already has GPS coordinates
|
||||||
ds->notes = add_to_string(ds->notes, translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords);
|
ds->notes = add_to_string(ds->notes, translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords);
|
||||||
free(coords);
|
free(coords);
|
||||||
|
|
|
@ -1201,7 +1201,7 @@ static void gps_in_dive(char *buffer, struct dive *dive, struct parser_state *st
|
||||||
fprintf(stderr, "dive site uuid in dive, but gps location (%10.6f/%10.6f) different from dive location (%10.6f/%10.6f)\n",
|
fprintf(stderr, "dive site uuid in dive, but gps location (%10.6f/%10.6f) different from dive location (%10.6f/%10.6f)\n",
|
||||||
ds->location.lat.udeg / 1000000.0, ds->location.lon.udeg / 1000000.0,
|
ds->location.lat.udeg / 1000000.0, ds->location.lon.udeg / 1000000.0,
|
||||||
location.lat.udeg / 1000000.0, location.lon.udeg / 1000000.0);
|
location.lat.udeg / 1000000.0, location.lon.udeg / 1000000.0);
|
||||||
char *coords = printGPSCoords(&location);
|
char *coords = printGPSCoordsC(&location);
|
||||||
ds->notes = add_to_string(ds->notes, translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords);
|
ds->notes = add_to_string(ds->notes, translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords);
|
||||||
free(coords);
|
free(coords);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -72,7 +72,7 @@ QString distance_string(int distanceInMeters)
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" char *printGPSCoords(const location_t *location)
|
QString printGPSCoords(const location_t *location)
|
||||||
{
|
{
|
||||||
int lat = location->lat.udeg;
|
int lat = location->lat.udeg;
|
||||||
int lon = location->lon.udeg;
|
int lon = location->lon.udeg;
|
||||||
|
@ -82,7 +82,7 @@ extern "C" char *printGPSCoords(const location_t *location)
|
||||||
QString lath, lonh, result;
|
QString lath, lonh, result;
|
||||||
|
|
||||||
if (!has_location(location))
|
if (!has_location(location))
|
||||||
return strdup("");
|
return QString();
|
||||||
|
|
||||||
if (prefs.coordinates_traditional) {
|
if (prefs.coordinates_traditional) {
|
||||||
lath = lat >= 0 ? gettextFromC::tr("N") : gettextFromC::tr("S");
|
lath = lat >= 0 ? gettextFromC::tr("N") : gettextFromC::tr("S");
|
||||||
|
@ -101,7 +101,12 @@ extern "C" char *printGPSCoords(const location_t *location)
|
||||||
} else {
|
} else {
|
||||||
result.sprintf("%f %f", (double) lat / 1000000.0, (double) lon / 1000000.0);
|
result.sprintf("%f %f", (double) lat / 1000000.0, (double) lon / 1000000.0);
|
||||||
}
|
}
|
||||||
return copy_qstring(result);
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" char *printGPSCoordsC(const location_t *location)
|
||||||
|
{
|
||||||
|
return copy_qstring(printGPSCoords(location));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -82,6 +82,7 @@ QString uiLanguage(QLocale *callerLoc);
|
||||||
QLocale getLocale();
|
QLocale getLocale();
|
||||||
void selectedDivesGasUsed(QVector<QPair<QString, int> > &gasUsed);
|
void selectedDivesGasUsed(QVector<QPair<QString, int> > &gasUsed);
|
||||||
QString getUserAgent();
|
QString getUserAgent();
|
||||||
|
QString printGPSCoords(const location_t *loc);
|
||||||
|
|
||||||
#if defined __APPLE__
|
#if defined __APPLE__
|
||||||
#define TITLE_OR_TEXT(_t, _m) "", _t + "\n" + _m
|
#define TITLE_OR_TEXT(_t, _m) "", _t + "\n" + _m
|
||||||
|
@ -123,7 +124,7 @@ void moveInVector(Vector &v, int rangeBegin, int rangeEnd, int destination)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char *printGPSCoords(const location_t *loc);
|
char *printGPSCoordsC(const location_t *loc);
|
||||||
bool in_planner();
|
bool in_planner();
|
||||||
bool getProxyString(char **buffer);
|
bool getProxyString(char **buffer);
|
||||||
bool canReachCloudServer();
|
bool canReachCloudServer();
|
||||||
|
|
|
@ -114,10 +114,7 @@ QString DiveObjectHelper::gps() const
|
||||||
struct dive_site *ds = m_dive->dive_site;
|
struct dive_site *ds = m_dive->dive_site;
|
||||||
if (!ds)
|
if (!ds)
|
||||||
return QString();
|
return QString();
|
||||||
char *gps = printGPSCoords(&ds->location);
|
return printGPSCoords(&ds->location);
|
||||||
QString res = gps;
|
|
||||||
free(gps);
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DiveObjectHelper::gps_decimal() const
|
QString DiveObjectHelper::gps_decimal() const
|
||||||
|
|
|
@ -113,13 +113,10 @@ void LocationInformationWidget::updateLabels()
|
||||||
ui.diveSiteNotes->setPlainText(diveSite->notes);
|
ui.diveSiteNotes->setPlainText(diveSite->notes);
|
||||||
else
|
else
|
||||||
ui.diveSiteNotes->clear();
|
ui.diveSiteNotes->clear();
|
||||||
if (has_location(&diveSite->location)) {
|
if (has_location(&diveSite->location))
|
||||||
char *coords = printGPSCoords(&diveSite->location);
|
ui.diveSiteCoordinates->setText(printGPSCoords(&diveSite->location));
|
||||||
ui.diveSiteCoordinates->setText(coords);
|
else
|
||||||
free(coords);
|
|
||||||
} else {
|
|
||||||
ui.diveSiteCoordinates->clear();
|
ui.diveSiteCoordinates->clear();
|
||||||
}
|
|
||||||
|
|
||||||
ui.locationTags->setText(constructLocationTags(&taxonomy, false));
|
ui.locationTags->setText(constructLocationTags(&taxonomy, false));
|
||||||
}
|
}
|
||||||
|
@ -138,10 +135,8 @@ void LocationInformationWidget::updateGpsCoordinates(const location_t &location)
|
||||||
{
|
{
|
||||||
QString oldText = ui.diveSiteCoordinates->text();
|
QString oldText = ui.diveSiteCoordinates->text();
|
||||||
|
|
||||||
char *coords = printGPSCoords(&location);
|
ui.diveSiteCoordinates->setText(printGPSCoords(&location));
|
||||||
ui.diveSiteCoordinates->setText(coords);
|
|
||||||
enableLocationButtons(has_location(&location));
|
enableLocationButtons(has_location(&location));
|
||||||
free(coords);
|
|
||||||
if (oldText != ui.diveSiteCoordinates->text())
|
if (oldText != ui.diveSiteCoordinates->text())
|
||||||
markChangedWidget(ui.diveSiteCoordinates);
|
markChangedWidget(ui.diveSiteCoordinates);
|
||||||
}
|
}
|
||||||
|
|
|
@ -483,11 +483,8 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
||||||
bottomText += QString(ds->taxonomy.category[idx].value);
|
bottomText += QString(ds->taxonomy.category[idx].value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bottomText.isEmpty()) {
|
if (bottomText.isEmpty())
|
||||||
char *gpsCoords = printGPSCoords(&ds->location);
|
bottomText = printGPSCoords(&ds->location);
|
||||||
bottomText = QString(gpsCoords);
|
|
||||||
free(gpsCoords);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dive_site_has_gps_location(ds) && currentDiveSiteHasGPS) {
|
if (dive_site_has_gps_location(ds) && currentDiveSiteHasGPS) {
|
||||||
// so we are showing a completion and both the current dive site and the completion
|
// so we are showing a completion and both the current dive site and the completion
|
||||||
|
|
|
@ -410,11 +410,8 @@ void MainTab::updateDiveInfo(bool clear)
|
||||||
ui.location->setCurrentDiveSite(ds);
|
ui.location->setCurrentDiveSite(ds);
|
||||||
ui.locationTags->setText(constructLocationTags(&ds->taxonomy, true));
|
ui.locationTags->setText(constructLocationTags(&ds->taxonomy, true));
|
||||||
|
|
||||||
if (ui.locationTags->text().isEmpty() && has_location(&ds->location)) {
|
if (ui.locationTags->text().isEmpty() && has_location(&ds->location))
|
||||||
char *coords = printGPSCoords(&ds->location);
|
ui.locationTags->setText(printGPSCoords(&ds->location));
|
||||||
ui.locationTags->setText(coords);
|
|
||||||
free(coords);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
ui.location->clear();
|
ui.location->clear();
|
||||||
ui.locationTags->clear();
|
ui.locationTags->clear();
|
||||||
|
|
|
@ -246,10 +246,8 @@ void MapWidgetHelper::copyToClipboardCoordinates(QGeoCoordinate coord, bool form
|
||||||
bool savep = prefs.coordinates_traditional;
|
bool savep = prefs.coordinates_traditional;
|
||||||
prefs.coordinates_traditional = formatTraditional;
|
prefs.coordinates_traditional = formatTraditional;
|
||||||
location_t location = mk_location(coord);
|
location_t location = mk_location(coord);
|
||||||
char *coordinates = printGPSCoords(&location);
|
QApplication::clipboard()->setText(printGPSCoords(&location), QClipboard::Clipboard);
|
||||||
QApplication::clipboard()->setText(QString(coordinates), QClipboard::Clipboard);
|
|
||||||
|
|
||||||
free(coordinates);
|
|
||||||
prefs.coordinates_traditional = savep;
|
prefs.coordinates_traditional = savep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1604,10 +1604,7 @@ QString QMLManager::getGpsFromSiteName(const QString& siteName)
|
||||||
ds = get_dive_site_by_name(qPrintable(siteName));
|
ds = get_dive_site_by_name(qPrintable(siteName));
|
||||||
if (!ds)
|
if (!ds)
|
||||||
return QString();
|
return QString();
|
||||||
char *gps = printGPSCoords(&ds->location);
|
return printGPSCoords(&ds->location);
|
||||||
QString res = gps;
|
|
||||||
free(gps);
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QMLManager::setNotificationText(QString text)
|
void QMLManager::setNotificationText(QString text)
|
||||||
|
|
Loading…
Add table
Reference in a new issue