1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Charts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30#ifndef QCHART_H
31#define QCHART_H
32
33#include <QtCharts/QAbstractSeries>
34#include <QtCharts/QLegend>
35#include <QtWidgets/QGraphicsWidget>
36#include <QtCore/QMargins>
37
38QT_BEGIN_NAMESPACE
39class QGraphicsSceneResizeEvent;
40QT_END_NAMESPACE
41
42QT_CHARTS_BEGIN_NAMESPACE
43
44class QAbstractSeries;
45class QAbstractAxis;
46class QLegend;
47class QChartPrivate;
48class QBoxPlotSeries;
49
50class Q_CHARTS_EXPORT QChart : public QGraphicsWidget
51{
52 Q_OBJECT
53 Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme)
54 Q_PROPERTY(QString title READ title WRITE setTitle)
55 Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible)
56 Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled)
57 Q_PROPERTY(qreal backgroundRoundness READ backgroundRoundness WRITE setBackgroundRoundness)
58 Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions)
59 Q_PROPERTY(int animationDuration READ animationDuration WRITE setAnimationDuration)
60 Q_PROPERTY(QEasingCurve animationEasingCurve READ animationEasingCurve WRITE setAnimationEasingCurve)
61 Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
62 Q_PROPERTY(QChart::ChartType chartType READ chartType)
63 Q_PROPERTY(bool plotAreaBackgroundVisible READ isPlotAreaBackgroundVisible WRITE setPlotAreaBackgroundVisible)
64 Q_PROPERTY(bool localizeNumbers READ localizeNumbers WRITE setLocalizeNumbers)
65 Q_PROPERTY(QLocale locale READ locale WRITE setLocale)
66 Q_PROPERTY(QRectF plotArea READ plotArea WRITE setPlotArea NOTIFY plotAreaChanged)
67 Q_ENUMS(ChartTheme)
68 Q_ENUMS(AnimationOption)
69 Q_ENUMS(ChartType)
70
71public:
72 enum ChartType {
73 ChartTypeUndefined = 0,
74 ChartTypeCartesian,
75 ChartTypePolar
76 };
77
78 enum ChartTheme {
79 ChartThemeLight = 0,
80 ChartThemeBlueCerulean,
81 ChartThemeDark,
82 ChartThemeBrownSand,
83 ChartThemeBlueNcs,
84 ChartThemeHighContrast,
85 ChartThemeBlueIcy,
86 ChartThemeQt
87 };
88
89 enum AnimationOption {
90 NoAnimation = 0x0,
91 GridAxisAnimations = 0x1,
92 SeriesAnimations = 0x2,
93 AllAnimations = 0x3
94 };
95
96 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
97
98public:
99 explicit QChart(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = Qt::WindowFlags());
100 ~QChart();
101
102 void addSeries(QAbstractSeries *series);
103 void removeSeries(QAbstractSeries *series);
104 void removeAllSeries();
105 QList<QAbstractSeries *> series() const;
106
107 Q_DECL_DEPRECATED void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = nullptr);
108 Q_DECL_DEPRECATED void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = nullptr);
109 Q_DECL_DEPRECATED QAbstractAxis *axisX(QAbstractSeries *series = nullptr) const;
110 Q_DECL_DEPRECATED QAbstractAxis *axisY(QAbstractSeries *series = nullptr) const;
111
112 void addAxis(QAbstractAxis *axis, Qt::Alignment alignment);
113 void removeAxis(QAbstractAxis *axis);
114 QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = nullptr) const;
115
116 void createDefaultAxes();
117
118 void setTheme(QChart::ChartTheme theme);
119 QChart::ChartTheme theme() const;
120
121 void setTitle(const QString &title);
122 QString title() const;
123 void setTitleFont(const QFont &font);
124 QFont titleFont() const;
125 void setTitleBrush(const QBrush &brush);
126 QBrush titleBrush() const;
127
128 void setBackgroundBrush(const QBrush &brush);
129 QBrush backgroundBrush() const;
130 void setBackgroundPen(const QPen &pen);
131 QPen backgroundPen() const;
132 void setBackgroundVisible(bool visible = true);
133 bool isBackgroundVisible() const;
134
135 void setDropShadowEnabled(bool enabled = true);
136 bool isDropShadowEnabled() const;
137 void setBackgroundRoundness(qreal diameter);
138 qreal backgroundRoundness() const;
139
140 void setAnimationOptions(AnimationOptions options);
141 AnimationOptions animationOptions() const;
142 void setAnimationDuration(int msecs);
143 int animationDuration() const;
144 void setAnimationEasingCurve(const QEasingCurve &curve);
145 QEasingCurve animationEasingCurve() const;
146
147 void zoomIn();
148 void zoomOut();
149
150 void zoomIn(const QRectF &rect);
151 void zoom(qreal factor);
152 void zoomReset();
153 bool isZoomed();
154
155 void scroll(qreal dx, qreal dy);
156
157 QLegend *legend() const;
158
159 void setMargins(const QMargins &margins);
160 QMargins margins() const;
161
162 QRectF plotArea() const;
163 void setPlotArea(const QRectF &rect);
164 void setPlotAreaBackgroundBrush(const QBrush &brush);
165 QBrush plotAreaBackgroundBrush() const;
166 void setPlotAreaBackgroundPen(const QPen &pen);
167 QPen plotAreaBackgroundPen() const;
168 void setPlotAreaBackgroundVisible(bool visible = true);
169 bool isPlotAreaBackgroundVisible() const;
170 void setLocalizeNumbers(bool localize);
171 bool localizeNumbers() const;
172 void setLocale(const QLocale &locale);
173 QLocale locale() const;
174
175 QPointF mapToValue(const QPointF &position, QAbstractSeries *series = nullptr);
176 QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = nullptr);
177
178 ChartType chartType() const;
179
180Q_SIGNALS:
181 void plotAreaChanged(const QRectF &plotArea);
182
183protected:
184 explicit QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags);
185 QScopedPointer<QChartPrivate> d_ptr;
186 friend class QLegend;
187 friend class DeclarativeChart;
188 friend class ChartDataSet;
189 friend class ChartPresenter;
190 friend class ChartThemeManager;
191 friend class QAbstractSeries;
192 friend class QBoxPlotSeriesPrivate;
193 friend class QCandlestickSeriesPrivate;
194 friend class AbstractBarChartItem;
195
196private:
197 Q_DISABLE_COPY(QChart)
198};
199
200QT_CHARTS_END_NAMESPACE
201
202#ifndef Q_CLANG_QDOC
203Q_DECLARE_OPERATORS_FOR_FLAGS(QT_CHARTS_NAMESPACE::QChart::AnimationOptions)
204#endif
205
206#endif // QCHART_H
207

source code of qtcharts/src/charts/qchart.h