Skip to content
Permalink
Browse files

Flip remaining scale API from real to denominators

  • Loading branch information
nyalldawson committed Jun 8, 2017
1 parent 463e722 commit b07726592c1142826185e40572f4986d352209d7
@@ -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}
@@ -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}
--------------------
@@ -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
@@ -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

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

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

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

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

0 comments on commit b077265

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