Merge pull request #765 from 3nids/rightclickdigitize

right click ends digitizing without adding a vertex
This commit is contained in:
Nathan Woodrow 2013-07-29 23:42:06 -07:00
commit f350de67e9
7 changed files with 98 additions and 76 deletions

View File

@ -22,7 +22,6 @@
#include "qgsmapcanvas.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsrubberband.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include "qgslogger.h"
@ -161,6 +160,8 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
}
//add point to list and to rubber band
if ( e->button() == Qt::LeftButton )
{
int error = addVertex( e->pos() );
if ( error == 1 )
{
@ -175,14 +176,14 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
return;
}
if ( e->button() == Qt::LeftButton )
{
startCapturing();
}
else if ( e->button() == Qt::RightButton )
{
// End of string
resetLastVertex();
//lines: bail out if there are not at least two vertices
if ( mode() == CaptureLine && size() < 2 )
{

View File

@ -17,7 +17,6 @@
#include "qgsgeometry.h"
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgsrubberband.h"
#include "qgsvectorlayer.h"
#include "qgslogger.h"
@ -91,6 +90,8 @@ void QgsMapToolAddPart::canvasReleaseEvent( QMouseEvent * e )
case CapturePolygon:
{
//add point to list and to rubber band
if ( e->button() == Qt::LeftButton )
{
int error = addVertex( e->pos() );
if ( error == 1 )
{
@ -106,13 +107,13 @@ void QgsMapToolAddPart::canvasReleaseEvent( QMouseEvent * e )
return;
}
if ( e->button() == Qt::LeftButton )
{
startCapturing();
return;
}
else if ( e->button() != Qt::RightButton )
{
resetLastVertex();
return;
}

View File

@ -17,7 +17,6 @@
#include "qgsgeometry.h"
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgsrubberband.h"
#include "qgsvectorlayer.h"
#include <QMessageBox>
#include <QMouseEvent>
@ -50,6 +49,8 @@ void QgsMapToolAddRing::canvasReleaseEvent( QMouseEvent * e )
}
//add point to list and to rubber band
if ( e->button() == Qt::LeftButton )
{
int error = addVertex( e->pos() );
if ( error == 1 )
{
@ -64,12 +65,12 @@ void QgsMapToolAddRing::canvasReleaseEvent( QMouseEvent * e )
return;
}
if ( e->button() == Qt::LeftButton )
{
startCapturing();
}
else if ( e->button() == Qt::RightButton )
{
resetLastVertex();
closePolygon();
vlayer->beginEditCommand( tr( "Ring added" ) );

View File

@ -231,6 +231,20 @@ void QgsMapToolCapture::undo()
}
}
void QgsMapToolCapture::resetLastVertex()
{
if ( mRubberBand )
{
int rubberBandSize = mRubberBand->numberOfVertices();
if ( rubberBandSize < 2 )
{
return;
}
const QgsPoint *lastPoint = mRubberBand->getPoint(0, rubberBandSize-2);
mRubberBand->movePoint( *lastPoint );
}
}
void QgsMapToolCapture::keyPressEvent( QKeyEvent* e )
{
if ( e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete )

View File

@ -82,6 +82,9 @@ class QgsMapToolCapture : public QgsMapToolEdit
/**Removes the last vertex from mRubberBand and mCaptureList*/
void undo();
/**Reset the last vertex from RubberBand to the previous one position*/
void resetLastVertex();
void startCapturing();
void stopCapturing();

View File

@ -16,7 +16,6 @@
#include "qgsmaptoolreshape.h"
#include "qgsgeometry.h"
#include "qgsmapcanvas.h"
#include "qgsrubberband.h"
#include "qgsvectorlayer.h"
#include <QMessageBox>
#include <QMouseEvent>
@ -49,6 +48,8 @@ void QgsMapToolReshape::canvasReleaseEvent( QMouseEvent * e )
}
//add point to list and to rubber band
if ( e->button() == Qt::LeftButton )
{
int error = addVertex( e->pos() );
if ( error == 1 )
{
@ -63,12 +64,12 @@ void QgsMapToolReshape::canvasReleaseEvent( QMouseEvent * e )
return;
}
if ( e->button() == Qt::LeftButton )
{
startCapturing();
}
else if ( e->button() == Qt::RightButton )
{
resetLastVertex();
//find out bounding box of mCaptureList
if ( size() < 1 )
{

View File

@ -16,7 +16,6 @@
#include "qgsmaptoolsplitfeatures.h"
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgsrubberband.h"
#include "qgsvectorlayer.h"
#include <QMessageBox>
#include <QMouseEvent>
@ -49,6 +48,8 @@ void QgsMapToolSplitFeatures::canvasReleaseEvent( QMouseEvent * e )
}
//add point to list and to rubber band
if ( e->button() == Qt::LeftButton )
{
int error = addVertex( e->pos() );
if ( error == 1 )
{
@ -63,12 +64,12 @@ void QgsMapToolSplitFeatures::canvasReleaseEvent( QMouseEvent * e )
return;
}
if ( e->button() == Qt::LeftButton )
{
startCapturing();
}
else if ( e->button() == Qt::RightButton )
{
resetLastVertex();
//bring up dialog if a split was not possible (polygon) or only done once (line)
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
vlayer->beginEditCommand( tr( "Features split" ) );