@@ -95,7 +95,7 @@ QgsSvgCache::~QgsSvgCache()
9595}
9696
9797
98- const QImage& QgsSvgCache::svgAsImage ( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
98+ const QImage& QgsSvgCache::svgAsImage ( const QString& file, int size, const QColor& fill, const QColor& outline, double outlineWidth,
9999 double widthScaleFactor, double rasterScaleFactor )
100100{
101101 QgsSvgCacheEntry* currentEntry = cacheEntry ( file, size, fill, outline, outlineWidth, widthScaleFactor, rasterScaleFactor );
@@ -111,7 +111,7 @@ const QImage& QgsSvgCache::svgAsImage( const QString& file, double size, const Q
111111 return *( currentEntry->image );
112112}
113113
114- const QPicture& QgsSvgCache::svgAsPicture ( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
114+ const QPicture& QgsSvgCache::svgAsPicture ( const QString& file, int size, const QColor& fill, const QColor& outline, double outlineWidth,
115115 double widthScaleFactor, double rasterScaleFactor )
116116{
117117 QgsSvgCacheEntry* currentEntry = cacheEntry ( file, size, fill, outline, outlineWidth, widthScaleFactor, rasterScaleFactor );
@@ -127,7 +127,7 @@ const QPicture& QgsSvgCache::svgAsPicture( const QString& file, double size, con
127127 return *( currentEntry->picture );
128128}
129129
130- QgsSvgCacheEntry* QgsSvgCache::insertSVG ( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
130+ QgsSvgCacheEntry* QgsSvgCache::insertSVG ( const QString& file, int size, const QColor& fill, const QColor& outline, double outlineWidth,
131131 double widthScaleFactor, double rasterScaleFactor )
132132{
133133 QgsSvgCacheEntry* entry = new QgsSvgCacheEntry ( file, size, outlineWidth, widthScaleFactor, rasterScaleFactor, fill, outline );
@@ -159,37 +159,6 @@ QgsSvgCacheEntry* QgsSvgCache::insertSVG( const QString& file, double size, cons
159159void QgsSvgCache::containsParams ( const QString& path, bool & hasFillParam, QColor& defaultFillColor, bool & hasOutlineParam, QColor& defaultOutlineColor,
160160 bool & hasOutlineWidthParam, double & defaultOutlineWidth ) const
161161{
162- /* hasFillParam = false;
163- hasOutlineParam = false;
164- hasOutlineWidthParam = false;
165-
166- QFile svgFile( path );
167- if ( !svgFile.open( QIODevice::ReadOnly ) )
168- {
169- return;
170- }
171-
172- QDomDocument svgDoc;
173- if ( !svgDoc.setContent( &svgFile ) )
174- {
175- return;
176- }
177-
178- //there are surely faster ways to get this information
179- QString content = svgDoc.toString();
180- if ( content.contains( "param(fill" ) )
181- {
182- hasFillParam = true;
183- }
184- if ( content.contains( "param(outline" ) )
185- {
186- hasOutlineParam = true;
187- }
188- if ( content.contains( "param(outline-width)" ) )
189- {
190- hasOutlineWidthParam = true;
191- }*/
192-
193162 defaultFillColor = QColor ( Qt::black );
194163 defaultOutlineColor = QColor ( Qt::black );
195164 defaultOutlineWidth = 1.0 ;
@@ -247,7 +216,7 @@ void QgsSvgCache::cacheImage( QgsSvgCacheEntry* entry )
247216 delete entry->image ;
248217 entry->image = 0 ;
249218
250- double imageSize = entry->size * entry-> widthScaleFactor * entry-> rasterScaleFactor ;
219+ int imageSize = entry->size ;
251220 QImage* image = new QImage ( imageSize, imageSize, QImage::Format_ARGB32_Premultiplied );
252221 image->fill ( 0 ); // transparent background
253222
@@ -271,8 +240,7 @@ void QgsSvgCache::cachePicture( QgsSvgCacheEntry *entry )
271240
272241 // correct QPictures dpi correction
273242 QPicture* picture = new QPicture ();
274- double dpi = entry->widthScaleFactor * 25.4 * entry->rasterScaleFactor ;
275- double pictureSize = entry->size * entry->widthScaleFactor / dpi * picture->logicalDpiX ();
243+ double pictureSize = entry->size / 25.4 / entry->rasterScaleFactor * picture->logicalDpiX ();
276244 QRectF rect ( QPointF ( -pictureSize / 2.0 , -pictureSize / 2.0 ), QSizeF ( pictureSize, pictureSize ) );
277245
278246
@@ -283,7 +251,7 @@ void QgsSvgCache::cachePicture( QgsSvgCacheEntry *entry )
283251 mTotalSize += entry->picture ->size ();
284252}
285253
286- QgsSvgCacheEntry* QgsSvgCache::cacheEntry ( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
254+ QgsSvgCacheEntry* QgsSvgCache::cacheEntry ( const QString& file, int size, const QColor& fill, const QColor& outline, double outlineWidth,
287255 double widthScaleFactor, double rasterScaleFactor )
288256{
289257 // search entries in mEntryLookup
@@ -302,7 +270,6 @@ QgsSvgCacheEntry* QgsSvgCache::cacheEntry( const QString& file, double size, con
302270 }
303271 }
304272
305-
306273 // if not found: create new entry
307274 // cache and replace params in svg content
308275 if ( !currentEntry )
@@ -312,10 +279,18 @@ QgsSvgCacheEntry* QgsSvgCache::cacheEntry( const QString& file, double size, con
312279 else
313280 {
314281 takeEntryFromList ( currentEntry );
315- mMostRecentEntry ->nextEntry = currentEntry;
316- currentEntry->previousEntry = mMostRecentEntry ;
317- currentEntry->nextEntry = 0 ;
318- mMostRecentEntry = currentEntry;
282+ if ( !mMostRecentEntry ) // list is empty
283+ {
284+ mMostRecentEntry = currentEntry;
285+ mLeastRecentEntry = currentEntry;
286+ }
287+ else
288+ {
289+ mMostRecentEntry ->nextEntry = currentEntry;
290+ currentEntry->previousEntry = mMostRecentEntry ;
291+ currentEntry->nextEntry = 0 ;
292+ mMostRecentEntry = currentEntry;
293+ }
319294 }
320295
321296 // debugging
@@ -537,6 +512,7 @@ void QgsSvgCache::trimToMaximumSize()
537512 entry = entry->nextEntry ;
538513
539514 takeEntryFromList ( bkEntry );
515+ mEntryLookup .remove ( bkEntry->file , bkEntry );
540516 mTotalSize -= bkEntry->dataSize ();
541517 delete bkEntry;
542518 }
0 commit comments