3333
3434QgsMeasureDialog::QgsMeasureDialog ( QgsMeasureTool *tool, Qt::WindowFlags f )
3535 : QDialog( tool->canvas ()->topLevelWidget(), f )
36+ , mMeasureArea( tool->measureArea () )
3637 , mTool( tool )
38+ , mCanvas( tool->canvas () )
3739{
3840 setupUi ( this );
3941 connect ( buttonBox, &QDialogButtonBox::helpRequested, this , &QgsMeasureDialog::showHelp );
@@ -47,16 +49,13 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool *tool, Qt::WindowFlags f )
4749 buttonBox->addButton ( cb, QDialogButtonBox::ActionRole );
4850 connect ( cb, &QAbstractButton::clicked, this , &QgsMeasureDialog::openConfigTab );
4951
50- mMeasureArea = tool->measureArea ();
51- mTotal = 0 .;
52-
5352 repopulateComboBoxUnits ( mMeasureArea );
5453 if ( mMeasureArea )
5554 mUnitsCombo ->setCurrentIndex ( mUnitsCombo ->findData ( QgsProject::instance ()->areaUnits () ) );
5655 else
5756 mUnitsCombo ->setCurrentIndex ( mUnitsCombo ->findData ( QgsProject::instance ()->distanceUnits () ) );
5857
59- if ( !mTool -> canvas () ->mapSettings ().destinationCrs ().isValid () )
58+ if ( !mCanvas ->mapSettings ().destinationCrs ().isValid () )
6059 {
6160 mUnitsCombo ->setEnabled ( false );
6261 if ( mMeasureArea )
@@ -69,7 +68,7 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool *tool, Qt::WindowFlags f )
6968
7069 connect ( mUnitsCombo , static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this , &QgsMeasureDialog::unitsChanged );
7170 connect ( buttonBox, &QDialogButtonBox::rejected, this , &QgsMeasureDialog::reject );
72- connect ( mTool -> canvas () , &QgsMapCanvas::destinationCrsChanged, this , &QgsMeasureDialog::crsChanged );
71+ connect ( mCanvas , &QgsMapCanvas::destinationCrsChanged, this , &QgsMeasureDialog::crsChanged );
7372
7473 groupBox->setCollapsed ( true );
7574}
@@ -81,7 +80,7 @@ void QgsMeasureDialog::openConfigTab()
8180
8281void QgsMeasureDialog::crsChanged ()
8382{
84- if ( !mTool -> canvas () ->mapSettings ().destinationCrs ().isValid () )
83+ if ( !mCanvas ->mapSettings ().destinationCrs ().isValid () )
8584 {
8685 mUnitsCombo ->setEnabled ( false );
8786 if ( mMeasureArea )
@@ -101,11 +100,11 @@ void QgsMeasureDialog::updateSettings()
101100 QgsSettings settings;
102101
103102 mDecimalPlaces = settings.value ( QStringLiteral ( " qgis/measure/decimalplaces" ), " 3" ).toInt ();
104- mCanvasUnits = mTool -> canvas () ->mapUnits ();
103+ mCanvasUnits = mCanvas ->mapUnits ();
105104 // Configure QgsDistanceArea
106105 mDistanceUnits = QgsProject::instance ()->distanceUnits ();
107106 mAreaUnits = QgsProject::instance ()->areaUnits ();
108- mDa .setSourceCrs ( mTool -> canvas () ->mapSettings ().destinationCrs (), QgsProject::instance ()->transformContext () );
107+ mDa .setSourceCrs ( mCanvas ->mapSettings ().destinationCrs (), QgsProject::instance ()->transformContext () );
109108 mDa .setEllipsoid ( QgsProject::instance ()->ellipsoid () );
110109
111110 mTable ->clear ();
@@ -306,20 +305,20 @@ void QgsMeasureDialog::updateUi()
306305
307306 if ( mMeasureArea )
308307 {
309- if ( !mTool -> canvas () ->mapSettings ().destinationCrs ().isValid () )
308+ if ( !mCanvas ->mapSettings ().destinationCrs ().isValid () )
310309 {
311310 // no CRS => no units, newb!
312311 toolTip += " <br> * " + tr ( " No map projection set, so area is calculated using Cartesian calculations." );
313312 toolTip += " <br> * " + tr ( " Units are unknown." );
314313 forceCartesian = true ;
315314 convertToDisplayUnits = false ;
316315 }
317- else if ( mTool -> canvas () ->mapSettings ().destinationCrs ().mapUnits () == QgsUnitTypes::DistanceDegrees
316+ else if ( mCanvas ->mapSettings ().destinationCrs ().mapUnits () == QgsUnitTypes::DistanceDegrees
318317 && ( mAreaUnits == QgsUnitTypes::AreaSquareDegrees || mAreaUnits == QgsUnitTypes::AreaUnknownUnit ) )
319318 {
320319 // both source and destination units are degrees
321320 toolTip += " <br> * " + tr ( " Both project CRS (%1) and measured area are in degrees, so area is calculated using Cartesian calculations in square degrees." ).arg (
322- mTool -> canvas () ->mapSettings ().destinationCrs ().description () );
321+ mCanvas ->mapSettings ().destinationCrs ().description () );
323322 forceCartesian = true ;
324323 convertToDisplayUnits = false ; // not required since we will be measuring in degrees
325324 }
@@ -335,10 +334,10 @@ void QgsMeasureDialog::updateUi()
335334 }
336335 else
337336 {
338- resultUnit = QgsUnitTypes::distanceToAreaUnit ( mTool -> canvas () ->mapSettings ().destinationCrs ().mapUnits () );
337+ resultUnit = QgsUnitTypes::distanceToAreaUnit ( mCanvas ->mapSettings ().destinationCrs ().mapUnits () );
339338 toolTip += " <br> * " + tr ( " Project ellipsoidal calculation is not selected." ) + ' ' ;
340339 toolTip += tr ( " Area is calculated in %1, based on project CRS (%2)." ).arg ( QgsUnitTypes::toString ( resultUnit ),
341- mTool -> canvas () ->mapSettings ().destinationCrs ().description () );
340+ mCanvas ->mapSettings ().destinationCrs ().description () );
342341 }
343342 setWindowTitle ( tr ( " Measure" ) );
344343
@@ -376,20 +375,20 @@ void QgsMeasureDialog::updateUi()
376375 }
377376 else
378377 {
379- if ( !mTool -> canvas () ->mapSettings ().destinationCrs ().isValid () )
378+ if ( !mCanvas ->mapSettings ().destinationCrs ().isValid () )
380379 {
381380 // no CRS => no units, newb!
382381 toolTip += " <br> * " + tr ( " No map projection set, so distance is calculated using Cartesian calculations." );
383382 toolTip += " <br> * " + tr ( " Units are unknown." );
384383 forceCartesian = true ;
385384 convertToDisplayUnits = false ;
386385 }
387- else if ( mTool -> canvas () ->mapSettings ().destinationCrs ().mapUnits () == QgsUnitTypes::DistanceDegrees
386+ else if ( mCanvas ->mapSettings ().destinationCrs ().mapUnits () == QgsUnitTypes::DistanceDegrees
388387 && mDistanceUnits == QgsUnitTypes::DistanceDegrees )
389388 {
390389 // both source and destination units are degrees
391390 toolTip += " <br> * " + tr ( " Both project CRS (%1) and measured length are in degrees, so distance is calculated using Cartesian calculations in degrees." ).arg (
392- mTool -> canvas () ->mapSettings ().destinationCrs ().description () );
391+ mCanvas ->mapSettings ().destinationCrs ().description () );
393392 forceCartesian = true ;
394393 convertToDisplayUnits = false ; // not required since we will be measuring in degrees
395394 }
@@ -405,10 +404,10 @@ void QgsMeasureDialog::updateUi()
405404 }
406405 else
407406 {
408- resultUnit = mTool -> canvas () ->mapSettings ().destinationCrs ().mapUnits ();
407+ resultUnit = mCanvas ->mapSettings ().destinationCrs ().mapUnits ();
409408 toolTip += " <br> * " + tr ( " Project ellipsoidal calculation is not selected." ) + ' ' ;
410409 toolTip += tr ( " Distance is calculated in %1, based on project CRS (%2)." ).arg ( QgsUnitTypes::toString ( resultUnit ),
411- mTool -> canvas () ->mapSettings ().destinationCrs ().description () );
410+ mCanvas ->mapSettings ().destinationCrs ().description () );
412411 }
413412 setWindowTitle ( tr ( " Measure" ) );
414413
0 commit comments