@@ -1,112 +1,113 | |||
|
1 | 1 | #include "areachartitem_p.h" |
|
2 | 2 | #include "qareaseries.h" |
|
3 | 3 | #include "qlineseries.h" |
|
4 | #include "chartpresenter_p.h" | |
|
4 | 5 | #include <QPainter> |
|
5 | 6 | |
|
6 | 7 | |
|
7 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | 9 | |
|
9 | 10 | //TODO: optimize : remove points which are not visible |
|
10 | 11 | |
|
11 | 12 | AreaChartItem::AreaChartItem(QAreaSeries* areaSeries,QGraphicsItem *parent):ChartItem(parent), |
|
12 | 13 | m_series(areaSeries), |
|
13 | 14 | m_upper(0), |
|
14 | 15 | m_lower(0), |
|
15 | 16 | m_pointsVisible(false) |
|
16 | 17 | { |
|
17 |
|
|
|
18 | setZValue(ChartPresenter::LineChartZValue); | |
|
18 | 19 | m_upper = new AreaBoundItem(this,m_series->upperSeries()); |
|
19 | 20 | if(m_series->lowerSeries()){ |
|
20 | 21 | m_lower = new AreaBoundItem(this,m_series->lowerSeries()); |
|
21 | 22 | } |
|
22 | 23 | |
|
23 | 24 | QObject::connect(areaSeries,SIGNAL(updated()),this,SLOT(handleUpdated())); |
|
24 | 25 | |
|
25 | 26 | handleUpdated(); |
|
26 | 27 | } |
|
27 | 28 | |
|
28 | 29 | AreaChartItem::~AreaChartItem() |
|
29 | 30 | { |
|
30 | 31 | delete m_upper; |
|
31 | 32 | delete m_lower; |
|
32 | 33 | }; |
|
33 | 34 | |
|
34 | 35 | QRectF AreaChartItem::boundingRect() const |
|
35 | 36 | { |
|
36 | 37 | return m_rect; |
|
37 | 38 | } |
|
38 | 39 | |
|
39 | 40 | QPainterPath AreaChartItem::shape() const |
|
40 | 41 | { |
|
41 | 42 | return m_path; |
|
42 | 43 | } |
|
43 | 44 | |
|
44 | 45 | void AreaChartItem::updatePath() |
|
45 | 46 | { |
|
46 | 47 | QPainterPath path; |
|
47 | 48 | |
|
48 | 49 | path.connectPath(m_upper->shape()); |
|
49 | 50 | if(m_lower){ |
|
50 | 51 | path.connectPath(m_lower->shape().toReversed()); |
|
51 | 52 | } |
|
52 | 53 | else{ |
|
53 | 54 | QPointF first = path.pointAtPercent(0); |
|
54 | 55 | QPointF last = path.pointAtPercent(1); |
|
55 | 56 | path.lineTo(last.x(),m_clipRect.bottom()); |
|
56 | 57 | path.lineTo(first.x(),m_clipRect.bottom()); |
|
57 | 58 | } |
|
58 | 59 | path.closeSubpath(); |
|
59 | 60 | prepareGeometryChange(); |
|
60 | 61 | m_path=path; |
|
61 | 62 | m_rect=path.boundingRect(); |
|
62 | 63 | update(); |
|
63 | 64 | } |
|
64 | 65 | |
|
65 | 66 | void AreaChartItem::handleUpdated() |
|
66 | 67 | { |
|
67 | 68 | m_pointsVisible = m_series->pointsVisible(); |
|
68 | 69 | m_linePen = m_series->pen(); |
|
69 | 70 | m_brush = m_series->brush(); |
|
70 | 71 | m_pointPen = m_series->pen(); |
|
71 | 72 | m_pointPen.setWidthF(2*m_pointPen.width()); |
|
72 | 73 | |
|
73 | 74 | update(); |
|
74 | 75 | } |
|
75 | 76 | |
|
76 | 77 | void AreaChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
77 | 78 | { |
|
78 | 79 | m_upper->handleDomainChanged(minX,maxX,minY,maxY); |
|
79 | 80 | if(m_lower) |
|
80 | 81 | m_lower->handleDomainChanged(minX,maxX,minY,maxY); |
|
81 | 82 | } |
|
82 | 83 | |
|
83 | 84 | void AreaChartItem::handleGeometryChanged(const QRectF& rect) |
|
84 | 85 | { |
|
85 | 86 | m_clipRect=rect.translated(-rect.topLeft()); |
|
86 | 87 | setPos(rect.topLeft()); |
|
87 | 88 | m_upper->handleGeometryChanged(rect); |
|
88 | 89 | if(m_lower) |
|
89 | 90 | m_lower->handleGeometryChanged(rect); |
|
90 | 91 | } |
|
91 | 92 | //painter |
|
92 | 93 | |
|
93 | 94 | void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
94 | 95 | { |
|
95 | 96 | Q_UNUSED(widget); |
|
96 | 97 | Q_UNUSED(option); |
|
97 | 98 | painter->save(); |
|
98 | 99 | painter->setPen(m_linePen); |
|
99 | 100 | painter->setBrush(m_brush); |
|
100 | 101 | painter->setClipRect(m_clipRect); |
|
101 | 102 | painter->drawPath(m_path); |
|
102 | 103 | if(m_pointsVisible){ |
|
103 | 104 | painter->setPen(m_pointPen); |
|
104 | 105 | painter->drawPoints(m_upper->points()); |
|
105 | 106 | if(m_lower) painter->drawPoints(m_lower->points()); |
|
106 | 107 | } |
|
107 | 108 | painter->restore(); |
|
108 | 109 | } |
|
109 | 110 | |
|
110 | 111 | #include "moc_areachartitem_p.cpp" |
|
111 | 112 | |
|
112 | 113 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now