Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Enable snapping whatever the scale when limit to scale is off. Also f…
…ix style.
  • Loading branch information
obrix committed Apr 7, 2020
1 parent b484cae commit 2346718
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 21 deletions.
30 changes: 30 additions & 0 deletions python/core/auto_generated/qgssnappingconfig.sip.in
Expand Up @@ -265,6 +265,36 @@ Returns the tolerance
void setTolerance( double tolerance );
%Docstring
Sets the tolerance
%End

double minScale() const;
%Docstring
Returns the min scale
%End

void setMinScale( double pMinScale );
%Docstring
Sets the min scale
%End

double maxScale() const;
%Docstring
Returns the max scale
%End

void setMaxScale( double pMaxScale );
%Docstring
Set the max scale
%End

bool limitToScale() const;
%Docstring
Returns limit to scale
%End

void setLimitToScale( bool pLimitSnapping );
%Docstring
Set limit to scale
%End

QgsTolerance::UnitType units() const;
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgssnappinglayertreemodel.cpp
Expand Up @@ -107,7 +107,7 @@ QWidget *QgsSnappingLayerDelegate::createEditor( QWidget *parent, const QStyleOp
minLimitSp->setMinimum( 0.0 );
minLimitSp->setMaximum( 99999999.990000 );
minLimitSp->setToolTip( tr( "Min Scale" ) );
minLimitSp->setSpecialValueText("NULL");
minLimitSp->setSpecialValueText( "NULL" );
return minLimitSp;
}

Expand All @@ -118,7 +118,7 @@ QWidget *QgsSnappingLayerDelegate::createEditor( QWidget *parent, const QStyleOp
maxLimitSp->setMinimum( 0.0 );
maxLimitSp->setMaximum( 99999999.990000 );
maxLimitSp->setToolTip( tr( "Max Scale" ) );
maxLimitSp->setSpecialValueText("NULL");
maxLimitSp->setSpecialValueText( "NULL" );
return maxLimitSp;
}

