Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 26, 2024
1 parent cdbf6b8 commit d27654a
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 76 deletions.
3 changes: 1 addition & 2 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2980,7 +2980,7 @@ void QgisApp::createActions()
connect( mActionMeasureArea, &QAction::triggered, this, &QgisApp::measureArea );
connect( mActionMeasureAngle, &QAction::triggered, this, &QgisApp::measureAngle );
connect( mActionMeasureBearing, &QAction::triggered, this, [=] { setMapTool( mMapTools->mapTool( QgsAppMapTools::MeasureBearing ) ); } );
connect( mActionMeasureRadius, &QAction::triggered, this, [ = ] { setMapTool( mMapTools->mapTool( QgsAppMapTools::MeasureRadius ) ); } );
connect( mActionMeasureRadius, &QAction::triggered, this, [=] { setMapTool( mMapTools->mapTool( QgsAppMapTools::MeasureRadius ) ); } );
connect( mActionZoomFullExtent, &QAction::triggered, this, &QgisApp::zoomFull );
connect( mActionZoomToLayer, &QAction::triggered, this, &QgisApp::zoomToLayerExtent );
connect( mActionZoomToLayers, &QAction::triggered, this, &QgisApp::zoomToLayerExtent );
Expand Down Expand Up @@ -3721,7 +3721,6 @@ void QgisApp::createToolBars()
case 4:
defMeasureAction = mActionMeasureRadius;
break;

}
bt->setDefaultAction( defMeasureAction );
QAction *measureAction = mAttributesToolBar->insertWidget( mActionMapTips, bt );
Expand Down
62 changes: 22 additions & 40 deletions src/app/qgsmeasuredialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool *tool, Qt::WindowFlags f )
radiusLayout->addWidget( mEditExteriorX, 1, 1 );
radiusLayout->addWidget( lblExtY, 1, 2 );
radiusLayout->addWidget( mEditExteriorY, 1, 3 );
mGrid->addLayout(radiusLayout, 0, 0, 2, 4);
mGrid->addLayout( radiusLayout, 0, 0, 2, 4 );
totalDistanceLabel->setText( "Radius" );
}

Expand Down Expand Up @@ -193,9 +193,7 @@ void QgsMeasureDialog::updateSettings()
// Calling projChanged() will set the ellipsoid and clear then re-populate the table
projChanged();

if ( mCartesian->isChecked() || !mCanvas->mapSettings().destinationCrs().isValid() ||
( mCanvas->mapSettings().destinationCrs().mapUnits() == Qgis::DistanceUnit::Degrees
&& mDistanceUnits == Qgis::DistanceUnit::Degrees ) )
if ( mCartesian->isChecked() || !mCanvas->mapSettings().destinationCrs().isValid() || ( mCanvas->mapSettings().destinationCrs().mapUnits() == Qgis::DistanceUnit::Degrees && mDistanceUnits == Qgis::DistanceUnit::Degrees ) )
{
mDa.setEllipsoid( geoNone() );
}
Expand All @@ -220,7 +218,7 @@ void QgsMeasureDialog::unitsChanged( int index )
updateUi();
}

