From 65acd9976c35689ae4b8faafd3ca29a4b9c1905d Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 12 Dec 2019 23:40:16 +0100 Subject: Dive list: mark invalid dives with a struck out font Mark invalid dives in the dive list by striking them out and rendering them with a grey color. The color-change is not sufficient, because the default model delegate ignores color hints if the item is selected. Signed-off-by: Berthold Stoeger --- qt-models/divetripmodel.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index e5a1b8cc5..23eda0c51 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -107,6 +107,9 @@ QVariant DiveTripModelBase::tripData(const dive_trip *trip, int column, int role case MobileListModel::TripNotesRole: return QString(trip->notes); } #endif + // Set the font for all trips alike + if (role == Qt::FontRole) + return defaultModelFont(); if (role == TRIP_ROLE) return QVariant::fromValue(const_cast(trip)); // Not nice: casting away a const @@ -187,6 +190,15 @@ static QString displayWeight(const struct dive *d, bool units) return s + gettextFromC::tr("lbs"); } +static QFont struckOutFont() +{ + QFont font; + font.setStrikeOut(true); + return font; +} +static QBrush invalidForeground(Qt::gray); +static QFont invalidFont = struckOutFont(); + QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role) { #ifdef SUBSURFACE_MOBILE @@ -235,6 +247,10 @@ QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role) } #endif switch (role) { + case Qt::FontRole: + return d->invalid ? invalidFont : defaultModelFont(); + case Qt::ForegroundRole: + return d->invalid ? invalidForeground : QVariant(); case Qt::TextAlignmentRole: return dive_table_alignment(column); case Qt::DisplayRole: @@ -922,10 +938,6 @@ void DiveTripModelTree::divesHidden(dive_trip *trip, const QVector &dive QVariant DiveTripModelTree::data(const QModelIndex &index, int role) const { - // Set the font for all items alike - if (role == Qt::FontRole) - return defaultModelFont(); - dive_or_trip entry = tripOrDive(index); if (!entry.trip && !entry.dive) return QVariant(); // That's an invalid index! @@ -1524,10 +1536,6 @@ void DiveTripModelList::filterReset() QVariant DiveTripModelList::data(const QModelIndex &index, int role) const { - // Set the font for all items alike - if (role == Qt::FontRole) - return defaultModelFont(); - dive *d = diveOrNull(index); return d ? diveData(d, index.column(), role) : QVariant(); } -- cgit v1.2.3-70-g09d2