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:
Berthold Stoeger 2019-03-25 09:05:47 +01:00 committed by Robert C. Helling
parent 04593e8ec4
commit 40a3e562b0
11 changed files with 24 additions and 39 deletions

View file

@ -113,13 +113,10 @@ void LocationInformationWidget::updateLabels()
ui.diveSiteNotes->setPlainText(diveSite->notes);
else
ui.diveSiteNotes->clear();
if (has_location(&diveSite->location)) {
char *coords = printGPSCoords(&diveSite->location);
ui.diveSiteCoordinates->setText(coords);
free(coords);
} else {
if (has_location(&diveSite->location))
ui.diveSiteCoordinates->setText(printGPSCoords(&diveSite->location));
else
ui.diveSiteCoordinates->clear();
}
ui.locationTags->setText(constructLocationTags(&taxonomy, false));
}
@ -138,10 +135,8 @@ void LocationInformationWidget::updateGpsCoordinates(const location_t &location)
{
QString oldText = ui.diveSiteCoordinates->text();
char *coords = printGPSCoords(&location);
ui.diveSiteCoordinates->setText(coords);
ui.diveSiteCoordinates->setText(printGPSCoords(&location));
enableLocationButtons(has_location(&location));
free(coords);
if (oldText != ui.diveSiteCoordinates->text())
markChangedWidget(ui.diveSiteCoordinates);
}

View file

@ -483,11 +483,8 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
bottomText += QString(ds->taxonomy.category[idx].value);
}
if (bottomText.isEmpty()) {
char *gpsCoords = printGPSCoords(&ds->location);
bottomText = QString(gpsCoords);
free(gpsCoords);
}
if (bottomText.isEmpty())
bottomText = printGPSCoords(&ds->location);
if (dive_site_has_gps_location(ds) && currentDiveSiteHasGPS) {
// so we are showing a completion and both the current dive site and the completion

View file

@ -410,11 +410,8 @@ void MainTab::updateDiveInfo(bool clear)
ui.location->setCurrentDiveSite(ds);
ui.locationTags->setText(constructLocationTags(&ds->taxonomy, true));
if (ui.locationTags->text().isEmpty() && has_location(&ds->location)) {
char *coords = printGPSCoords(&ds->location);
ui.locationTags->setText(coords);
free(coords);
}
if (ui.locationTags->text().isEmpty() && has_location(&ds->location))
ui.locationTags->setText(printGPSCoords(&ds->location));
} else {
ui.location->clear();
ui.locationTags->clear();