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 );
149 double r1 = w / 2.0;
double r2 = h / 2.0;
151 for (
int i = 1; i < nCategories; ++i )
155 lineEllipseIntersection(
QPointF( baseX + w / nCategories * i, baseY ),
QPointF( baseX + w / nCategories * i, baseY + h ), center, r1, r2, intersect );
159 lineEllipseIntersection(
QPointF( baseX, baseY + h / nCategories * i ),
QPointF( baseX + w, baseY + h / nCategories * i ), center, r1, r2, intersect );
161 if ( intersect.
size() > 1 )
170 for (
int i = 1; i < nCategories; ++i )
174 p->
drawLine(
QPointF( baseX + w / nCategories * i, baseY ),
QPointF( baseX + w / nCategories * i, baseY + h ) );
178 p->
drawLine(
QPointF( baseX, baseY + h / nCategories * i ),
QPointF( baseX + w, baseY + h / nCategories * i ) );
185 triangle <<
QPointF( baseX, baseY + h ) <<
QPointF( baseX + w, baseY + h ) <<
QPointF( baseX + w / 2.0, baseY );
188 QLineF triangleEdgeLeft( baseX + w / 2.0, baseY, baseX, baseY + h );
189 QLineF triangleEdgeRight( baseX + w, baseY + h, baseX + w / 2.0, baseY );
190 QPointF intersectionPoint1, intersectionPoint2;
192 for (
int i = 1; i < nCategories; ++i )
196 QLineF verticalLine( baseX + w / nCategories * i, baseY + h, baseX + w / nCategories * i, baseY );
197 if ( baseX + w / nCategories * i < baseX + w / 2.0 )
199 verticalLine.
intersect( triangleEdgeLeft, &intersectionPoint1 );
203 verticalLine.
intersect( triangleEdgeRight, &intersectionPoint1 );
205 p->
drawLine( QPointF( baseX + w / nCategories * i, baseY + h ), intersectionPoint1 );
209 QLineF horizontalLine( baseX, baseY + h / nCategories * i, baseX + w, baseY + h / nCategories * i );
210 horizontalLine.
intersect( triangleEdgeLeft, &intersectionPoint1 );
211 horizontalLine.
intersect( triangleEdgeRight, &intersectionPoint2 );
212 p->
drawLine( intersectionPoint1, intersectionPoint2 );
227 for (
int i = 0; i < textPositions.
size(); ++i )
233 double textWidth = fontMetrics.
width( val );
234 double textHeight = fontMetrics.
height();
238 QPointF position = textPositions.
at( i );
246 xOffset = textHeight / 2.0;
250 xOffset = fontMetrics.
xHeight();
253 p->
drawText(
QPointF( position.
x() - textWidth / 2.0, position.
y() + xOffset ), val );
257 void QgsTextDiagram::lineEllipseIntersection(
const QPointF& lineStart,
const QPointF& lineEnd,
const QPointF& ellipseMid,
double r1,
double r2,
QList<QPointF>& result )
const
261 double rrx = r1 * r1;
262 double rry = r2 * r2;
263 double x21 = lineEnd.
x() - lineStart.
x();
264 double y21 = lineEnd.
y() - lineStart.
y();
265 double x10 = lineStart.
x() - ellipseMid.
x();
266 double y10 = lineStart.
y() - ellipseMid.
y();
267 double a = x21 * x21 / rrx + y21 * y21 / rry;
268 double b = x21 * x10 / rrx + y21 * y10 / rry;
269 double c = x10 * x10 / rrx + y10 * y10 / rry;
270 double d = b * b - a * ( c - 1 );
273 double e = sqrt( d );
274 double u1 = ( -b - e ) / a;
275 double u2 = ( -b + e ) / a;
277 if ( -0.00001 <= u1 && u1 < 1.00001 )
281 if ( -0.00001 <= u2 && u2 <= 1.00001 )
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)
virtual QgsDiagram * clone() const override
Returns an instance that is equivalent to this one.
void setStyle(Qt::BrushStyle style)
qreal width(const QString &text) const
QSizeF sizePainterUnits(const QSizeF &size, const QgsDiagramSettings &s, const QgsRenderContext &c)
Calculates a size to match the current settings and rendering context.
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)
void setColor(const QColor &color)
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
Base class for all diagram types.
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.
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)
void renderDiagram(const QgsFeature &feature, QgsRenderContext &c, const QgsDiagramSettings &s, const QPointF &position) override
Draws the diagram at the given position (in pixel coordinates)
LabelPlacementMethod labelPlacementMethod