Skip to content

Commit

Permalink
Merge pull request #3995 from nyalldawson/render_context
Browse files Browse the repository at this point in the history
Remove rasterScaleFactor/setRasterScaleFactor from QgsRenderContext
  • Loading branch information
nyalldawson committed Jan 16, 2017
2 parents 4941121 + 3274e19 commit 5e459d7
Show file tree
Hide file tree
Showing 30 changed files with 182 additions and 222 deletions.
9 changes: 9 additions & 0 deletions doc/api_break.dox
Expand Up @@ -1532,6 +1532,9 @@ QgsRenderContext {#qgis_api_break_3_0_QgsRenderContext}
- coordinateTransform() now returns a QgsCoordinateTransform object, not a pointer. An invalid QgsCoordinateTransform will
be returned instead of a null pointer if no transformation is required.
- setCoordinateTransform() now takes a QgsCoordinateTransform reference, not a pointer. An invalid QgsCoordinateTransform should be used instead of a null pointer if no transformation is required.
- rasterScaleFactor() and setRasterScaleFactor() were removed. In QGIS 3.0 QPainter destinations should always be constructed so that 1 painter unit = 1 pixel.
- The constPainter() getter was removed. Const QPainters cannot be painted to or modified, so this
method was of little use.

QgsRendererRangeLabelFormat {#qgis_api_break_3_0_QgsRendererRangeLabelFormat}
---------------------------
Expand Down Expand Up @@ -1629,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
2 changes: 1 addition & 1 deletion python/core/qgsmapunitscale.sip
Expand Up @@ -18,7 +18,7 @@ class QgsMapUnitScale
* @param minScale minimum allowed scale, or 0.0 if no minimum scale set
* @param maxScale maximum allowed scale, or 0.0 if no maximum scale set
*/
QgsMapUnitScale( double minScale = 0.0, double maxScale = 0.0 );
explicit QgsMapUnitScale( double minScale = 0.0, double maxScale = 0.0 );

/** The minimum scale, or 0.0 if unset */
double minScale;
Expand Down
4 changes: 0 additions & 4 deletions python/core/qgsrendercontext.sip
Expand Up @@ -62,7 +62,6 @@ class QgsRenderContext
//getters

QPainter* painter();
const QPainter* constPainter() const;

/** Returns the current coordinate transform for the context, or an invalid
* transform is no coordinate transformation is required.
Expand All @@ -75,8 +74,6 @@ class QgsRenderContext

double scaleFactor() const;

double rasterScaleFactor() const;

bool renderingStopped() const;

bool forceVectorOutput() const;
Expand Down Expand Up @@ -119,7 +116,6 @@ class QgsRenderContext

void setRenderingStopped( bool stopped );
void setScaleFactor( double factor );
void setRasterScaleFactor( double factor );
void setRendererScale( double scale );
void setPainter( QPainter* p );

Expand Down
6 changes: 2 additions & 4 deletions python/core/qgstextrenderer.sip
Expand Up @@ -1049,21 +1049,19 @@ class QgsTextRenderer
* @param size size to convert
* @param c rendercontext
* @param unit size units
* @param rasterfactor whether to consider oversampling
* @param mapUnitScale a mapUnitScale clamper
* @return font pixel size
*/
static int sizeToPixel( double size, const QgsRenderContext& c, QgsUnitTypes::RenderUnit unit, bool rasterfactor = false, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );
static int sizeToPixel( double size, const QgsRenderContext& c, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );

/** Calculates size (considering output size should be in pixel or map units, scale factors and optionally oversampling)
* @param size size to convert
* @param c rendercontext
* @param unit size units
* @param rasterfactor whether to consider oversampling
* @param mapUnitScale a mapUnitScale clamper
* @return size that will render, as double
*/
static double scaleToPixelContext( double size, const QgsRenderContext& c, QgsUnitTypes::RenderUnit unit, bool rasterfactor = false, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );
static double scaleToPixelContext( double size, const QgsRenderContext& c, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );

/** Draws text within a rectangle using the specified settings.
* @param rect destination rectangle for text
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/app/qgsmaptoollabel.cpp
Expand Up @@ -242,7 +242,7 @@ QFont QgsMapToolLabel::currentLabelFont()
if ( sizeIndx != -1 )
{
font.setPixelSize( QgsTextRenderer::sizeToPixel( f.attribute( sizeIndx ).toDouble(),
context, labelSettings.format().sizeUnit(), true,
context, labelSettings.format().sizeUnit(),
labelSettings.format().sizeMapUnitScale() ) );
}

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/qgsmapunitscale.h
Expand Up @@ -39,7 +39,7 @@ class CORE_EXPORT QgsMapUnitScale
* @param minScale minimum allowed scale, or 0.0 if no minimum scale set
* @param maxScale maximum allowed scale, or 0.0 if no maximum scale set
*/
QgsMapUnitScale( double minScale = 0.0, double maxScale = 0.0 )
explicit QgsMapUnitScale( double minScale = 0.0, double maxScale = 0.0 )
: minScale( minScale )
, maxScale( maxScale )
, minSizeMMEnabled( false )
Expand Down
12 changes: 5 additions & 7 deletions src/core/qgspallabeling.cpp
Expand Up @@ -1409,7 +1409,6 @@ void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF* fm, QString t
double labelHeight = fm->ascent() + fm->descent(); // ignore +1 for baseline

h += fm->height() + static_cast< double >(( lines - 1 ) * labelHeight * multilineH );
h /= context->rasterScaleFactor();

for ( int i = 0; i < lines; ++i )
{
Expand All @@ -1419,7 +1418,6 @@ void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF* fm, QString t
w = width;
}
}
w /= context->rasterScaleFactor();

#if 0 // XXX strk
QgsPoint ptSize = xform->toMapCoordinatesF( w, h );
Expand Down Expand Up @@ -1567,7 +1565,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
return;
}

