Allow removing last point while measuring via del/backspace keys (fix #10176)

This commit is contained in:
Nyall Dawson 2014-08-30 21:47:13 +10:00
parent acf1f70f13
commit 793db5f53f
4 changed files with 90 additions and 1 deletions

View File

@ -89,6 +89,7 @@ void QgsMeasureDialog::restart()
void QgsMeasureDialog::mouseMove( QgsPoint &point )
{
mLastMousePoint = point;
// show current distance/area while moving the point
// by creating a temporary copy of point array
// and adding moving point at the end
@ -145,6 +146,43 @@ void QgsMeasureDialog::addPoint( QgsPoint &p )
QgsDebugMsg( "Exiting" );
}
void QgsMeasureDialog::removeLastPoint()
{
int numPoints = mTool->points().size();
if ( mMeasureArea )
{
if ( numPoints > 1 )
{
QList<QgsPoint> tmpPoints = mTool->points();
tmpPoints.append( mLastMousePoint );
double area = mDa.measurePolygon( tmpPoints );
editTotal->setText( formatArea( area ) );
}
else
{
editTotal->setText( formatArea( 0 ) );
}
}
else if ( !mMeasureArea && numPoints >= 1 )
{
//remove final row
delete mTable->takeTopLevelItem( mTable->topLevelItemCount() - 1 );
QgsPoint p1( mTool->points().last() );
double d = mDa.measureLine( p1, mLastMousePoint );
mTotal = mDa.measureLine( mTool->points() );
editTotal->setText( formatDistance( mTotal + d ) );
QGis::UnitType displayUnits;
// Meters or feet?
convertMeasurement( d, displayUnits, false );
QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 );
item->setText( 0, QLocale::system().toString( d, 'f', mDecimalPlaces ) );
}
}
void QgsMeasureDialog::on_buttonBox_rejected( void )
{
restart();

View File

@ -47,6 +47,9 @@ class APP_EXPORT QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase
//! Mose move
void mouseMove( QgsPoint &point );
//! Remove last point
void removeLastPoint();
public slots:
//! Reject
void on_buttonBox_rejected( void );
@ -96,6 +99,8 @@ class APP_EXPORT QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase
//! pointer to measure tool which owns this dialog
QgsMeasureTool* mTool;
QgsPoint mLastMousePoint;
};
#endif

View File

@ -167,12 +167,54 @@ void QgsMeasureTool::canvasReleaseEvent( QMouseEvent * e )
mDone = false;
}
// we allways add the clicked point to the measuring feature
// we always add the clicked point to the measuring feature
addPoint( point );
mDialog->show();
}
void QgsMeasureTool::undo()
{
if ( mRubberBand )
{
if ( mPoints.size() < 1 )
{
return;
}
if ( mPoints.size() == 1 )
{
//removing first point, so restart everything
restart();
mDialog->restart();
}
else
{
//remove second last point from line band, and last point from points band
mRubberBand->removePoint( -2, true );
mRubberBandPoints->removePoint( -1, true );
mPoints.removeLast();
mDialog->removeLastPoint();
}
}
}
void QgsMeasureTool::keyPressEvent( QKeyEvent* e )
{
if (( e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete ) )
{
if ( !mDone )
{
undo();
}
// Override default shortcut management in MapCanvas
e->ignore();
}
}
void QgsMeasureTool::addPoint( QgsPoint &point )
{

4
src/app/qgsmeasuretool.h Normal file → Executable file
View File

@ -70,6 +70,8 @@ class APP_EXPORT QgsMeasureTool : public QgsMapTool
//! called when map tool is being deactivated
virtual void deactivate();
virtual void keyPressEvent( QKeyEvent* e );
public slots:
//! updates the projections we're using
void updateSettings();
@ -102,6 +104,8 @@ class APP_EXPORT QgsMeasureTool : public QgsMapTool
//@param p (pixel) coordinate
QgsPoint snapPoint( const QPoint& p );
/**Removes the last vertex from mRubberBand*/
void undo();
};
#endif