void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e ) { QgsDebugCall; mClicked = true; mPressCoordinates = e->pos(); QList<QgsSnappingResult> snapResults; if ( !mSelectedFeature ) { QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() ); if ( !vlayer ) return; mSelectAnother = false; mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToVertexAndSegment, -1 ); if ( snapResults.size() < 1 ) { displaySnapToleranceWarning(); return; } mSelectedFeature = new QgsSelectedFeature( snapResults[0].snappedAtGeometry, vlayer, mCanvas ); connect( QgisApp::instance()->legend(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( currentLayerChanged( QgsMapLayer* ) ) ); connect( mSelectedFeature, SIGNAL( destroyed() ), this, SLOT( selectedFeatureDestroyed() ) ); mIsPoint = vlayer->geometryType() == QGis::Point; }
void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e ) { QgsDebugCall; mClicked = true; mPressCoordinates = e->pos(); if ( !mSelectedFeature ) { QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() ); if ( !vlayer ) return; mSelectAnother = false; QgsPointLocator::Match m = mCanvas->snappingUtils()->snapToCurrentLayer( e->pos(), QgsPointLocator::Vertex | QgsPointLocator::Edge ); if ( !m.isValid() ) { emit messageEmitted( tr( "could not snap to a segment on the current layer." ) ); return; } // remove previous warning emit messageDiscarded(); mSelectedFeature = new QgsSelectedFeature( m.featureId(), vlayer, mCanvas ); connect( QgisApp::instance()->layerTreeView(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( currentLayerChanged( QgsMapLayer* ) ) ); connect( mSelectedFeature, SIGNAL( destroyed() ), this, SLOT( selectedFeatureDestroyed() ) ); connect( vlayer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) ); mIsPoint = vlayer->geometryType() == QGis::Point; }
void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e ) { QgsDebugCall; mClicked = true; mPressCoordinates = e->pos(); QList<QgsSnappingResult> snapResults; if ( !mSelectedFeature ) { QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() ); if ( !vlayer ) return; mSelectAnother = false; mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToVertexAndSegment, -1 ); if ( snapResults.size() < 1 ) { emit messageEmitted( tr( "could not snap to a segment on the current layer." ) ); return; } // remove previous warning emit messageDiscarded(); mSelectedFeature = new QgsSelectedFeature( snapResults[0].snappedAtGeometry, vlayer, mCanvas ); connect( QgisApp::instance()->layerTreeView(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( currentLayerChanged( QgsMapLayer* ) ) ); connect( mSelectedFeature, SIGNAL( destroyed() ), this, SLOT( selectedFeatureDestroyed() ) ); connect( vlayer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) ); mIsPoint = vlayer->geometryType() == QGis::Point; }
void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e ) { QgsDebugCall; mClicked = true; mPressCoordinates = e->pos(); QList<QgsSnappingResult> snapResults; if ( !mSelectedFeature ) { QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() ); if ( !vlayer ) return; mSelectAnother = false; mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToVertexAndSegment, -1 ); if ( snapResults.size() < 1 ) { displaySnapToleranceWarning(); return; } mSelectedFeature = new QgsSelectedFeature( snapResults[0].snappedAtGeometry, vlayer, mCanvas ); connect( mSelectedFeature, SIGNAL( destroyed() ), this, SLOT( selectedFeatureDestroyed() ) ); mIsPoint = vlayer->geometryType() == QGis::Point; } else { QgsVectorLayer *vlayer = mSelectedFeature->vlayer(); Q_ASSERT( vlayer ); // some feature already selected QgsPoint layerCoordPoint = toLayerCoordinates( vlayer, e->pos() ); double tol = QgsTolerance::vertexSearchRadius( vlayer, mCanvas->mapRenderer() ); // get geometry and find if snapping is near it int atVertex, beforeVertex, afterVertex; double dist; QgsPoint closestLayerVertex = mSelectedFeature->geometry()->closestVertex( layerCoordPoint, atVertex, beforeVertex, afterVertex, dist ); dist = sqrt( dist ); mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToVertex, tol ); if ( dist <= tol ) { // some vertex selected mMoving = true; mClosestMapVertex = toMapCoordinates( vlayer, closestLayerVertex ); if ( mMoving ) { if ( mSelectedFeature->isSelected( atVertex ) ) { mDeselectOnRelease = atVertex; } else if ( mCtrl ) { mSelectedFeature->invertVertexSelection( atVertex ); } else { mSelectedFeature->deselectAllVertexes(); mSelectedFeature->selectVertex( atVertex ); } } else { // select another feature mAnother = snapResults.first().snappedAtGeometry; mSelectAnother = true; } } else { // no near vertex to snap // unless point layer, try segment if ( !mIsPoint ) mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToSegment, tol ); if ( snapResults.size() > 0 ) { // need to check all if there is a point in the feature mAnother = snapResults.first().snappedAtGeometry; mSelectAnother = true; QList<QgsSnappingResult>::iterator it = snapResults.begin(); QgsSnappingResult snapResult; for ( ; it != snapResults.end(); ++it ) { if ( it->snappedAtGeometry == mSelectedFeature->featureId() ) { snapResult = *it; mAnother = 0; mSelectAnother = false; break; } } if ( !mSelectAnother ) { mMoving = true; mClosestMapVertex = toMapCoordinates( vlayer, closestLayerVertex ); if ( mIsPoint ) { if ( !mCtrl ) { mSelectedFeature->deselectAllVertexes(); mSelectedFeature->selectVertex( snapResult.snappedVertexNr ); } else { mSelectedFeature->invertVertexSelection( snapResult.snappedVertexNr ); } } else { if ( !mCtrl ) { mSelectedFeature->deselectAllVertexes(); mSelectedFeature->selectVertex( snapResult.afterVertexNr ); mSelectedFeature->selectVertex( snapResult.beforeVertexNr ); } else { mSelectedFeature->invertVertexSelection( snapResult.afterVertexNr ); mSelectedFeature->invertVertexSelection( snapResult.beforeVertexNr ); } } } } else if ( !mCtrl ) { mSelectedFeature->deselectAllVertexes(); } } } }