Skip to content
Permalink
Browse files

When we use the node tool we able to select a feature

  • Loading branch information
sbrunner committed Nov 5, 2015
1 parent 2f9db5a commit 580f70a912b722973c879df9f3230497745d5de0
@@ -26,6 +26,7 @@
#include "qgsproject.h"
#include "qgsgeometryrubberband.h"
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"

#include <QMouseEvent>
#include <QRubberBand>
@@ -168,6 +169,22 @@ void QgsMapToolNodeTool::canvasMoveEvent( QgsMapMouseEvent* e )
}
}

QgsFeature QgsMapToolNodeTool::getFeatureAtPoint( QgsMapMouseEvent* e )
{
QgsFeature feature;
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( vlayer == NULL ) {
return feature;
}

QgsFeatureRequest request;
request.setFilterRect( QgsRectangle( e->mapPoint().x(), e->mapPoint().y(), e->mapPoint().x(), e->mapPoint().y() ) );
QgsFeatureIterator features = vlayer->getFeatures( request );
features.nextFeature( feature );

return feature;
}

void QgsMapToolNodeTool::canvasPressEvent( QgsMapMouseEvent* e )
{
QgsDebugCall;
@@ -186,14 +203,23 @@ void QgsMapToolNodeTool::canvasPressEvent( QgsMapMouseEvent* e )

if ( snapResults.size() < 1 )
{
emit messageEmitted( tr( "could not snap to a segment on the current layer." ) );
return;
QgsFeature feature = getFeatureAtPoint( e );
if ( feature.geometry() == NULL ) {
emit messageEmitted(tr( "could not snap to a segment on the current layer." ) );
return;
}
else {
// remove previous warning
emit messageDiscarded();
mSelectedFeature = new QgsSelectedFeature( feature.id(), vlayer, mCanvas );
}
}
else {
// remove previous warning
emit messageDiscarded();

// remove previous warning
emit messageDiscarded();

mSelectedFeature = new QgsSelectedFeature( snapResults[0].snappedAtGeometry, vlayer, mCanvas );
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() ) );
@@ -254,7 +280,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QgsMapMouseEvent* e )
// no near vertex to snap
// unless point layer, try segment
if ( !mIsPoint )
mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToSegment, tol );
mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToSegment, tol, QList<QgsPoint>(), true );

if ( snapResults.size() > 0 )
{
@@ -310,6 +336,15 @@ void QgsMapToolNodeTool::canvasPressEvent( QgsMapMouseEvent* e )
else if ( !ctrlModifier )
{
mSelectedFeature->deselectAllVertexes();

QgsFeature feature = getFeatureAtPoint( e );
if ( feature.geometry() == NULL ) {
return;
}
else {
mAnother = feature.id();
mSelectAnother = true;
}
}
}
}
@@ -61,6 +61,11 @@ class QgsMapToolNodeTool: public QgsMapToolEdit
void editingToggled();

private:
/**
* Get the feature on the mouse click
*/
QgsFeature getFeatureAtPoint( QgsMapMouseEvent* e );

/**
* Deletes the rubber band pointers and clears mRubberBands
*/
@@ -62,7 +62,8 @@ void QgsMapCanvasSnapper::setMapCanvas( QgsMapCanvas* canvas )
int QgsMapCanvasSnapper::snapToCurrentLayer( const QPoint& p, QList<QgsSnappingResult>& results,
QgsSnapper::SnappingType snap_to,
double snappingTol,
const QList<QgsPoint>& excludePoints )
const QList<QgsPoint>& excludePoints,
bool allResutInTolerance )
{
results.clear();

@@ -71,7 +72,11 @@ int QgsMapCanvasSnapper::snapToCurrentLayer( const QPoint& p, QList<QgsSnappingR

//topological editing on?
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
if ( topologicalEditing == 0 )
if ( allResutInTolerance )
{
mSnapper->setSnapMode( QgsSnapper::SnapWithResultsWithinTolerances);
}
else if ( topologicalEditing == 0 )
{
mSnapper->setSnapMode( QgsSnapper::SnapWithOneResult );
}
@@ -50,8 +50,10 @@ class GUI_EXPORT QgsMapCanvasSnapper
@param results list to which the results are appended
@param snap_to snap to vertex or to segment
@param snappingTol snapping tolerance. -1 means that the search radius for vertex edits is taken
@param excludePoints a list with (map coordinate) points that should be excluded in the snapping result. Useful e.g. for vertex moves where a vertex should not be snapped to its original position*/
int snapToCurrentLayer( const QPoint& p, QList<QgsSnappingResult>& results, QgsSnapper::SnappingType snap_to, double snappingTol = -1, const QList<QgsPoint>& excludePoints = QList<QgsPoint>() );
@param excludePoints a list with (map coordinate) points that should be excluded in the snapping result. Useful e.g. for vertex moves where a vertex should not be snapped to its original position
@param allResutInTolerance return all thew results in the tollerance
*/
int snapToCurrentLayer( const QPoint& p, QList<QgsSnappingResult>& results, QgsSnapper::SnappingType snap_to, double snappingTol = -1, const QList<QgsPoint>& excludePoints = QList<QgsPoint>(), bool allResutInTolerance = false );
/** Snaps to the background layers. This method is useful to align the features of the
edited layers to those of other layers (as described in the project properties).
Uses snap mode QgsSnapper::SnapWithOneResult. Therefore, only the

0 comments on commit 580f70a

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