31 #include <QElapsedTimer> 37 #include "qgis_core.h" 49 class CORE_EXPORT QgsSvgCacheEntry
53 QgsSvgCacheEntry() =
delete;
65 QgsSvgCacheEntry(
const QString &path,
double size,
double strokeWidth,
double widthScaleFactor,
const QColor &fill,
const QColor &stroke,
66 double fixedAspectRatio = 0 ) ;
69 QgsSvgCacheEntry(
const QgsSvgCacheEntry &rh ) =
delete;
71 QgsSvgCacheEntry &operator=(
const QgsSvgCacheEntry &rh ) =
delete;
77 QDateTime fileModified;
79 QElapsedTimer fileModifiedLastCheckTimer;
80 int mFileModifiedCheckTimeout = 30000;
83 double strokeWidth = 0;
84 double widthScaleFactor = 1.0;
87 double fixedAspectRatio = 0;
95 QColor fill = Qt::black;
96 QColor stroke = Qt::black;
97 std::unique_ptr< QImage > image;
98 std::unique_ptr< QPicture > picture;
100 QByteArray svgContent;
103 QgsSvgCacheEntry *nextEntry =
nullptr;
104 QgsSvgCacheEntry *previousEntry =
nullptr;
107 bool operator==(
const QgsSvgCacheEntry &other )
const;
109 int dataSize()
const;
113 QgsSvgCacheEntry(
const QgsSvgCacheEntry &rh );
154 QImage svgAsImage(
const QString &path,
double size,
const QColor &fill,
const QColor &stroke,
double strokeWidth,
155 double widthScaleFactor,
bool &fitsInCache,
double fixedAspectRatio = 0 );
168 QPicture svgAsPicture(
const QString &path,
double size,
const QColor &fill,
const QColor &stroke,
double strokeWidth,
169 double widthScaleFactor,
bool forceVectorOutput =
false,
double fixedAspectRatio = 0 );
183 QSizeF svgViewboxSize(
const QString &path,
double size,
const QColor &fill,
const QColor &stroke,
double strokeWidth,
184 double widthScaleFactor,
double fixedAspectRatio = 0 );
189 void containsParams(
const QString &path,
bool &hasFillParam, QColor &defaultFillColor,
bool &hasStrokeParam, QColor &defaultStrokeColor,
bool &hasStrokeWidthParam,
190 double &defaultStrokeWidth )
const;
214 void containsParams(
const QString &path,
bool &hasFillParam,
bool &hasDefaultFillParam, QColor &defaultFillColor,
215 bool &hasFillOpacityParam,
bool &hasDefaultFillOpacity,
double &defaultFillOpacity,
216 bool &hasStrokeParam,
bool &hasDefaultStrokeColor, QColor &defaultStrokeColor,
217 bool &hasStrokeWidthParam,
bool &hasDefaultStrokeWidth,
double &defaultStrokeWidth,
218 bool &hasStrokeOpacityParam,
bool &hasDefaultStrokeOpacity,
double &defaultStrokeOpacity )
const SIP_PYNAME( containsParamsV3 );
221 QByteArray getImageData(
const QString &path )
const;
224 QByteArray svgContent(
const QString &path,
double size,
const QColor &fill,
const QColor &stroke,
double strokeWidth,
225 double widthScaleFactor,
double fixedAspectRatio = 0 );
229 void statusChanged(
const QString &statusQString );
235 void remoteSvgFetched(
const QString &url );
238 void downloadProgress( qint64, qint64 );
240 void onRemoteSvgFetched(
const QString &url,
bool success );
254 QgsSvgCacheEntry *insertSvg(
const QString &path,
double size,
const QColor &fill,
const QColor &stroke,
double strokeWidth,
255 double widthScaleFactor,
double fixedAspectRatio = 0 );
257 void replaceParamsAndCacheSvg( QgsSvgCacheEntry *entry );
258 void cacheImage( QgsSvgCacheEntry *entry );
259 void cachePicture( QgsSvgCacheEntry *entry,
bool forceVectorOutput =
false );
261 QgsSvgCacheEntry *cacheEntry(
const QString &path,
double size,
const QColor &fill,
const QColor &stroke,
double strokeWidth,
262 double widthScaleFactor,
double fixedAspectRatio = 0 );
265 void trimToMaximumSize();
268 void takeEntryFromList( QgsSvgCacheEntry *entry );
271 int mFileModifiedCheckTimeout = 30000;
274 QMultiHash< QString, QgsSvgCacheEntry * > mEntryLookup;
280 QgsSvgCacheEntry *mLeastRecentEntry =
nullptr;
281 QgsSvgCacheEntry *mMostRecentEntry =
nullptr;
284 static const long MAXIMUM_SIZE = 20000000;
287 void replaceElemParams( QDomElement &elem,
const QColor &fill,
const QColor &stroke,
double strokeWidth );
289 void containsElemParams(
const QDomElement &elem,
290 bool &hasFillParam,
bool &hasDefaultFill, QColor &defaultFill,
291 bool &hasFillOpacityParam,
bool &hasDefaultFillOpacity,
double &defaultFillOpacity,
292 bool &hasStrokeParam,
bool &hasDefaultStroke, QColor &defaultStroke,
293 bool &hasStrokeWidthParam,
bool &hasDefaultStrokeWidth,
double &defaultStrokeWidth,
294 bool &hasStrokeOpacityParam,
bool &hasDefaultStrokeOpacity,
double &defaultStrokeOpacity )
const SIP_PYNAME( containsParamsV3 );
297 double calcSizeScaleFactor( QgsSvgCacheEntry *entry,
const QDomElement &docElem, QSizeF &viewboxSize )
const;
300 void removeCacheEntry(
const QString &s, QgsSvgCacheEntry *entry );
303 void printEntryList();
309 QSize sizeForImage(
const QgsSvgCacheEntry &entry, QSizeF &viewBoxSize, QSizeF &scaledSize )
const;
314 QImage imageFromCachedPicture(
const QgsSvgCacheEntry &entry )
const;
316 QByteArray fetchImageData(
const QString &path,
bool &ok )
const;
319 QByteArray mMissingSvg;
321 QByteArray mFetchingSvg;
324 mutable QMutex mMutex;
326 mutable QCache< QString, QByteArray > mRemoteContentCache;
327 mutable QSet< QString > mPendingRemoteUrls;
329 friend class TestQgsSvgCache;
332 #endif // QGSSVGCACHE_H
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
A cache for images / pictures derived from svg files.