@@ -1,121 +1,125 | |||||
1 | #include "areachartitem_p.h" |
|
1 | #include "areachartitem_p.h" | |
2 | #include "qareaseries.h" |
|
2 | #include "qareaseries.h" | |
3 | #include "qlineseries.h" |
|
3 | #include "qlineseries.h" | |
4 | #include "chartpresenter_p.h" |
|
4 | #include "chartpresenter_p.h" | |
5 | #include <QPainter> |
|
5 | #include <QPainter> | |
6 | #include <QGraphicsSceneMouseEvent> |
|
6 | #include <QGraphicsSceneMouseEvent> | |
7 |
|
7 | |||
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | //TODO: optimize : remove points which are not visible |
|
11 | //TODO: optimize : remove points which are not visible | |
12 |
|
12 | |||
13 |
AreaChartItem::AreaChartItem(QAreaSeries* areaSeries,ChartPresenter *presenter):Chart(presenter), |
|
13 | AreaChartItem::AreaChartItem(QAreaSeries* areaSeries,ChartPresenter *presenter):ChartItem(presenter), | |
14 | m_series(areaSeries), |
|
14 | m_series(areaSeries), | |
15 | m_upper(0), |
|
15 | m_upper(0), | |
16 | m_lower(0), |
|
16 | m_lower(0), | |
17 | m_pointsVisible(false) |
|
17 | m_pointsVisible(false) | |
18 | { |
|
18 | { | |
19 | setZValue(ChartPresenter::LineChartZValue); |
|
19 | setZValue(ChartPresenter::LineChartZValue); | |
20 | m_upper = new AreaBoundItem(this,m_series->upperSeries(),presenter); |
|
20 | m_upper = new AreaBoundItem(this,m_series->upperSeries(),presenter); | |
21 | if(m_series->lowerSeries()){ |
|
21 | if(m_series->lowerSeries()){ | |
22 | m_lower = new AreaBoundItem(this,m_series->lowerSeries(),presenter); |
|
22 | m_lower = new AreaBoundItem(this,m_series->lowerSeries(),presenter); | |
23 | } |
|
23 | } | |
24 |
|
24 | |||
25 | QObject::connect(areaSeries,SIGNAL(updated()),this,SLOT(handleUpdated())); |
|
25 | QObject::connect(areaSeries,SIGNAL(updated()),this,SLOT(handleUpdated())); | |
26 | QObject::connect(this,SIGNAL(clicked(const QPointF&)),areaSeries,SIGNAL(clicked(const QPointF&))); |
|
26 | QObject::connect(this,SIGNAL(clicked(const QPointF&)),areaSeries,SIGNAL(clicked(const QPointF&))); | |
27 |
|
27 | |||
28 | handleUpdated(); |
|
28 | handleUpdated(); | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | AreaChartItem::~AreaChartItem() |
|
31 | AreaChartItem::~AreaChartItem() | |
32 | { |
|
32 | { | |
33 | delete m_upper; |
|
33 | delete m_upper; | |
34 | delete m_lower; |
|
34 | delete m_lower; | |
35 | }; |
|
35 | }; | |
36 |
|
36 | |||
37 | QRectF AreaChartItem::boundingRect() const |
|
37 | QRectF AreaChartItem::boundingRect() const | |
38 | { |
|
38 | { | |
39 | return m_rect; |
|
39 | return m_rect; | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | QPainterPath AreaChartItem::shape() const |
|
42 | QPainterPath AreaChartItem::shape() const | |
43 | { |
|
43 | { | |
44 | return m_path; |
|
44 | return m_path; | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void AreaChartItem::updatePath() |
|
47 | void AreaChartItem::updatePath() | |
48 | { |
|
48 | { | |
49 | QPainterPath path; |
|
49 | QPainterPath path; | |
50 |
|
50 | |||
51 | path.connectPath(m_upper->shape()); |
|
51 | path.connectPath(m_upper->shape()); | |
52 | if(m_lower){ |
|
52 | if(m_lower){ | |
53 | path.connectPath(m_lower->shape().toReversed()); |
|
53 | path.connectPath(m_lower->shape().toReversed()); | |
54 | } |
|
54 | } | |
55 | else{ |
|
55 | else{ | |
56 | QPointF first = path.pointAtPercent(0); |
|
56 | QPointF first = path.pointAtPercent(0); | |
57 | QPointF last = path.pointAtPercent(1); |
|
57 | QPointF last = path.pointAtPercent(1); | |
58 | path.lineTo(last.x(),m_clipRect.bottom()); |
|
58 | path.lineTo(last.x(),m_clipRect.bottom()); | |
59 | path.lineTo(first.x(),m_clipRect.bottom()); |
|
59 | path.lineTo(first.x(),m_clipRect.bottom()); | |
60 | } |
|
60 | } | |
61 | path.closeSubpath(); |
|
61 | path.closeSubpath(); | |
62 | prepareGeometryChange(); |
|
62 | prepareGeometryChange(); | |
63 | m_path=path; |
|
63 | m_path=path; | |
64 | m_rect=path.boundingRect(); |
|
64 | m_rect=path.boundingRect(); | |
65 | update(); |
|
65 | update(); | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | void AreaChartItem::handleUpdated() |
|
68 | void AreaChartItem::handleUpdated() | |
69 | { |
|
69 | { | |
70 | m_pointsVisible = m_series->pointsVisible(); |
|
70 | m_pointsVisible = m_series->pointsVisible(); | |
71 | m_linePen = m_series->pen(); |
|
71 | m_linePen = m_series->pen(); | |
72 | m_brush = m_series->brush(); |
|
72 | m_brush = m_series->brush(); | |
73 | m_pointPen = m_series->pen(); |
|
73 | m_pointPen = m_series->pen(); | |
74 | m_pointPen.setWidthF(2*m_pointPen.width()); |
|
74 | m_pointPen.setWidthF(2*m_pointPen.width()); | |
75 |
|
75 | |||
76 | update(); |
|
76 | update(); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | void AreaChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
79 | void AreaChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
80 | { |
|
80 | { | |
81 | m_upper->handleDomainChanged(minX,maxX,minY,maxY); |
|
81 | m_upper->handleDomainChanged(minX,maxX,minY,maxY); | |
82 | if(m_lower) |
|
82 | if(m_lower) | |
83 | m_lower->handleDomainChanged(minX,maxX,minY,maxY); |
|
83 | m_lower->handleDomainChanged(minX,maxX,minY,maxY); | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | void AreaChartItem::handleGeometryChanged(const QRectF& rect) |
|
86 | void AreaChartItem::handleGeometryChanged(const QRectF& rect) | |
87 | { |
|
87 | { | |
88 | m_clipRect=rect.translated(-rect.topLeft()); |
|
88 | m_clipRect=rect.translated(-rect.topLeft()); | |
89 | setPos(rect.topLeft()); |
|
89 | setPos(rect.topLeft()); | |
90 | m_upper->handleGeometryChanged(rect); |
|
90 | m_upper->handleGeometryChanged(rect); | |
91 | if(m_lower) |
|
91 | if(m_lower) | |
92 | m_lower->handleGeometryChanged(rect); |
|
92 | m_lower->handleGeometryChanged(rect); | |
93 | } |
|
93 | } | |
94 | //painter |
|
94 | //painter | |
95 |
|
95 | |||
96 | void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
96 | void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
97 | { |
|
97 | { | |
98 | Q_UNUSED(widget) |
|
98 | Q_UNUSED(widget) | |
99 | Q_UNUSED(option) |
|
99 | Q_UNUSED(option) | |
100 |
|
100 | |||
101 | painter->save(); |
|
101 | painter->save(); | |
102 | painter->setPen(m_linePen); |
|
102 | QPen pen; | |
103 | painter->setBrush(m_brush); |
|
103 | pen.setCosmetic(false); | |
|
104 | pen.setWidth(4); | |||
|
105 | pen.setColor(qRgb(200,0,250)); | |||
|
106 | painter->setPen(pen); | |||
|
107 | //painter->setBrush(m_brush); | |||
104 | painter->setClipRect(m_clipRect); |
|
108 | painter->setClipRect(m_clipRect); | |
105 | painter->drawPath(m_path); |
|
109 | painter->drawPath(m_path); | |
106 | if(m_pointsVisible){ |
|
110 | if(m_pointsVisible){ | |
107 | painter->setPen(m_pointPen); |
|
111 | painter->setPen(m_pointPen); | |
108 | painter->drawPoints(m_upper->points()); |
|
112 | painter->drawPoints(m_upper->points()); | |
109 | if(m_lower) painter->drawPoints(m_lower->points()); |
|
113 | if(m_lower) painter->drawPoints(m_lower->points()); | |
110 | } |
|
114 | } | |
111 | painter->restore(); |
|
115 | painter->restore(); | |
112 | } |
|
116 | } | |
113 |
|
117 | |||
114 | void AreaChartItem::mousePressEvent( QGraphicsSceneMouseEvent * event ) |
|
118 | void AreaChartItem::mousePressEvent( QGraphicsSceneMouseEvent * event ) | |
115 | { |
|
119 | { | |
116 | emit clicked(m_upper->calculateDomainPoint(event->pos())); |
|
120 | emit clicked(m_upper->calculateDomainPoint(event->pos())); | |
117 | } |
|
121 | } | |
118 |
|
122 | |||
119 | #include "moc_areachartitem_p.cpp" |
|
123 | #include "moc_areachartitem_p.cpp" | |
120 |
|
124 | |||
121 | QTCOMMERCIALCHART_END_NAMESPACE |
|
125 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,75 +1,75 | |||||
1 | #ifndef AREACHARTITEM_H |
|
1 | #ifndef AREACHARTITEM_H | |
2 | #define AREACHARTITEM_H |
|
2 | #define AREACHARTITEM_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "linechartitem_p.h" |
|
5 | #include "linechartitem_p.h" | |
6 | #include <QPen> |
|
6 | #include <QPen> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class QAreaSeries; |
|
10 | class QAreaSeries; | |
11 | class AreaChartItem; |
|
11 | class AreaChartItem; | |
12 |
|
12 | |||
13 |
class AreaChartItem : public Chart |
|
13 | class AreaChartItem : public ChartItem | |
14 | { |
|
14 | { | |
15 | Q_OBJECT |
|
15 | Q_OBJECT | |
16 | public: |
|
16 | public: | |
17 | AreaChartItem(QAreaSeries* areaSeries, ChartPresenter *presenter); |
|
17 | AreaChartItem(QAreaSeries* areaSeries, ChartPresenter *presenter); | |
18 | ~ AreaChartItem(); |
|
18 | ~ AreaChartItem(); | |
19 |
|
19 | |||
20 | //from QGraphicsItem |
|
20 | //from QGraphicsItem | |
21 | QRectF boundingRect() const; |
|
21 | QRectF boundingRect() const; | |
22 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
22 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
23 | QPainterPath shape() const; |
|
23 | QPainterPath shape() const; | |
24 |
|
24 | |||
25 | LineChartItem* upperLineItem() const { return m_upper ;} |
|
25 | LineChartItem* upperLineItem() const { return m_upper ;} | |
26 | LineChartItem* lowerLineItem() const { return m_lower ;} |
|
26 | LineChartItem* lowerLineItem() const { return m_lower ;} | |
27 |
|
27 | |||
28 | void updatePath(); |
|
28 | void updatePath(); | |
29 |
|
29 | |||
30 | protected: |
|
30 | protected: | |
31 | void mousePressEvent( QGraphicsSceneMouseEvent * event ); |
|
31 | void mousePressEvent( QGraphicsSceneMouseEvent * event ); | |
32 |
|
32 | |||
33 | signals: |
|
33 | signals: | |
34 | void clicked(const QPointF& point); |
|
34 | void clicked(const QPointF& point); | |
35 |
|
35 | |||
36 | public slots: |
|
36 | public slots: | |
37 | void handleUpdated(); |
|
37 | void handleUpdated(); | |
38 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
38 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
39 | void handleGeometryChanged(const QRectF& size); |
|
39 | void handleGeometryChanged(const QRectF& size); | |
40 |
|
40 | |||
41 | private: |
|
41 | private: | |
42 | QAreaSeries* m_series; |
|
42 | QAreaSeries* m_series; | |
43 | LineChartItem* m_upper; |
|
43 | LineChartItem* m_upper; | |
44 | LineChartItem* m_lower; |
|
44 | LineChartItem* m_lower; | |
45 | QPainterPath m_path; |
|
45 | QPainterPath m_path; | |
46 | QRectF m_rect; |
|
46 | QRectF m_rect; | |
47 | QRectF m_clipRect; |
|
47 | QRectF m_clipRect; | |
48 | QPen m_linePen; |
|
48 | QPen m_linePen; | |
49 | QPen m_pointPen; |
|
49 | QPen m_pointPen; | |
50 | QBrush m_brush; |
|
50 | QBrush m_brush; | |
51 | bool m_pointsVisible; |
|
51 | bool m_pointsVisible; | |
52 |
|
52 | |||
53 | }; |
|
53 | }; | |
54 |
|
54 | |||
55 | class AreaBoundItem : public LineChartItem |
|
55 | class AreaBoundItem : public LineChartItem | |
56 | { |
|
56 | { | |
57 | public: |
|
57 | public: | |
58 | AreaBoundItem(AreaChartItem* item,QLineSeries* lineSeries,ChartPresenter *presenter):LineChartItem(lineSeries,presenter), |
|
58 | AreaBoundItem(AreaChartItem* item,QLineSeries* lineSeries,ChartPresenter *presenter):LineChartItem(lineSeries,presenter), | |
59 | m_item(item){}; |
|
59 | m_item(item){}; | |
60 |
|
60 | |||
61 | ~AreaBoundItem(){}; |
|
61 | ~AreaBoundItem(){}; | |
62 |
|
62 | |||
63 | void setLayout(QVector<QPointF>& points){ |
|
63 | void setLayout(QVector<QPointF>& points){ | |
64 | LineChartItem::setLayout(points); |
|
64 | LineChartItem::setLayout(points); | |
65 | m_item->updatePath(); |
|
65 | m_item->updatePath(); | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | private: |
|
68 | private: | |
69 | AreaChartItem* m_item; |
|
69 | AreaChartItem* m_item; | |
70 |
|
70 | |||
71 | }; |
|
71 | }; | |
72 |
|
72 | |||
73 | QTCOMMERCIALCHART_END_NAMESPACE |
|
73 | QTCOMMERCIALCHART_END_NAMESPACE | |
74 |
|
74 | |||
75 | #endif |
|
75 | #endif |
@@ -1,641 +1,640 | |||||
1 | #include "qpieseries.h" |
|
1 | #include "qpieseries.h" | |
2 | #include "qpiesliceprivate_p.h" |
|
2 | #include "qpiesliceprivate_p.h" | |
3 | #include "qpieseriesprivate_p.h" |
|
3 | #include "qpieseriesprivate_p.h" | |
4 | #include <QDebug> |
|
4 | #include <QDebug> | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) |
|
8 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) | |
9 | :QObject(parent), |
|
9 | :QObject(parent), | |
10 | q_ptr(parent), |
|
10 | q_ptr(parent), | |
11 | m_pieRelativeHorPos(0.5), |
|
11 | m_pieRelativeHorPos(0.5), | |
12 | m_pieRelativeVerPos(0.5), |
|
12 | m_pieRelativeVerPos(0.5), | |
13 | m_pieRelativeSize(0.7), |
|
13 | m_pieRelativeSize(0.7), | |
14 | m_pieStartAngle(0), |
|
14 | m_pieStartAngle(0), | |
15 | m_pieEndAngle(360), |
|
15 | m_pieEndAngle(360), | |
16 | m_total(0) |
|
16 | m_total(0) | |
17 | { |
|
17 | { | |
18 |
|
18 | |||
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
21 | QPieSeriesPrivate::~QPieSeriesPrivate() | |
22 | { |
|
22 | { | |
23 |
|
23 | |||
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | void QPieSeriesPrivate::updateDerivativeData() |
|
26 | void QPieSeriesPrivate::updateDerivativeData() | |
27 | { |
|
27 | { | |
28 | m_total = 0; |
|
28 | m_total = 0; | |
29 |
|
29 | |||
30 | // nothing to do? |
|
30 | // nothing to do? | |
31 | if (m_slices.count() == 0) |
|
31 | if (m_slices.count() == 0) | |
32 | return; |
|
32 | return; | |
33 |
|
33 | |||
34 | // calculate total |
|
34 | // calculate total | |
35 | foreach (QPieSlice* s, m_slices) |
|
35 | foreach (QPieSlice* s, m_slices) | |
36 | m_total += s->value(); |
|
36 | m_total += s->value(); | |
37 |
|
37 | |||
38 | // nothing to show.. |
|
38 | // nothing to show.. | |
39 | if (m_total == 0) |
|
39 | if (m_total == 0) | |
40 | return; |
|
40 | return; | |
41 |
|
41 | |||
42 | // update slice attributes |
|
42 | // update slice attributes | |
43 | qreal sliceAngle = m_pieStartAngle; |
|
43 | qreal sliceAngle = m_pieStartAngle; | |
44 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
44 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | |
45 | QVector<QPieSlice*> changed; |
|
45 | QVector<QPieSlice*> changed; | |
46 | foreach (QPieSlice* s, m_slices) { |
|
46 | foreach (QPieSlice* s, m_slices) { | |
47 |
|
47 | |||
48 | bool isChanged = false; |
|
48 | bool isChanged = false; | |
49 |
|
49 | |||
50 | qreal percentage = s->value() / m_total; |
|
50 | qreal percentage = s->value() / m_total; | |
51 | if (s->data_ptr()->m_data.m_percentage != percentage) { |
|
51 | if (s->data_ptr()->m_data.m_percentage != percentage) { | |
52 | s->data_ptr()->m_data.m_percentage = percentage; |
|
52 | s->data_ptr()->m_data.m_percentage = percentage; | |
53 | isChanged = true; |
|
53 | isChanged = true; | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | qreal sliceSpan = pieSpan * percentage; |
|
56 | qreal sliceSpan = pieSpan * percentage; | |
57 | if (s->data_ptr()->m_data.m_angleSpan != sliceSpan) { |
|
57 | if (s->data_ptr()->m_data.m_angleSpan != sliceSpan) { | |
58 | s->data_ptr()->m_data.m_angleSpan = sliceSpan; |
|
58 | s->data_ptr()->m_data.m_angleSpan = sliceSpan; | |
59 | isChanged = true; |
|
59 | isChanged = true; | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | if (s->data_ptr()->m_data.m_startAngle != sliceAngle) { |
|
62 | if (s->data_ptr()->m_data.m_startAngle != sliceAngle) { | |
63 | s->data_ptr()->m_data.m_startAngle = sliceAngle; |
|
63 | s->data_ptr()->m_data.m_startAngle = sliceAngle; | |
64 | isChanged = true; |
|
64 | isChanged = true; | |
65 | } |
|
65 | } | |
66 | sliceAngle += sliceSpan; |
|
66 | sliceAngle += sliceSpan; | |
67 |
|
67 | |||
68 | if (isChanged) |
|
68 | if (isChanged) | |
69 | changed << s; |
|
69 | changed << s; | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | // emit signals |
|
72 | // emit signals | |
73 | foreach (QPieSlice* s, changed) |
|
73 | foreach (QPieSlice* s, changed) | |
74 | emit s->data_ptr()->changed(); |
|
74 | emit s->data_ptr()->changed(); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | void QPieSeriesPrivate::sliceChanged() |
|
77 | void QPieSeriesPrivate::sliceChanged() | |
78 | { |
|
78 | { | |
79 |
Q |
|
79 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | |
80 | Q_ASSERT(m_slices.contains(slice)); |
|
|||
81 | updateDerivativeData(); |
|
80 | updateDerivativeData(); | |
82 | } |
|
81 | } | |
83 |
|
82 | |||
84 | void QPieSeriesPrivate::sliceClicked() |
|
83 | void QPieSeriesPrivate::sliceClicked() | |
85 | { |
|
84 | { | |
86 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
85 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
87 | Q_ASSERT(m_slices.contains(slice)); |
|
86 | Q_ASSERT(m_slices.contains(slice)); | |
88 | Q_Q(QPieSeries); |
|
87 | Q_Q(QPieSeries); | |
89 | emit q->clicked(slice); |
|
88 | emit q->clicked(slice); | |
90 | } |
|
89 | } | |
91 |
|
90 | |||
92 | void QPieSeriesPrivate::sliceHoverEnter() |
|
91 | void QPieSeriesPrivate::sliceHoverEnter() | |
93 | { |
|
92 | { | |
94 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
93 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
95 | Q_ASSERT(m_slices.contains(slice)); |
|
94 | Q_ASSERT(m_slices.contains(slice)); | |
96 | Q_Q(QPieSeries); |
|
95 | Q_Q(QPieSeries); | |
97 | emit q->hoverEnter(slice); |
|
96 | emit q->hoverEnter(slice); | |
98 | } |
|
97 | } | |
99 |
|
98 | |||
100 | void QPieSeriesPrivate::sliceHoverLeave() |
|
99 | void QPieSeriesPrivate::sliceHoverLeave() | |
101 | { |
|
100 | { | |
102 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
101 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
103 | Q_ASSERT(m_slices.contains(slice)); |
|
102 | Q_ASSERT(m_slices.contains(slice)); | |
104 | Q_Q(QPieSeries); |
|
103 | Q_Q(QPieSeries); | |
105 | emit q->hoverLeave(slice); |
|
104 | emit q->hoverLeave(slice); | |
106 | } |
|
105 | } | |
107 |
|
106 | |||
108 | void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
107 | void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
109 | { |
|
108 | { | |
110 | Q_UNUSED(bottomRight) |
|
109 | Q_UNUSED(bottomRight) | |
111 | Q_Q(QPieSeries); |
|
110 | Q_Q(QPieSeries); | |
112 |
|
111 | |||
113 | if (m_mapOrientation == Qt::Vertical) |
|
112 | if (m_mapOrientation == Qt::Vertical) | |
114 | { |
|
113 | { | |
115 | // slices().at(topLeft.row())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble()); |
|
114 | // slices().at(topLeft.row())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble()); | |
116 | if (topLeft.column() == m_mapValues) |
|
115 | if (topLeft.column() == m_mapValues) | |
117 | if (m_mapValues == m_mapLabels) |
|
116 | if (m_mapValues == m_mapLabels) | |
118 | { |
|
117 | { | |
119 | m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
118 | m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
120 | m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
119 | m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
121 | } |
|
120 | } | |
122 | else |
|
121 | else | |
123 | { |
|
122 | { | |
124 | m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
123 | m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
125 | } |
|
124 | } | |
126 | else if (topLeft.column() == m_mapLabels) |
|
125 | else if (topLeft.column() == m_mapLabels) | |
127 | m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
126 | m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
128 | } |
|
127 | } | |
129 | else |
|
128 | else | |
130 | { |
|
129 | { | |
131 | // slices().at(topLeft.column())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble()); |
|
130 | // slices().at(topLeft.column())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble()); | |
132 | if (topLeft.row() == m_mapValues) |
|
131 | if (topLeft.row() == m_mapValues) | |
133 | if (m_mapValues == m_mapLabels) |
|
132 | if (m_mapValues == m_mapLabels) | |
134 | { |
|
133 | { | |
135 | m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
134 | m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
136 | m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
135 | m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
137 | } |
|
136 | } | |
138 | else |
|
137 | else | |
139 | { |
|
138 | { | |
140 | m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
139 | m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
141 | } |
|
140 | } | |
142 | else if (topLeft.row() == m_mapLabels) |
|
141 | else if (topLeft.row() == m_mapLabels) | |
143 | m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
142 | m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
144 | } |
|
143 | } | |
145 | } |
|
144 | } | |
146 |
|
145 | |||
147 | void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) |
|
146 | void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) | |
148 | { |
|
147 | { | |
149 | Q_UNUSED(parent) |
|
148 | Q_UNUSED(parent) | |
150 | Q_UNUSED(end) |
|
149 | Q_UNUSED(end) | |
151 | Q_Q(QPieSeries); |
|
150 | Q_Q(QPieSeries); | |
152 |
|
151 | |||
153 | QPieSlice* newSlice = new QPieSlice; |
|
152 | QPieSlice* newSlice = new QPieSlice; | |
154 | newSlice->setLabelVisible(true); |
|
153 | newSlice->setLabelVisible(true); | |
155 | if (m_mapOrientation == Qt::Vertical) |
|
154 | if (m_mapOrientation == Qt::Vertical) | |
156 | { |
|
155 | { | |
157 | newSlice->setValue(q->m_model->data(q->m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble()); |
|
156 | newSlice->setValue(q->m_model->data(q->m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble()); | |
158 | newSlice->setLabel(q->m_model->data(q->m_model->index(start, m_mapLabels), Qt::DisplayRole).toString()); |
|
157 | newSlice->setLabel(q->m_model->data(q->m_model->index(start, m_mapLabels), Qt::DisplayRole).toString()); | |
159 | } |
|
158 | } | |
160 | else |
|
159 | else | |
161 | { |
|
160 | { | |
162 | newSlice->setValue(q->m_model->data(q->m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble()); |
|
161 | newSlice->setValue(q->m_model->data(q->m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble()); | |
163 | newSlice->setLabel(q->m_model->data(q->m_model->index(m_mapLabels, start), Qt::DisplayRole).toString()); |
|
162 | newSlice->setLabel(q->m_model->data(q->m_model->index(m_mapLabels, start), Qt::DisplayRole).toString()); | |
164 | } |
|
163 | } | |
165 |
|
164 | |||
166 | q->insert(start, newSlice); |
|
165 | q->insert(start, newSlice); | |
167 | } |
|
166 | } | |
168 |
|
167 | |||
169 | void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) |
|
168 | void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |
170 | { |
|
169 | { | |
171 | Q_UNUSED(parent) |
|
170 | Q_UNUSED(parent) | |
172 | Q_UNUSED(end) |
|
171 | Q_UNUSED(end) | |
173 | Q_Q(QPieSeries); |
|
172 | Q_Q(QPieSeries); | |
174 | q->remove(m_slices.at(start)); |
|
173 | q->remove(m_slices.at(start)); | |
175 | } |
|
174 | } | |
176 |
|
175 | |||
177 |
|
176 | |||
178 |
|
177 | |||
179 | /*! |
|
178 | /*! | |
180 | \class QPieSeries |
|
179 | \class QPieSeries | |
181 | \brief Pie series API for QtCommercial Charts |
|
180 | \brief Pie series API for QtCommercial Charts | |
182 |
|
181 | |||
183 | The pie series defines a pie chart which consists of pie slices which are QPieSlice objects. |
|
182 | The pie series defines a pie chart which consists of pie slices which are QPieSlice objects. | |
184 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
183 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | |
185 | The actual slice size is determined by that relative value. |
|
184 | The actual slice size is determined by that relative value. | |
186 |
|
185 | |||
187 | By default the pie is defined as a full pie but it can be a partial pie. |
|
186 | By default the pie is defined as a full pie but it can be a partial pie. | |
188 | This can be done by setting a starting angle and angle span to the series. |
|
187 | This can be done by setting a starting angle and angle span to the series. | |
189 | */ |
|
188 | */ | |
190 |
|
189 | |||
191 | /*! |
|
190 | /*! | |
192 | Constructs a series object which is a child of \a parent. |
|
191 | Constructs a series object which is a child of \a parent. | |
193 | */ |
|
192 | */ | |
194 | QPieSeries::QPieSeries(QObject *parent) : |
|
193 | QPieSeries::QPieSeries(QObject *parent) : | |
195 | QSeries(parent), |
|
194 | QSeries(parent), | |
196 | d_ptr(new QPieSeriesPrivate(this)) |
|
195 | d_ptr(new QPieSeriesPrivate(this)) | |
197 | { |
|
196 | { | |
198 |
|
197 | |||
199 | } |
|
198 | } | |
200 |
|
199 | |||
201 | /*! |
|
200 | /*! | |
202 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. |
|
201 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. | |
203 | */ |
|
202 | */ | |
204 | QPieSeries::~QPieSeries() |
|
203 | QPieSeries::~QPieSeries() | |
205 | { |
|
204 | { | |
206 | // NOTE: d_prt destroyed by QObject |
|
205 | // NOTE: d_prt destroyed by QObject | |
207 | } |
|
206 | } | |
208 |
|
207 | |||
209 | /*! |
|
208 | /*! | |
210 | Returns QChartSeries::SeriesTypePie. |
|
209 | Returns QChartSeries::SeriesTypePie. | |
211 | */ |
|
210 | */ | |
212 | QSeries::QSeriesType QPieSeries::type() const |
|
211 | QSeries::QSeriesType QPieSeries::type() const | |
213 | { |
|
212 | { | |
214 | return QSeries::SeriesTypePie; |
|
213 | return QSeries::SeriesTypePie; | |
215 | } |
|
214 | } | |
216 |
|
215 | |||
217 | /*! |
|
216 | /*! | |
218 | Sets an array of \a slices to the series replacing the existing slices. |
|
217 | Sets an array of \a slices to the series replacing the existing slices. | |
219 | Slice ownership is passed to the series. |
|
218 | Slice ownership is passed to the series. | |
220 | */ |
|
219 | */ | |
221 | void QPieSeries::replace(QList<QPieSlice*> slices) |
|
220 | void QPieSeries::replace(QList<QPieSlice*> slices) | |
222 | { |
|
221 | { | |
223 | clear(); |
|
222 | clear(); | |
224 | add(slices); |
|
223 | add(slices); | |
225 | } |
|
224 | } | |
226 |
|
225 | |||
227 | /*! |
|
226 | /*! | |
228 | Adds an array of \a slices to the series. |
|
227 | Adds an array of \a slices to the series. | |
229 | Slice ownership is passed to the series. |
|
228 | Slice ownership is passed to the series. | |
230 | */ |
|
229 | */ | |
231 | void QPieSeries::add(QList<QPieSlice*> slices) |
|
230 | void QPieSeries::add(QList<QPieSlice*> slices) | |
232 | { |
|
231 | { | |
233 | Q_D(QPieSeries); |
|
232 | Q_D(QPieSeries); | |
234 |
|
233 | |||
235 | foreach (QPieSlice* s, slices) { |
|
234 | foreach (QPieSlice* s, slices) { | |
236 | s->setParent(this); |
|
235 | s->setParent(this); | |
237 | d->m_slices << s; |
|
236 | d->m_slices << s; | |
238 | } |
|
237 | } | |
239 |
|
238 | |||
240 | d->updateDerivativeData(); |
|
239 | d->updateDerivativeData(); | |
241 |
|
240 | |||
242 | foreach (QPieSlice* s, slices) { |
|
241 | foreach (QPieSlice* s, slices) { | |
243 | connect(s, SIGNAL(changed()), d, SLOT(sliceChanged())); |
|
242 | connect(s, SIGNAL(changed()), d, SLOT(sliceChanged())); | |
244 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
243 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
245 | connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); |
|
244 | connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); | |
246 | connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); |
|
245 | connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); | |
247 | } |
|
246 | } | |
248 |
|
247 | |||
249 | emit added(slices); |
|
248 | emit added(slices); | |
250 | } |
|
249 | } | |
251 |
|
250 | |||
252 | /*! |
|
251 | /*! | |
253 | Adds a single \a slice to the series. |
|
252 | Adds a single \a slice to the series. | |
254 | Slice ownership is passed to the series. |
|
253 | Slice ownership is passed to the series. | |
255 | */ |
|
254 | */ | |
256 | void QPieSeries::add(QPieSlice* slice) |
|
255 | void QPieSeries::add(QPieSlice* slice) | |
257 | { |
|
256 | { | |
258 | add(QList<QPieSlice*>() << slice); |
|
257 | add(QList<QPieSlice*>() << slice); | |
259 | } |
|
258 | } | |
260 |
|
259 | |||
261 | /*! |
|
260 | /*! | |
262 | Adds a single \a slice to the series and returns a reference to the series. |
|
261 | Adds a single \a slice to the series and returns a reference to the series. | |
263 | Slice ownership is passed to the series. |
|
262 | Slice ownership is passed to the series. | |
264 | */ |
|
263 | */ | |
265 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) |
|
264 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) | |
266 | { |
|
265 | { | |
267 | add(slice); |
|
266 | add(slice); | |
268 | return *this; |
|
267 | return *this; | |
269 | } |
|
268 | } | |
270 |
|
269 | |||
271 |
|
270 | |||
272 | /*! |
|
271 | /*! | |
273 | Adds a single slice to the series with give \a value and \a name. |
|
272 | Adds a single slice to the series with give \a value and \a name. | |
274 | Slice ownership is passed to the series. |
|
273 | Slice ownership is passed to the series. | |
275 | */ |
|
274 | */ | |
276 | QPieSlice* QPieSeries::add(qreal value, QString name) |
|
275 | QPieSlice* QPieSeries::add(qreal value, QString name) | |
277 | { |
|
276 | { | |
278 | QPieSlice* slice = new QPieSlice(value, name); |
|
277 | QPieSlice* slice = new QPieSlice(value, name); | |
279 | add(slice); |
|
278 | add(slice); | |
280 | return slice; |
|
279 | return slice; | |
281 | } |
|
280 | } | |
282 |
|
281 | |||
283 | void QPieSeries::insert(int i, QPieSlice* slice) |
|
282 | void QPieSeries::insert(int i, QPieSlice* slice) | |
284 | { |
|
283 | { | |
285 | Q_D(QPieSeries); |
|
284 | Q_D(QPieSeries); | |
286 | Q_ASSERT(i <= d->m_slices.count()); |
|
285 | Q_ASSERT(i <= d->m_slices.count()); | |
287 | slice->setParent(this); |
|
286 | slice->setParent(this); | |
288 | d->m_slices.insert(i, slice); |
|
287 | d->m_slices.insert(i, slice); | |
289 |
|
288 | |||
290 | d->updateDerivativeData(); |
|
289 | d->updateDerivativeData(); | |
291 |
|
290 | |||
292 | connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged())); |
|
291 | connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged())); | |
293 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
292 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
294 | connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); |
|
293 | connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); | |
295 | connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); |
|
294 | connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); | |
296 |
|
295 | |||
297 | emit added(QList<QPieSlice*>() << slice); |
|
296 | emit added(QList<QPieSlice*>() << slice); | |
298 | } |
|
297 | } | |
299 |
|
298 | |||
300 | /*! |
|
299 | /*! | |
301 | Removes a single \a slice from the series and deletes the slice. |
|
300 | Removes a single \a slice from the series and deletes the slice. | |
302 |
|
301 | |||
303 | Do not reference this pointer after this call. |
|
302 | Do not reference this pointer after this call. | |
304 | */ |
|
303 | */ | |
305 | void QPieSeries::remove(QPieSlice* slice) |
|
304 | void QPieSeries::remove(QPieSlice* slice) | |
306 | { |
|
305 | { | |
307 | Q_D(QPieSeries); |
|
306 | Q_D(QPieSeries); | |
308 | if (!d->m_slices.removeOne(slice)) { |
|
307 | if (!d->m_slices.removeOne(slice)) { | |
309 | Q_ASSERT(0); // TODO: how should this be reported? |
|
308 | Q_ASSERT(0); // TODO: how should this be reported? | |
310 | return; |
|
309 | return; | |
311 | } |
|
310 | } | |
312 |
|
311 | |||
313 | d->updateDerivativeData(); |
|
312 | d->updateDerivativeData(); | |
314 |
|
313 | |||
315 | emit removed(QList<QPieSlice*>() << slice); |
|
314 | emit removed(QList<QPieSlice*>() << slice); | |
316 |
|
315 | |||
317 | delete slice; |
|
316 | delete slice; | |
318 | slice = NULL; |
|
317 | slice = NULL; | |
319 | } |
|
318 | } | |
320 |
|
319 | |||
321 | /*! |
|
320 | /*! | |
322 | Clears all slices from the series. |
|
321 | Clears all slices from the series. | |
323 | */ |
|
322 | */ | |
324 | void QPieSeries::clear() |
|
323 | void QPieSeries::clear() | |
325 | { |
|
324 | { | |
326 | Q_D(QPieSeries); |
|
325 | Q_D(QPieSeries); | |
327 | if (d->m_slices.count() == 0) |
|
326 | if (d->m_slices.count() == 0) | |
328 | return; |
|
327 | return; | |
329 |
|
328 | |||
330 | QList<QPieSlice*> slices = d->m_slices; |
|
329 | QList<QPieSlice*> slices = d->m_slices; | |
331 | foreach (QPieSlice* s, d->m_slices) { |
|
330 | foreach (QPieSlice* s, d->m_slices) { | |
332 | d->m_slices.removeOne(s); |
|
331 | d->m_slices.removeOne(s); | |
333 | delete s; |
|
332 | delete s; | |
334 | } |
|
333 | } | |
335 |
|
334 | |||
336 | d->updateDerivativeData(); |
|
335 | d->updateDerivativeData(); | |
337 |
|
336 | |||
338 | emit removed(slices); |
|
337 | emit removed(slices); | |
339 | } |
|
338 | } | |
340 |
|
339 | |||
341 | /*! |
|
340 | /*! | |
342 | Counts the number of the slices in this series. |
|
341 | Counts the number of the slices in this series. | |
343 | */ |
|
342 | */ | |
344 | int QPieSeries::count() const |
|
343 | int QPieSeries::count() const | |
345 | { |
|
344 | { | |
346 | Q_D(const QPieSeries); |
|
345 | Q_D(const QPieSeries); | |
347 | return d->m_slices.count(); |
|
346 | return d->m_slices.count(); | |
348 | } |
|
347 | } | |
349 |
|
348 | |||
350 | /*! |
|
349 | /*! | |
351 | Returns true is the series is empty. |
|
350 | Returns true is the series is empty. | |
352 | */ |
|
351 | */ | |
353 | bool QPieSeries::isEmpty() const |
|
352 | bool QPieSeries::isEmpty() const | |
354 | { |
|
353 | { | |
355 | Q_D(const QPieSeries); |
|
354 | Q_D(const QPieSeries); | |
356 | return d->m_slices.isEmpty(); |
|
355 | return d->m_slices.isEmpty(); | |
357 | } |
|
356 | } | |
358 |
|
357 | |||
359 | /*! |
|
358 | /*! | |
360 | Returns a list of slices that belong to this series. |
|
359 | Returns a list of slices that belong to this series. | |
361 | */ |
|
360 | */ | |
362 | QList<QPieSlice*> QPieSeries::slices() const |
|
361 | QList<QPieSlice*> QPieSeries::slices() const | |
363 | { |
|
362 | { | |
364 | Q_D(const QPieSeries); |
|
363 | Q_D(const QPieSeries); | |
365 | return d->m_slices; |
|
364 | return d->m_slices; | |
366 | } |
|
365 | } | |
367 |
|
366 | |||
368 | /*! |
|
367 | /*! | |
369 | Sets the center position of the pie by \a relativeHorizontalPosition and \a relativeVerticalPosition. |
|
368 | Sets the center position of the pie by \a relativeHorizontalPosition and \a relativeVerticalPosition. | |
370 |
|
369 | |||
371 | The factors are relative to the chart rectangle where: |
|
370 | The factors are relative to the chart rectangle where: | |
372 |
|
371 | |||
373 | \a relativeHorizontalPosition 0.0 means the absolute left. |
|
372 | \a relativeHorizontalPosition 0.0 means the absolute left. | |
374 | \a relativeHorizontalPosition 1.0 means the absolute right. |
|
373 | \a relativeHorizontalPosition 1.0 means the absolute right. | |
375 | \a relativeVerticalPosition 0.0 means the absolute top. |
|
374 | \a relativeVerticalPosition 0.0 means the absolute top. | |
376 | \a relativeVerticalPosition 1.0 means the absolute bottom. |
|
375 | \a relativeVerticalPosition 1.0 means the absolute bottom. | |
377 |
|
376 | |||
378 | By default both values are 0.5 which puts the pie in the middle of the chart rectangle. |
|
377 | By default both values are 0.5 which puts the pie in the middle of the chart rectangle. | |
379 |
|
378 | |||
380 | \sa pieHorizontalPosition(), pieVerticalPosition(), setPieSize() |
|
379 | \sa pieHorizontalPosition(), pieVerticalPosition(), setPieSize() | |
381 | */ |
|
380 | */ | |
382 | void QPieSeries::setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition) |
|
381 | void QPieSeries::setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition) | |
383 | { |
|
382 | { | |
384 | Q_D(QPieSeries); |
|
383 | Q_D(QPieSeries); | |
385 | if (relativeHorizontalPosition < 0.0 || relativeHorizontalPosition > 1.0 || |
|
384 | if (relativeHorizontalPosition < 0.0 || relativeHorizontalPosition > 1.0 || | |
386 | relativeVerticalPosition < 0.0 || relativeVerticalPosition > 1.0) |
|
385 | relativeVerticalPosition < 0.0 || relativeVerticalPosition > 1.0) | |
387 | return; |
|
386 | return; | |
388 |
|
387 | |||
389 | if (d->m_pieRelativeHorPos != relativeHorizontalPosition || d->m_pieRelativeVerPos != relativeVerticalPosition) { |
|
388 | if (d->m_pieRelativeHorPos != relativeHorizontalPosition || d->m_pieRelativeVerPos != relativeVerticalPosition) { | |
390 | d->m_pieRelativeHorPos = relativeHorizontalPosition; |
|
389 | d->m_pieRelativeHorPos = relativeHorizontalPosition; | |
391 | d->m_pieRelativeVerPos = relativeVerticalPosition; |
|
390 | d->m_pieRelativeVerPos = relativeVerticalPosition; | |
392 | emit piePositionChanged(); |
|
391 | emit piePositionChanged(); | |
393 | } |
|
392 | } | |
394 | } |
|
393 | } | |
395 |
|
394 | |||
396 | /*! |
|
395 | /*! | |
397 | Gets the horizontal position of the pie. |
|
396 | Gets the horizontal position of the pie. | |
398 |
|
397 | |||
399 | The returned value is relative to the chart rectangle where: |
|
398 | The returned value is relative to the chart rectangle where: | |
400 |
|
399 | |||
401 | 0.0 means the absolute left. |
|
400 | 0.0 means the absolute left. | |
402 | 1.0 means the absolute right. |
|
401 | 1.0 means the absolute right. | |
403 |
|
402 | |||
404 | By default it is 0.5 which puts the pie in the horizontal middle of the chart rectangle. |
|
403 | By default it is 0.5 which puts the pie in the horizontal middle of the chart rectangle. | |
405 |
|
404 | |||
406 | \sa setPiePosition(), pieVerticalPosition(), setPieSize() |
|
405 | \sa setPiePosition(), pieVerticalPosition(), setPieSize() | |
407 | */ |
|
406 | */ | |
408 | qreal QPieSeries::pieHorizontalPosition() const |
|
407 | qreal QPieSeries::pieHorizontalPosition() const | |
409 | { |
|
408 | { | |
410 | Q_D(const QPieSeries); |
|
409 | Q_D(const QPieSeries); | |
411 | return d->m_pieRelativeHorPos; |
|
410 | return d->m_pieRelativeHorPos; | |
412 | } |
|
411 | } | |
413 |
|
412 | |||
414 | /*! |
|
413 | /*! | |
415 | Gets the vertical position position of the pie. |
|
414 | Gets the vertical position position of the pie. | |
416 |
|
415 | |||
417 | The returned value is relative to the chart rectangle where: |
|
416 | The returned value is relative to the chart rectangle where: | |
418 |
|
417 | |||
419 | 0.0 means the absolute top. |
|
418 | 0.0 means the absolute top. | |
420 | 1.0 means the absolute bottom. |
|
419 | 1.0 means the absolute bottom. | |
421 |
|
420 | |||
422 | By default it is 0.5 which puts the pie in the vertical middle of the chart rectangle. |
|
421 | By default it is 0.5 which puts the pie in the vertical middle of the chart rectangle. | |
423 |
|
422 | |||
424 | \sa setPiePosition(), pieHorizontalPosition(), setPieSize() |
|
423 | \sa setPiePosition(), pieHorizontalPosition(), setPieSize() | |
425 | */ |
|
424 | */ | |
426 | qreal QPieSeries::pieVerticalPosition() const |
|
425 | qreal QPieSeries::pieVerticalPosition() const | |
427 | { |
|
426 | { | |
428 | Q_D(const QPieSeries); |
|
427 | Q_D(const QPieSeries); | |
429 | return d->m_pieRelativeVerPos; |
|
428 | return d->m_pieRelativeVerPos; | |
430 | } |
|
429 | } | |
431 |
|
430 | |||
432 | /*! |
|
431 | /*! | |
433 | Sets the relative size of the pie. |
|
432 | Sets the relative size of the pie. | |
434 |
|
433 | |||
435 | The \a relativeSize is defined so that the 1.0 is the maximum that can fit the given chart rectangle. |
|
434 | The \a relativeSize is defined so that the 1.0 is the maximum that can fit the given chart rectangle. | |
436 |
|
435 | |||
437 | Default value is 0.7. |
|
436 | Default value is 0.7. | |
438 |
|
437 | |||
439 | \sa pieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() |
|
438 | \sa pieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() | |
440 | */ |
|
439 | */ | |
441 | void QPieSeries::setPieSize(qreal relativeSize) |
|
440 | void QPieSeries::setPieSize(qreal relativeSize) | |
442 | { |
|
441 | { | |
443 | Q_D(QPieSeries); |
|
442 | Q_D(QPieSeries); | |
444 | if (relativeSize < 0.0 || relativeSize > 1.0) |
|
443 | if (relativeSize < 0.0 || relativeSize > 1.0) | |
445 | return; |
|
444 | return; | |
446 |
|
445 | |||
447 | if (d->m_pieRelativeSize != relativeSize) { |
|
446 | if (d->m_pieRelativeSize != relativeSize) { | |
448 | d->m_pieRelativeSize = relativeSize; |
|
447 | d->m_pieRelativeSize = relativeSize; | |
449 | emit pieSizeChanged(); |
|
448 | emit pieSizeChanged(); | |
450 | } |
|
449 | } | |
451 | } |
|
450 | } | |
452 |
|
451 | |||
453 | /*! |
|
452 | /*! | |
454 | Gets the relative size of the pie. |
|
453 | Gets the relative size of the pie. | |
455 |
|
454 | |||
456 | The size is defined so that the 1.0 is the maximum that can fit the given chart rectangle. |
|
455 | The size is defined so that the 1.0 is the maximum that can fit the given chart rectangle. | |
457 |
|
456 | |||
458 | Default value is 0.7. |
|
457 | Default value is 0.7. | |
459 |
|
458 | |||
460 | \sa setPieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() |
|
459 | \sa setPieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() | |
461 | */ |
|
460 | */ | |
462 | qreal QPieSeries::pieSize() const |
|
461 | qreal QPieSeries::pieSize() const | |
463 | { |
|
462 | { | |
464 | Q_D(const QPieSeries); |
|
463 | Q_D(const QPieSeries); | |
465 | return d->m_pieRelativeSize; |
|
464 | return d->m_pieRelativeSize; | |
466 | } |
|
465 | } | |
467 |
|
466 | |||
468 |
|
467 | |||
469 | /*! |
|
468 | /*! | |
470 | Sets the end angle of the pie. |
|
469 | Sets the end angle of the pie. | |
471 |
|
470 | |||
472 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
471 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
473 |
|
472 | |||
474 | \a angle must be less than pie end angle. Default value is 0. |
|
473 | \a angle must be less than pie end angle. Default value is 0. | |
475 |
|
474 | |||
476 | \sa pieStartAngle(), pieEndAngle(), setPieEndAngle() |
|
475 | \sa pieStartAngle(), pieEndAngle(), setPieEndAngle() | |
477 | */ |
|
476 | */ | |
478 | void QPieSeries::setPieStartAngle(qreal angle) |
|
477 | void QPieSeries::setPieStartAngle(qreal angle) | |
479 | { |
|
478 | { | |
480 | Q_D(QPieSeries); |
|
479 | Q_D(QPieSeries); | |
481 | if (angle >= 0 && angle <= 360 && angle != d->m_pieStartAngle && angle <= d->m_pieEndAngle) { |
|
480 | if (angle >= 0 && angle <= 360 && angle != d->m_pieStartAngle && angle <= d->m_pieEndAngle) { | |
482 | d->m_pieStartAngle = angle; |
|
481 | d->m_pieStartAngle = angle; | |
483 | d->updateDerivativeData(); |
|
482 | d->updateDerivativeData(); | |
484 | } |
|
483 | } | |
485 | } |
|
484 | } | |
486 |
|
485 | |||
487 | /*! |
|
486 | /*! | |
488 | Gets the start angle of the pie. |
|
487 | Gets the start angle of the pie. | |
489 |
|
488 | |||
490 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360. |
|
489 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360. | |
491 |
|
490 | |||
492 | \sa setPieStartAngle(), pieEndAngle(), setPieEndAngle() |
|
491 | \sa setPieStartAngle(), pieEndAngle(), setPieEndAngle() | |
493 | */ |
|
492 | */ | |
494 | qreal QPieSeries::pieStartAngle() const |
|
493 | qreal QPieSeries::pieStartAngle() const | |
495 | { |
|
494 | { | |
496 | Q_D(const QPieSeries); |
|
495 | Q_D(const QPieSeries); | |
497 | return d->m_pieStartAngle; |
|
496 | return d->m_pieStartAngle; | |
498 | } |
|
497 | } | |
499 |
|
498 | |||
500 | /*! |
|
499 | /*! | |
501 | Sets the end angle of the pie. |
|
500 | Sets the end angle of the pie. | |
502 |
|
501 | |||
503 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
502 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
504 |
|
503 | |||
505 | \a angle must be greater than start angle. |
|
504 | \a angle must be greater than start angle. | |
506 |
|
505 | |||
507 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
506 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | |
508 | */ |
|
507 | */ | |
509 | void QPieSeries::setPieEndAngle(qreal angle) |
|
508 | void QPieSeries::setPieEndAngle(qreal angle) | |
510 | { |
|
509 | { | |
511 | Q_D(QPieSeries); |
|
510 | Q_D(QPieSeries); | |
512 | if (angle >= 0 && angle <= 360 && angle != d->m_pieEndAngle && angle >= d->m_pieStartAngle) { |
|
511 | if (angle >= 0 && angle <= 360 && angle != d->m_pieEndAngle && angle >= d->m_pieStartAngle) { | |
513 | d->m_pieEndAngle = angle; |
|
512 | d->m_pieEndAngle = angle; | |
514 | d->updateDerivativeData(); |
|
513 | d->updateDerivativeData(); | |
515 | } |
|
514 | } | |
516 | } |
|
515 | } | |
517 |
|
516 | |||
518 | /*! |
|
517 | /*! | |
519 | Returns the end angle of the pie. |
|
518 | Returns the end angle of the pie. | |
520 |
|
519 | |||
521 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
520 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
522 |
|
521 | |||
523 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
522 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | |
524 | */ |
|
523 | */ | |
525 | qreal QPieSeries::pieEndAngle() const |
|
524 | qreal QPieSeries::pieEndAngle() const | |
526 | { |
|
525 | { | |
527 | Q_D(const QPieSeries); |
|
526 | Q_D(const QPieSeries); | |
528 | return d->m_pieEndAngle; |
|
527 | return d->m_pieEndAngle; | |
529 | } |
|
528 | } | |
530 |
|
529 | |||
531 | /*! |
|
530 | /*! | |
532 | Sets the all the slice labels \a visible or invisible. |
|
531 | Sets the all the slice labels \a visible or invisible. | |
533 |
|
532 | |||
534 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
533 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | |
535 | */ |
|
534 | */ | |
536 | void QPieSeries::setLabelsVisible(bool visible) |
|
535 | void QPieSeries::setLabelsVisible(bool visible) | |
537 | { |
|
536 | { | |
538 | Q_D(QPieSeries); |
|
537 | Q_D(QPieSeries); | |
539 | foreach (QPieSlice* s, d->m_slices) |
|
538 | foreach (QPieSlice* s, d->m_slices) | |
540 | s->setLabelVisible(visible); |
|
539 | s->setLabelVisible(visible); | |
541 | } |
|
540 | } | |
542 |
|
541 | |||
543 | /*! |
|
542 | /*! | |
544 | Returns the sum of all slice values in this series. |
|
543 | Returns the sum of all slice values in this series. | |
545 |
|
544 | |||
546 | \sa QPieSlice::value(), QPieSlice::setValue() |
|
545 | \sa QPieSlice::value(), QPieSlice::setValue() | |
547 | */ |
|
546 | */ | |
548 | qreal QPieSeries::total() const |
|
547 | qreal QPieSeries::total() const | |
549 | { |
|
548 | { | |
550 | Q_D(const QPieSeries); |
|
549 | Q_D(const QPieSeries); | |
551 | return d->m_total; |
|
550 | return d->m_total; | |
552 | } |
|
551 | } | |
553 |
|
552 | |||
554 | /*! |
|
553 | /*! | |
555 | \fn void QPieSeries::clicked(QPieSlice* slice) |
|
554 | \fn void QPieSeries::clicked(QPieSlice* slice) | |
556 |
|
555 | |||
557 | This signal is emitted when a \a slice has been clicked. |
|
556 | This signal is emitted when a \a slice has been clicked. | |
558 |
|
557 | |||
559 | \sa QPieSlice::clicked() |
|
558 | \sa QPieSlice::clicked() | |
560 | */ |
|
559 | */ | |
561 |
|
560 | |||
562 | /*! |
|
561 | /*! | |
563 | \fn void QPieSeries::hoverEnter(QPieSlice* slice) |
|
562 | \fn void QPieSeries::hoverEnter(QPieSlice* slice) | |
564 |
|
563 | |||
565 | This signal is emitted when user has hovered over a \a slice. |
|
564 | This signal is emitted when user has hovered over a \a slice. | |
566 |
|
565 | |||
567 | \sa QPieSlice::hoverEnter() |
|
566 | \sa QPieSlice::hoverEnter() | |
568 | */ |
|
567 | */ | |
569 |
|
568 | |||
570 | /*! |
|
569 | /*! | |
571 | \fn void QPieSeries::hoverLeave(QPieSlice* slice) |
|
570 | \fn void QPieSeries::hoverLeave(QPieSlice* slice) | |
572 |
|
571 | |||
573 | This signal is emitted when user has hovered away from a \a slice. |
|
572 | This signal is emitted when user has hovered away from a \a slice. | |
574 |
|
573 | |||
575 | \sa QPieSlice::hoverLeave() |
|
574 | \sa QPieSlice::hoverLeave() | |
576 | */ |
|
575 | */ | |
577 |
|
576 | |||
578 |
|
577 | |||
579 |
|
578 | |||
580 |
|
579 | |||
581 | bool QPieSeries::setModel(QAbstractItemModel* model) |
|
580 | bool QPieSeries::setModel(QAbstractItemModel* model) | |
582 | { |
|
581 | { | |
583 | Q_D(QPieSeries); |
|
582 | Q_D(QPieSeries); | |
584 | // disconnect signals from old model |
|
583 | // disconnect signals from old model | |
585 | if(m_model) |
|
584 | if(m_model) | |
586 | { |
|
585 | { | |
587 | disconnect(m_model, 0, this, 0); |
|
586 | disconnect(m_model, 0, this, 0); | |
588 | d->m_mapValues = -1; |
|
587 | d->m_mapValues = -1; | |
589 | d->m_mapLabels = -1; |
|
588 | d->m_mapLabels = -1; | |
590 | d->m_mapOrientation = Qt::Vertical; |
|
589 | d->m_mapOrientation = Qt::Vertical; | |
591 | } |
|
590 | } | |
592 |
|
591 | |||
593 | // set new model |
|
592 | // set new model | |
594 | if(model) |
|
593 | if(model) | |
595 | { |
|
594 | { | |
596 | m_model = model; |
|
595 | m_model = model; | |
597 | return true; |
|
596 | return true; | |
598 | } |
|
597 | } | |
599 | else |
|
598 | else | |
600 | { |
|
599 | { | |
601 | m_model = NULL; |
|
600 | m_model = NULL; | |
602 | return false; |
|
601 | return false; | |
603 | } |
|
602 | } | |
604 | } |
|
603 | } | |
605 |
|
604 | |||
606 | void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) |
|
605 | void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) | |
607 | { |
|
606 | { | |
608 | Q_D(QPieSeries); |
|
607 | Q_D(QPieSeries); | |
609 |
|
608 | |||
610 | if (m_model == NULL) |
|
609 | if (m_model == NULL) | |
611 | return; |
|
610 | return; | |
612 |
|
611 | |||
613 | d->m_mapValues = modelValuesLine; |
|
612 | d->m_mapValues = modelValuesLine; | |
614 | d->m_mapLabels = modelLabelsLine; |
|
613 | d->m_mapLabels = modelLabelsLine; | |
615 | d->m_mapOrientation = orientation; |
|
614 | d->m_mapOrientation = orientation; | |
616 |
|
615 | |||
617 | // connect the signals |
|
616 | // connect the signals | |
618 | if (d->m_mapOrientation == Qt::Vertical) { |
|
617 | if (d->m_mapOrientation == Qt::Vertical) { | |
619 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
618 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
620 | connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
619 | connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
621 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
620 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
622 | } else { |
|
621 | } else { | |
623 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
622 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
624 | connect(m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
623 | connect(m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
625 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
624 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
626 | } |
|
625 | } | |
627 |
|
626 | |||
628 | // create the initial slices set |
|
627 | // create the initial slices set | |
629 | if (d->m_mapOrientation == Qt::Vertical) { |
|
628 | if (d->m_mapOrientation == Qt::Vertical) { | |
630 | for (int i = 0; i < m_model->rowCount(); i++) |
|
629 | for (int i = 0; i < m_model->rowCount(); i++) | |
631 | add(m_model->data(m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString()); |
|
630 | add(m_model->data(m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString()); | |
632 | } else { |
|
631 | } else { | |
633 | for (int i = 0; i < m_model->columnCount(); i++) |
|
632 | for (int i = 0; i < m_model->columnCount(); i++) | |
634 | add(m_model->data(m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString()); |
|
633 | add(m_model->data(m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString()); | |
635 | } |
|
634 | } | |
636 | } |
|
635 | } | |
637 |
|
636 | |||
638 | #include "moc_qpieseries.cpp" |
|
637 | #include "moc_qpieseries.cpp" | |
639 | #include "moc_qpieseriesprivate_p.cpp" |
|
638 | #include "moc_qpieseriesprivate_p.cpp" | |
640 |
|
639 | |||
641 | QTCOMMERCIALCHART_END_NAMESPACE |
|
640 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,170 +1,170 | |||||
1 | #include "scatterchartitem_p.h" |
|
1 | #include "scatterchartitem_p.h" | |
2 | #include "qscatterseries.h" |
|
2 | #include "qscatterseries.h" | |
3 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
4 | #include <QPainter> |
|
4 | #include <QPainter> | |
5 | #include <QGraphicsScene> |
|
5 | #include <QGraphicsScene> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) : |
|
9 | ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) : | |
10 | XYChartItem(series,presenter), |
|
10 | XYChartItem(series,presenter), | |
11 | m_series(series), |
|
11 | m_series(series), | |
12 | m_items(this), |
|
12 | m_items(this), | |
13 | m_shape(QScatterSeries::MarkerShapeRectangle), |
|
13 | m_shape(QScatterSeries::MarkerShapeRectangle), | |
14 | m_size(15) |
|
14 | m_size(15) | |
15 |
|
15 | |||
16 | { |
|
16 | { | |
17 | QObject::connect(m_series,SIGNAL(updated()), this, SLOT(handleUpdated())); |
|
17 | QObject::connect(m_series,SIGNAL(updated()), this, SLOT(handleUpdated())); | |
18 |
|
18 | |||
19 | setZValue(ChartPresenter::ScatterSeriesZValue); |
|
19 | setZValue(ChartPresenter::ScatterSeriesZValue); | |
20 | setFlags(QGraphicsItem::ItemHasNoContents); |
|
20 | setFlags(QGraphicsItem::ItemHasNoContents); | |
21 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
21 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
22 |
|
22 | |||
23 | handleUpdated(); |
|
23 | handleUpdated(); | |
24 |
|
24 | |||
25 | m_items.setHandlesChildEvents(false); |
|
25 | m_items.setHandlesChildEvents(false); | |
26 |
|
26 | |||
27 | // TODO: how to draw a drop shadow? |
|
27 | // TODO: how to draw a drop shadow? | |
28 | // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect(); |
|
28 | // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect(); | |
29 | // dropShadow->setOffset(2.0); |
|
29 | // dropShadow->setOffset(2.0); | |
30 | // dropShadow->setBlurRadius(2.0); |
|
30 | // dropShadow->setBlurRadius(2.0); | |
31 | // setGraphicsEffect(dropShadow); |
|
31 | // setGraphicsEffect(dropShadow); | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | QRectF ScatterChartItem::boundingRect() const |
|
35 | QRectF ScatterChartItem::boundingRect() const | |
36 | { |
|
36 | { | |
37 | return m_rect; |
|
37 | return m_rect; | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | void ScatterChartItem::createPoints(int count) |
|
40 | void ScatterChartItem::createPoints(int count) | |
41 | { |
|
41 | { | |
42 | for (int i = 0; i < count; ++i) { |
|
42 | for (int i = 0; i < count; ++i) { | |
43 |
|
43 | |||
44 | QGraphicsItem *item; |
|
44 | QGraphicsItem *item = 0; | |
45 |
|
45 | |||
46 | switch (m_shape) { |
|
46 | switch (m_shape) { | |
47 | case QScatterSeries::MarkerShapeCircle:{ |
|
47 | case QScatterSeries::MarkerShapeCircle:{ | |
48 | QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size); |
|
48 | QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size); | |
49 | const QRectF& rect = i->boundingRect(); |
|
49 | const QRectF& rect = i->boundingRect(); | |
50 | i->setPos(-rect.width()/2,-rect.height()/2); |
|
50 | i->setPos(-rect.width()/2,-rect.height()/2); | |
51 | item = new Marker(i,this); |
|
51 | item = new Marker(i,this); | |
52 | break; |
|
52 | break; | |
53 | } |
|
53 | } | |
54 | case QScatterSeries::MarkerShapeRectangle:{ |
|
54 | case QScatterSeries::MarkerShapeRectangle:{ | |
55 | QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size); |
|
55 | QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size); | |
56 | i->setPos(-m_size/2,-m_size/2); |
|
56 | i->setPos(-m_size/2,-m_size/2); | |
57 | item = new Marker(i,this); |
|
57 | item = new Marker(i,this); | |
58 | break; |
|
58 | break; | |
59 | } |
|
59 | } | |
60 | default: |
|
60 | default: | |
61 | qWarning()<<"Unsupported marker type"; |
|
61 | qWarning()<<"Unsupported marker type"; | |
62 | break; |
|
62 | break; | |
63 |
|
63 | |||
64 | } |
|
64 | } | |
65 | m_items.addToGroup(item); |
|
65 | m_items.addToGroup(item); | |
66 | } |
|
66 | } | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void ScatterChartItem::deletePoints(int count) |
|
69 | void ScatterChartItem::deletePoints(int count) | |
70 | { |
|
70 | { | |
71 | QList<QGraphicsItem *> items = m_items.childItems(); |
|
71 | QList<QGraphicsItem *> items = m_items.childItems(); | |
72 |
|
72 | |||
73 | for (int i = 0; i < count; ++i) { |
|
73 | for (int i = 0; i < count; ++i) { | |
74 | delete(items.takeLast()); |
|
74 | delete(items.takeLast()); | |
75 | } |
|
75 | } | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void ScatterChartItem::markerSelected(Marker* marker) |
|
78 | void ScatterChartItem::markerSelected(Marker* marker) | |
79 | { |
|
79 | { | |
80 | emit XYChartItem::clicked(QPointF(m_series->x(marker->index()), m_series->y(marker->index()))); |
|
80 | emit XYChartItem::clicked(QPointF(m_series->x(marker->index()), m_series->y(marker->index()))); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | void ScatterChartItem::setLayout(QVector<QPointF>& points) |
|
83 | void ScatterChartItem::setLayout(QVector<QPointF>& points) | |
84 | { |
|
84 | { | |
85 | if(points.size()==0) |
|
85 | if(points.size()==0) | |
86 | { |
|
86 | { | |
87 | XYChartItem::setLayout(points); |
|
87 | XYChartItem::setLayout(points); | |
88 | return; |
|
88 | return; | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | int diff = XYChartItem::points().size() - points.size(); |
|
91 | int diff = XYChartItem::points().size() - points.size(); | |
92 |
|
92 | |||
93 | if(diff>0) { |
|
93 | if(diff>0) { | |
94 | deletePoints(diff); |
|
94 | deletePoints(diff); | |
95 | } |
|
95 | } | |
96 | else if(diff<0) { |
|
96 | else if(diff<0) { | |
97 | createPoints(-diff); |
|
97 | createPoints(-diff); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | if(diff!=0) handleUpdated(); |
|
100 | if(diff!=0) handleUpdated(); | |
101 |
|
101 | |||
102 | QList<QGraphicsItem*> items = m_items.childItems(); |
|
102 | QList<QGraphicsItem*> items = m_items.childItems(); | |
103 |
|
103 | |||
104 | for(int i=0; i< points.size();i++) { |
|
104 | for(int i=0; i< points.size();i++) { | |
105 | Marker* item = static_cast<Marker*>(items.at(i)); |
|
105 | Marker* item = static_cast<Marker*>(items.at(i)); | |
106 | const QPointF& point = points.at(i); |
|
106 | const QPointF& point = points.at(i); | |
107 | const QRectF& rect = item->boundingRect(); |
|
107 | const QRectF& rect = item->boundingRect(); | |
108 | item->setIndex(i); |
|
108 | item->setIndex(i); | |
109 | item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2); |
|
109 | item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2); | |
110 | if(!clipRect().contains(point)) { |
|
110 | if(!clipRect().contains(point)) { | |
111 | item->setVisible(false); |
|
111 | item->setVisible(false); | |
112 | } |
|
112 | } | |
113 | else { |
|
113 | else { | |
114 | item->setVisible(true); |
|
114 | item->setVisible(true); | |
115 | } |
|
115 | } | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | prepareGeometryChange(); |
|
118 | prepareGeometryChange(); | |
119 | m_rect = clipRect(); |
|
119 | m_rect = clipRect(); | |
120 | XYChartItem::setLayout(points); |
|
120 | XYChartItem::setLayout(points); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 |
|
123 | |||
124 | void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
124 | void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
125 | { |
|
125 | { | |
126 | Q_UNUSED(painter) |
|
126 | Q_UNUSED(painter) | |
127 | Q_UNUSED(option) |
|
127 | Q_UNUSED(option) | |
128 | Q_UNUSED(widget) |
|
128 | Q_UNUSED(widget) | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | void ScatterChartItem::setPen(const QPen& pen) |
|
131 | void ScatterChartItem::setPen(const QPen& pen) | |
132 | { |
|
132 | { | |
133 | foreach(QGraphicsItem* item , m_items.childItems()) { |
|
133 | foreach(QGraphicsItem* item , m_items.childItems()) { | |
134 | static_cast<Marker*>(item)->setPen(pen); |
|
134 | static_cast<Marker*>(item)->setPen(pen); | |
135 | } |
|
135 | } | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | void ScatterChartItem::setBrush(const QBrush& brush) |
|
138 | void ScatterChartItem::setBrush(const QBrush& brush) | |
139 | { |
|
139 | { | |
140 | foreach(QGraphicsItem* item , m_items.childItems()) { |
|
140 | foreach(QGraphicsItem* item , m_items.childItems()) { | |
141 | static_cast<Marker*>(item)->setBrush(brush); |
|
141 | static_cast<Marker*>(item)->setBrush(brush); | |
142 | } |
|
142 | } | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | void ScatterChartItem::handleUpdated() |
|
145 | void ScatterChartItem::handleUpdated() | |
146 | { |
|
146 | { | |
147 |
|
147 | |||
148 | int count = m_items.childItems().count(); |
|
148 | int count = m_items.childItems().count(); | |
149 |
|
149 | |||
150 | if(count==0) return; |
|
150 | if(count==0) return; | |
151 |
|
151 | |||
152 | bool recreate = m_size != m_series->size() || m_shape != m_series->shape(); |
|
152 | bool recreate = m_size != m_series->size() || m_shape != m_series->shape(); | |
153 |
|
153 | |||
154 | //TODO: only rewrite on size change |
|
154 | //TODO: only rewrite on size change | |
155 |
|
155 | |||
156 | m_size = m_series->size(); |
|
156 | m_size = m_series->size(); | |
157 | m_shape = m_series->shape(); |
|
157 | m_shape = m_series->shape(); | |
158 |
|
158 | |||
159 | if(recreate){ |
|
159 | if(recreate){ | |
160 | deletePoints(count); |
|
160 | deletePoints(count); | |
161 | createPoints(count); |
|
161 | createPoints(count); | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | setPen(m_series->pen()); |
|
164 | setPen(m_series->pen()); | |
165 | setBrush(m_series->brush()); |
|
165 | setBrush(m_series->brush()); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | #include "moc_scatterchartitem_p.cpp" |
|
168 | #include "moc_scatterchartitem_p.cpp" | |
169 |
|
169 | |||
170 | QTCOMMERCIALCHART_END_NAMESPACE |
|
170 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now