Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/room/delegate/pixmapcache.cpp
Show All 17 Lines | 1 | /* | |||
---|---|---|---|---|---|
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "pixmapcache.h" | 21 | #include "pixmapcache.h" | ||
22 | #include "ruqolawidgets_debug.h" | 22 | #include "ruqolawidgets_debug.h" | ||
23 | 23 | | |||
24 | QPixmap PixmapCache::pixmapForLocalFile(const QString &path) | 24 | QPixmap PixmapCache::pixmapForLocalFile(const QString &path) | ||
25 | { | 25 | { | ||
26 | auto it = mCachedImages.find(path); | 26 | auto pixmap = findCachedPixmap(path); | ||
27 | if (it != mCachedImages.end()) { | 27 | | ||
28 | return it->value; | 28 | if (pixmap.isNull()) { | ||
29 | } | 29 | pixmap = QPixmap(path); | ||
30 | auto pixmap = QPixmap(path); | | |||
31 | if (pixmap.isNull()) { | 30 | if (pixmap.isNull()) { | ||
32 | qCWarning(RUQOLAWIDGETS_LOG) << "Could not load" << path; | 31 | qCWarning(RUQOLAWIDGETS_LOG) << "Could not load" << path; | ||
33 | return pixmap; | 32 | return pixmap; | ||
34 | } | 33 | } | ||
35 | mCachedImages.insert(path, pixmap); | 34 | insertCachedPixmap(path, pixmap); | ||
35 | } | ||||
36 | | ||||
36 | return pixmap; | 37 | return pixmap; | ||
37 | } | 38 | } | ||
39 | | ||||
40 | QPixmap PixmapCache::findCachedPixmap(const QString &path) | ||||
41 | { | ||||
42 | auto it = mCachedImages.find(path); | ||||
43 | return it == mCachedImages.end() ? QPixmap() : it->value; | ||||
44 | } | ||||
45 | | ||||
46 | void PixmapCache::insertCachedPixmap(const QString& path, const QPixmap& pixmap) | ||||
47 | { | ||||
48 | mCachedImages.insert(path, pixmap); | ||||
49 | } |