Skip to content

Commit 85c105d

Browse files
committedOct 20, 2016
Move management of avoidIntersectionLayers to QgsProject
1 parent 5c919fb commit 85c105d

File tree

9 files changed

+72
-51
lines changed

9 files changed

+72
-51
lines changed
 

‎python/core/qgsproject.sip

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,20 @@ class QgsProject : QObject
390390
*/
391391
void setSnappingConfig( const QgsSnappingConfig& snappingConfig );
392392

393+
/**
394+
* A list of layers with which intersections should be avoided.
395+
*
396+
* @note Added in QGIS 3.0
397+
*/
398+
QStringList avoidIntersectionsList() const;
399+
400+
/**
401+
* A list of layers with which intersections should be avoided.
402+
*
403+
* @note Added in QGIS 3.0
404+
*/
405+
void setAvoidIntersectionsList(const QStringList& avoidIntersectionsList);
406+
393407
signals:
394408
//! emitted when project is being read
395409
void readProject( const QDomDocument & );
@@ -462,6 +476,13 @@ class QgsProject : QObject
462476
*/
463477
void topologicalEditingChanged();
464478

479+
/**
480+
* Emitted whenever avoidIntersectionsList has changed.
481+
*
482+
* @note Added in QGIS 3.0
483+
*/
484+
void avoidIntersectionsListChanged();
485+
465486
public slots:
466487
/**
467488
* Flag the project as dirty (modified). If this flag is set, the user will

‎python/core/qgssnappingconfig.sip

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ class QgsSnappingConfig
4141
* @param type
4242
* @param tolerance
4343
* @param units
44-
* @param avoidIntersection
4544
*/
46-
IndividualLayerSettings( bool enabled, QgsSnappingConfig::SnappingType type, double tolerance, QgsTolerance::UnitType units, bool avoidIntersection = false );
45+
IndividualLayerSettings( bool enabled, QgsSnappingConfig::SnappingType type, double tolerance, QgsTolerance::UnitType units );
4746

4847
/**
4948
* Constructs an invalid setting
@@ -77,12 +76,6 @@ class QgsSnappingConfig
7776
//! set the type of units
7877
void setUnits( QgsTolerance::UnitType units );
7978

80-
//! return if it shall avoid intersection (polygon layers only)
81-
bool avoidIntersection() const;
82-
83-
//! set if it shall avoid intersection (polygon layers only)
84-
void setAvoidIntersection( bool avoidIntersection );
85-
8679
/**
8780
* Compare this configuration to other.
8881
*/

‎src/app/qgsmaptooladdfeature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
296296

