Remove more unused raster scale factor handling

This commit is contained in:
Nyall Dawson 2017-01-16 16:01:52 +10:00
parent 48797fa9b7
commit 3274e1926f
13 changed files with 50 additions and 57 deletions

View File

@ -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}
----------------------------------

View File

@ -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
@ -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
@ -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
@ -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.
@ -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*/
@ -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 */
@ -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();

View File

@ -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 ) );
}

View File

@ -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();

View File

@ -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() )
{

View File

@ -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...?

View File

@ -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;
@ -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)
@ -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;
}
}

View File

@ -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; }

View File

@ -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 )
{

View File

@ -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
@ -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 )
{
@ -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
@ -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;

View File

@ -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 )
@ -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 )
@ -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
@ -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
@ -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
@ -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 );
@ -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;
@ -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;
@ -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
{
@ -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;
}
}

View File

@ -46,12 +46,11 @@ class CORE_EXPORT QgsSvgCacheEntry
* @param size
* @param outlineWidth width of outline
* @param widthScaleFactor width scale factor
* @param rasterScaleFactor raster scale factor
* @param fill color of fill
* @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();
//! QgsSvgCacheEntry cannot be copied.
@ -66,7 +65,6 @@ class CORE_EXPORT 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
@ -119,11 +117,10 @@ class CORE_EXPORT QgsSvgCache : public QObject
* @param outline color of outline
* @param outlineWidth width of outline
* @param widthScaleFactor width scale factor
* @param rasterScaleFactor raster scale factor
* @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.
@ -132,11 +129,10 @@ class CORE_EXPORT QgsSvgCache : public QObject
* @param outline color of outline
* @param outlineWidth width of outline
* @param widthScaleFactor width scale factor
* @param rasterScaleFactor raster scale factor
* @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.
@ -145,12 +141,11 @@ class CORE_EXPORT QgsSvgCache : public QObject
* @param outline color of outline
* @param outlineWidth width of outline
* @param widthScaleFactor width scale factor
* @param rasterScaleFactor raster scale factor
* @returns viewbox size set in SVG file
* @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*/
@ -189,7 +184,7 @@ class CORE_EXPORT QgsSvgCache : public 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
@ -205,17 +200,16 @@ class CORE_EXPORT QgsSvgCache : public QObject
* @param outline color of outline
* @param outlineWidth width of outline
* @param widthScaleFactor width scale factor
* @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();

View File

@ -259,7 +259,7 @@ QPixmap QgsSvgSelectorListModel::createPreview( const QString& entry ) const
outlineWidth = 0.2;
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( entry, 30.0, fill, outline, outlineWidth, 3.5 /*appr. 88 dpi*/, 1.0, fitsInCache );
const QImage& img = QgsApplication::svgCache()->svgAsImage( entry, 30.0, fill, outline, outlineWidth, 3.5 /*appr. 88 dpi*/, fitsInCache );
return QPixmap::fromImage( img );
}