File indexing completed on 2024-12-08 04:34:23
0001 /* 0002 SPDX-FileCopyrightText: 2020 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "pixmapcache.h" 0008 #include "ruqolawidgets_debug.h" 0009 0010 void PixmapCache::setMaxEntries(int maxEntries) 0011 { 0012 mCachedImages.setMaxEntries(maxEntries); 0013 } 0014 0015 QPixmap PixmapCache::pixmapForLocalFile(const QString &path) 0016 { 0017 auto pixmap = findCachedPixmap(path); 0018 0019 if (pixmap.isNull()) { 0020 pixmap = QPixmap(path); 0021 if (pixmap.isNull()) { 0022 qCWarning(RUQOLAWIDGETS_LOG) << "Could not load" << path; 0023 return pixmap; 0024 } 0025 insertCachedPixmap(path, pixmap); 0026 } 0027 0028 return pixmap; 0029 } 0030 0031 QPixmap PixmapCache::findCachedPixmap(const QString &path) 0032 { 0033 auto it = mCachedImages.find(path); 0034 return it == mCachedImages.end() ? QPixmap() : it->value; 0035 } 0036 0037 void PixmapCache::insertCachedPixmap(const QString &path, const QPixmap &pixmap) 0038 { 0039 mCachedImages.insert(path, pixmap); 0040 } 0041 0042 void PixmapCache::clear() 0043 { 0044 mCachedImages.clear(); 0045 } 0046 0047 void PixmapCache::remove(const QString &path) 0048 { 0049 mCachedImages.remove(path); 0050 }