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() );
284 QDomElement embeddedRendererElem = symbologyElem.firstChildElement(
"renderer-v2" );
285 if ( !embeddedRendererElem.isNull() )
291 QDomElement centerSymbolElem = symbologyElem.firstChildElement(
"symbol" );
292 if ( !centerSymbolElem.isNull() )
302 rendererElement.setAttribute(
"type",
"pointDisplacement" );
304 rendererElement.setAttribute(
"labelFont",
mLabelFont.toString() );
305 rendererElement.setAttribute(
"circleWidth", QString::number(
mCircleWidth ) );
314 rendererElement.appendChild( embeddedRendererElem );
319 rendererElement.appendChild( centerSymbolElem );
321 return rendererElement;
358 QList<QString>::const_iterator attStringIt = attributeStrings.constBegin();
359 for ( ; attStringIt != attributeStrings.constEnd(); ++attStringIt )
365 QList<QgsFeatureId> intersectList;
373 intersectList.clear();
379 if ( intersectList.empty() )
391 if ( it->size() > 0 && it->contains( existingEntry ) )
403 QMap<QgsFeatureId, QgsFeature> newMap;
418 QMap<QgsFeatureId, QgsFeature>::iterator mapIt = it->begin();
419 for ( ; mapIt != it->end(); ++mapIt )
437 QgsDebugMsg(
"number of displacement groups:" + QString::number( nGroups ) );
438 for (
int i = 0; i < nGroups; ++i )
440 QgsDebugMsg(
"***************displacement group " + QString::number( i ) );
441 QMap<QgsFeatureId, QgsFeature>::const_iterator it =
mDisplacementGroups.at( i ).constBegin();
447 QgsDebugMsg(
"********all displacement ids*********" );
460 QList<QMap<QgsFeatureId, QgsFeature> >::const_iterator list_it =
mDisplacementGroups.constBegin();
463 QMap<QgsFeatureId, QgsFeature>::const_iterator map_it = list_it->constBegin();
464 for ( ; map_it != list_it->constEnd(); ++map_it )
491 double symbolDiagonal, QList<QPointF>& symbolPositions, QList<QPointF>& labelShifts )
const
493 symbolPositions.clear();
500 else if ( nPosition == 1 )
502 symbolPositions.append( centerPoint );
503 labelShifts.append( QPointF( symbolDiagonal / 2.0, -symbolDiagonal / 2.0 ) );
507 double fullPerimeter = 2 *
M_PI;
508 double angleStep = fullPerimeter / nPosition;
511 for ( currentAngle = 0.0; currentAngle < fullPerimeter; currentAngle += angleStep )
513 double sinusCurrentAngle = sin( currentAngle );
514 double cosinusCurrentAngle = cos( currentAngle );
515 QPointF positionShift( radius * sinusCurrentAngle, radius * cosinusCurrentAngle );
516 QPointF labelShift(( radius + symbolDiagonal / 2 ) * sinusCurrentAngle, ( radius + symbolDiagonal / 2 ) * cosinusCurrentAngle );
517 symbolPositions.append( centerPoint + positionShift );
518 labelShifts.append( labelShift );
525 if ( nSymbols < 2 || !p )
533 p->setPen( circlePen );
534 p->drawArc( QRectF( centerPoint.x() - radiusPainterUnits, centerPoint.y() - radiusPainterUnits, 2 * radiusPainterUnits, 2 * radiusPainterUnits ), 0, 5760 );
539 QList<QPointF>::const_iterator symbolPosIt = symbolPositions.constBegin();
540 QList<QgsMarkerSymbolV2*>::const_iterator symbolIt = symbolList.constBegin();
541 for ( ; symbolPosIt != symbolPositions.constEnd() && symbolIt != symbolList.constEnd(); ++symbolPosIt, ++symbolIt )
545 ( *symbolIt )->renderPoint( *symbolPosIt, &f, context, -1, selected );
559 p->setPen( labelPen );
564 QFont scaledFont = pixelSizeFont;
566 p->setFont( scaledFont );
568 QFontMetricsF fontMetrics( pixelSizeFont );
569 QPointF currentLabelShift;
571 QList<QPointF>::const_iterator labelPosIt = labelShifts.constBegin();
572 QStringList::const_iterator text_it = labelList.constBegin();
574 for ( ; labelPosIt != labelShifts.constEnd() && text_it != labelList.constEnd(); ++labelPosIt, ++text_it )
576 currentLabelShift = *labelPosIt;
577 if ( currentLabelShift.x() < 0 )
579 currentLabelShift.setX( currentLabelShift.x() - fontMetrics.width( *text_it ) );
581 if ( currentLabelShift.y() > 0 )
583 currentLabelShift.setY( currentLabelShift.y() + fontMetrics.ascent() );
586 QPointF drawingPoint( centerPoint + currentLabelShift );
588 p->translate( drawingPoint.x(), drawingPoint.y() );
590 p->drawText( QPointF( 0, 0 ), *text_it );
603 if ( symbolList.size() < 1 )
608 return symbolList.at( 0 );