|
@@ -43,14 +43,15 @@ |
|
|
// QgsSvgCacheEntry |
|
|
// |
|
|
|
|
|
QgsSvgCacheEntry::QgsSvgCacheEntry( const QString &path, double size, double strokeWidth, double widthScaleFactor, const QColor &fill, const QColor &stroke, double fixedAspectRatio ) |
|
|
QgsSvgCacheEntry::QgsSvgCacheEntry( const QString &path, double size, double strokeWidth, double widthScaleFactor, const QColor &fill, const QColor &stroke, double fixedAspectRatio, const QMap<QString, QString> ¶meters ) |
|
|
: QgsAbstractContentCacheEntry( path ) |
|
|
, size( size ) |
|
|
, strokeWidth( strokeWidth ) |
|
|
, widthScaleFactor( widthScaleFactor ) |
|
|
, fixedAspectRatio( fixedAspectRatio ) |
|
|
, fill( fill ) |
|
|
, stroke( stroke ) |
|
|
, parameters( parameters ) |
|
|
{ |
|
|
} |
|
|
|
|
@@ -120,12 +121,12 @@ QgsSvgCache::QgsSvgCache( QObject *parent ) |
|
|
} |
|
|
|
|
|
QImage QgsSvgCache::svgAsImage( const QString &file, double size, const QColor &fill, const QColor &stroke, double strokeWidth, |
|
|
double widthScaleFactor, bool &fitsInCache, double fixedAspectRatio, bool blocking ) |
|
|
double widthScaleFactor, bool &fitsInCache, double fixedAspectRatio, bool blocking, const QMap<QString, QString> ¶meters ) |
|
|
{ |
|
|
QMutexLocker locker( &mMutex ); |
|
|
|
|
|
fitsInCache = true; |
|
|
QgsSvgCacheEntry *currentEntry = cacheEntry( file, size, fill, stroke, strokeWidth, widthScaleFactor, fixedAspectRatio, blocking ); |
|
|
QgsSvgCacheEntry *currentEntry = cacheEntry( file, size, fill, stroke, strokeWidth, widthScaleFactor, fixedAspectRatio, parameters, blocking ); |
|
|
|
|
|
QImage result; |
|
|
|
|
@@ -180,11 +181,11 @@ QImage QgsSvgCache::svgAsImage( const QString &file, double size, const QColor & |
|
|
} |
|
|
|
|
|
QPicture QgsSvgCache::svgAsPicture( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, |
|
|
double widthScaleFactor, bool forceVectorOutput, double fixedAspectRatio, bool blocking ) |
|
|
double widthScaleFactor, bool forceVectorOutput, double fixedAspectRatio, bool blocking, const QMap<QString, QString> ¶meters ) |
|
|
{ |
|
|
QMutexLocker locker( &mMutex ); |
|
|
|
|
|
QgsSvgCacheEntry *currentEntry = cacheEntry( path, size, fill, stroke, strokeWidth, widthScaleFactor, fixedAspectRatio, blocking ); |
|
|
QgsSvgCacheEntry *currentEntry = cacheEntry( path, size, fill, stroke, strokeWidth, widthScaleFactor, fixedAspectRatio, parameters, blocking ); |
|
|
|
|
|
//if current entry picture is 0: cache picture for entry |
|
|
//update stats for memory usage |
|
@@ -204,21 +205,21 @@ QPicture QgsSvgCache::svgAsPicture( const QString &path, double size, const QCol |
|
|
} |
|
|
|
|
|
QByteArray QgsSvgCache::svgContent( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, |
|
|
double widthScaleFactor, double fixedAspectRatio, bool blocking, bool *isMissingImage ) |
|
|
double widthScaleFactor, double fixedAspectRatio, bool blocking, const QMap<QString, QString> ¶meters, bool *isMissingImage ) |
|
|
{ |
|
|
QMutexLocker locker( &mMutex ); |
|
|
|
|
|
QgsSvgCacheEntry *currentEntry = cacheEntry( path, size, fill, stroke, strokeWidth, widthScaleFactor, fixedAspectRatio, blocking, isMissingImage ); |
|
|
QgsSvgCacheEntry *currentEntry = cacheEntry( path, size, fill, stroke, strokeWidth, widthScaleFactor, fixedAspectRatio, parameters, blocking, isMissingImage ); |
|
|
|
|
|
return currentEntry->svgContent; |
|
|
} |
|
|
|
|
|
QSizeF QgsSvgCache::svgViewboxSize( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, |
|
|
double widthScaleFactor, double fixedAspectRatio, bool blocking ) |
|
|
double widthScaleFactor, double fixedAspectRatio, bool blocking, const QMap<QString, QString> ¶meters ) |
|
|
{ |
|
|
QMutexLocker locker( &mMutex ); |
|
|
|
|
|
QgsSvgCacheEntry *currentEntry = cacheEntry( path, size, fill, stroke, strokeWidth, widthScaleFactor, fixedAspectRatio, blocking ); |
|
|
QgsSvgCacheEntry *currentEntry = cacheEntry( path, size, fill, stroke, strokeWidth, widthScaleFactor, fixedAspectRatio, parameters, blocking ); |
|
|
return currentEntry->viewboxSize; |
|
|
} |
|
|
|
|
@@ -303,7 +304,7 @@ void QgsSvgCache::replaceParamsAndCacheSvg( QgsSvgCacheEntry *entry, bool blocki |
|
|
QSizeF viewboxSize; |
|
|
double sizeScaleFactor = calcSizeScaleFactor( entry, docElem, viewboxSize ); |
|
|
entry->viewboxSize = viewboxSize; |
|
|
replaceElemParams( docElem, entry->fill, entry->stroke, entry->strokeWidth * sizeScaleFactor ); |
|
|
replaceElemParams( docElem, entry->fill, entry->stroke, entry->strokeWidth * sizeScaleFactor, entry->parameters ); |
|
|
|
|
|
entry->svgContent = svgDoc.toByteArray( 0 ); |
|
|
|
|
@@ -494,9 +495,9 @@ void QgsSvgCache::cachePicture( QgsSvgCacheEntry *entry, bool forceVectorOutput |
|
|
} |
|
|
|
|
|
QgsSvgCacheEntry *QgsSvgCache::cacheEntry( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, |
|
|
double widthScaleFactor, double fixedAspectRatio, bool blocking, bool *isMissingImage ) |
|
|
double widthScaleFactor, double fixedAspectRatio, const QMap<QString, QString> ¶meters, bool blocking, bool *isMissingImage ) |
|
|
{ |
|
|
QgsSvgCacheEntry *currentEntry = findExistingEntry( new QgsSvgCacheEntry( path, size, strokeWidth, widthScaleFactor, fill, stroke, fixedAspectRatio ) ); |
|
|
QgsSvgCacheEntry *currentEntry = findExistingEntry( new QgsSvgCacheEntry( path, size, strokeWidth, widthScaleFactor, fill, stroke, fixedAspectRatio, parameters ) ); |
|
|
|
|
|
if ( currentEntry->svgContent.isEmpty() ) |
|
|
{ |
|
@@ -510,7 +511,7 @@ QgsSvgCacheEntry *QgsSvgCache::cacheEntry( const QString &path, double size, con |
|
|
} |
|
|
|
|
|
|
|
|
void QgsSvgCache::replaceElemParams( QDomElement &elem, const QColor &fill, const QColor &stroke, double strokeWidth ) |
|
|
void QgsSvgCache::replaceElemParams( QDomElement &elem, const QColor &fill, const QColor &stroke, double strokeWidth, const QMap<QString, QString> ¶meters ) |
|
|
{ |
|
|
if ( elem.isNull() ) |
|
|
{ |
|
@@ -595,6 +596,31 @@ void QgsSvgCache::replaceElemParams( QDomElement &elem, const QColor &fill, cons |
|
|
{ |
|
|
elem.setAttribute( attribute.name(), QString::number( strokeWidth ) ); |
|
|
} |
|
|
else |
|
|
{ |
|
|
QMap<QString, QString>::const_iterator paramIt = parameters.constBegin(); |
|
|
for ( ; paramIt != parameters.constEnd(); ++paramIt ) |
|
|
{ |
|
|
if ( value.startsWith( QString( QLatin1String( "param(%1)" ) ).arg( paramIt.key() ) ) ) |
|
|
{ |
|
|
elem.setAttribute( attribute.name(), paramIt.value() ); |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if ( elem.nodeValue().startsWith( "param(" ) ) |
|
|
{ |
|
|
QMap<QString, QString>::const_iterator paramIt = parameters.constBegin(); |
|
|
for ( ; paramIt != parameters.constEnd(); ++paramIt ) |
|
|
{ |
|
|
if ( elem.nodeValue().startsWith( QString( QLatin1String( "param(%1)" ) ).arg( paramIt.key() ) ) ) |
|
|
{ |
|
|
elem.setNodeValue( paramIt.value() ); |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
@@ -603,7 +629,7 @@ void QgsSvgCache::replaceElemParams( QDomElement &elem, const QColor &fill, cons |
|
|
for ( int i = 0; i < nChildren; ++i ) |
|
|
{ |
|
|
QDomElement childElem = childList.at( i ).toElement(); |
|
|
replaceElemParams( childElem, fill, stroke, strokeWidth ); |
|
|
replaceElemParams( childElem, fill, stroke, strokeWidth, parameters ); |
|
|
} |
|
|
} |
|
|
|
|
|