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