Skip to content

Commit a9a7d3c

Browse files
committedJun 3, 2017
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.
1 parent 0f2a49d commit a9a7d3c

19 files changed

+144
-109
lines changed
 

‎doc/api_break.dox

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,9 @@ screenUpdateRequested() were removed. These members have had no effect for a num
15151515
- readXml() and writeXml() expect QgsReadWriteContext reference as the last argument
15161516
- the invalidTransformInput() slot was removed - calling this slot had no effect
15171517
- metadata() was renamed to htmlMetadata()
1518+
- 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
1519+
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,
1520+
or most zoomed out) at which the layer will appear. The same is true for the maximumScale and minimumScale getters.
15181521

15191522

15201523
QgsMapLayerActionRegistry {#qgis_api_break_3_0_QgsMapLayerActionRegistry}

‎python/core/qgsmaplayer.sip

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -772,9 +772,12 @@ Return pointer to layer's undo stack
772772

773773
double minimumScale() const;
774774
%Docstring
775-
Returns the minimum scale denominator at which the layer is visible.
776-
Scale based visibility is only used if hasScaleBasedVisibility is true.
777-
:return: minimum scale denominator at which the layer will render
775+
Returns the minimum map scale (i.e. most "zoomed out" scale) at which the layer will be visible.
776+
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
777+
A scale of 0 indicates no minimum scale visibility.
778+
.. note::
779+
780+
Scale based visibility is only used if setScaleBasedVisibility() is set to true.
778781
.. seealso:: setMinimumScale()
779782
.. seealso:: maximumScale()
780783
.. seealso:: hasScaleBasedVisibility()
@@ -784,9 +787,12 @@ Return pointer to layer's undo stack
784787

785788
double maximumScale() const;
786789
%Docstring
787-
Returns the maximum scale denominator at which the layer is visible.
788-
Scale based visibility is only used if hasScaleBasedVisibility is true.
789-
:return: minimum scale denominator at which the layer will render
790+
Returns the maximum map scale (i.e. most "zoomed in" scale) at which the layer will be visible.
791+
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
792+
A scale of 0 indicates no maximum scale visibility.
793+
.. note::
794+
795+
Scale based visibility is only used if setScaleBasedVisibility() is set to true.
790796
.. seealso:: setMaximumScale()
791797
.. seealso:: minimumScale()
792798
.. seealso:: hasScaleBasedVisibility()
@@ -889,22 +895,28 @@ Time stamp of data source in the moment when data/metadata were loaded by provid
889895

890896
void setMinimumScale( double scale );
891897
%Docstring
892-
Sets the minimum scale denominator at which the layer will be visible.
893-
Scale based visibility is only used if setScaleBasedVisibility is set to true.
894-
\param scale minimum scale denominator at which the layer should render
895-
.. seealso:: minimumScale
896-
.. seealso:: setMaximumScale
897-
.. seealso:: setScaleBasedVisibility
898+
Sets the minimum map ``scale`` (i.e. most "zoomed out" scale) at which the layer will be visible.
899+
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
900+
A ``scale`` of 0 indicates no minimum scale visibility.
901+
.. note::
902+
903+
Scale based visibility is only used if setScaleBasedVisibility() is set to true.
904+
.. seealso:: minimumScale()
905+
.. seealso:: setMaximumScale()
906+
.. seealso:: setScaleBasedVisibility()
898907
%End
899908

900909
void setMaximumScale( double scale );
901910
%Docstring
902-
Sets the maximum scale denominator at which the layer will be visible.
903-
Scale based visibility is only used if setScaleBasedVisibility is set to true.
904-
\param scale maximum scale denominator at which the layer should render
905-
.. seealso:: maximumScale
906-
.. seealso:: setMinimumScale
907-
.. seealso:: setScaleBasedVisibility
911+
Sets the maximum map ``scale`` (i.e. most "zoomed in" scale) at which the layer will be visible.
912+
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
913+
A ``scale`` of 0 indicates no maximum scale visibility.
914+
.. note::
915+
916+
Scale based visibility is only used if setScaleBasedVisibility() is set to true.
917+
.. seealso:: maximumScale()
918+
.. seealso:: setMinimumScale()
919+
.. seealso:: setScaleBasedVisibility()
908920
%End
909921

910922
void setScaleBasedVisibility( const bool enabled );

‎src/app/qgisapp.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8979,17 +8979,17 @@ void QgisApp::setLayerScaleVisibility()
89798979
if ( layer )
89808980
{
89818981
dlg->setScaleVisiblity( layer->hasScaleBasedVisibility() );
8982-
dlg->setMinimumScale( 1.0 / layer->maximumScale() );
8983-
dlg->setMaximumScale( 1.0 / layer->minimumScale() );
8982+
dlg->setMinimumScale( 1.0 / layer->minimumScale() );
8983+
dlg->setMaximumScale( 1.0 / layer->maximumScale() );
89848984
}
89858985
if ( dlg->exec() )
89868986
{
89878987
freezeCanvases();
89888988
Q_FOREACH ( QgsMapLayer *layer, layers )
89898989
{
89908990
layer->setScaleBasedVisibility( dlg->hasScaleVisibility() );
8991-
layer->setMinimumScale( 1.0 / dlg->maximumScale() );
8992-
layer->setMaximumScale( 1.0 / dlg->minimumScale() );
8991+
layer->setMaximumScale( 1.0 / dlg->maximumScale() );
8992+
layer->setMinimumScale( 1.0 / dlg->minimumScale() );
89938993
}
89948994
freezeCanvases( false );
89958995
refreshMapCanvas();
@@ -9011,13 +9011,13 @@ void QgisApp::zoomToLayerScale()
90119011
if ( layer && layer->hasScaleBasedVisibility() )
90129012
{
90139013
const double scale = mMapCanvas->scale();
9014-
if ( scale > layer->maximumScale() )
9014+
if ( scale > layer->minimumScale() )
90159015
{
9016-
mMapCanvas->zoomScale( layer->maximumScale() * Qgis::SCALE_PRECISION );
9016+
mMapCanvas->zoomScale( layer->minimumScale() * Qgis::SCALE_PRECISION );
90179017
}
9018-
else if ( scale <= layer->minimumScale() )
9018+
else if ( scale <= layer->maximumScale() )
90199019
{
9020-
mMapCanvas->zoomScale( layer->minimumScale() );
9020+
mMapCanvas->zoomScale( layer->maximumScale() );
90219021
}
90229022
}
90239023
}

‎src/app/qgsdiagramproperties.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
205205
mIncreaseMinimumSizeLabel->setEnabled( false );
206206
mBarWidthSpinBox->setValue( 5 );
207207
mScaleVisibilityGroupBox->setChecked( layer->hasScaleBasedVisibility() );
208-
mScaleRangeWidget->setScaleRange( 1.0 / layer->maximumScale(), 1.0 / layer->minimumScale() ); // caution: layer uses scale denoms, widget uses true scales
208+
mScaleRangeWidget->setScaleRange( 1.0 / layer->minimumScale(), 1.0 / layer->maximumScale() ); // caution: layer uses scale denoms, widget uses true scales
209209
mShowAllCheckBox->setChecked( true );
210210
mCheckBoxAttributeLegend->setChecked( true );
211211
mCheckBoxSizeLegend->setChecked( false );
@@ -266,8 +266,8 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
266266
mPenWidthSpinBox->setValue( settingList.at( 0 ).penWidth );
267267
mDiagramSizeSpinBox->setValue( ( size.width() + size.height() ) / 2.0 );
268268
// caution: layer uses scale denoms, widget uses true scales
269-
mScaleRangeWidget->setScaleRange( 1.0 / ( settingList.at( 0 ).maxScaleDenominator > 0 ? settingList.at( 0 ).maxScaleDenominator : layer->maximumScale() ),
270-
1.0 / ( settingList.at( 0 ).minScaleDenominator > 0 ? settingList.at( 0 ).minScaleDenominator : layer->minimumScale() ) );
269+
mScaleRangeWidget->setScaleRange( 1.0 / ( settingList.at( 0 ).maxScaleDenominator > 0 ? settingList.at( 0 ).maxScaleDenominator : layer->minimumScale() ),
270+
1.0 / ( settingList.at( 0 ).minScaleDenominator > 0 ? settingList.at( 0 ).minScaleDenominator : layer->maximumScale() ) );
271271
mScaleVisibilityGroupBox->setChecked( settingList.at( 0 ).scaleBasedVisibility );
272272
mDiagramUnitComboBox->setUnit( settingList.at( 0 ).sizeType );
273273
mDiagramUnitComboBox->setMapUnitScale( settingList.at( 0 ).sizeScale );

‎src/app/qgsrasterlayerproperties.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
141141
// set up the scale based layer visibility stuff....
142142
mScaleRangeWidget->setMapCanvas( mMapCanvas );
143143
chkUseScaleDependentRendering->setChecked( lyr->hasScaleBasedVisibility() );
144-
mScaleRangeWidget->setScaleRange( 1.0 / lyr->maximumScale(), 1.0 / lyr->minimumScale() ); // caution: layer uses scale denoms, widget uses true scales
144+
mScaleRangeWidget->setScaleRange( 1.0 / lyr->minimumScale(), 1.0 / lyr->maximumScale() ); // caution: layer uses scale denoms, widget uses true scales
145145

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

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

917917
mRasterLayer->setAutoRefreshInterval( mRefreshLayerIntervalSpinBox->value() * 1000.0 );
918918
mRasterLayer->setAutoRefreshEnabled( mRefreshLayerCheckBox->isChecked() );

‎src/app/qgsvectorlayerproperties.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ void QgsVectorLayerProperties::syncToLayer()
411411
mDisplayExpressionWidget->setField( mLayer->displayExpression() );
412412

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

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

516516
// provider-specific options
517517
if ( mLayer->dataProvider() )

‎src/core/expression/qgsexpressionfunction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3361,9 +3361,9 @@ static QVariant fcnGetLayerProperty( const QVariantList &values, const QgsExpres
33613361
else if ( QString::compare( layerProperty, QStringLiteral( "source" ), Qt::CaseInsensitive ) == 0 )
33623362
return layer->publicSource();
33633363
else if ( QString::compare( layerProperty, QStringLiteral( "min_scale" ), Qt::CaseInsensitive ) == 0 )
3364-
return layer->minimumScale();
3365-
else if ( QString::compare( layerProperty, QStringLiteral( "max_scale" ), Qt::CaseInsensitive ) == 0 )
33663364
return layer->maximumScale();
3365+
else if ( QString::compare( layerProperty, QStringLiteral( "max_scale" ), Qt::CaseInsensitive ) == 0 )
3366+
return layer->minimumScale();
33673367
else if ( QString::compare( layerProperty, QStringLiteral( "crs" ), Qt::CaseInsensitive ) == 0 )
33683368
return layer->crs().authid();
33693369
else if ( QString::compare( layerProperty, QStringLiteral( "crs_definition" ), Qt::CaseInsensitive ) == 0 )

‎src/core/qgsmaplayer.cpp

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ void QgsMapLayer::clone( QgsMapLayer *layer ) const
106106
layer->setName( name() );
107107
layer->setShortName( shortName() );
108108
layer->setExtent( extent() );
109-
layer->setMinimumScale( minimumScale() );
110109
layer->setMaximumScale( maximumScale() );
110+
layer->setMinimumScale( minimumScale() );
111111
layer->setScaleBasedVisibility( hasScaleBasedVisibility() );
112112
layer->setTitle( title() );
113113
layer->setAbstract( abstract() );
@@ -460,8 +460,17 @@ bool QgsMapLayer::readLayerXml( const QDomElement &layerElement, const QgsReadWr
460460

461461
// use scale dependent visibility flag
462462
setScaleBasedVisibility( layerElement.attribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ) ).toInt() == 1 );
463-
setMinimumScale( layerElement.attribute( QStringLiteral( "minimumScale" ) ).toDouble() );
464-
setMaximumScale( layerElement.attribute( QStringLiteral( "maximumScale" ) ).toDouble() );
463+
if ( layerElement.hasAttribute( QStringLiteral( "minimumScale" ) ) )
464+
{
465+
// older element, when scales were reversed
466+
setMaximumScale( layerElement.attribute( QStringLiteral( "minimumScale" ) ).toDouble() );
467+
setMinimumScale( layerElement.attribute( QStringLiteral( "maximumScale" ) ).toDouble() );
468+
}
469+
else
470+
{
471+
setMaximumScale( layerElement.attribute( QStringLiteral( "maxScale" ) ).toDouble() );
472+
setMinimumScale( layerElement.attribute( QStringLiteral( "minScale" ) ).toDouble() );
473+
}
465474

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

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

925-
void QgsMapLayer::setMinimumScale( double scale )
934+
void QgsMapLayer::setMaximumScale( double scale )
926935
{
927936
mMinScale = scale;
928937
}
929938

930-
double QgsMapLayer::minimumScale() const
939+
double QgsMapLayer::maximumScale() const
931940
{
932941
return mMinScale;
933942
}
934943

935944

936-
void QgsMapLayer::setMaximumScale( double scale )
945+
void QgsMapLayer::setMinimumScale( double scale )
937946
{
938947
mMaxScale = scale;
939948
}
@@ -943,7 +952,7 @@ void QgsMapLayer::setScaleBasedVisibility( const bool enabled )
943952
mScaleBasedVisibility = enabled;
944953
}
945954

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

