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

source code of qtcharts/src/charts/areachart/areachartitem_p.h