Skip to content
Permalink
Browse files

Remove rasterScaleFactor/setRasterScaleFactor from QgsRenderContext

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 430af90cfa1f94d5bc82f705573423a7e047f0b1
@@ -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}
---------------------------
@@ -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;
@@ -75,8 +75,6 @@ class QgsRenderContext

double scaleFactor() const;

double rasterScaleFactor() const;

bool renderingStopped() const;

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

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

@@ -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 )
@@ -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 )
{
@@ -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 );
@@ -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 )
{
@@ -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
@@ -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...?
@@ -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();
@@ -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() ) )
@@ -28,7 +28,6 @@ QgsRenderContext::QgsRenderContext()
, mPainter( nullptr )
, mRenderingStopped( false )
, mScaleFactor( 1.0 )
, mRasterScaleFactor( 1.0 )
, mRendererScale( 1.0 )
, mLabelingEngine( nullptr )
, mGeometry( nullptr )
@@ -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 )
@@ -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;
@@ -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 );
@@ -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() );
@@ -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;
@@ -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;}

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

0 comments on commit 430af90

Please sign in to comment.
You can’t perform that action at this time.