Skip to content

Commit

Permalink
Remove more unused raster scale factor handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 16, 2017
1 parent 48797fa commit 3274e19
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 57 deletions.
6 changes: 6 additions & 0 deletions doc/api_break.dox
Expand Up @@ -1632,6 +1632,12 @@ QgsSvgCache {#qgis_api_break_3_0_QgsSvgCache}

- This class is no longer a singleton and instance() has been removed. Instead use QgsApplication::svgCache() to access an application-wide cache.
- containsParamsV2() was removed. Use containsParamsV3() instead.
- The rasterScaleFactor parameter was removed from all methods

QgsSvgCacheEntry {#qgis_api_break_3_0_QgsSvgCacheEntry}
----------------

- The rasterScaleFactor member was removed.

QgsStyle (renamed from QgsStyleV2) {#qgis_api_break_3_0_QgsStyle}
----------------------------------
Expand Down
15 changes: 7 additions & 8 deletions python/core/symbology-ng/qgssvgcache.sip
Expand Up @@ -16,7 +16,7 @@ class QgsSvgCacheEntry
* @param outline color of outline
* @param lookupKey the key string used in QgsSvgCache for quick lookup of this entry (relative or absolute path)
*/
QgsSvgCacheEntry( const QString& file, double size, double outlineWidth, double widthScaleFactor, double rasterScaleFactor, const QColor& fill, const QColor& outline, const QString& lookupKey = QString() );
QgsSvgCacheEntry( const QString& file, double size, double outlineWidth, double widthScaleFactor, const QColor& fill, const QColor& outline, const QString& lookupKey = QString() );
~QgsSvgCacheEntry();

//! Absolute path to SVG file
Expand All @@ -26,7 +26,6 @@ class QgsSvgCacheEntry
double size; //size in pixels (cast to int for QImage)
double outlineWidth;
double widthScaleFactor;
double rasterScaleFactor;

/** SVG viewbox size.
* @note added in QGIS 2.14
Expand Down Expand Up @@ -80,7 +79,7 @@ class QgsSvgCache : QObject
* @param fitsInCache
*/
QImage svgAsImage( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor, bool& fitsInCache );
double widthScaleFactor, bool& fitsInCache );
/** Get SVG as QPicture&.
* @param file Absolute or relative path to SVG file.
* @param size size of cached image
Expand All @@ -92,7 +91,7 @@ class QgsSvgCache : QObject
* @param forceVectorOutput
*/
QPicture svgAsPicture( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor, bool forceVectorOutput = false );
double widthScaleFactor, bool forceVectorOutput = false );

/** Calculates the viewbox size of a (possibly cached) SVG file.
* @param file Absolute or relative path to SVG file.
Expand All @@ -106,7 +105,7 @@ class QgsSvgCache : QObject
* @note added in QGIS 2.14
*/
QSizeF svgViewboxSize( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor );
double widthScaleFactor );

/** Tests if an svg file contains parameters for fill, outline color, outline width. If yes, possible default values are returned. If there are several
default values in the svg file, only the first one is considered*/
Expand Down Expand Up @@ -145,7 +144,7 @@ class QgsSvgCache : QObject

/** Get SVG content*/
QByteArray svgContent( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor );
double widthScaleFactor );

signals:
/** Emit a signal to be caught by qgisapp and display a msg on status bar */
Expand All @@ -164,14 +163,14 @@ class QgsSvgCache : QObject
* @param rasterScaleFactor raster scale factor
*/
QgsSvgCacheEntry* insertSVG( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor );
double widthScaleFactor );

void replaceParamsAndCacheSvg( QgsSvgCacheEntry* entry );
void cacheImage( QgsSvgCacheEntry* entry );
void cachePicture( QgsSvgCacheEntry* entry, bool forceVectorOutput = false );
/** Returns entry from cache or creates a new entry if it does not exist already*/
QgsSvgCacheEntry* cacheEntry( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor );
double widthScaleFactor );

/** Removes the least used items until the maximum size is under the limit*/
void trimToMaximumSize();
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposerpicturewidget.cpp
Expand Up @@ -434,7 +434,7 @@ QIcon QgsComposerPictureWidget::svgToIcon( const QString& filePath ) const
outlineWidth = 0.6;

bool fitsInCache; // should always fit in cache at these sizes (i.e. under 559 px ^ 2, or half cache size)
const QImage& img = QgsApplication::svgCache()->svgAsImage( filePath, 30.0, fill, outline, outlineWidth, 3.5 /*appr. 88 dpi*/, 1.0, fitsInCache );
const QImage& img = QgsApplication::svgCache()->svgAsImage( filePath, 30.0, fill, outline, outlineWidth, 3.5 /*appr. 88 dpi*/, fitsInCache );

