Skip to content
Permalink
Browse files

Swap QgsMapLayer min/max scale API definitions

setMaximumScale() and setMinimumScale(), maximumScale() and
minimumScale() had the opposite meaning to other min/max scales
in the API, and were the opposite to how these settings were
exposed in the GUI. This lead to very confusing API!!

Their definitions have now been swapped. setMaximumScale
now sets the maximum (i.e. largest scale, or most zoomed in)
at which the layer will appear, and setMinimumScale now sets
the minimum (i.e. smallest scale, or most zoomed out) at
which the layer will appear. The same is true for the
maximumScale and minimumScale getters.
  • Loading branch information
nyalldawson committed Jun 3, 2017
1 parent 0f2a49d commit a9a7d3c3d9cc471589c50e0656b5eda4a9c8d7bd
@@ -1515,6 +1515,9 @@ screenUpdateRequested() were removed. These members have had no effect for a num
- readXml() and writeXml() expect QgsReadWriteContext reference as the last argument
- the invalidTransformInput() slot was removed - calling this slot had no effect
- metadata() was renamed to htmlMetadata()
- setMaximumScale() and setMinimumScale(), maximumScale() and minimumScale() had the opposite meaning to other min/max scales in the API, and their definitions have now been swapped. setMaximumScale
now sets the maximum (i.e. largest scale, or most zoomed in) at which the layer will appear, and setMinimumScale now sets the minimum (i.e. smallest scale,
or most zoomed out) at which the layer will appear. The same is true for the maximumScale and minimumScale getters.


