Skip to content

Commit

Permalink
Fix clang warnings, scale truncation to int
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 1, 2018
1 parent 0e2ceb9 commit b5476ef
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgsrulebasedlabeling.sip.in
Expand Up @@ -35,7 +35,7 @@ class QgsRuleBasedLabeling : QgsAbstractVectorLayerLabeling
#include "qgsrulebasedlabeling.h"
%End
public:
Rule( QgsPalLayerSettings *settings /Transfer/, int maximumScale = 0, int minimumScale = 0, const QString &filterExp = QString(), const QString &description = QString(), bool elseRule = false );
Rule( QgsPalLayerSettings *settings /Transfer/, double maximumScale = 0, double minimumScale = 0, const QString &filterExp = QString(), const QString &description = QString(), bool elseRule = false );
%Docstring
takes ownership of settings, settings may be None
%End
Expand Down
Expand Up @@ -717,7 +717,7 @@ Checks if the properties contain scaleMinDenom and scaleMaxDenom, if available,
.. versionadded:: 3.0
%End

static void mergeScaleDependencies( int mScaleMinDenom, int mScaleMaxDenom, QgsStringMap &props );
static void mergeScaleDependencies( double mScaleMinDenom, double mScaleMaxDenom, QgsStringMap &props );
%Docstring
Merges the local scale limits, if any, with the ones already in the map, if any

Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsrulebasedlabeling.cpp
Expand Up @@ -54,7 +54,7 @@ QList<QgsAbstractLabelProvider *> QgsRuleBasedLabelProvider::subProviders()

////////////////////

QgsRuleBasedLabeling::Rule::Rule( QgsPalLayerSettings *settings, int scaleMinDenom, int scaleMaxDenom, const QString &filterExp, const QString &description, bool elseRule )
QgsRuleBasedLabeling::Rule::Rule( QgsPalLayerSettings *settings, double scaleMinDenom, double scaleMaxDenom, const QString &filterExp, const QString &description, bool elseRule )
: mSettings( settings )
, mMaximumScale( scaleMinDenom )
, mMinimumScale( scaleMaxDenom )
Expand Down Expand Up @@ -256,9 +256,9 @@ QDomElement QgsRuleBasedLabeling::Rule::save( QDomDocument &doc, const QgsReadWr
}
if ( !mFilterExp.isEmpty() )
ruleElem.setAttribute( QStringLiteral( "filter" ), mFilterExp );
if ( mMaximumScale != 0 )
if ( !qgsDoubleNear( mMaximumScale, 0 ) )
ruleElem.setAttribute( QStringLiteral( "scalemindenom" ), mMaximumScale );
if ( mMinimumScale != 0 )
if ( !qgsDoubleNear( mMinimumScale, 0 ) )
ruleElem.setAttribute( QStringLiteral( "scalemaxdenom" ), mMinimumScale );
if ( !mDescription.isEmpty() )
ruleElem.setAttribute( QStringLiteral( "description" ), mDescription );
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsrulebasedlabeling.h
Expand Up @@ -53,7 +53,7 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling
{
public:
//! takes ownership of settings, settings may be nullptr
Rule( QgsPalLayerSettings *settings SIP_TRANSFER, int maximumScale = 0, int minimumScale = 0, const QString &filterExp = QString(), const QString &description = QString(), bool elseRule = false );
Rule( QgsPalLayerSettings *settings SIP_TRANSFER, double maximumScale = 0, double minimumScale = 0, const QString &filterExp = QString(), const QString &description = QString(), bool elseRule = false );
~Rule();

//! Rules cannot be copied.
Expand All @@ -79,7 +79,7 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling
*
* \returns True if scale based labeling is active
*/
bool dependsOnScale() const { return mMinimumScale != 0 || mMaximumScale != 0; }
bool dependsOnScale() const { return !qgsDoubleNear( mMinimumScale, 0.0 ) || !qgsDoubleNear( mMaximumScale, 0 ); }

/**
* Returns the maximum map scale (i.e. most "zoomed in" scale) at which the label rule will be active.
Expand Down
10 changes: 5 additions & 5 deletions src/core/symbology/qgssymbollayerutils.cpp
Expand Up @@ -4201,22 +4201,22 @@ void QgsSymbolLayerUtils::applyScaleDependency( QDomDocument &doc, QDomElement &
}
}

void QgsSymbolLayerUtils::mergeScaleDependencies( int mScaleMinDenom, int mScaleMaxDenom, QgsStringMap &props )
void QgsSymbolLayerUtils::mergeScaleDependencies( double mScaleMinDenom, double mScaleMaxDenom, QgsStringMap &props )
{
if ( mScaleMinDenom != 0 )
if ( !qgsDoubleNear( mScaleMinDenom, 0 ) )
{
bool ok;
int parentScaleMinDenom = props.value( QStringLiteral( "scaleMinDenom" ), QStringLiteral( "0" ) ).toInt( &ok );
double parentScaleMinDenom = props.value( QStringLiteral( "scaleMinDenom" ), QStringLiteral( "0" ) ).toDouble( &ok );
if ( !ok || parentScaleMinDenom <= 0 )
props[ QStringLiteral( "scaleMinDenom" )] = QString::number( mScaleMinDenom );
else
props[ QStringLiteral( "scaleMinDenom" )] = QString::number( std::max( parentScaleMinDenom, mScaleMinDenom ) );
}

if ( mScaleMaxDenom != 0 )
if ( !qgsDoubleNear( mScaleMaxDenom, 0 ) )
{
bool ok;
int parentScaleMaxDenom = props.value( QStringLiteral( "scaleMaxDenom" ), QStringLiteral( "0" ) ).toInt( &ok );
double parentScaleMaxDenom = props.value( QStringLiteral( "scaleMaxDenom" ), QStringLiteral( "0" ) ).toDouble( &ok );
if ( !ok || parentScaleMaxDenom <= 0 )
props[ QStringLiteral( "scaleMaxDenom" )] = QString::number( mScaleMaxDenom );
else
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology/qgssymbollayerutils.h
Expand Up @@ -654,7 +654,7 @@ class CORE_EXPORT QgsSymbolLayerUtils
* Merges the local scale limits, if any, with the ones already in the map, if any
* \since QGIS 3.0
*/
static void mergeScaleDependencies( int mScaleMinDenom, int mScaleMaxDenom, QgsStringMap &props );
static void mergeScaleDependencies( double mScaleMinDenom, double mScaleMaxDenom, QgsStringMap &props );

/**
* Encodes a reference to a parametric SVG into SLD, as a succession of parametric SVG using URL parameters,
Expand Down

0 comments on commit b5476ef

Please sign in to comment.