Skip to content
Permalink
Browse files

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

  • Loading branch information
nyalldawson committed Aug 30, 2014
1 parent acf1f70 commit 793db5f53ff99891a297ee4c7dcda6861cc0a09e
Showing with 90 additions and 1 deletion.
  1. +38 −0 src/app/qgsmeasuredialog.cpp
  2. +5 −0 src/app/qgsmeasuredialog.h
  3. +43 −1 src/app/qgsmeasuretool.cpp
  4. +4 −0 src/app/qgsmeasuretool.h
@@ -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();
@@ -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
@@ -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 100644 → 100755
@@ -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

0 comments on commit 793db5f

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