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