From 54133eca4455886fae98b8be3a59450e3ab2a6d8 Mon Sep 17 00:00:00 2001 From: Magnus Homann Date: Mon, 27 Aug 2012 00:42:06 +0200 Subject: [PATCH] Looks good, but an extra line when finished is not so pretty. The total is constant, though --- src/app/qgsmeasuredialog.cpp | 30 +++++++++++++++++++----------- src/app/qgsmeasuretool.cpp | 24 +++++++++++++++++------- src/app/qgsmeasuretool.h | 6 +++++- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/app/qgsmeasuredialog.cpp b/src/app/qgsmeasuredialog.cpp index 59d935ccf20..8929188d59e 100644 --- a/src/app/qgsmeasuredialog.cpp +++ b/src/app/qgsmeasuredialog.cpp @@ -68,16 +68,21 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WFlags f ) void QgsMeasureDialog::ellipsoidalButton() { QSettings settings; - - if ( mcbProjectionEnabled->isChecked() ) + + // We set check state to Unchecked and button to Disabled when disabling CRS, + // which generates an call here. Ignore that event! + if ( mcbProjectionEnabled->isEnabled() ) { - settings.setValue( "/qgis/measure/projectionEnabled", 2 ); + if ( mcbProjectionEnabled->isChecked() ) + { + settings.setValue( "/qgis/measure/projectionEnabled", 2 ); + } + else + { + settings.setValue( "/qgis/measure/projectionEnabled", 0 ); + } + updateSettings(); } - else - { - settings.setValue( "/qgis/measure/projectionEnabled", 0 ); - } - updateSettings(); } void QgsMeasureDialog::updateSettings() @@ -139,8 +144,10 @@ void QgsMeasureDialog::mousePress( QgsPoint &point ) show(); } raise(); - - mouseMove( point ); + if ( ! mTool->done() ) + { + mouseMove( point ); + } } void QgsMeasureDialog::mouseMove( QgsPoint &point ) @@ -263,6 +270,7 @@ void QgsMeasureDialog::updateUi() // If project wide transformation is off, disbale checkbox and unmark it. // When on, enable checbox and mark with saved value. mcbProjectionEnabled->setEnabled( mTool->canvas()->hasCrsTransformEnabled() ); + mcbProjectionEnabled->setCheckState( mTool->canvas()->hasCrsTransformEnabled() && mEllipsoidal ? Qt::Checked : Qt::Unchecked ); // Set tooltip to indicate how we calculate measurments QString toolTip = tr( "The calculations are based on:" ); @@ -325,7 +333,7 @@ void QgsMeasureDialog::updateUi() convertMeasurement( d, myDisplayUnits, false ); QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 ); - item->setText( 0, QLocale::system().toString( d, 'f' ) ); + item->setText( 0, QLocale::system().toString( d, 'f', mDecimalPlaces ) ); item = new QTreeWidgetItem( QStringList( QLocale::system().toString( 0.0, 'f', mDecimalPlaces ) ) ); item->setTextAlignment( 0, Qt::AlignRight ); mTable->addTopLevelItem( item ); diff --git a/src/app/qgsmeasuretool.cpp b/src/app/qgsmeasuretool.cpp index cb4576a48f7..e63ee562b86 100644 --- a/src/app/qgsmeasuretool.cpp +++ b/src/app/qgsmeasuretool.cpp @@ -40,7 +40,7 @@ QgsMeasureTool::QgsMeasureTool( QgsMapCanvas* canvas, bool measureArea ) QPixmap myCrossHairQPixmap = QPixmap(( const char ** ) cross_hair_cursor ); mCursor = QCursor( myCrossHairQPixmap, 8, 8 ); - mRightMouseClicked = false; + mDone = false; mDialog = new QgsMeasureDialog( this ); mSnapper.setMapCanvas( canvas ); @@ -101,7 +101,7 @@ void QgsMeasureTool::restart() // re-read settings updateSettings(); - mRightMouseClicked = false; + mDone = false; mWrongProjectProjection = false; } @@ -127,7 +127,7 @@ void QgsMeasureTool::canvasPressEvent( QMouseEvent * e ) { if ( e->button() == Qt::LeftButton ) { - if ( mRightMouseClicked ) + if ( mDone ) mDialog->restart(); QgsPoint idPoint = snapPoint( e->pos() ); @@ -137,7 +137,7 @@ void QgsMeasureTool::canvasPressEvent( QMouseEvent * e ) void QgsMeasureTool::canvasMoveEvent( QMouseEvent * e ) { - if ( !mRightMouseClicked ) + if ( ! mDone ) { QgsPoint point = snapPoint( e->pos() ); @@ -153,10 +153,17 @@ void QgsMeasureTool::canvasReleaseEvent( QMouseEvent * e ) if ( e->button() == Qt::RightButton && ( e->buttons() & Qt::LeftButton ) == 0 ) // restart { - if ( mRightMouseClicked ) + if ( mDone ) + { mDialog->restart(); + } else - mRightMouseClicked = true; + { + // The figure is finished, store last point. + mDone = true; + addPoint( point ); + mDialog->show(); + } } else if ( e->button() == Qt::LeftButton ) { @@ -180,7 +187,10 @@ void QgsMeasureTool::addPoint( QgsPoint &point ) mRubberBand->addPoint( point ); - mDialog->addPoint( point ); + if ( ! mDone ) + { + mDialog->addPoint( point ); + } } QgsPoint QgsMeasureTool::snapPoint( const QPoint& p ) diff --git a/src/app/qgsmeasuretool.h b/src/app/qgsmeasuretool.h index 3b9da988ccc..71674081938 100644 --- a/src/app/qgsmeasuretool.h +++ b/src/app/qgsmeasuretool.h @@ -40,6 +40,10 @@ class QgsMeasureTool : public QgsMapTool //! returns whether measuring distance or area bool measureArea() { return mMeasureArea; } + //! When we hvae added our last point, and not following + // Added in 2.0 + bool done() { return mDone; } + //! Reset and start new void restart(); @@ -83,7 +87,7 @@ class QgsMeasureTool : public QgsMapTool bool mMeasureArea; //! indicates whether we've just done a right mouse click - bool mRightMouseClicked; + bool mDone; //! indicates whether we've recently warned the user about having the wrong // project projection