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