From 1ce42158f1610d9470ac7c15bb077203e568e0b2 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 12 Feb 2022 14:43:04 +0100 Subject: [PATCH] model: unify tooltip formating in DiveTripModel The formatting of the tooltips describing the columns was repeated in two functions. Infuriatingly, there were to minor differences: "Max. CNS" vs. "Max CNS" and one version understood "Country". Break that out into a single function to avoid these inconsistencies and to save a few lines of code. Signed-off-by: Berthold Stoeger --- qt-models/divetripmodel.cpp | 135 ++++++++++++++---------------------- qt-models/divetripmodel.h | 1 + 2 files changed, 52 insertions(+), 84 deletions(-) diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index 22b5071ce..1042a65a0 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -211,6 +211,55 @@ static QPixmap &getPhotoIcon(int idx) return icons[idx]; } +// textual description of the meaning of a column for use in tooltips +QString DiveTripModelBase::getDescription(int column) +{ + switch (column) { + case NR: + return tr("#"); + case DATE: + return tr("Date"); + case RATING: + return tr("Rating"); + case DEPTH: + return tr("Depth(%1)").arg((get_units()->length == units::METERS) ? tr("m") : tr("ft")); + case DURATION: + return tr("Duration"); + case TEMPERATURE: + return tr("Temp.(°%1)").arg((get_units()->temperature == units::CELSIUS) ? "C" : "F"); + case TOTALWEIGHT: + return tr("Weight(%1)").arg((get_units()->weight == units::KG) ? tr("kg") : tr("lbs")); + case SUIT: + return tr("Suit"); + case CYLINDER: + return tr("Cylinder"); + case GAS: + return tr("Gas"); + case SAC: + const char *unit; + get_volume_units(0, NULL, &unit); + return tr("SAC(%1)").arg(QString(unit).append(tr("/min"))); + case OTU: + return tr("OTU"); + case MAXCNS: + return tr("Max. CNS"); + case TAGS: + return tr("Tags"); + case PHOTOS: + return tr("Media before/during/after dive"); + case COUNTRY: + return tr("Country"); + case BUDDIES: + return tr("Buddy"); + case DIVEGUIDE: + return tr("Dive guide"); + case LOCATION: + return tr("Location"); + default: + return QString(); + } +} + QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role) const { #ifdef SUBSURFACE_MOBILE @@ -326,49 +375,7 @@ QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role) } break; case Qt::ToolTipRole: - switch (column) { - case NR: - return tr("#"); - case DATE: - return tr("Date"); - case RATING: - return tr("Rating"); - case DEPTH: - return tr("Depth(%1)").arg((get_units()->length == units::METERS) ? tr("m") : tr("ft")); - case DURATION: - return tr("Duration"); - case TEMPERATURE: - return tr("Temp.(°%1)").arg((get_units()->temperature == units::CELSIUS) ? "C" : "F"); - case TOTALWEIGHT: - return tr("Weight(%1)").arg((get_units()->weight == units::KG) ? tr("kg") : tr("lbs")); - case SUIT: - return tr("Suit"); - case CYLINDER: - return tr("Cylinder"); - case GAS: - return tr("Gas"); - case SAC: - const char *unit; - get_volume_units(0, NULL, &unit); - return tr("SAC(%1)").arg(QString(unit).append(tr("/min"))); - case OTU: - return tr("OTU"); - case MAXCNS: - return tr("Max. CNS"); - case TAGS: - return tr("Tags"); - case PHOTOS: - return tr("Media before/during/after dive"); - case COUNTRY: - return tr("Country"); - case BUDDIES: - return tr("Buddy"); - case DIVEGUIDE: - return tr("Dive guide"); - case LOCATION: - return tr("Location"); - } - break; + return getDescription(column); case STAR_ROLE: return d->rating; case DIVE_ROLE: @@ -439,47 +446,7 @@ QVariant DiveTripModelBase::headerData(int section, Qt::Orientation orientation, } break; case Qt::ToolTipRole: - switch (section) { - case NR: - return tr("#"); - case DATE: - return tr("Date"); - case RATING: - return tr("Rating"); - case DEPTH: - return tr("Depth(%1)").arg((get_units()->length == units::METERS) ? tr("m") : tr("ft")); - case DURATION: - return tr("Duration"); - case TEMPERATURE: - return tr("Temp.(°%1)").arg((get_units()->temperature == units::CELSIUS) ? "C" : "F"); - case TOTALWEIGHT: - return tr("Weight(%1)").arg((get_units()->weight == units::KG) ? tr("kg") : tr("lbs")); - case SUIT: - return tr("Suit"); - case CYLINDER: - return tr("Cylinder"); - case GAS: - return tr("Gas"); - case SAC: - const char *unit; - get_volume_units(0, NULL, &unit); - return tr("SAC(%1)").arg(QString(unit).append(tr("/min"))); - case OTU: - return tr("OTU"); - case MAXCNS: - return tr("Max CNS"); - case TAGS: - return tr("Tags"); - case PHOTOS: - return tr("Media before/during/after dive"); - case BUDDIES: - return tr("Buddy"); - case DIVEGUIDE: - return tr("Dive guide"); - case LOCATION: - return tr("Location"); - } - break; + return getDescription(section); } return QVariant(); diff --git a/qt-models/divetripmodel.h b/qt-models/divetripmodel.h index 2bd4ff649..99eb0c488 100644 --- a/qt-models/divetripmodel.h +++ b/qt-models/divetripmodel.h @@ -95,6 +95,7 @@ protected: static QVariant tripData(const dive_trip *trip, int column, int role); static QString tripTitle(const dive_trip *trip); static QString tripShortDate(const dive_trip *trip); + static QString getDescription(int column); void currentChanged(); virtual dive *diveOrNull(const QModelIndex &index) const = 0; // Returns a dive if this index represents a dive, null otherwise