Skip to content

Commit

Permalink
Use doubles instead of float for min/max layer scales
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 9, 2016
1 parent 1563193 commit 80afbed
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
8 changes: 4 additions & 4 deletions python/core/qgsmaplayer.sip
Expand Up @@ -510,7 +510,7 @@ class QgsMapLayer : QObject
* @see hasScaleBasedVisibility()
* @see isInScaleRange()
*/
float minimumScale() const;
double minimumScale() const;

/** Returns the maximum scale denominator at which the layer is visible.
* Scale based visibility is only used if hasScaleBasedVisibility is true.
Expand All @@ -520,7 +520,7 @@ class QgsMapLayer : QObject
* @see hasScaleBasedVisibility()
* @see isInScaleRange()
*/
float maximumScale() const;
double maximumScale() const;

/** Returns whether scale based visibility is enabled for the layer.
* @returns true if scale based visibility is enabled
Expand All @@ -543,7 +543,7 @@ class QgsMapLayer : QObject
* @see setMaximumScale
* @see setScaleBasedVisibility
*/
void setMinimumScale( const float theMinScale );
void setMinimumScale( double theMinScale );

/** Sets the maximum scale denominator at which the layer will be visible.
* Scale based visibility is only used if setScaleBasedVisibility is set to true.
Expand All @@ -552,7 +552,7 @@ class QgsMapLayer : QObject
* @see setMinimumScale
* @see setScaleBasedVisibility
*/
void setMaximumScale( const float theMaxScale );
void setMaximumScale( double theMaxScale );

/** Sets whether scale based visibility is enabled for the layer.
* @param enabled set to true to enable scale based visibility
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsexpression.cpp
Expand Up @@ -2716,9 +2716,9 @@ static QVariant fcnGetLayerProperty( const QVariantList& values, const QgsExpres
else if ( QString::compare( layerProperty, QString( "source" ), Qt::CaseInsensitive ) == 0 )
return layer->publicSource();
else if ( QString::compare( layerProperty, QString( "min_scale" ), Qt::CaseInsensitive ) == 0 )
return static_cast< double >( layer->minimumScale() );
return layer->minimumScale();
else if ( QString::compare( layerProperty, QString( "max_scale" ), Qt::CaseInsensitive ) == 0 )
return static_cast< double >( layer->maximumScale() );
return layer->maximumScale();
else if ( QString::compare( layerProperty, QString( "crs" ), Qt::CaseInsensitive ) == 0 )
return layer->crs().authid();
else if ( QString::compare( layerProperty, QString( "crs_definition" ), Qt::CaseInsensitive ) == 0 )
Expand Down
16 changes: 8 additions & 8 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -422,8 +422,8 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )

// use scale dependent visibility flag
setScaleBasedVisibility( layerElement.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 );
setMinimumScale( layerElement.attribute( "minimumScale" ).toFloat() );
setMaximumScale( layerElement.attribute( "maximumScale" ).toFloat() );
setMinimumScale( layerElement.attribute( "minimumScale" ).toDouble() );
setMaximumScale( layerElement.attribute( "maximumScale" ).toDouble() );

// set name
mnl = layerElement.namedItem( "layername" );
Expand Down Expand Up @@ -940,18 +940,18 @@ bool QgsMapLayer::hasScaleBasedVisibility() const
return mScaleBasedVisibility;
}

void QgsMapLayer::setMinimumScale( const float theMinScale )
void QgsMapLayer::setMinimumScale( double theMinScale )
{
mMinScale = theMinScale;
}

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


void QgsMapLayer::setMaximumScale( const float theMaxScale )
void QgsMapLayer::setMaximumScale( double theMaxScale )
{
mMaxScale = theMaxScale;
}
Expand All @@ -961,7 +961,7 @@ void QgsMapLayer::setScaleBasedVisibility( const bool enabled )
mScaleBasedVisibility = enabled;
}

float QgsMapLayer::maximumScale() const
double QgsMapLayer::maximumScale() const
{
return mMaxScale;
}
Expand Down Expand Up @@ -1209,8 +1209,8 @@ bool QgsMapLayer::importNamedStyle( QDomDocument& myDocument, QString& myErrorMe

// use scale dependent visibility flag
setScaleBasedVisibility( myRoot.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 );
setMinimumScale( myRoot.attribute( "minimumScale" ).toFloat() );
setMaximumScale( myRoot.attribute( "maximumScale" ).toFloat() );
setMinimumScale( myRoot.attribute( "minimumScale" ).toDouble() );
setMaximumScale( myRoot.attribute( "maximumScale" ).toDouble() );

#if 0
//read transparency level
Expand Down
12 changes: 6 additions & 6 deletions src/core/qgsmaplayer.h
Expand Up @@ -529,7 +529,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
* @see hasScaleBasedVisibility()
* @see isInScaleRange()
*/
float minimumScale() const;
double minimumScale() const;

