mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
mobile/summary: use more intuitive time periods
No one will ask you about your dives in the last seven months (and the existing code actually provided the past 210 days in that case). Instead do more intuitive periods. Last month, quarter, half year, year. Use Qt's ability to make sane date calculations easy. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
fb057b7094
commit
6c7411c776
2 changed files with 26 additions and 18 deletions
|
@ -48,19 +48,11 @@ Kirigami.ScrollablePage {
|
|||
|
||||
ListModel {
|
||||
id: monthModel
|
||||
ListElement {text: qsTr("Total")}
|
||||
ListElement {text: qsTr(" 1 month [ 30 days]")}
|
||||
ListElement {text: qsTr(" 2 month [ 60 days]")}
|
||||
ListElement {text: qsTr(" 3 month [ 90 days]")}
|
||||
ListElement {text: qsTr(" 4 month [120 days]")}
|
||||
ListElement {text: qsTr(" 5 month [150 days]")}
|
||||
ListElement {text: qsTr(" 6 month [180 days]")}
|
||||
ListElement {text: qsTr(" 7 month [210 days]")}
|
||||
ListElement {text: qsTr(" 8 month [240 days]")}
|
||||
ListElement {text: qsTr(" 9 month [270 days]")}
|
||||
ListElement {text: qsTr("10 month [300 days]")}
|
||||
ListElement {text: qsTr("11 month [330 days]")}
|
||||
ListElement {text: qsTr("12 month [360 days]")}
|
||||
ListElement {text: qsTr("All")}
|
||||
ListElement {text: qsTr("1 month")}
|
||||
ListElement {text: qsTr("3 months")}
|
||||
ListElement {text: qsTr("6 months")}
|
||||
ListElement {text: qsTr("1 year")}
|
||||
}
|
||||
|
||||
TemplateLabel {
|
||||
|
|
|
@ -242,12 +242,28 @@ void DiveSummaryModel::calc(int column, int period)
|
|||
if (column >= (int)results.size())
|
||||
return;
|
||||
|
||||
QDateTime localTime;
|
||||
QDateTime currentTime = QDateTime::currentDateTime();
|
||||
QDateTime startTime = currentTime;
|
||||
|
||||
// Calculate Start of the 2 periods.
|
||||
timestamp_t now, start;
|
||||
now = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset();
|
||||
start = (period == 0) ? 0 : now - period * 30 * 24 * 60 * 60;
|
||||
// Calculate Start of the periods.
|
||||
switch (period) {
|
||||
case 0: // having startTime == currentTime is used as special case below
|
||||
break;
|
||||
case 1: startTime = currentTime.addMonths(-1);
|
||||
break;
|
||||
case 2: startTime = currentTime.addMonths(-3);
|
||||
break;
|
||||
case 3: startTime = currentTime.addMonths(-6);
|
||||
break;
|
||||
case 4: startTime = currentTime.addYears(-1);
|
||||
break;
|
||||
default: qWarning("DiveSummaryModel::calc called with invalid period");
|
||||
}
|
||||
timestamp_t start;
|
||||
if (startTime == currentTime)
|
||||
start = 0;
|
||||
else
|
||||
start = startTime.toMSecsSinceEpoch() / 1000L + gettimezoneoffset();
|
||||
|
||||
// Loop over all dives and sum up data
|
||||
Stats stats = loopDives(start);
|
||||
|
|
Loading…
Reference in a new issue