QgsMapLayerActionRegistry {#qgis_api_break_3_0_QgsMapLayerActionRegistry}
@@ -772,9 +772,12 @@ Return pointer to layer's undo stack

double minimumScale() const;
%Docstring
Returns the minimum scale denominator at which the layer is visible.
Scale based visibility is only used if hasScaleBasedVisibility is true.
:return: minimum scale denominator at which the layer will render
Returns the minimum map scale (i.e. most "zoomed out" scale) at which the layer will be visible.
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
A scale of 0 indicates no minimum scale visibility.
.. note::

Scale based visibility is only used if setScaleBasedVisibility() is set to true.
.. seealso:: setMinimumScale()
.. seealso:: maximumScale()
.. seealso:: hasScaleBasedVisibility()
@@ -784,9 +787,12 @@ Return pointer to layer's undo stack

double maximumScale() const;
%Docstring
Returns the maximum scale denominator at which the layer is visible.
Scale based visibility is only used if hasScaleBasedVisibility is true.
:return: minimum scale denominator at which the layer will render
Returns the maximum map scale (i.e. most "zoomed in" scale) at which the layer will be visible.
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
A scale of 0 indicates no maximum scale visibility.
.. note::

Scale based visibility is only used if setScaleBasedVisibility() is set to true.
.. seealso:: setMaximumScale()
.. seealso:: minimumScale()
.. seealso:: hasScaleBasedVisibility()
@@ -889,22 +895,28 @@ Time stamp of data source in the moment when data/metadata were loaded by provid

void setMinimumScale( double scale );
%Docstring
Sets the minimum scale denominator at which the layer will be visible.
Scale based visibility is only used if setScaleBasedVisibility is set to true.
\param scale minimum scale denominator at which the layer should render
.. seealso:: minimumScale
.. seealso:: setMaximumScale
.. seealso:: setScaleBasedVisibility
Sets the minimum map ``scale`` (i.e. most "zoomed out" scale) at which the layer will be visible.
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
A ``scale`` of 0 indicates no minimum scale visibility.
.. note::

Scale based visibility is only used if setScaleBasedVisibility() is set to true.
.. seealso:: minimumScale()
.. seealso:: setMaximumScale()
.. seealso:: setScaleBasedVisibility()
%End

void setMaximumScale( double scale );
%Docstring
Sets the maximum scale denominator at which the layer will be visible.
Scale based visibility is only used if setScaleBasedVisibility is set to true.
\param scale maximum scale denominator at which the layer should render
.. seealso:: maximumScale
.. seealso:: setMinimumScale
.. seealso:: setScaleBasedVisibility
Sets the maximum map ``scale`` (i.e. most "zoomed in" scale) at which the layer will be visible.
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
A ``scale`` of 0 indicates no maximum scale visibility.
.. note::

Scale based visibility is only used if setScaleBasedVisibility() is set to true.
.. seealso:: maximumScale()
.. seealso:: setMinimumScale()
.. seealso:: setScaleBasedVisibility()
%End

void setScaleBasedVisibility( const bool enabled );
@@ -8979,17 +8979,17 @@ void QgisApp::setLayerScaleVisibility()
if ( layer )
{
dlg->setScaleVisiblity( layer->hasScaleBasedVisibility() );
dlg->setMinimumScale( 1.0 / layer->maximumScale() );
dlg->setMaximumScale( 1.0 / layer->minimumScale() );
dlg->setMinimumScale( 1.0 / layer->minimumScale() );
dlg->setMaximumScale( 1.0 / layer->maximumScale() );
}
if ( dlg->exec() )
{
freezeCanvases();
Q_FOREACH ( QgsMapLayer *layer, layers )
{
layer->setScaleBasedVisibility( dlg->hasScaleVisibility() );
layer->setMinimumScale( 1.0 / dlg->maximumScale() );
layer->setMaximumScale( 1.0 / dlg->minimumScale() );
layer->setMaximumScale( 1.0 / dlg->maximumScale() );
layer->setMinimumScale( 1.0 / dlg->minimumScale() );
}
freezeCanvases( false );
refreshMapCanvas();
@@ -9011,13 +9011,13 @@ void QgisApp::zoomToLayerScale()
if ( layer && layer->hasScaleBasedVisibility() )
{
const double scale = mMapCanvas->scale();
if ( scale > layer->maximumScale() )
if ( scale > layer->minimumScale() )
{
mMapCanvas->zoomScale( layer->maximumScale() * Qgis::SCALE_PRECISION );
mMapCanvas->zoomScale( layer->minimumScale() * Qgis::SCALE_PRECISION );
}
else if ( scale <= layer->minimumScale() )
else if ( scale <= layer->maximumScale() )
{
mMapCanvas->zoomScale( layer->minimumScale() );
mMapCanvas->zoomScale( layer->maximumScale() );
}
}
}
@@ -205,7 +205,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
mIncreaseMinimumSizeLabel->setEnabled( false );
mBarWidthSpinBox->setValue( 5 );
mScaleVisibilityGroupBox->setChecked( layer->hasScaleBasedVisibility() );
mScaleRangeWidget->setScaleRange( 1.0 / layer->maximumScale(), 1.0 / layer->minimumScale() ); // caution: layer uses scale denoms, widget uses true scales
mScaleRangeWidget->setScaleRange( 1.0 / layer->minimumScale(), 1.0 / layer->maximumScale() ); // caution: layer uses scale denoms, widget uses true scales
mShowAllCheckBox->setChecked( true );
mCheckBoxAttributeLegend->setChecked( true );
mCheckBoxSizeLegend->setChecked( false );
@@ -266,8 +266,8 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
mPenWidthSpinBox->setValue( settingList.at( 0 ).penWidth );
mDiagramSizeSpinBox->setValue( ( size.width() + size.height() ) / 2.0 );
// caution: layer uses scale denoms, widget uses true scales
mScaleRangeWidget->setScaleRange( 1.0 / ( settingList.at( 0 ).maxScaleDenominator > 0 ? settingList.at( 0 ).maxScaleDenominator : layer->maximumScale() ),
1.0 / ( settingList.at( 0 ).minScaleDenominator > 0 ? settingList.at( 0 ).minScaleDenominator : layer->minimumScale() ) );
mScaleRangeWidget->setScaleRange( 1.0 / ( settingList.at( 0 ).maxScaleDenominator > 0 ? settingList.at( 0 ).maxScaleDenominator : layer->minimumScale() ),
1.0 / ( settingList.at( 0 ).minScaleDenominator > 0 ? settingList.at( 0 ).minScaleDenominator : layer->maximumScale() ) );
mScaleVisibilityGroupBox->setChecked( settingList.at( 0 ).scaleBasedVisibility );
mDiagramUnitComboBox->setUnit( settingList.at( 0 ).sizeType );
mDiagramUnitComboBox->setMapUnitScale( settingList.at( 0 ).sizeScale );
@@ -141,7 +141,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
// set up the scale based layer visibility stuff....
mScaleRangeWidget->setMapCanvas( mMapCanvas );
chkUseScaleDependentRendering->setChecked( lyr->hasScaleBasedVisibility() );
mScaleRangeWidget->setScaleRange( 1.0 / lyr->maximumScale(), 1.0 / lyr->minimumScale() ); // caution: layer uses scale denoms, widget uses true scales
mScaleRangeWidget->setScaleRange( 1.0 / lyr->minimumScale(), 1.0 / lyr->maximumScale() ); // caution: layer uses scale denoms, widget uses true scales

leNoDataValue->setValidator( new QDoubleValidator( -std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), 1000, this ) );