return QIcon( QPixmap::fromImage( img ) );
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposerarrow.cpp
Expand Up @@ -256,7 +256,7 @@ void QgsComposerArrow::drawSVGMarker( QPainter* p, MarkerType type, const QStrin

QSvgRenderer r;
const QByteArray &svgContent = QgsApplication::svgCache()->svgContent( svgFileName, mArrowHeadWidth, mArrowHeadFillColor, mArrowHeadOutlineColor, mArrowHeadOutlineWidth,
1.0, 1.0 );
1.0 );
r.load( svgContent );

p->save();
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposerpicture.cpp
Expand Up @@ -373,7 +373,7 @@ void QgsComposerPicture::loadLocalPicture( const QString &path )
{
//try to open svg
const QByteArray &svgContent = QgsApplication::svgCache()->svgContent( pic.fileName(), rect().width(), mSvgFillColor, mSvgBorderColor, mSvgBorderWidth,
1.0, 1.0 );
1.0 );
mSVG.load( svgContent );
if ( mSVG.isValid() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgspallabeling.cpp
Expand Up @@ -2232,7 +2232,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
// TODO: only for placement which needs character info
// account for any data defined font metrics adjustments
lf->calculateInfo( placement == QgsPalLayerSettings::Curved || placement == QgsPalLayerSettings::PerimeterCurved,
labelFontMetrics.data(), xform, 1.0, maxcharanglein, maxcharangleout );
labelFontMetrics.data(), xform, maxcharanglein, maxcharangleout );
// for labelFeature the LabelInfo is passed to feat when it is registered

// TODO: allow layer-wide feature dist in PAL...?
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgstextlabelfeature.cpp
Expand Up @@ -43,7 +43,7 @@ QString QgsTextLabelFeature::text( int partId ) const
}


void QgsTextLabelFeature::calculateInfo( bool curvedLabeling, QFontMetricsF* fm, const QgsMapToPixel* xform, double fontScale, double maxinangle, double maxoutangle )
void QgsTextLabelFeature::calculateInfo( bool curvedLabeling, QFontMetricsF* fm, const QgsMapToPixel* xform, double maxinangle, double maxoutangle )
{
if ( mInfo )
return;
Expand All @@ -65,7 +65,7 @@ void QgsTextLabelFeature::calculateInfo( bool curvedLabeling, QFontMetricsF* fm,

// create label info!
double mapScale = xform->mapUnitsPerPixel();
double labelHeight = mapScale * fm->height() / fontScale;
double labelHeight = mapScale * fm->height();

// mLetterSpacing/mWordSpacing = 0.0 is default for non-curved labels
// (non-curved spacings handled by Qt in QgsPalLayerSettings/QgsPalLabeling)
Expand Down Expand Up @@ -102,7 +102,7 @@ void QgsTextLabelFeature::calculateInfo( bool curvedLabeling, QFontMetricsF* fm,
charWidth = fm->width( QString( mClusters[i] ) ) + wordSpaceFix;
}

double labelWidth = mapScale * charWidth / fontScale;
double labelWidth = mapScale * charWidth;
mInfo->char_info[i].width = labelWidth;
}
}
2 changes: 1 addition & 1 deletion src/core/qgstextlabelfeature.h
Expand Up @@ -39,7 +39,7 @@ class QgsTextLabelFeature : public QgsLabelFeature
QString text( int partId ) const;

//! calculate data for info(). setDefinedFont() must have been called already.
void calculateInfo( bool curvedLabeling, QFontMetricsF* fm, const QgsMapToPixel* xform, double fontScale, double maxinangle, double maxoutangle );
void calculateInfo( bool curvedLabeling, QFontMetricsF* fm, const QgsMapToPixel* xform, double maxinangle, double maxoutangle );

