@@ -52,7 +52,14 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WFlags f )
52
52
// mTable->setHeaderLabels(QStringList() << tr("Segments (in meters)") << tr("Total") << tr("Azimuth") );
53
53
54
54
QSettings settings;
55
+ int s = settings.value ( " /qgis/measure/projectionEnabled" , " 2" ).toInt ();
56
+ if ( s == 2 )
57
+ mcbProjectionEnabled->setCheckState ( Qt::Checked );
58
+ else
59
+ mcbProjectionEnabled->setCheckState ( Qt::Unchecked );
55
60
61
+ connect ( mcbProjectionEnabled, SIGNAL ( stateChanged (int ) ),
62
+ this , SLOT ( changeProjectionEnabledState () ));
56
63
57
64
updateUi ();
58
65
}
@@ -91,21 +98,27 @@ void QgsMeasureDialog::mouseMove( QgsPoint &point )
91
98
QSettings settings;
92
99
int decimalPlaces = settings.value ( " /qgis/measure/decimalplaces" , " 3" ).toInt ();
93
100
101
+ // Create QgsDistance Area for customization ProjectionEnabled setting
102
+ QgsDistanceArea myDa;
103
+ myDa.setSourceCrs ( mTool ->canvas ()->mapRenderer ()->destinationSrs ().srsid () );
104
+ myDa.setEllipsoid ( mTool ->canvas ()->mapRenderer ()->distanceArea ()->ellipsoid () );
105
+ myDa.setProjectionsEnabled ( mcbProjectionEnabled->isChecked () );
106
+
94
107
// show current distance/area while moving the point
95
108
// by creating a temporary copy of point array
96
- // and adding moving point at the end
109
+ // and adding moving point at the end
97
110
if ( mMeasureArea && mTool ->points ().size () > 1 )
98
111
{
99
112
QList<QgsPoint> tmpPoints = mTool ->points ();
100
113
tmpPoints.append ( point );
101
- double area = mTool -> canvas ()-> mapRenderer ()-> distanceArea ()-> measurePolygon ( tmpPoints );
114
+ double area = myDa. measurePolygon ( tmpPoints );
102
115
editTotal->setText ( formatArea ( area, decimalPlaces ) );
103
116
}
104
117
else if ( !mMeasureArea && mTool ->points ().size () > 0 )
105
118
{
106
119
QgsPoint p1 ( mTool ->points ().last () ), p2 ( point );
107
120
108
- double d = mTool -> canvas ()-> mapRenderer ()-> distanceArea ()-> measureLine ( p1, p2 );
121
+ double d = myDa. measureLine ( p1, p2 );
109
122
editTotal->setText ( formatDistance ( mTotal + d, decimalPlaces ) );
110
123
QGis::UnitType myDisplayUnits;
111
124
// Ignore units
@@ -120,10 +133,16 @@ void QgsMeasureDialog::addPoint( QgsPoint &point )
120
133
QSettings settings;
121
134
int decimalPlaces = settings.value ( " /qgis/measure/decimalplaces" , " 3" ).toInt ();
122
135
136
+ // Create QgsDistance Area for customization ProjectionEnabled setting
137
+ QgsDistanceArea myDa;
138
+ myDa.setSourceCrs ( mTool ->canvas ()->mapRenderer ()->destinationSrs ().srsid () );
139
+ myDa.setEllipsoid ( mTool ->canvas ()->mapRenderer ()->distanceArea ()->ellipsoid () );
140
+ myDa.setProjectionsEnabled ( mcbProjectionEnabled->isChecked () );
141
+
123
142
int numPoints = mTool ->points ().size ();
124
143
if ( mMeasureArea && numPoints > 2 )
125
144
{
126
- double area = mTool -> canvas ()-> mapRenderer ()-> distanceArea ()-> measurePolygon ( mTool ->points () );
145
+ double area = myDa. measurePolygon ( mTool ->points () );
127
146
editTotal->setText ( formatArea ( area, decimalPlaces ) );
128
147
}
129
148
else if ( !mMeasureArea && numPoints > 1 )
@@ -132,7 +151,7 @@ void QgsMeasureDialog::addPoint( QgsPoint &point )
132
151
133
152
QgsPoint p1 = mTool ->points ()[last], p2 = mTool ->points ()[last+1 ];
134
153
135
- double d = mTool -> canvas ()-> mapRenderer ()-> distanceArea ()-> measureLine ( p1, p2 );
154
+ double d = myDa. measureLine ( p1, p2 );
136
155
137
156
mTotal += d;
138
157
editTotal->setText ( formatDistance ( mTotal , decimalPlaces ) );
@@ -252,17 +271,17 @@ void QgsMeasureDialog::convertMeasurement( double &measure, QGis::UnitType &u, b
252
271
QGis::UnitType myUnits = mTool ->canvas ()->mapUnits ();
253
272
if (( myUnits == QGis::Degrees || myUnits == QGis::Feet ) &&
254
273
mTool ->canvas ()->mapRenderer ()->distanceArea ()->ellipsoid () != " NONE" &&
255
- mTool -> canvas ()-> mapRenderer ()-> distanceArea ()-> hasCrsTransformEnabled () )
274
+ mcbProjectionEnabled-> isChecked () )
256
275
{
257
276
// Measuring on an ellipsoid returns meters, and so does using projections???
258
277
myUnits = QGis::Meters;
259
278
QgsDebugMsg ( " We're measuring on an ellipsoid or using projections, the system is returning meters" );
260
279
}
261
-
280
+
262
281
// Get the units for display
263
282
QSettings settings;
264
283
QString myDisplayUnitsTxt = settings.value ( " /qgis/measure/displayunits" , " meters" ).toString ();
265
-
284
+
266
285
// Only convert between meters and feet
267
286
if ( myUnits == QGis::Meters && myDisplayUnitsTxt == " feet" )
268
287
{
@@ -289,3 +308,68 @@ void QgsMeasureDialog::convertMeasurement( double &measure, QGis::UnitType &u, b
289
308
290
309
u = myUnits;
291
310
}
311
+
312
+ void QgsMeasureDialog::changeProjectionEnabledState ()
313
+ {
314
+ // store value
315
+ QSettings settings;
316
+ if ( mcbProjectionEnabled->isChecked () )
317
+ settings.setValue ( " /qgis/measure/projectionEnabled" , 2 );
318
+ else
319
+ settings.setValue ( " /qgis/measure/projectionEnabled" , 0 );
320
+
321
+ // clear interface
322
+ mTable ->clear ();
323
+ QTreeWidgetItem* item = new QTreeWidgetItem ( QStringList ( QString::number ( 0 , ' f' , 1 ) ) );
324
+ item->setTextAlignment ( 0 , Qt::AlignRight );
325
+ mTable ->addTopLevelItem ( item );
326
+ mTotal = 0 ;
327
+ updateUi ();
328
+
329
+ int decimalPlaces = settings.value ( " /qgis/measure/decimalplaces" , " 3" ).toInt ();
330
+
331
+ // create DistanceArea
332
+ QgsDistanceArea myDa;
333
+ myDa.setSourceCrs ( mTool ->canvas ()->mapRenderer ()->destinationSrs ().srsid () );
334
+ myDa.setEllipsoid ( mTool ->canvas ()->mapRenderer ()->distanceArea ()->ellipsoid () );
335
+ myDa.setProjectionsEnabled ( mcbProjectionEnabled->isChecked () );
336
+
337
+ if ( mMeasureArea )
338
+ {
339
+ double area = 0.0 ;
340
+ if ( mTool ->points ().size () > 1 )
341
+ {
342
+ area = myDa.measurePolygon ( mTool ->points () );
343
+ }
344
+ editTotal->setText ( formatArea ( area, decimalPlaces ) );
345
+ }else
346
+ {
347
+ QList<QgsPoint>::const_iterator it;
348
+ bool b = true ; // first point
349
+
350
+ QgsPoint p1,p2;
351
+
352
+ for (it=mTool ->points ().constBegin (); it != mTool ->points ().constEnd (); ++it)
353
+ {
354
+ p2 = *it;
355
+ if ( !b )
356
+ {
357
+ double d = myDa.measureLine ( p1, p2 );
358
+ mTotal += d;
359
+ editTotal->setText ( formatDistance ( mTotal , decimalPlaces ) );
360
+ QGis::UnitType myDisplayUnits;
361
+
362
+ convertMeasurement ( d, myDisplayUnits, false );
363
+
364
+ QTreeWidgetItem *item = mTable ->topLevelItem ( mTable ->topLevelItemCount () - 1 );
365
+ item->setText ( 0 , QLocale::system ().toString ( d, ' f' , decimalPlaces ) );
366
+ item = new QTreeWidgetItem ( QStringList ( QLocale::system ().toString ( 0.0 , ' f' , decimalPlaces ) ) );
367
+ item->setTextAlignment ( 0 , Qt::AlignRight );
368
+ mTable ->addTopLevelItem ( item );
369
+ mTable ->scrollToItem ( item );
370
+ }
371
+ p1 = p2;
372
+ b = false ;
373
+ }
374
+ }
375
+ }
0 commit comments