Skip to content
Permalink
Browse files

Cleaned up a bit, fixed area dialog also

  • Loading branch information
homann committed Aug 29, 2012
1 parent 54133ec commit 8b74b9e77028cb461d7b096f843653de7c04c4bc
Showing with 49 additions and 66 deletions.
  1. +30 −55 src/app/qgsmeasuredialog.cpp
  2. +19 −11 src/app/qgsmeasuretool.cpp
@@ -55,12 +55,6 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WFlags f )
// but at least every time any canvas related settings changes
connect( mTool->canvas(), SIGNAL( mapCanvasRefreshed() ),
this, SLOT( updateSettings() ) );
// // Update when project wide transformation has changed
// connect( mTool->canvas()->mapRenderer(), SIGNAL( hasCrsTransformEnabled( bool ) ),
// this, SLOT( changeProjectionEnabledState() ) );
// // Update when project CRS has changed
// connect( mTool->canvas()->mapRenderer(), SIGNAL( destinationSrsChanged() ),
// this, SLOT( changeProjectionEnabledState() ) );

updateSettings();
}
@@ -113,9 +107,7 @@ void QgsMeasureDialog::updateSettings()

// clear interface
mTable->clear();
QTreeWidgetItem* item = new QTreeWidgetItem( QStringList( QString::number( 0, 'f', 1 ) ) );
item->setTextAlignment( 0, Qt::AlignRight );
mTable->addTopLevelItem( item );

mTotal = 0;
updateUi();

@@ -125,24 +117,16 @@ void QgsMeasureDialog::restart()
{
mTool->restart();

// Set one cell row where to update current distance
// If measuring area, the table doesn't get shown
mTable->clear();
QTreeWidgetItem* item = new QTreeWidgetItem( QStringList( QString::number( 0, 'f', 1 ) ) );
item->setTextAlignment( 0, Qt::AlignRight );
mTable->addTopLevelItem( item );
mTotal = 0.;
updateUi();
}


void QgsMeasureDialog::mousePress( QgsPoint &point )
{
if ( mTool->points().size() == 0 )
{
addPoint( point );
show();
}

show();
raise();
if ( ! mTool->done() )
{
@@ -152,25 +136,31 @@ void QgsMeasureDialog::mousePress( QgsPoint &point )

void QgsMeasureDialog::mouseMove( QgsPoint &point )
{
Q_UNUSED( point );

// show current distance/area while moving the point
// by creating a temporary copy of point array
// and adding moving point at the end
if ( mMeasureArea && mTool->points().size() > 1 )
if ( mMeasureArea && mTool->points().size() > 2 )
{
QList<QgsPoint> tmpPoints = mTool->points();
tmpPoints.append( point );
double area = mDa.measurePolygon( tmpPoints );
double area = mDa.measurePolygon( mTool->points() );
editTotal->setText( formatArea( area ) );
}
else if ( !mMeasureArea && mTool->points().size() > 0 )
else if ( !mMeasureArea && mTool->points().size() > 1 )
{
QgsPoint p1( mTool->points().last() ), p2( point );

int last = mTool->points().size() - 1;
QgsPoint p1 = mTool->points()[last];
QgsPoint p2 = mTool->points()[last-1];
double d = mDa.measureLine( p1, p2 );
editTotal->setText( formatDistance( mTotal + d ) );
QGis::UnitType myDisplayUnits;
// Ignore units
convertMeasurement( d, myDisplayUnits, false );

mTotal = mDa.measureLine( mTool->points() );
editTotal->setText( formatDistance( mTotal ) );

QGis::UnitType displayUnits;
// Meters or feet?
convertMeasurement( d, displayUnits, false );

// Set moving
QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 );
item->setText( 0, QLocale::system().toString( d, 'f', mDecimalPlaces ) );
QgsDebugMsg( QString( "Final result is %1" ).arg( item->text( 0 ) ) );
@@ -181,6 +171,7 @@ void QgsMeasureDialog::addPoint( QgsPoint &p )
{
Q_UNUSED( p );

QgsDebugMsg( "Entering" );
int numPoints = mTool->points().size();
if ( mMeasureArea && numPoints > 2 )
{
@@ -189,27 +180,12 @@ void QgsMeasureDialog::addPoint( QgsPoint &p )
}
else if ( !mMeasureArea && numPoints > 1 )
{
int last = numPoints - 2;

QgsPoint p1 = mTool->points()[last], p2 = mTool->points()[last+1];

double d = mDa.measureLine( p1, p2 );

mTotal += d;
editTotal->setText( formatDistance( mTotal ) );

QGis::UnitType myDisplayUnits;
// Ignore units
convertMeasurement( d, myDisplayUnits, false );

QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 );
item->setText( 0, QLocale::system().toString( d, 'f' ) );

item = new QTreeWidgetItem( QStringList( QLocale::system().toString( 0.0, 'f' ) ) );
QTreeWidgetItem * item = new QTreeWidgetItem( QStringList( QLocale::system().toString( 0.0, 'f', mDecimalPlaces ) ) );
item->setTextAlignment( 0, Qt::AlignRight );
mTable->addTopLevelItem( item );
mTable->scrollToItem( item );
}
QgsDebugMsg( "Exiting" );
}

void QgsMeasureDialog::on_buttonBox_rejected( void )
@@ -311,6 +287,7 @@ void QgsMeasureDialog::updateUi()
{
area = mDa.measurePolygon( mTool->points() );
}
mTable->hide(); // Hide the table, only show summary.
editTotal->setText( formatArea( area ) );
}
else
@@ -326,22 +303,20 @@ void QgsMeasureDialog::updateUi()
if ( !b )
{
double d = mDa.measureLine( p1, p2 );
mTotal += d;
editTotal->setText( formatDistance( mTotal ) );
QGis::UnitType myDisplayUnits;

convertMeasurement( d, myDisplayUnits, false );
QGis::UnitType dummyUnits;
convertMeasurement( d, dummyUnits, false );

QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 );
item->setText( 0, QLocale::system().toString( d, 'f', mDecimalPlaces ) );
item = new QTreeWidgetItem( QStringList( QLocale::system().toString( 0.0, 'f', mDecimalPlaces ) ) );
QTreeWidgetItem *item = new QTreeWidgetItem( QStringList( QLocale::system().toString( d , 'f', mDecimalPlaces ) ) );
item->setTextAlignment( 0, Qt::AlignRight );
mTable->addTopLevelItem( item );
mTable->scrollToItem( item );
}
p1 = p2;
b = false;
}
mTotal = mDa.measureLine( mTool->points() );
mTable->show(); // Show the table with items
editTotal->setText( formatDistance( mTotal ) );
}
}

