|
@@ -75,11 +75,17 @@ void QgsPointDisplacementRenderer::drawGroup( QPointF centerPoint, QgsRenderCont |
|
|
QList<QPointF> symbolPositions; |
|
|
QList<QPointF> labelPositions; |
|
|
double circleRadius = -1.0; |
|
|
calculateSymbolAndLabelPositions( symbolContext, centerPoint, group.size(), diagonal, symbolPositions, labelPositions, circleRadius ); |
|
|
double gridRadius; |
|
|
int gridSize; |
|
|
|
|
|
calculateSymbolAndLabelPositions( symbolContext, centerPoint, group.size(), diagonal, symbolPositions, labelPositions, circleRadius, gridRadius, gridSize ); |
|
|
|
|
|
//draw circle |
|
|
if ( circleRadius > 0 ) |
|
|
drawCircle( circleRadius, symbolContext, centerPoint, group.size() ); |
|
|
//draw grid |
|
|
else |
|
|
drawGrid( gridSize, symbolContext, symbolPositions, group.size() ); |
|
|
|
|
|
if ( group.size() > 1 ) |
|
|
{ |
|
@@ -221,7 +227,8 @@ void QgsPointDisplacementRenderer::setCenterSymbol( QgsMarkerSymbol *symbol ) |
|
|
} |
|
|
|
|
|
void QgsPointDisplacementRenderer::calculateSymbolAndLabelPositions( QgsSymbolRenderContext &symbolContext, QPointF centerPoint, int nPosition, |
|
|
double symbolDiagonal, QList<QPointF> &symbolPositions, QList<QPointF> &labelShifts, double &circleRadius ) const |
|
|
double symbolDiagonal, QList<QPointF> &symbolPositions, QList<QPointF> &labelShifts, double &circleRadius, double &gridRadius, |
|
|
int &gridSize ) const |
|
|
{ |
|
|
symbolPositions.clear(); |
|
|
labelShifts.clear(); |
|
@@ -294,6 +301,75 @@ void QgsPointDisplacementRenderer::calculateSymbolAndLabelPositions( QgsSymbolRe |
|
|
} |
|
|
break; |
|
|
} |
|
|
case Grid: |
|
|
{ |
|
|
double centerDiagonal = symbolContext.renderContext().convertToPainterUnits( M_SQRT2 * mCenterSymbol->size(), |
|
|
mCenterSymbol->sizeUnit(), mCenterSymbol->sizeMapUnitScale() ); |
|
|
int pointsRemaining = nPosition; |
|
|
gridSize = ceil( sqrt( pointsRemaining ) ); |
|
|
if ( pointsRemaining - pow( gridSize - 1, 2 ) < gridSize ) |
|
|
gridSize -= 1; |
|
|
double originalPointRadius = ( ( centerDiagonal / 2.0 + symbolDiagonal / 2.0 ) + symbolDiagonal ) / 2; |
|
|
double userPointRadius = originalPointRadius + circleAdditionPainterUnits; |
|
|
|
|
|
int yIndex = 0; |
|
|
while ( pointsRemaining > 0 ) |
|
|
{ |
|
|
for ( int xIndex = 0; xIndex < gridSize && pointsRemaining > 0; ++xIndex ) |
|
|
{ |
|
|
QPointF positionShift( userPointRadius * xIndex, userPointRadius * yIndex ); |
|
|
QPointF labelShift( ( userPointRadius + symbolDiagonal / 2 ) * xIndex, ( userPointRadius + symbolDiagonal / 2 ) * yIndex ); |
|
|
symbolPositions.append( centerPoint + positionShift ); |
|
|
labelShifts.append( labelShift ); |
|
|
pointsRemaining--; |
|
|
} |
|
|
yIndex++; |
|
|
} |
|
|
|
|
|
centralizeGrid( symbolPositions, userPointRadius, gridSize ); |
|
|
centralizeGrid( labelShifts, userPointRadius, gridSize ); |
|
|
gridRadius = userPointRadius; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
void QgsPointDisplacementRenderer::centralizeGrid( QList<QPointF> &pointSymbolPositions, double radius, int size ) const |
|
|
{ |
|
|
double shiftAmount = -radius * ( size - 1 ) / 2; |
|
|
QPointF centralShift( shiftAmount, shiftAmount ); |
|
|
for ( int i = 0; i < pointSymbolPositions.size(); ++i ) |
|
|
{ |
|
|
pointSymbolPositions[i] += centralShift; |
|
|
} |
|
|
} |
|
|
|
|
|
void QgsPointDisplacementRenderer::drawGrid( int gridSizeUnits, QgsSymbolRenderContext &context, |
|
|
QList<QPointF> pointSymbolPositions, int nSymbols ) |
|
|
{ |
|
|
QPainter *p = context.renderContext().painter(); |
|
|
if ( nSymbols < 2 || !p ) //draw grid only if multiple features |
|
|
{ |
|
|
return; |
|
|
} |
|
|
|
|
|
QPen gridPen( mCircleColor ); |
|
|
gridPen.setWidthF( context.outputLineWidth( mCircleWidth ) ); |
|
|
p->setPen( gridPen ); |
|
|
|
|
|
for ( int i = 0; i < pointSymbolPositions.size(); ++i ) |
|
|
{ |
|
|
if ( i + 1 < pointSymbolPositions.size() && 0 != ( i + 1 ) % gridSizeUnits ) |
|
|
{ |
|
|
QLineF gridLineRow( pointSymbolPositions[i], pointSymbolPositions[i + 1] ); |
|
|
p->drawLine( gridLineRow ); |
|
|
} |
|
|
|
|
|
if ( i + gridSizeUnits < pointSymbolPositions.size() ) |
|
|
{ |
|
|
QLineF gridLineColumn( pointSymbolPositions[i], pointSymbolPositions[i + gridSizeUnits] ); |
|
|
p->drawLine( gridLineColumn ); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|