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 CHARTPRESENTER_H |
14 | #define CHARTPRESENTER_H |
15 | |
16 | #include <QtCharts/QChartGlobal> |
17 | #include <QtCharts/QChart> //because of QChart::ChartThemeId |
18 | #include <QtCharts/private/qchartglobal_p.h> |
19 | #if !defined(QT_NO_OPENGL) |
20 | # include <private/glwidget_p.h> |
21 | #endif |
22 | #include <QtCore/QRectF> |
23 | #include <QtCore/QMargins> |
24 | #include <QtCore/QLocale> |
25 | #include <QtCore/QPointer> |
26 | #include <QtCore/QEasingCurve> |
27 | |
28 | QT_BEGIN_NAMESPACE |
29 | |
30 | class ChartItem; |
31 | class AxisItem; |
32 | class QAbstractSeries; |
33 | class ChartDataSet; |
34 | class AbstractDomain; |
35 | class ChartAxisElement; |
36 | class ChartAnimator; |
37 | class ChartBackground; |
38 | class ChartTitle; |
39 | class ChartAnimation; |
40 | class AbstractChartLayout; |
41 | |
42 | class Q_CHARTS_PRIVATE_EXPORT ChartPresenter: public QObject |
43 | { |
44 | Q_OBJECT |
45 | public: |
46 | enum ZValues { |
47 | BackgroundZValue = -1, |
48 | PlotAreaZValue, |
49 | ShadesZValue, |
50 | GridZValue, |
51 | AxisZValue, |
52 | SeriesZValue, |
53 | LineChartZValue = SeriesZValue, |
54 | SplineChartZValue = SeriesZValue, |
55 | BarSeriesZValue = SeriesZValue, |
56 | ScatterSeriesZValue = SeriesZValue, |
57 | PieSeriesZValue = SeriesZValue, |
58 | BoxPlotSeriesZValue = SeriesZValue, |
59 | CandlestickSeriesZValue = SeriesZValue, |
60 | LegendZValue, |
61 | TopMostZValue |
62 | }; |
63 | |
64 | enum State { |
65 | ShowState, |
66 | ScrollUpState, |
67 | ScrollDownState, |
68 | ScrollLeftState, |
69 | ScrollRightState, |
70 | ZoomInState, |
71 | ZoomOutState |
72 | }; |
73 | |
74 | ChartPresenter(QChart *chart, QChart::ChartType type); |
75 | virtual ~ChartPresenter(); |
76 | |
77 | bool isFixedGeometry() const { return !m_fixedRect.isNull(); } |
78 | void setFixedGeometry(const QRectF &rect); |
79 | void setGeometry(QRectF rect); |
80 | QRectF geometry() const; |
81 | void updateGeometry(const QRectF &rect); |
82 | |
83 | QGraphicsItem *rootItem(){ return m_chart; } |
84 | ChartBackground *backgroundElement(); |
85 | QAbstractGraphicsShapeItem *plotAreaElement(); |
86 | ChartTitle *titleElement(); |
87 | QList<ChartAxisElement *> axisItems() const; |
88 | QList<ChartItem *> chartItems() const; |
89 | |
90 | QLegend *legend(); |
91 | |
92 | void setBackgroundBrush(const QBrush &brush); |
93 | QBrush backgroundBrush() const; |
94 | |
95 | void setBackgroundPen(const QPen &pen); |
96 | QPen backgroundPen() const; |
97 | |
98 | void setBackgroundRoundness(qreal diameter); |
99 | qreal backgroundRoundness() const; |
100 | |
101 | void setPlotAreaBackgroundBrush(const QBrush &brush); |
102 | QBrush plotAreaBackgroundBrush() const; |
103 | |
104 | void setPlotAreaBackgroundPen(const QPen &pen); |
105 | QPen plotAreaBackgroundPen() const; |
106 | |
107 | void setTitle(const QString &title); |
108 | QString title() const; |
109 | |
110 | void setTitleFont(const QFont &font); |
111 | QFont titleFont() const; |
112 | |
113 | void setTitleBrush(const QBrush &brush); |
114 | QBrush titleBrush() const; |
115 | |
116 | void setBackgroundVisible(bool visible); |
117 | bool isBackgroundVisible() const; |
118 | |
119 | void setPlotAreaBackgroundVisible(bool visible); |
120 | bool isPlotAreaBackgroundVisible() const; |
121 | |
122 | void setBackgroundDropShadowEnabled(bool enabled); |
123 | bool isBackgroundDropShadowEnabled() const; |
124 | |
125 | void setLocalizeNumbers(bool localize); |
126 | inline bool localizeNumbers() const { return m_localizeNumbers; } |
127 | void setLocale(const QLocale &locale); |
128 | inline const QLocale &locale() const { return m_locale; } |
129 | |
130 | void setVisible(bool visible); |
131 | |
132 | void setAnimationOptions(QChart::AnimationOptions options); |
133 | QChart::AnimationOptions animationOptions() const; |
134 | void setAnimationDuration(int msecs); |
135 | int animationDuration() const { return m_animationDuration; } |
136 | void setAnimationEasingCurve(const QEasingCurve &curve); |
137 | QEasingCurve animationEasingCurve() const { return m_animationCurve; } |
138 | |
139 | void startAnimation(ChartAnimation *animation); |
140 | |
141 | void setState(State state,QPointF point); |
142 | State state() const { return m_state; } |
143 | QPointF statePoint() const { return m_statePoint; } |
144 | AbstractChartLayout *layout(); |
145 | |
146 | QChart::ChartType chartType() const { return m_chart->chartType(); } |
147 | QChart *chart() { return m_chart; } |
148 | |
149 | static QRectF textBoundingRect(const QFont &font, const QString &text, qreal angle = 0.0); |
150 | static QString truncatedText(const QFont &font, const QString &text, qreal angle, |
151 | qreal maxWidth, qreal maxHeight, QRectF &boundingRect); |
152 | inline static qreal textMargin() { return qreal(0.5); } |
153 | |
154 | QString numberToString(double value, char f = 'g', int prec = 6); |
155 | QString numberToString(int value); |
156 | |
157 | void updateGLWidget(); |
158 | void glSetUseWidget(bool enable) { m_glUseWidget = enable; } |
159 | |
160 | private: |
161 | void createBackgroundItem(); |
162 | void createPlotAreaBackgroundItem(); |
163 | void createTitleItem(); |
164 | |
165 | public Q_SLOTS: |
166 | void handleSeriesAdded(QAbstractSeries *series); |
167 | void handleSeriesRemoved(QAbstractSeries *series); |
168 | void handleAxisAdded(QAbstractAxis *axis); |
169 | void handleAxisRemoved(QAbstractAxis *axis); |
170 | |
171 | Q_SIGNALS: |
172 | void plotAreaChanged(const QRectF &plotArea); |
173 | |
174 | private: |
175 | QChart *m_chart; |
176 | QList<ChartItem *> m_chartItems; |
177 | QList<ChartAxisElement *> m_axisItems; |
178 | QList<QAbstractSeries *> m_series; |
179 | QList<QAbstractAxis *> m_axes; |
180 | QChart::AnimationOptions m_options; |
181 | int m_animationDuration; |
182 | QEasingCurve m_animationCurve; |
183 | State m_state; |
184 | QPointF m_statePoint; |
185 | AbstractChartLayout *m_layout; |
186 | ChartBackground *m_background; |
187 | QAbstractGraphicsShapeItem *m_plotAreaBackground; |
188 | ChartTitle *m_title; |
189 | QRectF m_rect; |
190 | bool m_localizeNumbers; |
191 | QLocale m_locale; |
192 | #ifndef QT_NO_OPENGL |
193 | QPointer<GLWidget> m_glWidget; |
194 | #endif |
195 | bool m_glUseWidget; |
196 | QRectF m_fixedRect; |
197 | }; |
198 | |
199 | QT_END_NAMESPACE |
200 | |
201 | #endif /* CHARTPRESENTER_H */ |
202 | |