23
23
#include " qgsnetworkaccessmanager.h"
24
24
#include " qgsmessagelog.h"
25
25
#include " qgsnetworkcontentfetchertask.h"
26
+ #include " qgssettings.h"
26
27
27
28
#include < QApplication>
28
29
#include < QCoreApplication>
@@ -66,7 +67,7 @@ int QgsImageCacheEntry::dataSize() const
66
67
int size = 0 ;
67
68
if ( !image.isNull () )
68
69
{
69
- size += ( image.width () * image. height () * 32 );
70
+ size += image.sizeInBytes ( );
70
71
}
71
72
return size;
72
73
}
@@ -78,10 +79,17 @@ void QgsImageCacheEntry::dump() const
78
79
79
80
// /@endcond
80
81
82
+ static const int DEFAULT_IMAGE_CACHE_MAX_BYTES = 104857600 ;
81
83
82
84
QgsImageCache::QgsImageCache ( QObject *parent )
83
- : QgsAbstractContentCache< QgsImageCacheEntry >( parent, QObject::tr( " Image" ) )
85
+ : QgsAbstractContentCache< QgsImageCacheEntry >( parent, QObject::tr( " Image" ), DEFAULT_IMAGE_CACHE_MAX_BYTES )
84
86
{
87
+ int bytes = QgsSettings ().value ( QStringLiteral ( " /qgis/maxImageCacheSize" ), 0 ).toInt ();
88
+ if ( bytes > 0 )
89
+ {
90
+ mMaxCacheSize = bytes;
91
+ }
92
+
85
93
mMissingSvg = QStringLiteral ( " <svg width='10' height='10'><text x='5' y='10' font-size='10' text-anchor='middle'>?</text></svg>" ).toLatin1 ();
86
94
87
95
const QString downloadingSvgPath = QgsApplication::defaultThemePath () + QStringLiteral ( " downloading_svg.svg" );
@@ -127,15 +135,15 @@ QImage QgsImageCache::pathAsImage( const QString &f, const QSize size, const boo
127
135
long cachedDataSize = 0 ;
128
136
bool isBroken = false ;
129
137
result = renderImage ( file, size, keepAspectRatio, opacity, targetDpi, isBroken, blocking );
130
- cachedDataSize += result.width () * result. height () * 32 ;
138
+ cachedDataSize += result.sizeInBytes () ;
131
139
if ( cachedDataSize > mMaxCacheSize / 2 )
132
140
{
133
141
fitsInCache = false ;
134
142
currentEntry->image = QImage ();
135
143
}
136
144
else
137
145
{
138
- mTotalSize += ( result.width () * result. height () * 32 );
146
+ mTotalSize += result.sizeInBytes ( );
139
147
currentEntry->image = result;
140
148
}
141
149
0 commit comments