Skip to content

Commit 6b4b9fe

Browse files
committed
Fix closest vertex z/m doesn't show in identify tool for multiline
geometries, remove duplicate closest M value attribute
1 parent ff900c0 commit 6b4b9fe

File tree

2 files changed

+19
-35
lines changed

2 files changed

+19
-35
lines changed

src/gui/qgsmaptoolidentify.cpp

+19-30
Original file line numberDiff line numberDiff line change
@@ -326,18 +326,6 @@ void QgsMapToolIdentify::closestVertexAttributes( const QgsAbstractGeometry &geo
326326
}
327327
}
328328

329-
void QgsMapToolIdentify::closestPointAttributes( const QgsAbstractGeometry &geometry, QgsMapLayer *layer, const QgsPointXY &layerPoint, QMap< QString, QString > &derivedAttributes )
330-
{
331-
Q_UNUSED( layer );
332-
// measure
333-
if ( QgsWkbTypes::hasM( geometry.wkbType() ) )
334-
{
335-
QgsPoint closestPoint = QgsGeometryUtils::closestPoint( geometry, QgsPoint( layerPoint.x(), layerPoint.y() ) );
336-
QString str = QLocale::system().toString( closestPoint.m(), 'g', 10 );
337-
derivedAttributes.insert( QStringLiteral( "Closest point M" ), str );
338-
}
339-
}
340-
341329
QString QgsMapToolIdentify::formatCoordinate( const QgsPointXY &canvasPoint ) const
342330
{
343331
return QgsCoordinateUtils::formatCoordinateForProject( canvasPoint, mCanvas->mapSettings().destinationCrs(),
@@ -396,27 +384,28 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur
396384
QString str = formatDistance( dist );
397385
derivedAttributes.insert( tr( "Length" ), str );
398386

399-
const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( feature->geometry().constGet() );
400-
if ( curve )
387+
const QgsAbstractGeometry *geom = feature->geometry().constGet();
388+
if ( geom )
401389
{
402-
str = QLocale::system().toString( curve->nCoordinates() );
390+
str = QLocale::system().toString( geom->nCoordinates() );
403391
derivedAttributes.insert( tr( "Vertices" ), str );
404-
405392
//add details of closest vertex to identify point
406-
closestVertexAttributes( *curve, vId, layer, derivedAttributes );
407-
closestPointAttributes( *curve, layer, layerPoint, derivedAttributes );
408-
409-
// Add the start and end points in as derived attributes
410-
QgsPointXY pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, QgsPointXY( curve->startPoint().x(), curve->startPoint().y() ) );
411-
str = formatXCoordinate( pnt );
412-
derivedAttributes.insert( tr( "firstX", "attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
413-
str = formatYCoordinate( pnt );
414-
derivedAttributes.insert( tr( "firstY" ), str );
415-
pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, QgsPointXY( curve->endPoint().x(), curve->endPoint().y() ) );
416-
str = formatXCoordinate( pnt );
417-
derivedAttributes.insert( tr( "lastX", "attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
418-
str = formatYCoordinate( pnt );
419-
derivedAttributes.insert( tr( "lastY" ), str );
393+
closestVertexAttributes( *geom, vId, layer, derivedAttributes );
394+
395+
if ( const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( geom ) )
396+
{
397+
// Add the start and end points in as derived attributes
398+
QgsPointXY pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, QgsPointXY( curve->startPoint().x(), curve->startPoint().y() ) );
399+
str = formatXCoordinate( pnt );
400+
derivedAttributes.insert( tr( "firstX", "attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
401+
str = formatYCoordinate( pnt );
402+
derivedAttributes.insert( tr( "firstY" ), str );
403+
pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, QgsPointXY( curve->endPoint().x(), curve->endPoint().y() ) );
404+
str = formatXCoordinate( pnt );
405+
derivedAttributes.insert( tr( "lastX", "attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
406+
str = formatYCoordinate( pnt );
407+
derivedAttributes.insert( tr( "lastY" ), str );
408+
}
420409
}
421410
}
422411
else if ( geometryType == QgsWkbTypes::PolygonGeometry )

src/gui/qgsmaptoolidentify.h

-5
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,6 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
195195
*/
196196
void closestVertexAttributes( const QgsAbstractGeometry &geometry, QgsVertexId vId, QgsMapLayer *layer, QMap< QString, QString > &derivedAttributes );
197197

198-
/**
199-
* Adds details of the closest point to derived attributes
200-
*/
201-
void closestPointAttributes( const QgsAbstractGeometry &geometry, QgsMapLayer *layer, const QgsPointXY &layerPoint, QMap< QString, QString > &derivedAttributes );
202-
203198
QString formatCoordinate( const QgsPointXY &canvasPoint ) const;
204199
QString formatXCoordinate( const QgsPointXY &canvasPoint ) const;
205200
QString formatYCoordinate( const QgsPointXY &canvasPoint ) const;

0 commit comments

Comments
 (0)