Skip to content

Commit

Permalink
Remove rasterScaleFactor/setRasterScaleFactor from QgsRenderContext
Browse files Browse the repository at this point in the history
These were not being used by QGIS code (always left at default 1.0
value), and removing them from the api allows us to simplify lots
of code. It also makes QgsRenderContext scaling much less confusing.
  • Loading branch information
nyalldawson committed Jan 16, 2017
1 parent 4941121 commit 430af90
Show file tree
Hide file tree
Showing 21 changed files with 79 additions and 135 deletions.
1 change: 1 addition & 0 deletions doc/api_break.dox
Expand Up @@ -1532,6 +1532,7 @@ 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.

QgsRendererRangeLabelFormat {#qgis_api_break_3_0_QgsRendererRangeLabelFormat}
---------------------------
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
3 changes: 0 additions & 3 deletions python/core/qgsrendercontext.sip
Expand Up @@ -75,8 +75,6 @@ class QgsRenderContext

double scaleFactor() const;

double rasterScaleFactor() const;

bool renderingStopped() const;

bool forceVectorOutput() const;
Expand Down Expand Up @@ -119,7 +117,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
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/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, 1.0, 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
5 changes: 0 additions & 5 deletions src/core/qgsrendercontext.cpp
Expand Up @@ -28,7 +28,6 @@ QgsRenderContext::QgsRenderContext()
, mPainter( nullptr )
, mRenderingStopped( false )
, mScaleFactor( 1.0 )
, mRasterScaleFactor( 1.0 )
, mRendererScale( 1.0 )
, mLabelingEngine( nullptr )
, mGeometry( nullptr )
Expand All @@ -47,7 +46,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,7 +67,6 @@ 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;
Expand All @@ -92,7 +89,6 @@ 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 +139,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
6 changes: 0 additions & 6 deletions src/core/qgsrendercontext.h
Expand Up @@ -117,8 +117,6 @@ class CORE_EXPORT QgsRenderContext

double scaleFactor() const {return mScaleFactor;}

double rasterScaleFactor() const {return mRasterScaleFactor;}

bool renderingStopped() const {return mRenderingStopped;}

bool forceVectorOutput() const;
Expand Down Expand Up @@ -160,7 +158,6 @@ class CORE_EXPORT QgsRenderContext

void setRenderingStopped( bool stopped ) {mRenderingStopped = stopped;}
void setScaleFactor( double factor ) {mScaleFactor = factor;}
void setRasterScaleFactor( double factor ) {mRasterScaleFactor = factor;}
void setRendererScale( double scale ) {mRendererScale = scale;}
void setPainter( QPainter* p ) {mPainter = p;}

Expand Down Expand Up @@ -262,9 +259,6 @@ class CORE_EXPORT QgsRenderContext
//! Factor to scale line widths and point marker sizes
double mScaleFactor;

//! Factor to scale rasters
double mRasterScaleFactor;

//! Map scale
double mRendererScale;

Expand Down

0 comments on commit 430af90

Please sign in to comment.