Skip to content
Permalink
Browse files

Use switch for enum comparison

  • Loading branch information
nyalldawson authored and wonder-sk committed Jan 4, 2021
1 parent e14750e commit 5fea4629b194a3beef43edae1119dd890609a551
Showing with 28 additions and 21 deletions.
  1. +2 −0 src/core/pointcloud/qgspointcloudindex.h
  2. +26 −21 src/core/pointcloud/qgspointcloudrenderer.cpp
@@ -85,6 +85,8 @@ class CORE_EXPORT IndexedPointCloudNode
int mD = -1, mX = -1, mY = -1, mZ = -1;
};

Q_DECLARE_TYPEINFO( IndexedPointCloudNode, Q_PRIMITIVE_TYPE );

//! Hash function for indexed nodes
CORE_EXPORT uint qHash( IndexedPointCloudNode id );

@@ -230,28 +230,33 @@ QVector<QVariantMap> QgsPointCloudRenderer::identify( QgsPointCloudLayer *layer,
{
double x = geometry.asPoint().x();
double y = geometry.asPoint().y();
if ( pointSymbol() == QgsPointCloudRenderer::PointSymbol::Square )
switch ( pointSymbol() )
{
QgsPointXY deviceCoords = renderContext.mapToPixel().transform( QgsPointXY( x, y ) );
QgsPointXY point1( deviceCoords.x() - 2 * pointSize(), deviceCoords.y() - 2 * pointSize() );
QgsPointXY point2( deviceCoords.x() + 2 * pointSize(), deviceCoords.y() + 2 * pointSize() );
QgsPointXY point1MapCoords = renderContext.mapToPixel().toMapCoordinates( point1.x(), point1.y() );
QgsPointXY point2MapCoords = renderContext.mapToPixel().toMapCoordinates( point2.x(), point2.y() );
QgsRectangle pointRect( point1MapCoords, point2MapCoords );
selectionGeometry = QgsGeometry::fromRect( pointRect );
}
else if ( pointSymbol() == QgsPointCloudRenderer::PointSymbol::Circle )
{
QgsPoint centerMapCoords( x, y );
QgsPointXY deviceCoords = renderContext.mapToPixel().transform( centerMapCoords );
QgsPoint point1( deviceCoords.x(), deviceCoords.y() - 2 * pointSize() );
QgsPoint point2( deviceCoords.x(), deviceCoords.y() + 2 * pointSize() );
QgsPointXY point1MapCoords = renderContext.mapToPixel().toMapCoordinates( point1.x(), point1.y() );
QgsPointXY point2MapCoords = renderContext.mapToPixel().toMapCoordinates( point2.x(), point2.y() );
QgsCircle circle = QgsCircle::from2Points( QgsPoint( point1MapCoords ), QgsPoint( point2MapCoords ) );
std::unique_ptr<QgsPolygon> polygon( circle.toPolygon( 6 ) );
QgsGeometry circleGeometry( std::move( polygon ) );
selectionGeometry = circleGeometry;
case QgsPointCloudRenderer::PointSymbol::Square:
{
QgsPointXY deviceCoords = renderContext.mapToPixel().transform( QgsPointXY( x, y ) );
QgsPointXY point1( deviceCoords.x() - 2 * pointSize(), deviceCoords.y() - 2 * pointSize() );
QgsPointXY point2( deviceCoords.x() + 2 * pointSize(), deviceCoords.y() + 2 * pointSize() );
QgsPointXY point1MapCoords = renderContext.mapToPixel().toMapCoordinates( point1.x(), point1.y() );
QgsPointXY point2MapCoords = renderContext.mapToPixel().toMapCoordinates( point2.x(), point2.y() );
QgsRectangle pointRect( point1MapCoords, point2MapCoords );
selectionGeometry = QgsGeometry::fromRect( pointRect );
break;
}
case QgsPointCloudRenderer::PointSymbol::Circle:
{
QgsPoint centerMapCoords( x, y );
QgsPointXY deviceCoords = renderContext.mapToPixel().transform( centerMapCoords );
QgsPoint point1( deviceCoords.x(), deviceCoords.y() - 2 * pointSize() );
QgsPoint point2( deviceCoords.x(), deviceCoords.y() + 2 * pointSize() );
QgsPointXY point1MapCoords = renderContext.mapToPixel().toMapCoordinates( point1.x(), point1.y() );
QgsPointXY point2MapCoords = renderContext.mapToPixel().toMapCoordinates( point2.x(), point2.y() );
QgsCircle circle = QgsCircle::from2Points( QgsPoint( point1MapCoords ), QgsPoint( point2MapCoords ) );
std::unique_ptr<QgsPolygon> polygon( circle.toPolygon( 6 ) );
QgsGeometry circleGeometry( std::move( polygon ) );
selectionGeometry = circleGeometry;
break;
}
}
}

0 comments on commit 5fea462

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