summaryrefslogtreecommitdiffstats
path: root/qt-ui/divepicturewidget.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-01 09:02:10 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-01 09:02:10 -0700
commit6548773ad6d703aac0d0994a55c78a9ab5a73507 (patch)
treec3cc81c4771ba7d6354738e288463b497eb1f61c /qt-ui/divepicturewidget.cpp
parent2af7aefd7312c0e85e3b3bc57f3e3ff106bc54db (diff)
downloadsubsurface-6548773ad6d703aac0d0994a55c78a9ab5a73507.tar.gz
Implement a cache for the scaled images
No point in scaling them every time the user looks at the dive. Over time this may waste some memory (especially if people have a ton of pictures and let the process run a very long time). For now I won't worry about that. Fixes #577 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divepicturewidget.cpp')
-rw-r--r--qt-ui/divepicturewidget.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/qt-ui/divepicturewidget.cpp b/qt-ui/divepicturewidget.cpp
index 6742fc274..cadbe04e6 100644
--- a/qt-ui/divepicturewidget.cpp
+++ b/qt-ui/divepicturewidget.cpp
@@ -2,6 +2,7 @@
#include <dive.h>
#include <QtConcurrentMap>
#include <QDir>
+#include <QHash>
DivePictureModel *DivePictureModel::instance()
{
@@ -18,10 +19,16 @@ typedef QList<SPixmap> SPixmapList;
SPixmap scaleImages(const QString &s)
{
- QImage p = QImage(s).scaled(128, 128, Qt::KeepAspectRatio);
+ static QHash <QString, QImage > cache;
SPixmap ret;
ret.first = s;
- ret.second = p;
+ if (cache.contains(s)) {
+ ret.second = cache.value(s);
+ } else {
+ QImage p = QImage(s).scaled(128, 128, Qt::KeepAspectRatio);
+ cache.insert(s, p);
+ ret.second = p;
+ }
return ret;
}