Skip to content

Commit

Permalink
Invert th meaning of min scale and max scale to be coherent with othe…
Browse files Browse the repository at this point in the history
…r qgis feature. Minimum scale is the most zoomed out scale, maximum scale the most zoomed in. Enrich the tooltip to be more explicit. Should fix issue #35786.
  • Loading branch information
obrix authored and Hugo Mercier committed Apr 29, 2020
1 parent 64caa4c commit 44fec55
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions python/core/auto_generated/qgssnappingconfig.sip.in
Expand Up @@ -285,7 +285,7 @@ Sets the tolerance

double minimumScale() const;
%Docstring
Returns the min scale
Returns the min scale (i.e. most \"zoomed out\" scale)

.. versionadded:: 3.14
%End
Expand All @@ -299,7 +299,7 @@ Sets the min scale on which snapping is enabled, 0.0 disable scale limit

double maximumScale() const;
%Docstring
Returns the max scale
Returns the max scale (i.e. most \"zoomed in\" scale)

.. versionadded:: 3.14
%End
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgssnappinglayertreemodel.cpp
Expand Up @@ -104,14 +104,14 @@ QWidget *QgsSnappingLayerDelegate::createEditor( QWidget *parent, const QStyleOp
if ( index.column() == QgsSnappingLayerTreeModel::MinScaleColumn )
{
QgsScaleWidget *minLimitSp = new QgsScaleWidget( parent );
minLimitSp->setToolTip( tr( "Min Scale" ) );
minLimitSp->setToolTip( tr( "Minimum scale from which snapping is enabled (i.e. most \"zoomed out\" scale)" ) );
return minLimitSp;
}

if ( index.column() == QgsSnappingLayerTreeModel::MaxScaleColumn )
{
QgsScaleWidget *maxLimitSp = new QgsScaleWidget( parent );
maxLimitSp->setToolTip( tr( "Max Scale" ) );
maxLimitSp->setToolTip( tr( "Maximum scale up to which snapping is enabled (i.e. most \"zoomed in\" scale)" ) );
return maxLimitSp;
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/qgssnappingwidget.cpp
Expand Up @@ -195,12 +195,12 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
connect( mToleranceSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSnappingWidget::changeTolerance );

mMinScaleWidget = new QgsScaleWidget();
mMinScaleWidget->setToolTip( tr( "Minimum scale from which snapping is enabled" ) );
mMinScaleWidget->setToolTip( tr( "Minimum scale from which snapping is enabled (i.e. most \"zoomed out\" scale)" ) );
mMinScaleWidget->setObjectName( QStringLiteral( "SnappingMinScaleSpinBox" ) );
connect( mMinScaleWidget, &QgsScaleWidget::scaleChanged, this, &QgsSnappingWidget::changeMinScale );

mMaxScaleWidget = new QgsScaleWidget();
mMaxScaleWidget->setToolTip( tr( "Maximum scale up to which snapping is enabled" ) );
mMaxScaleWidget->setToolTip( tr( "Maximum scale up to which snapping is enabled (i.e. most \"zoomed in\" scale)" ) );
mMaxScaleWidget->setObjectName( QStringLiteral( "SnappingMaxScaleSpinBox" ) );
connect( mMaxScaleWidget, &QgsScaleWidget::scaleChanged, this, &QgsSnappingWidget::changeMaxScale );

Expand Down
4 changes: 2 additions & 2 deletions src/core/qgssnappingconfig.h
Expand Up @@ -288,7 +288,7 @@ class CORE_EXPORT QgsSnappingConfig
void setTolerance( double tolerance );

/**
* Returns the min scale
* Returns the min scale (i.e. most \"zoomed out\" scale)
* \since QGIS 3.14
*/
double minimumScale() const;
Expand All @@ -300,7 +300,7 @@ class CORE_EXPORT QgsSnappingConfig
void setMinimumScale( double minScale );

/**
* Returns the max scale
* Returns the max scale (i.e. most \"zoomed in\" scale)
* \since QGIS 3.14
*/
double maximumScale() const;
Expand Down
11 changes: 7 additions & 4 deletions src/core/qgssnappingutils.cpp
Expand Up @@ -294,15 +294,18 @@ QgsPointLocator::Match QgsSnappingUtils::snapToMap( const QgsPointXY &pointMap,
QList<LayerAndAreaOfInterest> layers;
QList<LayerConfig> filteredConfigs;

bool inRangeGlobal = ( mSnappingConfig.minimumScale() <= 0.0 || mMapSettings.scale() >= mSnappingConfig.minimumScale() )
&& ( mSnappingConfig.maximumScale() <= 0.0 || mMapSettings.scale() <= mSnappingConfig.maximumScale() );
//maximum scale is the one with smallest denominator
//minimum scale is the one with highest denominator
//So : maxscale < range on which snapping is enabled < minscale
bool inRangeGlobal = ( mSnappingConfig.minimumScale() <= 0.0 || mMapSettings.scale() <= mSnappingConfig.minimumScale() )
&& ( mSnappingConfig.maximumScale() <= 0.0 || mMapSettings.scale() >= mSnappingConfig.maximumScale() );

for ( const LayerConfig &layerConfig : qgis::as_const( mLayers ) )
{
QgsSnappingConfig::IndividualLayerSettings layerSettings = mSnappingConfig.individualLayerSettings( layerConfig.layer );

bool inRangeLayer = ( layerSettings.minimumScale() <= 0.0 || mMapSettings.scale() >= layerSettings.minimumScale() )
&& ( layerSettings.maximumScale() <= 0.0 || mMapSettings.scale() <= layerSettings.maximumScale() );
bool inRangeLayer = ( layerSettings.minimumScale() <= 0.0 || mMapSettings.scale() <= layerSettings.minimumScale() )
&& ( layerSettings.maximumScale() <= 0.0 || mMapSettings.scale() >= layerSettings.maximumScale() );

//If limit to scale is disabled, snapping activated on all layer
//If no per layer config is set use the global one, otherwise use the layer config
Expand Down

0 comments on commit 44fec55

Please sign in to comment.