diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-12-12 23:40:16 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-03-20 15:20:44 -0700 |
commit | 65acd9976c35689ae4b8faafd3ca29a4b9c1905d (patch) | |
tree | 803b16e20b1da10858ecccd24664941af920fe41 | |
parent | 95b60d1b18adb5ef1ed4edb2797bc67cca511d4a (diff) | |
download | subsurface-65acd9976c35689ae4b8faafd3ca29a4b9c1905d.tar.gz |
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 <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | qt-models/divetripmodel.cpp | 24 |
1 files 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<dive_trip *>(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 *> &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(); } |