Skip to content

Commit

Permalink
Flip remaining scale API from real to denominators
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 8, 2017
1 parent 463e722 commit b077265
Show file tree
Hide file tree
Showing 21 changed files with 200 additions and 89 deletions.
8 changes: 8 additions & 0 deletions doc/api_break.dox
Expand Up @@ -1582,6 +1582,8 @@ QgsMapToPixel {#qgis_api_break_3_0_QgsMapToPixel}

- The constructor now uses the map center x and y, and requires both height and width in pixels and a rotation value
- setYMaximum(), setYMinimum(), setXMinimum() were removed. Use setParameters() instead
- fromScale now accepts the scale as a scale denominator, not actual scale (e.g. 2000 for 1:2000). This change
was made to make all scale based API calls uniform in behavior.


QgsMapToPixelGeometrySimplifier {#qgis_api_break_3_0_QgsMapToPixelGeometrySimplifier}
Expand All @@ -1605,6 +1607,12 @@ plugins calling this method will need to be updated.
- the default destination CRS has changed from WGS 84 to invalid CRS (i.e. undefined, no reprojection will be done).
- setMapUnits() was removed. The map units are dictated by the units for the destination CRS.

QgsMapUnitScale {#qgis_api_break_3_0_QgsMapUnitScale}
---------------

- minScale and maxScale now represent the scale as a scale denominator, not actual scale (e.g. 2000 for 1:2000). This change
was made to make all scale based API calls uniform in behavior.


QgsMarkerSymbolLayer {#qgis_api_break_3_0_QgsMarkerSymbolLayer}
--------------------
Expand Down
9 changes: 9 additions & 0 deletions python/core/qgslegendsettings.sip
Expand Up @@ -193,9 +193,18 @@ Returns style

double mapScale() const;
%Docstring
Returns the legend map scale.
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
.. seealso:: setMapScale()
:rtype: float
%End

void setMapScale( double scale );
%Docstring
Sets the legend map ``scale``.
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
.. seealso:: mapScale()
%End

int dpi() const;
%Docstring
Expand Down
4 changes: 3 additions & 1 deletion python/core/qgsmapsettings.sip
Expand Up @@ -238,9 +238,11 @@ Return the actual extent derived from requested extent that takes takes output i
Return the distance in geographical coordinates that equals to one pixel in the map
:rtype: float
%End

double scale() const;
%Docstring
Return the calculated scale of the map
Returns the calculated map scale.
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
:rtype: float
%End

Expand Down
4 changes: 2 additions & 2 deletions python/core/qgsmaptopixel.sip
Expand Up @@ -42,8 +42,8 @@ class QgsMapToPixel

static QgsMapToPixel fromScale( double scale, QgsUnitTypes::DistanceUnit mapUnits, double dpi = 96 );
%Docstring
Returns a new QgsMapToPixel created using a specified scale and distance unit.
\param scale map scale
Returns a new QgsMapToPixel created using a specified ``scale`` and distance unit.
\param scale map scale denominator, e.g. 1000.0 for a 1:1000 map.
\param dpi screen DPI
\param mapUnits map units
:return: matching QgsMapToPixel
Expand Down
8 changes: 6 additions & 2 deletions python/core/qgsmapunitscale.sip
Expand Up @@ -30,15 +30,19 @@ class QgsMapUnitScale
Constructor for 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
The scale values indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
%End

double minScale;
%Docstring
The minimum scale, or 0.0 if unset
The minimum scale, or 0.0 if unset.
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
%End

double maxScale;
%Docstring
The maximum scale, or 0.0 if unset
The maximum scale, or 0.0 if unset.
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
%End

bool minSizeMMEnabled;
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsscalecalculator.sip
Expand Up @@ -60,7 +60,7 @@ Returns current map units
Calculate the scale denominator
\param mapExtent QgsRectangle containing the current map extent
\param canvasWidth Width of the map canvas in pixel (physical) units
:return: scale denominator of current map view
:return: scale denominator of current map view, e.g. 1000.0 for a 1:1000 map.
:rtype: float
%End

Expand Down
11 changes: 11 additions & 0 deletions src/core/qgslegendsettings.h
Expand Up @@ -154,7 +154,18 @@ class CORE_EXPORT QgsLegendSettings
bool useAdvancedEffects() const { return mUseAdvancedEffects; }
void setUseAdvancedEffects( bool use ) { mUseAdvancedEffects = use; }

/**
* Returns the legend map scale.
* The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
* \see setMapScale()
*/
double mapScale() const { return mMapScale; }

/**
* Sets the legend map \a scale.
* The \a scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
* \see mapScale()
*/
void setMapScale( double scale ) { mMapScale = scale; }

int dpi() const { return mDpi; }
Expand Down
6 changes: 5 additions & 1 deletion src/core/qgsmapsettings.h
Expand Up @@ -198,7 +198,11 @@ class CORE_EXPORT QgsMapSettings
QPolygonF visiblePolygon() const;
//! Return the distance in geographical coordinates that equals to one pixel in the map
double mapUnitsPerPixel() const;
//! Return the calculated scale of the map

/**
* Returns the calculated map scale.
* The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
*/
double scale() const;

/** Sets the expression context. This context is used for all expression evaluation
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmaptopixel.cpp
Expand Up @@ -61,7 +61,7 @@ QgsMapToPixel QgsMapToPixel::fromScale( double scale, QgsUnitTypes::DistanceUnit
{
double metersPerPixel = 25.4 / dpi / 1000.0;
double mapUnitsPerPixel = metersPerPixel * QgsUnitTypes::fromUnitToUnitFactor( QgsUnitTypes::DistanceMeters, mapUnits );
return QgsMapToPixel( mapUnitsPerPixel / scale );
return QgsMapToPixel( mapUnitsPerPixel * scale );
}

QgsMapToPixel::QgsMapToPixel()
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsmaptopixel.h
Expand Up @@ -54,8 +54,8 @@ class CORE_EXPORT QgsMapToPixel
*/
QgsMapToPixel( double mapUnitsPerPixel );

/** Returns a new QgsMapToPixel created using a specified scale and distance unit.
* \param scale map scale
/** Returns a new QgsMapToPixel created using a specified \a scale and distance unit.
* \param scale map scale denominator, e.g. 1000.0 for a 1:1000 map.
* \param dpi screen DPI
* \param mapUnits map units
* \returns matching QgsMapToPixel
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsmapunitscale.cpp
Expand Up @@ -20,14 +20,14 @@
double QgsMapUnitScale::computeMapUnitsPerPixel( const QgsRenderContext &c ) const
{
double mup = c.mapToPixel().mapUnitsPerPixel();
double renderScale = c.rendererScale(); // Note: this value is 1 / scale
double renderScale = c.rendererScale();
if ( !qgsDoubleNear( minScale, 0 ) )
{
mup = qMin( mup / ( minScale * renderScale ), mup );
mup = qMin( mup / ( renderScale / minScale ), mup );
}
if ( !qgsDoubleNear( maxScale, 0 ) )
{
mup = qMax( mup / ( maxScale * renderScale ), mup );
mup = qMax( mup / ( renderScale / maxScale ), mup );
}
return mup;
}
15 changes: 12 additions & 3 deletions src/core/qgsmapunitscale.h
Expand Up @@ -37,9 +37,11 @@ class CORE_EXPORT QgsMapUnitScale
{
public:

/** Constructor for QgsMapUnitScale
/**
* Constructor for 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
* The scale values indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
*/
explicit QgsMapUnitScale( double minScale = 0.0, double maxScale = 0.0 )
: minScale( minScale )
Expand All @@ -50,9 +52,16 @@ class CORE_EXPORT QgsMapUnitScale
, maxSizeMM( 0.0 )
{}

//! The minimum scale, or 0.0 if unset
/**
* The minimum scale, or 0.0 if unset.
* The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
*/
double minScale;
//! The maximum scale, or 0.0 if unset

/**
* The maximum scale, or 0.0 if unset.
* The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
*/
double maxScale;

//! Whether the minimum size in mm should be respected
Expand Down
36 changes: 24 additions & 12 deletions src/core/qgspallabeling.cpp
Expand Up @@ -577,8 +577,10 @@ void QgsPalLayerSettings::readFromLayerCustomProperties( QgsVectorLayer *layer )
if ( layer->customProperty( QStringLiteral( "labeling/distMapUnitScale" ) ).toString().isEmpty() )
{
//fallback to older property
distMapUnitScale.minScale = layer->customProperty( QStringLiteral( "labeling/distMapUnitMinScale" ), 0.0 ).toDouble();
distMapUnitScale.maxScale = layer->customProperty( QStringLiteral( "labeling/distMapUnitMaxScale" ), 0.0 ).toDouble();
double oldMin = layer->customProperty( QStringLiteral( "labeling/distMapUnitMinScale" ), 0.0 ).toDouble();
distMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
double oldMax = layer->customProperty( QStringLiteral( "labeling/distMapUnitMaxScale" ), 0.0 ).toDouble();
distMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
}
else
{
Expand All @@ -592,8 +594,10 @@ void QgsPalLayerSettings::readFromLayerCustomProperties( QgsVectorLayer *layer )
if ( layer->customProperty( QStringLiteral( "labeling/labelOffsetMapUnitScale" ) ).toString().isEmpty() )
{
//fallback to older property
labelOffsetMapUnitScale.minScale = layer->customProperty( QStringLiteral( "labeling/labelOffsetMapUnitMinScale" ), 0.0 ).toDouble();
labelOffsetMapUnitScale.maxScale = layer->customProperty( QStringLiteral( "labeling/labelOffsetMapUnitMaxScale" ), 0.0 ).toDouble();
double oldMin = layer->customProperty( QStringLiteral( "labeling/labelOffsetMapUnitMinScale" ), 0.0 ).toDouble();
labelOffsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
double oldMax = layer->customProperty( QStringLiteral( "labeling/labelOffsetMapUnitMaxScale" ), 0.0 ).toDouble();
labelOffsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
}
else
{
Expand All @@ -620,8 +624,10 @@ void QgsPalLayerSettings::readFromLayerCustomProperties( QgsVectorLayer *layer )
if ( layer->customProperty( QStringLiteral( "labeling/repeatDistanceMapUnitScale" ) ).toString().isEmpty() )
{
//fallback to older property
repeatDistanceMapUnitScale.minScale = layer->customProperty( QStringLiteral( "labeling/repeatDistanceMapUnitMinScale" ), 0.0 ).toDouble();
repeatDistanceMapUnitScale.maxScale = layer->customProperty( QStringLiteral( "labeling/repeatDistanceMapUnitMaxScale" ), 0.0 ).toDouble();
double oldMin = layer->customProperty( QStringLiteral( "labeling/repeatDistanceMapUnitMinScale" ), 0.0 ).toDouble();
repeatDistanceMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
double oldMax = layer->customProperty( QStringLiteral( "labeling/repeatDistanceMapUnitMaxScale" ), 0.0 ).toDouble();
repeatDistanceMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
}
else
{
Expand Down Expand Up @@ -750,8 +756,10 @@ void QgsPalLayerSettings::readXml( QDomElement &elem, const QgsReadWriteContext
if ( !placementElem.hasAttribute( QStringLiteral( "distMapUnitScale" ) ) )
{
//fallback to older property
distMapUnitScale.minScale = placementElem.attribute( QStringLiteral( "distMapUnitMinScale" ), QStringLiteral( "0" ) ).toDouble();
distMapUnitScale.maxScale = placementElem.attribute( QStringLiteral( "distMapUnitMaxScale" ), QStringLiteral( "0" ) ).toDouble();
double oldMin = placementElem.attribute( QStringLiteral( "distMapUnitMinScale" ), QStringLiteral( "0" ) ).toDouble();
distMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
double oldMax = placementElem.attribute( QStringLiteral( "distMapUnitMaxScale" ), QStringLiteral( "0" ) ).toDouble();
distMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
}
else
{
Expand All @@ -765,8 +773,10 @@ void QgsPalLayerSettings::readXml( QDomElement &elem, const QgsReadWriteContext
if ( !placementElem.hasAttribute( QStringLiteral( "labelOffsetMapUnitScale" ) ) )
{
//fallback to older property
labelOffsetMapUnitScale.minScale = placementElem.attribute( QStringLiteral( "labelOffsetMapUnitMinScale" ), QStringLiteral( "0" ) ).toDouble();
labelOffsetMapUnitScale.maxScale = placementElem.attribute( QStringLiteral( "labelOffsetMapUnitMaxScale" ), QStringLiteral( "0" ) ).toDouble();
double oldMin = placementElem.attribute( QStringLiteral( "labelOffsetMapUnitMinScale" ), QStringLiteral( "0" ) ).toDouble();
labelOffsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
double oldMax = placementElem.attribute( QStringLiteral( "labelOffsetMapUnitMaxScale" ), QStringLiteral( "0" ) ).toDouble();
labelOffsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
}
else
{
Expand All @@ -792,8 +802,10 @@ void QgsPalLayerSettings::readXml( QDomElement &elem, const QgsReadWriteContext
if ( !placementElem.hasAttribute( QStringLiteral( "repeatDistanceMapUnitScale" ) ) )
{
//fallback to older property
repeatDistanceMapUnitScale.minScale = placementElem.attribute( QStringLiteral( "repeatDistanceMapUnitMinScale" ), QStringLiteral( "0" ) ).toDouble();
repeatDistanceMapUnitScale.maxScale = placementElem.attribute( QStringLiteral( "repeatDistanceMapUnitMaxScale" ), QStringLiteral( "0" ) ).toDouble();
double oldMin = placementElem.attribute( QStringLiteral( "repeatDistanceMapUnitMinScale" ), QStringLiteral( "0" ) ).toDouble();
repeatDistanceMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
double oldMax = placementElem.attribute( QStringLiteral( "repeatDistanceMapUnitMaxScale" ), QStringLiteral( "0" ) ).toDouble();
repeatDistanceMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsrendercontext.cpp
Expand Up @@ -283,7 +283,7 @@ double QgsRenderContext::convertToMapUnits( double size, QgsUnitTypes::RenderUni
}
if ( !qgsDoubleNear( scale.minScale, 0.0 ) )
{
minSizeMU = qMax( minSizeMU, size * ( scale.minScale * mRendererScale ) );
minSizeMU = qMax( minSizeMU, size * ( mRendererScale / scale.minScale ) );
}
size = qMax( size, minSizeMU );

Expand All @@ -294,7 +294,7 @@ double QgsRenderContext::convertToMapUnits( double size, QgsUnitTypes::RenderUni
}
if ( !qgsDoubleNear( scale.maxScale, 0.0 ) )
{
maxSizeMU = qMin( maxSizeMU, size * ( scale.maxScale * mRendererScale ) );
maxSizeMU = qMin( maxSizeMU, size * ( mRendererScale / scale.maxScale ) );
}
size = qMin( size, maxSizeMU );

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsscalecalculator.h
Expand Up @@ -67,7 +67,7 @@ class CORE_EXPORT QgsScaleCalculator
* Calculate the scale denominator
* \param mapExtent QgsRectangle containing the current map extent
* \param canvasWidth Width of the map canvas in pixel (physical) units
* \returns scale denominator of current map view
* \returns scale denominator of current map view, e.g. 1000.0 for a 1:1000 map.
*/
double calculate( const QgsRectangle &mapExtent, int canvasWidth );

Expand Down

0 comments on commit b077265

Please sign in to comment.