/** Returns the maximum scale denominator at which the layer is visible.
* Scale based visibility is only used if hasScaleBasedVisibility is true.
Expand All @@ -539,7 +539,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
* @see hasScaleBasedVisibility()
* @see isInScaleRange()
*/
float maximumScale() const;
double maximumScale() const;

/** Returns whether scale based visibility is enabled for the layer.
* @returns true if scale based visibility is enabled
Expand All @@ -562,7 +562,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
* @see setMaximumScale
* @see setScaleBasedVisibility
*/
void setMinimumScale( const float theMinScale );
void setMinimumScale( double theMinScale );

/** Sets the maximum scale denominator at which the layer will be visible.
* Scale based visibility is only used if setScaleBasedVisibility is set to true.
Expand All @@ -571,7 +571,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
* @see setMinimumScale
* @see setScaleBasedVisibility
*/
void setMaximumScale( const float theMaxScale );
void setMaximumScale( double theMaxScale );

/** Sets whether scale based visibility is enabled for the layer.
* @param enabled set to true to enable scale based visibility
Expand Down Expand Up @@ -753,9 +753,9 @@ class CORE_EXPORT QgsMapLayer : public QObject
QString mTag;

/** Minimum scale denominator at which this layer should be displayed */
float mMinScale;
double mMinScale;
/** Maximum scale denominator at which this layer should be displayed */
float mMaxScale;
double mMaxScale;
/** A flag that tells us whether to use the above vars to restrict layer visibility */
bool mScaleBasedVisibility;

Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/testqgsexpression.cpp
Expand Up @@ -771,8 +771,8 @@ class TestQgsExpression: public QObject
QTest::newRow( "layer_property attribution" ) << QString( "layer_property('%1','attribution')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->attribution() );
QTest::newRow( "layer_property attribution_url" ) << QString( "layer_property('%1','attribution_url')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->attributionUrl() );
QTest::newRow( "layer_property source" ) << QString( "layer_property('%1','source')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->publicSource() );
QTest::newRow( "layer_property min_scale" ) << QString( "layer_property('%1','min_scale')" ).arg( mPointsLayer->name() ) << false << QVariant(( double )mPointsLayer->minimumScale() );
QTest::newRow( "layer_property max_scale" ) << QString( "layer_property('%1','max_scale')" ).arg( mPointsLayer->name() ) << false << QVariant(( double )mPointsLayer->maximumScale() );
QTest::newRow( "layer_property min_scale" ) << QString( "layer_property('%1','min_scale')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->minimumScale() );
QTest::newRow( "layer_property max_scale" ) << QString( "layer_property('%1','max_scale')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->maximumScale() );
QTest::newRow( "layer_property crs" ) << QString( "layer_property('%1','crs')" ).arg( mPointsLayer->name() ) << false << QVariant( "EPSG:4326" );
QTest::newRow( "layer_property extent" ) << QString( "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))" );
QTest::newRow( "layer_property type" ) << QString( "layer_property('%1','type')" ).arg( mPointsLayer->name() ) << false << QVariant( "Vector" );
Expand Down
20 changes: 10 additions & 10 deletions tests/src/core/testqgsmaplayer.cpp
Expand Up @@ -123,24 +123,24 @@ void TestQgsMapLayer::setBlendMode()

void TestQgsMapLayer::isInScaleRange_data()
{
QTest::addColumn<float>( "scale" );
QTest::addColumn<double>( "scale" );
QTest::addColumn<bool>( "isInScale" );

QTest::newRow( "in the middle" ) << 3000.0f << true;
QTest::newRow( "too low" ) << 1000.0f << false;
QTest::newRow( "too high" ) << 6000.0f << false;
QTest::newRow( "max is not inclusive" ) << 5000.0f << false;
QTest::newRow( "min is inclusive" ) << 2500.0f << true;
QTest::newRow( "min is inclusive even with conversion errors" ) << static_cast< float >( 1.0f / (( float )1.0 / 2500.0 ) ) << true;
QTest::newRow( "in the middle" ) << 3000.0 << true;
QTest::newRow( "too low" ) << 1000.0 << false;
QTest::newRow( "too high" ) << 6000.0 << false;
QTest::newRow( "max is not inclusive" ) << 5000.0 << false;
QTest::newRow( "min is inclusive" ) << 2500.0 << true;
QTest::newRow( "min is inclusive even with conversion errors" ) << static_cast< double >( 1.0f / (( float )1.0 / 2500.0 ) ) << true;
}

void TestQgsMapLayer::isInScaleRange()
{
QFETCH( float, scale );
QFETCH( double, scale );
QFETCH( bool, isInScale );

mpLayer->setMinimumScale( 2500.0f );
mpLayer->setMaximumScale( 5000.0f );
mpLayer->setMinimumScale( 2500.0 );
mpLayer->setMaximumScale( 5000.0 );
mpLayer->setScaleBasedVisibility( true );
QCOMPARE( mpLayer->isInScaleRange( scale ), isInScale );
//always in scale range if scale based visibility is false
Expand Down

0 comments on commit 80afbed

Please sign in to comment.