26 #include <QDomElement>
33 , mLabelAttributeName( labelAttributeName )
35 , mTolerance( 0.00001 )
37 , mCircleColor( QColor( 125, 125, 125 ) )
38 , mCircleRadiusAddition( 0 )
39 , mMaxLabelScaleDenominator( -1 )
79 Q_UNUSED( drawVertexMarker );
93 QStringList labelAttributeList;
94 QList<QgsMarkerSymbolV2*> symbolList;
103 if ( feature.
id() == it->begin().key() )
105 QMap<QgsFeatureId, QgsFeature>::iterator attIt = it->begin();
106 for ( ; attIt != it->end(); ++attIt )
110 labelAttributeList <<
getLabel( attIt.value() );
114 labelAttributeList << QString();
126 labelAttributeList <<
getLabel( feature );
130 labelAttributeList << QString();
134 if ( symbolList.isEmpty() && labelAttributeList.isEmpty() )
142 double currentWidthFactor;
144 QList<QgsMarkerSymbolV2*>::const_iterator it = symbolList.constBegin();
145 for ( ; it != symbolList.constEnd(); ++it )
150 double currentDiagonal = sqrt( 2 * (( *it )->size() * ( *it )->size() ) ) * currentWidthFactor;
151 if ( currentDiagonal > diagonal )
153 diagonal = currentDiagonal;
161 double radius = qMax(( diagonal / 2 ), labelAttributeList.size() * diagonal / 2 /
M_PI ) + circleAdditionPainterUnits;
164 drawCircle( radius, symbolContext, pt, symbolList.size() );
166 QList<QPointF> symbolPositions;
167 QList<QPointF> labelPositions;
171 if ( labelAttributeList.size() > 1 )
184 drawSymbols( feature, context, symbolList, symbolPositions, selected );
186 drawLabels( pt, symbolContext, labelPositions, labelAttributeList );
236 QgsDebugMsg(
"QgsPointDisplacementRenderer::stopRender" );
246 QList<QString> attributeList;
255 return attributeList;
275 labelFont.fromString( symbologyElem.attribute(
"labelFont",
"" ) );
277 r->
setCircleWidth( symbologyElem.attribute(
"circleWidth",
"0.4" ).toDouble() );
282 r->
setTolerance( symbologyElem.attribute(
"tolerance",
"0.00001" ).toDouble() );
285 QDomElement embeddedRendererElem = symbologyElem.firstChildElement(
"renderer-v2" );
286 if ( !embeddedRendererElem.isNull() )
292 QDomElement centerSymbolElem = symbologyElem.firstChildElement(
"symbol" );
293 if ( !centerSymbolElem.isNull() )
303 rendererElement.setAttribute(
"type",
"pointDisplacement" );
305 rendererElement.setAttribute(
"labelFont",
mLabelFont.toString() );
306 rendererElement.setAttribute(
"circleWidth", QString::number(
mCircleWidth ) );
311 rendererElement.setAttribute(
"tolerance", QString::number(
mTolerance ) );
316 rendererElement.appendChild( embeddedRendererElem );
321 rendererElement.appendChild( centerSymbolElem );
323 return rendererElement;
360 QList<QString>::const_iterator attStringIt = attributeStrings.constBegin();
361 for ( ; attStringIt != attributeStrings.constEnd(); ++attStringIt )
367 QList<QgsFeatureId> intersectList;
375 intersectList.clear();
381 if ( intersectList.empty() )
393 if ( it->size() > 0 && it->contains( existingEntry ) )
405 QMap<QgsFeatureId, QgsFeature> newMap;
420 QMap<QgsFeatureId, QgsFeature>::iterator mapIt = it->begin();
421 for ( ; mapIt != it->end(); ++mapIt )
439 QgsDebugMsg(
"number of displacement groups:" + QString::number( nGroups ) );
440 for (
int i = 0; i < nGroups; ++i )
442 QgsDebugMsg(
"***************displacement group " + QString::number( i ) );
443 QMap<QgsFeatureId, QgsFeature>::const_iterator it =
mDisplacementGroups.at( i ).constBegin();
449 QgsDebugMsg(
"********all displacement ids*********" );
462 QList<QMap<QgsFeatureId, QgsFeature> >::const_iterator list_it =
mDisplacementGroups.constBegin();
465 QMap<QgsFeatureId, QgsFeature>::const_iterator map_it = list_it->constBegin();
466 for ( ; map_it != list_it->constEnd(); ++map_it )
493 double symbolDiagonal, QList<QPointF>& symbolPositions, QList<QPointF>& labelShifts )
const
495 symbolPositions.clear();
502 else if ( nPosition == 1 )
504 symbolPositions.append( centerPoint );
505 labelShifts.append( QPointF( symbolDiagonal / 2.0, -symbolDiagonal / 2.0 ) );
509 double fullPerimeter = 2 *
M_PI;
510 double angleStep = fullPerimeter / nPosition;
513 for ( currentAngle = 0.0; currentAngle < fullPerimeter; currentAngle += angleStep )
515 double sinusCurrentAngle = sin( currentAngle );
516 double cosinusCurrentAngle = cos( currentAngle );
517 QPointF positionShift( radius * sinusCurrentAngle, radius * cosinusCurrentAngle );
518 QPointF labelShift(( radius + symbolDiagonal / 2 ) * sinusCurrentAngle, ( radius + symbolDiagonal / 2 ) * cosinusCurrentAngle );
519 symbolPositions.append( centerPoint + positionShift );
520 labelShifts.append( labelShift );
527 if ( nSymbols < 2 || !p )
535 p->setPen( circlePen );
536 p->drawArc( QRectF( centerPoint.x() - radiusPainterUnits, centerPoint.y() - radiusPainterUnits, 2 * radiusPainterUnits, 2 * radiusPainterUnits ), 0, 5760 );
541 QList<QPointF>::const_iterator symbolPosIt = symbolPositions.constBegin();
542 QList<QgsMarkerSymbolV2*>::const_iterator symbolIt = symbolList.constBegin();
543 for ( ; symbolPosIt != symbolPositions.constEnd() && symbolIt != symbolList.constEnd(); ++symbolPosIt, ++symbolIt )
547 ( *symbolIt )->renderPoint( *symbolPosIt, &f, context, -1, selected );
561 p->setPen( labelPen );
566 QFont scaledFont = pixelSizeFont;
568 p->setFont( scaledFont );
570 QFontMetricsF fontMetrics( pixelSizeFont );
571 QPointF currentLabelShift;
573 QList<QPointF>::const_iterator labelPosIt = labelShifts.constBegin();
574 QStringList::const_iterator text_it = labelList.constBegin();
576 for ( ; labelPosIt != labelShifts.constEnd() && text_it != labelList.constEnd(); ++labelPosIt, ++text_it )
578 currentLabelShift = *labelPosIt;
579 if ( currentLabelShift.x() < 0 )
581 currentLabelShift.setX( currentLabelShift.x() - fontMetrics.width( *text_it ) );
583 if ( currentLabelShift.y() > 0 )
585 currentLabelShift.setY( currentLabelShift.y() + fontMetrics.ascent() );
588 QPointF drawingPoint( centerPoint + currentLabelShift );
590 p->translate( drawingPoint.x(), drawingPoint.y() );
592 p->drawText( QPointF( 0, 0 ), *text_it );
605 if ( symbolList.size() < 1 )
610 return symbolList.at( 0 );