Compare commits
6 Commits
master
...
bstoeger-c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e6d65ef08 | ||
|
|
4989041efd | ||
|
|
1cc57eaaa4 | ||
|
|
ebfefbc736 | ||
|
|
1faad2c1f1 | ||
|
|
f302be8798 |
@ -1,4 +1,4 @@
|
||||
|
||||
- profile: show local time of cursor position in tooltip (fixes #3469).
|
||||
---
|
||||
* Always add new entries at the very top of this file above other existing entries and this note.
|
||||
* Use this layout for new entries: `[Area]: [Details about the change] [reference thread / issue]`
|
||||
|
||||
@ -48,7 +48,7 @@ struct membuffer {
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
// In C++ code use this - it automatically frees the buffer, when going out of scope.
|
||||
// In C++ code use this - it automatically frees the buffer when going out of scope.
|
||||
struct membufferpp : public membuffer {
|
||||
membufferpp();
|
||||
~membufferpp();
|
||||
|
||||
173
core/profile.c
173
core/profile.c
@ -26,8 +26,6 @@
|
||||
|
||||
//#define DEBUG_GAS 1
|
||||
|
||||
#define MAX_PROFILE_DECO 7200
|
||||
|
||||
extern int ascent_velocity(int depth, int avg_depth, int bottom_time);
|
||||
|
||||
struct dive *current_dive = NULL;
|
||||
@ -59,7 +57,6 @@ static void dump_pi(struct plot_info *pi)
|
||||
#endif
|
||||
|
||||
#define ROUND_UP(x, y) ((((x) + (y) - 1) / (y)) * (y))
|
||||
#define DIV_UP(x, y) (((x) + (y) - 1) / (y))
|
||||
|
||||
/*
|
||||
* When showing dive profiles, we scale things to the
|
||||
@ -1328,176 +1325,6 @@ void create_plot_info_new(const struct dive *dive, const struct divecomputer *dc
|
||||
analyze_plot_info(pi);
|
||||
}
|
||||
|
||||
static void plot_string(const struct dive *d, const struct plot_info *pi, int idx, struct membuffer *b)
|
||||
{
|
||||
int pressurevalue, mod, ead, end, eadd;
|
||||
const char *depth_unit, *pressure_unit, *temp_unit, *vertical_speed_unit;
|
||||
double depthvalue, tempvalue, speedvalue, sacvalue;
|
||||
int decimals, cyl;
|
||||
const char *unit;
|
||||
const struct plot_data *entry = pi->entry + idx;
|
||||
|
||||
depthvalue = get_depth_units(entry->depth, NULL, &depth_unit);
|
||||
put_format_loc(b, translate("gettextFromC", "@: %d:%02d\nD: %.1f%s\n"), FRACTION(entry->sec, 60), depthvalue, depth_unit);
|
||||
for (cyl = 0; cyl < pi->nr_cylinders; cyl++) {
|
||||
int mbar = get_plot_pressure(pi, idx, cyl);
|
||||
if (!mbar)
|
||||
continue;
|
||||
struct gasmix mix = get_cylinder(d, cyl)->gasmix;
|
||||
pressurevalue = get_pressure_units(mbar, &pressure_unit);
|
||||
put_format_loc(b, translate("gettextFromC", "P: %d%s (%s)\n"), pressurevalue, pressure_unit, gasname(mix));
|
||||
}
|
||||
if (entry->temperature) {
|
||||
tempvalue = get_temp_units(entry->temperature, &temp_unit);
|
||||
put_format_loc(b, translate("gettextFromC", "T: %.1f%s\n"), tempvalue, temp_unit);
|
||||
}
|
||||
speedvalue = get_vertical_speed_units(abs(entry->speed), NULL, &vertical_speed_unit);
|
||||
/* Ascending speeds are positive, descending are negative */
|
||||
if (entry->speed > 0)
|
||||
speedvalue *= -1;
|
||||
put_format_loc(b, translate("gettextFromC", "V: %.1f%s\n"), speedvalue, vertical_speed_unit);
|
||||
sacvalue = get_volume_units(entry->sac, &decimals, &unit);
|
||||
if (entry->sac && prefs.show_sac)
|
||||
put_format_loc(b, translate("gettextFromC", "SAC: %.*f%s/min\n"), decimals, sacvalue, unit);
|
||||
if (entry->cns)
|
||||
put_format_loc(b, translate("gettextFromC", "CNS: %u%%\n"), entry->cns);
|
||||
if (prefs.pp_graphs.po2 && entry->pressures.o2 > 0) {
|
||||
put_format_loc(b, translate("gettextFromC", "pO₂: %.2fbar\n"), entry->pressures.o2);
|
||||
if (entry->scr_OC_pO2.mbar)
|
||||
put_format_loc(b, translate("gettextFromC", "SCR ΔpO₂: %.2fbar\n"), entry->scr_OC_pO2.mbar/1000.0 - entry->pressures.o2);
|
||||
}
|
||||
if (prefs.pp_graphs.pn2 && entry->pressures.n2 > 0)
|
||||
put_format_loc(b, translate("gettextFromC", "pN₂: %.2fbar\n"), entry->pressures.n2);
|
||||
if (prefs.pp_graphs.phe && entry->pressures.he > 0)
|
||||
put_format_loc(b, translate("gettextFromC", "pHe: %.2fbar\n"), entry->pressures.he);
|
||||
if (prefs.mod && entry->mod > 0) {
|
||||
mod = lrint(get_depth_units(entry->mod, NULL, &depth_unit));
|
||||
put_format_loc(b, translate("gettextFromC", "MOD: %d%s\n"), mod, depth_unit);
|
||||
}
|
||||
eadd = lrint(get_depth_units(entry->eadd, NULL, &depth_unit));
|
||||
|
||||
if (prefs.ead) {
|
||||
switch (pi->dive_type) {
|
||||
case NITROX:
|
||||
if (entry->ead > 0) {
|
||||
ead = lrint(get_depth_units(entry->ead, NULL, &depth_unit));
|
||||
put_format_loc(b, translate("gettextFromC", "EAD: %d%s\nEADD: %d%s / %.1fg/ℓ\n"), ead, depth_unit, eadd, depth_unit, entry->density);
|
||||
break;
|
||||
}
|
||||
case TRIMIX:
|
||||
if (entry->end > 0) {
|
||||
end = lrint(get_depth_units(entry->end, NULL, &depth_unit));
|
||||
put_format_loc(b, translate("gettextFromC", "END: %d%s\nEADD: %d%s / %.1fg/ℓ\n"), end, depth_unit, eadd, depth_unit, entry->density);
|
||||
break;
|
||||
}
|
||||
case AIR:
|
||||
if (entry->density > 0) {
|
||||
put_format_loc(b, translate("gettextFromC", "Density: %.1fg/ℓ\n"), entry->density);
|
||||
}
|
||||
case FREEDIVING:
|
||||
/* nothing */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (entry->stopdepth) {
|
||||
depthvalue = get_depth_units(entry->stopdepth, NULL, &depth_unit);
|
||||
if (entry->ndl > 0) {
|
||||
/* this is a safety stop as we still have ndl */
|
||||
if (entry->stoptime)
|
||||
put_format_loc(b, translate("gettextFromC", "Safety stop: %umin @ %.0f%s\n"), DIV_UP(entry->stoptime, 60),
|
||||
depthvalue, depth_unit);
|
||||
else
|
||||
put_format_loc(b, translate("gettextFromC", "Safety stop: unknown time @ %.0f%s\n"),
|
||||
depthvalue, depth_unit);
|
||||
} else {
|
||||
/* actual deco stop */
|
||||
if (entry->stoptime)
|
||||
put_format_loc(b, translate("gettextFromC", "Deco: %umin @ %.0f%s\n"), DIV_UP(entry->stoptime, 60),
|
||||
depthvalue, depth_unit);
|
||||
else
|
||||
put_format_loc(b, translate("gettextFromC", "Deco: unknown time @ %.0f%s\n"),
|
||||
depthvalue, depth_unit);
|
||||
}
|
||||
} else if (entry->in_deco) {
|
||||
put_string(b, translate("gettextFromC", "In deco\n"));
|
||||
} else if (entry->ndl >= 0) {
|
||||
put_format_loc(b, translate("gettextFromC", "NDL: %umin\n"), DIV_UP(entry->ndl, 60));
|
||||
}
|
||||
if (entry->tts)
|
||||
put_format_loc(b, translate("gettextFromC", "TTS: %umin\n"), DIV_UP(entry->tts, 60));
|
||||
if (entry->stopdepth_calc && entry->stoptime_calc) {
|
||||
depthvalue = get_depth_units(entry->stopdepth_calc, NULL, &depth_unit);
|
||||
put_format_loc(b, translate("gettextFromC", "Deco: %umin @ %.0f%s (calc)\n"), DIV_UP(entry->stoptime_calc, 60),
|
||||
depthvalue, depth_unit);
|
||||
} else if (entry->in_deco_calc) {
|
||||
/* This means that we have no NDL left,
|
||||
* and we have no deco stop,
|
||||
* so if we just accend to the surface slowly
|
||||
* (ascent_mm_per_step / ascent_s_per_step)
|
||||
* everything will be ok. */
|
||||
put_string(b, translate("gettextFromC", "In deco (calc)\n"));
|
||||
} else if (prefs.calcndltts && entry->ndl_calc != 0) {
|
||||
if(entry->ndl_calc < MAX_PROFILE_DECO)
|
||||
put_format_loc(b, translate("gettextFromC", "NDL: %umin (calc)\n"), DIV_UP(entry->ndl_calc, 60));
|
||||
else
|
||||
put_string(b, translate("gettextFromC", "NDL: >2h (calc)\n"));
|
||||
}
|
||||
if (entry->tts_calc) {
|
||||
if (entry->tts_calc < MAX_PROFILE_DECO)
|
||||
put_format_loc(b, translate("gettextFromC", "TTS: %umin (calc)\n"), DIV_UP(entry->tts_calc, 60));
|
||||
else
|
||||
put_string(b, translate("gettextFromC", "TTS: >2h (calc)\n"));
|
||||
}
|
||||
if (entry->rbt)
|
||||
put_format_loc(b, translate("gettextFromC", "RBT: %umin\n"), DIV_UP(entry->rbt, 60));
|
||||
if (prefs.decoinfo) {
|
||||
if (entry->current_gf > 0.0)
|
||||
put_format(b, translate("gettextFromC", "GF %d%%\n"), (int)(100.0 * entry->current_gf));
|
||||
if (entry->surface_gf > 0.0)
|
||||
put_format(b, translate("gettextFromC", "Surface GF %.0f%%\n"), entry->surface_gf);
|
||||
if (entry->ceiling) {
|
||||
depthvalue = get_depth_units(entry->ceiling, NULL, &depth_unit);
|
||||
put_format_loc(b, translate("gettextFromC", "Calculated ceiling %.1f%s\n"), depthvalue, depth_unit);
|
||||
if (prefs.calcalltissues) {
|
||||
int k;
|
||||
for (k = 0; k < 16; k++) {
|
||||
if (entry->ceilings[k]) {
|
||||
depthvalue = get_depth_units(entry->ceilings[k], NULL, &depth_unit);
|
||||
put_format_loc(b, translate("gettextFromC", "Tissue %.0fmin: %.1f%s\n"), buehlmann_N2_t_halflife[k], depthvalue, depth_unit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (entry->icd_warning)
|
||||
put_format(b, "%s", translate("gettextFromC", "ICD in leading tissue\n"));
|
||||
if (entry->heartbeat && prefs.hrgraph)
|
||||
put_format_loc(b, translate("gettextFromC", "heart rate: %d\n"), entry->heartbeat);
|
||||
if (entry->bearing >= 0)
|
||||
put_format_loc(b, translate("gettextFromC", "bearing: %d\n"), entry->bearing);
|
||||
if (entry->running_sum) {
|
||||
depthvalue = get_depth_units(entry->running_sum / entry->sec, NULL, &depth_unit);
|
||||
put_format_loc(b, translate("gettextFromC", "mean depth to here %.1f%s\n"), depthvalue, depth_unit);
|
||||
}
|
||||
|
||||
strip_mb(b);
|
||||
}
|
||||
|
||||
int get_plot_details_new(const struct dive *d, const struct plot_info *pi, int time, struct membuffer *mb)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* The two first and the two last plot entries do not have useful data */
|
||||
if (pi->nr <= 4)
|
||||
return 0;
|
||||
for (i = 2; i < pi->nr - 3; i++) {
|
||||
if (pi->entry[i].sec >= time)
|
||||
break;
|
||||
}
|
||||
plot_string(d, pi, i, mb);
|
||||
return i;
|
||||
}
|
||||
|
||||
/* Compare two plot_data entries and writes the results into a string */
|
||||
void compare_samples(const struct dive *d, const struct plot_info *pi, int idx1, int idx2, char *buf, int bufsize, bool sum)
|
||||
{
|
||||
|
||||
@ -95,12 +95,12 @@ struct plot_info {
|
||||
};
|
||||
|
||||
#define AMB_PERCENTAGE 50.0
|
||||
#define MAX_PROFILE_DECO 7200
|
||||
|
||||
extern void compare_samples(const struct dive *d, const struct plot_info *pi, int idx1, int idx2, char *buf, int bufsize, bool sum);
|
||||
extern void init_plot_info(struct plot_info *pi);
|
||||
/* when planner_dc is non-null, this is called in planner mode. */
|
||||
extern void create_plot_info_new(const struct dive *dive, const struct divecomputer *dc, struct plot_info *pi, const struct deco_state *planner_ds);
|
||||
extern int get_plot_details_new(const struct dive *d, const struct plot_info *pi, int time, struct membuffer *);
|
||||
extern void free_plot_info_data(struct plot_info *pi);
|
||||
|
||||
/*
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
#include "string-format.h"
|
||||
#include "deco.h"
|
||||
#include "dive.h"
|
||||
#include "divesite.h"
|
||||
#include "format.h"
|
||||
#include "profile.h"
|
||||
#include "qthelper.h"
|
||||
#include "subsurface-string.h"
|
||||
#include "trip.h"
|
||||
@ -300,3 +303,198 @@ QString formatTripTitleWithDives(const dive_trip *trip)
|
||||
return formatTripTitle(trip) + " " +
|
||||
gettextFromC::tr("(%n dive(s))", "", nr);
|
||||
}
|
||||
|
||||
static QString formatTimeOfDay(timestamp_t when)
|
||||
{
|
||||
auto [h, m, s] = utc_time_of_day(when);
|
||||
QLocale loc;
|
||||
QString format = loc.timeFormat(QLocale::LongFormat);
|
||||
// We don't want to show the timezone, as that currently is the
|
||||
// timezone the application is run in, not the timezone of the dive!
|
||||
format.replace("t", "");
|
||||
QTime time(h, m, s);
|
||||
return loc.toString(time, format.trimmed());
|
||||
}
|
||||
|
||||
#define DIV_UP(x, y) (((x) + (y) - 1) / (y))
|
||||
#define translate(x,y) qPrintable(QCoreApplication::translate(x,y))
|
||||
|
||||
static QString formatPlotInfoInternal(const dive *d, const plot_info *pi, int idx)
|
||||
{
|
||||
QString res;
|
||||
int pressurevalue, mod, ead, end, eadd;
|
||||
const char *depth_unit, *pressure_unit, *temp_unit, *vertical_speed_unit;
|
||||
double depthvalue, tempvalue, speedvalue, sacvalue;
|
||||
int decimals, cyl;
|
||||
const char *unit;
|
||||
const struct plot_data *entry = pi->entry + idx;
|
||||
timestamp_t when = d->when + entry->sec;
|
||||
|
||||
depthvalue = get_depth_units(entry->depth, NULL, &depth_unit);
|
||||
res = qasprintf_loc("%s: %d:%02d (%s)\n", translate("gettextFromC", "@"), FRACTION(entry->sec, 60),
|
||||
qPrintable(formatTimeOfDay(when)));
|
||||
res += qasprintf_loc("%s: %.1f%s\n", translate("gettextFromC", "D"), depthvalue, depth_unit);
|
||||
for (cyl = 0; cyl < pi->nr_cylinders; cyl++) {
|
||||
int mbar = get_plot_pressure(pi, idx, cyl);
|
||||
if (!mbar)
|
||||
continue;
|
||||
struct gasmix mix = get_cylinder(d, cyl)->gasmix;
|
||||
pressurevalue = get_pressure_units(mbar, &pressure_unit);
|
||||
res += qasprintf_loc("%s: %d%s (%s)\n", translate("gettextFromC", "P"), pressurevalue, pressure_unit, gasname(mix));
|
||||
}
|
||||
if (entry->temperature) {
|
||||
tempvalue = get_temp_units(entry->temperature, &temp_unit);
|
||||
res += qasprintf_loc("%s: %.1f%s\n", translate("gettextFromC", "T"), tempvalue, temp_unit);
|
||||
}
|
||||
speedvalue = get_vertical_speed_units(abs(entry->speed), NULL, &vertical_speed_unit);
|
||||
/* Ascending speeds are positive, descending are negative */
|
||||
if (entry->speed > 0)
|
||||
speedvalue *= -1;
|
||||
res += qasprintf_loc("%s: %.1f%s\n", translate("gettextFromC", "V"), speedvalue, vertical_speed_unit);
|
||||
sacvalue = get_volume_units(entry->sac, &decimals, &unit);
|
||||
if (entry->sac && prefs.show_sac)
|
||||
res += qasprintf_loc("%s: %.*f%s/%s\n", translate("gettextFromC", "SAC"), decimals, sacvalue, unit, translate("gettextFromC", "min"));
|
||||
if (entry->cns)
|
||||
res += qasprintf_loc("%s: %u%%\n", translate("gettextFromC", "CNS"), entry->cns);
|
||||
if (prefs.pp_graphs.po2 && entry->pressures.o2 > 0) {
|
||||
res += qasprintf_loc("%s: %.2f%s\n", translate("gettextFromC", "pO₂"), entry->pressures.o2, translate("gettextFromC", "bar"));
|
||||
if (entry->scr_OC_pO2.mbar)
|
||||
res += qasprintf_loc("%s: %.2f%s\n", translate("gettextFromC", "SCR ΔpO₂"), entry->scr_OC_pO2.mbar/1000.0 - entry->pressures.o2,
|
||||
translate("gettextFromC", "bar"));
|
||||
}
|
||||
if (prefs.pp_graphs.pn2 && entry->pressures.n2 > 0)
|
||||
res += qasprintf_loc("%s: %.2f%s\n", translate("gettextFromC", "pN₂"), entry->pressures.n2, translate("gettextFromC", "bar"));
|
||||
if (prefs.pp_graphs.phe && entry->pressures.he > 0)
|
||||
res += qasprintf_loc("%s: %.2f%s\n", translate("gettextFromC", "pHe"), entry->pressures.he, translate("gettextFromC", "bar"));
|
||||
if (prefs.mod && entry->mod > 0) {
|
||||
mod = lrint(get_depth_units(entry->mod, NULL, &depth_unit));
|
||||
res += qasprintf_loc("%s: %d%s\n", translate("gettextFromC", "MOD"), mod, depth_unit);
|
||||
}
|
||||
eadd = lrint(get_depth_units(entry->eadd, NULL, &depth_unit));
|
||||
|
||||
if (prefs.ead) {
|
||||
switch (pi->dive_type) {
|
||||
case plot_info::NITROX:
|
||||
if (entry->ead > 0) {
|
||||
ead = lrint(get_depth_units(entry->ead, NULL, &depth_unit));
|
||||
res += qasprintf_loc("%s: %d%s\n", translate("gettextFromC", "EAD"), ead, depth_unit);
|
||||
res += qasprintf_loc("%s: %d%s / %.1fg/ℓ\n", translate("gettextFromC", "EADO"), eadd, depth_unit, entry->density);
|
||||
break;
|
||||
}
|
||||
case plot_info::TRIMIX:
|
||||
if (entry->end > 0) {
|
||||
end = lrint(get_depth_units(entry->end, NULL, &depth_unit));
|
||||
res += qasprintf_loc("%s: %d%s\n", translate("gettextFromC", "END"), end, depth_unit);
|
||||
res += qasprintf_loc("%s: %d%s / %.1fg/ℓ\n", translate("gettextFromC", "EADO"), eadd, depth_unit, entry->density);
|
||||
break;
|
||||
}
|
||||
case plot_info::AIR:
|
||||
if (entry->density > 0) {
|
||||
res += qasprintf_loc("%s: %.1fg/ℓ\n", translate("gettextFromC", "Density"), entry->density);
|
||||
}
|
||||
case plot_info::FREEDIVING:
|
||||
/* nothing */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (entry->stopdepth) {
|
||||
depthvalue = get_depth_units(entry->stopdepth, NULL, &depth_unit);
|
||||
if (entry->ndl > 0) {
|
||||
/* this is a safety stop as we still have ndl */
|
||||
if (entry->stoptime)
|
||||
res += qasprintf_loc("%s: %u%s @ %.0f%s\n", translate("gettextFromC", "Safety stop"), DIV_UP(entry->stoptime, 60),
|
||||
translate("gettextFromC", "min"), depthvalue, depth_unit);
|
||||
else
|
||||
res += qasprintf_loc("%s: %s @ %.0f%s\n", translate("gettextFromC", "Safety stop"),
|
||||
translate("gettextFromC", "unknown time"), depthvalue, depth_unit);
|
||||
} else {
|
||||
/* actual deco stop */
|
||||
if (entry->stoptime)
|
||||
res += qasprintf_loc("%s: %u%s @ %.0f%s\n", translate("gettextFromC", "Deco"), DIV_UP(entry->stoptime, 60),
|
||||
translate("gettextFromC", "min"), depthvalue, depth_unit);
|
||||
else
|
||||
res += qasprintf_loc("%s: %s @ %.0f%s\n", translate("gettextFromC", "Deco"),
|
||||
translate("gettextFromC", "unknown time"), depthvalue, depth_unit);
|
||||
}
|
||||
} else if (entry->in_deco) {
|
||||
res += gettextFromC::tr("In deco\n");
|
||||
} else if (entry->ndl >= 0) {
|
||||
res += qasprintf_loc("%s: %u%s\n", translate("gettextFromC", "NDL"), DIV_UP(entry->ndl, 60), translate("gettextFromC", "min"));
|
||||
}
|
||||
if (entry->tts)
|
||||
res += qasprintf_loc("%s: %u%s\n", translate("gettextFromC", "TTS"), DIV_UP(entry->tts, 60), translate("gettextFromC", "min"));
|
||||
if (entry->stopdepth_calc && entry->stoptime_calc) {
|
||||
depthvalue = get_depth_units(entry->stopdepth_calc, NULL, &depth_unit);
|
||||
res += qasprintf_loc("%s: %u%s @ %.0f%s (%s)\n", translate("gettextFromC", "Deco"), DIV_UP(entry->stoptime_calc, 60),
|
||||
translate("gettextFromC", "min"), depthvalue, depth_unit, translate("gettextFromC", "calc"));
|
||||
} else if (entry->in_deco_calc) {
|
||||
/* This means that we have no NDL left,
|
||||
* and we have no deco stop,
|
||||
* so if we just accend to the surface slowly
|
||||
* (ascent_mm_per_step / ascent_s_per_step)
|
||||
* everything will be ok. */
|
||||
res += gettextFromC::tr("In deco (calc)\n");
|
||||
} else if (prefs.calcndltts && entry->ndl_calc != 0) {
|
||||
if(entry->ndl_calc < MAX_PROFILE_DECO)
|
||||
res += qasprintf_loc("%s: %u%s (%s)\n", translate("gettextFromC", "NDL"), DIV_UP(entry->ndl_calc, 60),
|
||||
translate("gettextFromC", "min"), translate("gettextFromC", "calc"));
|
||||
else
|
||||
res += gettextFromC::tr("NDL: >2h (calc)\n");
|
||||
}
|
||||
if (entry->tts_calc) {
|
||||
if (entry->tts_calc < MAX_PROFILE_DECO)
|
||||
res += qasprintf_loc("%s: %u%s (%s)\n", translate("gettextFromC", "TTS"), DIV_UP(entry->tts_calc, 60),
|
||||
translate("gettextFromC", "min"), translate("gettextFromC", "calc"));
|
||||
else
|
||||
res += gettextFromC::tr("TTS: >2h (calc)\n");
|
||||
}
|
||||
if (entry->rbt)
|
||||
res += qasprintf_loc("%s: %u%s\n", translate("gettextFromC", "RBT"), DIV_UP(entry->rbt, 60), translate("gettextFromC", "min"));
|
||||
if (prefs.decoinfo) {
|
||||
if (entry->current_gf > 0.0)
|
||||
res += qasprintf_loc("%s %d%%\n", translate("gettextFromC", "GF"), (int)(100.0 * entry->current_gf));
|
||||
if (entry->surface_gf > 0.0)
|
||||
res += qasprintf_loc("%s %.0f%%\n", translate("gettextFromC", "Surface GF"), entry->surface_gf);
|
||||
if (entry->ceiling) {
|
||||
depthvalue = get_depth_units(entry->ceiling, NULL, &depth_unit);
|
||||
res += qasprintf_loc("%s %.1f%s\n", translate("gettextFromC", "Calculated ceiling"), depthvalue, depth_unit);
|
||||
if (prefs.calcalltissues) {
|
||||
for (int k = 0; k < 16; k++) {
|
||||
if (entry->ceilings[k]) {
|
||||
depthvalue = get_depth_units(entry->ceilings[k], NULL, &depth_unit);
|
||||
res += qasprintf_loc("%s %.0f%s: %.1f%s\n", translate("gettextFromC", "Tissue"),
|
||||
buehlmann_N2_t_halflife[k], translate("gettextFromC", "min"),
|
||||
depthvalue, depth_unit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (entry->icd_warning)
|
||||
res += gettextFromC::tr("ICD in leading tissue\n");
|
||||
if (entry->heartbeat && prefs.hrgraph)
|
||||
res += qasprintf_loc("%s: %d\n", translate("gettextFromC", "heart rate"), entry->heartbeat);
|
||||
if (entry->bearing >= 0)
|
||||
res += qasprintf_loc("%s: %d\n", translate("gettextFromC", "bearing"), entry->bearing);
|
||||
if (entry->running_sum) {
|
||||
depthvalue = get_depth_units(entry->running_sum / entry->sec, NULL, &depth_unit);
|
||||
res += qasprintf_loc("%s %.1f%s\n", translate("gettextFromC", "mean depth to here"), depthvalue, depth_unit);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
std::pair<QString, int> formatProfileInfo(const struct dive *d, const struct plot_info *pi, int time)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* The two first and the two last plot entries do not have useful data */
|
||||
if (pi->nr <= 4)
|
||||
return std::make_pair(QString(), 0);
|
||||
for (i = 2; i < pi->nr - 3; i++) {
|
||||
if (pi->entry[i].sec >= time)
|
||||
break;
|
||||
}
|
||||
QString res = formatPlotInfoInternal(d, pi, i);
|
||||
return std::make_pair(res, i);
|
||||
}
|
||||
|
||||
@ -3,10 +3,12 @@
|
||||
#ifndef STRING_FORMAT_H
|
||||
#define STRING_FORMAT_H
|
||||
|
||||
#include <utility>
|
||||
#include <QStringList>
|
||||
|
||||
struct dive;
|
||||
struct dive_trip;
|
||||
struct plot_info;
|
||||
|
||||
QString formatSac(const dive *d);
|
||||
QString formatNotes(const dive *d);
|
||||
@ -29,5 +31,6 @@ QString formatDiveDateTime(const dive *d);
|
||||
QString formatDayOfWeek(int day);
|
||||
QString formatTripTitle(const dive_trip *trip);
|
||||
QString formatTripTitleWithDives(const dive_trip *trip);
|
||||
std::pair<QString, int> formatProfileInfo(const dive *d, const plot_info *pi, int time);
|
||||
|
||||
#endif
|
||||
|
||||
@ -9,10 +9,15 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct time_of_day {
|
||||
int h, m, s;
|
||||
};
|
||||
|
||||
extern timestamp_t utc_mktime(const struct tm *tm);
|
||||
extern void utc_mkdate(timestamp_t, struct tm *tm);
|
||||
extern int utc_year(timestamp_t timestamp);
|
||||
extern int utc_weekday(timestamp_t timestamp);
|
||||
extern struct time_of_day utc_time_of_day(timestamp_t timestamp);
|
||||
|
||||
/* parse and format date times of the form YYYY-MM-DD hh:mm:ss */
|
||||
extern timestamp_t parse_datetime(const char *s); /* returns 0 on error */
|
||||
|
||||
31
core/time.c
31
core/time.c
@ -99,6 +99,37 @@ void utc_mkdate(timestamp_t timestamp, struct tm *tm)
|
||||
tm->tm_mon = m;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert 64-bit timestamp to time of day (split into h, m, s)
|
||||
*
|
||||
* On 32-bit machines, only do 64-bit arithmetic for the seconds
|
||||
* part, after that we do everything in 'long'. 64-bit divides
|
||||
* are unnecessary once you're counting minutes (32-bit minutes:
|
||||
* 8000+ years).
|
||||
*/
|
||||
struct time_of_day utc_time_of_day(timestamp_t timestamp)
|
||||
{
|
||||
struct time_of_day res = { 0 };
|
||||
unsigned long val;
|
||||
|
||||
// Midnight at Jan 1, 1970 means "no date"
|
||||
if (!timestamp)
|
||||
return res;
|
||||
|
||||
/* Convert to seconds since 1900 */
|
||||
timestamp += EPOCH_OFFSET;
|
||||
|
||||
/* minutes since 1900 */
|
||||
res.s = timestamp % 60;
|
||||
val = timestamp / 60;
|
||||
|
||||
res.m = val % 60;
|
||||
val /= 60;
|
||||
res.h = val % 24;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
timestamp_t utc_mktime(const struct tm *tm)
|
||||
{
|
||||
static const int mdays[] = {
|
||||
|
||||
@ -1,44 +1,37 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "profile-widget/divetooltipitem.h"
|
||||
#include "profile-widget/divecartesianaxis.h"
|
||||
#include "core/membuffer.h"
|
||||
#include "core/metrics.h"
|
||||
#include "core/settings/qPrefDisplay.h"
|
||||
#include "core/qthelper.h"
|
||||
#include "core/string-format.h"
|
||||
#include <QPropertyAnimation>
|
||||
#include <QGraphicsView>
|
||||
#include "core/qthelper.h"
|
||||
|
||||
void ToolTipItem::addToolTip(const QString &toolTip, const QPixmap &pixmap)
|
||||
ToolTipItem::ToolTip ToolTipItem::makeToolTip(const QString &toolTip, const QPixmap &pixmap)
|
||||
{
|
||||
const IconMetrics &iconMetrics = defaultIconMetrics();
|
||||
|
||||
QGraphicsPixmapItem *iconItem = 0;
|
||||
double yValue = title->boundingRect().height() + iconMetrics.spacing;
|
||||
Q_FOREACH (ToolTip t, toolTips) {
|
||||
yValue += t.second->boundingRect().height();
|
||||
}
|
||||
if (entryToolTip.second) {
|
||||
yValue += entryToolTip.second->boundingRect().height();
|
||||
}
|
||||
iconItem = new QGraphicsPixmapItem(this);
|
||||
for (auto &[pixmap, text]: toolTips)
|
||||
yValue += text->boundingRect().height();
|
||||
if (entryToolTip.text)
|
||||
yValue += entryToolTip.text->boundingRect().height();
|
||||
std::unique_ptr<QGraphicsPixmapItem> iconItem = std::make_unique<QGraphicsPixmapItem>(this);
|
||||
if (!pixmap.isNull())
|
||||
iconItem->setPixmap(pixmap);
|
||||
const int sp2 = iconMetrics.spacing * 2;
|
||||
iconItem->setPos(sp2, yValue);
|
||||
|
||||
QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem(toolTip, this);
|
||||
auto textItem = std::make_unique<QGraphicsSimpleTextItem>(toolTip, this);
|
||||
textItem->setPos(sp2 + iconMetrics.sz_small + sp2, yValue);
|
||||
textItem->setBrush(QBrush(Qt::white));
|
||||
textItem->setFlag(ItemIgnoresTransformations);
|
||||
toolTips.push_back(qMakePair(iconItem, textItem));
|
||||
return { std::move(iconItem), std::move(textItem) };
|
||||
}
|
||||
|
||||
void ToolTipItem::clear()
|
||||
{
|
||||
Q_FOREACH (ToolTip t, toolTips) {
|
||||
delete t.first;
|
||||
delete t.second;
|
||||
}
|
||||
toolTips.clear();
|
||||
}
|
||||
|
||||
@ -77,19 +70,17 @@ void ToolTipItem::expand()
|
||||
const IconMetrics &iconMetrics = defaultIconMetrics();
|
||||
|
||||
double width = 0, height = title->boundingRect().height() + iconMetrics.spacing;
|
||||
Q_FOREACH (const ToolTip &t, toolTips) {
|
||||
QRectF sRect = t.second->boundingRect();
|
||||
for (const auto &[pixmap, text]: toolTips) {
|
||||
QRectF sRect = text->boundingRect();
|
||||
if (sRect.width() > width)
|
||||
width = sRect.width();
|
||||
height += sRect.height();
|
||||
}
|
||||
|
||||
if (entryToolTip.first) {
|
||||
QRectF sRect = entryToolTip.second->boundingRect();
|
||||
if (sRect.width() > width)
|
||||
width = sRect.width();
|
||||
height += sRect.height();
|
||||
}
|
||||
QRectF sRect = entryToolTip.text->boundingRect();
|
||||
if (sRect.width() > width)
|
||||
width = sRect.width();
|
||||
height += sRect.height();
|
||||
|
||||
const int sp2 = iconMetrics.spacing * 2;
|
||||
// pixmap left padding, icon, pixmap right padding, right padding
|
||||
@ -101,13 +92,9 @@ void ToolTipItem::expand()
|
||||
if (width < title->boundingRect().width() + sp2)
|
||||
width = title->boundingRect().width() + sp2;
|
||||
// clip the height
|
||||
if (entryToolTip.first) {
|
||||
const int minH = lrint(entryToolTip.first->y() + entryToolTip.first->pixmap().height() + sp2);
|
||||
if (height < minH)
|
||||
height = minH;
|
||||
} else if (height < iconMetrics.sz_small) {
|
||||
height = iconMetrics.sz_small;
|
||||
}
|
||||
const int minH = lrint(entryToolTip.pixmap->y() + entryToolTip.pixmap->pixmap().height() + sp2);
|
||||
if (height < minH)
|
||||
height = minH;
|
||||
|
||||
nextRectangle.setWidth(width);
|
||||
nextRectangle.setHeight(height);
|
||||
@ -136,8 +123,6 @@ ToolTipItem::ToolTipItem(QGraphicsItem *parent) : RoundRectItem(8.0, parent),
|
||||
lastTime(-1)
|
||||
{
|
||||
clearPlotInfo();
|
||||
entryToolTip.first = NULL;
|
||||
entryToolTip.second = NULL;
|
||||
setFlags(ItemIgnoresTransformations | ItemIsMovable | ItemClipsChildrenToShape);
|
||||
|
||||
QColor c = QColor(Qt::black);
|
||||
@ -146,9 +131,7 @@ ToolTipItem::ToolTipItem(QGraphicsItem *parent) : RoundRectItem(8.0, parent),
|
||||
|
||||
setZValue(99);
|
||||
|
||||
addToolTip(QString(), QPixmap(16,60));
|
||||
entryToolTip = toolTips.first();
|
||||
toolTips.clear();
|
||||
entryToolTip = makeToolTip(QString(), QPixmap(16,60));
|
||||
|
||||
title->setFlag(ItemIgnoresTransformations);
|
||||
title->setPen(QPen(Qt::white, 1));
|
||||
@ -220,8 +203,6 @@ void ToolTipItem::setTimeAxis(DiveCartesianAxis *axis)
|
||||
|
||||
void ToolTipItem::refresh(const dive *d, const QPointF &pos, bool inPlanner)
|
||||
{
|
||||
struct membufferpp mb;
|
||||
|
||||
if(refreshTime.elapsed() < 40)
|
||||
return;
|
||||
refreshTime.start();
|
||||
@ -231,7 +212,7 @@ void ToolTipItem::refresh(const dive *d, const QPointF &pos, bool inPlanner)
|
||||
lastTime = time;
|
||||
clear();
|
||||
|
||||
int idx = get_plot_details_new(d, &pInfo, time, &mb);
|
||||
auto [text, idx] = formatProfileInfo(d, &pInfo, time);
|
||||
|
||||
tissues.fill();
|
||||
painter.setPen(QColor(0, 0, 0, 0));
|
||||
@ -251,15 +232,15 @@ void ToolTipItem::refresh(const dive *d, const QPointF &pos, bool inPlanner)
|
||||
painter.setPen(QColor(0, 0, 0, 127));
|
||||
for (int i = 0; i < 16; i++)
|
||||
painter.drawLine(i, 60, i, 60 - entry->percentages[i] / 2);
|
||||
entryToolTip.second->setText(QString::fromUtf8(mb.buffer, mb.len));
|
||||
entryToolTip.text->setText(text);
|
||||
}
|
||||
entryToolTip.first->setPixmap(tissues);
|
||||
entryToolTip.pixmap->setPixmap(tissues);
|
||||
|
||||
const auto l = scene()->items(pos, Qt::IntersectsItemBoundingRect, Qt::DescendingOrder,
|
||||
scene()->views().first()->transform());
|
||||
for (QGraphicsItem *item: l) {
|
||||
if (!item->toolTip().isEmpty())
|
||||
addToolTip(item->toolTip(), QPixmap());
|
||||
toolTips.push_back(makeToolTip(item->toolTip(), QPixmap()));
|
||||
}
|
||||
expand();
|
||||
}
|
||||
|
||||
@ -2,12 +2,12 @@
|
||||
#ifndef DIVETOOLTIPITEM_H
|
||||
#define DIVETOOLTIPITEM_H
|
||||
|
||||
#include <QVector>
|
||||
#include <QPair>
|
||||
#include <QRectF>
|
||||
#include <QIcon>
|
||||
#include <QElapsedTimer>
|
||||
#include <QPainter>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "backend-shared/roundrectitem.h"
|
||||
#include "core/profile.h"
|
||||
|
||||
@ -45,8 +45,11 @@ slots:
|
||||
void setRect(const QRectF &rect);
|
||||
|
||||
private:
|
||||
typedef QPair<QGraphicsPixmapItem *, QGraphicsSimpleTextItem *> ToolTip;
|
||||
QVector<ToolTip> toolTips;
|
||||
struct ToolTip {
|
||||
std::unique_ptr<QGraphicsPixmapItem> pixmap;
|
||||
std::unique_ptr<QGraphicsSimpleTextItem> text;
|
||||
};
|
||||
std::vector<ToolTip> toolTips;
|
||||
ToolTip entryToolTip;
|
||||
QGraphicsSimpleTextItem *title;
|
||||
Status status;
|
||||
@ -60,7 +63,7 @@ private:
|
||||
QElapsedTimer refreshTime;
|
||||
QList<QGraphicsItem*> oldSelection;
|
||||
|
||||
void addToolTip(const QString &toolTip, const QPixmap &pixmap);
|
||||
ToolTip makeToolTip(const QString &toolTip, const QPixmap &pixmap);
|
||||
void collapse();
|
||||
void expand();
|
||||
void clear();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user