Skip to content

Commit

Permalink
Looks good, but an extra line when finished is not so pretty. The tot…
Browse files Browse the repository at this point in the history
…al is constant, though
  • Loading branch information
homann committed Aug 29, 2012
1 parent 5cbdd9c commit 54133ec
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
30 changes: 19 additions & 11 deletions src/app/qgsmeasuredialog.cpp
Expand Up @@ -68,16 +68,21 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WFlags f )
void QgsMeasureDialog::ellipsoidalButton()
{
QSettings settings;

if ( mcbProjectionEnabled->isChecked() )
{
settings.setValue( "/qgis/measure/projectionEnabled", 2 );
}
else

// 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", 0 );
if ( mcbProjectionEnabled->isChecked() )
{
settings.setValue( "/qgis/measure/projectionEnabled", 2 );
}
else
{
settings.setValue( "/qgis/measure/projectionEnabled", 0 );
}
updateSettings();
}
updateSettings();
}

void QgsMeasureDialog::updateSettings()
Expand Down Expand Up @@ -139,8 +144,10 @@ void QgsMeasureDialog::mousePress( QgsPoint &point )
show();
}
raise();

mouseMove( point );
if ( ! mTool->done() )
{
mouseMove( point );
}
}

void QgsMeasureDialog::mouseMove( QgsPoint &point )
Expand Down Expand Up @@ -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:" );
Expand Down Expand Up @@ -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 );
Expand Down
24 changes: 17 additions & 7 deletions src/app/qgsmeasuretool.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -101,7 +101,7 @@ void QgsMeasureTool::restart()
// re-read settings
updateSettings();

mRightMouseClicked = false;
mDone = false;
mWrongProjectProjection = false;

}
Expand All @@ -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() );
Expand All @@ -137,7 +137,7 @@ void QgsMeasureTool::canvasPressEvent( QMouseEvent * e )

void QgsMeasureTool::canvasMoveEvent( QMouseEvent * e )
{
if ( !mRightMouseClicked )
if ( ! mDone )
{
QgsPoint point = snapPoint( e->pos() );

Expand All @@ -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 )
{
Expand All @@ -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 )
Expand Down
6 changes: 5 additions & 1 deletion src/app/qgsmeasuretool.h
Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 54133ec

Please sign in to comment.