Skip to content

Commit

Permalink
Move topological editing setting management fully to QgsProject
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 20, 2016
1 parent a6a4f2e commit 5c919fb
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 59 deletions.
7 changes: 7 additions & 0 deletions python/core/qgsproject.sip
Expand Up @@ -455,6 +455,13 @@ class QgsProject : QObject
*/
void transactionGroupsChanged();

/**
* Emitted when the topological editing flag has changed.
*
* @note Added in QGIS 3.0
*/
void topologicalEditingChanged();

public slots:
/**
* Flag the project as dirty (modified). If this flag is set, the user will
Expand Down
6 changes: 0 additions & 6 deletions python/core/qgssnappingconfig.sip
Expand Up @@ -131,12 +131,6 @@ class QgsSnappingConfig
//! set the type of units
void setUnits( QgsTolerance::UnitType units );

//! return if the topological editing is enabled
bool topologicalEditing() const;

//! set if the topological editing is enabled
void setTopologicalEditing( bool enabled );

//! return if the snapping on intersection is enabled
bool intersectionSnapping() const;

Expand Down
9 changes: 4 additions & 5 deletions src/app/nodetool/qgsmaptoolnodetool.cpp
Expand Up @@ -150,7 +150,7 @@ void QgsMapToolNodeTool::canvasMoveEvent( QgsMapMouseEvent* e )
if ( vertexEntry->isSelected() )
mMoveVertices[mSelectedFeature->featureId()].append( qMakePair( vertexEntry->vertexId(), toMapCoordinates( vlayer, vertexEntry->point() ) ) );
}
if ( QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 ) )
if ( QgsProject::instance()->topologicalEditing() )
{
createTopologyRubberBands();
}
Expand Down Expand Up @@ -492,10 +492,9 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QgsMapMouseEvent* e )
{
pressLayerCoords = toLayerCoordinates( vlayer, mClosestMapVertex );

int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
if ( topologicalEditing )
if ( QgsProject::instance()->topologicalEditing() )
{
//insert vertices for snap, but don't add them to features which already has a vertex being moved
//insert vertices for snap, but don't add them to features which already have a vertex being moved
insertSegmentVerticesForSnap( snapResults, vlayer, movedFids );
}
}
Expand Down Expand Up @@ -608,7 +607,7 @@ void QgsMapToolNodeTool::canvasDoubleClickEvent( QgsMapMouseEvent* e )
QgsVectorLayer *vlayer = mSelectedFeature->vlayer();
Q_ASSERT( vlayer );

int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
bool topologicalEditing = QgsProject::instance()->topologicalEditing();
QMultiMap<double, QgsSnappingResult> currentResultList;

QList<QgsSnappingResult> snapResults;
Expand Down
12 changes: 2 additions & 10 deletions src/app/nodetool/qgsselectedfeature.cpp
Expand Up @@ -35,14 +35,11 @@ QgsSelectedFeature::QgsSelectedFeature( QgsFeatureId featureId,
, mChangingGeometry( false )
, mValidator( nullptr )
{
QgsDebugCall;
setSelectedFeature( featureId, vlayer, canvas );
}

QgsSelectedFeature::~QgsSelectedFeature()
{
QgsDebugCall;

deleteVertexMap();

while ( !mGeomErrorMarkers.isEmpty() )
Expand All @@ -63,15 +60,12 @@ QgsSelectedFeature::~QgsSelectedFeature()

void QgsSelectedFeature::currentLayerChanged( QgsMapLayer *layer )
{
QgsDebugCall;
if ( layer == mVlayer )
deleteLater();
}

void QgsSelectedFeature::updateGeometry( const QgsGeometry *geom )
{
QgsDebugCall;

delete mGeometry;

if ( !geom )
Expand Down Expand Up @@ -119,7 +113,6 @@ void QgsSelectedFeature::setSelectedFeature( QgsFeatureId featureId, QgsVectorLa

void QgsSelectedFeature::beforeRollBack()
{
QgsDebugCall;
disconnect( mVlayer, SIGNAL( geometryChanged( QgsFeatureId, const QgsGeometry & ) ), this, SLOT( geometryChanged( QgsFeatureId, const QgsGeometry & ) ) );
deleteVertexMap();
}
Expand Down Expand Up @@ -165,7 +158,6 @@ void QgsSelectedFeature::geometryChanged( QgsFeatureId fid, const QgsGeometry &g

void QgsSelectedFeature::validateGeometry( QgsGeometry *g )
{
QgsDebugCall;
QSettings settings;
if ( settings.value( "/qgis/digitizing/validate_geometries", 1 ).toInt() == 0 )
return;
Expand Down Expand Up @@ -242,7 +234,7 @@ void QgsSelectedFeature::deleteSelectedVertexes()
if ( nSelected == 0 )
return;

int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
bool topologicalEditing = QgsProject::instance()->topologicalEditing();
QMultiMap<double, QgsSnappingResult> currentResultList;

mVlayer->beginEditCommand( QObject::tr( "Deleted vertices" ) );
Expand Down Expand Up @@ -328,7 +320,7 @@ void QgsSelectedFeature::moveSelectedVertexes( QgsVector v )
return;

mVlayer->beginEditCommand( QObject::tr( "Moved vertices" ) );
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
bool topologicalEditing = QgsProject::instance()->topologicalEditing();

beginGeometryChange();

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptooladdfeature.cpp
Expand Up @@ -292,7 +292,7 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
if ( addFeature( vlayer, f.data(), false ) )
{
//add points to other features to keep topology up-to-date
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
bool topologicalEditing = QgsProject::instance()->topologicalEditing();

//use always topological editing for avoidIntersection.
//Otherwise, no way to guarantee the geometries don't have a small gap in between.
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptooladdpart.cpp
Expand Up @@ -185,7 +185,7 @@ void QgsMapToolAddPart::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
emit messageDiscarded();

//add points to other features to keep topology up-to-date
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
bool topologicalEditing = QgsProject::instance()->topologicalEditing();
if ( topologicalEditing )
{
addTopologicalPoints( points() );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolsplitfeatures.cpp
Expand Up @@ -96,7 +96,7 @@ void QgsMapToolSplitFeatures::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
deleteTempRubberBand();

//bring up dialog if a split was not possible (polygon) or only done once (line)
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
int topologicalEditing = QgsProject::instance()->topologicalEditing();
vlayer->beginEditCommand( tr( "Features split" ) );
int returnCode = vlayer->splitFeatures( points(), topologicalEditing );
vlayer->endEditCommand();
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolsplitparts.cpp
Expand Up @@ -94,7 +94,7 @@ void QgsMapToolSplitParts::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
deleteTempRubberBand();

//bring up dialog if a split was not possible (polygon) or only done once (line)
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
bool topologicalEditing = QgsProject::instance()->topologicalEditing();
vlayer->beginEditCommand( tr( "Parts split" ) );
int returnCode = vlayer->splitParts( points(), topologicalEditing );
vlayer->endEditCommand();
Expand Down
17 changes: 10 additions & 7 deletions src/app/qgssnappingwidget.cpp
Expand Up @@ -40,7 +40,7 @@



QgsSnappingWidget::QgsSnappingWidget( QgsProject* project, QgsMapCanvas *canvas, QWidget* parent )
QgsSnappingWidget::QgsSnappingWidget( QgsProject* project, QgsMapCanvas* canvas, QWidget* parent )
: QWidget( parent )
, mProject( project )
, mCanvas( canvas )
Expand Down Expand Up @@ -227,6 +227,7 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject* project, QgsMapCanvas *canvas,

// connect settings changed and map units changed to properly update the widget
connect( project, &QgsProject::snappingConfigChanged, this, &QgsSnappingWidget::projectSnapSettingsChanged );
connect( project, &QgsProject::topologicalEditingChanged, this, &QgsSnappingWidget::projectTopologicalEditingChanged );
connect( mCanvas, SIGNAL( mapUnitsChanged() ), this, SLOT( updateToleranceDecimals() ) );

// modeChanged determines if widget are visible or not based on mode
Expand Down Expand Up @@ -293,14 +294,17 @@ void QgsSnappingWidget::projectSnapSettingsChanged()
mUnitsComboBox->setCurrentIndex( mUnitsComboBox->findData( config.units() ) );
}

if ( config.topologicalEditing() != mTopologicalEditingAction->isChecked() )
if ( config.intersectionSnapping() != mIntersectionSnappingAction->isChecked() )
{
mTopologicalEditingAction->setChecked( config.topologicalEditing() );
mIntersectionSnappingAction->setChecked( config.intersectionSnapping() );
}
}

if ( config.intersectionSnapping() != mIntersectionSnappingAction->isChecked() )
void QgsSnappingWidget::projectTopologicalEditingChanged()
{
if ( QgsProject::instance()->topologicalEditing() != mTopologicalEditingAction->isChecked() )
{
mIntersectionSnappingAction->setChecked( config.intersectionSnapping() );
mTopologicalEditingAction->setChecked( QgsProject::instance()->topologicalEditing() );
}
}

Expand Down Expand Up @@ -338,8 +342,7 @@ void QgsSnappingWidget::changeUnit( int idx )

void QgsSnappingWidget::enableTopologicalEditing( bool enabled )
{
mConfig.setTopologicalEditing( enabled );
mProject->setSnappingConfig( mConfig );
QgsProject::instance()->setTopologicalEditing( enabled );
}

void QgsSnappingWidget::enableIntersectionSnapping( bool enabled )
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgssnappingwidget.h
Expand Up @@ -73,6 +73,8 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
private slots:
void projectSnapSettingsChanged();

void projectTopologicalEditingChanged();

void enableSnapping( bool checked );

void changeTolerance( double tolerance );
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsproject.cpp
Expand Up @@ -2029,12 +2029,12 @@ void QgsProject::setEvaluateDefaultValues( bool evaluateDefaultValues )
void QgsProject::setTopologicalEditing( bool enabled )
{
QgsProject::instance()->writeEntry( "Digitizing", "/TopologicalEditing", ( enabled ? 1 : 0 ) );
// todo emit snapSettingsChanged();
emit topologicalEditingChanged();
}

bool QgsProject::topologicalEditing() const
{
return ( QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 ) > 0 );
return QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
}

QgsUnitTypes::DistanceUnit QgsProject::distanceUnits() const
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgsproject.h
Expand Up @@ -536,6 +536,13 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
void transactionGroupsChanged();

/**
* Emitted when the topological editing flag has changed.
*
* @note Added in QGIS 3.0
*/
void topologicalEditingChanged();

