mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 06:15:26 +00:00
core: move get_dive_location()/_country() to struct dive
Feels natural in a C++ code base. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
f1f082d86a
commit
76d672210d
9 changed files with 18 additions and 21 deletions
|
@ -2496,16 +2496,14 @@ depth_t dive::gas_mnd(struct gasmix mix, depth_t end, int roundto) const
|
|||
return depth_t { (int)lrint(((double)mbar_to_depth(maxambient)) / roundto) * roundto };
|
||||
}
|
||||
|
||||
std::string get_dive_country(const struct dive *dive)
|
||||
std::string dive::get_country() const
|
||||
{
|
||||
struct dive_site *ds = dive->dive_site;
|
||||
return ds ? taxonomy_get_country(ds->taxonomy) : std::string();
|
||||
return dive_site ? taxonomy_get_country(dive_site->taxonomy) : std::string();
|
||||
}
|
||||
|
||||
std::string get_dive_location(const struct dive *dive)
|
||||
std::string dive::get_location() const
|
||||
{
|
||||
const struct dive_site *ds = dive->dive_site;
|
||||
return ds ? ds->name : std::string();
|
||||
return dive_site ? dive_site->name : std::string();
|
||||
}
|
||||
|
||||
int dive::number_of_computers() const
|
||||
|
|
|
@ -111,6 +111,8 @@ struct dive {
|
|||
const cylinder_t *get_cylinder(int idx) const;
|
||||
weight_t total_weight() const;
|
||||
int get_salinity() const;
|
||||
std::string get_country() const;
|
||||
std::string get_location() const;
|
||||
|
||||
int depth_to_mbar(int depth) const;
|
||||
double depth_to_mbarf(int depth) const;
|
||||
|
@ -163,9 +165,6 @@ struct dive_components {
|
|||
extern fraction_t best_o2(depth_t depth, const struct dive *dive, bool in_planner);
|
||||
extern fraction_t best_he(depth_t depth, const struct dive *dive, bool o2narcotic, fraction_t fo2);
|
||||
|
||||
extern std::string get_dive_country(const struct dive *dive);
|
||||
extern std::string get_dive_location(const struct dive *dive);
|
||||
|
||||
extern std::unique_ptr<dive> clone_make_first_dc(const struct dive &d, int dc_number);
|
||||
|
||||
extern bool time_during_dive_with_offset(const struct dive *dive, timestamp_t when, timestamp_t offset);
|
||||
|
|
|
@ -1099,7 +1099,7 @@ static void create_commit_message(struct membuffer *msg, bool create_empty)
|
|||
} else if (!divelog.dives.empty()) {
|
||||
const struct dive &dive = *divelog.dives.back();
|
||||
dive_trip *trip = dive.divetrip;
|
||||
std::string location = get_dive_location(&dive);
|
||||
std::string location = dive.get_location();
|
||||
if (location.empty())
|
||||
location = "no location";
|
||||
const char *sep = "\n";
|
||||
|
|
|
@ -345,7 +345,7 @@ static void write_one_dive(struct membuffer *b, const struct dive &dive, const c
|
|||
put_format(b, "\"subsurface_number\":%d,", dive.number);
|
||||
put_HTML_date(b, dive, "\"date\":\"", "\",");
|
||||
put_HTML_time(b, dive, "\"time\":\"", "\",");
|
||||
write_attribute(b, "location", get_dive_location(&dive).c_str(), ", ");
|
||||
write_attribute(b, "location", dive.get_location().c_str(), ", ");
|
||||
put_HTML_coordinates(b, dive);
|
||||
put_format(b, "\"rating\":%d,", dive.rating);
|
||||
put_format(b, "\"visibility\":%d,", dive.visibility);
|
||||
|
|
|
@ -60,7 +60,7 @@ struct dive_trip *unregister_dive_from_trip(struct dive *dive)
|
|||
std::unique_ptr<dive_trip> create_trip_from_dive(const struct dive *dive)
|
||||
{
|
||||
auto trip = std::make_unique<dive_trip>();
|
||||
trip->location = get_dive_location(dive);
|
||||
trip->location = dive->get_location();
|
||||
|
||||
return trip;
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ std::vector<dives_to_autogroup_result> get_dives_to_autogroup(const struct dive_
|
|||
dive->when >= lastdive->when + TRIP_THRESHOLD)
|
||||
break;
|
||||
if (trip->location.empty())
|
||||
trip->location = get_dive_location(dive.get());
|
||||
trip->location = dive->get_location();
|
||||
lastdive = dive.get();
|
||||
}
|
||||
res.push_back({ i, to, trip, std::move(allocated) });
|
||||
|
|
|
@ -59,7 +59,7 @@ static void writeMarkers(struct membuffer *b, bool selected_only)
|
|||
put_HTML_watertemp(b, *dive, " ", "</p>");
|
||||
pre = format_string_std("<p>%s <b>", translate("gettextFromC", "Location:"));
|
||||
put_string(b, pre.c_str());
|
||||
put_HTML_quoted(b, get_dive_location(dive.get()).c_str());
|
||||
put_HTML_quoted(b, dive->get_location().c_str());
|
||||
put_string(b, "</b></p>");
|
||||
pre = format_string_std("<p> %s ", translate("gettextFromC", "Notes:"));
|
||||
put_HTML_notes(b, *dive, pre.c_str(), " </p>");
|
||||
|
|
|
@ -526,7 +526,7 @@ QVariant TemplateLayout::getValue(QString list, QString property, const State &s
|
|||
} else if (property == "timestamp") {
|
||||
return QVariant::fromValue(d->when);
|
||||
} else if (property == "location") {
|
||||
return QString::fromStdString(get_dive_location(d));
|
||||
return QString::fromStdString(d->get_location());
|
||||
} else if (property == "gps") {
|
||||
return formatDiveGPS(d);
|
||||
} else if (property == "gps_decimal") {
|
||||
|
|
|
@ -1066,7 +1066,7 @@ bool QMLManager::checkLocation(DiveSiteChange &res, struct dive *d, QString loca
|
|||
{
|
||||
struct dive_site *ds = d->dive_site;
|
||||
bool changed = false;
|
||||
QString oldLocation = QString::fromStdString(get_dive_location(d));
|
||||
QString oldLocation = QString::fromStdString(d->get_location());
|
||||
if (oldLocation != location) {
|
||||
ds = divelog.sites.get_by_name(location.toStdString());
|
||||
if (!ds && !location.isEmpty()) {
|
||||
|
|
|
@ -279,7 +279,7 @@ QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role)
|
|||
case MobileListModel::DateTimeRole: return formatDiveDateTime(d);
|
||||
case MobileListModel::IdRole: return d->id;
|
||||
case MobileListModel::NumberRole: return d->number;
|
||||
case MobileListModel::LocationRole: return QString::fromStdString(get_dive_location(d));
|
||||
case MobileListModel::LocationRole: return QString::fromStdString(d->get_location());
|
||||
case MobileListModel::DepthRole: return get_depth_string(d->dcs[0].maxdepth.mm, true, true);
|
||||
case MobileListModel::DurationRole: return formatDiveDuration(d);
|
||||
case MobileListModel::DepthDurationRole: return QStringLiteral("%1 / %2").arg(get_depth_string(d->dcs[0].maxdepth.mm, true, true),
|
||||
|
@ -350,13 +350,13 @@ QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role)
|
|||
case PHOTOS:
|
||||
break;
|
||||
case COUNTRY:
|
||||
return QString::fromStdString(get_dive_country(d));
|
||||
return QString::fromStdString(d->get_country());
|
||||
case BUDDIES:
|
||||
return QString::fromStdString(d->buddy);
|
||||
case DIVEGUIDE:
|
||||
return QString::fromStdString(d->diveguide);
|
||||
case LOCATION:
|
||||
return QString::fromStdString(get_dive_location(d));
|
||||
return QString::fromStdString(d->get_location());
|
||||
case GAS:
|
||||
return formatDiveGasString(d);
|
||||
case NOTES:
|
||||
|
@ -1761,13 +1761,13 @@ bool DiveTripModelList::lessThan(const QModelIndex &i1, const QModelIndex &i2) c
|
|||
case PHOTOS:
|
||||
return lessThanHelper(countPhotos(d1) - countPhotos(d2), row_diff);
|
||||
case COUNTRY:
|
||||
return lessThanHelper(strCmp(get_dive_country(d1), get_dive_country(d2)), row_diff);
|
||||
return lessThanHelper(strCmp(d1->get_country(), d2->get_country()), row_diff);
|
||||
case BUDDIES:
|
||||
return lessThanHelper(strCmp(d1->buddy, d2->buddy), row_diff);
|
||||
case DIVEGUIDE:
|
||||
return lessThanHelper(strCmp(d1->diveguide, d2->diveguide), row_diff);
|
||||
case LOCATION:
|
||||
return lessThanHelper(strCmp(get_dive_location(d1), get_dive_location(d2)), row_diff);
|
||||
return lessThanHelper(strCmp(d1->get_location(), d2->get_location()), row_diff);
|
||||
case NOTES:
|
||||
return lessThanHelper(strCmp(d1->notes, d2->notes), row_diff);
|
||||
case DIVEMODE:
|
||||
|
|
Loading…
Add table
Reference in a new issue