@@ -95,7 +95,7 @@ QgsSvgCache::~QgsSvgCache()
95
95
}
96
96
97
97
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,
99
99
double widthScaleFactor, double rasterScaleFactor )
100
100
{
101
101
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
111
111
return *( currentEntry->image );
112
112
}
113
113
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,
115
115
double widthScaleFactor, double rasterScaleFactor )
116
116
{
117
117
QgsSvgCacheEntry* currentEntry = cacheEntry ( file, size, fill, outline, outlineWidth, widthScaleFactor, rasterScaleFactor );
@@ -127,7 +127,7 @@ const QPicture& QgsSvgCache::svgAsPicture( const QString& file, double size, con
127
127
return *( currentEntry->picture );
128
128
}
129
129
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,
131
131
double widthScaleFactor, double rasterScaleFactor )
132
132
{
133
133
QgsSvgCacheEntry* entry = new QgsSvgCacheEntry ( file, size, outlineWidth, widthScaleFactor, rasterScaleFactor, fill, outline );
@@ -159,37 +159,6 @@ QgsSvgCacheEntry* QgsSvgCache::insertSVG( const QString& file, double size, cons
159
159
void QgsSvgCache::containsParams ( const QString& path, bool & hasFillParam, QColor& defaultFillColor, bool & hasOutlineParam, QColor& defaultOutlineColor,
160
160
bool & hasOutlineWidthParam, double & defaultOutlineWidth ) const
161
161
{
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
-
193
162
defaultFillColor = QColor ( Qt::black );
194
163
defaultOutlineColor = QColor ( Qt::black );
195
164
defaultOutlineWidth = 1.0 ;
@@ -247,7 +216,7 @@ void QgsSvgCache::cacheImage( QgsSvgCacheEntry* entry )
247
216
delete entry->image ;
248
217
entry->image = 0 ;
249
218
250
- double imageSize = entry->size * entry-> widthScaleFactor * entry-> rasterScaleFactor ;
219
+ int imageSize = entry->size ;
251
220
QImage* image = new QImage ( imageSize, imageSize, QImage::Format_ARGB32_Premultiplied );
252
221
image->fill ( 0 ); // transparent background
253
222
@@ -271,8 +240,7 @@ void QgsSvgCache::cachePicture( QgsSvgCacheEntry *entry )
271
240
272
241
// correct QPictures dpi correction
273
242
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 ();
276
244
QRectF rect ( QPointF ( -pictureSize / 2.0 , -pictureSize / 2.0 ), QSizeF ( pictureSize, pictureSize ) );
277
245
278
246
@@ -283,7 +251,7 @@ void QgsSvgCache::cachePicture( QgsSvgCacheEntry *entry )
283
251
mTotalSize += entry->picture ->size ();
284
252
}
285
253
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,
287
255
double widthScaleFactor, double rasterScaleFactor )
288
256
{
289
257
// search entries in mEntryLookup
@@ -302,7 +270,6 @@ QgsSvgCacheEntry* QgsSvgCache::cacheEntry( const QString& file, double size, con
302
270
}
303
271
}
304
272
305
-
306
273
// if not found: create new entry
307
274
// cache and replace params in svg content
308
275
if ( !currentEntry )
@@ -312,10 +279,18 @@ QgsSvgCacheEntry* QgsSvgCache::cacheEntry( const QString& file, double size, con
312
279
else
313
280
{
314
281
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
+ }
319
294
}
320
295
321
296
// debugging
@@ -537,6 +512,7 @@ void QgsSvgCache::trimToMaximumSize()
537
512
entry = entry->nextEntry ;
538
513
539
514
takeEntryFromList ( bkEntry );
515
+ mEntryLookup .remove ( bkEntry->file , bkEntry );
540
516
mTotalSize -= bkEntry->dataSize ();
541
517
delete bkEntry;
542
518
}
0 commit comments