@@ -41,6 +41,8 @@ QgsMeasureTool::QgsMeasureTool( QgsMapCanvas* canvas, bool measureArea )
mCursor = QCursor( myCrossHairQPixmap, 8, 8 );

mDone = false;
// Append point we will move
mPoints.append( QgsPoint (0, 0) );

mDialog = new QgsMeasureDialog( this );
mSnapper.setMapCanvas( canvas );
@@ -96,6 +98,9 @@ void QgsMeasureTool::deactivate()
void QgsMeasureTool::restart()
{
mPoints.clear();
// Append point we will move
mPoints.append( QgsPoint (0, 0) );

mRubberBand->reset( mMeasureArea );

// re-read settings
@@ -106,10 +111,6 @@ void QgsMeasureTool::restart()

}





void QgsMeasureTool::updateSettings()
{
QSettings settings;
@@ -128,10 +129,11 @@ void QgsMeasureTool::canvasPressEvent( QMouseEvent * e )
if ( e->button() == Qt::LeftButton )
{
if ( mDone )
{
mDialog->restart();

}
QgsPoint idPoint = snapPoint( e->pos() );
mDialog->mousePress( idPoint );
// mDialog->mousePress( idPoint );
}
}

@@ -142,7 +144,13 @@ void QgsMeasureTool::canvasMoveEvent( QMouseEvent * e )
QgsPoint point = snapPoint( e->pos() );

mRubberBand->movePoint( point );
mDialog->mouseMove( point );
if( ! mPoints.isEmpty() )
{
// Update last point
mPoints.removeLast();
mPoints.append( point ) ;
mDialog->mouseMove( point );
}
}
}

@@ -159,9 +167,8 @@ void QgsMeasureTool::canvasReleaseEvent( QMouseEvent * e )
}
else
{
// The figure is finished, store last point.
// The figure is finished
mDone = true;
addPoint( point );
mDialog->show();
}
}
@@ -178,14 +185,15 @@ void QgsMeasureTool::addPoint( QgsPoint &point )
{
QgsDebugMsg( "point=" + point.toString() );

int last = mPoints.size() - 1;
// don't add points with the same coordinates
if ( mPoints.size() > 0 && point == mPoints[0] )
if ( mPoints.size() > 1 && mPoints[ last ] == mPoints[ last - 1 ] )
return;

QgsPoint pnt( point );
// Append point that we will be moving.
mPoints.append( pnt );


mRubberBand->addPoint( point );
if ( ! mDone )
{

0 comments on commit 8b74b9e

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