Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add message to QGIS status bar on selection of vertices #58811

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions src/app/mesh/qgsmaptooleditmeshframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
#include "qgsmaptooleditmeshframe.h"

#include <QMessageBox>
#include <QLocale>

#include "qgis.h"
#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsstatusbar.h"

#include "qgsadvanceddigitizingdockwidget.h"
#include "qgsdoublespinbox.h"
Expand All @@ -45,6 +47,7 @@
#include "qgsmeshselectbyexpressiondialog.h"
#include "qgsmaptoolidentify.h"
#include "qgsidentifymenu.h"
#include "qgsdistancearea.h"


//
Expand Down Expand Up @@ -331,6 +334,8 @@ QgsMapToolEditMeshFrame::QgsMapToolEditMeshFrame( QgsMapCanvas *canvas )
createZValueWidget();
} );

connect( this, &QgsMapToolEditMeshFrame::selectionChange, this, &QgsMapToolEditMeshFrame::updateStatusBarMessage );

setAutoSnapEnabled( true );
}

Expand Down Expand Up @@ -2841,3 +2846,59 @@ void QgsMapToolEditMeshFrame::showSelectByExpressionDialog()
connect( dialog, &QgsMeshSelectByExpressionDialog::select, this, &QgsMapToolEditMeshFrame::selectByExpression );
connect( dialog, &QgsMeshSelectByExpressionDialog::zoomToSelected, this, &QgsMapToolEditMeshFrame::onZoomToSelected );
}

void QgsMapToolEditMeshFrame::updateStatusBarMessage()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void QgsMapToolEditMeshFrame::updateStatusBarMessage()
void QgsMapToolEditMeshFrame::updateStatusBarMessage() const

{
if ( ! mSelectedVertices.isEmpty() )
{
QString message;
if ( mSelectedVertices.count() == 1 )
{
const QgsMesh &mesh = *mCurrentLayer->nativeMesh();
const int vertexId = mSelectedVertices.firstKey();
const QgsMeshVertex vertex = mesh.vertex( vertexId );

message = tr( "Selected mesh vertex ID: %1 at x: %2 y: %3 z: %4." ).arg( vertexId ).arg( QLocale().toString( vertex.x(), 'f' ) ).arg( QLocale().toString( vertex.y(), 'f' ) ).arg( QLocale().toString( vertex.z(), 'f' ) );
}
else if ( mSelectedVertices.count() == 2 )
{
const QgsMesh &mesh = *mCurrentLayer->nativeMesh();
const int vertexId1 = mSelectedVertices.firstKey();
const int vertexId2 = mSelectedVertices.lastKey();
const QgsMeshVertex vertex1 = mesh.vertex( vertexId1 );
const QgsMeshVertex vertex2 = mesh.vertex( vertexId2 );

QString formattedDistance;
double distance;
// if crs is valid calculate using QgsDistanceArea otherwise calculate just as distance
if ( mCurrentLayer->crs().isValid() )
{
QgsDistanceArea distArea = QgsDistanceArea();
distArea.setSourceCrs( mCurrentLayer->crs(), QgsProject::instance()->transformContext() );
distArea.setEllipsoid( QgsProject::instance()->ellipsoid() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to only set the ellipsoid for geographic crses, otherwise skip it so distArea it will calculate a cartesian distance for projected crses

distance = distArea.measureLine( QgsPointXY( vertex1 ), QgsPointXY( vertex2 ) );
distance = distArea.convertLengthMeasurement( distance, QgsProject::instance()->distanceUnits() );
formattedDistance = distArea.formatDistance( distance, 6, QgsProject::instance()->distanceUnits() );
}
else
{
distance = vertex1.distance( vertex2 );
formattedDistance = QLocale().toString( distance, 'f' );
}

const double zDiff = vertex2.z() - vertex1.z();

message = tr( "Selected mesh vertices IDs: %1 and %2 with distance %3 and dZ %4." ).arg( vertexId1 ).arg( vertexId2 ).arg( formattedDistance ).arg( QLocale().toString( zDiff, 'f' ) );
}
else if ( mSelectedVertices.count() > 2 )
{
message = tr( "Selected %1 mesh vertices." ).arg( mSelectedVertices.count() );
}

QgisApp::instance()->statusBarIface()->showMessage( message );
}
else
{
QgisApp::instance()->statusBarIface()->clearMessage();
}
}
1 change: 1 addition & 0 deletions src/app/mesh/qgsmaptooleditmeshframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class APP_EXPORT QgsMapToolEditMeshFrame : public QgsMapToolAdvancedDigitizing
void onZoomToSelected();
void reindexMesh();
void onUndoRedo();
void updateStatusBarMessage() const;

private:

Expand Down
Loading