50 attrVal = expression->
evaluate( &expressionContext );
58 double val = attrVal.
toDouble( &ok );
76 Q_UNUSED( attributes );
91 double w = spu.
width();
94 double baseX = position.
x();
95 double baseY = position.
y() - h;
99 for (
int i = 0; i < nCategories; ++i )
103 textPositions.
push_back(
QPointF( baseX + ( w / nCategories ) * i + w / nCategories / 2.0, baseY + h / 2.0 ) );
107 textPositions.
push_back(
QPointF( baseX + w / 2.0, baseY + h / nCategories * i + w / nCategories / 2.0 ) );
124 QPointF center( baseX + w / 2.0, baseY + h / 2.0 );
128 for (
int i = 1; i < nCategories; ++i )
132 lineEllipseIntersection(
QPointF( baseX + w / nCategories * i, baseY ),
QPointF( baseX + w / nCategories * i, baseY + h ), center, r1, r2, intersect );
136 lineEllipseIntersection(
QPointF( baseX, baseY + h / nCategories * i ),
QPointF( baseX + w, baseY + h / nCategories * i ), center, r1, r2, intersect );
138 if ( intersect.
size() > 1 )
147 for (
int i = 1; i < nCategories; ++i )
151 p->
drawLine(
QPointF( baseX + w / nCategories * i, baseY ),
QPointF( baseX + w / nCategories * i, baseY + h ) );
155 p->
drawLine(
QPointF( baseX, baseY + h / nCategories * i ),
QPointF( baseX + w, baseY + h / nCategories * i ) );
162 triangle <<
QPointF( baseX, baseY + h ) <<
QPointF( baseX + w, baseY + h ) <<
QPointF( baseX + w / 2.0, baseY );
165 QLineF triangleEdgeLeft( baseX + w / 2.0, baseY, baseX, baseY + h );
166 QLineF triangleEdgeRight( baseX + w, baseY + h, baseX + w / 2.0, baseY );
167 QPointF intersectionPoint1, intersectionPoint2;
169 for (
int i = 1; i < nCategories; ++i )
173 QLineF verticalLine( baseX + w / nCategories * i, baseY + h, baseX + w / nCategories * i, baseY );
174 if ( baseX + w / nCategories * i < baseX + w / 2.0 )
176 verticalLine.
intersect( triangleEdgeLeft, &intersectionPoint1 );
180 verticalLine.
intersect( triangleEdgeRight, &intersectionPoint1 );
182 p->
drawLine( QPointF( baseX + w / nCategories * i, baseY + h ), intersectionPoint1 );
186 QLineF horizontalLine( baseX, baseY + h / nCategories * i, baseX + w, baseY + h / nCategories * i );
187 horizontalLine.
intersect( triangleEdgeLeft, &intersectionPoint1 );
188 horizontalLine.
intersect( triangleEdgeRight, &intersectionPoint2 );
189 p->
drawLine( intersectionPoint1, intersectionPoint2 );
204 for (
int i = 0; i < textPositions.
size(); ++i )
210 double textWidth = fontMetrics.
width( val );
211 double textHeight = fontMetrics.
height();
215 QPointF position = textPositions.
at( i );
223 xOffset = textHeight / 2.0;
227 xOffset = fontMetrics.
xHeight();
230 p->
drawText(
QPointF( position.
x() - textWidth / 2.0, position.
y() + xOffset ), val );
238 double rrx = r1 * r1;
239 double rry = r2 * r2;
240 double x21 = lineEnd.
x() - lineStart.
x();
241 double y21 = lineEnd.
y() - lineStart.
y();
242 double x10 = lineStart.
x() - ellipseMid.
x();
243 double y10 = lineStart.
y() - ellipseMid.
y();
244 double a = x21 * x21 / rrx + y21 * y21 / rry;
245 double b = x21 * x10 / rrx + y21 * y10 / rry;
246 double c = x10 * x10 / rrx + y10 * y10 / rry;
247 double d = b * b - a * ( c - 1 );
250 double e = sqrt( d );
251 double u1 = ( -b - e ) / a;
252 double u2 = ( -b + e ) / a;
254 if ( -0.00001 <= u1 && u1 < 1.00001 )
258 if ( -0.00001 <= u2 && u2 <= 1.00001 )
QSizeF sizePainterUnits(QSizeF size, const QgsDiagramSettings &s, const QgsRenderContext &c)
Calculates a size to match the current settings and rendering context.
Class for parsing and evaluation of expressions (formerly called "search strings").
QgsAttributes attributes() const
Returns the feature's attributes.
Q_DECL_DEPRECATED QVariant evaluate(const QgsFeature *f)
Evaluate the feature and return the result.
void push_back(const T &value)
QList< QString > categoryAttributes
Q_DECL_DEPRECATED QgsExpression * getExpression(const QString &expression, const QgsFields *fields)
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
bool classificationAttributeIsExpression
const T & at(int i) const
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void drawLine(const QLineF &line)
void setStyle(Qt::BrushStyle style)
void renderDiagram(const QgsFeature &feature, QgsRenderContext &c, const QgsDiagramSettings &s, QPointF position) override
Draws the diagram at the given position (in pixel coordinates)
qreal width(const QString &text) const
void setCapStyle(Qt::PenCapStyle style)
void drawRect(const QRectF &rectangle)
void setFont(const QFont &font)
const QgsFields * fields() const
Returns the field map associated with the feature.
IntersectType intersect(const QLineF &line, QPointF *intersectionPoint) const
void setPen(const QColor &color)
void drawEllipse(const QRectF &rectangle)
QString classificationAttributeExpression
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setWidthF(qreal width)
void setBrush(const QBrush &brush)
void drawText(const QPointF &position, const QString &text)
virtual QgsTextDiagram * clone() const override
Returns an instance that is equivalent to this one.
void setColor(const QColor &color)
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
QSizeF sizeForValue(double value, const QgsDiagramSettings &s, const QgsDiagramInterpolationSettings &is) const
Returns the scaled size of a diagram for a value, respecting the specified diagram interpolation sett...
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.
QgsExpressionContext & expressionContext()
Gets the expression context.
const T & at(int i) const
Additional diagram settings for interpolated size rendering.
Contains information about the context of a rendering operation.
QFont scaledFont(const QgsDiagramSettings &s, const QgsRenderContext &c)
Calculates a size to match the current settings and rendering context.
QSizeF diagramSize(const QgsAttributes &attributes, const QgsRenderContext &c, const QgsDiagramSettings &s) override
Returns the size in map units the diagram will use to render.
void push_back(const T &value)
double toDouble(bool *ok) const
int classificationAttribute
Index of the classification attribute.
void setPenWidth(QPen &pen, const QgsDiagramSettings &s, const QgsRenderContext &c)
Changes the pen width to match the current settings and rendering context.
QList< QColor > categoryColors
void setColor(const QColor &color)
Stores the settings for rendering a single diagram.
LabelPlacementMethod labelPlacementMethod