|
16 | 16 | #include "qgsmaptooleditmeshframe.h"
|
17 | 17 |
|
18 | 18 | #include <QMessageBox>
|
| 19 | +#include <QLocale> |
19 | 20 |
|
20 | 21 | #include "qgis.h"
|
21 | 22 | #include "qgisapp.h"
|
22 | 23 | #include "qgsapplication.h"
|
| 24 | +#include "qgsstatusbar.h" |
23 | 25 |
|
24 | 26 | #include "qgsadvanceddigitizingdockwidget.h"
|
25 | 27 | #include "qgsdoublespinbox.h"
|
|
45 | 47 | #include "qgsmeshselectbyexpressiondialog.h"
|
46 | 48 | #include "qgsmaptoolidentify.h"
|
47 | 49 | #include "qgsidentifymenu.h"
|
| 50 | +#include "qgsdistancearea.h" |
48 | 51 |
|
49 | 52 |
|
50 | 53 | //
|
@@ -331,6 +334,8 @@ QgsMapToolEditMeshFrame::QgsMapToolEditMeshFrame( QgsMapCanvas *canvas )
|
331 | 334 | createZValueWidget();
|
332 | 335 | } );
|
333 | 336 |
|
| 337 | + connect( this, &QgsMapToolEditMeshFrame::selectionChange, this, &QgsMapToolEditMeshFrame::updateStatusBarMessage ); |
| 338 | + |
334 | 339 | setAutoSnapEnabled( true );
|
335 | 340 | }
|
336 | 341 |
|
@@ -2841,3 +2846,65 @@ void QgsMapToolEditMeshFrame::showSelectByExpressionDialog()
|
2841 | 2846 | connect( dialog, &QgsMeshSelectByExpressionDialog::select, this, &QgsMapToolEditMeshFrame::selectByExpression );
|
2842 | 2847 | connect( dialog, &QgsMeshSelectByExpressionDialog::zoomToSelected, this, &QgsMapToolEditMeshFrame::onZoomToSelected );
|
2843 | 2848 | }
|
| 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 | +} |
0 commit comments