mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
core: fold divesite-helper.cpp into divesite.cpp
The divesite-helper.cpp only existed because C-string manipulation was too tedious. Now that divesite.cpp is C++ anyway, the split is not necessary anymore. Moreover, return an std::string, since this is a core-function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
801b5d50b2
commit
177246b419
6 changed files with 55 additions and 59 deletions
|
@ -72,7 +72,6 @@ set(SUBSURFACE_CORE_LIB_SRCS
|
||||||
divelog.h
|
divelog.h
|
||||||
divelogexportlogic.cpp
|
divelogexportlogic.cpp
|
||||||
divelogexportlogic.h
|
divelogexportlogic.h
|
||||||
divesite-helper.cpp
|
|
||||||
divesite.cpp
|
divesite.cpp
|
||||||
divesite.h
|
divesite.h
|
||||||
divesitehelpers.cpp
|
divesitehelpers.cpp
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0
|
|
||||||
#include "divesite.h"
|
|
||||||
#include "pref.h"
|
|
||||||
#include "gettextfromc.h"
|
|
||||||
|
|
||||||
QString constructLocationTags(taxonomy_data &taxonomy, bool for_maintab)
|
|
||||||
{
|
|
||||||
QString locationTag;
|
|
||||||
|
|
||||||
if (taxonomy.empty())
|
|
||||||
return locationTag;
|
|
||||||
|
|
||||||
/* Check if the user set any of the 3 geocoding categories */
|
|
||||||
bool prefs_set = false;
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
if (prefs.geocoding.category[i] != TC_NONE)
|
|
||||||
prefs_set = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!prefs_set && !for_maintab) {
|
|
||||||
locationTag = QString("<small><small>") + gettextFromC::tr("No dive site layout categories set in preferences!") +
|
|
||||||
QString("</small></small>");
|
|
||||||
return locationTag;
|
|
||||||
}
|
|
||||||
else if (!prefs_set)
|
|
||||||
return locationTag;
|
|
||||||
|
|
||||||
if (for_maintab)
|
|
||||||
locationTag = QString("<small><small>(") + gettextFromC::tr("Tags") + QString(": ");
|
|
||||||
else
|
|
||||||
locationTag = QString("<small><small>");
|
|
||||||
QString connector;
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
if (prefs.geocoding.category[i] == TC_NONE)
|
|
||||||
continue;
|
|
||||||
for (auto const &t: taxonomy) {
|
|
||||||
if (t.category == prefs.geocoding.category[i]) {
|
|
||||||
if (!t.value.empty()) {
|
|
||||||
locationTag += connector + QString::fromStdString(t.value);
|
|
||||||
connector = " / ";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (for_maintab)
|
|
||||||
locationTag += ")</small></small>";
|
|
||||||
else
|
|
||||||
locationTag += "</small></small>";
|
|
||||||
return locationTag;
|
|
||||||
}
|
|
|
@ -5,7 +5,9 @@
|
||||||
#include "divelist.h"
|
#include "divelist.h"
|
||||||
#include "divelog.h"
|
#include "divelog.h"
|
||||||
#include "errorhelper.h"
|
#include "errorhelper.h"
|
||||||
|
#include "gettextfromc.h"
|
||||||
#include "membuffer.h"
|
#include "membuffer.h"
|
||||||
|
#include "pref.h"
|
||||||
#include "subsurface-string.h"
|
#include "subsurface-string.h"
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
#include "sha1.h"
|
#include "sha1.h"
|
||||||
|
@ -378,3 +380,52 @@ struct dive_site *unregister_dive_from_dive_site(struct dive *d)
|
||||||
d->dive_site = nullptr;
|
d->dive_site = nullptr;
|
||||||
return ds;
|
return ds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string constructLocationTags(const taxonomy_data &taxonomy, bool for_maintab)
|
||||||
|
{
|
||||||
|
using namespace std::string_literals;
|
||||||
|
std::string locationTag;
|
||||||
|
|
||||||
|
if (taxonomy.empty())
|
||||||
|
return locationTag;
|
||||||
|
|
||||||
|
/* Check if the user set any of the 3 geocoding categories */
|
||||||
|
bool prefs_set = false;
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
if (prefs.geocoding.category[i] != TC_NONE)
|
||||||
|
prefs_set = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!prefs_set && !for_maintab) {
|
||||||
|
locationTag = "<small><small>" + gettextFromC::tr("No dive site layout categories set in preferences!").toStdString() +
|
||||||
|
"</small></small>"s;
|
||||||
|
return locationTag;
|
||||||
|
}
|
||||||
|
else if (!prefs_set)
|
||||||
|
return locationTag;
|
||||||
|
|
||||||
|
if (for_maintab)
|
||||||
|
locationTag = "<small><small>("s + gettextFromC::tr("Tags").toStdString() + ": "s;
|
||||||
|
else
|
||||||
|
locationTag = "<small><small>"s;
|
||||||
|
std::string connector;
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
if (prefs.geocoding.category[i] == TC_NONE)
|
||||||
|
continue;
|
||||||
|
for (auto const &t: taxonomy) {
|
||||||
|
if (t.category == prefs.geocoding.category[i]) {
|
||||||
|
if (!t.value.empty()) {
|
||||||
|
locationTag += connector + t.value;
|
||||||
|
connector = " / "s;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (for_maintab)
|
||||||
|
locationTag += ")</small></small>"s;
|
||||||
|
else
|
||||||
|
locationTag += "</small></small>"s;
|
||||||
|
return locationTag;
|
||||||
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include <QString>
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
struct dive_site
|
struct dive_site
|
||||||
|
@ -73,8 +72,7 @@ void clear_dive_site_table(struct dive_site_table *ds_table);
|
||||||
void move_dive_site_table(struct dive_site_table *src, struct dive_site_table *dst);
|
void move_dive_site_table(struct dive_site_table *src, struct dive_site_table *dst);
|
||||||
void add_dive_to_dive_site(struct dive *d, struct dive_site *ds);
|
void add_dive_to_dive_site(struct dive *d, struct dive_site *ds);
|
||||||
struct dive_site *unregister_dive_from_dive_site(struct dive *d);
|
struct dive_site *unregister_dive_from_dive_site(struct dive *d);
|
||||||
|
std::string constructLocationTags(const taxonomy_data &taxonomy, bool for_maintab);
|
||||||
QString constructLocationTags(taxonomy_data &taxonomy, bool for_maintab);
|
|
||||||
|
|
||||||
/* Make pointer-to-dive_site a "Qt metatype" so that we can pass it through QVariants */
|
/* Make pointer-to-dive_site a "Qt metatype" so that we can pass it through QVariants */
|
||||||
Q_DECLARE_METATYPE(dive_site *);
|
Q_DECLARE_METATYPE(dive_site *);
|
||||||
|
|
|
@ -152,7 +152,7 @@ void LocationInformationWidget::updateLabels()
|
||||||
ui.diveSiteCoordinates->clear();
|
ui.diveSiteCoordinates->clear();
|
||||||
coordinatesSetWarning(false);
|
coordinatesSetWarning(false);
|
||||||
|
|
||||||
ui.locationTags->setText(constructLocationTags(diveSite->taxonomy, false));
|
ui.locationTags->setText(QString::fromStdString(constructLocationTags(diveSite->taxonomy, false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationInformationWidget::unitsChanged()
|
void LocationInformationWidget::unitsChanged()
|
||||||
|
@ -182,7 +182,7 @@ void LocationInformationWidget::diveSiteChanged(struct dive_site *ds, int field)
|
||||||
return;
|
return;
|
||||||
case LocationInformationModel::TAXONOMY:
|
case LocationInformationModel::TAXONOMY:
|
||||||
ui.diveSiteCountry->setText(QString::fromStdString(taxonomy_get_country(diveSite->taxonomy)));
|
ui.diveSiteCountry->setText(QString::fromStdString(taxonomy_get_country(diveSite->taxonomy)));
|
||||||
ui.locationTags->setText(constructLocationTags(diveSite->taxonomy, false));
|
ui.locationTags->setText(QString::fromStdString(constructLocationTags(diveSite->taxonomy, false)));
|
||||||
return;
|
return;
|
||||||
case LocationInformationModel::LOCATION:
|
case LocationInformationModel::LOCATION:
|
||||||
filter_model.setCoordinates(diveSite->location);
|
filter_model.setCoordinates(diveSite->location);
|
||||||
|
|
|
@ -178,7 +178,7 @@ void TabDiveNotes::updateDiveSite(struct dive *d)
|
||||||
struct dive_site *ds = d->dive_site;
|
struct dive_site *ds = d->dive_site;
|
||||||
ui.location->setCurrentDiveSite(d);
|
ui.location->setCurrentDiveSite(d);
|
||||||
if (ds) {
|
if (ds) {
|
||||||
ui.locationTags->setText(constructLocationTags(ds->taxonomy, true));
|
ui.locationTags->setText(QString::fromStdString(constructLocationTags(ds->taxonomy, true)));
|
||||||
|
|
||||||
if (ui.locationTags->text().isEmpty() && has_location(&ds->location))
|
if (ui.locationTags->text().isEmpty() && has_location(&ds->location))
|
||||||
ui.locationTags->setText(printGPSCoords(&ds->location));
|
ui.locationTags->setText(printGPSCoords(&ds->location));
|
||||||
|
|
Loading…
Reference in a new issue