@@ -1,129 +1,132 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2015 The Qt Company Ltd |
|
3 | ** Copyright (C) 2015 The Qt Company Ltd | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to The Qt Company, please use contact form at http://qt.io |
|
5 | ** For any questions to The Qt Company, please use contact form at http://qt.io | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Charts module. |
|
7 | ** This file is part of the Qt Charts module. | |
8 | ** |
|
8 | ** | |
9 | ** Licensees holding valid commercial license for Qt may use this file in |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
10 | ** accordance with the Qt License Agreement provided with the Software |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
11 | ** or, alternatively, in accordance with the terms contained in a written |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
12 | ** agreement between you and The Qt Company. |
|
12 | ** agreement between you and The Qt Company. | |
13 | ** |
|
13 | ** | |
14 | ** If you have questions regarding the use of this file, please use |
|
14 | ** If you have questions regarding the use of this file, please use | |
15 | ** contact form at http://qt.io |
|
15 | ** contact form at http://qt.io | |
16 | ** |
|
16 | ** | |
17 | ****************************************************************************/ |
|
17 | ****************************************************************************/ | |
18 |
|
18 | |||
19 | // W A R N I N G |
|
19 | // W A R N I N G | |
20 | // ------------- |
|
20 | // ------------- | |
21 | // |
|
21 | // | |
22 | // This file is not part of the Qt Enterprise Chart API. It exists purely as an |
|
22 | // This file is not part of the Qt Enterprise Chart API. It exists purely as an | |
23 | // implementation detail. This header file may change from version to |
|
23 | // implementation detail. This header file may change from version to | |
24 | // version without notice, or even be removed. |
|
24 | // version without notice, or even be removed. | |
25 | // |
|
25 | // | |
26 | // We mean it. |
|
26 | // We mean it. | |
27 |
|
27 | |||
28 | #ifndef AREACHARTITEM_H |
|
28 | #ifndef AREACHARTITEM_H | |
29 | #define AREACHARTITEM_H |
|
29 | #define AREACHARTITEM_H | |
30 |
|
30 | |||
31 | #include <QtCharts/QChartGlobal> |
|
31 | #include <QtCharts/QChartGlobal> | |
32 | #include <private/linechartitem_p.h> |
|
32 | #include <private/linechartitem_p.h> | |
33 | #include <QtCharts/QAreaSeries> |
|
33 | #include <QtCharts/QAreaSeries> | |
34 | #include <QtGui/QPen> |
|
34 | #include <QtGui/QPen> | |
35 |
|
35 | |||
36 | QT_CHARTS_BEGIN_NAMESPACE |
|
36 | QT_CHARTS_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 | class AreaChartItem; |
|
38 | class AreaChartItem; | |
39 |
|
39 | |||
40 | class AreaChartItem : public ChartItem |
|
40 | class AreaChartItem : public ChartItem | |
41 | { |
|
41 | { | |
42 | Q_OBJECT |
|
42 | Q_OBJECT | |
43 | public: |
|
43 | public: | |
44 | AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item = 0); |
|
44 | AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item = 0); | |
45 | ~AreaChartItem(); |
|
45 | ~AreaChartItem(); | |
46 |
|
46 | |||
47 | //from QGraphicsItem |
|
47 | //from QGraphicsItem | |
48 | QRectF boundingRect() const; |
|
48 | QRectF boundingRect() const; | |
49 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
49 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
50 | QPainterPath shape() const; |
|
50 | QPainterPath shape() const; | |
51 |
|
51 | |||
52 | LineChartItem *upperLineItem() const { return m_upper; } |
|
52 | LineChartItem *upperLineItem() const { return m_upper; } | |
53 | LineChartItem *lowerLineItem() const { return m_lower; } |
|
53 | LineChartItem *lowerLineItem() const { return m_lower; } | |
54 |
|
54 | |||
55 | void updatePath(); |
|
55 | void updatePath(); | |
56 |
|
56 | |||
57 | void setPresenter(ChartPresenter *presenter); |
|
57 | void setPresenter(ChartPresenter *presenter); | |
58 | QAreaSeries *series() const { return m_series; } |
|
58 | QAreaSeries *series() const { return m_series; } | |
59 |
|
59 | |||
60 | protected: |
|
60 | protected: | |
61 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
61 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
62 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); |
|
62 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); | |
63 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); |
|
63 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); | |
64 | void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); |
|
64 | void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); | |
65 | void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); |
|
65 | void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); | |
66 |
|
66 | |||
67 | Q_SIGNALS: |
|
67 | Q_SIGNALS: | |
68 | void clicked(const QPointF &point); |
|
68 | void clicked(const QPointF &point); | |
69 | void hovered(const QPointF &point, bool state); |
|
69 | void hovered(const QPointF &point, bool state); | |
70 | void pressed(const QPointF &point); |
|
70 | void pressed(const QPointF &point); | |
71 | void released(const QPointF &point); |
|
71 | void released(const QPointF &point); | |
72 | void doubleClicked(const QPointF &point); |
|
72 | void doubleClicked(const QPointF &point); | |
73 |
|
73 | |||
74 | public Q_SLOTS: |
|
74 | public Q_SLOTS: | |
75 | void handleUpdated(); |
|
75 | void handleUpdated(); | |
76 | void handleDomainUpdated(); |
|
76 | void handleDomainUpdated(); | |
77 |
|
77 | |||
78 | private: |
|
78 | private: | |
79 | QAreaSeries *m_series; |
|
79 | QAreaSeries *m_series; | |
80 | LineChartItem *m_upper; |
|
80 | LineChartItem *m_upper; | |
81 | LineChartItem *m_lower; |
|
81 | LineChartItem *m_lower; | |
82 | QPainterPath m_path; |
|
82 | QPainterPath m_path; | |
83 | QRectF m_rect; |
|
83 | QRectF m_rect; | |
84 | QPen m_linePen; |
|
84 | QPen m_linePen; | |
85 | QPen m_pointPen; |
|
85 | QPen m_pointPen; | |
86 | QBrush m_brush; |
|
86 | QBrush m_brush; | |
87 | bool m_pointsVisible; |
|
87 | bool m_pointsVisible; | |
88 |
|
88 | |||
89 | bool m_pointLabelsVisible; |
|
89 | bool m_pointLabelsVisible; | |
90 | QString m_pointLabelsFormat; |
|
90 | QString m_pointLabelsFormat; | |
91 | QFont m_pointLabelsFont; |
|
91 | QFont m_pointLabelsFont; | |
92 | QColor m_pointLabelsColor; |
|
92 | QColor m_pointLabelsColor; | |
93 |
|
93 | |||
94 | QPointF m_lastMousePos; |
|
94 | QPointF m_lastMousePos; | |
95 | bool m_mousePressed; |
|
95 | bool m_mousePressed; | |
96 |
|
96 | |||
97 | }; |
|
97 | }; | |
98 |
|
98 | |||
99 | class AreaBoundItem : public LineChartItem |
|
99 | class AreaBoundItem : public LineChartItem | |
100 | { |
|
100 | { | |
101 | public: |
|
101 | public: | |
102 | AreaBoundItem(AreaChartItem *area, QLineSeries *lineSeries,QGraphicsItem* item = 0) |
|
102 | AreaBoundItem(AreaChartItem *area, QLineSeries *lineSeries,QGraphicsItem* item = 0) | |
103 | : LineChartItem(lineSeries, item), m_item(area) |
|
103 | : LineChartItem(lineSeries, item), m_item(area) | |
104 | { |
|
104 | { | |
105 | // We do not actually want to draw anything from LineChartItem. |
|
105 | // We do not actually want to draw anything from LineChartItem. | |
106 | // Drawing is done in AreaChartItem only. |
|
106 | // Drawing is done in AreaChartItem only. | |
107 | setVisible(false); |
|
107 | setVisible(false); | |
108 | } |
|
108 | } | |
109 | ~AreaBoundItem() {} |
|
109 | ~AreaBoundItem() {} | |
110 |
|
110 | |||
111 | void updateGeometry() |
|
111 | void updateGeometry() | |
112 | { |
|
112 | { | |
|
113 | // Make sure the series is in a chart before trying to update | |||
|
114 | if (m_item->series()->chart()) { | |||
113 | // Turn off points drawing from component line chart item, as that |
|
115 | // Turn off points drawing from component line chart item, as that | |
114 | // messes up the fill for area series. |
|
116 | // messes up the fill for area series. | |
115 | suppressPoints(); |
|
117 | suppressPoints(); | |
116 | // Component lineseries are not necessarily themselves on the chart, |
|
118 | // Component lineseries are not necessarily themselves on the chart, | |
117 | // so get the chart type for them from area chart. |
|
119 | // so get the chart type for them from area chart. | |
118 | forceChartType(m_item->series()->chart()->chartType()); |
|
120 | forceChartType(m_item->series()->chart()->chartType()); | |
119 | LineChartItem::updateGeometry(); |
|
121 | LineChartItem::updateGeometry(); | |
120 | m_item->updatePath(); |
|
122 | m_item->updatePath(); | |
121 | } |
|
123 | } | |
|
124 | } | |||
122 |
|
125 | |||
123 | private: |
|
126 | private: | |
124 | AreaChartItem *m_item; |
|
127 | AreaChartItem *m_item; | |
125 | }; |
|
128 | }; | |
126 |
|
129 | |||
127 | QT_CHARTS_END_NAMESPACE |
|
130 | QT_CHARTS_END_NAMESPACE | |
128 |
|
131 | |||
129 | #endif |
|
132 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now