Skip to content

Commit

Permalink
Various small reworks :
Browse files Browse the repository at this point in the history
* better documentation
* translation on non translated string
* Grey out column min and max of individual layer snapping settings when snapping limit on scale is disabled.
  Force the refresh when rowChanged is called even if the individual settings are the same to enable/disable immediately the columns when the snapping limit on scale button is pushed.
  • Loading branch information
obrix committed Apr 7, 2020
1 parent 30a52ac commit f56e0f5
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 32 deletions.
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgssnappingconfig.sip.in
Expand Up @@ -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

Expand Down
13 changes: 10 additions & 3 deletions src/app/qgssnappinglayertreemodel.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) );
Expand Down Expand Up @@ -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
{
Expand All @@ -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
{
Expand Down
6 changes: 4 additions & 2 deletions src/app/qgssnappingwidget.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 1 addition & 3 deletions src/core/qgssnappingconfig.cpp
Expand Up @@ -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 );
Expand Down
72 changes: 57 additions & 15 deletions src/core/qgssnappingconfig.h
Expand Up @@ -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
Expand Down Expand Up @@ -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 );

/**
Expand Down Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions src/core/qgssnappingutils.cpp
Expand Up @@ -291,16 +291,14 @@ QgsPointLocator::Match QgsSnappingUtils::snapToMap( const QgsPointXY &pointMap,
}
else if ( mSnappingConfig.mode() == QgsSnappingConfig::AdvancedConfiguration )
{
typedef QList<LayerConfig>::const_iterator LayerConfigIterator;
QList<LayerAndAreaOfInterest> layers;
QList<LayerConfigIterator> filteredConfigs;
QList<LayerConfig> 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
Expand All @@ -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 );
Expand All @@ -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 ) )
{
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/testqgssnappingutils.cpp
Expand Up @@ -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;
};
Expand Down

0 comments on commit f56e0f5

Please sign in to comment.