Skip to content

Commit d357bc5

Browse files
committed
Correctly handle when either min or max map layer scale visibility
is set to 0 0 is intrepreted as "no limit"
1 parent eec595b commit d357bc5

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎src/core/qgsmaplayer.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,9 @@ void QgsMapLayer::connectNotify( const char *signal )
873873

874874
bool QgsMapLayer::isInScaleRange( double scale ) const
875875
{
876-
return !mScaleBasedVisibility || ( mMinScale * Qgis::SCALE_PRECISION < scale && scale < mMaxScale );
876+
return !mScaleBasedVisibility ||
877+
( ( mMinScale == 0 || mMinScale * Qgis::SCALE_PRECISION < scale )
878+
&& ( mMaxScale == 0 || scale < mMaxScale ) );
877879
}
878880

879881
bool QgsMapLayer::hasScaleBasedVisibility() const

‎tests/src/core/testqgsmaplayer.cpp‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class TestQgsMapLayer : public QObject
6969

7070
void isInScaleRange_data();
7171
void isInScaleRange();
72+
void isInScaleRange2();
7273

7374
void layerRef();
7475
void layerRefListUtils();
@@ -155,7 +156,27 @@ void TestQgsMapLayer::isInScaleRange()
155156
//always in scale range if scale based visibility is false
156157
mpLayer->setScaleBasedVisibility( false );
157158
QCOMPARE( mpLayer->isInScaleRange( scale ), true );
159+
}
160+
161+
void TestQgsMapLayer::isInScaleRange2()
162+
{
163+
mpLayer->setMinimumScale( 5000.0 );
164+
mpLayer->setMaximumScale( 0.0 );
165+
mpLayer->setScaleBasedVisibility( true );
166+
QVERIFY( !mpLayer->isInScaleRange( 1000 ) );
167+
QVERIFY( !mpLayer->isInScaleRange( 1 ) );
168+
QVERIFY( !mpLayer->isInScaleRange( 4999 ) );
169+
QVERIFY( mpLayer->isInScaleRange( 5001 ) );
170+
QVERIFY( mpLayer->isInScaleRange( 15000 ) );
158171

172+
mpLayer->setMinimumScale( 0.0 );
173+
mpLayer->setMaximumScale( 5000.0 );
174+
mpLayer->setScaleBasedVisibility( true );
175+
QVERIFY( mpLayer->isInScaleRange( 1000 ) );
176+
QVERIFY( mpLayer->isInScaleRange( 1 ) );
177+
QVERIFY( mpLayer->isInScaleRange( 4999 ) );
178+
QVERIFY( !mpLayer->isInScaleRange( 5001 ) );
179+
QVERIFY( !mpLayer->isInScaleRange( 15000 ) );
159180
}
160181

161182
void TestQgsMapLayer::layerRef()

0 commit comments

Comments
 (0)