//! Get data-defined values
const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& dataDefinedValues() const { return mDataDefinedValues; }
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgsfillsymbollayer.cpp
Expand Up @@ -1951,11 +1951,11 @@ void QgsSVGFillSymbolLayer::applyPattern( QBrush& brush, const QString& svgFileP
bool fitsInCache = true;
double outlineWidth = QgsSymbolLayerUtils::convertToPainterUnits( context.renderContext(), svgOutlineWidth, svgOutlineWidthUnit, svgOutlineWidthMapUnitScale );
const QImage& patternImage = QgsApplication::svgCache()->svgAsImage( svgFilePath, size, svgFillColor, svgOutlineColor, outlineWidth,
context.renderContext().scaleFactor(), 1.0, fitsInCache );
context.renderContext().scaleFactor(), fitsInCache );
if ( !fitsInCache )
{
const QPicture& patternPict = QgsApplication::svgCache()->svgAsPicture( svgFilePath, size, svgFillColor, svgOutlineColor, outlineWidth,
context.renderContext().scaleFactor(), 1.0 );
context.renderContext().scaleFactor() );
double hwRatio = 1.0;
if ( patternPict.width() > 0 )
{
Expand Down
10 changes: 4 additions & 6 deletions src/core/symbology-ng/qgsmarkersymbollayer.cpp
Expand Up @@ -1973,7 +1973,7 @@ void QgsSvgMarkerSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContext
{
usePict = false;
const QImage& img = QgsApplication::svgCache()->svgAsImage( path, size, fillColor, outlineColor, outlineWidth,
context.renderContext().scaleFactor(), 1.0, fitsInCache );
context.renderContext().scaleFactor(), fitsInCache );
if ( fitsInCache && img.width() > 1 )
{
//consider transparency
Expand All @@ -1996,7 +1996,7 @@ void QgsSvgMarkerSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContext
{
p->setOpacity( context.alpha() );
const QPicture& pct = QgsApplication::svgCache()->svgAsPicture( path, size, fillColor, outlineColor, outlineWidth,
context.renderContext().scaleFactor(), 1.0, context.renderContext().forceVectorOutput() );
context.renderContext().scaleFactor(), context.renderContext().forceVectorOutput() );

if ( pct.width() > 1 )
{
Expand Down Expand Up @@ -2348,8 +2348,7 @@ bool QgsSvgMarkerSymbolLayer::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
}

const QByteArray &svgContent = QgsApplication::svgCache()->svgContent( path, size, fillColor, outlineColor, outlineWidth,
context.renderContext().scaleFactor(),
1.0 );
context.renderContext().scaleFactor() );

//if current entry image is 0: cache image for entry
// checks to see if image will fit into cache
Expand Down Expand Up @@ -2431,8 +2430,7 @@ QRectF QgsSvgMarkerSymbolLayer::bounds( QPointF point, QgsSymbolRenderContext& c
}

QSizeF svgViewbox = QgsApplication::svgCache()->svgViewboxSize( path, scaledSize, fillColor, outlineColor, outlineWidth,
context.renderContext().scaleFactor(),
1.0 );
context.renderContext().scaleFactor() );

double scaledHeight = svgViewbox.isValid() ? scaledSize * svgViewbox.height() / svgViewbox.width() : scaledSize;

Expand Down
34 changes: 15 additions & 19 deletions src/core/symbology-ng/qgssvgcache.cpp
Expand Up @@ -41,7 +41,6 @@ QgsSvgCacheEntry::QgsSvgCacheEntry()
, size( 0.0 )
, outlineWidth( 0 )
, widthScaleFactor( 1.0 )
, rasterScaleFactor( 1.0 )
, fill( Qt::black )
, outline( Qt::black )
, image( nullptr )
Expand All @@ -51,13 +50,12 @@ QgsSvgCacheEntry::QgsSvgCacheEntry()
{
}

QgsSvgCacheEntry::QgsSvgCacheEntry( const QString& f, double s, double ow, double wsf, double rsf, const QColor& fi, const QColor& ou, const QString& lk )
QgsSvgCacheEntry::QgsSvgCacheEntry( const QString& f, double s, double ow, double wsf, const QColor& fi, const QColor& ou, const QString& lk )
: file( f )
, lookupKey( lk.isEmpty() ? f : lk )
, size( s )
, outlineWidth( ow )
, widthScaleFactor( wsf )
, rasterScaleFactor( rsf )
, fill( fi )
, outline( ou )
, image( nullptr )
Expand All @@ -77,7 +75,7 @@ QgsSvgCacheEntry::~QgsSvgCacheEntry()
bool QgsSvgCacheEntry::operator==( const QgsSvgCacheEntry& other ) const
{
return other.file == file && qgsDoubleNear( other.size, size ) && qgsDoubleNear( other.outlineWidth, outlineWidth ) && qgsDoubleNear( other.widthScaleFactor, widthScaleFactor )
&& qgsDoubleNear( other.rasterScaleFactor, rasterScaleFactor ) && other.fill == fill && other.outline == outline;
&& other.fill == fill && other.outline == outline;
}

int QgsSvgCacheEntry::dataSize() const
Expand Down Expand Up @@ -110,12 +108,12 @@ QgsSvgCache::~QgsSvgCache()


