Skip to content

Commit

Permalink
Merge pull request #765 from 3nids/rightclickdigitize
Browse files Browse the repository at this point in the history
right click ends digitizing without adding a vertex
  • Loading branch information
NathanW2 committed Jul 30, 2013
2 parents 812d1ed + 6fce142 commit f350de6
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 76 deletions.
31 changes: 16 additions & 15 deletions src/app/qgsmaptooladdfeature.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -161,28 +160,30 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
}

//add point to list and to rubber band
int error = addVertex( e->pos() );
if ( error == 1 )
{
//current layer is not a vector layer
return;
}
else if ( error == 2 )
{
//problem with coordinate transformation
QMessageBox::information( 0, tr( "Coordinate transform error" ),
tr( "Cannot transform the point to the layers coordinate system" ) );
return;
}

if ( e->button() == Qt::LeftButton )
{
int error = addVertex( e->pos() );
if ( error == 1 )
{
//current layer is not a vector layer
return;
}
else if ( error == 2 )
{
//problem with coordinate transformation
QMessageBox::information( 0, tr( "Coordinate transform error" ),
tr( "Cannot transform the point to the layers coordinate system" ) );
return;
}

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 )
{
Expand Down
33 changes: 17 additions & 16 deletions src/app/qgsmaptooladdpart.cpp
Expand Up @@ -17,7 +17,6 @@
#include "qgsgeometry.h"
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgsrubberband.h"
#include "qgsvectorlayer.h"
#include "qgslogger.h"

Expand Down Expand Up @@ -91,28 +90,30 @@ void QgsMapToolAddPart::canvasReleaseEvent( QMouseEvent * e )
case CapturePolygon:
{
//add point to list and to rubber band
int error = addVertex( e->pos() );
if ( error == 1 )
{
QgsDebugMsg( "current layer is not a vector layer" );
return;
}
else if ( error == 2 )
{
//problem with coordinate transformation
QMessageBox::information( 0,
tr( "Coordinate transform error" ),
tr( "Cannot transform the point to the layers coordinate system" ) );
return;
}

if ( e->button() == Qt::LeftButton )
{
int error = addVertex( e->pos() );
if ( error == 1 )
{
QgsDebugMsg( "current layer is not a vector layer" );
return;
}
else if ( error == 2 )
{
//problem with coordinate transformation
QMessageBox::information( 0,
tr( "Coordinate transform error" ),
tr( "Cannot transform the point to the layers coordinate system" ) );
return;
}

startCapturing();
return;
}
else if ( e->button() != Qt::RightButton )
{
resetLastVertex();

return;
}

Expand Down
31 changes: 16 additions & 15 deletions src/app/qgsmaptooladdring.cpp
Expand Up @@ -17,7 +17,6 @@
#include "qgsgeometry.h"
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgsrubberband.h"
#include "qgsvectorlayer.h"
#include <QMessageBox>
#include <QMouseEvent>
Expand Down Expand Up @@ -50,26 +49,28 @@ void QgsMapToolAddRing::canvasReleaseEvent( QMouseEvent * e )
}

//add point to list and to rubber band
int error = addVertex( e->pos() );
if ( error == 1 )
{
//current layer is not a vector layer
return;
}
else if ( error == 2 )
{
//problem with coordinate transformation
QMessageBox::information( 0, tr( "Coordinate transform error" ),
tr( "Cannot transform the point to the layers coordinate system" ) );
return;
}

if ( e->button() == Qt::LeftButton )
{
int error = addVertex( e->pos() );
if ( error == 1 )
{
//current layer is not a vector layer
return;
}
else if ( error == 2 )
{
//problem with coordinate transformation
QMessageBox::information( 0, tr( "Coordinate transform error" ),
tr( "Cannot transform the point to the layers coordinate system" ) );
return;
}

startCapturing();
}
else if ( e->button() == Qt::RightButton )
{
resetLastVertex();

closePolygon();

vlayer->beginEditCommand( tr( "Ring added" ) );
Expand Down
14 changes: 14 additions & 0 deletions src/app/qgsmaptoolcapture.cpp
Expand Up @@ -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 )
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsmaptoolcapture.h
Expand Up @@ -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();

Expand Down
31 changes: 16 additions & 15 deletions src/app/qgsmaptoolreshape.cpp
Expand Up @@ -16,7 +16,6 @@
#include "qgsmaptoolreshape.h"
#include "qgsgeometry.h"
#include "qgsmapcanvas.h"
#include "qgsrubberband.h"
#include "qgsvectorlayer.h"
#include <QMessageBox>
#include <QMouseEvent>
Expand Down Expand Up @@ -49,26 +48,28 @@ void QgsMapToolReshape::canvasReleaseEvent( QMouseEvent * e )
}

//add point to list and to rubber band
int error = addVertex( e->pos() );
if ( error == 1 )
{
//current layer is not a vector layer
return;
}
else if ( error == 2 )
{
//problem with coordinate transformation
QMessageBox::information( 0, tr( "Coordinate transform error" ),
tr( "Cannot transform the point to the layers coordinate system" ) );
return;
}

if ( e->button() == Qt::LeftButton )
{
int error = addVertex( e->pos() );
if ( error == 1 )
{
//current layer is not a vector layer
return;
}
else if ( error == 2 )
{
//problem with coordinate transformation
QMessageBox::information( 0, tr( "Coordinate transform error" ),
tr( "Cannot transform the point to the layers coordinate system" ) );
return;
}

startCapturing();
}
else if ( e->button() == Qt::RightButton )
{
resetLastVertex();

//find out bounding box of mCaptureList
if ( size() < 1 )
{
Expand Down
31 changes: 16 additions & 15 deletions src/app/qgsmaptoolsplitfeatures.cpp
Expand Up @@ -16,7 +16,6 @@
#include "qgsmaptoolsplitfeatures.h"
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgsrubberband.h"
#include "qgsvectorlayer.h"
#include <QMessageBox>
#include <QMouseEvent>
Expand Down Expand Up @@ -49,26 +48,28 @@ void QgsMapToolSplitFeatures::canvasReleaseEvent( QMouseEvent * e )
}

//add point to list and to rubber band
int error = addVertex( e->pos() );
if ( error == 1 )
{
//current layer is not a vector layer
return;
}
else if ( error == 2 )
{
//problem with coordinate transformation
QMessageBox::information( 0, tr( "Coordinate transform error" ),
tr( "Cannot transform the point to the layers coordinate system" ) );
return;
}

if ( e->button() == Qt::LeftButton )
{
int error = addVertex( e->pos() );
if ( error == 1 )
{
//current layer is not a vector layer
return;
}
else if ( error == 2 )
{
//problem with coordinate transformation
QMessageBox::information( 0, tr( "Coordinate transform error" ),
tr( "Cannot transform the point to the layers coordinate system" ) );
return;
}

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" ) );
Expand Down

0 comments on commit f350de6

Please sign in to comment.