@@ -911,8 +911,8 @@ void QgsRasterLayerProperties::apply()
// set up the scale based layer visibility stuff....
mRasterLayer->setScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
// caution: layer uses scale denoms, widget uses true scales
mRasterLayer->setMaximumScale( 1.0 / mScaleRangeWidget->minimumScale() );
mRasterLayer->setMinimumScale( 1.0 / mScaleRangeWidget->maximumScale() );
mRasterLayer->setMinimumScale( 1.0 / mScaleRangeWidget->minimumScale() );
mRasterLayer->setMaximumScale( 1.0 / mScaleRangeWidget->maximumScale() );

mRasterLayer->setAutoRefreshInterval( mRefreshLayerIntervalSpinBox->value() * 1000.0 );
mRasterLayer->setAutoRefreshEnabled( mRefreshLayerCheckBox->isChecked() );
@@ -411,7 +411,7 @@ void QgsVectorLayerProperties::syncToLayer()
mDisplayExpressionWidget->setField( mLayer->displayExpression() );

// set up the scale based layer visibility stuff....
mScaleRangeWidget->setScaleRange( 1.0 / mLayer->maximumScale(), 1.0 / mLayer->minimumScale() ); // caution: layer uses scale denoms, widget uses true scales
mScaleRangeWidget->setScaleRange( 1.0 / mLayer->minimumScale(), 1.0 / mLayer->maximumScale() ); // caution: layer uses scale denoms, widget uses true scales
mScaleVisibilityGroupBox->setChecked( mLayer->hasScaleBasedVisibility() );
mScaleRangeWidget->setMapCanvas( QgisApp::instance()->mapCanvas() );

@@ -510,8 +510,8 @@ void QgsVectorLayerProperties::apply()
// set up the scale based layer visibility stuff....
mLayer->setScaleBasedVisibility( mScaleVisibilityGroupBox->isChecked() );
// caution: layer uses scale denoms, widget uses true scales
mLayer->setMaximumScale( mScaleRangeWidget->maximumScaleDenom() );
mLayer->setMinimumScale( mScaleRangeWidget->minimumScaleDenom() );
mLayer->setMinimumScale( mScaleRangeWidget->maximumScaleDenom() );
mLayer->setMaximumScale( mScaleRangeWidget->minimumScaleDenom() );