void QgsMeasureDialog:: updateUnitsMembers()
void QgsMeasureDialog::updateUnitsMembers()
{
if ( mMeasureArea )
{
Expand Down Expand Up @@ -495,7 +493,7 @@ QString QgsMeasureDialog::formatDistance( double distance, bool convertUnits ) c
distance = convertLength( distance, mDistanceUnits );

int decimals = mDecimalPlaces;
if ( mDistanceUnits == Qgis::DistanceUnit::Degrees && distance < 1 )
if ( mDistanceUnits == Qgis::DistanceUnit::Degrees && distance < 1 )
{
// special handling for degrees - because we can't use smaller units (eg m->mm), we need to make sure there's
// enough decimal places to show a usable measurement value
Expand Down Expand Up @@ -526,8 +524,7 @@ void QgsMeasureDialog::updateUi()
mDa.setEllipsoid( QgsProject::instance()->ellipsoid() );
mConvertToDisplayUnits = true;

const auto getEllipsoidFriendlyName = [this]()
{
const auto getEllipsoidFriendlyName = [this]() {
// If mDa.ellipsoid is an acronym (e.g "EPSG:7030"), retrieve the user
// friendly name ("WGS 84 (EPSG:7030)")
QString ellipsoid = mDa.ellipsoid();
Expand Down Expand Up @@ -568,8 +565,7 @@ void QgsMeasureDialog::updateUi()
&& ( mAreaUnits == Qgis::AreaUnit::SquareDegrees || mAreaUnits == Qgis::AreaUnit::Unknown ) )
{
//both source and destination units are degrees
toolTip += "<br> * " + tr( "Both project CRS (%1) and measured area are in degrees, so area is calculated using Cartesian calculations in square degrees." ).arg(
mCanvas->mapSettings().destinationCrs().userFriendlyIdentifier() );
toolTip += "<br> * " + tr( "Both project CRS (%1) and measured area are in degrees, so area is calculated using Cartesian calculations in square degrees." ).arg( mCanvas->mapSettings().destinationCrs().userFriendlyIdentifier() );
mDa.setEllipsoid( geoNone() );
mConvertToDisplayUnits = false; //not required since we will be measuring in degrees
}
Expand All @@ -580,42 +576,36 @@ void QgsMeasureDialog::updateUi()
{
resultUnit = Qgis::AreaUnit::SquareMeters;
toolTip += "<br> * " + tr( "Project ellipsoidal calculation is selected." ) + ' ';
toolTip += "<br> * " + tr( "The coordinates are transformed to the chosen ellipsoid (%1), and the area is calculated in %2." ).arg( getEllipsoidFriendlyName(),
QgsUnitTypes::toString( resultUnit ) );
toolTip += "<br> * " + tr( "The coordinates are transformed to the chosen ellipsoid (%1), and the area is calculated in %2." ).arg( getEllipsoidFriendlyName(), QgsUnitTypes::toString( resultUnit ) );
}
else
{
resultUnit = QgsUnitTypes::distanceToAreaUnit( mCanvas->mapSettings().destinationCrs().mapUnits() );
toolTip += "<br> * " + tr( "Project ellipsoidal calculation is not selected." ) + ' ';
toolTip += tr( "Area is calculated in %1, based on project CRS (%2)." ).arg( QgsUnitTypes::toString( resultUnit ),
mCanvas->mapSettings().destinationCrs().userFriendlyIdentifier() );
toolTip += tr( "Area is calculated in %1, based on project CRS (%2)." ).arg( QgsUnitTypes::toString( resultUnit ), mCanvas->mapSettings().destinationCrs().userFriendlyIdentifier() );
}
setWindowTitle( tr( "Measure" ) );

if ( QgsUnitTypes::unitType( resultUnit ) == Qgis::DistanceUnitType::Geographic &&
QgsUnitTypes::unitType( mAreaUnits ) == Qgis::DistanceUnitType::Standard )
if ( QgsUnitTypes::unitType( resultUnit ) == Qgis::DistanceUnitType::Geographic && QgsUnitTypes::unitType( mAreaUnits ) == Qgis::DistanceUnitType::Standard )
{
toolTip += QLatin1String( "<br> * Area is roughly converted to square meters by using scale at equator (1 degree = 111319.49 meters)." );
resultUnit = Qgis::AreaUnit::SquareMeters;
}
else if ( QgsUnitTypes::unitType( resultUnit ) == Qgis::DistanceUnitType::Standard &&
QgsUnitTypes::unitType( mAreaUnits ) == Qgis::DistanceUnitType::Geographic )
else if ( QgsUnitTypes::unitType( resultUnit ) == Qgis::DistanceUnitType::Standard && QgsUnitTypes::unitType( mAreaUnits ) == Qgis::DistanceUnitType::Geographic )
{
toolTip += QLatin1String( "<br> * Area is roughly converted to square degrees by using scale at equator (1 degree = 111319.49 meters)." );
resultUnit = Qgis::AreaUnit::SquareDegrees;
}

if ( resultUnit != mAreaUnits )
{
if ( QgsUnitTypes::unitType( resultUnit ) == Qgis::DistanceUnitType::Standard &&
QgsUnitTypes::unitType( mAreaUnits ) == Qgis::DistanceUnitType::Standard )
if ( QgsUnitTypes::unitType( resultUnit ) == Qgis::DistanceUnitType::Standard && QgsUnitTypes::unitType( mAreaUnits ) == Qgis::DistanceUnitType::Standard )
{
// only shown if both conditions are true:
// - the display unit is a standard distance measurement (e.g., square feet)
// - either the canvas units is also a standard distance OR we are using an ellipsoid (in which case the
// value will be in square meters)
toolTip += "<br> * " + tr( "The value is converted from %1 to %2." ).arg( QgsUnitTypes::toString( resultUnit ),
QgsUnitTypes::toString( mAreaUnits ) );
toolTip += "<br> * " + tr( "The value is converted from %1 to %2." ).arg( QgsUnitTypes::toString( resultUnit ), QgsUnitTypes::toString( mAreaUnits ) );
}
else
{
Expand Down Expand Up @@ -646,8 +636,7 @@ void QgsMeasureDialog::updateUi()
&& mDistanceUnits == Qgis::DistanceUnit::Degrees )
{
//both source and destination units are degrees
toolTip += "<br> * " + tr( "Both project CRS (%1) and measured length are in degrees, so distance is calculated using Cartesian calculations in degrees." ).arg(
mCanvas->mapSettings().destinationCrs().userFriendlyIdentifier() );
toolTip += "<br> * " + tr( "Both project CRS (%1) and measured length are in degrees, so distance is calculated using Cartesian calculations in degrees." ).arg( mCanvas->mapSettings().destinationCrs().userFriendlyIdentifier() );
mDa.setEllipsoid( geoNone() );
mConvertToDisplayUnits = false; //not required since we will be measuring in degrees
}
Expand All @@ -658,42 +647,36 @@ void QgsMeasureDialog::updateUi()
{
resultUnit = Qgis::DistanceUnit::Meters;
toolTip += "<br> * " + tr( "Project ellipsoidal calculation is selected." ) + ' ';
toolTip += "<br> * " + tr( "The coordinates are transformed to the chosen ellipsoid (%1), and the distance is calculated in %2." ).arg( getEllipsoidFriendlyName(),
QgsUnitTypes::toString( resultUnit ) );
toolTip += "<br> * " + tr( "The coordinates are transformed to the chosen ellipsoid (%1), and the distance is calculated in %2." ).arg( getEllipsoidFriendlyName(), QgsUnitTypes::toString( resultUnit ) );
}
else
{
resultUnit = mCanvas->mapSettings().destinationCrs().mapUnits();
toolTip += "<br> * " + tr( "Project ellipsoidal calculation is not selected." ) + ' ';
toolTip += tr( "Distance is calculated in %1, based on project CRS (%2)." ).arg( QgsUnitTypes::toString( resultUnit ),
mCanvas->mapSettings().destinationCrs().userFriendlyIdentifier() );
toolTip += tr( "Distance is calculated in %1, based on project CRS (%2)." ).arg( QgsUnitTypes::toString( resultUnit ), mCanvas->mapSettings().destinationCrs().userFriendlyIdentifier() );
}
setWindowTitle( tr( "Measure" ) );

if ( QgsUnitTypes::unitType( resultUnit ) == Qgis::DistanceUnitType::Geographic &&
QgsUnitTypes::unitType( mDistanceUnits ) == Qgis::DistanceUnitType::Standard )
if ( QgsUnitTypes::unitType( resultUnit ) == Qgis::DistanceUnitType::Geographic && QgsUnitTypes::unitType( mDistanceUnits ) == Qgis::DistanceUnitType::Standard )
{
toolTip += QLatin1String( "<br> * Distance is roughly converted to meters by using scale at equator (1 degree = 111319.49 meters)." );
resultUnit = Qgis::DistanceUnit::Meters;
}
else if ( QgsUnitTypes::unitType( resultUnit ) == Qgis::DistanceUnitType::Standard &&
QgsUnitTypes::unitType( mDistanceUnits ) == Qgis::DistanceUnitType::Geographic )
else if ( QgsUnitTypes::unitType( resultUnit ) == Qgis::DistanceUnitType::Standard && QgsUnitTypes::unitType( mDistanceUnits ) == Qgis::DistanceUnitType::Geographic )
{
toolTip += QLatin1String( "<br> * Distance is roughly converted to degrees by using scale at equator (1 degree = 111319.49 meters)." );
resultUnit = Qgis::DistanceUnit::Degrees;
}

if ( resultUnit != mDistanceUnits )
{
if ( QgsUnitTypes::unitType( resultUnit ) == Qgis::DistanceUnitType::Standard &&
QgsUnitTypes::unitType( mDistanceUnits ) == Qgis::DistanceUnitType::Standard )
if ( QgsUnitTypes::unitType( resultUnit ) == Qgis::DistanceUnitType::Standard && QgsUnitTypes::unitType( mDistanceUnits ) == Qgis::DistanceUnitType::Standard )
{
// only shown if both conditions are true:
// - the display unit is a standard distance measurement (e.g., feet)
// - either the canvas units is also a standard distance OR we are using an ellipsoid (in which case the
// value will be in meters)
toolTip += "<br> * " + tr( "The value is converted from %1 to %2." ).arg( QgsUnitTypes::toString( resultUnit ),
QgsUnitTypes::toString( mDistanceUnits ) );
toolTip += "<br> * " + tr( "The value is converted from %1 to %2." ).arg( QgsUnitTypes::toString( resultUnit ), QgsUnitTypes::toString( mDistanceUnits ) );
}
else
{
Expand Down Expand Up @@ -734,9 +717,9 @@ void QgsMeasureDialog::updateUi()
{
mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( static_cast< int >( mDistanceUnits ) ) );
if ( mDistanceUnits != Qgis::DistanceUnit::Unknown )
mTable->headerItem()->setText( Columns::Distance, tr( "Segments [%1]" ).arg( QgsUnitTypes::toString( mDistanceUnits ) ) );
mTable->headerItem()->setText( Columns::Distance, tr( "Segments [%1]" ).arg( QgsUnitTypes::toString( mDistanceUnits ) ) );
else
mTable->headerItem()->setText( Columns::Distance, tr( "Segments" ) );
mTable->headerItem()->setText( Columns::Distance, tr( "Segments" ) );
}
}

Expand Down Expand Up @@ -945,8 +928,7 @@ void QgsMeasureDialog::copyMeasurements()
}


auto replaceDecimalSeparator = [ alwaysUseDecimalPoint ]( const QString & value ) -> QString
{
auto replaceDecimalSeparator = [alwaysUseDecimalPoint]( const QString &value ) -> QString {
QString result = value;
if ( alwaysUseDecimalPoint && QLocale().decimalPoint() != QLatin1String( "." ) )
result.replace( QLocale().decimalPoint(), QStringLiteral( "." ) );
Expand Down
8 changes: 3 additions & 5 deletions src/app/qgsmeasuredialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class APP_EXPORT QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase
Q_OBJECT

public:

static const QgsSettingsEntryBool *settingClipboardHeader;
static const QgsSettingsEntryString *settingClipboardSeparator;
static const QgsSettingsEntryBool *settingClipboardAlwaysUseDecimalPoint;
Expand Down Expand Up @@ -90,7 +89,6 @@ class APP_EXPORT QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase
void projChanged();

private:

//! \since QGIS 3.32 columns
enum Columns
{
Expand Down Expand Up @@ -144,13 +142,13 @@ class APP_EXPORT QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase
Qgis::DistanceUnit mCanvasUnits = Qgis::DistanceUnit::Unknown;

//! Current unit for distance values
Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Unknown;
Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Unknown;

//! Current map unit for distance values
Qgis::DistanceUnit mMapDistanceUnits = Qgis::DistanceUnit::Unknown;
Qgis::DistanceUnit mMapDistanceUnits = Qgis::DistanceUnit::Unknown;

//! Current unit for area values
Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::Unknown;
Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::Unknown;

//! Our measurement object
QgsDistanceArea mDa;
Expand Down
29 changes: 12 additions & 17 deletions src/app/qgsmeasuretool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <QMessageBox>


QgsMeasureTool::QgsMeasureTool( QgsMapCanvas *canvas, bool measureArea, bool measureRadius )
QgsMeasureTool::QgsMeasureTool( QgsMapCanvas *canvas, bool measureArea, bool measureRadius )
: QgsMapTool( canvas )
, mMeasureArea( measureArea )
, mMeasureRadius( measureRadius )
Expand Down Expand Up @@ -77,20 +77,16 @@ void QgsMeasureTool::activate()

// If we suspect that they have data that is projected, yet the
// map CRS is set to a geographic one, warn them.
if ( mCanvas->mapSettings().destinationCrs().isValid() &&
mCanvas->mapSettings().destinationCrs().isGeographic() &&
( mCanvas->extent().height() > 360 ||
mCanvas->extent().width() > 720 ) )
if ( mCanvas->mapSettings().destinationCrs().isValid() && mCanvas->mapSettings().destinationCrs().isGeographic() && ( mCanvas->extent().height() > 360 || mCanvas->extent().width() > 720 ) )
{
QMessageBox::warning( nullptr, tr( "Incorrect Measure Results" ),
tr( "<p>This map is defined with a geographic coordinate system "
"(latitude/longitude) "
"but the map extents suggests that it is actually a projected "
"coordinate system (e.g., Mercator). "
"If so, the results from line or area measurements will be "
"incorrect.</p>"
"<p>To fix this, explicitly set an appropriate map coordinate "
"system using the <tt>Settings:Project Properties</tt> menu." ) );
QMessageBox::warning( nullptr, tr( "Incorrect Measure Results" ), tr( "<p>This map is defined with a geographic coordinate system "
"(latitude/longitude) "
"but the map extents suggests that it is actually a projected "
"coordinate system (e.g., Mercator). "
"If so, the results from line or area measurements will be "
"incorrect.</p>"
"<p>To fix this, explicitly set an appropriate map coordinate "
"system using the <tt>Settings:Project Properties</tt> menu." ) );
mWrongProjectProjection = true;
}
}
Expand Down Expand Up @@ -193,7 +189,7 @@ void QgsMeasureTool::updateSettings()
int nbVertices = mRubberBandPoints->numberOfVertices();

// Add a temporary point to the rubber band if the user is currently measuring
if ( !mDone && mRubberBand->size() > 0 && nbTempVertices <= nbVertices )
if ( !mDone && mRubberBand->size() > 0 && nbTempVertices <= nbVertices )
{
mRubberBand->addPoint( mPoints.last() );
}
Expand All @@ -216,7 +212,7 @@ void QgsMeasureTool::canvasMoveEvent( QgsMapMouseEvent *e )
const QgsPointXY point = e->snapPoint();
mSnapIndicator->setMatch( e->mapPointMatch() );

if ( ! mDone )
if ( !mDone )
{
mRubberBand->movePoint( point );
mDialog->mouseMove( point );
Expand Down Expand Up @@ -266,7 +262,6 @@ void QgsMeasureTool::canvasReleaseEvent( QgsMapMouseEvent *e )
}

mDialog->show();

}

QgsGeometry QgsMeasureTool::createCircleGeom()
Expand Down
2 changes: 0 additions & 2 deletions src/app/qgsmeasuretool.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class APP_EXPORT QgsMeasureTool : public QgsMapTool
Q_OBJECT

public:

QgsMeasureTool( QgsMapCanvas *canvas, bool measureArea, bool measureRadius );

~QgsMeasureTool() override;
Expand Down Expand Up @@ -78,7 +77,6 @@ class APP_EXPORT QgsMeasureTool : public QgsMapTool
void updateSettings();

protected:

QVector<QgsPointXY> mPoints;

QgsMeasureDialog *mDialog = nullptr;
Expand Down
Loading

0 comments on commit d27654a

Please sign in to comment.