Skip to content

Commit

Permalink
Use alt to select vertices by polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
uclaros authored and nyalldawson committed Mar 30, 2021
1 parent 5e0d409 commit bd38014
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
48 changes: 44 additions & 4 deletions src/app/vertextool/qgsvertextool.cpp
Expand Up @@ -526,7 +526,9 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
mouseMoveNotDragging( e );
}
}
else if ( mSelectionRubberBand )
else if ( mSelectionRubberBand &&
( mSelectionMethod == SelectionNormal ||
( mSelectionMethod == SelectionPolygon && e->button() == Qt::RightButton ) ) )
{
// only handling of selection rect being dragged
QList<Vertex> vertices;
Expand Down Expand Up @@ -649,6 +651,18 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

stopSelectionRubberBand();
}
else if ( e->button() == Qt::LeftButton && e->modifiers() & Qt::AltModifier )
{
mSelectionMethod = SelectionPolygon;
initSelectionRubberBand();
mSelectionRubberBand->addPoint( toMapCoordinates( e->pos() ) );
return;
}
else if ( mSelectionRubberBand && mSelectionMethod == SelectionPolygon )
{
mSelectionRubberBand->addPoint( toMapCoordinates( e->pos() ) );
return;
}
else // selection rect is not being dragged
{
if ( e->button() == Qt::LeftButton && !( e->modifiers() & Qt::ShiftModifier ) && !( e->modifiers() & Qt::ControlModifier ) )
Expand Down Expand Up @@ -716,6 +730,7 @@ void QgsVertexTool::cadCanvasMoveEvent( QgsMapMouseEvent *e )
// the user may be dragging a rect to select vertices
if ( !mSelectionRubberBand && ( e->pos() - *mSelectionRubberBandStartPos ).manhattanLength() >= 10 )
{
mSelectionMethod = SelectionNormal;
initSelectionRubberBand();
}
if ( mSelectionRubberBand )
Expand Down Expand Up @@ -1334,13 +1349,22 @@ void QgsVertexTool::keyPressEvent( QKeyEvent *e )
{
if ( mSelectionMethod == SelectionRange )
stopRangeVertexSelection();
if ( mSelectionMethod == SelectionPolygon )
stopSelectionRubberBand();
if ( mDraggingVertex || mDraggingEdge )
stopDragging();
break;
}
case Qt::Key_Delete:
case Qt::Key_Backspace:
{
if ( mSelectionMethod == SelectionPolygon )
{
e->ignore(); // Override default shortcut management
mSelectionRubberBand->removeLastPoint();
if ( mSelectionRubberBand->numberOfVertices() < 2 )
stopSelectionRubberBand();
}
if ( mDraggingVertex || ( !mDraggingEdge && !mSelectedVertices.isEmpty() ) )
{
e->ignore(); // Override default shortcut management
Expand Down Expand Up @@ -2582,14 +2606,30 @@ void QgsVertexTool::initSelectionRubberBand()

void QgsVertexTool::updateSelectionRubberBand( QgsMapMouseEvent *e )
{
QRect rect = QRect( e->pos(), *mSelectionRubberBandStartPos );
if ( mSelectionRubberBand )
mSelectionRubberBand->setToCanvasRectangle( rect );
switch ( mSelectionMethod )
{
case SelectionNormal:
{
QRect rect = QRect( e->pos(), *mSelectionRubberBandStartPos );
if ( mSelectionRubberBand )
mSelectionRubberBand->setToCanvasRectangle( rect );
break;
}
case SelectionPolygon:
{
mSelectionRubberBand->movePoint( toMapCoordinates( e->pos() ) );
break;
}
default:
break;
}
}

void QgsVertexTool::stopSelectionRubberBand()
{
mSelectionRubberBand.reset();
mSelectionRubberBandStartPos.reset();
mSelectionMethod = SelectionNormal;
}

bool QgsVertexTool::matchEdgeCenterTest( const QgsPointLocator::Match &m, const QgsPointXY &mapPoint, QgsPointXY *edgeCenterPtr )
Expand Down
5 changes: 3 additions & 2 deletions src/app/vertextool/qgsvertextool.h
Expand Up @@ -408,9 +408,9 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing

// members for rectangle for selection

//! the rubberband for rectangle selection visualization
//! the rubberband for rectangle/polygon selection visualization
std::unique_ptr<QgsRubberBand> mSelectionRubberBand;
//! Initial point (in screen coordinates) when using rectangle selection
//! Initial point (in screen coordinates) when using rectangle/polygon selection
std::unique_ptr<QPoint> mSelectionRubberBandStartPos;

// members for addition of vertices at the end of a curve
Expand Down Expand Up @@ -487,6 +487,7 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing
{
SelectionNormal, //!< Default selection: clicking vertex starts move, ctrl+click selects vertex, dragging rectangle select multiple vertices
SelectionRange, //!< Range selection: clicking selects start vertex, next click select final vertex, vertices in the range get selected
SelectionPolygon, //!< Polygon selection: alt+click starts digitizing a polygon, subsequent clicks add vertices, right click selects vertices within the polygon
};

//! Current vertex selection method
Expand Down

0 comments on commit bd38014

Please sign in to comment.