formatting: move get_trip_title to string-format.h and split it

To enable grouping by trip in the statistics module, split
the get_trip_title() function in a version that appends
a "(n dive(s)" string an one that doesn't. The statistics
module doesn't want that added string, since it displays
the number of dives in a different way.

Also, move the functions to string-format.h, where these
are collected. And rename them to camelCase. Yes, it's
ugly, but consistent with most other C++ code in the code
base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-12-16 23:09:39 +01:00 committed by Dirk Hohndel
parent 5d1f12438b
commit d1b8f1ca3d
6 changed files with 35 additions and 25 deletions

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include "qthelper.h"
#include "dive.h"
#include "divelist.h"
#include "core/settings/qPrefLanguage.h"
#include "core/settings/qPrefUpdateManager.h"
#include "core/subsurface-qt/divelistnotifier.h"
@ -18,7 +19,6 @@
#include "picture.h"
#include "selection.h"
#include "tag.h"
#include "trip.h"
#include "imagedownloader.h"
#include "xmlparams.h"
#include "core/git-access.h" // for CLOUD_HOST definitions
@ -1040,25 +1040,6 @@ extern "C" char *get_current_date()
return copy_qstring(current_date);
}
QString get_trip_string(const dive_trip *trip)
{
if (!trip)
return QString();
int nr = trip->dives.nr;
timestamp_t when = trip_date(trip);
bool getday = trip_is_single_day(trip);
QDateTime localTime = timestampToDateTime(when);
QString prefix = !empty_string(trip->location) ? QString(trip->location) + ", " : QString();
QString suffix = " " + gettextFromC::tr("(%n dive(s))", "", nr);
if (getday)
return prefix + loc.toString(localTime, prefs.date_format) + suffix;
else
return prefix + loc.toString(localTime, "MMM yyyy") + suffix;
}
static QMutex hashOfMutex;
static QHash<QString, QString> localFilenameOf;