86 QPainter *p =
c.painter();
94 const double w = spu.width();
95 const double h = spu.height();
97 const double baseX = position.x();
98 const double baseY = position.y() - h;
100 QVector<QPointF> textPositions;
102 for (
int i = 0; i < nCategories; ++i )
106 textPositions.push_back( QPointF( baseX + ( w / nCategories ) * i + w / nCategories / 2.0, baseY + h / 2.0 ) );
110 textPositions.push_back( QPointF( baseX + w / 2.0, baseY + h / nCategories * i + w / nCategories / 2.0 ) );
118 p->setBrush( mBrush );
123 p->drawEllipse( baseX, baseY, w, h );
126 QList<QPointF> intersect;
127 const QPointF center( baseX + w / 2.0, baseY + h / 2.0 );
128 const double r1 = w / 2.0;
129 const double r2 = h / 2.0;
131 for (
int i = 1; i < nCategories; ++i )
135 lineEllipseIntersection( QPointF( baseX + w / nCategories * i, baseY ), QPointF( baseX + w / nCategories * i, baseY + h ), center, r1, r2, intersect );
139 lineEllipseIntersection( QPointF( baseX, baseY + h / nCategories * i ), QPointF( baseX + w, baseY + h / nCategories * i ), center, r1, r2, intersect );
141 if ( intersect.size() > 1 )
143 p->drawLine( intersect.at( 0 ), intersect.at( 1 ) );
149 p->drawRect( QRectF( baseX, baseY, w, h ) );
150 for (
int i = 1; i < nCategories; ++i )
154 p->drawLine( QPointF( baseX + w / nCategories * i, baseY ), QPointF( baseX + w / nCategories * i, baseY + h ) );
158 p->drawLine( QPointF( baseX, baseY + h / nCategories * i ), QPointF( baseX + w, baseY + h / nCategories * i ) );
165 triangle << QPointF( baseX, baseY + h ) << QPointF( baseX + w, baseY + h ) << QPointF( baseX + w / 2.0, baseY );
166 p->drawPolygon( triangle );
168 const QLineF triangleEdgeLeft( baseX + w / 2.0, baseY, baseX, baseY + h );
169 const QLineF triangleEdgeRight( baseX + w, baseY + h, baseX + w / 2.0, baseY );
170 QPointF intersectionPoint1, intersectionPoint2;
172 for (
int i = 1; i < nCategories; ++i )
176 const QLineF verticalLine( baseX + w / nCategories * i, baseY + h, baseX + w / nCategories * i, baseY );
177 if ( baseX + w / nCategories * i < baseX + w / 2.0 )
179 verticalLine.intersects( triangleEdgeLeft, &intersectionPoint1 );
183 verticalLine.intersects( triangleEdgeRight, &intersectionPoint1 );
185 p->drawLine( QPointF( baseX + w / nCategories * i, baseY + h ), intersectionPoint1 );
189 const QLineF horizontalLine( baseX, baseY + h / nCategories * i, baseX + w, baseY + h / nCategories * i );
190 horizontalLine.intersects( triangleEdgeLeft, &intersectionPoint1 );
191 horizontalLine.intersects( triangleEdgeRight, &intersectionPoint2 );
192 p->drawLine( intersectionPoint1, intersectionPoint2 );
199 const QFontMetricsF fontMetrics( sFont );
207 for (
int i = 0; i < textPositions.size(); ++i )
210 const QString val = expression->
evaluate( &expressionContext ).toString();
213 const double textWidth = fontMetrics.horizontalAdvance( val );
214 const double textHeight = fontMetrics.height();
218 const QPointF position = textPositions.at( i );
226 xOffset = textHeight / 2.0;
230 xOffset = fontMetrics.xHeight();
233 p->drawText( QPointF( position.x() - textWidth / 2.0, position.y() + xOffset ), val );
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
Contains information about the context of a rendering operation.
void renderDiagram(const QgsFeature &feature, QgsRenderContext &c, const QgsDiagramSettings &s, QPointF position) override
Draws the diagram at the given position (in pixel coordinates)
double legendSize(double value, const QgsDiagramSettings &s, const QgsDiagramInterpolationSettings &interpolationSettings) const override
Returns the size of the legend item for the diagram corresponding to a specified value.
QgsTextDiagram * clone() const override
Returns an instance that is equivalent to this one.
QSizeF diagramSize(const QgsAttributes &attributes, const QgsRenderContext &c, const QgsDiagramSettings &s) override
Returns the size in map units the diagram will use to render.
QString diagramName() const override
Gets a descriptive name for this diagram type.