-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
JanCaha
wants to merge
4
commits into
qgis:master
Choose a base branch
from
JanCaha:mesh-selected-items
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+62
−0
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -45,6 +47,7 @@ | |
#include "qgsmeshselectbyexpressiondialog.h" | ||
#include "qgsmaptoolidentify.h" | ||
#include "qgsidentifymenu.h" | ||
#include "qgsdistancearea.h" | ||
|
||
|
||
// | ||
|
@@ -331,6 +334,8 @@ QgsMapToolEditMeshFrame::QgsMapToolEditMeshFrame( QgsMapCanvas *canvas ) | |
createZValueWidget(); | ||
} ); | ||
|
||
connect( this, &QgsMapToolEditMeshFrame::selectionChange, this, &QgsMapToolEditMeshFrame::updateStatusBarMessage ); | ||
|
||
setAutoSnapEnabled( true ); | ||
} | ||
|
||
|
@@ -2841,3 +2846,59 @@ void QgsMapToolEditMeshFrame::showSelectByExpressionDialog() | |
connect( dialog, &QgsMeshSelectByExpressionDialog::select, this, &QgsMapToolEditMeshFrame::selectByExpression ); | ||
connect( dialog, &QgsMeshSelectByExpressionDialog::zoomToSelected, this, &QgsMapToolEditMeshFrame::onZoomToSelected ); | ||
} | ||
|
||
void QgsMapToolEditMeshFrame::updateStatusBarMessage() | ||
{ | ||
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() ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest to only set the ellipsoid for geographic |
||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.