11921201
// use scale dependent visibility flag
11931202
setScaleBasedVisibility( myRoot.attribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ) ).toInt() == 1 );
1194-
setMinimumScale( myRoot.attribute( QStringLiteral( "minimumScale" ) ).toDouble() );
1195-
setMaximumScale( myRoot.attribute( QStringLiteral( "maximumScale" ) ).toDouble() );
1203+
if ( myRoot.hasAttribute( QStringLiteral( "minimumScale" ) ) )
1204+
{
1205+
//older scale element, when min/max were reversed
1206+
setMaximumScale( myRoot.attribute( QStringLiteral( "minimumScale" ) ).toDouble() );
1207+
setMinimumScale( myRoot.attribute( QStringLiteral( "maximumScale" ) ).toDouble() );
1208+
}
1209+
else
1210+
{
1211+
setMaximumScale( myRoot.attribute( QStringLiteral( "maxScale" ) ).toDouble() );
1212+
setMinimumScale( myRoot.attribute( QStringLiteral( "minScale" ) ).toDouble() );
1213+
}
11961214

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

12101228
myRootNode.setAttribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ), hasScaleBasedVisibility() ? 1 : 0 );
1211-
myRootNode.setAttribute( QStringLiteral( "minimumScale" ), QString::number( minimumScale() ) );
1212-
myRootNode.setAttribute( QStringLiteral( "maximumScale" ), QString::number( maximumScale() ) );
1229+
myRootNode.setAttribute( QStringLiteral( "maxScale" ), QString::number( maximumScale() ) );
1230+
myRootNode.setAttribute( QStringLiteral( "mincale" ), QString::number( minimumScale() ) );
12131231