public slots:
/**
* Flag the project as dirty (modified). If this flag is set, the user will
Expand Down
16 changes: 0 additions & 16 deletions src/core/qgssnappingconfig.cpp
Expand Up @@ -135,7 +135,6 @@ bool QgsSnappingConfig::operator==( const QgsSnappingConfig& other ) const
&& mType == other.mType
&& mTolerance == other.mTolerance
&& mUnits == other.mUnits
&& mTopologicalEditing == other.mTopologicalEditing
&& mIntersectionSnapping == other.mIntersectionSnapping
&& mIndividualLayerSettings == other.mIndividualLayerSettings;
}
Expand Down Expand Up @@ -169,7 +168,6 @@ void QgsSnappingConfig::reset()
{
mUnits = units;
}
mTopologicalEditing = false;
mIntersectionSnapping = false;

// set advanced config
Expand Down Expand Up @@ -254,16 +252,6 @@ void QgsSnappingConfig::setUnits( QgsTolerance::UnitType units )
mUnits = units;
}

bool QgsSnappingConfig::topologicalEditing() const
{
return mTopologicalEditing;
}

void QgsSnappingConfig::setTopologicalEditing( bool enabled )
{
mTopologicalEditing = enabled;
}

bool QgsSnappingConfig::intersectionSnapping() const
{
return mIntersectionSnapping;
Expand Down Expand Up @@ -335,9 +323,6 @@ void QgsSnappingConfig::readProject( const QDomDocument& doc )
if ( snapSettingsElem.hasAttribute( "unit" ) )
mUnits = ( QgsTolerance::UnitType )snapSettingsElem.attribute( "unit" ).toInt();

if ( snapSettingsElem.hasAttribute( "topological-editing" ) )
mTopologicalEditing = snapSettingsElem.attribute( "topological-editing" ) == "1";

if ( snapSettingsElem.hasAttribute( "intersection-snapping" ) )
mIntersectionSnapping = snapSettingsElem.attribute( "intersection-snapping" ) == "1";

Expand Down Expand Up @@ -384,7 +369,6 @@ void QgsSnappingConfig::writeProject( QDomDocument& doc )
snapSettingsElem.setAttribute( "type", ( int )mType );
snapSettingsElem.setAttribute( "tolerance", mTolerance );
snapSettingsElem.setAttribute( "unit", ( int )mUnits );
snapSettingsElem.setAttribute( "topological-editing", QString::number( mTopologicalEditing ) );
snapSettingsElem.setAttribute( "intersection-snapping", QString::number( mIntersectionSnapping ) );

QDomElement ilsElement = doc.createElement( "individual-layer-settings" );
Expand Down
7 changes: 0 additions & 7 deletions src/core/qgssnappingconfig.h
Expand Up @@ -162,12 +162,6 @@ class CORE_EXPORT QgsSnappingConfig
//! set the type of units
void setUnits( QgsTolerance::UnitType units );

//! return if the topological editing is enabled
bool topologicalEditing() const;

//! set if the topological editing is enabled
void setTopologicalEditing( bool enabled );

//! return if the snapping on intersection is enabled
bool intersectionSnapping() const;

Expand Down Expand Up @@ -235,7 +229,6 @@ class CORE_EXPORT QgsSnappingConfig
SnappingType mType;
double mTolerance;
QgsTolerance::UnitType mUnits;
bool mTopologicalEditing;
bool mIntersectionSnapping;

QHash<QgsVectorLayer*, IndividualLayerSettings> mIndividualLayerSettings;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsmapcanvassnapper.cpp
Expand Up @@ -71,7 +71,7 @@ int QgsMapCanvasSnapper::snapToCurrentLayer( QPoint p, QList<QgsSnappingResult>&
return 1;

//topological editing on?
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
bool topologicalEditing = QgsProject::instance()->topologicalEditing();
if ( allResutInTolerance )
{
mSnapper->setSnapMode( QgsSnapper::SnapWithResultsWithinTolerances );
Expand Down Expand Up @@ -134,7 +134,7 @@ int QgsMapCanvasSnapper::snapToBackgroundLayers( const QgsPoint& point, QList<Qg
return 5;

//topological editing on?
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
bool topologicalEditing = QgsProject::instance()->topologicalEditing();

//snapping on intersection on?
int intersectionSnapping = QgsProject::instance()->readNumEntry( "Digitizing", "/IntersectionSnapping", 0 );
Expand Down

0 comments on commit 5c919fb

Please sign in to comment.