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