// provider-specific options
if ( mLayer->dataProvider() )
@@ -3361,9 +3361,9 @@ static QVariant fcnGetLayerProperty( const QVariantList &values, const QgsExpres
else if ( QString::compare( layerProperty, QStringLiteral( "source" ), Qt::CaseInsensitive ) == 0 )
return layer->publicSource();
else if ( QString::compare( layerProperty, QStringLiteral( "min_scale" ), Qt::CaseInsensitive ) == 0 )
return layer->minimumScale();
else if ( QString::compare( layerProperty, QStringLiteral( "max_scale" ), Qt::CaseInsensitive ) == 0 )
return layer->maximumScale();
else if ( QString::compare( layerProperty, QStringLiteral( "max_scale" ), Qt::CaseInsensitive ) == 0 )
return layer->minimumScale();
else if ( QString::compare( layerProperty, QStringLiteral( "crs" ), Qt::CaseInsensitive ) == 0 )
return layer->crs().authid();
else if ( QString::compare( layerProperty, QStringLiteral( "crs_definition" ), Qt::CaseInsensitive ) == 0 )
@@ -106,8 +106,8 @@ void QgsMapLayer::clone( QgsMapLayer *layer ) const
layer->setName( name() );
layer->setShortName( shortName() );
layer->setExtent( extent() );
layer->setMinimumScale( minimumScale() );
layer->setMaximumScale( maximumScale() );
layer->setMinimumScale( minimumScale() );
layer->setScaleBasedVisibility( hasScaleBasedVisibility() );
layer->setTitle( title() );
layer->setAbstract( abstract() );
@@ -460,8 +460,17 @@ bool QgsMapLayer::readLayerXml( const QDomElement &layerElement, const QgsReadWr

// use scale dependent visibility flag
setScaleBasedVisibility( layerElement.attribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ) ).toInt() == 1 );
setMinimumScale( layerElement.attribute( QStringLiteral( "minimumScale" ) ).toDouble() );
setMaximumScale( layerElement.attribute( QStringLiteral( "maximumScale" ) ).toDouble() );
if ( layerElement.hasAttribute( QStringLiteral( "minimumScale" ) ) )
{
// older element, when scales were reversed
setMaximumScale( layerElement.attribute( QStringLiteral( "minimumScale" ) ).toDouble() );
setMinimumScale( layerElement.attribute( QStringLiteral( "maximumScale" ) ).toDouble() );
}
else
{
setMaximumScale( layerElement.attribute( QStringLiteral( "maxScale" ) ).toDouble() );
setMinimumScale( layerElement.attribute( QStringLiteral( "minScale" ) ).toDouble() );
}

setAutoRefreshInterval( layerElement.attribute( QStringLiteral( "autoRefreshTime" ), 0 ).toInt() );
setAutoRefreshEnabled( layerElement.attribute( QStringLiteral( "autoRefreshEnabled" ), QStringLiteral( "0" ) ).toInt() );
@@ -564,8 +573,8 @@ bool QgsMapLayer::writeLayerXml( QDomElement &layerElement, QDomDocument &docume
{
// use scale dependent visibility flag
layerElement.setAttribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ), hasScaleBasedVisibility() ? 1 : 0 );
layerElement.setAttribute( QStringLiteral( "minimumScale" ), QString::number( minimumScale() ) );
layerElement.setAttribute( QStringLiteral( "maximumScale" ), QString::number( maximumScale() ) );
layerElement.setAttribute( QStringLiteral( "maxScale" ), QString::number( maximumScale() ) );
layerElement.setAttribute( QStringLiteral( "minScale" ), QString::number( minimumScale() ) );

if ( !mExtent.isNull() )
{
@@ -922,18 +931,18 @@ const QgsLayerMetadata &QgsMapLayer::metadata() const
return mMetadata;
}

void QgsMapLayer::setMinimumScale( double scale )
void QgsMapLayer::setMaximumScale( double scale )
{
mMinScale = scale;
}

double QgsMapLayer::minimumScale() const
double QgsMapLayer::maximumScale() const
{
return mMinScale;
}


void QgsMapLayer::setMaximumScale( double scale )
void QgsMapLayer::setMinimumScale( double scale )
{
mMaxScale = scale;
}
@@ -943,7 +952,7 @@ void QgsMapLayer::setScaleBasedVisibility( const bool enabled )
mScaleBasedVisibility = enabled;
}

double QgsMapLayer::maximumScale() const
double QgsMapLayer::minimumScale() const
{
return mMaxScale;
}
@@ -1191,8 +1200,17 @@ bool QgsMapLayer::importNamedStyle( QDomDocument &myDocument, QString &myErrorMe

// use scale dependent visibility flag
setScaleBasedVisibility( myRoot.attribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ) ).toInt() == 1 );
setMinimumScale( myRoot.attribute( QStringLiteral( "minimumScale" ) ).toDouble() );
setMaximumScale( myRoot.attribute( QStringLiteral( "maximumScale" ) ).toDouble() );
if ( myRoot.hasAttribute( QStringLiteral( "minimumScale" ) ) )
{
//older scale element, when min/max were reversed
setMaximumScale( myRoot.attribute( QStringLiteral( "minimumScale" ) ).toDouble() );
setMinimumScale( myRoot.attribute( QStringLiteral( "maximumScale" ) ).toDouble() );
}
else
{
setMaximumScale( myRoot.attribute( QStringLiteral( "maxScale" ) ).toDouble() );
setMinimumScale( myRoot.attribute( QStringLiteral( "minScale" ) ).toDouble() );
}

