50 attrVal = expression->
evaluate( &expressionContext );
62 double scaledValue = attrVal.
toDouble();
73 scaledValue = sqrt( scaledValue );
74 scaledLowerValue = sqrt( scaledLowerValue );
75 scaledUpperValue = sqrt( scaledUpperValue );
76 scaledLowerSizeWidth = sqrt( scaledLowerSizeWidth );
77 scaledLowerSizeHeight = sqrt( scaledLowerSizeHeight );
78 scaledUpperSizeWidth = sqrt( scaledUpperSizeWidth );
79 scaledUpperSizeHeight = sqrt( scaledUpperSizeHeight );
83 double scaledRatio = ( scaledValue - scaledLowerValue ) / ( scaledUpperValue - scaledLowerValue );
100 Q_UNUSED( attributes );
115 double w = spu.
width();
118 double baseX = position.
x();
119 double baseY = position.
y() - h;
123 for (
int i = 0; i < nCategories; ++i )
127 textPositions.
push_back(
QPointF( baseX + ( w / nCategories ) * i + w / nCategories / 2.0, baseY + h / 2.0 ) );
131 textPositions.
push_back(
QPointF( baseX + w / 2.0, baseY + h / nCategories * i + w / nCategories / 2.0 ) );
148 QPointF center( baseX + w / 2.0, baseY + h / 2.0 );
152 for (
int i = 1; i < nCategories; ++i )
156 lineEllipseIntersection(
QPointF( baseX + w / nCategories * i, baseY ),
QPointF( baseX + w / nCategories * i, baseY + h ), center, r1, r2, intersect );
160 lineEllipseIntersection(
QPointF( baseX, baseY + h / nCategories * i ),
QPointF( baseX + w, baseY + h / nCategories * i ), center, r1, r2, intersect );
162 if ( intersect.
size() > 1 )
171 for (
int i = 1; i < nCategories; ++i )
175 p->
drawLine(
QPointF( baseX + w / nCategories * i, baseY ),
QPointF( baseX + w / nCategories * i, baseY + h ) );
179 p->
drawLine(
QPointF( baseX, baseY + h / nCategories * i ),
QPointF( baseX + w, baseY + h / nCategories * i ) );
186 triangle <<
QPointF( baseX, baseY + h ) <<
QPointF( baseX + w, baseY + h ) <<
QPointF( baseX + w / 2.0, baseY );
189 QLineF triangleEdgeLeft( baseX + w / 2.0, baseY, baseX, baseY + h );
190 QLineF triangleEdgeRight( baseX + w, baseY + h, baseX + w / 2.0, baseY );
191 QPointF intersectionPoint1, intersectionPoint2;
193 for (
int i = 1; i < nCategories; ++i )
197 QLineF verticalLine( baseX + w / nCategories * i, baseY + h, baseX + w / nCategories * i, baseY );
198 if ( baseX + w / nCategories * i < baseX + w / 2.0 )
200 verticalLine.
intersect( triangleEdgeLeft, &intersectionPoint1 );
204 verticalLine.
intersect( triangleEdgeRight, &intersectionPoint1 );
206 p->
drawLine( QPointF( baseX + w / nCategories * i, baseY + h ), intersectionPoint1 );
210 QLineF horizontalLine( baseX, baseY + h / nCategories * i, baseX + w, baseY + h / nCategories * i );
211 horizontalLine.
intersect( triangleEdgeLeft, &intersectionPoint1 );
212 horizontalLine.
intersect( triangleEdgeRight, &intersectionPoint2 );
213 p->
drawLine( intersectionPoint1, intersectionPoint2 );
228 for (
int i = 0; i < textPositions.
size(); ++i )
234 double textWidth = fontMetrics.
width( val );
235 double textHeight = fontMetrics.
height();
239 QPointF position = textPositions.
at( i );
247 xOffset = textHeight / 2.0;
251 xOffset = fontMetrics.
xHeight();
254 p->
drawText(
QPointF( position.
x() - textWidth / 2.0, position.
y() + xOffset ), val );
262 double rrx = r1 * r1;
263 double rry = r2 * r2;
264 double x21 = lineEnd.
x() - lineStart.
x();
265 double y21 = lineEnd.
y() - lineStart.
y();
266 double x10 = lineStart.
x() - ellipseMid.
x();
267 double y10 = lineStart.
y() - ellipseMid.
y();
268 double a = x21 * x21 / rrx + y21 * y21 / rry;
269 double b = x21 * x10 / rrx + y21 * y10 / rry;
270 double c = x10 * x10 / rrx + y10 * y10 / rry;
271 double d = b * b - a * ( c - 1 );
274 double e = sqrt( d );
275 double u1 = ( -b - e ) / a;
276 double u2 = ( -b + e ) / a;
278 if ( -0.00001 <= u1 && u1 < 1.00001 )
282 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").
double minimumSize
Scale diagrams smaller than mMinimumSize to mMinimumSize.
void scale(qreal width, qreal height, Qt::AspectRatioMode mode)
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)
IntersectType intersect(const QLineF &line, QPointF *intersectionPoint) const
QgsAttributes attributes() const
Returns the feature's attributes.
void setPen(const QColor &color)
void drawEllipse(const QRectF &rectangle)
QString classificationAttributeExpression
const QgsFields * fields() const
Returns the field map associated with the feature.
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.
QgsExpressionContext & expressionContext()
Gets the expression context.
const T & at(int i) const
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)
LabelPlacementMethod labelPlacementMethod