mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
cleanup: move minute formating to format-string.cpp
The get_minutes() function formats a time as m:ss and returns a static C-string. Since all callers are C++ anyway and transform directly into QString, let us move this to the other string formatting function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
1047937197
commit
4a7ee872f3
7 changed files with 17 additions and 18 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include "qthelper.h"
|
#include "qthelper.h"
|
||||||
#include "units.h"
|
#include "units.h"
|
||||||
#include "statistics.h"
|
#include "statistics.h"
|
||||||
|
#include "string-format.h"
|
||||||
#include "save-html.h"
|
#include "save-html.h"
|
||||||
|
|
||||||
static void file_copy_and_overwrite(const QString &fileName, const QString &newName)
|
static void file_copy_and_overwrite(const QString &fileName, const QString &newName)
|
||||||
|
@ -93,9 +94,9 @@ static void exportHTMLstatistics(const QString filename, struct htmlExportSettin
|
||||||
out << "\"DIVES\":\"" << stats.stats_yearly[i].selection_size << "\",";
|
out << "\"DIVES\":\"" << stats.stats_yearly[i].selection_size << "\",";
|
||||||
out << "\"TOTAL_TIME\":\"" << get_dive_duration_string(stats.stats_yearly[i].total_time.seconds,
|
out << "\"TOTAL_TIME\":\"" << get_dive_duration_string(stats.stats_yearly[i].total_time.seconds,
|
||||||
gettextFromC::tr("h"), gettextFromC::tr("min"), gettextFromC::tr("sec"), " ") << "\",";
|
gettextFromC::tr("h"), gettextFromC::tr("min"), gettextFromC::tr("sec"), " ") << "\",";
|
||||||
out << "\"AVERAGE_TIME\":\"" << get_minutes(stats.stats_yearly[i].total_time.seconds / stats.stats_yearly[i].selection_size) << "\",";
|
out << "\"AVERAGE_TIME\":\"" << formatMinutes(stats.stats_yearly[i].total_time.seconds / stats.stats_yearly[i].selection_size) << "\",";
|
||||||
out << "\"SHORTEST_TIME\":\"" << get_minutes(stats.stats_yearly[i].shortest_time.seconds) << "\",";
|
out << "\"SHORTEST_TIME\":\"" << formatMinutes(stats.stats_yearly[i].shortest_time.seconds) << "\",";
|
||||||
out << "\"LONGEST_TIME\":\"" << get_minutes(stats.stats_yearly[i].longest_time.seconds) << "\",";
|
out << "\"LONGEST_TIME\":\"" << formatMinutes(stats.stats_yearly[i].longest_time.seconds) << "\",";
|
||||||
out << "\"AVG_DEPTH\":\"" << get_depth_string(stats.stats_yearly[i].avg_depth) << "\",";
|
out << "\"AVG_DEPTH\":\"" << get_depth_string(stats.stats_yearly[i].avg_depth) << "\",";
|
||||||
out << "\"MIN_DEPTH\":\"" << get_depth_string(stats.stats_yearly[i].min_depth) << "\",";
|
out << "\"MIN_DEPTH\":\"" << get_depth_string(stats.stats_yearly[i].min_depth) << "\",";
|
||||||
out << "\"MAX_DEPTH\":\"" << get_depth_string(stats.stats_yearly[i].max_depth) << "\",";
|
out << "\"MAX_DEPTH\":\"" << get_depth_string(stats.stats_yearly[i].max_depth) << "\",";
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
/* statistics.c
|
/* statistics.c
|
||||||
*
|
*
|
||||||
* core logic for the Info & Stats page -
|
* core logic for the Info & Stats page -
|
||||||
* char *get_minutes(int seconds);
|
|
||||||
* void calculate_stats_summary(struct stats_summary *out, bool selected_only);
|
* void calculate_stats_summary(struct stats_summary *out, bool selected_only);
|
||||||
* void calculate_stats_selected(stats_t *stats_selection);
|
* void calculate_stats_selected(stats_t *stats_selection);
|
||||||
*/
|
*/
|
||||||
|
@ -84,13 +83,6 @@ static void process_dive(struct dive *dive, stats_t *stats)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_minutes(int seconds)
|
|
||||||
{
|
|
||||||
static char buf[80];
|
|
||||||
snprintf(buf, sizeof(buf), "%d:%.2d", FRACTION(seconds, 60));
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calculate a summary of the statistics and put in the stats_summary
|
* Calculate a summary of the statistics and put in the stats_summary
|
||||||
* structure provided in the first parameter.
|
* structure provided in the first parameter.
|
||||||
|
|
|
@ -58,7 +58,6 @@ struct stats_summary {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern char *get_minutes(int seconds);
|
|
||||||
extern void init_stats_summary(struct stats_summary *stats);
|
extern void init_stats_summary(struct stats_summary *stats);
|
||||||
extern void free_stats_summary(struct stats_summary *stats);
|
extern void free_stats_summary(struct stats_summary *stats);
|
||||||
extern void calculate_stats_summary(struct stats_summary *stats, bool selected_only);
|
extern void calculate_stats_summary(struct stats_summary *stats, bool selected_only);
|
||||||
|
|
|
@ -277,6 +277,11 @@ QString formatDayOfWeek(int day)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString formatMinutes(int seconds)
|
||||||
|
{
|
||||||
|
return QString::asprintf("%d:%.2d", FRACTION(seconds, 60));
|
||||||
|
}
|
||||||
|
|
||||||
QString formatTripTitle(const dive_trip *trip)
|
QString formatTripTitle(const dive_trip *trip)
|
||||||
{
|
{
|
||||||
if (!trip)
|
if (!trip)
|
||||||
|
|
|
@ -27,6 +27,7 @@ QString formatDiveDate(const dive *d);
|
||||||
QString formatDiveTime(const dive *d);
|
QString formatDiveTime(const dive *d);
|
||||||
QString formatDiveDateTime(const dive *d);
|
QString formatDiveDateTime(const dive *d);
|
||||||
QString formatDayOfWeek(int day);
|
QString formatDayOfWeek(int day);
|
||||||
|
QString formatMinutes(int seconds);
|
||||||
QString formatTripTitle(const dive_trip *trip);
|
QString formatTripTitle(const dive_trip *trip);
|
||||||
QString formatTripTitleWithDives(const dive_trip *trip);
|
QString formatTripTitleWithDives(const dive_trip *trip);
|
||||||
|
|
||||||
|
|
|
@ -464,11 +464,11 @@ QVariant TemplateLayout::getValue(QString list, QString property, const State &s
|
||||||
return get_dive_duration_string(object->total_time.seconds, gettextFromC::tr("h"),
|
return get_dive_duration_string(object->total_time.seconds, gettextFromC::tr("h"),
|
||||||
gettextFromC::tr("min"), gettextFromC::tr("sec"), " ");
|
gettextFromC::tr("min"), gettextFromC::tr("sec"), " ");
|
||||||
} else if (property == "avg_time") {
|
} else if (property == "avg_time") {
|
||||||
return get_minutes(object->total_time.seconds / object->selection_size);
|
return formatMinutes(object->total_time.seconds / object->selection_size);
|
||||||
} else if (property == "shortest_time") {
|
} else if (property == "shortest_time") {
|
||||||
return get_minutes(object->shortest_time.seconds);
|
return formatMinutes(object->shortest_time.seconds);
|
||||||
} else if (property == "longest_time") {
|
} else if (property == "longest_time") {
|
||||||
return get_minutes(object->longest_time.seconds);
|
return formatMinutes(object->longest_time.seconds);
|
||||||
} else if (property == "avg_depth") {
|
} else if (property == "avg_depth") {
|
||||||
return get_depth_string(object->avg_depth);
|
return get_depth_string(object->avg_depth);
|
||||||
} else if (property == "min_depth") {
|
} else if (property == "min_depth") {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "core/qthelper.h"
|
#include "core/qthelper.h"
|
||||||
#include "core/metrics.h"
|
#include "core/metrics.h"
|
||||||
#include "core/statistics.h"
|
#include "core/statistics.h"
|
||||||
|
#include "core/string-format.h"
|
||||||
#include "core/dive.h" // For NUM_DIVEMODE
|
#include "core/dive.h" // For NUM_DIVEMODE
|
||||||
|
|
||||||
class YearStatisticsItem : public TreeItem {
|
class YearStatisticsItem : public TreeItem {
|
||||||
|
@ -65,13 +66,13 @@ QVariant YearStatisticsItem::data(int column, int role) const
|
||||||
ret = get_dive_duration_string(stats_interval.total_time.seconds, tr("h"), tr("min"), tr("sec"), " ");
|
ret = get_dive_duration_string(stats_interval.total_time.seconds, tr("h"), tr("min"), tr("sec"), " ");
|
||||||
break;
|
break;
|
||||||
case AVERAGE_TIME:
|
case AVERAGE_TIME:
|
||||||
ret = get_minutes(stats_interval.total_time.seconds / stats_interval.selection_size);
|
ret = formatMinutes(stats_interval.total_time.seconds / stats_interval.selection_size);
|
||||||
break;
|
break;
|
||||||
case SHORTEST_TIME:
|
case SHORTEST_TIME:
|
||||||
ret = get_minutes(stats_interval.shortest_time.seconds);
|
ret = formatMinutes(stats_interval.shortest_time.seconds);
|
||||||
break;
|
break;
|
||||||
case LONGEST_TIME:
|
case LONGEST_TIME:
|
||||||
ret = get_minutes(stats_interval.longest_time.seconds);
|
ret = formatMinutes(stats_interval.longest_time.seconds);
|
||||||
break;
|
break;
|
||||||
case AVG_DEPTH:
|
case AVG_DEPTH:
|
||||||
ret = get_depth_string(stats_interval.avg_depth);
|
ret = get_depth_string(stats_interval.avg_depth);
|
||||||
|
|
Loading…
Add table
Reference in a new issue