@@ -55,10 +55,20 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WindowFlags f )
55
55
else
56
56
mUnitsCombo ->setCurrentIndex ( mUnitsCombo ->findData ( QgsProject::instance ()->distanceUnits () ) );
57
57
58
+ if ( !mTool ->canvas ()->mapSettings ().destinationCrs ().isValid () )
59
+ {
60
+ mUnitsCombo ->setEnabled ( false );
61
+ if ( mMeasureArea )
62
+ mUnitsCombo ->setCurrentIndex ( mUnitsCombo ->findData ( QgsUnitTypes::DistanceUnknownUnit ) );
63
+ else
64
+ mUnitsCombo ->setCurrentIndex ( mUnitsCombo ->findData ( QgsUnitTypes::AreaUnknownUnit ) );
65
+ }
66
+
58
67
updateSettings ();
59
68
60
69
connect ( mUnitsCombo , SIGNAL ( currentIndexChanged ( int ) ), this , SLOT ( unitsChanged ( int ) ) );
61
70
connect ( buttonBox, SIGNAL ( rejected () ), this , SLOT ( reject () ) );
71
+ connect ( mTool ->canvas (), &QgsMapCanvas::destinationCrsChanged, this , &QgsMeasureDialog::crsChanged );
62
72
63
73
groupBox->setCollapsed ( true );
64
74
}
@@ -68,6 +78,23 @@ void QgsMeasureDialog::openConfigTab()
68
78
QgisApp::instance ()->showOptionsDialog ( this , QStringLiteral ( " mOptionsPageMapTools" ) );
69
79
}
70
80
81
+ void QgsMeasureDialog::crsChanged ()
82
+ {
83
+ if ( !mTool ->canvas ()->mapSettings ().destinationCrs ().isValid () )
84
+ {
85
+ mUnitsCombo ->setEnabled ( false );
86
+ if ( mMeasureArea )
87
+ mUnitsCombo ->setCurrentIndex ( mUnitsCombo ->findData ( QgsUnitTypes::DistanceUnknownUnit ) );
88
+ else
89
+ mUnitsCombo ->setCurrentIndex ( mUnitsCombo ->findData ( QgsUnitTypes::AreaUnknownUnit ) );
90
+ }
91
+ else
92
+ {
93
+ mUnitsCombo ->setEnabled ( true );
94
+ }
95
+ updateUi ();
96
+ }
97
+
71
98
void QgsMeasureDialog::updateSettings ()
72
99
{
73
100
QSettings settings;
@@ -268,8 +295,16 @@ void QgsMeasureDialog::updateUi()
268
295
269
296
if ( mMeasureArea )
270
297
{
271
- if ( mTool ->canvas ()->mapSettings ().destinationCrs ().mapUnits () == QgsUnitTypes::DistanceDegrees
272
- && ( mAreaUnits == QgsUnitTypes::AreaSquareDegrees || mAreaUnits == QgsUnitTypes::AreaUnknownUnit ) )
298
+ if ( !mTool ->canvas ()->mapSettings ().destinationCrs ().isValid () )
299
+ {
300
+ // no CRS => no units, newb!
301
+ toolTip += " <br> * " + tr ( " No map projection set, so area is calculated using cartesian calculations." );
302
+ toolTip += " <br> * " + tr ( " Units are unknown." );
303
+ forceCartesian = true ;
304
+ convertToDisplayUnits = false ;
305
+ }
306
+ else if ( mTool ->canvas ()->mapSettings ().destinationCrs ().mapUnits () == QgsUnitTypes::DistanceDegrees
307
+ && ( mAreaUnits == QgsUnitTypes::AreaSquareDegrees || mAreaUnits == QgsUnitTypes::AreaUnknownUnit ) )
273
308
{
274
309
// both source and destination units are degrees
275
310
toolTip += " <br> * " + tr ( " Both project CRS (%1) and measured area are in degrees, so area is calculated using cartesian calculations in square degrees." ).arg (
@@ -294,7 +329,7 @@ void QgsMeasureDialog::updateUi()
294
329
toolTip += tr ( " Area is calculated in %1, based on project CRS (%2)." ).arg ( QgsUnitTypes::toString ( resultUnit ),
295
330
mTool ->canvas ()->mapSettings ().destinationCrs ().description () );
296
331
}
297
- setWindowTitle ( tr ( " Measure (OTF on) " ) );
332
+ setWindowTitle ( tr ( " Measure" ) );
298
333
299
334
if ( QgsUnitTypes::unitType ( resultUnit ) == QgsUnitTypes::Geographic &&
300
335
QgsUnitTypes::unitType ( mAreaUnits ) == QgsUnitTypes::Standard )
@@ -330,8 +365,16 @@ void QgsMeasureDialog::updateUi()
330
365
}
331
366
else
332
367
{
333
- if ( mTool ->canvas ()->mapSettings ().destinationCrs ().mapUnits () == QgsUnitTypes::DistanceDegrees
334
- && mDistanceUnits == QgsUnitTypes::DistanceDegrees )
368
+ if ( !mTool ->canvas ()->mapSettings ().destinationCrs ().isValid () )
369
+ {
370
+ // no CRS => no units, newb!
371
+ toolTip += " <br> * " + tr ( " No map projection set, so distance is calculated using cartesian calculations." );
372
+ toolTip += " <br> * " + tr ( " Units are unknown." );
373
+ forceCartesian = true ;
374
+ convertToDisplayUnits = false ;
375
+ }
376
+ else if ( mTool ->canvas ()->mapSettings ().destinationCrs ().mapUnits () == QgsUnitTypes::DistanceDegrees
377
+ && mDistanceUnits == QgsUnitTypes::DistanceDegrees )
335
378
{
336
379
// both source and destination units are degrees
337
380
toolTip += " <br> * " + tr ( " Both project CRS (%1) and measured length are in degrees, so distance is calculated using cartesian calculations in degrees." ).arg (
@@ -356,7 +399,7 @@ void QgsMeasureDialog::updateUi()
356
399
toolTip += tr ( " Distance is calculated in %1, based on project CRS (%2)." ).arg ( QgsUnitTypes::toString ( resultUnit ),
357
400
mTool ->canvas ()->mapSettings ().destinationCrs ().description () );
358
401
}
359
- setWindowTitle ( tr ( " Measure (OTF on) " ) );
402
+ setWindowTitle ( tr ( " Measure" ) );
360
403
361
404
if ( QgsUnitTypes::unitType ( resultUnit ) == QgsUnitTypes::Geographic &&
362
405
QgsUnitTypes::unitType ( mDistanceUnits ) == QgsUnitTypes::Standard )
@@ -402,7 +445,14 @@ void QgsMeasureDialog::updateUi()
402
445
else
403
446
{
404
447
mUnitsCombo ->setCurrentIndex ( mUnitsCombo ->findData ( mDistanceUnits ) );
405
- mTable ->setHeaderLabels ( QStringList ( tr ( " Segments [%1]" ).arg ( QgsUnitTypes::toString ( mDistanceUnits ) ) ) );
448
+ if ( mDistanceUnits != QgsUnitTypes::DistanceUnknownUnit )
449
+ {
450
+ mTable ->setHeaderLabels ( QStringList ( tr ( " Segments [%1]" ).arg ( QgsUnitTypes::toString ( mDistanceUnits ) ) ) );
451
+ }
452
+ else
453
+ {
454
+ mTable ->setHeaderLabels ( QStringList ( tr ( " Segments" ) ) );
455
+ }
406
456
}
407
457
408
458
if ( mMeasureArea )
@@ -481,6 +531,7 @@ void QgsMeasureDialog::repopulateComboBoxUnits( bool isArea )
481
531
mUnitsCombo ->addItem ( QgsUnitTypes::toString ( QgsUnitTypes::DistanceMiles ), QgsUnitTypes::DistanceMiles );
482
532
mUnitsCombo ->addItem ( QgsUnitTypes::toString ( QgsUnitTypes::DistanceDegrees ), QgsUnitTypes::DistanceDegrees );
483
533
mUnitsCombo ->addItem ( QgsUnitTypes::toString ( QgsUnitTypes::DistanceNauticalMiles ), QgsUnitTypes::DistanceNauticalMiles );
534
+ mUnitsCombo ->addItem ( tr ( " map units" ), QgsUnitTypes::DistanceUnknownUnit );
484
535
}
485
536
}
486
537
0 commit comments