@@ -1,125 +1,122 | |||||
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):ChartItem(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() |
|
20 | m_upper = new AreaBoundItem(this,m_series->upperSeries()); | |
21 | if(m_series->lowerSeries()){ |
|
21 | if(m_series->lowerSeries()){ | |
22 |
m_lower = new AreaBoundItem(this,m_series->lowerSeries() |
|
22 | m_lower = new AreaBoundItem(this,m_series->lowerSeries()); | |
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 |
|
51 | path = m_upper->shape(); | |
|
52 | ||||
52 | if(m_lower){ |
|
53 | if(m_lower){ | |
53 | path.connectPath(m_lower->shape().toReversed()); |
|
54 | path.connectPath(m_lower->shape().toReversed()); | |
54 | } |
|
55 | } | |
55 | else{ |
|
56 | else{ | |
56 | QPointF first = path.pointAtPercent(0); |
|
57 | QPointF first = path.pointAtPercent(0); | |
57 | QPointF last = path.pointAtPercent(1); |
|
58 | QPointF last = path.pointAtPercent(1); | |
58 | path.lineTo(last.x(),m_clipRect.bottom()); |
|
59 | path.lineTo(last.x(),m_clipRect.bottom()); | |
59 | path.lineTo(first.x(),m_clipRect.bottom()); |
|
60 | path.lineTo(first.x(),m_clipRect.bottom()); | |
60 | } |
|
61 | } | |
61 | path.closeSubpath(); |
|
62 | path.closeSubpath(); | |
62 | prepareGeometryChange(); |
|
63 | prepareGeometryChange(); | |
63 | m_path=path; |
|
64 | m_path=path; | |
64 | m_rect=path.boundingRect(); |
|
65 | m_rect=path.boundingRect(); | |
65 | update(); |
|
66 | update(); | |
66 | } |
|
67 | } | |
67 |
|
68 | |||
68 | void AreaChartItem::handleUpdated() |
|
69 | void AreaChartItem::handleUpdated() | |
69 | { |
|
70 | { | |
70 | m_pointsVisible = m_series->pointsVisible(); |
|
71 | m_pointsVisible = m_series->pointsVisible(); | |
71 | m_linePen = m_series->pen(); |
|
72 | m_linePen = m_series->pen(); | |
72 | m_brush = m_series->brush(); |
|
73 | m_brush = m_series->brush(); | |
73 | m_pointPen = m_series->pen(); |
|
74 | m_pointPen = m_series->pen(); | |
74 | m_pointPen.setWidthF(2*m_pointPen.width()); |
|
75 | m_pointPen.setWidthF(2*m_pointPen.width()); | |
75 |
|
76 | |||
76 | update(); |
|
77 | update(); | |
77 | } |
|
78 | } | |
78 |
|
79 | |||
79 | void AreaChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
80 | void AreaChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
80 | { |
|
81 | { | |
81 | m_upper->handleDomainChanged(minX,maxX,minY,maxY); |
|
82 | m_upper->handleDomainChanged(minX,maxX,minY,maxY); | |
82 | if(m_lower) |
|
83 | if(m_lower) | |
83 | m_lower->handleDomainChanged(minX,maxX,minY,maxY); |
|
84 | m_lower->handleDomainChanged(minX,maxX,minY,maxY); | |
84 | } |
|
85 | } | |
85 |
|
86 | |||
86 | void AreaChartItem::handleGeometryChanged(const QRectF& rect) |
|
87 | void AreaChartItem::handleGeometryChanged(const QRectF& rect) | |
87 | { |
|
88 | { | |
88 | m_clipRect=rect.translated(-rect.topLeft()); |
|
89 | m_clipRect=rect.translated(-rect.topLeft()); | |
89 | setPos(rect.topLeft()); |
|
90 | setPos(rect.topLeft()); | |
90 | m_upper->handleGeometryChanged(rect); |
|
91 | m_upper->handleGeometryChanged(rect); | |
91 | if(m_lower) |
|
92 | if(m_lower) | |
92 | m_lower->handleGeometryChanged(rect); |
|
93 | m_lower->handleGeometryChanged(rect); | |
93 | } |
|
94 | } | |
94 | //painter |
|
95 | //painter | |
95 |
|
96 | |||
96 | void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
97 | void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
97 | { |
|
98 | { | |
98 | Q_UNUSED(widget) |
|
99 | Q_UNUSED(widget) | |
99 | Q_UNUSED(option) |
|
100 | Q_UNUSED(option) | |
100 |
|
101 | |||
101 | painter->save(); |
|
102 | painter->save(); | |
102 | QPen pen; |
|
103 | painter->setPen(m_linePen); | |
103 | pen.setCosmetic(false); |
|
104 | painter->setBrush(m_brush); | |
104 | pen.setWidth(4); |
|
|||
105 | pen.setColor(qRgb(200,0,250)); |
|
|||
106 | painter->setPen(pen); |
|
|||
107 | //painter->setBrush(m_brush); |
|
|||
108 | painter->setClipRect(m_clipRect); |
|
105 | painter->setClipRect(m_clipRect); | |
109 | painter->drawPath(m_path); |
|
106 | painter->drawPath(m_path); | |
110 | if(m_pointsVisible){ |
|
107 | if(m_pointsVisible){ | |
111 | painter->setPen(m_pointPen); |
|
108 | painter->setPen(m_pointPen); | |
112 | painter->drawPoints(m_upper->points()); |
|
109 | painter->drawPoints(m_upper->points()); | |
113 | if(m_lower) painter->drawPoints(m_lower->points()); |
|
110 | if(m_lower) painter->drawPoints(m_lower->points()); | |
114 | } |
|
111 | } | |
115 | painter->restore(); |
|
112 | painter->restore(); | |
116 | } |
|
113 | } | |
117 |
|
114 | |||
118 | void AreaChartItem::mousePressEvent( QGraphicsSceneMouseEvent * event ) |
|
115 | void AreaChartItem::mousePressEvent( QGraphicsSceneMouseEvent * event ) | |
119 | { |
|
116 | { | |
120 | emit clicked(m_upper->calculateDomainPoint(event->pos())); |
|
117 | emit clicked(m_upper->calculateDomainPoint(event->pos())); | |
121 | } |
|
118 | } | |
122 |
|
119 | |||
123 | #include "moc_areachartitem_p.cpp" |
|
120 | #include "moc_areachartitem_p.cpp" | |
124 |
|
121 | |||
125 | QTCOMMERCIALCHART_END_NAMESPACE |
|
122 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,75 +1,76 | |||||
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 ChartItem |
|
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 |
|
58 | AreaBoundItem(AreaChartItem* item,QLineSeries* lineSeries):LineChartItem(lineSeries,0), | |
59 |
m_item(item){ |
|
59 | m_item(item){ | |
|
60 | }; | |||
60 |
|
61 | |||
61 | ~AreaBoundItem(){}; |
|
62 | ~AreaBoundItem(){}; | |
62 |
|
63 | |||
63 | void setLayout(QVector<QPointF>& points){ |
|
64 | void setLayout(QVector<QPointF>& points){ | |
64 | LineChartItem::setLayout(points); |
|
65 | LineChartItem::setLayout(points); | |
65 | m_item->updatePath(); |
|
66 | m_item->updatePath(); | |
66 | } |
|
67 | } | |
67 |
|
68 | |||
68 | private: |
|
69 | private: | |
69 | AreaChartItem* m_item; |
|
70 | AreaChartItem* m_item; | |
70 |
|
71 | |||
71 | }; |
|
72 | }; | |
72 |
|
73 | |||
73 | QTCOMMERCIALCHART_END_NAMESPACE |
|
74 | QTCOMMERCIALCHART_END_NAMESPACE | |
74 |
|
75 | |||
75 | #endif |
|
76 | #endif |
@@ -1,19 +1,19 | |||||
1 | #ifndef CHARTITEM_H_ |
|
1 | #ifndef CHARTITEM_H_ | |
2 | #define CHARTITEM_H_ |
|
2 | #define CHARTITEM_H_ | |
3 |
|
3 | |||
4 | #include "chart_p.h" |
|
4 | #include "chart_p.h" | |
5 | #include "chartpresenter_p.h" |
|
5 | #include "chartpresenter_p.h" | |
6 | #include <QGraphicsItem> |
|
6 | #include <QGraphicsItem> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class ChartItem : public QGraphicsItem, public Chart |
|
10 | class ChartItem : public QGraphicsItem, public Chart | |
11 | { |
|
11 | { | |
12 | enum ChartItemTypes{ AXIS_ITEM = UserType+1, XYLINE_ITEM}; |
|
12 | enum ChartItemTypes{ AXIS_ITEM = UserType+1, XYLINE_ITEM}; | |
13 | public: |
|
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 | QTCOMMERCIALCHART_END_NAMESPACE |
|
17 | QTCOMMERCIALCHART_END_NAMESPACE | |
18 |
|
18 | |||
19 | #endif /* CHARTITEM_H_ */ |
|
19 | #endif /* CHARTITEM_H_ */ |
General Comments 0
You need to be logged in to leave comments.
Login now