Skip to content
Permalink
Browse files

Adjust to const-correct renderer API

  • Loading branch information
m-kuhn committed Apr 20, 2018
1 parent 5204fd3 commit e6181e1a5b89721741d671a22494eb003f482741
Showing with 20 additions and 20 deletions.
  1. +19 −19 src/gui/qgsmaptoolidentify.cpp
  2. +1 −1 src/gui/qgsmaptoolidentify.h
@@ -263,12 +263,12 @@ bool QgsMapToolIdentify::identifyVectorLayer( QList<IdentifyResult> *results, Qg
QgsFeatureId fid = feature.id();
context.expressionContext().setFeature( feature );

if ( filter && !renderer->willRenderFeature( const_cast<QgsFeature &>( feature ), context ) )
if ( filter && !renderer->willRenderFeature( feature, context ) )
continue;

featureCount++;

derivedAttributes.unite( featureDerivedAttributes( const_cast<QgsFeature *>( &feature ), layer, toLayerCoordinates( layer, point ) ) );
derivedAttributes.unite( featureDerivedAttributes( feature, layer, toLayerCoordinates( layer, point ) ) );

derivedAttributes.insert( tr( "feature id" ), fid < 0 ? tr( "new feature" ) : FID_TO_STRING( fid ) );

@@ -339,7 +339,7 @@ QString QgsMapToolIdentify::formatYCoordinate( const QgsPointXY &canvasPoint ) c
return coordinate.split( ',' ).at( 1 );
}

QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeature *feature, QgsMapLayer *layer, const QgsPointXY &layerPoint )
QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( const QgsFeature &feature, QgsMapLayer *layer, const QgsPointXY &layerPoint )
{
// Calculate derived attributes and insert:
// measure distance or area depending on geometry type
@@ -356,30 +356,30 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur

QgsVertexId vId;
QgsPoint closestPoint;
if ( feature->hasGeometry() )
if ( feature.hasGeometry() )
{
geometryType = feature->geometry().type();
wkbType = feature->geometry().wkbType();
geometryType = feature.geometry().type();
wkbType = feature.geometry().wkbType();
//find closest vertex to clicked point
closestPoint = QgsGeometryUtils::closestVertex( *feature->geometry().constGet(), QgsPoint( layerPoint.x(), layerPoint.y() ), vId );
closestPoint = QgsGeometryUtils::closestVertex( *feature.geometry().constGet(), QgsPoint( layerPoint.x(), layerPoint.y() ), vId );
}

if ( QgsWkbTypes::isMultiType( wkbType ) )
{
QString str = QLocale::system().toString( static_cast<const QgsGeometryCollection *>( feature->geometry().constGet() )->numGeometries() );
QString str = QLocale::system().toString( static_cast<const QgsGeometryCollection *>( feature.geometry().constGet() )->numGeometries() );
derivedAttributes.insert( tr( "Parts" ), str );
str = QLocale::system().toString( vId.part + 1 );
derivedAttributes.insert( tr( "Part number" ), str );
}

if ( geometryType == QgsWkbTypes::LineGeometry )
{
double dist = calc.measureLength( feature->geometry() );
double dist = calc.measureLength( feature.geometry() );
dist = calc.convertLengthMeasurement( dist, displayDistanceUnits() );
QString str = formatDistance( dist );
derivedAttributes.insert( tr( "Length" ), str );

const QgsAbstractGeometry *geom = feature->geometry().constGet();
const QgsAbstractGeometry *geom = feature.geometry().constGet();
if ( geom )
{
str = QLocale::system().toString( geom->nCoordinates() );
@@ -405,41 +405,41 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur
}
else if ( geometryType == QgsWkbTypes::PolygonGeometry )
{
double area = calc.measureArea( feature->geometry() );
double area = calc.measureArea( feature.geometry() );
area = calc.convertAreaMeasurement( area, displayAreaUnits() );
QString str = formatArea( area );
derivedAttributes.insert( tr( "Area" ), str );

double perimeter = calc.measurePerimeter( feature->geometry() );
double perimeter = calc.measurePerimeter( feature.geometry() );
perimeter = calc.convertLengthMeasurement( perimeter, displayDistanceUnits() );
str = formatDistance( perimeter );
derivedAttributes.insert( tr( "Perimeter" ), str );

str = QLocale::system().toString( feature->geometry().constGet()->nCoordinates() );
str = QLocale::system().toString( feature.geometry().constGet()->nCoordinates() );
derivedAttributes.insert( tr( "Vertices" ), str );

//add details of closest vertex to identify point
closestVertexAttributes( *feature->geometry().constGet(), vId, layer, derivedAttributes );
closestVertexAttributes( *feature.geometry().constGet(), vId, layer, derivedAttributes );
}
else if ( geometryType == QgsWkbTypes::PointGeometry )
{
if ( QgsWkbTypes::flatType( wkbType ) == QgsWkbTypes::Point )
{
// Include the x and y coordinates of the point as a derived attribute
QgsPointXY pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, feature->geometry().asPoint() );
QgsPointXY pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, feature.geometry().asPoint() );
QString str = formatXCoordinate( pnt );
derivedAttributes.insert( QStringLiteral( "X" ), str );
str = formatYCoordinate( pnt );
derivedAttributes.insert( QStringLiteral( "Y" ), str );

if ( QgsWkbTypes::hasZ( wkbType ) )
{
str = QLocale::system().toString( static_cast<const QgsPoint *>( feature->geometry().constGet() )->z(), 'g', 10 );
str = QLocale::system().toString( static_cast<const QgsPoint *>( feature.geometry().constGet() )->z(), 'g', 10 );
derivedAttributes.insert( QStringLiteral( "Z" ), str );
}
if ( QgsWkbTypes::hasM( wkbType ) )
{
str = QLocale::system().toString( static_cast<const QgsPoint *>( feature->geometry().constGet() )->m(), 'g', 10 );
str = QLocale::system().toString( static_cast<const QgsPoint *>( feature.geometry().constGet() )->m(), 'g', 10 );
derivedAttributes.insert( QStringLiteral( "M" ), str );
}
}
@@ -448,7 +448,7 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur
//multipart

//add details of closest vertex to identify point
const QgsAbstractGeometry *geom = feature->geometry().constGet();
const QgsAbstractGeometry *geom = feature.geometry().constGet();
{
closestVertexAttributes( *geom, vId, layer, derivedAttributes );
}
@@ -632,7 +632,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
}

QMap< QString, QString > derAttributes = derivedAttributes;
derAttributes.unite( featureDerivedAttributes( &feature, layer ) );
derAttributes.unite( featureDerivedAttributes( feature, layer ) );

IdentifyResult identifyResult( qobject_cast<QgsMapLayer *>( layer ), labels.join( QStringLiteral( " / " ) ), featureStore.fields(), feature, derAttributes );

@@ -189,7 +189,7 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
*/
QString formatArea( double area ) const;

QMap< QString, QString > featureDerivedAttributes( QgsFeature *feature, QgsMapLayer *layer, const QgsPointXY &layerPoint = QgsPointXY() );
QMap< QString, QString > featureDerivedAttributes( const QgsFeature &feature, QgsMapLayer *layer, const QgsPointXY &layerPoint = QgsPointXY() );

/**
* Adds details of the closest vertex to derived attributes

0 comments on commit e6181e1

Please sign in to comment.
You can’t perform that action at this time.