@@ -55,12 +55,6 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WFlags f )
5555 // but at least every time any canvas related settings changes
5656 connect ( mTool ->canvas (), SIGNAL ( mapCanvasRefreshed () ),
5757 this , SLOT ( updateSettings () ) );
58- // // Update when project wide transformation has changed
59- // connect( mTool->canvas()->mapRenderer(), SIGNAL( hasCrsTransformEnabled( bool ) ),
60- // this, SLOT( changeProjectionEnabledState() ) );
61- // // Update when project CRS has changed
62- // connect( mTool->canvas()->mapRenderer(), SIGNAL( destinationSrsChanged() ),
63- // this, SLOT( changeProjectionEnabledState() ) );
6458
6559 updateSettings ();
6660}
@@ -113,9 +107,7 @@ void QgsMeasureDialog::updateSettings()
113107
114108 // clear interface
115109 mTable ->clear ();
116- QTreeWidgetItem* item = new QTreeWidgetItem ( QStringList ( QString::number ( 0 , ' f' , 1 ) ) );
117- item->setTextAlignment ( 0 , Qt::AlignRight );
118- mTable ->addTopLevelItem ( item );
110+
119111 mTotal = 0 ;
120112 updateUi ();
121113
@@ -125,24 +117,16 @@ void QgsMeasureDialog::restart()
125117{
126118 mTool ->restart ();
127119
128- // Set one cell row where to update current distance
129- // If measuring area, the table doesn't get shown
130120 mTable ->clear ();
131- QTreeWidgetItem* item = new QTreeWidgetItem ( QStringList ( QString::number ( 0 , ' f' , 1 ) ) );
132- item->setTextAlignment ( 0 , Qt::AlignRight );
133- mTable ->addTopLevelItem ( item );
134121 mTotal = 0 .;
135122 updateUi ();
136123}
137124
138125
139126void QgsMeasureDialog::mousePress ( QgsPoint &point )
140127{
141- if ( mTool ->points ().size () == 0 )
142- {
143- addPoint ( point );
144- show ();
145- }
128+
129+ show ();
146130 raise ();
147131 if ( ! mTool ->done () )
148132 {
@@ -152,25 +136,31 @@ void QgsMeasureDialog::mousePress( QgsPoint &point )
152136
153137void QgsMeasureDialog::mouseMove ( QgsPoint &point )
154138{
139+ Q_UNUSED ( point );
140+
155141 // show current distance/area while moving the point
156142 // by creating a temporary copy of point array
157143 // and adding moving point at the end
158- if ( mMeasureArea && mTool ->points ().size () > 1 )
144+ if ( mMeasureArea && mTool ->points ().size () > 2 )
159145 {
160- QList<QgsPoint> tmpPoints = mTool ->points ();
161- tmpPoints.append ( point );
162- double area = mDa .measurePolygon ( tmpPoints );
146+ double area = mDa .measurePolygon ( mTool ->points () );
163147 editTotal->setText ( formatArea ( area ) );
164148 }
165- else if ( !mMeasureArea && mTool ->points ().size () > 0 )
149+ else if ( !mMeasureArea && mTool ->points ().size () > 1 )
166150 {
167- QgsPoint p1 ( mTool ->points ().last () ), p2 ( point );
168-
151+ int last = mTool ->points ().size () - 1 ;
152+ QgsPoint p1 = mTool ->points ()[last];
153+ QgsPoint p2 = mTool ->points ()[last-1 ];
169154 double d = mDa .measureLine ( p1, p2 );
170- editTotal->setText ( formatDistance ( mTotal + d ) );
171- QGis::UnitType myDisplayUnits;
172- // Ignore units
173- convertMeasurement ( d, myDisplayUnits, false );
155+
156+ mTotal = mDa .measureLine ( mTool ->points () );
157+ editTotal->setText ( formatDistance ( mTotal ) );
158+
159+ QGis::UnitType displayUnits;
160+ // Meters or feet?
161+ convertMeasurement ( d, displayUnits, false );
162+
163+ // Set moving
174164 QTreeWidgetItem *item = mTable ->topLevelItem ( mTable ->topLevelItemCount () - 1 );
175165 item->setText ( 0 , QLocale::system ().toString ( d, ' f' , mDecimalPlaces ) );
176166 QgsDebugMsg ( QString ( " Final result is %1" ).arg ( item->text ( 0 ) ) );
@@ -181,6 +171,7 @@ void QgsMeasureDialog::addPoint( QgsPoint &p )
181171{
182172 Q_UNUSED ( p );
183173
174+ QgsDebugMsg ( " Entering" );
184175 int numPoints = mTool ->points ().size ();
185176 if ( mMeasureArea && numPoints > 2 )
186177 {
@@ -189,27 +180,12 @@ void QgsMeasureDialog::addPoint( QgsPoint &p )
189180 }
190181 else if ( !mMeasureArea && numPoints > 1 )
191182 {
192- int last = numPoints - 2 ;
193-
194- QgsPoint p1 = mTool ->points ()[last], p2 = mTool ->points ()[last+1 ];
195-
196- double d = mDa .measureLine ( p1, p2 );
197-
198- mTotal += d;
199- editTotal->setText ( formatDistance ( mTotal ) );
200-
201- QGis::UnitType myDisplayUnits;
202- // Ignore units
203- convertMeasurement ( d, myDisplayUnits, false );
204-
205- QTreeWidgetItem *item = mTable ->topLevelItem ( mTable ->topLevelItemCount () - 1 );
206- item->setText ( 0 , QLocale::system ().toString ( d, ' f' ) );
207-
208- item = new QTreeWidgetItem ( QStringList ( QLocale::system ().toString ( 0.0 , ' f' ) ) );
183+ QTreeWidgetItem * item = new QTreeWidgetItem ( QStringList ( QLocale::system ().toString ( 0.0 , ' f' , mDecimalPlaces ) ) );
209184 item->setTextAlignment ( 0 , Qt::AlignRight );
210185 mTable ->addTopLevelItem ( item );
211186 mTable ->scrollToItem ( item );
212187 }
188+ QgsDebugMsg ( " Exiting" );
213189}
214190
215191void QgsMeasureDialog::on_buttonBox_rejected ( void )
@@ -311,6 +287,7 @@ void QgsMeasureDialog::updateUi()
311287 {
312288 area = mDa .measurePolygon ( mTool ->points () );
313289 }
290+ mTable ->hide (); // Hide the table, only show summary.
314291 editTotal->setText ( formatArea ( area ) );
315292 }
316293 else
@@ -326,22 +303,20 @@ void QgsMeasureDialog::updateUi()
326303 if ( !b )
327304 {
328305 double d = mDa .measureLine ( p1, p2 );
329- mTotal += d;
330- editTotal->setText ( formatDistance ( mTotal ) );
331- QGis::UnitType myDisplayUnits;
332-
333- convertMeasurement ( d, myDisplayUnits, false );
306+ QGis::UnitType dummyUnits;
307+ convertMeasurement ( d, dummyUnits, false );
334308
335- QTreeWidgetItem *item = mTable ->topLevelItem ( mTable ->topLevelItemCount () - 1 );
336- item->setText ( 0 , QLocale::system ().toString ( d, ' f' , mDecimalPlaces ) );
337- item = new QTreeWidgetItem ( QStringList ( QLocale::system ().toString ( 0.0 , ' f' , mDecimalPlaces ) ) );
309+ QTreeWidgetItem *item = new QTreeWidgetItem ( QStringList ( QLocale::system ().toString ( d , ' f' , mDecimalPlaces ) ) );
338310 item->setTextAlignment ( 0 , Qt::AlignRight );
339311 mTable ->addTopLevelItem ( item );
340312 mTable ->scrollToItem ( item );
341313 }
342314 p1 = p2;
343315 b = false ;
344316 }
317+ mTotal = mDa .measureLine ( mTool ->points () );
318+ mTable ->show (); // Show the table with items
319+ editTotal->setText ( formatDistance ( mTotal ) );
345320 }
346321}
347322
0 commit comments