int fontPixelSize = QgsTextRenderer::sizeToPixel( fontSize, context, fontunits, true, mFormat.sizeMapUnitScale() );
int fontPixelSize = QgsTextRenderer::sizeToPixel( fontSize, context, fontunits, mFormat.sizeMapUnitScale() );
// don't try to show font sizes less than 1 pixel (Qt complains)
if ( fontPixelSize < 1 )
{
Expand Down Expand Up @@ -2224,7 +2222,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
double topMargin = qMax( 0.25 * labelFontMetrics->ascent(), 0.0 );
double bottomMargin = 1.0 + labelFontMetrics->descent();
QgsLabelFeature::VisualMargin vm( topMargin, 0.0, bottomMargin, 0.0 );
vm *= xform->mapUnitsPerPixel() / context.rasterScaleFactor();
vm *= xform->mapUnitsPerPixel();
( *labelFeature )->setVisualMargin( vm );

// store the label's calculated font for later use during painting
Expand All @@ -2234,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, context.rasterScaleFactor(), 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 Expand Up @@ -2706,7 +2704,7 @@ void QgsPalLayerSettings::parseTextStyle( QFont& labelFont,
wordspace = wspacing;
}
}
labelFont.setWordSpacing( QgsTextRenderer::scaleToPixelContext( wordspace, context, fontunits, false, mFormat.sizeMapUnitScale() ) );
labelFont.setWordSpacing( QgsTextRenderer::scaleToPixelContext( wordspace, context, fontunits, mFormat.sizeMapUnitScale() ) );

// data defined letter spacing?
double letterspace = labelFont.letterSpacing();
Expand All @@ -2720,7 +2718,7 @@ void QgsPalLayerSettings::parseTextStyle( QFont& labelFont,
letterspace = lspacing;
}
}
labelFont.setLetterSpacing( QFont::AbsoluteSpacing, QgsTextRenderer::scaleToPixelContext( letterspace, context, fontunits, false, mFormat.sizeMapUnitScale() ) );
labelFont.setLetterSpacing( QFont::AbsoluteSpacing, QgsTextRenderer::scaleToPixelContext( letterspace, context, fontunits, mFormat.sizeMapUnitScale() ) );

// data defined strikeout font style?
if ( dataDefinedEvaluate( QgsPalLayerSettings::Strikeout, exprVal, &context.expressionContext(), labelFont.strikeOut() ) )
Expand Down
36 changes: 11 additions & 25 deletions src/core/qgsrendercontext.cpp
Expand Up @@ -25,16 +25,6 @@

