diff --git a/python/core/auto_generated/qgssnappingconfig.sip.in b/python/core/auto_generated/qgssnappingconfig.sip.in index 83be1005ad2..9ff2bd0a024 100644 --- a/python/core/auto_generated/qgssnappingconfig.sip.in +++ b/python/core/auto_generated/qgssnappingconfig.sip.in @@ -73,7 +73,7 @@ This is a container of advanced configuration (per layer) of the snapping of the %End public: - IndividualLayerSettings( bool enabled, SnappingType type, double tolerance, QgsTolerance::UnitType units, double minScale, double maxScale ) /Deprecated/; + IndividualLayerSettings( bool enabled, SnappingType type, double tolerance, QgsTolerance::UnitType units ) /Deprecated/; %Docstring IndividualLayerSettings diff --git a/src/app/qgssnappinglayertreemodel.cpp b/src/app/qgssnappinglayertreemodel.cpp index a90cbab1d55..f0261a25d1e 100644 --- a/src/app/qgssnappinglayertreemodel.cpp +++ b/src/app/qgssnappinglayertreemodel.cpp @@ -278,6 +278,13 @@ Qt::ItemFlags QgsSnappingLayerTreeModel::flags( const QModelIndex &idx ) const return Qt::NoItemFlags; } } + else if( idx.column() == MaxScaleColumn || idx.column() == MinScaleColumn ) + { + if( mProject->snappingConfig().limitToScale() ) + { + return Qt::ItemIsEnabled | Qt::ItemIsEditable; + } + } else { return Qt::ItemIsEnabled | Qt::ItemIsEditable; @@ -381,7 +388,7 @@ void QgsSnappingLayerTreeModel::hasRowchanged( QgsLayerTreeNode *node, const QHa { emit dataChanged( QModelIndex(), idx ); } - if ( oldSettings.value( vl ) != mProject->snappingConfig().individualLayerSettings().value( vl ) ) + else { mIndividualLayerSettings.insert( vl, mProject->snappingConfig().individualLayerSettings().value( vl ) ); emit dataChanged( idx, index( idx.row(), columnCount( idx ) - 1 ) ); @@ -637,7 +644,7 @@ QVariant QgsSnappingLayerTreeModel::data( const QModelIndex &idx, int role ) con { if ( ls.minScale() <= 0.0 ) { - return QString( "not set" ); + return QString( tr( "not set" ) ); } else { @@ -657,7 +664,7 @@ QVariant QgsSnappingLayerTreeModel::data( const QModelIndex &idx, int role ) con { if ( ls.maxScale() <= 0.0 ) { - return QString( "not set" ); + return QString( tr( "not set" ) ); } else { diff --git a/src/app/qgssnappingwidget.cpp b/src/app/qgssnappingwidget.cpp index db4ecb9783a..d5c4fdd4dae 100644 --- a/src/app/qgssnappingwidget.cpp +++ b/src/app/qgssnappingwidget.cpp @@ -186,10 +186,10 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas, connect( mMaxScaleWidget, &QgsScaleWidget::scaleChanged, this, &QgsSnappingWidget::changeMaxScale ); - mLimitToScale = new QAction( tr( "Toggle Snapping limit on scale" ), this ); + mLimitToScale = new QAction( tr( "Toggle scale dependent snapping" ), this ); mLimitToScale->setCheckable( true ); mLimitToScale->setIcon( QIcon( QgsApplication::getThemeIcon( "/mIconSnappingOnScale.svg" ) ) ); - mLimitToScale->setObjectName( QStringLiteral( "EnableSnappinLimitOnScaleAction" ) ); + mLimitToScale->setObjectName( QStringLiteral( "EnableSnappingLimitOnScaleAction" ) ); connect( mLimitToScale, &QAction::toggled, this, &QgsSnappingWidget::changeLimitToScale ); // units @@ -472,10 +472,12 @@ void QgsSnappingWidget::toggleSnappingWidgets( bool enabled ) mMinScaleWidget->setEnabled( enabled && mConfig.limitToScale() ); mMaxScaleWidget->setEnabled( enabled && mConfig.limitToScale() ); mUnitsComboBox->setEnabled( enabled ); + if ( mEditAdvancedConfigAction ) { mEditAdvancedConfigAction->setEnabled( enabled ); } + if ( mAdvancedConfigWidget ) { mAdvancedConfigWidget->setEnabled( enabled ); diff --git a/src/core/qgssnappingconfig.cpp b/src/core/qgssnappingconfig.cpp index bfa15f8a15b..5e34edb3e3a 100644 --- a/src/core/qgssnappingconfig.cpp +++ b/src/core/qgssnappingconfig.cpp @@ -35,13 +35,11 @@ QgsSnappingConfig::IndividualLayerSettings::IndividualLayerSettings( bool enable , mMaxScale( maxScale ) {} -QgsSnappingConfig::IndividualLayerSettings::IndividualLayerSettings( bool enabled, SnappingType type, double tolerance, QgsTolerance::UnitType units, double minScale, double maxScale ) +QgsSnappingConfig::IndividualLayerSettings::IndividualLayerSettings( bool enabled, SnappingType type, double tolerance, QgsTolerance::UnitType units ) : mValid( true ) , mEnabled( enabled ) , mTolerance( tolerance ) , mUnits( units ) - , mMinScale( minScale ) - , mMaxScale( maxScale ) { Q_NOWARN_DEPRECATED_PUSH setType( type ); diff --git a/src/core/qgssnappingconfig.h b/src/core/qgssnappingconfig.h index 4f4afc6b298..a1bb8612c5f 100644 --- a/src/core/qgssnappingconfig.h +++ b/src/core/qgssnappingconfig.h @@ -120,7 +120,7 @@ class CORE_EXPORT QgsSnappingConfig * \param maxScale 0.0 disable scale limit * \deprecated since QGIS 3.12 use the method with SnappingTypeFlag instead. */ - Q_DECL_DEPRECATED IndividualLayerSettings( bool enabled, SnappingType type, double tolerance, QgsTolerance::UnitType units, double minScale, double maxScale ) SIP_DEPRECATED; + Q_DECL_DEPRECATED IndividualLayerSettings( bool enabled, SnappingType type, double tolerance, QgsTolerance::UnitType units ) SIP_DEPRECATED; /** * \brief IndividualLayerSettings @@ -172,28 +172,52 @@ class CORE_EXPORT QgsSnappingConfig */ void setTypeFlag( QgsSnappingConfig::SnappingTypeFlag type ); - //! Returns the tolerance + /**! + * Returns the tolerance + * \since QGIS 3.12 + */ double tolerance() const; - //! Sets the tolerance + /** + * Sets the tolerance + * \since QGIS 3.12 + */ void setTolerance( double tolerance ); - //! Returns the type of units + /** + * Returns the type of units + * \since QGIS 3.12 + */ QgsTolerance::UnitType units() const; - //! Sets the type of units + /** + * Sets the type of units + * \since QGIS 3.12 + */ void setUnits( QgsTolerance::UnitType units ); - //! Returns min scale on which snapping is limited + /** + * Returns min scale on which snapping is limited + * \since QGIS 3.14 + */ double minScale() const; - //! Sets the min scale value on which snapping is used, 0.0 disable scale limit + /** + * Sets the min scale value on which snapping is used, 0.0 disable scale limit + * \since QGIS 3.14 + */ void setMinScale( double p_minScale ); - //! Returns max scale on which snapping is limite + /** + * Returns max scale on which snapping is limited + * \since QGIS 3.14 + */ double maxScale() const; - //! Sets the max scale value on which snapping is used, 0.0 disable scale limit + /** + * Sets the max scale value on which snapping is used, 0.0 disable scale limit + * \since QGIS 3.14 + */ void setMaxScale( double p_maxScale ); /** @@ -265,22 +289,40 @@ class CORE_EXPORT QgsSnappingConfig //! Sets the tolerance void setTolerance( double tolerance ); - //! Returns the min scale + /** + * Returns the min scale + * \since QGIS 3.14 + */ double minScale() const; - //! Sets the min scale on which snapping is enabled, 0.0 disable scale limit + /** + * Sets the min scale on which snapping is enabled, 0.0 disable scale limit + * \since QGIS 3.14 + */ void setMinScale( double pMinScale ); - //! Returns the max scale + /** + * Returns the max scale + * \since QGIS 3.14 + */ double maxScale() const; - //! Set the max scale on which snapping is enabled, 0.0 disable scale limit + /** + * Set the max scale on which snapping is enabled, 0.0 disable scale limit + * \since QGIS 3.14 + */ void setMaxScale( double pMaxScale ); - //! Returns limit to scale + /** + * Returns limit to scale + * \since QGIS 3.14 + */ bool limitToScale() const; - //! Set limit to scale, true means snapping will be limited to the [minScale, maxScale] range + /** + * Set limit to scale, true means snapping will be limited to the [minScale, maxScale] range + * \since QGIS 3.14 + */ void setLimitToScale( bool pLimitSnapping ); //! Returns the type of units diff --git a/src/core/qgssnappingutils.cpp b/src/core/qgssnappingutils.cpp index cb61cde25ec..d283434f253 100644 --- a/src/core/qgssnappingutils.cpp +++ b/src/core/qgssnappingutils.cpp @@ -291,16 +291,14 @@ QgsPointLocator::Match QgsSnappingUtils::snapToMap( const QgsPointXY &pointMap, } else if ( mSnappingConfig.mode() == QgsSnappingConfig::AdvancedConfiguration ) { - typedef QList::const_iterator LayerConfigIterator; QList layers; - QList filteredConfigs; + QList filteredConfigs; bool inRangeGlobal = ( mSnappingConfig.minScale() <= 0.0 || mMapSettings.scale() >= mSnappingConfig.minScale() ) && ( mSnappingConfig.maxScale() <= 0.0 || mMapSettings.scale() <= mSnappingConfig.maxScale() ); - for ( LayerConfigIterator it = mLayers.begin(); it != mLayers.end(); ++it ) + for ( const LayerConfig &layerConfig : qgis::as_const( mLayers )) { - const LayerConfig &layerConfig = *it; QgsSnappingConfig::IndividualLayerSettings layerSettings = mSnappingConfig.individualLayerSettings( layerConfig.layer ); //Default value for layer config means it is not set ( appears NULL ) layerSpecificRange <- false @@ -313,7 +311,7 @@ QgsPointLocator::Match QgsSnappingUtils::snapToMap( const QgsPointXY &pointMap, { double tolerance = QgsTolerance::toleranceInProjectUnits( layerConfig.tolerance, layerConfig.layer, mMapSettings, layerConfig.unit ); layers << qMakePair( layerConfig.layer, _areaOfInterest( pointMap, tolerance ) ); - filteredConfigs << it; + filteredConfigs << layerConfig; } } prepareIndex( layers, relaxed ); @@ -322,9 +320,8 @@ QgsPointLocator::Match QgsSnappingUtils::snapToMap( const QgsPointXY &pointMap, QgsPointLocator::MatchList edges; // for snap on intersection double maxSnapIntTolerance = 0; - for ( LayerConfigIterator &it : filteredConfigs ) + for ( const LayerConfig &layerConfig : qgis::as_const( filteredConfigs ) ) { - const LayerConfig &layerConfig = *it; double tolerance = QgsTolerance::toleranceInProjectUnits( layerConfig.tolerance, layerConfig.layer, mMapSettings, layerConfig.unit ); if ( QgsPointLocator *loc = locatorForLayerUsingStrategy( layerConfig.layer, pointMap, tolerance ) ) { diff --git a/tests/src/core/testqgssnappingutils.cpp b/tests/src/core/testqgssnappingutils.cpp index 6b6b9ee80d2..3519b63ccab 100644 --- a/tests/src/core/testqgssnappingutils.cpp +++ b/tests/src/core/testqgssnappingutils.cpp @@ -33,7 +33,7 @@ struct FilterExcludePoint : public QgsPointLocator::MatchFilter { explicit FilterExcludePoint( const QgsPointXY &p ) : mPoint( p ) {} - bool acceptMatch( const QgsPointLocator::Match &match ) override { return match.point() != mPoint; } + bool acceptMatch( const QgsPointLocator::Match &match ) override { return match.point() != mPoint; } QgsPointXY mPoint; };