10#include <QAbstractItemModel>
13#include "RangeGroup.h"
14#include "datasource/ChartDataSource.h"
15#include "scenegraph/PieChartNode.h"
21 m_range = std::make_unique<RangeGroup>();
35void PieChart::setFilled(
bool newFilled)
37 if (newFilled == m_filled) {
51void PieChart::setThickness(qreal newThickness)
53 if (newThickness == m_thickness) {
57 m_thickness = newThickness;
67void PieChart::setSpacing(qreal newSpacing)
69 if (newSpacing == m_spacing) {
73 m_spacing = newSpacing;
80 return m_backgroundColor;
83void PieChart::setBackgroundColor(
const QColor &color)
85 if (color == m_backgroundColor) {
88 m_backgroundColor = color;
90 Q_EMIT backgroundColorChanged();
98void PieChart::setFromAngle(qreal newFromAngle)
100 if (qFuzzyCompare(newFromAngle, m_fromAngle)) {
104 m_fromAngle = newFromAngle;
106 Q_EMIT fromAngleChanged();
114void PieChart::setToAngle(qreal newToAngle)
116 if (qFuzzyCompare(newToAngle, m_toAngle)) {
120 m_toAngle = newToAngle;
130void PieChart::setSmoothEnds(
bool newSmoothEnds)
132 if (newSmoothEnds == m_smoothEnds) {
136 m_smoothEnds = newSmoothEnds;
138 Q_EMIT smoothEndsChanged();
150 if (m_sections.
count() < sourceCount) {
156 float outerRadius = minDimension;
157 for (
int i = 0; i < sourceCount; ++i) {
158 float innerRadius = i == sourceCount - 1 && m_filled ? 0.0 : outerRadius - m_thickness * 2.0;
164 auto pieNode =
static_cast<PieChartNode *
>(node->
childAtIndex(i));
166 pieNode->setInnerRadius(innerRadius);
167 pieNode->setOuterRadius(outerRadius);
168 pieNode->setSections(m_sections.
at(i));
169 pieNode->setBackgroundColor(m_backgroundColor);
170 pieNode->setColors(m_colors.
at(i));
171 pieNode->setFromAngle(m_fromAngle);
172 pieNode->setToAngle(m_toAngle);
173 pieNode->setSmoothEnds(m_smoothEnds);
175 outerRadius = innerRadius - m_spacing * 2.0;
195 if (!colors || sources.isEmpty() || !m_range->isValid()) {
201 for (
int i = 0; i < source->itemCount(); ++i) {
202 result += source->item(i).toDouble();
204 return std::max(result, source->maximum().toDouble());
213 auto range = m_range->calculateRange(
valueSources(), calculateZeroRange, maximum);
215 for (
auto source : sources) {
216 qreal threshold =
range.start;
222 for (
int i = 0; i < source->itemCount(); ++i) {
223 auto value = source->item(i).toReal();
224 auto limited = value - threshold;
226 if (total + limited >=
range.end) {
227 limited =
range.end - total;
233 auto color = colors->item(colorIndex).
value<
QColor>();
235 if (highlightIndex >= 0 && highlightIndex != colorIndex) {
239 sectionColors << color;
241 threshold = std::max(0.0, threshold - value);
248 if (qFuzzyCompare(total, 0.0)) {
249 m_sections << QList<qreal>{0.0};
250 m_colors << QList<QColor>{colors->item(colorIndex).value<
QColor>()};
253 for (
auto &value : sections) {
257 m_sections << sections;
258 m_colors << sectionColors;
270#include "moc_PieChart.cpp"
Abstract base class for data sources.
Abstract base class for all charts.
QColor desaturate(const QColor &input)
Desaturate and de-emphasise a color.
QQmlListProperty< ChartDataSource > valueSources
The data sources providing the data this chart needs to render.
ChartDataSource * colorSource
The data source to use for colors of chart items.
int highlight
The index of a value source to highlight.
@ IndexSourceValues
Index each value, restart indexing for each value source.
@ IndexEachSource
Index each value source, never index individual values.
IndexingMode indexingMode
The indexing mode used for indexing colors and names.
bool smoothEnds
Smooth the ends of pie sections.
QSGNode * updatePaintNode(QSGNode *node, UpdatePaintNodeData *data) override
Reimplemented from QQuickItem.
qreal fromAngle
The starting angle of the arc used for the entire pie.
qreal spacing
The amount of spacing between pies when rendering multiple value sources.
void onDataChanged() override
Reimplemented from Chart.
qreal toAngle
The end angle of the arc used for the entire pie.
qreal thickness
The thickness of an individual pie, in pixels.
RangeGroup * range
The range of values to display in this PieChart.
bool filled
Whether to use a filled pie or not.
QColor backgroundColor
Sets a colour to use to fill remaining space on the pie.
An object that can be used as a grouped property to provide a value range for charts.
qreal distance
The distance between from and to.
const_reference at(qsizetype i) const const
qsizetype count() const const
virtual QRectF boundingRect() const const
void appendChildNode(QSGNode *node)
QSGNode * childAtIndex(int i) const const
int childCount() const const
void removeChildNode(QSGNode *node)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)