mobile/summary: implement firstDiveDate and lastDiveDate

Instead of transporting the global first and last dive date
in the dive summary, calculate it in an external function.
Since we already have time and date functions in qthelper.cpp
implement those functions there. Provide a stub in QMLInterface
so that QML can access these standalone functions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-02-06 23:29:26 +01:00 committed by Dirk Hohndel
parent 988ccba710
commit f7c73f1987
4 changed files with 28 additions and 2 deletions

View file

@ -948,6 +948,23 @@ char *get_dive_date_c_string(timestamp_t when)
return copy_qstring(text);
}
static QString get_dive_only_date_string(timestamp_t when)
{
QDateTime ts;
ts.setMSecsSinceEpoch(when * 1000L);
return loc.toString(ts.toUTC(), QString(prefs.date_format));
}
QString get_first_dive_date_string()
{
return dive_table.nr > 0 ? get_dive_only_date_string(dive_table.dives[0]->when) : gettextFromC::tr("no dives");
}
QString get_last_dive_date_string()
{
return dive_table.nr > 0 ? get_dive_only_date_string(dive_table.dives[dive_table.nr - 1]->when) : gettextFromC::tr("no dives");
}
extern "C" char *get_current_date()
{
QDateTime ts(QDateTime::currentDateTime());;

View file

@ -72,6 +72,8 @@ QString render_seconds_to_string(int seconds);
QString get_dive_duration_string(timestamp_t when, QString hoursText, QString minutesText, QString secondsText = gettextFromC::tr("sec"), QString separator = ":", bool isFreeDive = false);
QString get_dive_surfint_string(timestamp_t when, QString daysText, QString hoursText, QString minutesText, QString separator = " ", int maxdays = 4);
QString get_dive_date_string(timestamp_t when);
QString get_first_dive_date_string();
QString get_last_dive_date_string();
QString get_short_dive_date_string(timestamp_t when);
QString get_trip_date_string(timestamp_t when, int nr, bool getday);
QString uiLanguage(QLocale *callerLoc);

View file

@ -8,6 +8,10 @@ import org.subsurfacedivelog.mobile 1.0
import org.kde.kirigami 2.4 as Kirigami
Kirigami.ScrollablePage {
id: summary
property string firstDive: ""
property string lastDive: ""
background: Rectangle { color: subsurfaceTheme.backgroundColor }
title: qsTr("Dive summary")
@ -54,10 +58,10 @@ Kirigami.ScrollablePage {
font.bold: true
}
TemplateLabel {
text: Backend.diveSummaryText[0]
text: summary.firstDive
}
TemplateLabel {
text: Backend.diveSummaryText[1]
text: summary.lastDive
}
TemplateLabel {

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#ifndef QMLINTERFACE_H
#define QMLINTERFACE_H
#include "core/qthelper.h"
#include "core/settings/qPrefCloudStorage.h"
#include "core/settings/qPrefUnit.h"
#include "core/settings/qPrefDivePlanner.h"
@ -265,6 +266,8 @@ public slots:
void set_display_transitions(bool value) { DivePlannerPointsModel::instance()->setDisplayTransitions(value); }
void set_verbatim_plan(bool value) { DivePlannerPointsModel::instance()->setVerbatim(value); }
void set_display_variations(bool value) { DivePlannerPointsModel::instance()->setDisplayVariations(value); }
QString firstDiveDate() { return get_first_dive_date_string(); }
QString lastDiveDate() { return get_last_dive_date_string(); }
signals:
void cloud_verification_statusChanged(CLOUD_STATUS);