@@ -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 | Q_ASSERT(series); |
|
17 | Q_ASSERT(series); | |
18 |
|
18 | |||
19 | // Add test data to the series |
|
19 | // Add test data to the series | |
20 | QList<qreal> x; |
|
20 | series->add(QPieSlice(1, "test1", Qt::red)); | |
21 | for (qreal i(0.0); i < 20; i += 0.5) { |
|
21 | series->add(QPieSlice(2, "test2", Qt::green)); | |
22 | // Linear data with random component |
|
22 | series->add(QPieSlice(3, "test3", Qt::blue)); | |
23 | x.append(i + ((qreal)(rand() % 100)) / 100 ); |
|
23 | series->add(QPieSlice(4, "test4", Qt::darkRed)); | |
24 | } |
|
24 | series->add(QPieSlice(5, "test5", Qt::darkGreen)); | |
25 | series->setData(x); |
|
|||
26 |
|
25 | |||
27 | // Use the chart widget as the central widget |
|
26 | // Use the chart widget as the central widget | |
28 | QMainWindow w; |
|
27 | QMainWindow w; |
@@ -4,6 +4,8 | |||||
4 | #include "barchartseries.h" |
|
4 | #include "barchartseries.h" | |
5 | #include "stackedbarchartseries.h" |
|
5 | #include "stackedbarchartseries.h" | |
6 | #include "percentbarchartseries.h" |
|
6 | #include "percentbarchartseries.h" | |
|
7 | #include "piechart/qpieseries.h" | |||
|
8 | #include "piechart/piepresentation.h" | |||
7 |
|
9 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
11 | |||
@@ -82,6 +84,12 void ChartDataSet::addSeries(QChartSeries* series) | |||||
82 | } |
|
84 | } | |
83 | break; |
|
85 | break; | |
84 |
|
86 | |||
|
87 | case QChartSeries::SeriesTypePie: { | |||
|
88 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |||
|
89 | // TODO: domain stuff | |||
|
90 | break; | |||
|
91 | } | |||
|
92 | ||||
85 | default: { |
|
93 | default: { | |
86 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; |
|
94 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; | |
87 | return; |
|
95 | return; |
@@ -7,6 +7,7 | |||||
7 | #include "stackedbarchartseries.h" |
|
7 | #include "stackedbarchartseries.h" | |
8 | #include "percentbarchartseries.h" |
|
8 | #include "percentbarchartseries.h" | |
9 | #include "qxychartseries.h" |
|
9 | #include "qxychartseries.h" | |
|
10 | #include "qpieseries.h" | |||
10 | //items |
|
11 | //items | |
11 | #include "axisitem_p.h" |
|
12 | #include "axisitem_p.h" | |
12 | #include "bargroup.h" |
|
13 | #include "bargroup.h" | |
@@ -14,6 +15,7 | |||||
14 | #include "xylinechartitem_p.h" |
|
15 | #include "xylinechartitem_p.h" | |
15 | #include "percentbargroup.h" |
|
16 | #include "percentbargroup.h" | |
16 | #include "linechartanimationitem_p.h" |
|
17 | #include "linechartanimationitem_p.h" | |
|
18 | #include "piepresentation.h" | |||
17 |
|
19 | |||
18 | #include <QAbstractAnimation> |
|
20 | #include <QAbstractAnimation> | |
19 | #include <QPropertyAnimation> |
|
21 | #include <QPropertyAnimation> | |
@@ -162,18 +164,17 void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |||||
162 |
|
164 | |||
163 | break; |
|
165 | break; | |
164 | } |
|
166 | } | |
|
167 | */ | |||
|
168 | ||||
165 |
|
|
169 | case QChartSeries::SeriesTypePie: { | |
166 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); |
|
170 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |
167 | pieSeries->d->setParentItem(this); |
|
171 | PiePresentation* pieChart = new PiePresentation(m_chart, pieSeries); | |
168 | m_chartItems << pieSeries->d; |
|
172 | pieSeries->m_piePresentation = pieChart; // TODO: remove this pointer passing use signals&slots | |
169 | pieSeries->d->m_chartTheme = m_chartTheme; |
|
173 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pieChart, SLOT(handleGeometryChanged(const QRectF&))); | |
170 | m_chartTheme->addObserver(pieSeries->d); |
|
174 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pieChart, SLOT(handleDomainChanged(const Domain&))); | |
|
175 | m_chartItems.insert(series, pieChart); | |||
171 | break; |
|
176 | break; | |
172 |
|
|
177 | } | |
173 | default: |
|
|||
174 | break; |
|
|||
175 | } |
|
|||
176 | */ |
|
|||
177 |
|
178 | |||
178 | default: { |
|
179 | default: { | |
179 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
180 | qDebug()<< "Series type" << series->type() << "not implemented."; |
@@ -1,16 +1,19 | |||||
1 | #include "pieslice.h" |
|
1 | #include "pieslice.h" | |
|
2 | #include "piepresentation.h" | |||
2 | #include <QPainter> |
|
3 | #include <QPainter> | |
3 | #include <QDebug> |
|
4 | #include <QDebug> | |
4 |
|
5 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
7 | |||
7 |
PieSlice::PieSlice( |
|
8 | PieSlice::PieSlice(PiePresentation *piePresentation, int seriesIndex, qreal startAngle, qreal span) | |
8 | : m_color(color), |
|
9 | :QGraphicsItem(piePresentation), | |
|
10 | m_seriesIndex(seriesIndex), | |||
9 | m_startAngle(startAngle), |
|
11 | m_startAngle(startAngle), | |
10 |
m_span(span) |
|
12 | m_span(span) | |
11 | m_rect(rect) |
|
|||
12 | { |
|
13 | { | |
|
14 | Q_ASSERT(piePresentation); | |||
13 | setAcceptHoverEvents(true); |
|
15 | setAcceptHoverEvents(true); | |
|
16 | setAcceptedMouseButtons(Qt::LeftButton); | |||
14 | } |
|
17 | } | |
15 |
|
18 | |||
16 | PieSlice::~PieSlice() |
|
19 | PieSlice::~PieSlice() | |
@@ -19,17 +22,18 PieSlice::~PieSlice() | |||||
19 |
|
22 | |||
20 | QRectF PieSlice::boundingRect() const |
|
23 | QRectF PieSlice::boundingRect() const | |
21 | { |
|
24 | { | |
22 | return m_rect; |
|
25 | return shape().boundingRect(); | |
23 | } |
|
26 | } | |
24 |
|
27 | |||
25 | QPainterPath PieSlice::shape() const |
|
28 | QPainterPath PieSlice::shape() const | |
26 | { |
|
29 | { | |
|
30 | QRectF rect = (static_cast<PiePresentation*>(parentItem()))->pieRect(); | |||
27 | qreal angle = (-m_startAngle) + (90); |
|
31 | qreal angle = (-m_startAngle) + (90); | |
28 | qreal span = -m_span; |
|
32 | qreal span = -m_span; | |
29 |
|
33 | |||
30 | QPainterPath path; |
|
34 | QPainterPath path; | |
31 |
path.moveTo( |
|
35 | path.moveTo(rect.center()); | |
32 |
path.arcTo( |
|
36 | path.arcTo(rect, angle, span); | |
33 |
|
37 | |||
34 | // TODO: draw the shape so that it might have a hole in the center |
|
38 | // TODO: draw the shape so that it might have a hole in the center | |
35 | // - Sin & Cos will be needed to find inner/outer arc endpoints |
|
39 | // - Sin & Cos will be needed to find inner/outer arc endpoints | |
@@ -50,7 +54,11 void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option | |||||
50 | // TODO: how to map theme settings to a pie slice? Now we |
|
54 | // TODO: how to map theme settings to a pie slice? Now we | |
51 | //painter->setPen(m_theme.linePen); |
|
55 | //painter->setPen(m_theme.linePen); | |
52 | // TODO: |
|
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 | // From Qt docs: |
|
63 | // From Qt docs: | |
56 | // The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360). |
|
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 | //painter->drawPie(boundingRect(), angle, span); |
|
71 | //painter->drawPie(boundingRect(), angle, span); | |
64 |
|
72 | |||
65 | painter->drawPath(shape()); |
|
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 | void PieSlice::hoverEnterEvent(QGraphicsSceneHoverEvent * event) |
|
80 | void PieSlice::hoverEnterEvent(QGraphicsSceneHoverEvent * event) | |
69 | { |
|
81 | { | |
70 | QGraphicsItem::hoverEnterEvent(event); |
|
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 | QTCOMMERCIALCHART_END_NAMESPACE |
|
90 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -8,11 +8,12 | |||||
8 | #include <QColor> |
|
8 | #include <QColor> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
11 | class PiePresentation; | |||
11 |
|
12 | |||
12 | class PieSlice : public QGraphicsItem |
|
13 | class PieSlice : public QGraphicsItem | |
13 | { |
|
14 | { | |
14 | public: |
|
15 | public: | |
15 | PieSlice(const QColor& color, qreal startAngle, qreal span, QRectF rect); |
|
16 | PieSlice(PiePresentation *piePresentation, int seriesIndex, qreal startAngle, qreal span); | |
16 | ~PieSlice(); |
|
17 | ~PieSlice(); | |
17 |
|
18 | |||
18 | public: // from QGraphicsItem |
|
19 | public: // from QGraphicsItem | |
@@ -20,13 +21,13 public: // from QGraphicsItem | |||||
20 | QPainterPath shape() const; |
|
21 | QPainterPath shape() const; | |
21 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
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: |
|
26 | private: | |
25 | QColor m_color; |
|
27 | int m_seriesIndex; | |
26 | qreal m_startAngle; |
|
28 | qreal m_startAngle; | |
27 | qreal m_span; |
|
29 | qreal m_span; | |
28 | QRectF m_rect; |
|
30 | //SeriesTheme m_theme; | |
29 | SeriesTheme m_theme; |
|
|||
30 | }; |
|
31 | }; | |
31 |
|
32 | |||
32 | QTCOMMERCIALCHART_END_NAMESPACE |
|
33 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -8,9 +8,24 | |||||
8 |
|
8 | |||
9 | class QGraphicsObject; |
|
9 | class QGraphicsObject; | |
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
class |
|
11 | class PiePresentation; | |
12 | class PieSlice; |
|
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 | class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries |
|
29 | class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries | |
15 | { |
|
30 | { | |
16 | Q_OBJECT |
|
31 | Q_OBJECT | |
@@ -25,27 +40,45 public: | |||||
25 | }; |
|
40 | }; | |
26 |
|
41 | |||
27 | public: |
|
42 | public: | |
28 | // TODO: use a generic data class instead of x and y |
|
43 | QPieSeries(QObject *parent = 0); | |
29 | QPieSeries(QGraphicsObject *parent = 0); |
|
|||
30 | ~QPieSeries(); |
|
44 | ~QPieSeries(); | |
31 |
|
45 | |||
32 | public: // from QChartSeries |
|
46 | public: // from QChartSeries | |
33 | QChartSeriesType type() const { return QChartSeries::SeriesTypePie; } |
|
47 | QChartSeriesType type() const { return QChartSeries::SeriesTypePie; } | |
34 | bool setData(QList<qreal> data); |
|
|||
35 |
|
48 | |||
36 | public: |
|
49 | public: | |
37 | void setSliceColor(int index, QColor color); |
|
50 | void set(QList<QPieSlice> slices); | |
38 | QColor sliceColor(int index); |
|
51 | void add(QList<QPieSlice> slices); | |
39 | int sliceCount(); |
|
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 | void setSizeFactor(qreal sizeFactor); |
|
66 | void setSizeFactor(qreal sizeFactor); | |
41 | qreal sizeFactor(); |
|
67 | qreal sizeFactor() const { return m_sizeFactor; } | |
|
68 | ||||
42 | void setPosition(PiePosition position); |
|
69 | void setPosition(PiePosition position); | |
|
70 | PiePosition position() const { return m_position; } | |||
43 |
|
71 | |||
44 | private: |
|
72 | private: | |
45 | Q_DECLARE_PRIVATE(QPieSeries) |
|
|||
46 | Q_DISABLE_COPY(QPieSeries) |
|
73 | Q_DISABLE_COPY(QPieSeries) | |
47 | friend class QChart; |
|
74 | // TODO: use PIML | |
48 | QPieSeriesPrivate *const d; |
|
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 | QTCOMMERCIALCHART_END_NAMESPACE |
|
84 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -3,7 +3,6 | |||||
3 | #include "qscatterseries.h" |
|
3 | #include "qscatterseries.h" | |
4 | #include "qscatterseries_p.h" |
|
4 | #include "qscatterseries_p.h" | |
5 | #include "qpieseries.h" |
|
5 | #include "qpieseries.h" | |
6 | #include "qpieseries_p.h" |
|
|||
7 | #include "qchartaxis.h" |
|
6 | #include "qchartaxis.h" | |
8 | #include "charttheme_p.h" |
|
7 | #include "charttheme_p.h" | |
9 | #include "chartitem_p.h" |
|
8 | #include "chartitem_p.h" | |
@@ -121,7 +120,7 void QChart::setTitle(const QString& title,const QFont& font) | |||||
121 |
|
120 | |||
122 | int QChart::margin() const |
|
121 | int QChart::margin() const | |
123 | { |
|
122 | { | |
124 | m_presenter->margin(); |
|
123 | return m_presenter->margin(); | |
125 | } |
|
124 | } | |
126 |
|
125 | |||
127 | void QChart::setMargin(int margin) |
|
126 | void QChart::setMargin(int margin) |
@@ -23,12 +23,13 SOURCES += \ | |||||
23 | xylinechart/qxychartseries.cpp \ |
|
23 | xylinechart/qxychartseries.cpp \ | |
24 | xylinechart/xylinechartitem.cpp \ |
|
24 | xylinechart/xylinechartitem.cpp \ | |
25 | xylinechart/linechartanimationitem.cpp \ |
|
25 | xylinechart/linechartanimationitem.cpp \ | |
|
26 | piechart/qpieseries.cpp \ | |||
|
27 | piechart/pieslice.cpp \ | |||
|
28 | piechart/piepresentation.cpp \ | |||
26 | plotdomain.cpp \ |
|
29 | plotdomain.cpp \ | |
27 | qscatterseries.cpp \ |
|
30 | qscatterseries.cpp \ | |
28 | qpieseries.cpp \ |
|
|||
29 | qchart.cpp \ |
|
31 | qchart.cpp \ | |
30 | axisitem.cpp \ |
|
32 | axisitem.cpp \ | |
31 | pieslice.cpp \ |
|
|||
32 | qchartview.cpp \ |
|
33 | qchartview.cpp \ | |
33 | qchartseries.cpp \ |
|
34 | qchartseries.cpp \ | |
34 | qchartaxis.cpp \ |
|
35 | qchartaxis.cpp \ | |
@@ -40,16 +41,18 SOURCES += \ | |||||
40 | chartpresenter.cpp \ |
|
41 | chartpresenter.cpp \ | |
41 | domain.cpp |
|
42 | domain.cpp | |
42 |
|
43 | |||
|
44 | ||||
|
45 | ||||
43 | PRIVATE_HEADERS += \ |
|
46 | PRIVATE_HEADERS += \ | |
44 | xylinechart/xylinechartitem_p.h \ |
|
47 | xylinechart/xylinechartitem_p.h \ | |
45 | xylinechart/linechartanimationitem_p.h \ |
|
48 | xylinechart/linechartanimationitem_p.h \ | |
46 | barchart/barlabel_p.h \ |
|
49 | barchart/barlabel_p.h \ | |
47 | barchart/bar_p.h \ |
|
50 | barchart/bar_p.h \ | |
48 | barchart/separator_p.h \ |
|
51 | barchart/separator_p.h \ | |
|
52 | piechart/piepresentation.h \ | |||
|
53 | piechart/pieslice.h \ | |||
49 | plotdomain_p.h \ |
|
54 | plotdomain_p.h \ | |
50 | qscatterseries_p.h \ |
|
55 | qscatterseries_p.h \ | |
51 | qpieseries_p.h \ |
|
|||
52 | pieslice.h \ |
|
|||
53 | axisitem_p.h \ |
|
56 | axisitem_p.h \ | |
54 | chartitem_p.h \ |
|
57 | chartitem_p.h \ | |
55 | charttheme_p.h \ |
|
58 | charttheme_p.h \ | |
@@ -60,7 +63,6 PRIVATE_HEADERS += \ | |||||
60 | PUBLIC_HEADERS += \ |
|
63 | PUBLIC_HEADERS += \ | |
61 | qchartseries.h \ |
|
64 | qchartseries.h \ | |
62 | qscatterseries.h \ |
|
65 | qscatterseries.h \ | |
63 | qpieseries.h \ |
|
|||
64 | qchart.h \ |
|
66 | qchart.h \ | |
65 | qchartglobal.h \ |
|
67 | qchartglobal.h \ | |
66 | xylinechart/qxychartseries.h \ |
|
68 | xylinechart/qxychartseries.h \ | |
@@ -72,6 +74,7 PUBLIC_HEADERS += \ | |||||
72 | barchart/percentbargroup.h \ |
|
74 | barchart/percentbargroup.h \ | |
73 | barchart/barchartseriesbase.h \ |
|
75 | barchart/barchartseriesbase.h \ | |
74 | barchart/bargroupbase.h \ |
|
76 | barchart/bargroupbase.h \ | |
|
77 | piechart/qpieseries.h \ | |||
75 | qchartview.h \ |
|
78 | qchartview.h \ | |
76 | qchartaxis.h |
|
79 | qchartaxis.h | |
77 |
|
80 | |||
@@ -80,6 +83,7 HEADERS += $$PRIVATE_HEADERS | |||||
80 |
|
83 | |||
81 | INCLUDEPATH += xylinechart \ |
|
84 | INCLUDEPATH += xylinechart \ | |
82 | barchart \ |
|
85 | barchart \ | |
|
86 | piechart \ | |||
83 | . |
|
87 | . | |
84 |
|
88 | |||
85 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
89 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now