47 attrVal = expression->
evaluate( feature );
59 double scaledValue = attrVal.
toDouble();
70 scaledValue = sqrt( scaledValue );
71 scaledLowerValue = sqrt( scaledLowerValue );
72 scaledUpperValue = sqrt( scaledUpperValue );
73 scaledLowerSizeWidth = sqrt( scaledLowerSizeWidth );
74 scaledLowerSizeHeight = sqrt( scaledLowerSizeHeight );
75 scaledUpperSizeWidth = sqrt( scaledUpperSizeWidth );
76 scaledUpperSizeHeight = sqrt( scaledUpperSizeHeight );
80 double scaledRatio = ( scaledValue - scaledLowerValue ) / ( scaledUpperValue - scaledLowerValue );
97 Q_UNUSED( attributes );
114 double w = spu.
width();
117 double baseX = position.
x();
118 double baseY = position.
y() - h;
122 for (
int i = 0; i < nCategories; ++i )
126 textPositions.
push_back(
QPointF( baseX + ( w / nCategories ) * i + w / nCategories / 2.0, baseY + h / 2.0 ) );
130 textPositions.
push_back(
QPointF( baseX + w / 2.0, baseY + h / nCategories * i + w / nCategories / 2.0 ) );
147 QPointF center( baseX + w / 2.0, baseY + h / 2.0 );
148 double r1 = w / 2.0;
double r2 = h / 2.0;
150 for (
int i = 1; i < nCategories; ++i )
154 lineEllipseIntersection(
QPointF( baseX + w / nCategories * i, baseY ),
QPointF( baseX + w / nCategories * i, baseY + h ), center, r1, r2, intersect );
158 lineEllipseIntersection(
QPointF( baseX, baseY + h / nCategories * i ),
QPointF( baseX + w, baseY + h / nCategories * i ), center, r1, r2, intersect );
160 if ( intersect.
size() > 1 )
169 for (
int i = 1; i < nCategories; ++i )
173 p->
drawLine(
QPointF( baseX + w / nCategories * i, baseY ),
QPointF( baseX + w / nCategories * i, baseY + h ) );
177 p->
drawLine(
QPointF( baseX, baseY + h / nCategories * i ),
QPointF( baseX + w, baseY + h / nCategories * i ) );
184 triangle <<
QPointF( baseX, baseY + h ) <<
QPointF( baseX + w, baseY + h ) <<
QPointF( baseX + w / 2.0, baseY );
187 QLineF triangleEdgeLeft( baseX + w / 2.0, baseY, baseX, baseY + h );
188 QLineF triangleEdgeRight( baseX + w, baseY + h, baseX + w / 2.0, baseY );
189 QPointF intersectionPoint1, intersectionPoint2;
191 for (
int i = 1; i < nCategories; ++i )
195 QLineF verticalLine( baseX + w / nCategories * i, baseY + h, baseX + w / nCategories * i, baseY );
196 if ( baseX + w / nCategories * i < baseX + w / 2.0 )
198 verticalLine.
intersect( triangleEdgeLeft, &intersectionPoint1 );
202 verticalLine.
intersect( triangleEdgeRight, &intersectionPoint1 );
204 p->
drawLine( QPointF( baseX + w / nCategories * i, baseY + h ), intersectionPoint1 );
208 QLineF horizontalLine( baseX, baseY + h / nCategories * i, baseX + w, baseY + h / nCategories * i );
209 horizontalLine.
intersect( triangleEdgeLeft, &intersectionPoint1 );
210 horizontalLine.
intersect( triangleEdgeRight, &intersectionPoint2 );
211 p->
drawLine( intersectionPoint1, intersectionPoint2 );
221 for (
int i = 0; i < textPositions.
size(); ++i )
227 double textWidth = fontMetrics.
width( val );
228 double textHeight = fontMetrics.
height();
232 QPointF position = textPositions.
at( i );
240 xOffset = textHeight / 2.0;
244 xOffset = fontMetrics.
xHeight();
247 p->
drawText(
QPointF( position.
x() - textWidth / 2.0, position.
y() + xOffset ), val );
251 void QgsTextDiagram::lineEllipseIntersection(
const QPointF& lineStart,
const QPointF& lineEnd,
const QPointF& ellipseMid,
double r1,
double r2,
QList<QPointF>& result )
const
255 double rrx = r1 * r1;
256 double rry = r2 * r2;
257 double x21 = lineEnd.
x() - lineStart.
x();
258 double y21 = lineEnd.
y() - lineStart.
y();
259 double x10 = lineStart.
x() - ellipseMid.
x();
260 double y10 = lineStart.
y() - ellipseMid.
y();
261 double a = x21 * x21 / rrx + y21 * y21 / rry;
262 double b = x21 * x10 / rrx + y21 * y10 / rry;
263 double c = x10 * x10 / rrx + y10 * y10 / rry;
264 double d = b * b - a * ( c - 1 );
267 double e = sqrt( d );
268 double u1 = ( -b - e ) / a;
269 double u2 = ( -b + e ) / a;
271 if ( -0.00001 <= u1 && u1 < 1.00001 )
275 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)
void push_back(const T &value)
QVariant evaluate(const QgsFeature *f=NULL)
Evaluate the feature and return the result.
QList< QString > categoryAttributes
QgsExpression * getExpression(const QString &expression, const QgsFields *fields)
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.
void setWidthF(qreal width)
void setBrush(const QBrush &brush)
void drawText(const QPointF &position, const QString &text)
void setColor(const QColor &color)
Base class for all diagram types.
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