Skip to content

Commit f9f51cc

Browse files
henriknyalldawson
henrik
authored andcommitted
Fixes labels for point displacement grid.
1 parent 6fb0673 commit f9f51cc

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

src/core/symbology/qgspointdisplacementrenderer.cpp

+32-8
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ void QgsPointDisplacementRenderer::calculateSymbolAndLabelPositions( QgsSymbolRe
255255
}
256256
else if ( nPosition == 1 ) //If there is only one feature, draw it exactly at the center position
257257
{
258-
double side = sqrt( pow( symbolDiagonal, 2 ) / 2.0 );
258+
const double side = sqrt( pow( symbolDiagonal, 2 ) / 2.0 );
259259
symbolPositions.append( centerPoint );
260260
labelShifts.append( QPointF( side * mLabelDistanceFactor, -side * mLabelDistanceFactor ) );
261261
return;
@@ -281,7 +281,7 @@ void QgsPointDisplacementRenderer::calculateSymbolAndLabelPositions( QgsSymbolRe
281281
double cosinusCurrentAngle = std::cos( currentAngle );
282282
QPointF positionShift( radius * sinusCurrentAngle, radius * cosinusCurrentAngle );
283283

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 );
285285
symbolPositions.append( centerPoint + positionShift );
286286
labelShifts.append( labelShift );
287287
}
@@ -309,7 +309,7 @@ void QgsPointDisplacementRenderer::calculateSymbolAndLabelPositions( QgsSymbolRe
309309
double sinusCurrentAngle = std::sin( currentAngle );
310310
double cosinusCurrentAngle = std::cos( currentAngle );
311311
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 );
313313
symbolPositions.append( centerPoint + positionShift );
314314
labelShifts.append( labelShift );
315315
currentAngle += angleStep;
@@ -333,23 +333,47 @@ void QgsPointDisplacementRenderer::calculateSymbolAndLabelPositions( QgsSymbolRe
333333
double userPointRadius = originalPointRadius + circleAdditionPainterUnits;
334334

335335
int yIndex = 0;
336-
int featureIndex = 0;
337336
while ( pointsRemaining > 0 )
338337
{
339338
for ( int xIndex = 0; xIndex < gridSize && pointsRemaining > 0; ++xIndex )
340339
{
341340
QPointF positionShift( userPointRadius * xIndex, userPointRadius * yIndex );
342-
QPointF labelShift( ( userPointRadius + diagonals[featureIndex] * mLabelDistanceFactor ) * xIndex, ( userPointRadius + diagonals[featureIndex] * mLabelDistanceFactor ) * yIndex );
343341
symbolPositions.append( centerPoint + positionShift );
344-
labelShifts.append( labelShift );
345342
pointsRemaining--;
346-
featureIndex++;
347343
}
348344
yIndex++;
349345
}
350346

351347
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+
353377
gridRadius = userPointRadius;
354378
break;
355379
}

0 commit comments

Comments
 (0)