Skip to content
Permalink
Browse files

Correctly handle when either min or max map layer scale visibility

is set to 0

0 is intrepreted as "no limit"
  • Loading branch information
nyalldawson committed Jun 2, 2017
1 parent eec595b commit d357bc5a36f1e2cdbffe88cde0857570d5d9e748
Showing with 24 additions and 1 deletion.
  1. +3 −1 src/core/qgsmaplayer.cpp
  2. +21 −0 tests/src/core/testqgsmaplayer.cpp
@@ -873,7 +873,9 @@ void QgsMapLayer::connectNotify( const char *signal )

bool QgsMapLayer::isInScaleRange( double scale ) const
{
return !mScaleBasedVisibility || ( mMinScale * Qgis::SCALE_PRECISION < scale && scale < mMaxScale );
return !mScaleBasedVisibility ||
( ( mMinScale == 0 || mMinScale * Qgis::SCALE_PRECISION < scale )
&& ( mMaxScale == 0 || scale < mMaxScale ) );
}

bool QgsMapLayer::hasScaleBasedVisibility() const
@@ -69,6 +69,7 @@ class TestQgsMapLayer : public QObject

void isInScaleRange_data();
void isInScaleRange();
void isInScaleRange2();

void layerRef();
void layerRefListUtils();
@@ -155,7 +156,27 @@ void TestQgsMapLayer::isInScaleRange()
//always in scale range if scale based visibility is false
mpLayer->setScaleBasedVisibility( false );
QCOMPARE( mpLayer->isInScaleRange( scale ), true );
}

void TestQgsMapLayer::isInScaleRange2()
{
mpLayer->setMinimumScale( 5000.0 );
mpLayer->setMaximumScale( 0.0 );
mpLayer->setScaleBasedVisibility( true );
QVERIFY( !mpLayer->isInScaleRange( 1000 ) );
QVERIFY( !mpLayer->isInScaleRange( 1 ) );
QVERIFY( !mpLayer->isInScaleRange( 4999 ) );
QVERIFY( mpLayer->isInScaleRange( 5001 ) );
QVERIFY( mpLayer->isInScaleRange( 15000 ) );

mpLayer->setMinimumScale( 0.0 );
mpLayer->setMaximumScale( 5000.0 );
mpLayer->setScaleBasedVisibility( true );
QVERIFY( mpLayer->isInScaleRange( 1000 ) );
QVERIFY( mpLayer->isInScaleRange( 1 ) );
QVERIFY( mpLayer->isInScaleRange( 4999 ) );
QVERIFY( !mpLayer->isInScaleRange( 5001 ) );
QVERIFY( !mpLayer->isInScaleRange( 15000 ) );
}

void TestQgsMapLayer::layerRef()

0 comments on commit d357bc5

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