@@ -55,12 +55,6 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WFlags f )
55
55
// but at least every time any canvas related settings changes
56
56
connect ( mTool ->canvas (), SIGNAL ( mapCanvasRefreshed () ),
57
57
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() ) );
64
58
65
59
updateSettings ();
66
60
}
@@ -113,9 +107,7 @@ void QgsMeasureDialog::updateSettings()
113
107
114
108
// clear interface
115
109
mTable ->clear ();
116
- QTreeWidgetItem* item = new QTreeWidgetItem ( QStringList ( QString::number ( 0 , ' f' , 1 ) ) );
117
- item->setTextAlignment ( 0 , Qt::AlignRight );
118
- mTable ->addTopLevelItem ( item );
110
+
119
111
mTotal = 0 ;
120
112
updateUi ();
121
113
@@ -125,24 +117,16 @@ void QgsMeasureDialog::restart()
125
117
{
126
118
mTool ->restart ();
127
119
128
- // Set one cell row where to update current distance
129
- // If measuring area, the table doesn't get shown
130
120
mTable ->clear ();
131
- QTreeWidgetItem* item = new QTreeWidgetItem ( QStringList ( QString::number ( 0 , ' f' , 1 ) ) );
132
- item->setTextAlignment ( 0 , Qt::AlignRight );
133
- mTable ->addTopLevelItem ( item );
134
121
mTotal = 0 .;
135
122
updateUi ();
136
123
}
137
124
138
125
139
126
void QgsMeasureDialog::mousePress ( QgsPoint &point )
140
127
{
141
- if ( mTool ->points ().size () == 0 )
142
- {
143
- addPoint ( point );
144
- show ();
145
- }
128
+
129
+ show ();
146
130
raise ();
147
131
if ( ! mTool ->done () )
148
132
{
@@ -152,25 +136,31 @@ void QgsMeasureDialog::mousePress( QgsPoint &point )
152
136
153
137
void QgsMeasureDialog::mouseMove ( QgsPoint &point )
154
138
{
139
+ Q_UNUSED ( point );
140
+
155
141
// show current distance/area while moving the point
156
142
// by creating a temporary copy of point array
157
143
// and adding moving point at the end
158
- if ( mMeasureArea && mTool ->points ().size () > 1 )
144
+ if ( mMeasureArea && mTool ->points ().size () > 2 )
159
145
{
160
- QList<QgsPoint> tmpPoints = mTool ->points ();
161
- tmpPoints.append ( point );
162
- double area = mDa .measurePolygon ( tmpPoints );
146
+ double area = mDa .measurePolygon ( mTool ->points () );
163
147
editTotal->setText ( formatArea ( area ) );
164
148
}
165
- else if ( !mMeasureArea && mTool ->points ().size () > 0 )
149
+ else if ( !mMeasureArea && mTool ->points ().size () > 1 )
166
150
{
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 ];
169
154
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
174
164
QTreeWidgetItem *item = mTable ->topLevelItem ( mTable ->topLevelItemCount () - 1 );
175
165
item->setText ( 0 , QLocale::system ().toString ( d, ' f' , mDecimalPlaces ) );
176
166
QgsDebugMsg ( QString ( " Final result is %1" ).arg ( item->text ( 0 ) ) );
@@ -181,6 +171,7 @@ void QgsMeasureDialog::addPoint( QgsPoint &p )
181
171
{
182
172
Q_UNUSED ( p );
183
173
174
+ QgsDebugMsg ( " Entering" );
184
175
int numPoints = mTool ->points ().size ();
185
176
if ( mMeasureArea && numPoints > 2 )
186
177
{
@@ -189,27 +180,12 @@ void QgsMeasureDialog::addPoint( QgsPoint &p )
189
180
}
190
181
else if ( !mMeasureArea && numPoints > 1 )
191
182
{
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 ) ) );
209
184
item->setTextAlignment ( 0 , Qt::AlignRight );
210
185
mTable ->addTopLevelItem ( item );
211
186
mTable ->scrollToItem ( item );
212
187
}
188
+ QgsDebugMsg ( " Exiting" );
213
189
}
214
190
215
191
void QgsMeasureDialog::on_buttonBox_rejected ( void )
@@ -311,6 +287,7 @@ void QgsMeasureDialog::updateUi()
311
287
{
312
288
area = mDa .measurePolygon ( mTool ->points () );
313
289
}
290
+ mTable ->hide (); // Hide the table, only show summary.
314
291
editTotal->setText ( formatArea ( area ) );
315
292
}
316
293
else
@@ -326,22 +303,20 @@ void QgsMeasureDialog::updateUi()
326
303
if ( !b )
327
304
{
328
305
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 );
334
308
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 ) ) );
338
310
item->setTextAlignment ( 0 , Qt::AlignRight );
339
311
mTable ->addTopLevelItem ( item );
340
312
mTable ->scrollToItem ( item );
341
313
}
342
314
p1 = p2;
343
315
b = false ;
344
316
}
317
+ mTotal = mDa .measureLine ( mTool ->points () );
318
+ mTable ->show (); // Show the table with items
319
+ editTotal->setText ( formatDistance ( mTotal ) );
345
320
}
346
321
}
347
322
0 commit comments