1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QCHART_H
5#define QCHART_H
6
7#include <QtCharts/QAbstractSeries>
8#include <QtCharts/QLegend>
9#include <QtWidgets/QGraphicsWidget>
10#include <QtCore/QMargins>
11
12QT_BEGIN_NAMESPACE
13class QGraphicsSceneResizeEvent;
14QT_END_NAMESPACE
15
16QT_BEGIN_NAMESPACE
17
18class QAbstractSeries;
19class QAbstractAxis;
20class QLegend;
21class QChartPrivate;
22class QBoxPlotSeries;
23
24class Q_CHARTS_EXPORT QChart : public QGraphicsWidget
25{
26 Q_OBJECT
27 Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme)
28 Q_PROPERTY(QString title READ title WRITE setTitle)
29 Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible)
30 Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled)
31 Q_PROPERTY(qreal backgroundRoundness READ backgroundRoundness WRITE setBackgroundRoundness)
32 Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions)
33 Q_PROPERTY(int animationDuration READ animationDuration WRITE setAnimationDuration)
34 Q_PROPERTY(QEasingCurve animationEasingCurve READ animationEasingCurve WRITE setAnimationEasingCurve)
35 Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
36 Q_PROPERTY(QChart::ChartType chartType READ chartType)
37 Q_PROPERTY(bool plotAreaBackgroundVisible READ isPlotAreaBackgroundVisible WRITE setPlotAreaBackgroundVisible)
38 Q_PROPERTY(bool localizeNumbers READ localizeNumbers WRITE setLocalizeNumbers)
39 Q_PROPERTY(QLocale locale READ locale WRITE setLocale)
40 Q_PROPERTY(QRectF plotArea READ plotArea WRITE setPlotArea NOTIFY plotAreaChanged)
41 Q_ENUMS(ChartTheme)
42 Q_ENUMS(AnimationOption)
43 Q_ENUMS(ChartType)
44
45public:
46 enum ChartType {
47 ChartTypeUndefined = 0,
48 ChartTypeCartesian,
49 ChartTypePolar
50 };
51
52 enum ChartTheme {
53 ChartThemeLight = 0,
54 ChartThemeBlueCerulean,
55 ChartThemeDark,
56 ChartThemeBrownSand,
57 ChartThemeBlueNcs,
58 ChartThemeHighContrast,
59 ChartThemeBlueIcy,
60 ChartThemeQt
61 };
62
63 enum AnimationOption {
64 NoAnimation = 0x0,
65 GridAxisAnimations = 0x1,
66 SeriesAnimations = 0x2,
67 AllAnimations = 0x3
68 };
69
70 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
71
72public:
73 explicit QChart(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = Qt::WindowFlags());
74 ~QChart();
75
76 void addSeries(QAbstractSeries *series);
77 void removeSeries(QAbstractSeries *series);
78 void removeAllSeries();
79 QList<QAbstractSeries *> series() const;
80
81 Q_DECL_DEPRECATED void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = nullptr);
82 Q_DECL_DEPRECATED void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = nullptr);
83 Q_DECL_DEPRECATED QAbstractAxis *axisX(QAbstractSeries *series = nullptr) const;
84 Q_DECL_DEPRECATED QAbstractAxis *axisY(QAbstractSeries *series = nullptr) const;
85
86 void addAxis(QAbstractAxis *axis, Qt::Alignment alignment);
87 void removeAxis(QAbstractAxis *axis);
88 QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = nullptr) const;
89
90 void createDefaultAxes();
91
92 void setTheme(QChart::ChartTheme theme);
93 QChart::ChartTheme theme() const;
94
95 void setTitle(const QString &title);
96 QString title() const;
97 void setTitleFont(const QFont &font);
98 QFont titleFont() const;
99 void setTitleBrush(const QBrush &brush);
100 QBrush titleBrush() const;
101
102 void setBackgroundBrush(const QBrush &brush);
103 QBrush backgroundBrush() const;
104 void setBackgroundPen(const QPen &pen);
105 QPen backgroundPen() const;
106 void setBackgroundVisible(bool visible = true);
107 bool isBackgroundVisible() const;
108
109 void setDropShadowEnabled(bool enabled = true);
110 bool isDropShadowEnabled() const;
111 void setBackgroundRoundness(qreal diameter);
112 qreal backgroundRoundness() const;
113
114 void setAnimationOptions(AnimationOptions options);
115 AnimationOptions animationOptions() const;
116 void setAnimationDuration(int msecs);
117 int animationDuration() const;
118 void setAnimationEasingCurve(const QEasingCurve &curve);
119 QEasingCurve animationEasingCurve() const;
120
121 void zoomIn();
122 void zoomOut();
123
124 void zoomIn(const QRectF &rect);
125 void zoom(qreal factor);
126 void zoomReset();
127 bool isZoomed();
128
129 void scroll(qreal dx, qreal dy);
130
131 QLegend *legend() const;
132
133 void setMargins(const QMargins &margins);
134 QMargins margins() const;
135
136 QRectF plotArea() const;
137 void setPlotArea(const QRectF &rect);
138 void setPlotAreaBackgroundBrush(const QBrush &brush);
139 QBrush plotAreaBackgroundBrush() const;
140 void setPlotAreaBackgroundPen(const QPen &pen);
141 QPen plotAreaBackgroundPen() const;
142 void setPlotAreaBackgroundVisible(bool visible = true);
143 bool isPlotAreaBackgroundVisible() const;
144 void setLocalizeNumbers(bool localize);
145 bool localizeNumbers() const;
146 void setLocale(const QLocale &locale);
147 QLocale locale() const;
148
149 QPointF mapToValue(const QPointF &position, QAbstractSeries *series = nullptr);
150 QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = nullptr);
151
152 ChartType chartType() const;
153
154Q_SIGNALS:
155 void plotAreaChanged(const QRectF &plotArea);
156
157protected:
158 explicit QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags);
159 QScopedPointer<QChartPrivate> d_ptr;
160 friend class QLegend;
161 friend class DeclarativeChart;
162 friend class ChartDataSet;
163 friend class ChartPresenter;
164 friend class ChartThemeManager;
165 friend class QAbstractSeries;
166 friend class QBoxPlotSeriesPrivate;
167 friend class QCandlestickSeriesPrivate;
168 friend class AbstractBarChartItem;
169
170private:
171 Q_DISABLE_COPY(QChart)
172};
173
174QT_END_NAMESPACE
175
176#ifndef Q_QDOC
177Q_DECLARE_OPERATORS_FOR_FLAGS(QChart::AnimationOptions)
178#endif
179
180#endif // QCHART_H
181

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