297297
//use always topological editing for avoidIntersection.
298298
//Otherwise, no way to guarantee the geometries don't have a small gap in between.
299-
QStringList intersectionLayers = QgsProject::instance()->readListEntry( "Digitizing", "/AvoidIntersectionsList" );
299+
QStringList intersectionLayers = QgsProject::instance()->avoidIntersectionsList();
300300
bool avoidIntersection = !intersectionLayers.isEmpty();
301301
if ( avoidIntersection ) //try to add topological points also to background layers
302302
{

‎src/app/qgssnappinglayertreemodel.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ QVariant QgsSnappingLayerTreeModel::data( const QModelIndex& idx, int role ) con
494494
{
495495
if ( role == Qt::CheckStateRole && vl->geometryType() == QgsWkbTypes::PolygonGeometry )
496496
{
497-
if ( ls.avoidIntersection() )
497+
if ( mProject->avoidIntersectionsList().contains( vl->id() ) )
498498
{
499499
return Qt::Checked;
500500
}
@@ -614,20 +614,20 @@ bool QgsSnappingLayerTreeModel::setData( const QModelIndex& index, const QVarian
614614

615615
if ( index.column() == AvoidIntersectionColumn && role == Qt::CheckStateRole )
616616
{
617-
QgsVectorLayer *vl = vectorLayer( index );
617+
QgsVectorLayer* vl = vectorLayer( index );
618618
if ( vl )
619619
{
620620
if ( !mIndividualLayerSettings.contains( vl ) )
621621
return false;
622622

623-
QgsSnappingConfig::IndividualLayerSettings ls = mIndividualLayerSettings.value( vl );
624-
if ( !ls.valid() )
625-
return false;
623+
QStringList avoidIntersectionsList = mProject->avoidIntersectionsList();
626624

627-
ls.setAvoidIntersection( value.toInt() == Qt::Checked );
628-
QgsSnappingConfig config = mProject->snappingConfig();
629-
config.setIndividualLayerSettings( vl, ls );
630-
mProject->setSnappingConfig( config );
625+
if ( value.toInt() == Qt::Checked && !avoidIntersectionsList.contains( vl->id() ) )
626+
avoidIntersectionsList.append( vl->id() );
627+
else
628+
avoidIntersectionsList.removeAll( vl->id() );
629+
630+
mProject->setAvoidIntersectionsList( avoidIntersectionsList );
631631
return true;
632632
}
633633
}

‎src/core/geometry/qgsgeometryeditutils.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,8 @@ QgsAbstractGeometry* QgsGeometryEditUtils::avoidIntersections( const QgsAbstract
241241
return nullptr;
242242
}
243243

244-
//read avoid intersections list from project properties
245-
bool listReadOk;
246-
QStringList avoidIntersectionsList = QgsProject::instance()->readListEntry( "Digitizing", "/AvoidIntersectionsList", QStringList(), &listReadOk );
247-
if ( !listReadOk )
244+
QStringList avoidIntersectionsList = QgsProject::instance()->avoidIntersectionsList();
245+
if ( avoidIntersectionsList.isEmpty() )
248246
return nullptr; //no intersections stored in project does not mean error
249247

250248
QList< QgsAbstractGeometry* > nearGeometries;

‎src/core/qgsproject.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,17 @@ void QgsProject::loadEmbeddedNodes( QgsLayerTreeGroup *group )
10021002
}
10031003
}
10041004

1005+
QStringList QgsProject::avoidIntersectionsList() const
1006+
{
1007+
return readListEntry( "Digitizing", "/AvoidIntersectionsList", QStringList() );
1008+
}
1009+
1010+
void QgsProject::setAvoidIntersectionsList( const QStringList& avoidIntersectionsList )
1011+
{
1012+
writeEntry( "Digitizing", "/AvoidIntersectionsList", avoidIntersectionsList );
1013+
emit avoidIntersectionsListChanged();
1014+
}
1015+
10051016
QgsExpressionContext QgsProject::createExpressionContext() const
10061017
{
10071018
QgsExpressionContext context;

‎src/core/qgsproject.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
8080
Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs )
8181
Q_PROPERTY( QgsMapThemeCollection* mapThemeCollection READ mapThemeCollection )
8282
Q_PROPERTY( QgsSnappingConfig snappingConfig READ snappingConfig WRITE setSnappingConfig NOTIFY snappingConfigChanged )
83+
Q_PROPERTY( QStringList avoidIntersectionsList READ avoidIntersectionsList WRITE setAvoidIntersectionsList NOTIFY avoidIntersectionsListChanged )
8384

8485
public:
8586

@@ -469,6 +470,20 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
469470
*/
470471
void setSnappingConfig( const QgsSnappingConfig& snappingConfig );
471472

473+
/**
474+
* A list of layers with which intersections should be avoided.
475+
*
476+
* @note Added in QGIS 3.0
477+
*/
478+
QStringList avoidIntersectionsList() const;
479+
480+
/**
481+
* A list of layers with which intersections should be avoided.
482+
*
483+
* @note Added in QGIS 3.0
484+
*/
485+
void setAvoidIntersectionsList( const QStringList& avoidIntersectionsList );
486+
472487
signals:
473488
//! emitted when project is being read
474489
void readProject( const QDomDocument& );
@@ -543,6 +558,13 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
543558
*/
544559
void topologicalEditingChanged();
545560

561+
/**
562+
* Emitted whenever avoidIntersectionsList has changed.
563+
*
564+
* @note Added in QGIS 3.0
565+
*/
566+
void avoidIntersectionsListChanged();
567+
546568
public slots:
547569
/**
548570
* Flag the project as dirty (modified). If this flag is set, the user will

‎src/core/qgssnappingconfig.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,15 @@ QgsSnappingConfig::IndividualLayerSettings::IndividualLayerSettings()
3030
, mType( Vertex )
3131
, mTolerance( 0 )
3232
, mUnits( QgsTolerance::Pixels )
33-
, mAvoidIntersection( false )
3433
{}
3534

3635

37-
QgsSnappingConfig::IndividualLayerSettings::IndividualLayerSettings( bool enabled, SnappingType type, double tolerance, QgsTolerance::UnitType units, bool avoidIntersection )
36+
QgsSnappingConfig::IndividualLayerSettings::IndividualLayerSettings( bool enabled, SnappingType type, double tolerance, QgsTolerance::UnitType units )
3837
: mValid( true )
3938
, mEnabled( enabled )
4039
, mType( type )
4140
, mTolerance( tolerance )
4241
, mUnits( units )
43-
, mAvoidIntersection( avoidIntersection )
4442
{}
4543

4644
bool QgsSnappingConfig::IndividualLayerSettings::valid() const
@@ -88,24 +86,13 @@ void QgsSnappingConfig::IndividualLayerSettings::setUnits( QgsTolerance::UnitTyp
8886
mUnits = units;
8987
}
9088

91-
bool QgsSnappingConfig::IndividualLayerSettings::avoidIntersection() const
92-
{
93-
return mAvoidIntersection;
94-
}
95-
96-
void QgsSnappingConfig::IndividualLayerSettings::setAvoidIntersection( bool avoidIntersection )
97-
{
98-
mAvoidIntersection = avoidIntersection;
99-
}
100-
10189
bool QgsSnappingConfig::IndividualLayerSettings::operator !=( const QgsSnappingConfig::IndividualLayerSettings& other ) const
10290
{
10391
return mValid != other.mValid
10492
|| mEnabled != other.mEnabled
10593
|| mType != other.mType
10694
|| mTolerance != other.mTolerance
107-
|| mUnits != other.mUnits
108-
|| mAvoidIntersection != other.mAvoidIntersection;
95+
|| mUnits != other.mUnits;
10996
}
11097

11198
bool QgsSnappingConfig::IndividualLayerSettings::operator ==( const QgsSnappingConfig::IndividualLayerSettings& other ) const
@@ -114,8 +101,7 @@ bool QgsSnappingConfig::IndividualLayerSettings::operator ==( const QgsSnappingC
114101
&& mEnabled == other.mEnabled
115102
&& mType == other.mType
116103
&& mTolerance == other.mTolerance
117-
&& mUnits == other.mUnits
118-
&& mAvoidIntersection == other.mAvoidIntersection;
104+
&& mUnits == other.mUnits;
119105
}
120106

121107

@@ -347,15 +333,14 @@ void QgsSnappingConfig::readProject( const QDomDocument& doc )
347333
SnappingType type = ( SnappingType )settingElement.attribute( "type" ).toInt();
348334
double tolerance = settingElement.attribute( "tolerance" ).toDouble();
349335
QgsTolerance::UnitType units = ( QgsTolerance::UnitType )settingElement.attribute( "units" ).toInt();
350-
bool avoidIntersection = settingElement.attribute( "avoid-intersection" ) == "1";
351336

352337
QgsMapLayer* ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
353338
if ( !ml || ml->type() != QgsMapLayer::VectorLayer )
354339
continue;
355340

356341
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( ml );
357342

358-
IndividualLayerSettings setting = IndividualLayerSettings( enabled, type, tolerance, units, avoidIntersection );
343+
IndividualLayerSettings setting = IndividualLayerSettings( enabled, type, tolerance, units );
359344
mIndividualLayerSettings.insert( vl, setting );
360345
}
361346
}
@@ -382,7 +367,6 @@ void QgsSnappingConfig::writeProject( QDomDocument& doc )
382367
layerElement.setAttribute( "type", ( int )setting.type() );
383368
layerElement.setAttribute( "tolerance", setting.tolerance() );
384369
layerElement.setAttribute( "units", ( int )setting.units() );
385-
layerElement.setAttribute( "avoid-intersection", QString::number( setting.avoidIntersection() ) );
386370
ilsElement.appendChild( layerElement );
387371
}
388372
snapSettingsElem.appendChild( ilsElement );

‎src/core/qgssnappingconfig.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ class CORE_EXPORT QgsSnappingConfig
6262
* @param type
6363
* @param tolerance
6464
* @param units
65-
* @param avoidIntersection
6665
*/
67-
IndividualLayerSettings( bool enabled, QgsSnappingConfig::SnappingType type, double tolerance, QgsTolerance::UnitType units, bool avoidIntersection = false );
66+
IndividualLayerSettings( bool enabled, QgsSnappingConfig::SnappingType type, double tolerance, QgsTolerance::UnitType units );
6867

6968
/**
7069
* Constructs an invalid setting
@@ -98,12 +97,6 @@ class CORE_EXPORT QgsSnappingConfig
9897
//! set the type of units
9998
void setUnits( QgsTolerance::UnitType units );
10099

101-
//! return if it shall avoid intersection (polygon layers only)
102-
bool avoidIntersection() const;
103-
104-
//! set if it shall avoid intersection (polygon layers only)
105-
void setAvoidIntersection( bool avoidIntersection );
106-
107100
/**
108101
* Compare this configuration to other.
109102
*/
@@ -117,7 +110,6 @@ class CORE_EXPORT QgsSnappingConfig
117110
SnappingType mType;
118111
double mTolerance;
119112
QgsTolerance::UnitType mUnits;
120-
bool mAvoidIntersection;
121113
};
122114

123115
/**

0 commit comments

Comments
 (0)
Please sign in to comment.