Looks good, but an extra line when finished is not so pretty. The total is constant, though

This commit is contained in:
Magnus Homann 2012-08-27 00:42:06 +02:00
parent 5cbdd9c18c
commit 54133eca44
3 changed files with 41 additions and 19 deletions

View File

@ -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 );

View File

@ -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 )

View File

@ -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