@@ -0,0 +1,122 | |||
|
1 | ||
|
2 | #include "piepresentation.h" | |
|
3 | #include "pieslice.h" | |
|
4 | #include <QDebug> | |
|
5 | ||
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
7 | ||
|
8 | PiePresentation::PiePresentation(QGraphicsItem *parent, QPieSeries *series) : | |
|
9 | ChartItem(parent), | |
|
10 | m_pieSeries(series) | |
|
11 | { | |
|
12 | Q_ASSERT(parent); | |
|
13 | Q_ASSERT(series); | |
|
14 | m_rect = parentItem()->boundingRect(); | |
|
15 | setAcceptHoverEvents(true); | |
|
16 | } | |
|
17 | ||
|
18 | PiePresentation::~PiePresentation() | |
|
19 | { | |
|
20 | while (m_slices.count()) | |
|
21 | delete m_slices.takeLast(); | |
|
22 | } | |
|
23 | ||
|
24 | void PiePresentation::seriesChanged() | |
|
25 | { | |
|
26 | const qreal fullPie = 360; | |
|
27 | qreal total = 0; | |
|
28 | ||
|
29 | // calculate total | |
|
30 | foreach (QPieSlice sliceData, m_pieSeries->slices()) | |
|
31 | total += sliceData.m_value; | |
|
32 | ||
|
33 | // TODO: no need to create new slices in case size changed; we should re-use the existing ones | |
|
34 | while (m_slices.count()) | |
|
35 | delete m_slices.takeLast(); | |
|
36 | ||
|
37 | // create slices | |
|
38 | qreal angle = 0; | |
|
39 | for (int i=0; i<m_pieSeries->count(); i++) { | |
|
40 | QPieSlice sliceData = m_pieSeries->slice(i); | |
|
41 | qreal span = sliceData.m_value / total * fullPie; | |
|
42 | PieSlice *slice = new PieSlice(this, i, angle, span); | |
|
43 | m_slices.append(slice); | |
|
44 | angle += span; | |
|
45 | } | |
|
46 | ||
|
47 | resize(); | |
|
48 | } | |
|
49 | ||
|
50 | void PiePresentation::setSize(const QSizeF &size) | |
|
51 | { | |
|
52 | // TODO: allow user setting the size? | |
|
53 | // TODO: allow user defining the margins? | |
|
54 | m_rect.setSize(size); | |
|
55 | resize(); | |
|
56 | } | |
|
57 | ||
|
58 | void PiePresentation::setPlotDomain(const PlotDomain& plotDomain) | |
|
59 | { | |
|
60 | // TODO | |
|
61 | } | |
|
62 | ||
|
63 | void PiePresentation::resize() | |
|
64 | { | |
|
65 | m_pieRect = m_rect; | |
|
66 | ||
|
67 | if (m_pieRect.width() < m_pieRect.height()) { | |
|
68 | m_pieRect.setWidth(m_pieRect.width() * m_pieSeries->m_sizeFactor); | |
|
69 | m_pieRect.setHeight(m_pieRect.width()); | |
|
70 | m_pieRect.moveCenter(m_rect.center()); | |
|
71 | } else { | |
|
72 | m_pieRect.setHeight(m_pieRect.height() * m_pieSeries->m_sizeFactor); | |
|
73 | m_pieRect.setWidth(m_pieRect.height()); | |
|
74 | m_pieRect.moveCenter(m_rect.center()); | |
|
75 | } | |
|
76 | ||
|
77 | switch (m_pieSeries->m_position) { | |
|
78 | case QPieSeries::PiePositionTopLeft: { | |
|
79 | m_pieRect.setHeight(m_pieRect.height() / 2); | |
|
80 | m_pieRect.setWidth(m_pieRect.height()); | |
|
81 | m_pieRect.moveCenter(QPointF(m_rect.center().x() / 2, m_rect.center().y() / 2)); | |
|
82 | break; | |
|
83 | } | |
|
84 | case QPieSeries::PiePositionTopRight: { | |
|
85 | m_pieRect.setHeight(m_pieRect.height() / 2); | |
|
86 | m_pieRect.setWidth(m_pieRect.height()); | |
|
87 | m_pieRect.moveCenter(QPointF((m_rect.center().x() / 2) * 3, m_rect.center().y() / 2)); | |
|
88 | break; | |
|
89 | } | |
|
90 | case QPieSeries::PiePositionBottomLeft: { | |
|
91 | m_pieRect.setHeight(m_pieRect.height() / 2); | |
|
92 | m_pieRect.setWidth(m_pieRect.height()); | |
|
93 | m_pieRect.moveCenter(QPointF(m_rect.center().x() / 2, (m_rect.center().y() / 2) * 3)); | |
|
94 | break; | |
|
95 | } | |
|
96 | case QPieSeries::PiePositionBottomRight: { | |
|
97 | m_pieRect.setHeight(m_pieRect.height() / 2); | |
|
98 | m_pieRect.setWidth(m_pieRect.height()); | |
|
99 | m_pieRect.moveCenter(QPointF((m_rect.center().x() / 2) * 3, (m_rect.center().y() / 2) * 3)); | |
|
100 | break; | |
|
101 | } | |
|
102 | default: | |
|
103 | break; | |
|
104 | } | |
|
105 | ||
|
106 | qDebug() << "presentation rect:" << m_rect; | |
|
107 | qDebug() << "pie rect:" << m_pieRect; | |
|
108 | } | |
|
109 | ||
|
110 | void PiePresentation::handleDomainChanged(const Domain& domain) | |
|
111 | { | |
|
112 | // TODO | |
|
113 | } | |
|
114 | ||
|
115 | void PiePresentation::handleGeometryChanged(const QRectF& rect) | |
|
116 | { | |
|
117 | setSize(rect.size()); | |
|
118 | } | |
|
119 | ||
|
120 | #include "moc_piepresentation.cpp" | |
|
121 | ||
|
122 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,45 | |||
|
1 | #ifndef PIEPRESENTATION_H | |
|
2 | #define PIEPRESENTATION_H | |
|
3 | ||
|
4 | #include "chartitem_p.h" | |
|
5 | #include "qpieseries.h" | |
|
6 | ||
|
7 | class QGraphicsItem; | |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
9 | class PieSlice; | |
|
10 | ||
|
11 | class PiePresentation : public QObject, public ChartItem | |
|
12 | { | |
|
13 | Q_OBJECT | |
|
14 | ||
|
15 | public: | |
|
16 | // TODO: use a generic data class instead of x and y | |
|
17 | PiePresentation(QGraphicsItem *parent, QPieSeries *series); | |
|
18 | ~PiePresentation(); | |
|
19 | ||
|
20 | public: // from ChartItem | |
|
21 | void setSize(const QSizeF &size); | |
|
22 | void setPlotDomain(const PlotDomain& data); | |
|
23 | QRectF boundingRect() const { return m_rect; } | |
|
24 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {} | |
|
25 | ||
|
26 | public: | |
|
27 | void seriesChanged(); | |
|
28 | void resize(); | |
|
29 | QRectF pieRect() const { return m_pieRect; } | |
|
30 | ||
|
31 | public Q_SLOTS: | |
|
32 | void handleDomainChanged(const Domain& domain); | |
|
33 | void handleGeometryChanged(const QRectF& rect); | |
|
34 | ||
|
35 | private: | |
|
36 | friend class PieSlice; | |
|
37 | QList<PieSlice*> m_slices; | |
|
38 | QPieSeries *m_pieSeries; | |
|
39 | QRectF m_rect; | |
|
40 | QRectF m_pieRect; | |
|
41 | }; | |
|
42 | ||
|
43 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
44 | ||
|
45 | #endif // PIEPRESENTATION_H |
@@ -0,0 +1,93 | |||
|
1 | #include "qpieseries.h" | |
|
2 | #include "piepresentation.h" | |
|
3 | #include "pieslice.h" | |
|
4 | #include <QDebug> | |
|
5 | ||
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
7 | ||
|
8 | QPieSeries::QPieSeries(QObject *parent) : | |
|
9 | QChartSeries(parent), | |
|
10 | m_piePresentation(0), | |
|
11 | m_sizeFactor(1.0), | |
|
12 | m_position(PiePositionMaximized) | |
|
13 | { | |
|
14 | } | |
|
15 | ||
|
16 | QPieSeries::~QPieSeries() | |
|
17 | { | |
|
18 | ||
|
19 | } | |
|
20 | ||
|
21 | void QPieSeries::set(QList<QPieSlice> slices) | |
|
22 | { | |
|
23 | m_slices = slices; | |
|
24 | if (m_piePresentation) { | |
|
25 | m_piePresentation->seriesChanged(); | |
|
26 | m_piePresentation->update(); | |
|
27 | } | |
|
28 | } | |
|
29 | ||
|
30 | void QPieSeries::add(QList<QPieSlice> slices) | |
|
31 | { | |
|
32 | m_slices += slices; | |
|
33 | if (m_piePresentation) { | |
|
34 | m_piePresentation->seriesChanged(); | |
|
35 | // TODO: m_piePresentation->seriesAppended()?? | |
|
36 | m_piePresentation->update(); | |
|
37 | } | |
|
38 | } | |
|
39 | ||
|
40 | void QPieSeries::add(QPieSlice slice) | |
|
41 | { | |
|
42 | add(QList<QPieSlice>() << slice); | |
|
43 | } | |
|
44 | ||
|
45 | QPieSlice QPieSeries::slice(int index) const | |
|
46 | { | |
|
47 | if ((index >= 0) && (index < m_slices.count())) | |
|
48 | return m_slices.at(index); | |
|
49 | return QPieSlice(); | |
|
50 | } | |
|
51 | ||
|
52 | bool QPieSeries::update(int index, QPieSlice slice) | |
|
53 | { | |
|
54 | if ((index >= 0) && (index < m_slices.count())) { | |
|
55 | m_slices[index] = slice; | |
|
56 | if (m_piePresentation) { | |
|
57 | m_piePresentation->seriesChanged(); | |
|
58 | // TODO: for a nice animation we need something like | |
|
59 | // m_piePresentation->sliceChanged(index, oldslice, newslice) | |
|
60 | m_piePresentation->update(); | |
|
61 | } | |
|
62 | return true; | |
|
63 | } | |
|
64 | return false; | |
|
65 | } | |
|
66 | ||
|
67 | void QPieSeries::setSizeFactor(qreal factor) | |
|
68 | { | |
|
69 | if (factor > 0.0) | |
|
70 | m_sizeFactor = factor; | |
|
71 | ||
|
72 | if (m_piePresentation) { | |
|
73 | m_piePresentation->resize(); | |
|
74 | m_piePresentation->update(); | |
|
75 | // TODO: do we have to update the parent item also? | |
|
76 | // - potential issue: what if this function is called from the parent context? | |
|
77 | } | |
|
78 | } | |
|
79 | ||
|
80 | void QPieSeries::setPosition(PiePosition position) | |
|
81 | { | |
|
82 | m_position = position; | |
|
83 | if (m_piePresentation) { | |
|
84 | m_piePresentation->resize(); | |
|
85 | m_piePresentation->update(); | |
|
86 | // TODO: do we have to update the parent item also? | |
|
87 | // - potential issue: what if this function is called from the parent context? | |
|
88 | } | |
|
89 | } | |
|
90 | ||
|
91 | #include "moc_qpieseries.cpp" | |
|
92 | ||
|
93 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -17,12 +17,11 int main(int argc, char *argv[]) | |||
|
17 | 17 | Q_ASSERT(series); |
|
18 | 18 | |
|
19 | 19 | // Add test data to the series |
|
20 | QList<qreal> x; | |
|
21 | for (qreal i(0.0); i < 20; i += 0.5) { | |
|
22 | // Linear data with random component | |
|
23 | x.append(i + ((qreal)(rand() % 100)) / 100 ); | |
|
24 | } | |
|
25 | series->setData(x); | |
|
20 | series->add(QPieSlice(1, "test1", Qt::red)); | |
|
21 | series->add(QPieSlice(2, "test2", Qt::green)); | |
|
22 | series->add(QPieSlice(3, "test3", Qt::blue)); | |
|
23 | series->add(QPieSlice(4, "test4", Qt::darkRed)); | |
|
24 | series->add(QPieSlice(5, "test5", Qt::darkGreen)); | |
|
26 | 25 | |
|
27 | 26 | // Use the chart widget as the central widget |
|
28 | 27 | QMainWindow w; |
@@ -4,6 +4,8 | |||
|
4 | 4 | #include "barchartseries.h" |
|
5 | 5 | #include "stackedbarchartseries.h" |
|
6 | 6 | #include "percentbarchartseries.h" |
|
7 | #include "piechart/qpieseries.h" | |
|
8 | #include "piechart/piepresentation.h" | |
|
7 | 9 | |
|
8 | 10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 11 | |
@@ -82,6 +84,12 void ChartDataSet::addSeries(QChartSeries* series) | |||
|
82 | 84 | } |
|
83 | 85 | break; |
|
84 | 86 | |
|
87 | case QChartSeries::SeriesTypePie: { | |
|
88 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
|
89 | // TODO: domain stuff | |
|
90 | break; | |
|
91 | } | |
|
92 | ||
|
85 | 93 | default: { |
|
86 | 94 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; |
|
87 | 95 | return; |
@@ -7,6 +7,7 | |||
|
7 | 7 | #include "stackedbarchartseries.h" |
|
8 | 8 | #include "percentbarchartseries.h" |
|
9 | 9 | #include "qxychartseries.h" |
|
10 | #include "qpieseries.h" | |
|
10 | 11 | //items |
|
11 | 12 | #include "axisitem_p.h" |
|
12 | 13 | #include "bargroup.h" |
@@ -14,6 +15,7 | |||
|
14 | 15 | #include "xylinechartitem_p.h" |
|
15 | 16 | #include "percentbargroup.h" |
|
16 | 17 | #include "linechartanimationitem_p.h" |
|
18 | #include "piepresentation.h" | |
|
17 | 19 | |
|
18 | 20 | #include <QAbstractAnimation> |
|
19 | 21 | #include <QPropertyAnimation> |
@@ -162,19 +164,18 void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |||
|
162 | 164 | |
|
163 | 165 | break; |
|
164 | 166 | } |
|
165 | case QChartSeries::SeriesTypePie: { | |
|
166 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |
|
167 | pieSeries->d->setParentItem(this); | |
|
168 | m_chartItems << pieSeries->d; | |
|
169 | pieSeries->d->m_chartTheme = m_chartTheme; | |
|
170 | m_chartTheme->addObserver(pieSeries->d); | |
|
171 | break; | |
|
172 | } | |
|
173 | default: | |
|
174 | break; | |
|
175 | } | |
|
176 | 167 | */ |
|
177 | 168 | |
|
169 | case QChartSeries::SeriesTypePie: { | |
|
170 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |
|
171 | PiePresentation* pieChart = new PiePresentation(m_chart, pieSeries); | |
|
172 | pieSeries->m_piePresentation = pieChart; // TODO: remove this pointer passing use signals&slots | |
|
173 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pieChart, SLOT(handleGeometryChanged(const QRectF&))); | |
|
174 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pieChart, SLOT(handleDomainChanged(const Domain&))); | |
|
175 | m_chartItems.insert(series, pieChart); | |
|
176 | break; | |
|
177 | } | |
|
178 | ||
|
178 | 179 | default: { |
|
179 | 180 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
180 | 181 | break; |
@@ -1,16 +1,19 | |||
|
1 | 1 | #include "pieslice.h" |
|
2 | #include "piepresentation.h" | |
|
2 | 3 | #include <QPainter> |
|
3 | 4 | #include <QDebug> |
|
4 | 5 | |
|
5 | 6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | 7 | |
|
7 |
PieSlice::PieSlice( |
|
|
8 | : m_color(color), | |
|
8 | PieSlice::PieSlice(PiePresentation *piePresentation, int seriesIndex, qreal startAngle, qreal span) | |
|
9 | :QGraphicsItem(piePresentation), | |
|
10 | m_seriesIndex(seriesIndex), | |
|
9 | 11 | m_startAngle(startAngle), |
|
10 |
m_span(span) |
|
|
11 | m_rect(rect) | |
|
12 | m_span(span) | |
|
12 | 13 | { |
|
14 | Q_ASSERT(piePresentation); | |
|
13 | 15 | setAcceptHoverEvents(true); |
|
16 | setAcceptedMouseButtons(Qt::LeftButton); | |
|
14 | 17 | } |
|
15 | 18 | |
|
16 | 19 | PieSlice::~PieSlice() |
@@ -19,17 +22,18 PieSlice::~PieSlice() | |||
|
19 | 22 | |
|
20 | 23 | QRectF PieSlice::boundingRect() const |
|
21 | 24 | { |
|
22 | return m_rect; | |
|
25 | return shape().boundingRect(); | |
|
23 | 26 | } |
|
24 | 27 | |
|
25 | 28 | QPainterPath PieSlice::shape() const |
|
26 | 29 | { |
|
30 | QRectF rect = (static_cast<PiePresentation*>(parentItem()))->pieRect(); | |
|
27 | 31 | qreal angle = (-m_startAngle) + (90); |
|
28 | 32 | qreal span = -m_span; |
|
29 | 33 | |
|
30 | 34 | QPainterPath path; |
|
31 |
path.moveTo( |
|
|
32 |
path.arcTo( |
|
|
35 | path.moveTo(rect.center()); | |
|
36 | path.arcTo(rect, angle, span); | |
|
33 | 37 | |
|
34 | 38 | // TODO: draw the shape so that it might have a hole in the center |
|
35 | 39 | // - Sin & Cos will be needed to find inner/outer arc endpoints |
@@ -44,13 +48,17 QPainterPath PieSlice::shape() const | |||
|
44 | 48 | return path; |
|
45 | 49 | } |
|
46 | 50 | |
|
47 |
void PieSlice::paint(QPainter |
|
|
51 | void PieSlice::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) | |
|
48 | 52 | { |
|
49 | 53 | painter->setRenderHint(QPainter::Antialiasing); |
|
50 | 54 | // TODO: how to map theme settings to a pie slice? Now we |
|
51 | 55 | //painter->setPen(m_theme.linePen); |
|
52 | 56 | // TODO: |
|
53 | painter->setBrush(m_theme.linePen.color()); | |
|
57 | ||
|
58 | QPieSlice data = (static_cast<PiePresentation*>(parentItem()))->m_pieSeries->slice(m_seriesIndex); | |
|
59 | painter->setBrush(data.m_color); | |
|
60 | ||
|
61 | //painter->setBrush(m_theme.linePen.color()); | |
|
54 | 62 | |
|
55 | 63 | // From Qt docs: |
|
56 | 64 | // The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360). |
@@ -63,12 +71,20 void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option | |||
|
63 | 71 | //painter->drawPie(boundingRect(), angle, span); |
|
64 | 72 | |
|
65 | 73 | painter->drawPath(shape()); |
|
74 | ||
|
75 | // Draw the label | |
|
76 | // TODO: do this better | |
|
77 | painter->drawText(boundingRect().center(), data.m_label); | |
|
66 | 78 | } |
|
67 | 79 | |
|
68 | 80 | void PieSlice::hoverEnterEvent(QGraphicsSceneHoverEvent * event) |
|
69 | 81 | { |
|
70 | 82 | QGraphicsItem::hoverEnterEvent(event); |
|
71 |
qDebug() << "hover" << m_ |
|
|
83 | qDebug() << "hover" << m_seriesIndex << m_startAngle << m_span; | |
|
72 | 84 | } |
|
73 | 85 | |
|
86 | void PieSlice::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
|
87 | { | |
|
88 | QGraphicsItem::mousePressEvent(event); | |
|
89 | } | |
|
74 | 90 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -8,25 +8,26 | |||
|
8 | 8 | #include <QColor> |
|
9 | 9 | |
|
10 | 10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | class PiePresentation; | |
|
11 | 12 | |
|
12 | 13 | class PieSlice : public QGraphicsItem |
|
13 | 14 | { |
|
14 | 15 | public: |
|
15 | PieSlice(const QColor& color, qreal startAngle, qreal span, QRectF rect); | |
|
16 | PieSlice(PiePresentation *piePresentation, int seriesIndex, qreal startAngle, qreal span); | |
|
16 | 17 | ~PieSlice(); |
|
17 | 18 | |
|
18 | 19 | public: // from QGraphicsItem |
|
19 | 20 | QRectF boundingRect() const; |
|
20 | 21 | QPainterPath shape() const; |
|
21 | 22 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
22 |
void hoverEnterEvent(QGraphicsSceneHoverEvent * |
|
|
23 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); | |
|
24 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
|
23 | 25 | |
|
24 | public: | |
|
25 | QColor m_color; | |
|
26 | private: | |
|
27 | int m_seriesIndex; | |
|
26 | 28 | qreal m_startAngle; |
|
27 | 29 | qreal m_span; |
|
28 | QRectF m_rect; | |
|
29 | SeriesTheme m_theme; | |
|
30 | //SeriesTheme m_theme; | |
|
30 | 31 | }; |
|
31 | 32 | |
|
32 | 33 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -8,9 +8,24 | |||
|
8 | 8 | |
|
9 | 9 | class QGraphicsObject; |
|
10 | 10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 |
class |
|
|
11 | class PiePresentation; | |
|
12 | 12 | class PieSlice; |
|
13 | 13 | |
|
14 | class QPieSlice | |
|
15 | { | |
|
16 | public: | |
|
17 | QPieSlice() | |
|
18 | :m_value(0), m_label("<empty>"), m_color(Qt::white), m_isExploded(false) {} | |
|
19 | ||
|
20 | QPieSlice(qreal value, QString label, QColor color, bool exploded = false) | |
|
21 | :m_value(value), m_label(label), m_color(color), m_isExploded(exploded) {} | |
|
22 | public: | |
|
23 | qreal m_value; | |
|
24 | QString m_label; | |
|
25 | QColor m_color; | |
|
26 | bool m_isExploded; | |
|
27 | }; | |
|
28 | ||
|
14 | 29 | class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries |
|
15 | 30 | { |
|
16 | 31 | Q_OBJECT |
@@ -25,27 +40,45 public: | |||
|
25 | 40 | }; |
|
26 | 41 | |
|
27 | 42 | public: |
|
28 | // TODO: use a generic data class instead of x and y | |
|
29 | QPieSeries(QGraphicsObject *parent = 0); | |
|
43 | QPieSeries(QObject *parent = 0); | |
|
30 | 44 | ~QPieSeries(); |
|
31 | 45 | |
|
32 | 46 | public: // from QChartSeries |
|
33 | 47 | QChartSeriesType type() const { return QChartSeries::SeriesTypePie; } |
|
34 | bool setData(QList<qreal> data); | |
|
35 | 48 | |
|
36 | 49 | public: |
|
37 | void setSliceColor(int index, QColor color); | |
|
38 | QColor sliceColor(int index); | |
|
39 | int sliceCount(); | |
|
50 | void set(QList<QPieSlice> slices); | |
|
51 | void add(QList<QPieSlice> slices); | |
|
52 | void add(QPieSlice slice); | |
|
53 | ||
|
54 | int count() const { return m_slices.count(); } | |
|
55 | ||
|
56 | QList<QPieSlice> slices() const { return m_slices; } | |
|
57 | QPieSlice slice(int index) const; | |
|
58 | bool update(int index, QPieSlice slice); | |
|
59 | ||
|
60 | // TODO: convenience functions | |
|
61 | //void updateValue(int sliceIndex, qreal value); | |
|
62 | //void updateLabel(int sliceIndex, QString label); | |
|
63 | //void updateColor(int sliceIndex, QColor color); | |
|
64 | //void updateExploded(int slizeIndex, bool exploded); | |
|
65 | ||
|
40 | 66 | void setSizeFactor(qreal sizeFactor); |
|
41 | qreal sizeFactor(); | |
|
67 | qreal sizeFactor() const { return m_sizeFactor; } | |
|
68 | ||
|
42 | 69 | void setPosition(PiePosition position); |
|
70 | PiePosition position() const { return m_position; } | |
|
43 | 71 | |
|
44 | 72 | private: |
|
45 | Q_DECLARE_PRIVATE(QPieSeries) | |
|
46 | 73 | Q_DISABLE_COPY(QPieSeries) |
|
47 | friend class QChart; | |
|
48 | QPieSeriesPrivate *const d; | |
|
74 | // TODO: use PIML | |
|
75 | friend class ChartPresenter; | |
|
76 | friend class ChartDataSet; | |
|
77 | friend class PiePresentation; | |
|
78 | PiePresentation *m_piePresentation; | |
|
79 | QList<QPieSlice> m_slices; | |
|
80 | qreal m_sizeFactor; | |
|
81 | PiePosition m_position; | |
|
49 | 82 | }; |
|
50 | 83 | |
|
51 | 84 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -3,7 +3,6 | |||
|
3 | 3 | #include "qscatterseries.h" |
|
4 | 4 | #include "qscatterseries_p.h" |
|
5 | 5 | #include "qpieseries.h" |
|
6 | #include "qpieseries_p.h" | |
|
7 | 6 | #include "qchartaxis.h" |
|
8 | 7 | #include "charttheme_p.h" |
|
9 | 8 | #include "chartitem_p.h" |
@@ -121,7 +120,7 void QChart::setTitle(const QString& title,const QFont& font) | |||
|
121 | 120 | |
|
122 | 121 | int QChart::margin() const |
|
123 | 122 | { |
|
124 | m_presenter->margin(); | |
|
123 | return m_presenter->margin(); | |
|
125 | 124 | } |
|
126 | 125 | |
|
127 | 126 | void QChart::setMargin(int margin) |
@@ -23,12 +23,13 SOURCES += \ | |||
|
23 | 23 | xylinechart/qxychartseries.cpp \ |
|
24 | 24 | xylinechart/xylinechartitem.cpp \ |
|
25 | 25 | xylinechart/linechartanimationitem.cpp \ |
|
26 | piechart/qpieseries.cpp \ | |
|
27 | piechart/pieslice.cpp \ | |
|
28 | piechart/piepresentation.cpp \ | |
|
26 | 29 | plotdomain.cpp \ |
|
27 | 30 | qscatterseries.cpp \ |
|
28 | qpieseries.cpp \ | |
|
29 | 31 | qchart.cpp \ |
|
30 | 32 | axisitem.cpp \ |
|
31 | pieslice.cpp \ | |
|
32 | 33 | qchartview.cpp \ |
|
33 | 34 | qchartseries.cpp \ |
|
34 | 35 | qchartaxis.cpp \ |
@@ -40,16 +41,18 SOURCES += \ | |||
|
40 | 41 | chartpresenter.cpp \ |
|
41 | 42 | domain.cpp |
|
42 | 43 | |
|
44 | ||
|
45 | ||
|
43 | 46 | PRIVATE_HEADERS += \ |
|
44 | 47 | xylinechart/xylinechartitem_p.h \ |
|
45 | 48 | xylinechart/linechartanimationitem_p.h \ |
|
46 | 49 | barchart/barlabel_p.h \ |
|
47 | 50 | barchart/bar_p.h \ |
|
48 | 51 | barchart/separator_p.h \ |
|
52 | piechart/piepresentation.h \ | |
|
53 | piechart/pieslice.h \ | |
|
49 | 54 | plotdomain_p.h \ |
|
50 | 55 | qscatterseries_p.h \ |
|
51 | qpieseries_p.h \ | |
|
52 | pieslice.h \ | |
|
53 | 56 | axisitem_p.h \ |
|
54 | 57 | chartitem_p.h \ |
|
55 | 58 | charttheme_p.h \ |
@@ -60,7 +63,6 PRIVATE_HEADERS += \ | |||
|
60 | 63 | PUBLIC_HEADERS += \ |
|
61 | 64 | qchartseries.h \ |
|
62 | 65 | qscatterseries.h \ |
|
63 | qpieseries.h \ | |
|
64 | 66 | qchart.h \ |
|
65 | 67 | qchartglobal.h \ |
|
66 | 68 | xylinechart/qxychartseries.h \ |
@@ -72,6 +74,7 PUBLIC_HEADERS += \ | |||
|
72 | 74 | barchart/percentbargroup.h \ |
|
73 | 75 | barchart/barchartseriesbase.h \ |
|
74 | 76 | barchart/bargroupbase.h \ |
|
77 | piechart/qpieseries.h \ | |
|
75 | 78 | qchartview.h \ |
|
76 | 79 | qchartaxis.h |
|
77 | 80 | |
@@ -80,6 +83,7 HEADERS += $$PRIVATE_HEADERS | |||
|
80 | 83 | |
|
81 | 84 | INCLUDEPATH += xylinechart \ |
|
82 | 85 | barchart \ |
|
86 | piechart \ | |
|
83 | 87 | . |
|
84 | 88 | |
|
85 | 89 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now