mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
41df39fdbe
commit
b3e4c9c8da
3 changed files with 31 additions and 11 deletions
|
@ -43,7 +43,7 @@ static int defaultIconSize(int height)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const IconMetrics & defaultIconMetrics()
|
const IconMetrics &defaultIconMetrics()
|
||||||
{
|
{
|
||||||
if (dfltIconMetrics.sz_small == -1) {
|
if (dfltIconMetrics.sz_small == -1) {
|
||||||
int small = defaultIconSize(defaultModelFontMetrics().height());
|
int small = defaultIconSize(defaultModelFontMetrics().height());
|
||||||
|
|
|
@ -31,7 +31,7 @@ struct IconMetrics {
|
||||||
IconMetrics();
|
IconMetrics();
|
||||||
};
|
};
|
||||||
|
|
||||||
const IconMetrics & defaultIconMetrics();
|
const IconMetrics &defaultIconMetrics();
|
||||||
void updateDevicePixelRatio(double dpr);
|
void updateDevicePixelRatio(double dpr);
|
||||||
|
|
||||||
#endif // METRICS_H
|
#endif // METRICS_H
|
||||||
|
|
|
@ -188,6 +188,28 @@ static QString displayWeight(const struct dive *d, bool units)
|
||||||
return s + gettextFromC::tr("lbs");
|
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
|
QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role) const
|
||||||
{
|
{
|
||||||
#ifdef SUBSURFACE_MOBILE
|
#ifdef SUBSURFACE_MOBILE
|
||||||
|
@ -289,17 +311,15 @@ QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role)
|
||||||
case COUNTRY:
|
case COUNTRY:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
case LOCATION:
|
case LOCATION:
|
||||||
if (dive_has_gps_location(d)) {
|
if (dive_has_gps_location(d))
|
||||||
IconMetrics im = defaultIconMetrics();
|
return getGlobeIcon();
|
||||||
return QIcon(":globe-icon").pixmap(im.sz_small, im.sz_small);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case PHOTOS:
|
case PHOTOS:
|
||||||
if (d->pictures.nr > 0) {
|
// If there are photos, show one of the three photo icons: fish= photos during dive;
|
||||||
IconMetrics im = defaultIconMetrics();
|
// sun=photos before/after dive; sun+fish=photos during dive as well as before/after
|
||||||
return QIcon(icon_names[countPhotos(d)]).pixmap(im.sz_small, im.sz_small);
|
if (d->pictures.nr > 0)
|
||||||
} // If there are photos, show one of the three photo icons: fish= photos during dive;
|
return getPhotoIcon(countPhotos(d));
|
||||||
break; // sun=photos before/after dive; sun+fish=photos during dive as well as before/after
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Qt::ToolTipRole:
|
case Qt::ToolTipRole:
|
||||||
|
|
Loading…
Add table
Reference in a new issue