diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-02-10 22:16:25 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-02-10 14:33:15 -0800 |
commit | b3e4c9c8daee8df29c7d6fc943e37886217d3c98 (patch) | |
tree | 3deac4ca5344f82394bf96627dda737f87fa292c /qt-models | |
parent | 41df39fdbe22fed32cee28a0035ee283dc49b79b (diff) | |
download | subsurface-b3e4c9c8daee8df29c7d6fc943e37886217d3c98.tar.gz |
desktop: cache photo and geo icons
The icons shown in the dive list were rendered for every single
access. Render them only once. This supposes that the
defaultIconMetrics structure does not change once the icons are
rendered!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r-- | qt-models/divetripmodel.cpp | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index 358d032a6..71430a7d3 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -188,6 +188,28 @@ static QString displayWeight(const struct dive *d, bool units) return s + gettextFromC::tr("lbs"); } +static QPixmap &getGlobeIcon() +{ + static std::unique_ptr<QPixmap> icon; + if (!icon) { + const IconMetrics &im = defaultIconMetrics(); + icon = std::make_unique<QPixmap>(QIcon(":globe-icon").pixmap(im.sz_small, im.sz_small)); + } + return *icon; +} + +static QPixmap &getPhotoIcon(int idx) +{ + static std::unique_ptr<QPixmap[]> icons; + if (!icons) { + const IconMetrics &im = defaultIconMetrics(); + icons = std::make_unique<QPixmap[]>(std::size(icon_names)); + for (size_t i = 0; i < std::size(icon_names); ++i) + icons[i] = QIcon(icon_names[i]).pixmap(im.sz_small, im.sz_small); + } + return icons[idx]; +} + QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role) const { #ifdef SUBSURFACE_MOBILE @@ -289,17 +311,15 @@ QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role) case COUNTRY: return QVariant(); case LOCATION: - if (dive_has_gps_location(d)) { - IconMetrics im = defaultIconMetrics(); - return QIcon(":globe-icon").pixmap(im.sz_small, im.sz_small); - } + if (dive_has_gps_location(d)) + return getGlobeIcon(); break; case PHOTOS: - if (d->pictures.nr > 0) { - IconMetrics im = defaultIconMetrics(); - return QIcon(icon_names[countPhotos(d)]).pixmap(im.sz_small, im.sz_small); - } // If there are photos, show one of the three photo icons: fish= photos during dive; - break; // sun=photos before/after dive; sun+fish=photos during dive as well as before/after + // If there are photos, show one of the three photo icons: fish= photos during dive; + // sun=photos before/after dive; sun+fish=photos during dive as well as before/after + if (d->pictures.nr > 0) + return getPhotoIcon(countPhotos(d)); + break; } break; case Qt::ToolTipRole: |