Skip to content

Commit 35cf2d6

Browse files
committedSep 4, 2012
Looks good, but an extra line when finished is not so pretty. The total is constant, though
1 parent c523511 commit 35cf2d6

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed
 

‎src/app/qgsmeasuredialog.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,21 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WFlags f )
6868
void QgsMeasureDialog::ellipsoidalButton()
6969
{
7070
QSettings settings;
71-
72-
if ( mcbProjectionEnabled->isChecked() )
73-
{
74-
settings.setValue( "/qgis/measure/projectionEnabled", 2 );
75-
}
76-
else
71+
72+
// We set check state to Unchecked and button to Disabled when disabling CRS,
73+
// which generates an call here. Ignore that event!
74+
if ( mcbProjectionEnabled->isEnabled() )
7775
{
78-
settings.setValue( "/qgis/measure/projectionEnabled", 0 );
76+
if ( mcbProjectionEnabled->isChecked() )
77+
{
78+
settings.setValue( "/qgis/measure/projectionEnabled", 2 );
79+
}
80+
else
81+
{
82+
settings.setValue( "/qgis/measure/projectionEnabled", 0 );
83+
}
84+
updateSettings();
7985
}
80-
updateSettings();
8186
}
8287

8388
void QgsMeasureDialog::updateSettings()
@@ -139,8 +144,10 @@ void QgsMeasureDialog::mousePress( QgsPoint &point )
139144
show();
140145
}
141146
raise();
142-
143-
mouseMove( point );
147+
if ( ! mTool->done() )
148+
{
149+
mouseMove( point );
150+
}
144151
}
145152

146153
void QgsMeasureDialog::mouseMove( QgsPoint &point )
@@ -263,6 +270,7 @@ void QgsMeasureDialog::updateUi()
263270
// If project wide transformation is off, disbale checkbox and unmark it.
264271
// When on, enable checbox and mark with saved value.
265272
mcbProjectionEnabled->setEnabled( mTool->canvas()->hasCrsTransformEnabled() );
273+
mcbProjectionEnabled->setCheckState( mTool->canvas()->hasCrsTransformEnabled() && mEllipsoidal ? Qt::Checked : Qt::Unchecked );
266274

267275
// Set tooltip to indicate how we calculate measurments
268276
QString toolTip = tr( "The calculations are based on:" );
@@ -325,7 +333,7 @@ void QgsMeasureDialog::updateUi()
325333
convertMeasurement( d, myDisplayUnits, false );
326334

327335
QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 );
328-
item->setText( 0, QLocale::system().toString( d, 'f' ) );
336+
item->setText( 0, QLocale::system().toString( d, 'f', mDecimalPlaces ) );
329337
item = new QTreeWidgetItem( QStringList( QLocale::system().toString( 0.0, 'f', mDecimalPlaces ) ) );
330338
item->setTextAlignment( 0, Qt::AlignRight );
331339
mTable->addTopLevelItem( item );

‎src/app/qgsmeasuretool.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ QgsMeasureTool::QgsMeasureTool( QgsMapCanvas* canvas, bool measureArea )
4040
QPixmap myCrossHairQPixmap = QPixmap(( const char ** ) cross_hair_cursor );
4141
mCursor = QCursor( myCrossHairQPixmap, 8, 8 );
4242

43-
mRightMouseClicked = false;
43+
mDone = false;
4444

4545
mDialog = new QgsMeasureDialog( this );
4646
mSnapper.setMapCanvas( canvas );
@@ -101,7 +101,7 @@ void QgsMeasureTool::restart()
101101
// re-read settings
102102
updateSettings();
103103

104-
mRightMouseClicked = false;
104+
mDone = false;
105105
mWrongProjectProjection = false;
106106

107107
}
@@ -127,7 +127,7 @@ void QgsMeasureTool::canvasPressEvent( QMouseEvent * e )
127127
{
128128
if ( e->button() == Qt::LeftButton )
129129
{
130-
if ( mRightMouseClicked )
130+
if ( mDone )
131131
mDialog->restart();
132132

133133
QgsPoint idPoint = snapPoint( e->pos() );
@@ -137,7 +137,7 @@ void QgsMeasureTool::canvasPressEvent( QMouseEvent * e )
137137

138138
void QgsMeasureTool::canvasMoveEvent( QMouseEvent * e )
139139
{
140-
if ( !mRightMouseClicked )
140+
if ( ! mDone )
141141
{
142142
QgsPoint point = snapPoint( e->pos() );
143143

@@ -153,10 +153,17 @@ void QgsMeasureTool::canvasReleaseEvent( QMouseEvent * e )
153153

154154
if ( e->button() == Qt::RightButton && ( e->buttons() & Qt::LeftButton ) == 0 ) // restart
155155
{
156-
if ( mRightMouseClicked )
156+
if ( mDone )
157+
{
157158
mDialog->restart();
159+
}
158160
else
159-
mRightMouseClicked = true;
161+
{
162+
// The figure is finished, store last point.
163+
mDone = true;
164+
addPoint( point );
165+
mDialog->show();
166+
}
160167
}
161168
else if ( e->button() == Qt::LeftButton )
162169
{
@@ -180,7 +187,10 @@ void QgsMeasureTool::addPoint( QgsPoint &point )
180187

181188

182189
mRubberBand->addPoint( point );
183-
mDialog->addPoint( point );
190+
if ( ! mDone )
191+
{
192+
mDialog->addPoint( point );
193+
}
184194
}
185195

186196
QgsPoint QgsMeasureTool::snapPoint( const QPoint& p )

‎src/app/qgsmeasuretool.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class QgsMeasureTool : public QgsMapTool
4040
//! returns whether measuring distance or area
4141
bool measureArea() { return mMeasureArea; }
4242

43+
//! When we hvae added our last point, and not following
44+
// Added in 2.0
45+
bool done() { return mDone; }
46+
4347
//! Reset and start new
4448
void restart();
4549

@@ -83,7 +87,7 @@ class QgsMeasureTool : public QgsMapTool
8387
bool mMeasureArea;
8488

8589
//! indicates whether we've just done a right mouse click
86-
bool mRightMouseClicked;
90+
bool mDone;
8791

8892
//! indicates whether we've recently warned the user about having the wrong
8993
// project projection

0 commit comments

Comments
 (0)
Please sign in to comment.