84 QPainter *p =
c.painter();
92 const double w = spu.width();
93 const double h = spu.height();
95 const double baseX = position.x();
96 const double baseY = position.y() - h;
98 QVector<QPointF> textPositions;
100 for (
int i = 0; i < nCategories; ++i )
104 textPositions.push_back( QPointF( baseX + ( w / nCategories ) * i + w / nCategories / 2.0, baseY + h / 2.0 ) );
108 textPositions.push_back( QPointF( baseX + w / 2.0, baseY + h / nCategories * i + w / nCategories / 2.0 ) );
116 p->setBrush( mBrush );
121 p->drawEllipse( baseX, baseY, w, h );
124 QList<QPointF> intersect;
125 const QPointF center( baseX + w / 2.0, baseY + h / 2.0 );
126 const double r1 = w / 2.0;
127 const double r2 = h / 2.0;
129 for (
int i = 1; i < nCategories; ++i )
133 lineEllipseIntersection( QPointF( baseX + w / nCategories * i, baseY ), QPointF( baseX + w / nCategories * i, baseY + h ), center, r1, r2, intersect );
137 lineEllipseIntersection( QPointF( baseX, baseY + h / nCategories * i ), QPointF( baseX + w, baseY + h / nCategories * i ), center, r1, r2, intersect );
139 if ( intersect.size() > 1 )
141 p->drawLine( intersect.at( 0 ), intersect.at( 1 ) );
147 p->drawRect( QRectF( baseX, baseY, w, h ) );
148 for (
int i = 1; i < nCategories; ++i )
152 p->drawLine( QPointF( baseX + w / nCategories * i, baseY ), QPointF( baseX + w / nCategories * i, baseY + h ) );
156 p->drawLine( QPointF( baseX, baseY + h / nCategories * i ), QPointF( baseX + w, baseY + h / nCategories * i ) );
163 triangle << QPointF( baseX, baseY + h ) << QPointF( baseX + w, baseY + h ) << QPointF( baseX + w / 2.0, baseY );
164 p->drawPolygon( triangle );
166 const QLineF triangleEdgeLeft( baseX + w / 2.0, baseY, baseX, baseY + h );
167 const QLineF triangleEdgeRight( baseX + w, baseY + h, baseX + w / 2.0, baseY );
168 QPointF intersectionPoint1, intersectionPoint2;
170 for (
int i = 1; i < nCategories; ++i )
174 const QLineF verticalLine( baseX + w / nCategories * i, baseY + h, baseX + w / nCategories * i, baseY );
175 if ( baseX + w / nCategories * i < baseX + w / 2.0 )
177 verticalLine.intersects( triangleEdgeLeft, &intersectionPoint1 );
181 verticalLine.intersects( triangleEdgeRight, &intersectionPoint1 );
183 p->drawLine( QPointF( baseX + w / nCategories * i, baseY + h ), intersectionPoint1 );
187 const QLineF horizontalLine( baseX, baseY + h / nCategories * i, baseX + w, baseY + h / nCategories * i );
188 horizontalLine.intersects( triangleEdgeLeft, &intersectionPoint1 );
189 horizontalLine.intersects( triangleEdgeRight, &intersectionPoint2 );
190 p->drawLine( intersectionPoint1, intersectionPoint2 );
197 const QFontMetricsF fontMetrics( sFont );
205 for (
int i = 0; i < textPositions.size(); ++i )
208 const QString val = expression->
evaluate( &expressionContext ).toString();
211 const double textWidth = fontMetrics.horizontalAdvance( val );
212 const double textHeight = fontMetrics.height();
216 const QPointF position = textPositions.at( i );
224 xOffset = textHeight / 2.0;
228 xOffset = fontMetrics.xHeight();
231 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)
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.
double legendSize(double value, const QgsDiagramSettings &s, const QgsDiagramInterpolationSettings &is) const override
Returns the size of the legend item for the diagram corresponding to a specified value.
#define DIAGRAM_NAME_TEXT