Skip to content
Permalink
Browse files

Move topological editing setting management fully to QgsProject

  • Loading branch information
m-kuhn committed Oct 20, 2016
1 parent a6a4f2e commit 5c919fbcca490091d637c1f25291223d23e429d7
@@ -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
@@ -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;

@@ -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();
}
@@ -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 );
}
}
@@ -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;
@@ -35,14 +35,11 @@ QgsSelectedFeature::QgsSelectedFeature( QgsFeatureId featureId,
, mChangingGeometry( false )
, mValidator( nullptr )
{
QgsDebugCall;
setSelectedFeature( featureId, vlayer, canvas );
}

QgsSelectedFeature::~QgsSelectedFeature()
{
QgsDebugCall;

deleteVertexMap();

while ( !mGeomErrorMarkers.isEmpty() )
@@ -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 )
@@ -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();
}
@@ -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;
@@ -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" ) );
@@ -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();

@@ -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.
@@ -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() );
@@ -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();
@@ -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();
@@ -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 )
@@ -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
@@ -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() );
}
}

@@ -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 )
@@ -73,6 +73,8 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
private slots:
void projectSnapSettingsChanged();

void projectTopologicalEditingChanged();

void enableSnapping( bool checked );

void changeTolerance( double tolerance );
@@ -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
@@ -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
@@ -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;
}
@@ -169,7 +168,6 @@ void QgsSnappingConfig::reset()
{
mUnits = units;
}
mTopologicalEditing = false;
mIntersectionSnapping = false;

// set advanced config
@@ -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;
@@ -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";

@@ -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" );
@@ -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;

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

QHash<QgsVectorLayer*, IndividualLayerSettings> mIndividualLayerSettings;
@@ -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 );
@@ -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 );

0 comments on commit 5c919fb

Please sign in to comment.
You can’t perform that action at this time.