Expand Down Expand Up @@ -628,7 +628,7 @@ QVariant QgsSnappingLayerTreeModel::data( const QModelIndex &idx, int role ) con
{
if ( role == Qt::DisplayRole )
{
if( ls.minScale() <= 0.0)
if ( ls.minScale() <= 0.0 )
{
return QString( "NULL" );
}
Expand All @@ -648,7 +648,7 @@ QVariant QgsSnappingLayerTreeModel::data( const QModelIndex &idx, int role ) con
{
if ( role == Qt::DisplayRole )
{
if( ls.maxScale() <= 0.0 )
if ( ls.maxScale() <= 0.0 )
{
return QString( "NULL" );
}
Expand Down
14 changes: 5 additions & 9 deletions src/app/qgssnappingwidget.cpp
Expand Up @@ -180,7 +180,7 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
mMinScaleSpinBox->setMinimum( 0.0 );
mMinScaleSpinBox->setToolTip( tr( "Min scale on which snapping is enabled" ) );
mMinScaleSpinBox->setObjectName( QStringLiteral( "SnappingMinScaleSpinBox" ) );
mMinScaleSpinBox->setSpecialValueText("NULL");
mMinScaleSpinBox->setSpecialValueText( "NULL" );
connect( mMinScaleSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSnappingWidget::changeMinScale );

mMaxScaleSpinBox = new QDoubleSpinBox();
Expand All @@ -189,7 +189,7 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
mMaxScaleSpinBox->setMinimum( 0.0 );
mMaxScaleSpinBox->setToolTip( tr( "Max scale on which snapping is enabled" ) );
mMaxScaleSpinBox->setObjectName( QStringLiteral( "SnappingMaxScaleSpinBox" ) );
mMaxScaleSpinBox->setSpecialValueText("NULL");
mMaxScaleSpinBox->setSpecialValueText( "NULL" );
connect( mMaxScaleSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSnappingWidget::changeMaxScale );


Expand Down Expand Up @@ -447,11 +447,7 @@ void QgsSnappingWidget::projectSnapSettingsChanged()
mMaxScaleSpinBox->setValue( config.maxScale() );
}

mLimitToScale->setChecked(config.limitToScale());
/*if( mLimitToScale->isChecked() != config.limitToScale() )
{
mLimitToScale->setCheckState( config.limitToScale() ? Qt::Checked : Qt::Unchecked );
}*/
mLimitToScale->setChecked( config.limitToScale() );

if ( config.intersectionSnapping() != mIntersectionSnappingAction->isChecked() )
{
Expand Down Expand Up @@ -519,8 +515,8 @@ void QgsSnappingWidget::changeMaxScale( double pMaxScale )
void QgsSnappingWidget::changeLimitToScale( bool enabled )
{
mConfig.setLimitToScale( enabled );
mMinScaleSpinBox->setEnabled(mConfig.limitToScale());
mMaxScaleSpinBox->setEnabled(mConfig.limitToScale());
mMinScaleSpinBox->setEnabled( mConfig.limitToScale() );
mMaxScaleSpinBox->setEnabled( mConfig.limitToScale() );
mProject->setSnappingConfig( mConfig );
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/qgssnappingwidget.h
Expand Up @@ -105,7 +105,7 @@ class APP_EXPORT QgsSnappingWidget : public QWidget

void changeMaxScale( double pMaxScale );

void changeLimitToScale(bool enabled);
void changeLimitToScale( bool enabled );

void changeUnit( int idx );

Expand Down Expand Up @@ -151,7 +151,7 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
QAction *mCentroidAction = nullptr;
QAction *mMiddleAction = nullptr;
QDoubleSpinBox *mToleranceSpinBox = nullptr;
QAction* mLimitToScale = nullptr;
QAction *mLimitToScale = nullptr;
QDoubleSpinBox *mMinScaleSpinBox = nullptr;
QDoubleSpinBox *mMaxScaleSpinBox = nullptr;
QAction *mToleranceAction = nullptr; // hide widget does not work on toolbar, action needed
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgssnappingconfig.cpp
Expand Up @@ -655,7 +655,7 @@ double QgsSnappingConfig::minScale() const
return mMinScale;
}

void QgsSnappingConfig::setMinScale(double pMinScale)
void QgsSnappingConfig::setMinScale( double pMinScale )
{
mMinScale = pMinScale;
}
Expand All @@ -665,7 +665,7 @@ double QgsSnappingConfig::maxScale() const
return mMaxScale;
}

void QgsSnappingConfig::setMaxScale(double pMaxScale)
void QgsSnappingConfig::setMaxScale( double pMaxScale )
{
mMaxScale = pMaxScale;
}
Expand Down
9 changes: 5 additions & 4 deletions src/core/qgssnappingutils.cpp
Expand Up @@ -296,19 +296,20 @@ QgsPointLocator::Match QgsSnappingUtils::snapToMap( const QgsPointXY &pointMap,
QList<LayerConfigIterator> filteredConfigs;

bool inRangeGlobal = ( mSnappingConfig.minScale() <= 0.0 || mMapSettings.scale() >= mSnappingConfig.minScale() )
&& ( mSnappingConfig.maxScale() <= 0.0 || mMapSettings.scale() <= mSnappingConfig.maxScale() );
&& ( mSnappingConfig.maxScale() <= 0.0 || mMapSettings.scale() <= mSnappingConfig.maxScale() );

for ( LayerConfigIterator it = mLayers.begin(); it != mLayers.end(); ++it )
{
const LayerConfig &layerConfig = *it;
QgsSnappingConfig::IndividualLayerSettings layerSettings = mSnappingConfig.individualLayerSettings( layerConfig.layer );

//Default value for layer config means it is not set (appears NULL)
//Default value for layer config means it is not set ( appears NULL ) layerSpecificRange <- false
bool layerSpecificRange = layerSettings.minScale() > 0.0 || layerSettings.maxScale() > 0.0;
bool inRangeLayer = ( layerSettings.minScale() < 0.0 || mMapSettings.scale() >= layerSettings.minScale() ) && ( layerSettings.maxScale() < 0.0 || mMapSettings.scale() <= layerSettings.maxScale() );

//If no per layer config is set use the global one otherwise use the layer config if it is set
if ( ( !layerSpecificRange && inRangeGlobal ) || ( layerSpecificRange && inRangeLayer) )
//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
if ( !mSnappingConfig.limitToScale() || ( ( !layerSpecificRange && inRangeGlobal ) || ( layerSpecificRange && inRangeLayer ) ) )
{
double tolerance = QgsTolerance::toleranceInProjectUnits( layerConfig.tolerance, layerConfig.layer, mMapSettings, layerConfig.unit );
layers << qMakePair( layerConfig.layer, _areaOfInterest( pointMap, tolerance ) );
Expand Down

0 comments on commit 2346718

Please sign in to comment.