Skip to content

Commit 8a93c2d

Browse files
authored
add message to QGIS status bar on selection of vertices (qgis#58811)
1 parent 4252b61 commit 8a93c2d

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

src/app/mesh/qgsmaptooleditmeshframe.cpp

+67
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
#include "qgsmaptooleditmeshframe.h"
1717

1818
#include <QMessageBox>
19+
#include <QLocale>
1920

2021
#include "qgis.h"
2122
#include "qgisapp.h"
2223
#include "qgsapplication.h"
24+
#include "qgsstatusbar.h"
2325

2426
#include "qgsadvanceddigitizingdockwidget.h"
2527
#include "qgsdoublespinbox.h"
@@ -45,6 +47,7 @@
4547
#include "qgsmeshselectbyexpressiondialog.h"
4648
#include "qgsmaptoolidentify.h"
4749
#include "qgsidentifymenu.h"
50+
#include "qgsdistancearea.h"
4851

4952

5053
//
@@ -331,6 +334,8 @@ QgsMapToolEditMeshFrame::QgsMapToolEditMeshFrame( QgsMapCanvas *canvas )
331334
createZValueWidget();
332335
} );
333336

337+
connect( this, &QgsMapToolEditMeshFrame::selectionChange, this, &QgsMapToolEditMeshFrame::updateStatusBarMessage );
338+
334339
setAutoSnapEnabled( true );
335340
}
336341

@@ -2841,3 +2846,65 @@ void QgsMapToolEditMeshFrame::showSelectByExpressionDialog()
28412846
connect( dialog, &QgsMeshSelectByExpressionDialog::select, this, &QgsMapToolEditMeshFrame::selectByExpression );
28422847
connect( dialog, &QgsMeshSelectByExpressionDialog::zoomToSelected, this, &QgsMapToolEditMeshFrame::onZoomToSelected );
28432848
}
2849+
2850+
void QgsMapToolEditMeshFrame::updateStatusBarMessage() const
2851+
{
2852+
if ( ! mSelectedVertices.isEmpty() )
2853+
{
2854+
QString message;
2855+
if ( mSelectedVertices.count() == 1 )
2856+
{
2857+
const QgsMesh &mesh = *mCurrentLayer->nativeMesh();
2858+
const int vertexId = mSelectedVertices.firstKey();
2859+
const QgsMeshVertex vertex = mesh.vertex( vertexId );
2860+
2861+
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' ) );
2862+
}
2863+
else if ( mSelectedVertices.count() == 2 )
2864+
{
2865+
const QgsMesh &mesh = *mCurrentLayer->nativeMesh();
2866+
const int vertexId1 = mSelectedVertices.firstKey();
2867+
const int vertexId2 = mSelectedVertices.lastKey();
2868+
const QgsMeshVertex vertex1 = mesh.vertex( vertexId1 );
2869+
const QgsMeshVertex vertex2 = mesh.vertex( vertexId2 );
2870+
2871+
QString formattedDistance;
2872+
double distance;
2873+
2874+
// if crs is valid calculate using QgsDistanceArea otherwise calculate just as distance
2875+
if ( mCurrentLayer->crs().isValid() )
2876+
{
2877+
QgsDistanceArea distArea = QgsDistanceArea();
2878+
distArea.setSourceCrs( mCurrentLayer->crs(), QgsProject::instance()->transformContext() );
2879+
distArea.setEllipsoid( QgsProject::instance()->ellipsoid() );
2880+
try
2881+
{
2882+
distance = distArea.measureLine( QgsPointXY( vertex1 ), QgsPointXY( vertex2 ) );
2883+
distance = distArea.convertLengthMeasurement( distance, QgsProject::instance()->distanceUnits() );
2884+
formattedDistance = distArea.formatDistance( distance, 6, QgsProject::instance()->distanceUnits() );
2885+
}
2886+
catch ( QgsCsException & ) {}
2887+
}
2888+
2889+
if ( formattedDistance.isEmpty() )
2890+
{
2891+
distance = vertex1.distance( vertex2 );
2892+
formattedDistance = QLocale().toString( distance, 'f' );
2893+
}
2894+
2895+
const double zDiff = vertex2.z() - vertex1.z();
2896+
2897+
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' ) );
2898+
}
2899+
else if ( mSelectedVertices.count() > 2 )
2900+
{
2901+
message = tr( "Selected %1 mesh vertices." ).arg( mSelectedVertices.count() );
2902+
}
2903+
2904+
QgisApp::instance()->statusBarIface()->showMessage( message );
2905+
}
2906+
else
2907+
{
2908+
QgisApp::instance()->statusBarIface()->clearMessage();
2909+
}
2910+
}

src/app/mesh/qgsmaptooleditmeshframe.h

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class APP_EXPORT QgsMapToolEditMeshFrame : public QgsMapToolAdvancedDigitizing
166166
void onZoomToSelected();
167167
void reindexMesh();
168168
void onUndoRedo();
169+
void updateStatusBarMessage() const;
169170

170171
private:
171172

0 commit comments

Comments
 (0)