@@ -255,7 +255,7 @@ void QgsPointDisplacementRenderer::calculateSymbolAndLabelPositions( QgsSymbolRe
255
255
}
256
256
else if ( nPosition == 1 ) // If there is only one feature, draw it exactly at the center position
257
257
{
258
- double side = sqrt ( pow ( symbolDiagonal, 2 ) / 2.0 );
258
+ const double side = sqrt ( pow ( symbolDiagonal, 2 ) / 2.0 );
259
259
symbolPositions.append ( centerPoint );
260
260
labelShifts.append ( QPointF ( side * mLabelDistanceFactor , -side * mLabelDistanceFactor ) );
261
261
return ;
@@ -281,7 +281,7 @@ void QgsPointDisplacementRenderer::calculateSymbolAndLabelPositions( QgsSymbolRe
281
281
double cosinusCurrentAngle = std::cos ( currentAngle );
282
282
QPointF positionShift ( radius * sinusCurrentAngle, radius * cosinusCurrentAngle );
283
283
284
- QPointF labelShift ( ( radius + diagonals[ featureIndex] * mLabelDistanceFactor ) * sinusCurrentAngle, ( radius + diagonals[ featureIndex] * mLabelDistanceFactor ) * cosinusCurrentAngle );
284
+ QPointF labelShift ( ( radius + diagonals. at ( featureIndex ) * mLabelDistanceFactor ) * sinusCurrentAngle, ( radius + diagonals. at ( featureIndex ) * mLabelDistanceFactor ) * cosinusCurrentAngle );
285
285
symbolPositions.append ( centerPoint + positionShift );
286
286
labelShifts.append ( labelShift );
287
287
}
@@ -309,7 +309,7 @@ void QgsPointDisplacementRenderer::calculateSymbolAndLabelPositions( QgsSymbolRe
309
309
double sinusCurrentAngle = std::sin ( currentAngle );
310
310
double cosinusCurrentAngle = std::cos ( currentAngle );
311
311
QPointF positionShift ( radiusCurrentRing * sinusCurrentAngle, radiusCurrentRing * cosinusCurrentAngle );
312
- QPointF labelShift ( ( radiusCurrentRing + diagonals[ featureIndex] * mLabelDistanceFactor ) * sinusCurrentAngle, ( radiusCurrentRing + diagonals[ featureIndex] * mLabelDistanceFactor ) * cosinusCurrentAngle );
312
+ QPointF labelShift ( ( radiusCurrentRing + diagonals. at ( featureIndex ) * mLabelDistanceFactor ) * sinusCurrentAngle, ( radiusCurrentRing + diagonals. at ( featureIndex ) * mLabelDistanceFactor ) * cosinusCurrentAngle );
313
313
symbolPositions.append ( centerPoint + positionShift );
314
314
labelShifts.append ( labelShift );
315
315
currentAngle += angleStep;
@@ -333,23 +333,47 @@ void QgsPointDisplacementRenderer::calculateSymbolAndLabelPositions( QgsSymbolRe
333
333
double userPointRadius = originalPointRadius + circleAdditionPainterUnits;
334
334
335
335
int yIndex = 0 ;
336
- int featureIndex = 0 ;
337
336
while ( pointsRemaining > 0 )
338
337
{
339
338
for ( int xIndex = 0 ; xIndex < gridSize && pointsRemaining > 0 ; ++xIndex )
340
339
{
341
340
QPointF positionShift ( userPointRadius * xIndex, userPointRadius * yIndex );
342
- QPointF labelShift ( ( userPointRadius + diagonals[featureIndex] * mLabelDistanceFactor ) * xIndex, ( userPointRadius + diagonals[featureIndex] * mLabelDistanceFactor ) * yIndex );
343
341
symbolPositions.append ( centerPoint + positionShift );
344
- labelShifts.append ( labelShift );
345
342
pointsRemaining--;
346
- featureIndex++;
347
343
}
348
344
yIndex++;
349
345
}
350
346
351
347
centralizeGrid ( symbolPositions, userPointRadius, gridSize );
352
- centralizeGrid ( labelShifts, userPointRadius, gridSize );
348
+
349
+ int xFactor;
350
+ int yFactor;
351
+ double side = 0 ;
352
+ for ( int symbolIndex = 0 ; symbolIndex < symbolPositions.size (); ++symbolIndex )
353
+ {
354
+ if ( symbolPositions.at ( symbolIndex ).x () < centerPoint.x () )
355
+ {
356
+ xFactor = -1 ;
357
+ }
358
+ else
359
+ {
360
+ xFactor = 1 ;
361
+ }
362
+
363
+ if ( symbolPositions.at ( symbolIndex ).y () < centerPoint.y () )
364
+ {
365
+ yFactor = 1 ;
366
+ }
367
+ else
368
+ {
369
+ yFactor = -1 ;
370
+ }
371
+
372
+ side = sqrt ( pow ( diagonals.at ( symbolIndex ), 2 ) / 2.0 );
373
+ QPointF labelShift ( ( side * mLabelDistanceFactor * xFactor ), ( -side * mLabelDistanceFactor * yFactor ) );
374
+ labelShifts.append ( symbolPositions.at ( symbolIndex ) - centerPoint + labelShift );
375
+ }
376
+
353
377
gridRadius = userPointRadius;
354
378
break ;
355
379
}
0 commit comments