From 3dbba5ae699d317013e88de7f05a8639f9f84558 Mon Sep 17 00:00:00 2001 From: Michael Werle Date: Wed, 17 Aug 2022 09:14:09 +0900 Subject: [PATCH] Map Short Names - display shortened names on the map. Only the last component of the Site Name is displayed, otherwise the full name is displayed. Site Name components are separated using slash (/) characters. For example, if the full dive-site name is "Japan / Izu Peninsula / Atami / Chinsen-Aft" then only "Chinsen-Aft" is displayed on the Map. Signed-off-by: Michael WERLE --- qt-models/maplocationmodel.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/qt-models/maplocationmodel.cpp b/qt-models/maplocationmodel.cpp index b92d1385e..98bb17e9f 100644 --- a/qt-models/maplocationmodel.cpp +++ b/qt-models/maplocationmodel.cpp @@ -10,6 +10,24 @@ #define MIN_DISTANCE_BETWEEN_DIVE_SITES_M 50.0 +// MKW If "Map Short Names" preference is set, only return the last component +// of the full dive site name. +// Example: +// Japan/Izu Peninsula/Atami/Chinsen-Aft +// Short name: Chinsen-Aft +static QString siteMapDisplayName(const char *sitename) +{ + const char Separator = '/'; + QString fullname(sitename); + QString name = fullname.section(Separator, -1).trimmed(); + + if (name.isEmpty()) { + name = fullname; + } + return name; +} + + MapLocation::MapLocation(struct dive_site *dsIn, QGeoCoordinate coordIn, QString nameIn, bool selectedIn) : divesite(dsIn), coordinate(coordIn), name(nameIn), selected(selectedIn) { @@ -159,7 +177,7 @@ void MapLocationModel::reload(QObject *map) } if (!diveSiteMode && hasSelectedDive(ds) && !m_selectedDs.contains(ds)) m_selectedDs.append(ds); - QString name(ds->name); + QString name = siteMapDisplayName(ds->name); if (!diveSiteMode) { // don't add dive locations with the same name, unless they are // at least MIN_DISTANCE_BETWEEN_DIVE_SITES_M apart @@ -223,7 +241,7 @@ void MapLocationModel::diveSiteChanged(struct dive_site *ds, int field) } break; case LocationInformationModel::NAME: - m_mapLocations[row]->name = ds->name; + m_mapLocations[row]->name = siteMapDisplayName(ds->name); break; default: break;