@@ -59,6 +59,12 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WFlags f )
59
59
60
60
connect ( mcbProjectionEnabled, SIGNAL ( stateChanged ( int ) ),
61
61
this , SLOT ( changeProjectionEnabledState () ) );
62
+ // Update when project wide transformation has changed
63
+ connect ( mTool ->canvas ()->mapRenderer (), SIGNAL ( hasCrsTransformEnabled ( bool ) ),
64
+ this , SLOT ( changeProjectionEnabledState () ) );
65
+ // Update when project CRS has changed
66
+ connect ( mTool ->canvas ()->mapRenderer (), SIGNAL ( destinationSrsChanged () ),
67
+ this , SLOT ( changeProjectionEnabledState () ) );
62
68
63
69
updateUi ();
64
70
}
@@ -118,6 +124,7 @@ void QgsMeasureDialog::mouseMove( QgsPoint &point )
118
124
convertMeasurement ( d, myDisplayUnits, false );
119
125
QTreeWidgetItem *item = mTable ->topLevelItem ( mTable ->topLevelItemCount () - 1 );
120
126
item->setText ( 0 , QLocale::system ().toString ( d, ' f' , decimalPlaces ) );
127
+ QgsDebugMsg ( QString ( " Final result is %1" ).arg ( item->text ( 0 ) ) );
121
128
}
122
129
}
123
130
@@ -214,29 +221,50 @@ QString QgsMeasureDialog::formatArea( double area, int decimalPlaces )
214
221
215
222
void QgsMeasureDialog::updateUi ()
216
223
{
224
+ // Only enable checkbox when project wide transformation is on
225
+ mcbProjectionEnabled->setEnabled ( mTool ->canvas ()->hasCrsTransformEnabled () );
226
+
227
+ configureDistanceArea ();
228
+
217
229
QSettings settings;
218
- int decimalPlaces = settings.value ( " /qgis/measure/decimalplaces" , " 3" ).toInt ();
219
230
220
- double dummy = 1.0 ;
221
- QGis::UnitType myDisplayUnits;
222
- // The dummy distance is ignored
223
- convertMeasurement ( dummy, myDisplayUnits, false );
231
+ // Set tooltip to indicate how we calculate measurments
232
+ QGis::UnitType mapUnits = mTool ->canvas ()->mapUnits ();
233
+ QGis::UnitType displayUnits = QGis::fromLiteral ( settings.value ( " /qgis/measure/displayunits" , QGis::toLiteral ( QGis::Meters ) ).toString () );
224
234
225
- switch ( myDisplayUnits )
235
+ QString toolTip = tr ( " The calculations are based on:" );
236
+ if ( ! mTool ->canvas ()->hasCrsTransformEnabled () )
226
237
{
227
- case QGis::Meters:
228
- mTable ->setHeaderLabels ( QStringList ( tr ( " Segments (in meters)" ) ) );
229
- break ;
230
- case QGis::Feet:
231
- mTable ->setHeaderLabels ( QStringList ( tr ( " Segments (in feet)" ) ) );
232
- break ;
233
- case QGis::Degrees:
234
- mTable ->setHeaderLabels ( QStringList ( tr ( " Segments (in degrees)" ) ) );
235
- break ;
236
- case QGis::UnknownUnit:
237
- mTable ->setHeaderLabels ( QStringList ( tr ( " Segments" ) ) );
238
+ toolTip += " <br> * " + tr ( " Project CRS transformation is turned off." ) + " " ;
239
+ toolTip += tr ( " Canvas units setting is taken from project properties setting (%1)." ).arg ( QGis::tr ( mapUnits ) );
240
+ toolTip += " <br> * " + tr ( " Ellipsoidal calculation is not possible, as project CRS is undefined." );
241
+ }
242
+ else
243
+ {
244
+ if ( mDa .ellipsoidalEnabled () )
245
+ {
246
+ toolTip += " <br> * " + tr ( " Project CRS transformation is turned on and ellipsoidal calculation is selected." ) + " " ;
247
+ toolTip += " <br> * " + tr ( " The coordinates are transformed to the chosen ellipsoid (%1), and the result is in meters" ).arg ( mDa .ellipsoid () );
248
+ }
249
+ else
250
+ {
251
+ toolTip += " <br> * " + tr ( " Project CRS transformation is turned on but ellipsoidal calculation is not selected." );
252
+ toolTip += " <br> * " + tr ( " The canvas units setting is taken from the project CRS (%1)." ).arg ( QGis::tr ( mapUnits ) );
253
+ }
238
254
}
239
255
256
+ if (( mapUnits == QGis::Meters && displayUnits == QGis::Feet ) || ( mapUnits == QGis::Feet && displayUnits == QGis::Meters ) )
257
+ {
258
+ toolTip += " <br> * " + tr ( " Finally, the value is converted from %2 to %3." ).arg ( QGis::tr ( mapUnits ) ).arg ( QGis::tr ( displayUnits ) );
259
+ }
260
+
261
+ editTotal->setToolTip ( toolTip );
262
+ mTable ->setToolTip ( toolTip );
263
+
264
+ int decimalPlaces = settings.value ( " /qgis/measure/decimalplaces" , " 3" ).toInt ();
265
+
266
+ mTable ->setHeaderLabels ( QStringList ( tr ( " Segments [%1]" ).arg ( QGis::tr ( displayUnits ) ) ) );
267
+
240
268
if ( mMeasureArea )
241
269
{
242
270
mTable ->hide ();
@@ -247,52 +275,23 @@ void QgsMeasureDialog::updateUi()
247
275
mTable ->show ();
248
276
editTotal->setText ( formatDistance ( 0 , decimalPlaces ) );
249
277
}
250
-
251
- configureDistanceArea ();
252
278
}
253
279
254
280
void QgsMeasureDialog::convertMeasurement ( double &measure, QGis::UnitType &u, bool isArea )
255
281
{
256
282
// Helper for converting between meters and feet
257
283
// The parameter &u is out only...
258
284
285
+ // Get the canvas units
259
286
QGis::UnitType myUnits = mTool ->canvas ()->mapUnits ();
260
- if (( myUnits == QGis::Degrees || myUnits == QGis::Feet ) &&
261
- mcbProjectionEnabled->isChecked () )
262
- {
263
- // Measuring on an ellipsoid returns meters, and so does using projections???
264
- myUnits = QGis::Meters;
265
- QgsDebugMsg ( " We're measuring on an ellipsoid or using projections, the system is returning meters" );
266
- }
267
287
268
288
// Get the units for display
269
289
QSettings settings;
270
- QString myDisplayUnitsTxt = settings.value ( " /qgis/measure/displayunits" , " meters " ) .toString ();
290
+ QGis::UnitType displayUnits = QGis::fromLiteral ( settings.value ( " /qgis/measure/displayunits" , QGis::toLiteral ( QGis::Meters ) ) .toString () );
271
291
272
- // Only convert between meters and feet
273
- if ( myUnits == QGis::Meters && myDisplayUnitsTxt == " feet" )
274
- {
275
- QgsDebugMsg ( QString ( " Converting %1 meters" ).arg ( QString::number ( measure ) ) );
276
- measure /= 0.3048 ;
277
- if ( isArea )
278
- {
279
- measure /= 0.3048 ;
280
- }
281
- QgsDebugMsg ( QString ( " to %1 feet" ).arg ( QString::number ( measure ) ) );
282
- myUnits = QGis::Feet;
283
- }
284
- if ( myUnits == QGis::Feet && myDisplayUnitsTxt == " meters" )
285
- {
286
- QgsDebugMsg ( QString ( " Converting %1 feet" ).arg ( QString::number ( measure ) ) );
287
- measure *= 0.3048 ;
288
- if ( isArea )
289
- {
290
- measure *= 0.3048 ;
291
- }
292
- QgsDebugMsg ( QString ( " to %1 meters" ).arg ( QString::number ( measure ) ) );
293
- myUnits = QGis::Meters;
294
- }
292
+ QgsDebugMsg ( QString ( " Preferred display units are %1" ).arg ( QGis::toLiteral ( displayUnits ) ) );
295
293
294
+ mDa .convertMeasurement ( measure, myUnits, displayUnits, isArea );
296
295
u = myUnits;
297
296
}
298
297
@@ -301,9 +300,13 @@ void QgsMeasureDialog::changeProjectionEnabledState()
301
300
// store value
302
301
QSettings settings;
303
302
if ( mcbProjectionEnabled->isChecked () )
303
+ {
304
304
settings.setValue ( " /qgis/measure/projectionEnabled" , 2 );
305
+ }
305
306
else
307
+ {
306
308
settings.setValue ( " /qgis/measure/projectionEnabled" , 0 );
309
+ }
307
310
308
311
// clear interface
309
312
mTable ->clear ();
@@ -362,5 +365,6 @@ void QgsMeasureDialog::configureDistanceArea()
362
365
QString ellipsoidId = settings.value ( " /qgis/measure/ellipsoid" , " WGS84" ).toString ();
363
366
mDa .setSourceCrs ( mTool ->canvas ()->mapRenderer ()->destinationCrs ().srsid () );
364
367
mDa .setEllipsoid ( ellipsoidId );
365
- mDa .setProjectionsEnabled ( mcbProjectionEnabled->isChecked () );
368
+ // Only use ellipsoidal calculation when project wide transformation is enabled.
369
+ mDa .setEllipsoidalMode ( mcbProjectionEnabled->isChecked () && mTool ->canvas ()->hasCrsTransformEnabled () );
366
370
}
0 commit comments