##// END OF EJS Templates
Bugfix : black line drawn during areachart paint
Michal Klocek -
r690:847ff650439d
parent child
Show More
@@ -1,125 +1,122
1 1 #include "areachartitem_p.h"
2 2 #include "qareaseries.h"
3 3 #include "qlineseries.h"
4 4 #include "chartpresenter_p.h"
5 5 #include <QPainter>
6 6 #include <QGraphicsSceneMouseEvent>
7 7
8 8
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 11 //TODO: optimize : remove points which are not visible
12 12
13 13 AreaChartItem::AreaChartItem(QAreaSeries* areaSeries,ChartPresenter *presenter):ChartItem(presenter),
14 14 m_series(areaSeries),
15 15 m_upper(0),
16 16 m_lower(0),
17 17 m_pointsVisible(false)
18 18 {
19 19 setZValue(ChartPresenter::LineChartZValue);
20 m_upper = new AreaBoundItem(this,m_series->upperSeries(),presenter);
20 m_upper = new AreaBoundItem(this,m_series->upperSeries());
21 21 if(m_series->lowerSeries()){
22 m_lower = new AreaBoundItem(this,m_series->lowerSeries(),presenter);
22 m_lower = new AreaBoundItem(this,m_series->lowerSeries());
23 23 }
24 24
25 25 QObject::connect(areaSeries,SIGNAL(updated()),this,SLOT(handleUpdated()));
26 26 QObject::connect(this,SIGNAL(clicked(const QPointF&)),areaSeries,SIGNAL(clicked(const QPointF&)));
27 27
28 28 handleUpdated();
29 29 }
30 30
31 31 AreaChartItem::~AreaChartItem()
32 32 {
33 33 delete m_upper;
34 34 delete m_lower;
35 35 };
36 36
37 37 QRectF AreaChartItem::boundingRect() const
38 38 {
39 39 return m_rect;
40 40 }
41 41
42 42 QPainterPath AreaChartItem::shape() const
43 43 {
44 44 return m_path;
45 45 }
46 46
47 47 void AreaChartItem::updatePath()
48 48 {
49 49 QPainterPath path;
50 50
51 path.connectPath(m_upper->shape());
51 path = m_upper->shape();
52
52 53 if(m_lower){
53 54 path.connectPath(m_lower->shape().toReversed());
54 55 }
55 56 else{
56 57 QPointF first = path.pointAtPercent(0);
57 58 QPointF last = path.pointAtPercent(1);
58 59 path.lineTo(last.x(),m_clipRect.bottom());
59 60 path.lineTo(first.x(),m_clipRect.bottom());
60 61 }
61 62 path.closeSubpath();
62 63 prepareGeometryChange();
63 64 m_path=path;
64 65 m_rect=path.boundingRect();
65 66 update();
66 67 }
67 68
68 69 void AreaChartItem::handleUpdated()
69 70 {
70 71 m_pointsVisible = m_series->pointsVisible();
71 72 m_linePen = m_series->pen();
72 73 m_brush = m_series->brush();
73 74 m_pointPen = m_series->pen();
74 75 m_pointPen.setWidthF(2*m_pointPen.width());
75 76
76 77 update();
77 78 }
78 79
79 80 void AreaChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
80 81 {
81 82 m_upper->handleDomainChanged(minX,maxX,minY,maxY);
82 83 if(m_lower)
83 84 m_lower->handleDomainChanged(minX,maxX,minY,maxY);
84 85 }
85 86
86 87 void AreaChartItem::handleGeometryChanged(const QRectF& rect)
87 88 {
88 89 m_clipRect=rect.translated(-rect.topLeft());
89 90 setPos(rect.topLeft());
90 91 m_upper->handleGeometryChanged(rect);
91 92 if(m_lower)
92 93 m_lower->handleGeometryChanged(rect);
93 94 }
94 95 //painter
95 96
96 97 void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
97 98 {
98 99 Q_UNUSED(widget)
99 100 Q_UNUSED(option)
100 101
101 102 painter->save();
102 QPen pen;
103 pen.setCosmetic(false);
104 pen.setWidth(4);
105 pen.setColor(qRgb(200,0,250));
106 painter->setPen(pen);
107 //painter->setBrush(m_brush);
103 painter->setPen(m_linePen);
104 painter->setBrush(m_brush);
108 105 painter->setClipRect(m_clipRect);
109 106 painter->drawPath(m_path);
110 107 if(m_pointsVisible){
111 108 painter->setPen(m_pointPen);
112 109 painter->drawPoints(m_upper->points());
113 110 if(m_lower) painter->drawPoints(m_lower->points());
114 111 }
115 112 painter->restore();
116 113 }
117 114
118 115 void AreaChartItem::mousePressEvent( QGraphicsSceneMouseEvent * event )
119 116 {
120 117 emit clicked(m_upper->calculateDomainPoint(event->pos()));
121 118 }
122 119
123 120 #include "moc_areachartitem_p.cpp"
124 121
125 122 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,75 +1,76
1 1 #ifndef AREACHARTITEM_H
2 2 #define AREACHARTITEM_H
3 3
4 4 #include "qchartglobal.h"
5 5 #include "linechartitem_p.h"
6 6 #include <QPen>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class QAreaSeries;
11 11 class AreaChartItem;
12 12
13 13 class AreaChartItem : public ChartItem
14 14 {
15 15 Q_OBJECT
16 16 public:
17 17 AreaChartItem(QAreaSeries* areaSeries, ChartPresenter *presenter);
18 18 ~ AreaChartItem();
19 19
20 20 //from QGraphicsItem
21 21 QRectF boundingRect() const;
22 22 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
23 23 QPainterPath shape() const;
24 24
25 25 LineChartItem* upperLineItem() const { return m_upper ;}
26 26 LineChartItem* lowerLineItem() const { return m_lower ;}
27 27
28 28 void updatePath();
29 29
30 30 protected:
31 31 void mousePressEvent( QGraphicsSceneMouseEvent * event );
32 32
33 33 signals:
34 34 void clicked(const QPointF& point);
35 35
36 36 public slots:
37 37 void handleUpdated();
38 38 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
39 39 void handleGeometryChanged(const QRectF& size);
40 40
41 41 private:
42 42 QAreaSeries* m_series;
43 43 LineChartItem* m_upper;
44 44 LineChartItem* m_lower;
45 45 QPainterPath m_path;
46 46 QRectF m_rect;
47 47 QRectF m_clipRect;
48 48 QPen m_linePen;
49 49 QPen m_pointPen;
50 50 QBrush m_brush;
51 51 bool m_pointsVisible;
52 52
53 53 };
54 54
55 55 class AreaBoundItem : public LineChartItem
56 56 {
57 57 public:
58 AreaBoundItem(AreaChartItem* item,QLineSeries* lineSeries,ChartPresenter *presenter):LineChartItem(lineSeries,presenter),
59 m_item(item){};
58 AreaBoundItem(AreaChartItem* item,QLineSeries* lineSeries):LineChartItem(lineSeries,0),
59 m_item(item){
60 };
60 61
61 62 ~AreaBoundItem(){};
62 63
63 64 void setLayout(QVector<QPointF>& points){
64 65 LineChartItem::setLayout(points);
65 66 m_item->updatePath();
66 67 }
67 68
68 69 private:
69 70 AreaChartItem* m_item;
70 71
71 72 };
72 73
73 74 QTCOMMERCIALCHART_END_NAMESPACE
74 75
75 76 #endif
@@ -1,19 +1,19
1 1 #ifndef CHARTITEM_H_
2 2 #define CHARTITEM_H_
3 3
4 4 #include "chart_p.h"
5 5 #include "chartpresenter_p.h"
6 6 #include <QGraphicsItem>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class ChartItem : public QGraphicsItem, public Chart
11 11 {
12 12 enum ChartItemTypes{ AXIS_ITEM = UserType+1, XYLINE_ITEM};
13 13 public:
14 ChartItem(ChartPresenter *presenter):QGraphicsItem(presenter->rootItem()),Chart(presenter){};
14 ChartItem(ChartPresenter *presenter):QGraphicsItem(presenter?presenter->rootItem():0),Chart(presenter){};
15 15 };
16 16
17 17 QTCOMMERCIALCHART_END_NAMESPACE
18 18
19 19 #endif /* CHARTITEM_H_ */
General Comments 0
You need to be logged in to leave comments. Login now