return readSymbology( myRoot, myErrorMessage, QgsReadWriteContext() ); // TODO: support relative paths in QML?
}
@@ -1208,8 +1226,8 @@ void QgsMapLayer::exportNamedStyle( QDomDocument &doc, QString &errorMsg ) const
myDocument.appendChild( myRootNode );

myRootNode.setAttribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ), hasScaleBasedVisibility() ? 1 : 0 );
myRootNode.setAttribute( QStringLiteral( "minimumScale" ), QString::number( minimumScale() ) );
myRootNode.setAttribute( QStringLiteral( "maximumScale" ), QString::number( maximumScale() ) );
myRootNode.setAttribute( QStringLiteral( "maxScale" ), QString::number( maximumScale() ) );
myRootNode.setAttribute( QStringLiteral( "mincale" ), QString::number( minimumScale() ) );

if ( !writeSymbology( myRootNode, myDocument, errorMsg, QgsReadWriteContext() ) ) // TODO: support relative paths in QML?
{
@@ -689,19 +689,23 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
bool isInScaleRange( double scale ) const;

/** Returns the minimum scale denominator at which the layer is visible.
* Scale based visibility is only used if hasScaleBasedVisibility is true.
* \returns minimum scale denominator at which the layer will render
/**
* Returns the minimum map scale (i.e. most "zoomed out" scale) at which the layer will be visible.
* The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
* A scale of 0 indicates no minimum scale visibility.
* \note Scale based visibility is only used if setScaleBasedVisibility() is set to true.
* \see setMinimumScale()
* \see maximumScale()
* \see hasScaleBasedVisibility()
* \see isInScaleRange()
*/
double minimumScale() const;

/** Returns the maximum scale denominator at which the layer is visible.
* Scale based visibility is only used if hasScaleBasedVisibility is true.
* \returns minimum scale denominator at which the layer will render
/**
* Returns the maximum map scale (i.e. most "zoomed in" scale) at which the layer will be visible.
* The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
* A scale of 0 indicates no maximum scale visibility.
* \note Scale based visibility is only used if setScaleBasedVisibility() is set to true.
* \see setMaximumScale()
* \see minimumScale()
* \see hasScaleBasedVisibility()
@@ -792,21 +796,25 @@ class CORE_EXPORT QgsMapLayer : public QObject

public slots:

/** Sets the minimum scale denominator at which the layer will be visible.
* Scale based visibility is only used if setScaleBasedVisibility is set to true.
* \param scale minimum scale denominator at which the layer should render
* \see minimumScale
* \see setMaximumScale
* \see setScaleBasedVisibility
/**
* Sets the minimum map \a scale (i.e. most "zoomed out" scale) at which the layer will be visible.
* The \a scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
* A \a scale of 0 indicates no minimum scale visibility.
* \note Scale based visibility is only used if setScaleBasedVisibility() is set to true.
* \see minimumScale()
* \see setMaximumScale()
* \see setScaleBasedVisibility()
*/
void setMinimumScale( double scale );

/** Sets the maximum scale denominator at which the layer will be visible.
* Scale based visibility is only used if setScaleBasedVisibility is set to true.
* \param scale maximum scale denominator at which the layer should render
* \see maximumScale
* \see setMinimumScale
* \see setScaleBasedVisibility
/**
* Sets the maximum map \a scale (i.e. most "zoomed in" scale) at which the layer will be visible.
* The \a scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
* A \a scale of 0 indicates no maximum scale visibility.
* \note Scale based visibility is only used if setScaleBasedVisibility() is set to true.
* \see maximumScale()
* \see setMinimumScale()
* \see setScaleBasedVisibility()
*/
void setMaximumScale( double scale );

@@ -2209,7 +2209,7 @@ bool QgsVectorLayer::writeSld( QDomNode &node, QDomDocument &doc, QString &error
QgsStringMap localProps = QgsStringMap( props );
if ( hasScaleBasedVisibility() )
{
QgsSymbolLayerUtils::mergeScaleDependencies( minimumScale(), maximumScale(), localProps );
QgsSymbolLayerUtils::mergeScaleDependencies( maximumScale(), minimumScale(), localProps );
}

if ( hasGeometryType() )

0 comments on commit a9a7d3c

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