QImage QgsSvgCache::svgAsImage( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor, bool& fitsInCache )
double widthScaleFactor, bool& fitsInCache )
{
QMutexLocker locker( &mMutex );

fitsInCache = true;
QgsSvgCacheEntry* currentEntry = cacheEntry( file, size, fill, outline, outlineWidth, widthScaleFactor, rasterScaleFactor );
QgsSvgCacheEntry* currentEntry = cacheEntry( file, size, fill, outline, outlineWidth, widthScaleFactor );

//if current entry image is 0: cache image for entry
// checks to see if image will fit into cache
Expand Down Expand Up @@ -155,11 +153,11 @@ QImage QgsSvgCache::svgAsImage( const QString& file, double size, const QColor&
}

QPicture QgsSvgCache::svgAsPicture( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor, bool forceVectorOutput )
double widthScaleFactor, bool forceVectorOutput )
{
QMutexLocker locker( &mMutex );

QgsSvgCacheEntry* currentEntry = cacheEntry( file, size, fill, outline, outlineWidth, widthScaleFactor, rasterScaleFactor );
QgsSvgCacheEntry* currentEntry = cacheEntry( file, size, fill, outline, outlineWidth, widthScaleFactor );

//if current entry picture is 0: cache picture for entry
//update stats for memory usage
Expand All @@ -173,31 +171,31 @@ QPicture QgsSvgCache::svgAsPicture( const QString& file, double size, const QCol
}

QByteArray QgsSvgCache::svgContent( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor )
double widthScaleFactor )
{
QMutexLocker locker( &mMutex );

QgsSvgCacheEntry *currentEntry = cacheEntry( file, size, fill, outline, outlineWidth, widthScaleFactor, rasterScaleFactor );
QgsSvgCacheEntry *currentEntry = cacheEntry( file, size, fill, outline, outlineWidth, widthScaleFactor );

return currentEntry->svgContent;
}

QSizeF QgsSvgCache::svgViewboxSize( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth, double widthScaleFactor, double rasterScaleFactor )
QSizeF QgsSvgCache::svgViewboxSize( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth, double widthScaleFactor )
{
QMutexLocker locker( &mMutex );

QgsSvgCacheEntry *currentEntry = cacheEntry( file, size, fill, outline, outlineWidth, widthScaleFactor, rasterScaleFactor );
QgsSvgCacheEntry *currentEntry = cacheEntry( file, size, fill, outline, outlineWidth, widthScaleFactor );

return currentEntry->viewboxSize;
}

QgsSvgCacheEntry* QgsSvgCache::insertSVG( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor )
double widthScaleFactor )
{
// The file may be relative path (e.g. if path is data defined)
QString path = QgsSymbolLayerUtils::symbolNameToPath( file );

QgsSvgCacheEntry* entry = new QgsSvgCacheEntry( path, size, outlineWidth, widthScaleFactor, rasterScaleFactor, fill, outline, file );
QgsSvgCacheEntry* entry = new QgsSvgCacheEntry( path, size, outlineWidth, widthScaleFactor, fill, outline, file );

replaceParamsAndCacheSvg( entry );

Expand Down Expand Up @@ -564,7 +562,7 @@ void QgsSvgCache::cachePicture( QgsSvgCacheEntry *entry, bool forceVectorOutput
}

QgsSvgCacheEntry* QgsSvgCache::cacheEntry( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor )
double widthScaleFactor )
{
//search entries in mEntryLookup
QgsSvgCacheEntry* currentEntry = nullptr;
Expand All @@ -575,8 +573,7 @@ QgsSvgCacheEntry* QgsSvgCache::cacheEntry( const QString& file, double size, con
{
QgsSvgCacheEntry* cacheEntry = *entryIt;
if ( qgsDoubleNear( cacheEntry->size, size ) && cacheEntry->fill == fill && cacheEntry->outline == outline &&
qgsDoubleNear( cacheEntry->outlineWidth, outlineWidth ) && qgsDoubleNear( cacheEntry->widthScaleFactor, widthScaleFactor )
&& qgsDoubleNear( cacheEntry->rasterScaleFactor, rasterScaleFactor ) )
qgsDoubleNear( cacheEntry->outlineWidth, outlineWidth ) && qgsDoubleNear( cacheEntry->widthScaleFactor, widthScaleFactor ) )
{
currentEntry = cacheEntry;
break;
Expand All @@ -587,7 +584,7 @@ QgsSvgCacheEntry* QgsSvgCache::cacheEntry( const QString& file, double size, con
//cache and replace params in svg content
if ( !currentEntry )
{
currentEntry = insertSVG( file, size, fill, outline, outlineWidth, widthScaleFactor, rasterScaleFactor );
currentEntry = insertSVG( file, size, fill, outline, outlineWidth, widthScaleFactor );
}
else
{
Expand Down Expand Up @@ -895,7 +892,6 @@ void QgsSvgCache::printEntryList()
QgsDebugMsg( "File:" + entry->file );
QgsDebugMsg( "Size:" + QString::number( entry->size ) );
QgsDebugMsg( "Width scale factor" + QString::number( entry->widthScaleFactor ) );
QgsDebugMsg( "Raster scale factor" + QString::number( entry->rasterScaleFactor ) );
entry = entry->nextEntry;
}
}
Expand Down

0 comments on commit 3274e19

Please sign in to comment.