Skip to content

Commit b7d89a7

Browse files
committed
Consolidate all render context unit conversion to single methods
within QgsRenderContext Fix invalid conversions, update unit tests
1 parent dd187a3 commit b7d89a7

45 files changed

Lines changed: 602 additions & 762 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎doc/api_break.dox‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,11 @@ QgsSymbolLayerUtils (renamed from QgsSymbolLayerUtilsV2) {#qgis_api_break
17181718
- The signatures for wellKnownMarkerToSld() and wellKnownMarkerFromSld() were changed.
17191719
- The symbolPreviewPixmap() customContext is now the fourth parameter
17201720
- createRenderContext() was moved to QgsRenderContext::fromQPainter()
1721+
- lineWidthScaleFactor() and convertToPainterUnits() were moved to QgsRenderContext::convertToPainterUnits()
1722+
- convertToMapUnits() was moved to QgsRenderContext::convertToMapUnits()
1723+
- convertFromMapUnits() was moved to QgsRenderContext::convertFromMapUnits()
1724+
- pixelSizeScaleFactor() was removed. Use QgsRenderContext::convertToPainterUnits() instead.
1725+
- mapUnitScaleFactor() was removed. Use QgsRenderContext::convertToMapUnits() instead.
17211726

17221727

17231728
QgsSymbolSelectorWidget {#qgis_api_break_3_0_QgsSymbolSelectorWidget}

‎python/core/diagram/qgsdiagram.sip‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class QgsDiagram
6161
*
6262
* @return The converted length for rendering
6363
*/
64-
float sizePainterUnits( float l, const QgsDiagramSettings& s, const QgsRenderContext& c );
64+
double sizePainterUnits( double l, const QgsDiagramSettings& s, const QgsRenderContext& c );
6565

6666
/** Calculates a size to match the current settings and rendering context
6767
* @param s The settings that contain the font size and size type

‎python/core/qgsrendercontext.sip‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,9 @@ class QgsRenderContext
196196
void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type );
197197
/** Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)*/
198198
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const;
199+
200+
double convertToPainterUnits( double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale& scale = QgsMapUnitScale() ) const;
201+
double convertToMapUnits( double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale& scale = QgsMapUnitScale() ) const;
202+
double convertFromMapUnits( double sizeInMapUnits, QgsUnitTypes::RenderUnit outputUnit ) const;
203+
199204
};

‎python/core/qgstextrenderer.sip‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,15 +1054,6 @@ class QgsTextRenderer
10541054
*/
10551055
static int sizeToPixel( double size, const QgsRenderContext& c, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );
10561056

1057-
/** Calculates size (considering output size should be in pixel or map units, scale factors and optionally oversampling)
1058-
* @param size size to convert
1059-
* @param c rendercontext
1060-
* @param unit size units
1061-
* @param mapUnitScale a mapUnitScale clamper
1062-
* @return size that will render, as double
1063-
*/
1064-
static double scaleToPixelContext( double size, const QgsRenderContext& c, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );
1065-
10661057
/** Draws text within a rectangle using the specified settings.
10671058
* @param rect destination rectangle for text
10681059
* @param rotation text rotation

‎python/core/symbology-ng/qgssymbollayerutils.sip‎

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -380,56 +380,6 @@ class QgsSymbolLayerUtils
380380
*/
381381
static QColor parseColorWithAlpha( const QString& colorStr, bool &containsAlpha, bool strictEval = false );
382382

383-
/** Returns the line width scale factor depending on the unit and the paint device.
384-
* Consider using convertToPainterUnits() instead, as convertToPainterUnits() respects the size limits specified by the scale
385-
* parameter.
386-
* @param c render context
387-
* @param u units to convert from
388-
* @param scale map unit scale, specifying limits for the map units to convert from
389-
* @see convertToPainterUnits()
390-
*/
391-
static double lineWidthScaleFactor( const QgsRenderContext& c, QgsUnitTypes::RenderUnit u, const QgsMapUnitScale& scale = QgsMapUnitScale() );
392-
393-
/** Converts a size from the specied units to painter units. The conversion respects the limits
394-
* specified by the optional scale parameter.
395-
* @param c render context
396-
* @param size size to convert
397-
* @param unit units for specified size
398-
* @param scale map unit scale
399-
* @note added in QGIS 2.12
400-
* @see lineWidthScaleFactor()
401-
* @see convertToMapUnits()
402-
*/
403-
static double convertToPainterUnits( const QgsRenderContext&c, double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale& scale = QgsMapUnitScale() );
404-
405-
/** Converts a size from the specied units to map units. The conversion respects the limits
406-
* specified by the optional scale parameter.
407-
* @param c render context
408-
* @param size size to convert
409-
* @param unit units for specified size
410-
* @param scale map unit scale
411-
* @note added in QGIS 2.16
412-
* @see convertFromMapUnits()
413-
* @see convertToPainterUnits()
414-
*/
415-
static double convertToMapUnits( const QgsRenderContext&c, double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale& scale = QgsMapUnitScale() );
416-
417-
/** Converts a size from map units to the specied units.
418-
* @param context render context
419-
* @param sizeInMapUnits size (in map units) to convert
420-
* @param outputUnit output units
421-
* @note added in QGIS 3.0
422-
* @see convertToMapUnits()
423-
*/
424-
static double convertFromMapUnits( const QgsRenderContext& context, double sizeInMapUnits, QgsUnitTypes::RenderUnit outputUnit );
425-
426-
427-
/** Returns scale factor painter units -> pixel dimensions*/
428-
static double pixelSizeScaleFactor( const QgsRenderContext& c, QgsUnitTypes::RenderUnit u, const QgsMapUnitScale& scale = QgsMapUnitScale() );
429-
430-
/** Returns scale factor painter units -> map units*/
431-
static double mapUnitScaleFactor( const QgsRenderContext& c, QgsUnitTypes::RenderUnit u, const QgsMapUnitScale& scale = QgsMapUnitScale() );
432-
433383
/** Multiplies opacity of image pixel values with a (global) transparency value*/
434384
static void multiplyImageOpacity( QImage* image, qreal alpha );
435385

‎scripts/spell_check/spelling.dat‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6374,6 +6374,7 @@ specialise:specialize
63746374
speciallized:specialized
63756375
speciefied:specified
63766376
specifc:specific
6377+
specied:specified
63776378
specifed:specified
63786379
specificatin:specification
63796380
specificaton:specification

‎src/core/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ SET(QGIS_CORE_SRCS
164164
qgsmapsettings.cpp
165165
qgsmaptopixel.cpp
166166
qgsmaptopixelgeometrysimplifier.cpp
167+
qgsmapunitscale.cpp
167168
qgsmessagelog.cpp
168169
qgsmessageoutput.cpp
169170
qgsmimedatautils.cpp

‎src/core/diagram/qgsdiagram.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ QgsExpression *QgsDiagram::getExpression( const QString &expression, const QgsEx
5858

5959
void QgsDiagram::setPenWidth( QPen& pen, const QgsDiagramSettings& s, const QgsRenderContext& c )
6060
{
61-
pen.setWidthF( QgsSymbolLayerUtils::convertToPainterUnits( c, s.penWidth, s.lineSizeUnit, s.lineSizeScale ) );
61+
pen.setWidthF( c.convertToPainterUnits( s.penWidth, s.lineSizeUnit, s.lineSizeScale ) );
6262
}
6363

6464

6565
QSizeF QgsDiagram::sizePainterUnits( QSizeF size, const QgsDiagramSettings& s, const QgsRenderContext& c )
6666
{
67-
return QSizeF( QgsSymbolLayerUtils::convertToPainterUnits( c, size.width(), s.sizeType, s.sizeScale ), QgsSymbolLayerUtils::convertToPainterUnits( c, size.height(), s.sizeType, s.sizeScale ) );
67+
return QSizeF( c.convertToPainterUnits( size.width(), s.sizeType, s.sizeScale ), c.convertToPainterUnits( size.height(), s.sizeType, s.sizeScale ) );
6868
}
6969

70-
float QgsDiagram::sizePainterUnits( float l, const QgsDiagramSettings& s, const QgsRenderContext& c )
70+
double QgsDiagram::sizePainterUnits( double l, const QgsDiagramSettings& s, const QgsRenderContext& c )
7171
{
72-
return QgsSymbolLayerUtils::convertToPainterUnits( c, l, s.sizeType, s.sizeScale );
72+
return c.convertToPainterUnits( l, s.sizeType, s.sizeScale );
7373
}
7474

7575
QFont QgsDiagram::scaledFont( const QgsDiagramSettings& s, const QgsRenderContext& c )

‎src/core/diagram/qgsdiagram.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class CORE_EXPORT QgsDiagram
9898
*
9999
* @return The converted length for rendering
100100
*/
101-
float sizePainterUnits( float l, const QgsDiagramSettings& s, const QgsRenderContext& c );
101+
double sizePainterUnits( double l, const QgsDiagramSettings& s, const QgsRenderContext& c );
102102

103103
/** Calculates a size to match the current settings and rendering context
104104
* @param s The settings that contain the font size and size type

‎src/core/effects/qgsgloweffect.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void QgsGlowEffect::draw( QgsRenderContext &context )
7979
}
8080

8181
QgsImageOperation::DistanceTransformProperties dtProps;
82-
dtProps.spread = mSpread * QgsSymbolLayerUtils::pixelSizeScaleFactor( context, mSpreadUnit, mSpreadMapUnitScale );
82+
dtProps.spread = context.convertToPainterUnits( mSpread, mSpreadUnit, mSpreadMapUnitScale );
8383
dtProps.useMaxDistance = false;
8484
dtProps.shadeExterior = shadeExterior();
8585
dtProps.ramp = ramp;
@@ -213,7 +213,7 @@ QgsGlowEffect &QgsGlowEffect::operator=( const QgsGlowEffect & rhs )
213213
QRectF QgsGlowEffect::boundingRect( const QRectF &rect, const QgsRenderContext& context ) const
214214
{
215215
//spread size
216-
double spread = mSpread * QgsSymbolLayerUtils::pixelSizeScaleFactor( context, mSpreadUnit, mSpreadMapUnitScale );
216+
double spread = context.convertToPainterUnits( mSpread, mSpreadUnit, mSpreadMapUnitScale );
217217
//plus possible extension due to blur, with a couple of extra pixels thrown in for safety
218218
spread += mBlurLevel * 2 + 10;
219219
return rect.adjusted( -spread, -spread, spread, spread );

0 commit comments

Comments
 (0)