QgsRenderContext::QgsRenderContext()
: mFlags( DrawEditingInfo | UseAdvancedEffects | DrawSelection | UseRenderingOptimization )
, mPainter( nullptr )
, mRenderingStopped( false )
, mScaleFactor( 1.0 )
, mRasterScaleFactor( 1.0 )
, mRendererScale( 1.0 )
, mLabelingEngine( nullptr )
, mGeometry( nullptr )
, mFeatureFilterProvider( nullptr )
, mSegmentationTolerance( M_PI_2 / 90 )
, mSegmentationToleranceType( QgsAbstractGeometry::MaximumAngle )
{
mVectorSimplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification );
}
Expand All @@ -47,7 +37,6 @@ QgsRenderContext::QgsRenderContext( const QgsRenderContext& rh )
, mMapToPixel( rh.mMapToPixel )
, mRenderingStopped( rh.mRenderingStopped )
, mScaleFactor( rh.mScaleFactor )
, mRasterScaleFactor( rh.mRasterScaleFactor )
, mRendererScale( rh.mRendererScale )
, mLabelingEngine( rh.mLabelingEngine )
, mSelectionColor( rh.mSelectionColor )
Expand All @@ -69,30 +58,22 @@ QgsRenderContext&QgsRenderContext::operator=( const QgsRenderContext & rh )
mMapToPixel = rh.mMapToPixel;
mRenderingStopped = rh.mRenderingStopped;
mScaleFactor = rh.mScaleFactor;
mRasterScaleFactor = rh.mRasterScaleFactor;
mRendererScale = rh.mRendererScale;
mLabelingEngine = rh.mLabelingEngine;
mSelectionColor = rh.mSelectionColor;
mVectorSimplifyMethod = rh.mVectorSimplifyMethod;
mExpressionContext = rh.mExpressionContext;
mGeometry = rh.mGeometry;
mFeatureFilterProvider = rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr;
mFeatureFilterProvider.reset( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr );
mSegmentationTolerance = rh.mSegmentationTolerance;
mSegmentationToleranceType = rh.mSegmentationToleranceType;
return *this;
}

QgsRenderContext::~QgsRenderContext()
{
delete mFeatureFilterProvider;
mFeatureFilterProvider = nullptr;
}

QgsRenderContext QgsRenderContext::fromQPainter( QPainter* painter )
{
QgsRenderContext context;
context.setPainter( painter );
context.setRasterScaleFactor( 1.0 );
if ( painter && painter->device() )
{
context.setScaleFactor( painter->device()->logicalDpiX() / 25.4 );
Expand Down Expand Up @@ -143,7 +124,6 @@ QgsRenderContext QgsRenderContext::fromMapSettings( const QgsMapSettings& mapSet
ctx.setFlag( RenderMapTile, mapSettings.testFlag( QgsMapSettings::RenderMapTile ) );
ctx.setFlag( Antialiasing, mapSettings.testFlag( QgsMapSettings::Antialiasing ) );
ctx.setFlag( RenderPartialOutput, mapSettings.testFlag( QgsMapSettings::RenderPartialOutput ) );
ctx.setRasterScaleFactor( 1.0 );
ctx.setScaleFactor( mapSettings.outputDpi() / 25.4 ); // = pixels per mm
ctx.setRendererScale( mapSettings.scale() );
ctx.setExpressionContext( mapSettings.expressionContext() );
Expand Down Expand Up @@ -214,11 +194,17 @@ void QgsRenderContext::setUseRenderingOptimization( bool enabled )

void QgsRenderContext::setFeatureFilterProvider( const QgsFeatureFilterProvider* ffp )
{
delete mFeatureFilterProvider;
mFeatureFilterProvider = nullptr;

if ( ffp )
{
mFeatureFilterProvider = ffp->clone();
mFeatureFilterProvider.reset( ffp->clone() );
}
else
{
mFeatureFilterProvider.reset( nullptr );
}
}

const QgsFeatureFilterProvider* QgsRenderContext::featureFilterProvider() const
{
return mFeatureFilterProvider.data();
}

0 comments on commit 5e459d7

Please sign in to comment.