12141232
if ( !writeSymbology( myRootNode, myDocument, errorMsg, QgsReadWriteContext() ) ) // TODO: support relative paths in QML?
12151233
{

‎src/core/qgsmaplayer.h

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -689,19 +689,23 @@ class CORE_EXPORT QgsMapLayer : public QObject
689689
*/
690690
bool isInScaleRange( double scale ) const;
691691

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

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

793797
public slots:
794798

795-
/** Sets the minimum scale denominator at which the layer will be visible.
796-
* Scale based visibility is only used if setScaleBasedVisibility is set to true.
797-
* \param scale minimum scale denominator at which the layer should render
798-
* \see minimumScale
799-
* \see setMaximumScale
800-
* \see setScaleBasedVisibility
799+
/**
800+
* Sets the minimum map \a scale (i.e. most "zoomed out" scale) at which the layer will be visible.
801+
* The \a scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
802+
* A \a scale of 0 indicates no minimum scale visibility.
803+
* \note Scale based visibility is only used if setScaleBasedVisibility() is set to true.
804+
* \see minimumScale()
805+
* \see setMaximumScale()
806+
* \see setScaleBasedVisibility()
801807
*/
802808
void setMinimumScale( double scale );
803809

804-
/** Sets the maximum scale denominator at which the layer will be visible.
805-
* Scale based visibility is only used if setScaleBasedVisibility is set to true.
806-
* \param scale maximum scale denominator at which the layer should render
807-
* \see maximumScale
808-
* \see setMinimumScale
809-
* \see setScaleBasedVisibility
810+
/**
811+
* Sets the maximum map \a scale (i.e. most "zoomed in" scale) at which the layer will be visible.
812+
* The \a scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
813+
* A \a scale of 0 indicates no maximum scale visibility.
814+
* \note Scale based visibility is only used if setScaleBasedVisibility() is set to true.
815+
* \see maximumScale()
816+
* \see setMinimumScale()
817+
* \see setScaleBasedVisibility()
810818
*/
811819
void setMaximumScale( double scale );
812820

‎src/core/qgsvectorlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2209,7 +2209,7 @@ bool QgsVectorLayer::writeSld( QDomNode &node, QDomDocument &doc, QString &error
22092209
QgsStringMap localProps = QgsStringMap( props );
22102210
if ( hasScaleBasedVisibility() )
22112211
{
2212-
QgsSymbolLayerUtils::mergeScaleDependencies( minimumScale(), maximumScale(), localProps );
2212+
QgsSymbolLayerUtils::mergeScaleDependencies( maximumScale(), minimumScale(), localProps );
22132213
}
22142214

22152215
if ( hasGeometryType() )

‎src/server/qgswmsconfigparser.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -588,12 +588,9 @@ void QgsWmsConfigParser::setLayerIdsToLegendModel( QgsLegendModel *model, const
588588
else
589589
{
590590
QgsMapLayer *layer = nodeLayer->layer();
591-
if ( layer->hasScaleBasedVisibility() )
591+
if ( !layer->isInScaleRange( scale ) )
592592
{
593-
if ( layer->minimumScale() > scale )
594-
qobject_cast<QgsLayerTreeGroup *>( nodeLayer->parent() )->removeChildNode( nodeLayer );
595-
else if ( layer->maximumScale() < scale )
596-
qobject_cast<QgsLayerTreeGroup *>( nodeLayer->parent() )->removeChildNode( nodeLayer );
593+
qobject_cast<QgsLayerTreeGroup *>( nodeLayer->parent() )->removeChildNode( nodeLayer );
597594
}
598595
}
599596
}

‎src/server/qgswmsprojectparser.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,19 +1324,19 @@ void QgsWmsProjectParser::addLayers( QDomDocument &doc,
13241324
double SCALE_TO_SCALEHINT = OGC_PX_M * sqrt( 2.0 );
13251325

13261326
QDomElement scaleHintElem = doc.createElement( QStringLiteral( "ScaleHint" ) );
1327-
scaleHintElem.setAttribute( QStringLiteral( "min" ), QString::number( currentLayer->minimumScale() * SCALE_TO_SCALEHINT ) );
1328-
scaleHintElem.setAttribute( QStringLiteral( "max" ), QString::number( currentLayer->maximumScale() * SCALE_TO_SCALEHINT ) );
1327+
scaleHintElem.setAttribute( QStringLiteral( "min" ), QString::number( currentLayer->maximumScale() * SCALE_TO_SCALEHINT ) );
1328+
scaleHintElem.setAttribute( QStringLiteral( "max" ), QString::number( currentLayer->minimumScale() * SCALE_TO_SCALEHINT ) );
13291329
layerElem.appendChild( scaleHintElem );
13301330
}
13311331
else
13321332
{
1333-
QString minScaleString = QString::number( currentLayer->minimumScale() );
1333+
QString minScaleString = QString::number( currentLayer->maximumScale() );
13341334
QDomElement minScaleElem = doc.createElement( QStringLiteral( "MinScaleDenominator" ) );
13351335
QDomText minScaleText = doc.createTextNode( minScaleString );
13361336
minScaleElem.appendChild( minScaleText );
13371337
layerElem.appendChild( minScaleElem );
13381338

1339-
QString maxScaleString = QString::number( currentLayer->maximumScale() );
1339+
QString maxScaleString = QString::number( currentLayer->minimumScale() );
13401340
QDomElement maxScaleElem = doc.createElement( QStringLiteral( "MaxScaleDenominator" ) );
13411341
QDomText maxScaleText = doc.createTextNode( maxScaleString );
13421342
maxScaleElem.appendChild( maxScaleText );
@@ -1638,8 +1638,8 @@ void QgsWmsProjectParser::addOWSLayers( QDomDocument &doc,
16381638
//min/max scale denominatormScaleBasedVisibility
16391639
if ( currentLayer->hasScaleBasedVisibility() )
16401640
{
1641-
QString minScaleString = QString::number( currentLayer->minimumScale() );
1642-
QString maxScaleString = QString::number( currentLayer->maximumScale() );
1641+
QString minScaleString = QString::number( currentLayer->maximumScale() );
1642+
QString maxScaleString = QString::number( currentLayer->minimumScale() );
16431643
QDomElement minScaleElem = doc.createElement( QStringLiteral( "sld:MinScaleDenominator" ) );
16441644
QDomText minScaleText = doc.createTextNode( minScaleString );
16451645
minScaleElem.appendChild( minScaleText );

‎src/server/services/wms/qgswmsgetcapabilities.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,19 +1002,19 @@ namespace QgsWms
10021002
double SCALE_TO_SCALEHINT = OGC_PX_M * sqrt( 2.0 );
10031003

10041004
QDomElement scaleHintElem = doc.createElement( QStringLiteral( "ScaleHint" ) );
1005-
scaleHintElem.setAttribute( QStringLiteral( "min" ), QString::number( l->minimumScale() * SCALE_TO_SCALEHINT ) );
1006-
scaleHintElem.setAttribute( QStringLiteral( "max" ), QString::number( l->maximumScale() * SCALE_TO_SCALEHINT ) );
1005+
scaleHintElem.setAttribute( QStringLiteral( "min" ), QString::number( l->maximumScale() * SCALE_TO_SCALEHINT ) );
1006+
scaleHintElem.setAttribute( QStringLiteral( "max" ), QString::number( l->minimumScale() * SCALE_TO_SCALEHINT ) );
10071007
layerElem.appendChild( scaleHintElem );
10081008
}
10091009
else
10101010
{
1011-
QString minScaleString = QString::number( l->minimumScale() );
1011+
QString minScaleString = QString::number( l->maximumScale() );
10121012
QDomElement minScaleElem = doc.createElement( QStringLiteral( "MinScaleDenominator" ) );
10131013
QDomText minScaleText = doc.createTextNode( minScaleString );
10141014
minScaleElem.appendChild( minScaleText );
10151015
layerElem.appendChild( minScaleElem );
10161016

1017-
QString maxScaleString = QString::number( l->maximumScale() );
1017+
QString maxScaleString = QString::number( l->minimumScale() );
10181018
QDomElement maxScaleElem = doc.createElement( QStringLiteral( "MaxScaleDenominator" ) );
10191019
QDomText maxScaleText = doc.createTextNode( maxScaleString );
10201020
maxScaleElem.appendChild( maxScaleText );

‎src/server/services/wms/qgswmsgetcontext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ namespace QgsWms
338338
//min/max scale denominatorScaleBasedVisibility
339339
if ( l->hasScaleBasedVisibility() )
340340
{
341-
QString minScaleString = QString::number( l->minimumScale() );
342-
QString maxScaleString = QString::number( l->maximumScale() );
341+
QString minScaleString = QString::number( l->maximumScale() );
342+
QString maxScaleString = QString::number( l->minimumScale() );
343343
QDomElement minScaleElem = doc.createElement( QStringLiteral( "sld:MinScaleDenominator" ) );
344344
QDomText minScaleText = doc.createTextNode( minScaleString );
345345
minScaleElem.appendChild( minScaleText );

‎src/server/services/wms/qgswmsrenderer.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,8 +1104,7 @@ namespace QgsWms
11041104
#endif
11051105

11061106
//skip layer if not visible at current map scale
1107-
bool useScaleConstraint = ( scaleDenominator > 0 && currentLayer->hasScaleBasedVisibility() );
1108-
if ( useScaleConstraint && ( currentLayer->minimumScale() > scaleDenominator || currentLayer->maximumScale() < scaleDenominator ) )
1107+
if ( scaleDenominator > 0 && !currentLayer->isInScaleRange( scaleDenominator ) )
11091108
{
11101109
continue;
11111110
}
@@ -1886,9 +1885,7 @@ namespace QgsWms
18861885
lName = mapLayer->shortName();
18871886
QgsMessageLog::logMessage( QStringLiteral( "Checking layer: %1" ).arg( lName ) );
18881887
//test if layer is visible in requested scale
1889-
bool useScaleConstraint = ( scaleDenominator > 0 && mapLayer->hasScaleBasedVisibility() );
1890-
if ( !useScaleConstraint ||
1891-
( mapLayer->minimumScale() <= scaleDenominator && mapLayer->maximumScale() >= scaleDenominator ) )
1888+
if ( scaleDenominator == 0 || mapLayer->isInScaleRange( scaleDenominator ) )
18921889
{
18931890
layerKeys.push_front( mapLayer->id() );
18941891
QgsProject::instance()->addMapLayers(

‎tests/src/core/testqgsexpression.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ class TestQgsExpression: public QObject
9393
mPointsLayer->setDataUrl( QStringLiteral( "data url" ) );
9494
mPointsLayer->setAttribution( QStringLiteral( "layer attribution" ) );
9595
mPointsLayer->setAttributionUrl( QStringLiteral( "attribution url" ) );
96-
mPointsLayer->setMaximumScale( 500 );
97-
mPointsLayer->setMinimumScale( 1000 );
96+
mPointsLayer->setMinimumScale( 500 );
97+
mPointsLayer->setMaximumScale( 1000 );
9898

9999
QString rasterFileName = testDataDir + "tenbytenraster.asc";
100100
QFileInfo rasterFileInfo( rasterFileName );
@@ -1086,8 +1086,8 @@ class TestQgsExpression: public QObject
10861086
QTest::newRow( "layer_property attribution" ) << QStringLiteral( "layer_property('%1','attribution')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->attribution() );
10871087
QTest::newRow( "layer_property attribution_url" ) << QStringLiteral( "layer_property('%1','attribution_url')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->attributionUrl() );
10881088
QTest::newRow( "layer_property source" ) << QStringLiteral( "layer_property('%1','source')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->publicSource() );
1089-
QTest::newRow( "layer_property min_scale" ) << QStringLiteral( "layer_property('%1','min_scale')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->minimumScale() );
1090-
QTest::newRow( "layer_property max_scale" ) << QStringLiteral( "layer_property('%1','max_scale')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->maximumScale() );
1089+
QTest::newRow( "layer_property min_scale" ) << QStringLiteral( "layer_property('%1','min_scale')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->maximumScale() );
1090+
QTest::newRow( "layer_property max_scale" ) << QStringLiteral( "layer_property('%1','max_scale')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->minimumScale() );
10911091
QTest::newRow( "layer_property crs" ) << QStringLiteral( "layer_property('%1','crs')" ).arg( mPointsLayer->name() ) << false << QVariant( "EPSG:4326" );
10921092
QTest::newRow( "layer_property extent" ) << QStringLiteral( "geom_to_wkt(layer_property('%1','extent'))" ).arg( mPointsLayer->name() ) << false << QVariant( "Polygon ((-118.88888889 22.80020704, -83.33333333 22.80020704, -83.33333333 46.87198068, -118.88888889 46.87198068, -118.88888889 22.80020704))" );
10931093
QTest::newRow( "layer_property type" ) << QStringLiteral( "layer_property('%1','type')" ).arg( mPointsLayer->name() ) << false << QVariant( "Vector" );

‎tests/src/core/testqgsmaplayer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ void TestQgsMapLayer::isInScaleRange()
149149
QFETCH( double, scale );
150150
QFETCH( bool, isInScale );
151151

152-
mpLayer->setMinimumScale( 2500.0 );
153-
mpLayer->setMaximumScale( 5000.0 );
152+
mpLayer->setMaximumScale( 2500.0 );
153+
mpLayer->setMinimumScale( 5000.0 );
154154
mpLayer->setScaleBasedVisibility( true );
155155
QCOMPARE( mpLayer->isInScaleRange( scale ), isInScale );
156156
//always in scale range if scale based visibility is false
@@ -160,17 +160,17 @@ void TestQgsMapLayer::isInScaleRange()
160160

161161
void TestQgsMapLayer::isInScaleRange2()
162162
{
163-
mpLayer->setMinimumScale( 5000.0 );
164-
mpLayer->setMaximumScale( 0.0 );
163+
mpLayer->setMaximumScale( 5000.0 );
164+
mpLayer->setMinimumScale( 0.0 );
165165
mpLayer->setScaleBasedVisibility( true );
166166
QVERIFY( !mpLayer->isInScaleRange( 1000 ) );
167167
QVERIFY( !mpLayer->isInScaleRange( 1 ) );
168168
QVERIFY( !mpLayer->isInScaleRange( 4999 ) );
169169
QVERIFY( mpLayer->isInScaleRange( 5001 ) );
170170
QVERIFY( mpLayer->isInScaleRange( 15000 ) );
171171

172-
mpLayer->setMinimumScale( 0.0 );
173-
mpLayer->setMaximumScale( 5000.0 );
172+
mpLayer->setMaximumScale( 0.0 );
173+
mpLayer->setMinimumScale( 5000.0 );
174174
mpLayer->setScaleBasedVisibility( true );
175175
QVERIFY( mpLayer->isInScaleRange( 1000 ) );
176176
QVERIFY( mpLayer->isInScaleRange( 1 ) );

‎tests/src/python/test_qgssymbollayer_createsld.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,8 @@ def testSingleSymbolScaleDependencies(self):
417417
layer = QgsVectorLayer("Point", "addfeat", "memory")
418418
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.qml' % (unitTestDataPath(), "singleSymbol"))
419419
layer.loadNamedStyle(mFilePath)
420-
layer.setMinimumScale(1000)
421-
layer.setMaximumScale(500000)
420+
layer.setMaximumScale(1000)
421+
layer.setMinimumScale(500000)
422422
layer.setScaleBasedVisibility(True)
423423

424424
dom, root = self.layerToSld(layer)
@@ -442,8 +442,8 @@ def testCategorizedWithScaleDependencies(self):
442442
layer = QgsVectorLayer("Polygon", "addfeat", "memory")
443443
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.qml' % (unitTestDataPath(), "categorized"))
444444
layer.loadNamedStyle(mFilePath)
445-
layer.setMinimumScale(1000)
446-
layer.setMaximumScale(500000)
445+
layer.setMaximumScale(1000)
446+
layer.setMinimumScale(500000)
447447
layer.setScaleBasedVisibility(True)
448448

449449
dom, root = self.layerToSld(layer)
@@ -484,8 +484,8 @@ def testRuleBasedNoRootScaleDependencies(self):
484484

485485
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.qml' % (unitTestDataPath(), "ruleBased"))
486486
status = layer.loadNamedStyle(mFilePath) # NOQA
487-
layer.setMinimumScale(5000)
488-
layer.setMaximumScale(50000000)
487+
layer.setMaximumScale(5000)
488+
layer.setMinimumScale(50000000)
489489
layer.setScaleBasedVisibility(True)
490490

491491
dom, root = self.layerToSld(layer)

‎tests/src/python/test_qgsvectorlayer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,8 +2176,8 @@ def testClone(self):
21762176
layer.styleManager().addStyle('style1', style1)
21772177
layer.setName('MyName')
21782178
layer.setShortName('MyShortName')
2179-
layer.setMinimumScale(0.5)
2180-
layer.setMaximumScale(1.5)
2179+
layer.setMaximumScale(0.5)
2180+
layer.setMinimumScale(1.5)
21812181
layer.setScaleBasedVisibility(True)
21822182
layer.setTitle('MyTitle')
21832183
layer.setAbstract('MyAbstract')

0 commit comments

Comments
 (0)
Please sign in to comment.