divelist: don't initialize invalidFont at startup

To mark invalid dives, we use a struck-out font, which was a static
variable at translation unit scope, i.e. initialized at application
startup. Sadly, this crashes on iOS.

It is unclear when we can initialize fonts. Try to move initialization
to the constructore of DiveTripModelBase and make the font a member
of that class. For consistency, also make the invalidBrush a member
of this class.

This now means that the diveData function cannot be static anymore,
since it needs access to the font and brush. But OK.

Reported-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-03-24 09:01:24 +01:00 committed by Dirk Hohndel
parent 0b83971ff9
commit 59b6ad6a0b
2 changed files with 9 additions and 12 deletions

View file

@ -190,16 +190,7 @@ static QString displayWeight(const struct dive *d, bool units)
return s + gettextFromC::tr("lbs"); return s + gettextFromC::tr("lbs");
} }
static QFont struckOutFont() QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role) const
{
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 #ifdef SUBSURFACE_MOBILE
// Special roles for mobile // Special roles for mobile
@ -509,8 +500,10 @@ void DiveTripModelBase::reset()
emit diveListNotifier.numShownChanged(); emit diveListNotifier.numShownChanged();
} }
DiveTripModelBase::DiveTripModelBase(QObject *parent) : QAbstractItemModel(parent) DiveTripModelBase::DiveTripModelBase(QObject *parent) : QAbstractItemModel(parent),
invalidForeground(Qt::gray)
{ {
invalidFont.setStrikeOut(true);
} }
int DiveTripModelBase::columnCount(const QModelIndex&) const int DiveTripModelBase::columnCount(const QModelIndex&) const

View file

@ -5,6 +5,8 @@
#include "core/dive.h" #include "core/dive.h"
#include "core/subsurface-qt/divelistnotifier.h" #include "core/subsurface-qt/divelistnotifier.h"
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QBrush>
#include <QFont>
class DiveFilter; class DiveFilter;
@ -88,9 +90,11 @@ signals:
void currentDiveChanged(QModelIndex index); void currentDiveChanged(QModelIndex index);
protected: protected:
dive *oldCurrent; dive *oldCurrent;
QBrush invalidForeground;
QFont invalidFont;
// Access trip and dive data // Access trip and dive data
static QVariant diveData(const struct dive *d, int column, int role); QVariant diveData(const struct dive *d, int column, int role) const; // Not static because we have to access invalidFont
static QVariant tripData(const dive_trip *trip, int column, int role); static QVariant tripData(const dive_trip *trip, int column, int role);
static QString tripTitle(const dive_trip *trip); static QString tripTitle(const dive_trip *trip);
static QString tripShortDate(const dive_trip *trip); static QString tripShortDate(const dive_trip *trip);