@@ -0,0 +1,8 | |||
|
1 | Qt Charts 2.1.1 | |
|
2 | ||
|
3 | Fixed issues | |
|
4 | ------------ | |
|
5 | - Fixed crash with empty BarSet values | |
|
6 | - Fixed model resetting with model mapper | |
|
7 | - Fixed crash when axis range is infinite | |
|
8 | - Fixed clearing the chart title |
@@ -1,123 +1,123 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QAREASERIES_H |
|
31 | 31 | #define QAREASERIES_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtCharts/QAbstractSeries> |
|
35 | 35 | #include <QtGui/QPen> |
|
36 | 36 | #include <QtGui/QBrush> |
|
37 | 37 | |
|
38 | 38 | QT_CHARTS_BEGIN_NAMESPACE |
|
39 | 39 | class QLineSeries; |
|
40 | 40 | class QAreaSeriesPrivate; |
|
41 | 41 | |
|
42 | 42 | class QT_CHARTS_EXPORT QAreaSeries : public QAbstractSeries |
|
43 | 43 | { |
|
44 | 44 | Q_OBJECT |
|
45 | 45 | Q_PROPERTY(QLineSeries *upperSeries READ upperSeries) |
|
46 | 46 | Q_PROPERTY(QLineSeries *lowerSeries READ lowerSeries) |
|
47 | 47 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
48 | 48 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
|
49 | 49 | Q_PROPERTY(QString pointLabelsFormat READ pointLabelsFormat WRITE setPointLabelsFormat NOTIFY pointLabelsFormatChanged) |
|
50 | 50 | Q_PROPERTY(bool pointLabelsVisible READ pointLabelsVisible WRITE setPointLabelsVisible NOTIFY pointLabelsVisibilityChanged) |
|
51 | 51 | Q_PROPERTY(QFont pointLabelsFont READ pointLabelsFont WRITE setPointLabelsFont NOTIFY pointLabelsFontChanged) |
|
52 | 52 | Q_PROPERTY(QColor pointLabelsColor READ pointLabelsColor WRITE setPointLabelsColor NOTIFY pointLabelsColorChanged) |
|
53 | 53 | Q_PROPERTY(bool pointLabelsClipping READ pointLabelsClipping WRITE setPointLabelsClipping NOTIFY pointLabelsClippingChanged) |
|
54 | 54 | |
|
55 | 55 | public: |
|
56 |
explicit QAreaSeries(QObject *parent = |
|
|
57 |
explicit QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries = |
|
|
56 | explicit QAreaSeries(QObject *parent = Q_NULLPTR); | |
|
57 | explicit QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries = Q_NULLPTR); | |
|
58 | 58 | ~QAreaSeries(); |
|
59 | 59 | |
|
60 | 60 | public: |
|
61 | 61 | QAbstractSeries::SeriesType type() const; |
|
62 | 62 | |
|
63 | 63 | void setUpperSeries(QLineSeries *series); |
|
64 | 64 | QLineSeries *upperSeries() const; |
|
65 | 65 | void setLowerSeries(QLineSeries *series); |
|
66 | 66 | QLineSeries *lowerSeries() const; |
|
67 | 67 | |
|
68 | 68 | void setPen(const QPen &pen); |
|
69 | 69 | QPen pen() const; |
|
70 | 70 | |
|
71 | 71 | void setBrush(const QBrush &brush); |
|
72 | 72 | QBrush brush() const; |
|
73 | 73 | |
|
74 | 74 | void setColor(const QColor &color); |
|
75 | 75 | QColor color() const; |
|
76 | 76 | |
|
77 | 77 | void setBorderColor(const QColor &color); |
|
78 | 78 | QColor borderColor() const; |
|
79 | 79 | |
|
80 | 80 | void setPointsVisible(bool visible = true); |
|
81 | 81 | bool pointsVisible() const; |
|
82 | 82 | |
|
83 | 83 | void setPointLabelsFormat(const QString &format); |
|
84 | 84 | QString pointLabelsFormat() const; |
|
85 | 85 | |
|
86 | 86 | void setPointLabelsVisible(bool visible = true); |
|
87 | 87 | bool pointLabelsVisible() const; |
|
88 | 88 | |
|
89 | 89 | void setPointLabelsFont(const QFont &font); |
|
90 | 90 | QFont pointLabelsFont() const; |
|
91 | 91 | |
|
92 | 92 | void setPointLabelsColor(const QColor &color); |
|
93 | 93 | QColor pointLabelsColor() const; |
|
94 | 94 | |
|
95 | 95 | void setPointLabelsClipping(bool enabled = true); |
|
96 | 96 | bool pointLabelsClipping() const; |
|
97 | 97 | |
|
98 | 98 | Q_SIGNALS: |
|
99 | 99 | void clicked(const QPointF &point); |
|
100 | 100 | void hovered(const QPointF &point, bool state); |
|
101 | 101 | void pressed(const QPointF &point); |
|
102 | 102 | void released(const QPointF &point); |
|
103 | 103 | void doubleClicked(const QPointF &point); |
|
104 | 104 | void selected(); |
|
105 | 105 | void colorChanged(QColor color); |
|
106 | 106 | void borderColorChanged(QColor color); |
|
107 | 107 | void pointLabelsFormatChanged(const QString &format); |
|
108 | 108 | void pointLabelsVisibilityChanged(bool visible); |
|
109 | 109 | void pointLabelsFontChanged(const QFont &font); |
|
110 | 110 | void pointLabelsColorChanged(const QColor &color); |
|
111 | 111 | void pointLabelsClippingChanged(bool clipping); |
|
112 | 112 | |
|
113 | 113 | private: |
|
114 | 114 | Q_DECLARE_PRIVATE(QAreaSeries) |
|
115 | 115 | Q_DISABLE_COPY(QAreaSeries) |
|
116 | 116 | friend class AreaLegendMarker; |
|
117 | 117 | friend class AreaChartItem; |
|
118 | 118 | friend class QAreaLegendMarkerPrivate; |
|
119 | 119 | }; |
|
120 | 120 | |
|
121 | 121 | QT_CHARTS_END_NAMESPACE |
|
122 | 122 | |
|
123 | 123 | #endif // QAREASERIES_H |
@@ -1,90 +1,90 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QBARCATEGORYAXIS_H |
|
31 | 31 | #define QBARCATEGORYAXIS_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QAbstractAxis> |
|
34 | 34 | |
|
35 | 35 | QT_CHARTS_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | class QBarCategoryAxisPrivate; |
|
38 | 38 | |
|
39 | 39 | class QT_CHARTS_EXPORT QBarCategoryAxis : public QAbstractAxis |
|
40 | 40 | { |
|
41 | 41 | Q_OBJECT |
|
42 | 42 | Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged) |
|
43 | 43 | Q_PROPERTY(QString min READ min WRITE setMin NOTIFY minChanged) |
|
44 | 44 | Q_PROPERTY(QString max READ max WRITE setMax NOTIFY maxChanged) |
|
45 | 45 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
|
46 | 46 | |
|
47 | 47 | public: |
|
48 |
explicit QBarCategoryAxis(QObject *parent = |
|
|
48 | explicit QBarCategoryAxis(QObject *parent = Q_NULLPTR); | |
|
49 | 49 | ~QBarCategoryAxis(); |
|
50 | 50 | |
|
51 | 51 | protected: |
|
52 |
QBarCategoryAxis(QBarCategoryAxisPrivate &d, QObject *parent = |
|
|
52 | QBarCategoryAxis(QBarCategoryAxisPrivate &d, QObject *parent = Q_NULLPTR); | |
|
53 | 53 | |
|
54 | 54 | public: |
|
55 | 55 | AxisType type() const; |
|
56 | 56 | void append(const QStringList &categories); |
|
57 | 57 | void append(const QString &category); |
|
58 | 58 | void remove(const QString &category); |
|
59 | 59 | void insert(int index, const QString &category); |
|
60 | 60 | void replace(const QString &oldCategory, const QString &newCategory); |
|
61 | 61 | Q_INVOKABLE void clear(); |
|
62 | 62 | void setCategories(const QStringList &categories); |
|
63 | 63 | QStringList categories(); |
|
64 | 64 | int count() const; |
|
65 | 65 | QString at(int index) const; |
|
66 | 66 | |
|
67 | 67 | //range handling |
|
68 | 68 | void setMin(const QString &minCategory); |
|
69 | 69 | QString min() const; |
|
70 | 70 | void setMax(const QString &maxCategory); |
|
71 | 71 | QString max() const; |
|
72 | 72 | void setRange(const QString &minCategory, const QString &maxCategory); |
|
73 | 73 | |
|
74 | 74 | Q_SIGNALS: |
|
75 | 75 | void categoriesChanged(); |
|
76 | 76 | void minChanged(const QString &min); |
|
77 | 77 | void maxChanged(const QString &max); |
|
78 | 78 | void rangeChanged(const QString &min, const QString &max); |
|
79 | 79 | void countChanged(); |
|
80 | 80 | |
|
81 | 81 | private: |
|
82 | 82 | Q_DECLARE_PRIVATE(QBarCategoryAxis) |
|
83 | 83 | Q_DISABLE_COPY(QBarCategoryAxis) |
|
84 | 84 | friend class ChartBarCategoryAxisX; |
|
85 | 85 | friend class ChartBarCategoryAxisY; |
|
86 | 86 | }; |
|
87 | 87 | |
|
88 | 88 | QT_CHARTS_END_NAMESPACE |
|
89 | 89 | |
|
90 | 90 | #endif // QBARCATEGORYAXIS_H |
@@ -1,91 +1,91 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QCATEGORYAXIS_H |
|
31 | 31 | #define QCATEGORYAXIS_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QAbstractAxis> |
|
34 | 34 | #include <QtCharts/QValueAxis> |
|
35 | 35 | |
|
36 | 36 | QT_CHARTS_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | class QCategoryAxisPrivate; |
|
39 | 39 | |
|
40 | 40 | class QT_CHARTS_EXPORT QCategoryAxis : public QValueAxis |
|
41 | 41 | { |
|
42 | 42 | Q_OBJECT |
|
43 | 43 | Q_PROPERTY(qreal startValue READ startValue WRITE setStartValue) |
|
44 | 44 | Q_PROPERTY(int count READ count) |
|
45 | 45 | Q_PROPERTY(QStringList categoriesLabels READ categoriesLabels) |
|
46 | 46 | Q_PROPERTY(AxisLabelsPosition labelsPosition READ labelsPosition WRITE setLabelsPosition NOTIFY labelsPositionChanged) |
|
47 | 47 | Q_ENUMS(AxisLabelsPosition) |
|
48 | 48 | |
|
49 | 49 | public: |
|
50 | 50 | |
|
51 | 51 | enum AxisLabelsPosition { |
|
52 | 52 | AxisLabelsPositionCenter = 0x0, |
|
53 | 53 | AxisLabelsPositionOnValue = 0x1 |
|
54 | 54 | }; |
|
55 | 55 | |
|
56 |
explicit QCategoryAxis(QObject *parent = |
|
|
56 | explicit QCategoryAxis(QObject *parent = Q_NULLPTR); | |
|
57 | 57 | ~QCategoryAxis(); |
|
58 | 58 | |
|
59 | 59 | protected: |
|
60 |
QCategoryAxis(QCategoryAxisPrivate &d, QObject *parent = |
|
|
60 | QCategoryAxis(QCategoryAxisPrivate &d, QObject *parent = Q_NULLPTR); | |
|
61 | 61 | |
|
62 | 62 | public: |
|
63 | 63 | AxisType type() const; |
|
64 | 64 | |
|
65 | 65 | void append(const QString &label, qreal categoryEndValue); |
|
66 | 66 | void remove(const QString &label); |
|
67 | 67 | void replaceLabel(const QString &oldLabel, const QString &newLabel); |
|
68 | 68 | |
|
69 | 69 | qreal startValue(const QString &categoryLabel = QString()) const; |
|
70 | 70 | void setStartValue(qreal min); |
|
71 | 71 | |
|
72 | 72 | qreal endValue(const QString &categoryLabel) const; |
|
73 | 73 | |
|
74 | 74 | QStringList categoriesLabels(); |
|
75 | 75 | int count() const; |
|
76 | 76 | |
|
77 | 77 | QCategoryAxis::AxisLabelsPosition labelsPosition() const; |
|
78 | 78 | void setLabelsPosition(QCategoryAxis::AxisLabelsPosition position); |
|
79 | 79 | |
|
80 | 80 | Q_SIGNALS: |
|
81 | 81 | void categoriesChanged(); |
|
82 | 82 | void labelsPositionChanged(QCategoryAxis::AxisLabelsPosition position); |
|
83 | 83 | |
|
84 | 84 | private: |
|
85 | 85 | Q_DECLARE_PRIVATE(QCategoryAxis) |
|
86 | 86 | Q_DISABLE_COPY(QCategoryAxis) |
|
87 | 87 | }; |
|
88 | 88 | |
|
89 | 89 | QT_CHARTS_END_NAMESPACE |
|
90 | 90 | |
|
91 | 91 | #endif // QCATEGORYAXIS_H |
@@ -1,89 +1,89 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QDATETIMEAXIS_H |
|
31 | 31 | #define QDATETIMEAXIS_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QAbstractAxis> |
|
34 | 34 | |
|
35 | 35 | QT_BEGIN_NAMESPACE |
|
36 | 36 | class QDateTime; |
|
37 | 37 | QT_END_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | QT_CHARTS_BEGIN_NAMESPACE |
|
40 | 40 | |
|
41 | 41 | class QDateTimeAxisPrivate; |
|
42 | 42 | |
|
43 | 43 | class QT_CHARTS_EXPORT QDateTimeAxis : public QAbstractAxis |
|
44 | 44 | { |
|
45 | 45 | Q_OBJECT |
|
46 | 46 | Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount NOTIFY tickCountChanged) |
|
47 | 47 | Q_PROPERTY(QDateTime min READ min WRITE setMin NOTIFY minChanged) |
|
48 | 48 | Q_PROPERTY(QDateTime max READ max WRITE setMax NOTIFY maxChanged) |
|
49 | 49 | Q_PROPERTY(QString format READ format WRITE setFormat NOTIFY formatChanged) |
|
50 | 50 | |
|
51 | 51 | public: |
|
52 |
explicit QDateTimeAxis(QObject *parent = |
|
|
52 | explicit QDateTimeAxis(QObject *parent = Q_NULLPTR); | |
|
53 | 53 | ~QDateTimeAxis(); |
|
54 | 54 | |
|
55 | 55 | protected: |
|
56 |
QDateTimeAxis(QDateTimeAxisPrivate &d, QObject *parent = |
|
|
56 | QDateTimeAxis(QDateTimeAxisPrivate &d, QObject *parent = Q_NULLPTR); | |
|
57 | 57 | |
|
58 | 58 | public: |
|
59 | 59 | AxisType type() const; |
|
60 | 60 | |
|
61 | 61 | //range handling |
|
62 | 62 | void setMin(QDateTime min); |
|
63 | 63 | QDateTime min() const; |
|
64 | 64 | void setMax(QDateTime max); |
|
65 | 65 | QDateTime max() const; |
|
66 | 66 | void setRange(QDateTime min, QDateTime max); |
|
67 | 67 | |
|
68 | 68 | void setFormat(QString format); |
|
69 | 69 | QString format() const; |
|
70 | 70 | |
|
71 | 71 | //ticks handling |
|
72 | 72 | void setTickCount(int count); |
|
73 | 73 | int tickCount() const; |
|
74 | 74 | |
|
75 | 75 | Q_SIGNALS: |
|
76 | 76 | void minChanged(QDateTime min); |
|
77 | 77 | void maxChanged(QDateTime max); |
|
78 | 78 | void rangeChanged(QDateTime min, QDateTime max); |
|
79 | 79 | void formatChanged(QString format); |
|
80 | 80 | void tickCountChanged(int tick); |
|
81 | 81 | |
|
82 | 82 | private: |
|
83 | 83 | Q_DECLARE_PRIVATE(QDateTimeAxis) |
|
84 | 84 | Q_DISABLE_COPY(QDateTimeAxis) |
|
85 | 85 | }; |
|
86 | 86 | |
|
87 | 87 | QT_CHARTS_END_NAMESPACE |
|
88 | 88 | |
|
89 | 89 | #endif // QDATETIMEAXIS_H |
@@ -1,88 +1,88 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QLOGVALUEAXIS_H |
|
31 | 31 | #define QLOGVALUEAXIS_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QAbstractAxis> |
|
34 | 34 | |
|
35 | 35 | QT_BEGIN_NAMESPACE |
|
36 | 36 | class QDateTime; |
|
37 | 37 | QT_END_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | QT_CHARTS_BEGIN_NAMESPACE |
|
40 | 40 | |
|
41 | 41 | class QLogValueAxisPrivate; |
|
42 | 42 | |
|
43 | 43 | class QT_CHARTS_EXPORT QLogValueAxis : public QAbstractAxis |
|
44 | 44 | { |
|
45 | 45 | Q_OBJECT |
|
46 | 46 | Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged) |
|
47 | 47 | Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged) |
|
48 | 48 | Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat NOTIFY labelFormatChanged) |
|
49 | 49 | Q_PROPERTY(qreal base READ base WRITE setBase NOTIFY baseChanged) |
|
50 | 50 | |
|
51 | 51 | public: |
|
52 |
explicit QLogValueAxis(QObject *parent = |
|
|
52 | explicit QLogValueAxis(QObject *parent = Q_NULLPTR); | |
|
53 | 53 | ~QLogValueAxis(); |
|
54 | 54 | |
|
55 | 55 | protected: |
|
56 |
QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent = |
|
|
56 | QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent = Q_NULLPTR); | |
|
57 | 57 | |
|
58 | 58 | public: |
|
59 | 59 | AxisType type() const; |
|
60 | 60 | |
|
61 | 61 | //range handling |
|
62 | 62 | void setMin(qreal min); |
|
63 | 63 | qreal min() const; |
|
64 | 64 | void setMax(qreal max); |
|
65 | 65 | qreal max() const; |
|
66 | 66 | void setRange(qreal min, qreal max); |
|
67 | 67 | |
|
68 | 68 | void setLabelFormat(const QString &format); |
|
69 | 69 | QString labelFormat() const; |
|
70 | 70 | |
|
71 | 71 | void setBase(qreal base); |
|
72 | 72 | qreal base() const; |
|
73 | 73 | |
|
74 | 74 | Q_SIGNALS: |
|
75 | 75 | void minChanged(qreal min); |
|
76 | 76 | void maxChanged(qreal max); |
|
77 | 77 | void rangeChanged(qreal min, qreal max); |
|
78 | 78 | void labelFormatChanged(const QString &format); |
|
79 | 79 | void baseChanged(qreal base); |
|
80 | 80 | |
|
81 | 81 | private: |
|
82 | 82 | Q_DECLARE_PRIVATE(QLogValueAxis) |
|
83 | 83 | Q_DISABLE_COPY(QLogValueAxis) |
|
84 | 84 | }; |
|
85 | 85 | |
|
86 | 86 | QT_CHARTS_END_NAMESPACE |
|
87 | 87 | |
|
88 | 88 | #endif // QLOGVALUEAXIS_H |
@@ -1,218 +1,218 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QABSTRACTAXIS_H |
|
31 | 31 | #define QABSTRACTAXIS_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtGui/QPen> |
|
35 | 35 | #include <QtGui/QFont> |
|
36 | 36 | #include <QtCore/QVariant> |
|
37 | 37 | |
|
38 | 38 | QT_CHARTS_BEGIN_NAMESPACE |
|
39 | 39 | |
|
40 | 40 | class QAbstractAxisPrivate; |
|
41 | 41 | |
|
42 | 42 | class QT_CHARTS_EXPORT QAbstractAxis : public QObject |
|
43 | 43 | { |
|
44 | 44 | Q_OBJECT |
|
45 | 45 | //visibility |
|
46 | 46 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) |
|
47 | 47 | //arrow |
|
48 | 48 | Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged) |
|
49 | 49 | Q_PROPERTY(QPen linePen READ linePen WRITE setLinePen NOTIFY linePenChanged) |
|
50 | 50 | Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged) |
|
51 | 51 | //labels |
|
52 | 52 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
53 | 53 | Q_PROPERTY(QBrush labelsBrush READ labelsBrush WRITE setLabelsBrush NOTIFY labelsBrushChanged) |
|
54 | 54 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle NOTIFY labelsAngleChanged) |
|
55 | 55 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont NOTIFY labelsFontChanged) |
|
56 | 56 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) |
|
57 | 57 | //grid |
|
58 | 58 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) |
|
59 | 59 | Q_PROPERTY(QPen gridLinePen READ gridLinePen WRITE setGridLinePen NOTIFY gridLinePenChanged) |
|
60 | 60 | Q_PROPERTY(bool minorGridVisible READ isMinorGridLineVisible WRITE setMinorGridLineVisible NOTIFY minorGridVisibleChanged) |
|
61 | 61 | Q_PROPERTY(QPen minorGridLinePen READ minorGridLinePen WRITE setMinorGridLinePen NOTIFY minorGridLinePenChanged) |
|
62 | 62 | Q_PROPERTY(QColor gridLineColor READ gridLineColor WRITE setGridLineColor NOTIFY gridLineColorChanged) |
|
63 | 63 | Q_PROPERTY(QColor minorGridLineColor READ minorGridLineColor WRITE setMinorGridLineColor NOTIFY minorGridLineColorChanged) |
|
64 | 64 | //shades |
|
65 | 65 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) |
|
66 | 66 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) |
|
67 | 67 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) |
|
68 | 68 | Q_PROPERTY(QPen shadesPen READ shadesPen WRITE setShadesPen NOTIFY shadesPenChanged) |
|
69 | 69 | Q_PROPERTY(QBrush shadesBrush READ shadesBrush WRITE setShadesBrush NOTIFY shadesBrushChanged) |
|
70 | 70 | //title |
|
71 | 71 | Q_PROPERTY(QString titleText READ titleText WRITE setTitleText NOTIFY titleTextChanged) |
|
72 | 72 | Q_PROPERTY(QBrush titleBrush READ titleBrush WRITE setTitleBrush NOTIFY titleBrushChanged) |
|
73 | 73 | Q_PROPERTY(bool titleVisible READ isTitleVisible WRITE setTitleVisible NOTIFY titleVisibleChanged) |
|
74 | 74 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont NOTIFY titleFontChanged) |
|
75 | 75 | //orientation |
|
76 | 76 | Q_PROPERTY(Qt::Orientation orientation READ orientation) |
|
77 | 77 | //aligment |
|
78 | 78 | Q_PROPERTY(Qt::Alignment alignment READ alignment) |
|
79 | 79 | Q_PROPERTY(bool reverse READ isReverse WRITE setReverse NOTIFY reverseChanged) |
|
80 | 80 | |
|
81 | 81 | public: |
|
82 | 82 | |
|
83 | 83 | enum AxisType { |
|
84 | 84 | AxisTypeNoAxis = 0x0, |
|
85 | 85 | AxisTypeValue = 0x1, |
|
86 | 86 | AxisTypeBarCategory = 0x2, |
|
87 | 87 | AxisTypeCategory = 0x4, |
|
88 | 88 | AxisTypeDateTime = 0x8, |
|
89 | 89 | AxisTypeLogValue = 0x10 |
|
90 | 90 | }; |
|
91 | 91 | |
|
92 | 92 | Q_DECLARE_FLAGS(AxisTypes, AxisType) |
|
93 | 93 | |
|
94 | 94 | protected: |
|
95 |
explicit QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent = |
|
|
95 | explicit QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent = Q_NULLPTR); | |
|
96 | 96 | |
|
97 | 97 | public: |
|
98 | 98 | ~QAbstractAxis(); |
|
99 | 99 | |
|
100 | 100 | virtual AxisType type() const = 0; |
|
101 | 101 | |
|
102 | 102 | //visibility handling |
|
103 | 103 | bool isVisible() const; |
|
104 | 104 | void setVisible(bool visible = true); |
|
105 | 105 | void show(); |
|
106 | 106 | void hide(); |
|
107 | 107 | |
|
108 | 108 | //arrow handling |
|
109 | 109 | bool isLineVisible() const; |
|
110 | 110 | void setLineVisible(bool visible = true); |
|
111 | 111 | void setLinePen(const QPen &pen); |
|
112 | 112 | QPen linePen() const; |
|
113 | 113 | void setLinePenColor(QColor color); |
|
114 | 114 | QColor linePenColor() const; |
|
115 | 115 | |
|
116 | 116 | //grid handling |
|
117 | 117 | bool isGridLineVisible() const; |
|
118 | 118 | void setGridLineVisible(bool visible = true); |
|
119 | 119 | void setGridLinePen(const QPen &pen); |
|
120 | 120 | QPen gridLinePen() const; |
|
121 | 121 | bool isMinorGridLineVisible() const; |
|
122 | 122 | void setMinorGridLineVisible(bool visible = true); |
|
123 | 123 | void setMinorGridLinePen(const QPen &pen); |
|
124 | 124 | QPen minorGridLinePen() const; |
|
125 | 125 | void setGridLineColor(const QColor &color); |
|
126 | 126 | QColor gridLineColor(); |
|
127 | 127 | void setMinorGridLineColor(const QColor &color); |
|
128 | 128 | QColor minorGridLineColor(); |
|
129 | 129 | |
|
130 | 130 | //labels handling |
|
131 | 131 | bool labelsVisible() const; |
|
132 | 132 | void setLabelsVisible(bool visible = true); |
|
133 | 133 | void setLabelsBrush(const QBrush &brush); |
|
134 | 134 | QBrush labelsBrush() const; |
|
135 | 135 | void setLabelsFont(const QFont &font); |
|
136 | 136 | QFont labelsFont() const; |
|
137 | 137 | void setLabelsAngle(int angle); |
|
138 | 138 | int labelsAngle() const; |
|
139 | 139 | void setLabelsColor(QColor color); |
|
140 | 140 | QColor labelsColor() const; |
|
141 | 141 | |
|
142 | 142 | //title handling |
|
143 | 143 | bool isTitleVisible() const; |
|
144 | 144 | void setTitleVisible(bool visible = true); |
|
145 | 145 | void setTitleBrush(const QBrush &brush); |
|
146 | 146 | QBrush titleBrush() const; |
|
147 | 147 | void setTitleFont(const QFont &font); |
|
148 | 148 | QFont titleFont() const; |
|
149 | 149 | void setTitleText(const QString &title); |
|
150 | 150 | QString titleText() const; |
|
151 | 151 | |
|
152 | 152 | //shades handling |
|
153 | 153 | bool shadesVisible() const; |
|
154 | 154 | void setShadesVisible(bool visible = true); |
|
155 | 155 | void setShadesPen(const QPen &pen); |
|
156 | 156 | QPen shadesPen() const; |
|
157 | 157 | void setShadesBrush(const QBrush &brush); |
|
158 | 158 | QBrush shadesBrush() const; |
|
159 | 159 | void setShadesColor(QColor color); |
|
160 | 160 | QColor shadesColor() const; |
|
161 | 161 | void setShadesBorderColor(QColor color); |
|
162 | 162 | QColor shadesBorderColor() const; |
|
163 | 163 | |
|
164 | 164 | Qt::Orientation orientation() const; |
|
165 | 165 | Qt::Alignment alignment() const; |
|
166 | 166 | |
|
167 | 167 | //range handling |
|
168 | 168 | void setMin(const QVariant &min); |
|
169 | 169 | void setMax(const QVariant &max); |
|
170 | 170 | void setRange(const QVariant &min, const QVariant &max); |
|
171 | 171 | |
|
172 | 172 | //reverse handling |
|
173 | 173 | void setReverse(bool reverse = true); |
|
174 | 174 | bool isReverse() const; |
|
175 | 175 | |
|
176 | 176 | Q_SIGNALS: |
|
177 | 177 | void visibleChanged(bool visible); |
|
178 | 178 | void linePenChanged(const QPen &pen); |
|
179 | 179 | void lineVisibleChanged(bool visible); |
|
180 | 180 | void labelsVisibleChanged(bool visible); |
|
181 | 181 | void labelsBrushChanged(const QBrush &brush); |
|
182 | 182 | void labelsFontChanged(const QFont &pen); |
|
183 | 183 | void labelsAngleChanged(int angle); |
|
184 | 184 | void gridLinePenChanged(const QPen &pen); |
|
185 | 185 | void gridVisibleChanged(bool visible); |
|
186 | 186 | void minorGridVisibleChanged(bool visible); |
|
187 | 187 | void minorGridLinePenChanged(const QPen &pen); |
|
188 | 188 | void gridLineColorChanged(const QColor &color); |
|
189 | 189 | void minorGridLineColorChanged(const QColor &color); |
|
190 | 190 | void colorChanged(QColor color); |
|
191 | 191 | void labelsColorChanged(QColor color); |
|
192 | 192 | void titleTextChanged(const QString &title); |
|
193 | 193 | void titleBrushChanged(const QBrush &brush); |
|
194 | 194 | void titleVisibleChanged(bool visible); |
|
195 | 195 | void titleFontChanged(const QFont &font); |
|
196 | 196 | void shadesVisibleChanged(bool visible); |
|
197 | 197 | void shadesColorChanged(QColor color); |
|
198 | 198 | void shadesBorderColorChanged(QColor color); |
|
199 | 199 | void shadesPenChanged(const QPen &pen); |
|
200 | 200 | void shadesBrushChanged(const QBrush &brush); |
|
201 | 201 | void reverseChanged(bool reverse); |
|
202 | 202 | |
|
203 | 203 | protected: |
|
204 | 204 | QScopedPointer<QAbstractAxisPrivate> d_ptr; |
|
205 | 205 | friend class ChartDataSet; |
|
206 | 206 | friend class ChartPresenter; |
|
207 | 207 | friend class ChartThemeManager; |
|
208 | 208 | friend class AbstractDomain; |
|
209 | 209 | friend class ChartAxisElement; |
|
210 | 210 | friend class XYChart; |
|
211 | 211 | |
|
212 | 212 | private: |
|
213 | 213 | Q_DISABLE_COPY(QAbstractAxis) |
|
214 | 214 | }; |
|
215 | 215 | |
|
216 | 216 | QT_CHARTS_END_NAMESPACE |
|
217 | 217 | |
|
218 | 218 | #endif // QABSTRACTAXIS_H |
@@ -1,466 +1,472 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include <QtCharts/QValueAxis> |
|
31 | 31 | #include <private/qvalueaxis_p.h> |
|
32 | 32 | #include <private/chartvalueaxisx_p.h> |
|
33 | 33 | #include <private/chartvalueaxisy_p.h> |
|
34 | 34 | #include <private/abstractdomain_p.h> |
|
35 | 35 | #include <private/polarchartvalueaxisangular_p.h> |
|
36 | 36 | #include <private/polarchartvalueaxisradial_p.h> |
|
37 | 37 | #include <private/chartdataset_p.h> |
|
38 | 38 | #include <private/chartpresenter_p.h> |
|
39 | 39 | #include <private/charttheme_p.h> |
|
40 | ||
|
40 | #include <private/charthelpers_p.h> | |
|
41 | 41 | |
|
42 | 42 | QT_CHARTS_BEGIN_NAMESPACE |
|
43 | 43 | /*! |
|
44 | 44 | \class QValueAxis |
|
45 | 45 | \inmodule Qt Charts |
|
46 | 46 | \brief The QValueAxis class is used for manipulating chart's axis. |
|
47 | 47 | |
|
48 | 48 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
49 | 49 | Values of axis are drawn to position of ticks. |
|
50 | 50 | |
|
51 | 51 | Example code on how to use QValueAxis. |
|
52 | 52 | \code |
|
53 | 53 | QChartView *chartView = new QChartView; |
|
54 | 54 | QLineSeries *series = new QLineSeries; |
|
55 | 55 | // ... |
|
56 | 56 | chartView->chart()->addSeries(series); |
|
57 | 57 | |
|
58 | 58 | QValueAxis *axisX = new QValueAxis; |
|
59 | 59 | axisX->setRange(10, 20.5); |
|
60 | 60 | axisX->setTickCount(10); |
|
61 | 61 | axisX->setLabelFormat("%.2f"); |
|
62 | 62 | chartView->chart()->setAxisX(axisX, series); |
|
63 | 63 | \endcode |
|
64 | 64 | */ |
|
65 | 65 | /*! |
|
66 | 66 | \qmltype ValueAxis |
|
67 | 67 | \instantiates QValueAxis |
|
68 | 68 | \inqmlmodule QtCharts |
|
69 | 69 | |
|
70 | 70 | \inherits AbstractAxis |
|
71 | 71 | \brief The ValueAxis element is used for manipulating chart's axes |
|
72 | 72 | |
|
73 | 73 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
74 | 74 | Values of axis are drawn to position of ticks |
|
75 | 75 | |
|
76 | 76 | Example about using ValueAxis: |
|
77 | 77 | \code |
|
78 | 78 | ChartView { |
|
79 | 79 | ValueAxis { |
|
80 | 80 | id: xAxis |
|
81 | 81 | min: 0 |
|
82 | 82 | max: 10 |
|
83 | 83 | } |
|
84 | 84 | // Add a few series... |
|
85 | 85 | } |
|
86 | 86 | \endcode |
|
87 | 87 | */ |
|
88 | 88 | |
|
89 | 89 | /*! |
|
90 | 90 | \property QValueAxis::min |
|
91 | 91 | Defines the minimum value on the axis. |
|
92 | 92 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
93 | 93 | */ |
|
94 | 94 | /*! |
|
95 | 95 | \qmlproperty real ValueAxis::min |
|
96 | 96 | Defines the minimum value on the axis. |
|
97 | 97 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
98 | 98 | */ |
|
99 | 99 | |
|
100 | 100 | /*! |
|
101 | 101 | \property QValueAxis::max |
|
102 | 102 | Defines the maximum value on the axis. |
|
103 | 103 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
104 | 104 | */ |
|
105 | 105 | /*! |
|
106 | 106 | \qmlproperty real ValueAxis::max |
|
107 | 107 | Defines the maximum value on the axis. |
|
108 | 108 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
109 | 109 | */ |
|
110 | 110 | |
|
111 | 111 | /*! |
|
112 | 112 | \property QValueAxis::tickCount |
|
113 | 113 | Defines the number of ticks on the axis. This indicates how many grid lines are drawn on the |
|
114 | 114 | chart. The default value is 5, and it can not be below 2. |
|
115 | 115 | */ |
|
116 | 116 | /*! |
|
117 | 117 | \qmlproperty int ValueAxis::tickCount |
|
118 | 118 | Defines the number of ticks on the axis. This indicates how many grid lines are drawn on the |
|
119 | 119 | chart. The default value is 5, and it can not be below 2. |
|
120 | 120 | */ |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | \property QValueAxis::minorTickCount |
|
124 | 124 | Defines the number of minor ticks on the axis. This indicates how many grid lines are drawn |
|
125 | 125 | between major ticks on the chart. Labels are not drawn for minor ticks. The default value is 0. |
|
126 | 126 | */ |
|
127 | 127 | /*! |
|
128 | 128 | \qmlproperty int ValueAxis::minorTickCount |
|
129 | 129 | Defines the number of minor ticks on the axis. This indicates how many grid lines are drawn |
|
130 | 130 | between major ticks on the chart. Labels are not drawn for minor ticks. The default value is 0. |
|
131 | 131 | */ |
|
132 | 132 | |
|
133 | 133 | /*! |
|
134 | 134 | \property QValueAxis::labelFormat |
|
135 | 135 | Defines the label format of the axis. |
|
136 | 136 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, and c. |
|
137 | 137 | See QString::sprintf() for additional details. |
|
138 | 138 | |
|
139 | 139 | If the QChart::localizeNumbers is \c{true}, the supported specifiers are limited to: d, e, E, f, |
|
140 | 140 | g, G, and i. Also, only the precision modifier is supported. The rest of the formatting comes from |
|
141 | 141 | the default QLocale of the application. |
|
142 | 142 | */ |
|
143 | 143 | /*! |
|
144 | 144 | \qmlproperty real ValueAxis::labelFormat |
|
145 | 145 | Defines the label format of the axis. |
|
146 | 146 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, and c. |
|
147 | 147 | See QString::sprintf() for additional details. |
|
148 | 148 | |
|
149 | 149 | If the ChartView::localizeNumbers is \c{true}, the supported specifiers are limited to: d, e, E, f, |
|
150 | 150 | g, G, and i. Also, only the precision modifier is supported. The rest of the formatting comes from |
|
151 | 151 | the default QLocale of the application. |
|
152 | 152 | */ |
|
153 | 153 | |
|
154 | 154 | /*! |
|
155 | 155 | \fn void QValueAxis::minChanged(qreal min) |
|
156 | 156 | Axis emits signal when \a min of axis has changed. |
|
157 | 157 | */ |
|
158 | 158 | /*! |
|
159 | 159 | \qmlsignal ValueAxis::onMinChanged(real min) |
|
160 | 160 | Axis emits signal when \a min of axis has changed. |
|
161 | 161 | */ |
|
162 | 162 | |
|
163 | 163 | /*! |
|
164 | 164 | \fn void QValueAxis::maxChanged(qreal max) |
|
165 | 165 | Axis emits signal when \a max of axis has changed. |
|
166 | 166 | */ |
|
167 | 167 | /*! |
|
168 | 168 | \qmlsignal ValueAxis::onMaxChanged(real max) |
|
169 | 169 | Axis emits signal when \a max of axis has changed. |
|
170 | 170 | */ |
|
171 | 171 | |
|
172 | 172 | /*! |
|
173 | 173 | \fn void QValueAxis::tickCountChanged(int tickCount) |
|
174 | 174 | Axis emits signal when \a tickCount of axis has changed. |
|
175 | 175 | */ |
|
176 | 176 | /*! |
|
177 | 177 | \qmlsignal ValueAxis::tickCountChanged(int tickCount) |
|
178 | 178 | Axis emits signal when \a tickCount of axis has changed. |
|
179 | 179 | */ |
|
180 | 180 | |
|
181 | 181 | /*! |
|
182 | 182 | \fn void QValueAxis::minorTickCountChanged(int minorTickCount) |
|
183 | 183 | Axis emits signal when \a minorTickCount of axis has changed. |
|
184 | 184 | */ |
|
185 | 185 | /*! |
|
186 | 186 | \qmlsignal ValueAxis::minorTickCountChanged(int minorTickCount) |
|
187 | 187 | Axis emits signal when \a minorTickCount of axis has changed. |
|
188 | 188 | */ |
|
189 | 189 | |
|
190 | 190 | /*! |
|
191 | 191 | \fn void QValueAxis::rangeChanged(qreal min, qreal max) |
|
192 | 192 | Axis emits signal when \a min or \a max of axis has changed. |
|
193 | 193 | */ |
|
194 | 194 | |
|
195 | 195 | /*! |
|
196 | 196 | \fn void QValueAxis::labelFormatChanged(const QString &format) |
|
197 | 197 | Axis emits signal when \a format of axis labels has changed. |
|
198 | 198 | */ |
|
199 | 199 | /*! |
|
200 | 200 | \qmlsignal ValueAxis::labelFormatChanged(const QString &format) |
|
201 | 201 | Axis emits signal when \a format of axis labels has changed. |
|
202 | 202 | */ |
|
203 | 203 | |
|
204 | 204 | /*! |
|
205 | 205 | Constructs an axis object which is a child of \a parent. |
|
206 | 206 | */ |
|
207 | 207 | QValueAxis::QValueAxis(QObject *parent) : |
|
208 | 208 | QAbstractAxis(*new QValueAxisPrivate(this), parent) |
|
209 | 209 | { |
|
210 | 210 | |
|
211 | 211 | } |
|
212 | 212 | |
|
213 | 213 | /*! |
|
214 | 214 | \internal |
|
215 | 215 | */ |
|
216 | 216 | QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent) |
|
217 | 217 | : QAbstractAxis(d, parent) |
|
218 | 218 | { |
|
219 | 219 | |
|
220 | 220 | } |
|
221 | 221 | |
|
222 | 222 | /*! |
|
223 | 223 | Destroys the object |
|
224 | 224 | */ |
|
225 | 225 | QValueAxis::~QValueAxis() |
|
226 | 226 | { |
|
227 | 227 | Q_D(QValueAxis); |
|
228 | 228 | if (d->m_chart) |
|
229 | 229 | d->m_chart->removeAxis(this); |
|
230 | 230 | } |
|
231 | 231 | |
|
232 | 232 | void QValueAxis::setMin(qreal min) |
|
233 | 233 | { |
|
234 | 234 | Q_D(QValueAxis); |
|
235 | 235 | setRange(min, qMax(d->m_max, min)); |
|
236 | 236 | } |
|
237 | 237 | |
|
238 | 238 | qreal QValueAxis::min() const |
|
239 | 239 | { |
|
240 | 240 | Q_D(const QValueAxis); |
|
241 | 241 | return d->m_min; |
|
242 | 242 | } |
|
243 | 243 | |
|
244 | 244 | void QValueAxis::setMax(qreal max) |
|
245 | 245 | { |
|
246 | 246 | Q_D(QValueAxis); |
|
247 | 247 | setRange(qMin(d->m_min, max), max); |
|
248 | 248 | } |
|
249 | 249 | |
|
250 | 250 | qreal QValueAxis::max() const |
|
251 | 251 | { |
|
252 | 252 | Q_D(const QValueAxis); |
|
253 | 253 | return d->m_max; |
|
254 | 254 | } |
|
255 | 255 | |
|
256 | 256 | /*! |
|
257 | 257 | Sets range from \a min to \a max on the axis. |
|
258 | 258 | If min is greater than max then this function returns without making any changes. |
|
259 | 259 | */ |
|
260 | 260 | void QValueAxis::setRange(qreal min, qreal max) |
|
261 | 261 | { |
|
262 | 262 | Q_D(QValueAxis); |
|
263 | 263 | d->setRange(min,max); |
|
264 | 264 | } |
|
265 | 265 | |
|
266 | 266 | void QValueAxis::setTickCount(int count) |
|
267 | 267 | { |
|
268 | 268 | Q_D(QValueAxis); |
|
269 | 269 | if (d->m_tickCount != count && count >= 2) { |
|
270 | 270 | d->m_tickCount = count; |
|
271 | 271 | emit tickCountChanged(count); |
|
272 | 272 | } |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | int QValueAxis::tickCount() const |
|
276 | 276 | { |
|
277 | 277 | Q_D(const QValueAxis); |
|
278 | 278 | return d->m_tickCount; |
|
279 | 279 | } |
|
280 | 280 | |
|
281 | 281 | void QValueAxis::setMinorTickCount(int count) |
|
282 | 282 | { |
|
283 | 283 | Q_D(QValueAxis); |
|
284 | 284 | if (d->m_minorTickCount != count && count >= 0) { |
|
285 | 285 | d->m_minorTickCount = count; |
|
286 | 286 | emit minorTickCountChanged(count); |
|
287 | 287 | } |
|
288 | 288 | } |
|
289 | 289 | |
|
290 | 290 | int QValueAxis::minorTickCount() const |
|
291 | 291 | { |
|
292 | 292 | Q_D(const QValueAxis); |
|
293 | 293 | return d->m_minorTickCount; |
|
294 | 294 | } |
|
295 | 295 | |
|
296 | 296 | void QValueAxis::setLabelFormat(const QString &format) |
|
297 | 297 | { |
|
298 | 298 | Q_D(QValueAxis); |
|
299 | 299 | d->m_format = format; |
|
300 | 300 | emit labelFormatChanged(format); |
|
301 | 301 | } |
|
302 | 302 | |
|
303 | 303 | QString QValueAxis::labelFormat() const |
|
304 | 304 | { |
|
305 | 305 | Q_D(const QValueAxis); |
|
306 | 306 | return d->m_format; |
|
307 | 307 | } |
|
308 | 308 | |
|
309 | 309 | /*! |
|
310 | 310 | Returns the type of the axis |
|
311 | 311 | */ |
|
312 | 312 | QAbstractAxis::AxisType QValueAxis::type() const |
|
313 | 313 | { |
|
314 | 314 | return AxisTypeValue; |
|
315 | 315 | } |
|
316 | 316 | |
|
317 | 317 | /*! |
|
318 | 318 | This method modifies range and number of ticks on the axis to look "nice". Algorithm considers numbers that |
|
319 | 319 | can be expressed as form of 1*10^n, 2* 10^n or 5*10^n as a nice numbers. These numbers are used for spacing the ticks. |
|
320 | 320 | This method will modify the current range and number of ticks. |
|
321 | 321 | \sa setRange(), setTickCount() |
|
322 | 322 | */ |
|
323 | 323 | void QValueAxis::applyNiceNumbers() |
|
324 | 324 | { |
|
325 | 325 | Q_D(QValueAxis); |
|
326 | 326 | if(d->m_applying) return; |
|
327 | 327 | qreal min = d->m_min; |
|
328 | 328 | qreal max = d->m_max; |
|
329 | 329 | int ticks = d->m_tickCount; |
|
330 | 330 | AbstractDomain::looseNiceNumbers(min,max,ticks); |
|
331 | 331 | d->m_applying=true; |
|
332 | 332 | d->setRange(min,max); |
|
333 | 333 | setTickCount(ticks); |
|
334 | 334 | d->m_applying=false; |
|
335 | 335 | } |
|
336 | 336 | |
|
337 | 337 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
338 | 338 | |
|
339 | 339 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q) |
|
340 | 340 | : QAbstractAxisPrivate(q), |
|
341 | 341 | m_min(0), |
|
342 | 342 | m_max(0), |
|
343 | 343 | m_tickCount(5), |
|
344 | 344 | m_minorTickCount(0), |
|
345 | 345 | m_format(QString::null), |
|
346 | 346 | m_applying(false) |
|
347 | 347 | { |
|
348 | 348 | |
|
349 | 349 | } |
|
350 | 350 | |
|
351 | 351 | QValueAxisPrivate::~QValueAxisPrivate() |
|
352 | 352 | { |
|
353 | 353 | |
|
354 | 354 | } |
|
355 | 355 | |
|
356 | 356 | void QValueAxisPrivate::setMin(const QVariant &min) |
|
357 | 357 | { |
|
358 | 358 | Q_Q(QValueAxis); |
|
359 | 359 | bool ok; |
|
360 | 360 | qreal value = min.toReal(&ok); |
|
361 | 361 | if (ok) |
|
362 | 362 | q->setMin(value); |
|
363 | 363 | } |
|
364 | 364 | |
|
365 | 365 | void QValueAxisPrivate::setMax(const QVariant &max) |
|
366 | 366 | { |
|
367 | 367 | Q_Q(QValueAxis); |
|
368 | 368 | bool ok; |
|
369 | 369 | qreal value = max.toReal(&ok); |
|
370 | 370 | if (ok) |
|
371 | 371 | q->setMax(value); |
|
372 | 372 | } |
|
373 | 373 | |
|
374 | 374 | void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
375 | 375 | { |
|
376 | 376 | Q_Q(QValueAxis); |
|
377 | 377 | bool ok1; |
|
378 | 378 | bool ok2; |
|
379 | 379 | qreal value1 = min.toReal(&ok1); |
|
380 | 380 | qreal value2 = max.toReal(&ok2); |
|
381 | 381 | if (ok1 && ok2) |
|
382 | 382 | q->setRange(value1, value2); |
|
383 | 383 | } |
|
384 | 384 | |
|
385 | 385 | void QValueAxisPrivate::setRange(qreal min, qreal max) |
|
386 | 386 | { |
|
387 | 387 | Q_Q(QValueAxis); |
|
388 | 388 | bool changed = false; |
|
389 | 389 | |
|
390 | 390 | if (min > max) |
|
391 | 391 | return; |
|
392 | 392 | |
|
393 | if (!isValidValue(min, max)) { | |
|
394 | qWarning() << "Attempting to set invalid range for value axis: [" | |
|
395 | << min << " - " << max << "]"; | |
|
396 | return; | |
|
397 | } | |
|
398 | ||
|
393 | 399 | bool changeMin = false; |
|
394 | 400 | if (m_min == 0 || min == 0) |
|
395 | 401 | changeMin = !qFuzzyCompare(1 + m_min, 1 + min); |
|
396 | 402 | else |
|
397 | 403 | changeMin = !qFuzzyCompare(m_min, min); |
|
398 | 404 | |
|
399 | 405 | bool changeMax = false; |
|
400 | 406 | if (m_max == 0 || max == 0) |
|
401 | 407 | changeMax = !qFuzzyCompare(1 + m_max, 1 + max); |
|
402 | 408 | else |
|
403 | 409 | changeMax = !qFuzzyCompare(m_max, max); |
|
404 | 410 | |
|
405 | 411 | if (changeMin) { |
|
406 | 412 | m_min = min; |
|
407 | 413 | changed = true; |
|
408 | 414 | emit q->minChanged(min); |
|
409 | 415 | } |
|
410 | 416 | |
|
411 | 417 | if (changeMax) { |
|
412 | 418 | m_max = max; |
|
413 | 419 | changed = true; |
|
414 | 420 | emit q->maxChanged(max); |
|
415 | 421 | } |
|
416 | 422 | |
|
417 | 423 | if (changed) { |
|
418 | 424 | emit rangeChanged(min,max); |
|
419 | 425 | emit q->rangeChanged(min, max); |
|
420 | 426 | } |
|
421 | 427 | } |
|
422 | 428 | |
|
423 | 429 | void QValueAxisPrivate::initializeGraphics(QGraphicsItem *parent) |
|
424 | 430 | { |
|
425 | 431 | Q_Q(QValueAxis); |
|
426 | 432 | ChartAxisElement *axis(0); |
|
427 | 433 | |
|
428 | 434 | if (m_chart->chartType() == QChart::ChartTypeCartesian) { |
|
429 | 435 | if (orientation() == Qt::Vertical) |
|
430 | 436 | axis = new ChartValueAxisY(q,parent); |
|
431 | 437 | if (orientation() == Qt::Horizontal) |
|
432 | 438 | axis = new ChartValueAxisX(q,parent); |
|
433 | 439 | } |
|
434 | 440 | |
|
435 | 441 | if (m_chart->chartType() == QChart::ChartTypePolar) { |
|
436 | 442 | if (orientation() == Qt::Vertical) |
|
437 | 443 | axis = new PolarChartValueAxisRadial(q, parent); |
|
438 | 444 | if (orientation() == Qt::Horizontal) |
|
439 | 445 | axis = new PolarChartValueAxisAngular(q, parent); |
|
440 | 446 | } |
|
441 | 447 | |
|
442 | 448 | m_item.reset(axis); |
|
443 | 449 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
444 | 450 | } |
|
445 | 451 | |
|
446 | 452 | |
|
447 | 453 | void QValueAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
448 | 454 | { |
|
449 | 455 | if (orientation() == Qt::Vertical) { |
|
450 | 456 | if (!qFuzzyIsNull(m_max - m_min)) |
|
451 | 457 | domain->setRangeY(m_min, m_max); |
|
452 | 458 | else |
|
453 | 459 | setRange(domain->minY(), domain->maxY()); |
|
454 | 460 | } |
|
455 | 461 | if (orientation() == Qt::Horizontal) { |
|
456 | 462 | if (!qFuzzyIsNull(m_max - m_min)) |
|
457 | 463 | domain->setRangeX(m_min, m_max); |
|
458 | 464 | else |
|
459 | 465 | setRange(domain->minX(), domain->maxX()); |
|
460 | 466 | } |
|
461 | 467 | } |
|
462 | 468 | |
|
463 | 469 | #include "moc_qvalueaxis.cpp" |
|
464 | 470 | #include "moc_qvalueaxis_p.cpp" |
|
465 | 471 | |
|
466 | 472 | QT_CHARTS_END_NAMESPACE |
@@ -1,92 +1,92 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QVALUEAXIS_H |
|
31 | 31 | #define QVALUEAXIS_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QAbstractAxis> |
|
34 | 34 | |
|
35 | 35 | QT_CHARTS_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | class QValueAxisPrivate; |
|
38 | 38 | |
|
39 | 39 | class QT_CHARTS_EXPORT QValueAxis : public QAbstractAxis |
|
40 | 40 | { |
|
41 | 41 | Q_OBJECT |
|
42 | 42 | Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount NOTIFY tickCountChanged) |
|
43 | 43 | Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged) |
|
44 | 44 | Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged) |
|
45 | 45 | Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat NOTIFY labelFormatChanged) |
|
46 | 46 | Q_PROPERTY(int minorTickCount READ minorTickCount WRITE setMinorTickCount NOTIFY minorTickCountChanged) |
|
47 | 47 | |
|
48 | 48 | public: |
|
49 |
explicit QValueAxis(QObject *parent = |
|
|
49 | explicit QValueAxis(QObject *parent = Q_NULLPTR); | |
|
50 | 50 | ~QValueAxis(); |
|
51 | 51 | |
|
52 | 52 | protected: |
|
53 |
QValueAxis(QValueAxisPrivate &d, QObject *parent = |
|
|
53 | QValueAxis(QValueAxisPrivate &d, QObject *parent = Q_NULLPTR); | |
|
54 | 54 | |
|
55 | 55 | public: |
|
56 | 56 | AxisType type() const; |
|
57 | 57 | |
|
58 | 58 | //range handling |
|
59 | 59 | void setMin(qreal min); |
|
60 | 60 | qreal min() const; |
|
61 | 61 | void setMax(qreal max); |
|
62 | 62 | qreal max() const; |
|
63 | 63 | void setRange(qreal min, qreal max); |
|
64 | 64 | |
|
65 | 65 | //ticks handling |
|
66 | 66 | void setTickCount(int count); |
|
67 | 67 | int tickCount() const; |
|
68 | 68 | void setMinorTickCount(int count); |
|
69 | 69 | int minorTickCount() const; |
|
70 | 70 | |
|
71 | 71 | void setLabelFormat(const QString &format); |
|
72 | 72 | QString labelFormat() const; |
|
73 | 73 | |
|
74 | 74 | public Q_SLOTS: |
|
75 | 75 | void applyNiceNumbers(); |
|
76 | 76 | |
|
77 | 77 | Q_SIGNALS: |
|
78 | 78 | void minChanged(qreal min); |
|
79 | 79 | void maxChanged(qreal max); |
|
80 | 80 | void rangeChanged(qreal min, qreal max); |
|
81 | 81 | void tickCountChanged(int tickCount); |
|
82 | 82 | void minorTickCountChanged(int tickCount); |
|
83 | 83 | void labelFormatChanged(const QString &format); |
|
84 | 84 | |
|
85 | 85 | private: |
|
86 | 86 | Q_DECLARE_PRIVATE(QValueAxis) |
|
87 | 87 | Q_DISABLE_COPY(QValueAxis) |
|
88 | 88 | }; |
|
89 | 89 | |
|
90 | 90 | QT_CHARTS_END_NAMESPACE |
|
91 | 91 | |
|
92 | 92 | #endif // QVALUEAXIS_H |
@@ -1,54 +1,54 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QHORIZONTALBARSERIES_H |
|
31 | 31 | #define QHORIZONTALBARSERIES_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QAbstractBarSeries> |
|
34 | 34 | |
|
35 | 35 | QT_CHARTS_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | class QHorizontalBarSeriesPrivate; |
|
38 | 38 | |
|
39 | 39 | class QT_CHARTS_EXPORT QHorizontalBarSeries : public QAbstractBarSeries |
|
40 | 40 | { |
|
41 | 41 | Q_OBJECT |
|
42 | 42 | public: |
|
43 |
explicit QHorizontalBarSeries(QObject *parent = |
|
|
43 | explicit QHorizontalBarSeries(QObject *parent = Q_NULLPTR); | |
|
44 | 44 | ~QHorizontalBarSeries(); |
|
45 | 45 | QAbstractSeries::SeriesType type() const; |
|
46 | 46 | |
|
47 | 47 | private: |
|
48 | 48 | Q_DECLARE_PRIVATE(QHorizontalBarSeries) |
|
49 | 49 | Q_DISABLE_COPY(QHorizontalBarSeries) |
|
50 | 50 | }; |
|
51 | 51 | |
|
52 | 52 | QT_CHARTS_END_NAMESPACE |
|
53 | 53 | |
|
54 | 54 | #endif // QHORIZONTALBARSERIES_H |
@@ -1,54 +1,54 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QHORIZONTALPERCENTBARSERIES_H |
|
31 | 31 | #define QHORIZONTALPERCENTBARSERIES_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QAbstractBarSeries> |
|
34 | 34 | |
|
35 | 35 | QT_CHARTS_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | class QHorizontalPercentBarSeriesPrivate; |
|
38 | 38 | |
|
39 | 39 | class QT_CHARTS_EXPORT QHorizontalPercentBarSeries : public QAbstractBarSeries |
|
40 | 40 | { |
|
41 | 41 | Q_OBJECT |
|
42 | 42 | public: |
|
43 |
explicit QHorizontalPercentBarSeries(QObject *parent = |
|
|
43 | explicit QHorizontalPercentBarSeries(QObject *parent = Q_NULLPTR); | |
|
44 | 44 | ~QHorizontalPercentBarSeries(); |
|
45 | 45 | QAbstractSeries::SeriesType type() const; |
|
46 | 46 | |
|
47 | 47 | private: |
|
48 | 48 | Q_DECLARE_PRIVATE(QHorizontalPercentBarSeries) |
|
49 | 49 | Q_DISABLE_COPY(QHorizontalPercentBarSeries) |
|
50 | 50 | }; |
|
51 | 51 | |
|
52 | 52 | QT_CHARTS_END_NAMESPACE |
|
53 | 53 | |
|
54 | 54 | #endif // QHORIZONTALPERCENTBARSERIES_H |
@@ -1,54 +1,54 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QHORIZONTALSTACKEDBARSERIES_H |
|
31 | 31 | #define QHORIZONTALSTACKEDBARSERIES_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QAbstractBarSeries> |
|
34 | 34 | |
|
35 | 35 | QT_CHARTS_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | class QHorizontalStackedBarSeriesPrivate; |
|
38 | 38 | |
|
39 | 39 | class QT_CHARTS_EXPORT QHorizontalStackedBarSeries : public QAbstractBarSeries |
|
40 | 40 | { |
|
41 | 41 | Q_OBJECT |
|
42 | 42 | public: |
|
43 |
explicit QHorizontalStackedBarSeries(QObject *parent = |
|
|
43 | explicit QHorizontalStackedBarSeries(QObject *parent = Q_NULLPTR); | |
|
44 | 44 | ~QHorizontalStackedBarSeries(); |
|
45 | 45 | QAbstractSeries::SeriesType type() const; |
|
46 | 46 | |
|
47 | 47 | private: |
|
48 | 48 | Q_DECLARE_PRIVATE(QHorizontalStackedBarSeries) |
|
49 | 49 | Q_DISABLE_COPY(QHorizontalStackedBarSeries) |
|
50 | 50 | }; |
|
51 | 51 | |
|
52 | 52 | QT_CHARTS_END_NAMESPACE |
|
53 | 53 | |
|
54 | 54 | #endif // QHORIZONTALSTACKEDBARSERIES_H |
@@ -1,121 +1,121 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QABSTRACTBARSERIES_H |
|
31 | 31 | #define QABSTRACTBARSERIES_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QAbstractSeries> |
|
34 | 34 | #include <QtCore/QStringList> |
|
35 | 35 | |
|
36 | 36 | QT_CHARTS_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | class QBarSet; |
|
39 | 39 | class QAbstractBarSeriesPrivate; |
|
40 | 40 | |
|
41 | 41 | // Container for series |
|
42 | 42 | class QT_CHARTS_EXPORT QAbstractBarSeries : public QAbstractSeries |
|
43 | 43 | { |
|
44 | 44 | Q_OBJECT |
|
45 | 45 | Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth) |
|
46 | 46 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
|
47 | 47 | Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
48 | 48 | Q_PROPERTY(QString labelsFormat READ labelsFormat WRITE setLabelsFormat NOTIFY labelsFormatChanged) |
|
49 | 49 | Q_PROPERTY(LabelsPosition labelsPosition READ labelsPosition WRITE setLabelsPosition NOTIFY labelsPositionChanged) |
|
50 | 50 | Q_PROPERTY(qreal labelsAngle READ labelsAngle WRITE setLabelsAngle NOTIFY labelsAngleChanged) |
|
51 | 51 | Q_ENUMS(LabelsPosition) |
|
52 | 52 | |
|
53 | 53 | public: |
|
54 | 54 | enum LabelsPosition { |
|
55 | 55 | LabelsCenter = 0, |
|
56 | 56 | LabelsInsideEnd, |
|
57 | 57 | LabelsInsideBase, |
|
58 | 58 | LabelsOutsideEnd |
|
59 | 59 | }; |
|
60 | 60 | |
|
61 | 61 | public: |
|
62 | 62 | virtual ~QAbstractBarSeries(); |
|
63 | 63 | |
|
64 | 64 | void setBarWidth(qreal width); |
|
65 | 65 | qreal barWidth() const; |
|
66 | 66 | |
|
67 | 67 | bool append(QBarSet *set); |
|
68 | 68 | bool remove(QBarSet *set); |
|
69 | 69 | bool take(QBarSet *set); |
|
70 | 70 | bool append(QList<QBarSet *> sets); |
|
71 | 71 | bool insert(int index, QBarSet *set); |
|
72 | 72 | int count() const; |
|
73 | 73 | QList<QBarSet *> barSets() const; |
|
74 | 74 | void clear(); |
|
75 | 75 | |
|
76 | 76 | void setLabelsVisible(bool visible = true); |
|
77 | 77 | bool isLabelsVisible() const; |
|
78 | 78 | |
|
79 | 79 | void setLabelsFormat(const QString &format); |
|
80 | 80 | QString labelsFormat() const; |
|
81 | 81 | |
|
82 | 82 | void setLabelsAngle(qreal angle); |
|
83 | 83 | qreal labelsAngle() const; |
|
84 | 84 | |
|
85 | 85 | void setLabelsPosition(QAbstractBarSeries::LabelsPosition position); |
|
86 | 86 | QAbstractBarSeries::LabelsPosition labelsPosition() const; |
|
87 | 87 | |
|
88 | 88 | protected: |
|
89 |
explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent = |
|
|
89 | explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent = Q_NULLPTR); | |
|
90 | 90 | |
|
91 | 91 | Q_SIGNALS: |
|
92 | 92 | void clicked(int index, QBarSet *barset); |
|
93 | 93 | void hovered(bool status, int index, QBarSet *barset); |
|
94 | 94 | void pressed(int index, QBarSet *barset); |
|
95 | 95 | void released(int index, QBarSet *barset); |
|
96 | 96 | void doubleClicked(int index, QBarSet *barset); |
|
97 | 97 | void countChanged(); |
|
98 | 98 | void labelsVisibleChanged(); |
|
99 | 99 | void labelsFormatChanged(const QString &format); |
|
100 | 100 | void labelsPositionChanged(QAbstractBarSeries::LabelsPosition position); |
|
101 | 101 | void labelsAngleChanged(qreal angle); |
|
102 | 102 | |
|
103 | 103 | void barsetsAdded(QList<QBarSet *> sets); |
|
104 | 104 | void barsetsRemoved(QList<QBarSet *> sets); |
|
105 | 105 | |
|
106 | 106 | protected: |
|
107 | 107 | Q_DECLARE_PRIVATE(QAbstractBarSeries) |
|
108 | 108 | friend class AbstractBarChartItem; |
|
109 | 109 | friend class PercentBarChartItem; |
|
110 | 110 | friend class StackedBarChartItem; |
|
111 | 111 | friend class BoxPlotChartItem; |
|
112 | 112 | friend class BarChartItem; |
|
113 | 113 | friend class HorizontalBarChartItem; |
|
114 | 114 | friend class HorizontalStackedBarChartItem; |
|
115 | 115 | friend class HorizontalPercentBarChartItem; |
|
116 | 116 | friend class BarSet; |
|
117 | 117 | }; |
|
118 | 118 | |
|
119 | 119 | QT_CHARTS_END_NAMESPACE |
|
120 | 120 | |
|
121 | 121 | #endif // QABSTRACTBARSERIES_H |
@@ -1,570 +1,571 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include <QtCharts/QBarModelMapper> |
|
31 | 31 | #include <private/qbarmodelmapper_p.h> |
|
32 | 32 | #include <QtCharts/QAbstractBarSeries> |
|
33 | 33 | #include <QtCharts/QBarSet> |
|
34 | 34 | #include <QtCharts/QChart> |
|
35 | 35 | #include <QtCore/QAbstractItemModel> |
|
36 | 36 | |
|
37 | 37 | QT_CHARTS_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | QBarModelMapper::QBarModelMapper(QObject *parent) : |
|
40 | 40 | QObject(parent), |
|
41 | 41 | d_ptr(new QBarModelMapperPrivate(this)) |
|
42 | 42 | { |
|
43 | 43 | } |
|
44 | 44 | |
|
45 | 45 | QAbstractItemModel *QBarModelMapper::model() const |
|
46 | 46 | { |
|
47 | 47 | Q_D(const QBarModelMapper); |
|
48 | 48 | return d->m_model; |
|
49 | 49 | } |
|
50 | 50 | |
|
51 | 51 | void QBarModelMapper::setModel(QAbstractItemModel *model) |
|
52 | 52 | { |
|
53 | 53 | if (model == 0) |
|
54 | 54 | return; |
|
55 | 55 | |
|
56 | 56 | Q_D(QBarModelMapper); |
|
57 | 57 | if (d->m_model) |
|
58 | 58 | disconnect(d->m_model, 0, d, 0); |
|
59 | 59 | |
|
60 | 60 | d->m_model = model; |
|
61 | 61 | d->initializeBarFromModel(); |
|
62 | 62 | // connect signals from the model |
|
63 | connect(d->m_model, SIGNAL(modelReset()), d, SLOT(initializeBarFromModel())); | |
|
63 | 64 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
64 | 65 | connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int))); |
|
65 | 66 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
66 | 67 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
67 | 68 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
68 | 69 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); |
|
69 | 70 | connect(d->m_model, SIGNAL(destroyed()), d, SLOT(handleModelDestroyed())); |
|
70 | 71 | } |
|
71 | 72 | |
|
72 | 73 | QAbstractBarSeries *QBarModelMapper::series() const |
|
73 | 74 | { |
|
74 | 75 | Q_D(const QBarModelMapper); |
|
75 | 76 | return d->m_series; |
|
76 | 77 | } |
|
77 | 78 | |
|
78 | 79 | void QBarModelMapper::setSeries(QAbstractBarSeries *series) |
|
79 | 80 | { |
|
80 | 81 | Q_D(QBarModelMapper); |
|
81 | 82 | if (d->m_series) |
|
82 | 83 | disconnect(d->m_series, 0, d, 0); |
|
83 | 84 | |
|
84 | 85 | if (series == 0) |
|
85 | 86 | return; |
|
86 | 87 | |
|
87 | 88 | d->m_series = series; |
|
88 | 89 | d->initializeBarFromModel(); |
|
89 | 90 | // connect the signals from the series |
|
90 | 91 | connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>))); |
|
91 | 92 | connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>))); |
|
92 | 93 | connect(d->m_series, SIGNAL(destroyed()), d, SLOT(handleSeriesDestroyed())); |
|
93 | 94 | } |
|
94 | 95 | |
|
95 | 96 | /*! |
|
96 | 97 | Returns which row/column of the model contains the first values of the QBarSets in the series. |
|
97 | 98 | The default value is 0. |
|
98 | 99 | */ |
|
99 | 100 | int QBarModelMapper::first() const |
|
100 | 101 | { |
|
101 | 102 | Q_D(const QBarModelMapper); |
|
102 | 103 | return d->m_first; |
|
103 | 104 | } |
|
104 | 105 | |
|
105 | 106 | /*! |
|
106 | 107 | Sets which row of the model contains the \a first values of the QBarSets in the series. |
|
107 | 108 | The default value is 0. |
|
108 | 109 | */ |
|
109 | 110 | void QBarModelMapper::setFirst(int first) |
|
110 | 111 | { |
|
111 | 112 | Q_D(QBarModelMapper); |
|
112 | 113 | d->m_first = qMax(first, 0); |
|
113 | 114 | d->initializeBarFromModel(); |
|
114 | 115 | } |
|
115 | 116 | |
|
116 | 117 | /*! |
|
117 | 118 | Returns the number of rows/columns of the model that are mapped as the data for QAbstractBarSeries |
|
118 | 119 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
119 | 120 | */ |
|
120 | 121 | int QBarModelMapper::count() const |
|
121 | 122 | { |
|
122 | 123 | Q_D(const QBarModelMapper); |
|
123 | 124 | return d->m_count; |
|
124 | 125 | } |
|
125 | 126 | |
|
126 | 127 | /*! |
|
127 | 128 | Sets the \a count of rows/columns of the model that are mapped as the data for QAbstractBarSeries |
|
128 | 129 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
129 | 130 | */ |
|
130 | 131 | void QBarModelMapper::setCount(int count) |
|
131 | 132 | { |
|
132 | 133 | Q_D(QBarModelMapper); |
|
133 | 134 | d->m_count = qMax(count, -1); |
|
134 | 135 | d->initializeBarFromModel(); |
|
135 | 136 | } |
|
136 | 137 | |
|
137 | 138 | /*! |
|
138 | 139 | Returns the orientation that is used when QBarModelMapper accesses the model. |
|
139 | 140 | This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal) |
|
140 | 141 | or from columns (Qt::Vertical) |
|
141 | 142 | */ |
|
142 | 143 | Qt::Orientation QBarModelMapper::orientation() const |
|
143 | 144 | { |
|
144 | 145 | Q_D(const QBarModelMapper); |
|
145 | 146 | return d->m_orientation; |
|
146 | 147 | } |
|
147 | 148 | |
|
148 | 149 | /*! |
|
149 | 150 | Returns the \a orientation that is used when QBarModelMapper accesses the model. |
|
150 | 151 | This mean whether the consecutive values of the pie are read from row (Qt::Horizontal) |
|
151 | 152 | or from columns (Qt::Vertical) |
|
152 | 153 | */ |
|
153 | 154 | void QBarModelMapper::setOrientation(Qt::Orientation orientation) |
|
154 | 155 | { |
|
155 | 156 | Q_D(QBarModelMapper); |
|
156 | 157 | d->m_orientation = orientation; |
|
157 | 158 | d->initializeBarFromModel(); |
|
158 | 159 | } |
|
159 | 160 | |
|
160 | 161 | /*! |
|
161 | 162 | Returns which section of the model is used as the data source for the first bar set |
|
162 | 163 | */ |
|
163 | 164 | int QBarModelMapper::firstBarSetSection() const |
|
164 | 165 | { |
|
165 | 166 | Q_D(const QBarModelMapper); |
|
166 | 167 | return d->m_firstBarSetSection; |
|
167 | 168 | } |
|
168 | 169 | |
|
169 | 170 | /*! |
|
170 | 171 | Sets the model section that is used as the data source for the first bar set |
|
171 | 172 | Parameter \a firstBarSetSection specifies the section of the model. |
|
172 | 173 | */ |
|
173 | 174 | void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection) |
|
174 | 175 | { |
|
175 | 176 | Q_D(QBarModelMapper); |
|
176 | 177 | d->m_firstBarSetSection = qMax(-1, firstBarSetSection); |
|
177 | 178 | d->initializeBarFromModel(); |
|
178 | 179 | } |
|
179 | 180 | |
|
180 | 181 | /*! |
|
181 | 182 | Returns which section of the model is used as the data source for the last bar set |
|
182 | 183 | */ |
|
183 | 184 | int QBarModelMapper::lastBarSetSection() const |
|
184 | 185 | { |
|
185 | 186 | Q_D(const QBarModelMapper); |
|
186 | 187 | return d->m_lastBarSetSection; |
|
187 | 188 | } |
|
188 | 189 | |
|
189 | 190 | /*! |
|
190 | 191 | Sets the model section that is used as the data source for the last bar set |
|
191 | 192 | Parameter \a lastBarSetSection specifies the section of the model. |
|
192 | 193 | */ |
|
193 | 194 | void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) |
|
194 | 195 | { |
|
195 | 196 | Q_D(QBarModelMapper); |
|
196 | 197 | d->m_lastBarSetSection = qMax(-1, lastBarSetSection); |
|
197 | 198 | d->initializeBarFromModel(); |
|
198 | 199 | } |
|
199 | 200 | |
|
200 | 201 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
201 | 202 | |
|
202 | 203 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : |
|
203 | 204 | QObject(q), |
|
204 | 205 | m_series(0), |
|
205 | 206 | m_model(0), |
|
206 | 207 | m_first(0), |
|
207 | 208 | m_count(-1), |
|
208 | 209 | m_orientation(Qt::Vertical), |
|
209 | 210 | m_firstBarSetSection(-1), |
|
210 | 211 | m_lastBarSetSection(-1), |
|
211 | 212 | m_seriesSignalsBlock(false), |
|
212 | 213 | m_modelSignalsBlock(false), |
|
213 | 214 | q_ptr(q) |
|
214 | 215 | { |
|
215 | 216 | } |
|
216 | 217 | |
|
217 | 218 | void QBarModelMapperPrivate::blockModelSignals(bool block) |
|
218 | 219 | { |
|
219 | 220 | m_modelSignalsBlock = block; |
|
220 | 221 | } |
|
221 | 222 | |
|
222 | 223 | void QBarModelMapperPrivate::blockSeriesSignals(bool block) |
|
223 | 224 | { |
|
224 | 225 | m_seriesSignalsBlock = block; |
|
225 | 226 | } |
|
226 | 227 | |
|
227 | 228 | QBarSet *QBarModelMapperPrivate::barSet(QModelIndex index) |
|
228 | 229 | { |
|
229 | 230 | if (!index.isValid()) |
|
230 | 231 | return 0; |
|
231 | 232 | |
|
232 | 233 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { |
|
233 | 234 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { |
|
234 | 235 | return m_series->barSets().at(index.column() - m_firstBarSetSection); |
|
235 | 236 | } |
|
236 | 237 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { |
|
237 | 238 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) |
|
238 | 239 | return m_series->barSets().at(index.row() - m_firstBarSetSection); |
|
239 | 240 | } |
|
240 | 241 | return 0; // This part of model has not been mapped to any slice |
|
241 | 242 | } |
|
242 | 243 | |
|
243 | 244 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) |
|
244 | 245 | { |
|
245 | 246 | if (m_count != -1 && posInBar >= m_count) |
|
246 | 247 | return QModelIndex(); // invalid |
|
247 | 248 | |
|
248 | 249 | if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection) |
|
249 | 250 | return QModelIndex(); // invalid |
|
250 | 251 | |
|
251 | 252 | if (m_orientation == Qt::Vertical) |
|
252 | 253 | return m_model->index(posInBar + m_first, barSection); |
|
253 | 254 | else |
|
254 | 255 | return m_model->index(barSection, posInBar + m_first); |
|
255 | 256 | } |
|
256 | 257 | |
|
257 | 258 | void QBarModelMapperPrivate::handleSeriesDestroyed() |
|
258 | 259 | { |
|
259 | 260 | m_series = 0; |
|
260 | 261 | } |
|
261 | 262 | |
|
262 | 263 | void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
263 | 264 | { |
|
264 | 265 | Q_UNUSED(topLeft) |
|
265 | 266 | Q_UNUSED(bottomRight) |
|
266 | 267 | |
|
267 | 268 | if (m_model == 0 || m_series == 0) |
|
268 | 269 | return; |
|
269 | 270 | |
|
270 | 271 | if (m_modelSignalsBlock) |
|
271 | 272 | return; |
|
272 | 273 | |
|
273 | 274 | blockSeriesSignals(); |
|
274 | 275 | QModelIndex index; |
|
275 | 276 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
276 | 277 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
277 | 278 | index = topLeft.sibling(row, column); |
|
278 | 279 | QBarSet *bar = barSet(index); |
|
279 | 280 | if (bar) { |
|
280 | 281 | if (m_orientation == Qt::Vertical) |
|
281 | 282 | bar->replace(row - m_first, m_model->data(index).toReal()); |
|
282 | 283 | else |
|
283 | 284 | bar->replace(column - m_first, m_model->data(index).toReal()); |
|
284 | 285 | } |
|
285 | 286 | } |
|
286 | 287 | } |
|
287 | 288 | blockSeriesSignals(false); |
|
288 | 289 | } |
|
289 | 290 | |
|
290 | 291 | void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last) |
|
291 | 292 | { |
|
292 | 293 | if (m_model == 0 || m_series == 0) |
|
293 | 294 | return; |
|
294 | 295 | |
|
295 | 296 | if (m_modelSignalsBlock) |
|
296 | 297 | return; |
|
297 | 298 | |
|
298 | 299 | blockSeriesSignals(); |
|
299 | 300 | if (orientation != m_orientation) { |
|
300 | 301 | for (int section = first; section <= last; section++) { |
|
301 | 302 | if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) { |
|
302 | 303 | QBarSet *bar = m_series->barSets().at(section - m_firstBarSetSection); |
|
303 | 304 | if (bar) |
|
304 | 305 | bar->setLabel(m_model->headerData(section, orientation).toString()); |
|
305 | 306 | } |
|
306 | 307 | } |
|
307 | 308 | } |
|
308 | 309 | blockSeriesSignals(false); |
|
309 | 310 | } |
|
310 | 311 | |
|
311 | 312 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
312 | 313 | { |
|
313 | 314 | Q_UNUSED(parent) |
|
314 | 315 | if (m_modelSignalsBlock) |
|
315 | 316 | return; |
|
316 | 317 | |
|
317 | 318 | blockSeriesSignals(); |
|
318 | 319 | if (m_orientation == Qt::Vertical) |
|
319 | 320 | insertData(start, end); |
|
320 | 321 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
321 | 322 | initializeBarFromModel(); |
|
322 | 323 | blockSeriesSignals(false); |
|
323 | 324 | } |
|
324 | 325 | |
|
325 | 326 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
326 | 327 | { |
|
327 | 328 | Q_UNUSED(parent) |
|
328 | 329 | if (m_modelSignalsBlock) |
|
329 | 330 | return; |
|
330 | 331 | |
|
331 | 332 | blockSeriesSignals(); |
|
332 | 333 | if (m_orientation == Qt::Vertical) |
|
333 | 334 | removeData(start, end); |
|
334 | 335 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
335 | 336 | initializeBarFromModel(); |
|
336 | 337 | blockSeriesSignals(false); |
|
337 | 338 | } |
|
338 | 339 | |
|
339 | 340 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
340 | 341 | { |
|
341 | 342 | Q_UNUSED(parent) |
|
342 | 343 | if (m_modelSignalsBlock) |
|
343 | 344 | return; |
|
344 | 345 | |
|
345 | 346 | blockSeriesSignals(); |
|
346 | 347 | if (m_orientation == Qt::Horizontal) |
|
347 | 348 | insertData(start, end); |
|
348 | 349 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
349 | 350 | initializeBarFromModel(); |
|
350 | 351 | blockSeriesSignals(false); |
|
351 | 352 | } |
|
352 | 353 | |
|
353 | 354 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
354 | 355 | { |
|
355 | 356 | Q_UNUSED(parent) |
|
356 | 357 | if (m_modelSignalsBlock) |
|
357 | 358 | return; |
|
358 | 359 | |
|
359 | 360 | blockSeriesSignals(); |
|
360 | 361 | if (m_orientation == Qt::Horizontal) |
|
361 | 362 | removeData(start, end); |
|
362 | 363 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
363 | 364 | initializeBarFromModel(); |
|
364 | 365 | blockSeriesSignals(false); |
|
365 | 366 | } |
|
366 | 367 | |
|
367 | 368 | void QBarModelMapperPrivate::handleModelDestroyed() |
|
368 | 369 | { |
|
369 | 370 | m_model = 0; |
|
370 | 371 | } |
|
371 | 372 | |
|
372 | 373 | void QBarModelMapperPrivate::insertData(int start, int end) |
|
373 | 374 | { |
|
374 | 375 | Q_UNUSED(end) |
|
375 | 376 | Q_UNUSED(start) |
|
376 | 377 | Q_UNUSED(end) |
|
377 | 378 | // Currently barchart needs to be fully recalculated when change is made. |
|
378 | 379 | // Re-initialize |
|
379 | 380 | initializeBarFromModel(); |
|
380 | 381 | } |
|
381 | 382 | |
|
382 | 383 | void QBarModelMapperPrivate::removeData(int start, int end) |
|
383 | 384 | { |
|
384 | 385 | Q_UNUSED(end) |
|
385 | 386 | Q_UNUSED(start) |
|
386 | 387 | Q_UNUSED(end) |
|
387 | 388 | // Currently barchart needs to be fully recalculated when change is made. |
|
388 | 389 | // Re-initialize |
|
389 | 390 | initializeBarFromModel(); |
|
390 | 391 | } |
|
391 | 392 | |
|
392 | 393 | void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet *> sets) |
|
393 | 394 | { |
|
394 | 395 | if (m_seriesSignalsBlock) |
|
395 | 396 | return; |
|
396 | 397 | |
|
397 | 398 | if (sets.count() == 0) |
|
398 | 399 | return; |
|
399 | 400 | |
|
400 | 401 | int firstIndex = m_series->barSets().indexOf(sets.at(0)); |
|
401 | 402 | if (firstIndex == -1) |
|
402 | 403 | return; |
|
403 | 404 | |
|
404 | 405 | int maxCount = 0; |
|
405 | 406 | for (int i = 0; i < sets.count(); i++) { |
|
406 | 407 | if (sets.at(i)->count() > m_count) |
|
407 | 408 | maxCount = sets.at(i)->count(); |
|
408 | 409 | } |
|
409 | 410 | |
|
410 | 411 | if (m_count != -1 && m_count < maxCount) |
|
411 | 412 | m_count = maxCount; |
|
412 | 413 | |
|
413 | 414 | m_lastBarSetSection += sets.count(); |
|
414 | 415 | |
|
415 | 416 | blockModelSignals(); |
|
416 | 417 | int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first; |
|
417 | 418 | if (maxCount > modelCapacity) { |
|
418 | 419 | if (m_orientation == Qt::Vertical) |
|
419 | 420 | m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity); |
|
420 | 421 | else |
|
421 | 422 | m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity); |
|
422 | 423 | } |
|
423 | 424 | |
|
424 | 425 | if (m_orientation == Qt::Vertical) |
|
425 | 426 | m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count()); |
|
426 | 427 | else |
|
427 | 428 | m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count()); |
|
428 | 429 | |
|
429 | 430 | |
|
430 | 431 | for (int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) { |
|
431 | 432 | m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label()); |
|
432 | 433 | for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++) |
|
433 | 434 | m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j)); |
|
434 | 435 | } |
|
435 | 436 | blockModelSignals(false); |
|
436 | 437 | initializeBarFromModel(); |
|
437 | 438 | } |
|
438 | 439 | |
|
439 | 440 | void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet *> sets) |
|
440 | 441 | { |
|
441 | 442 | if (m_seriesSignalsBlock) |
|
442 | 443 | return; |
|
443 | 444 | |
|
444 | 445 | if (sets.count() == 0) |
|
445 | 446 | return; |
|
446 | 447 | |
|
447 | 448 | int firstIndex = m_barSets.indexOf(sets.at(0)); |
|
448 | 449 | if (firstIndex == -1) |
|
449 | 450 | return; |
|
450 | 451 | |
|
451 | 452 | m_lastBarSetSection -= sets.count(); |
|
452 | 453 | |
|
453 | 454 | for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--) |
|
454 | 455 | m_barSets.removeAt(i); |
|
455 | 456 | |
|
456 | 457 | blockModelSignals(); |
|
457 | 458 | if (m_orientation == Qt::Vertical) |
|
458 | 459 | m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count()); |
|
459 | 460 | else |
|
460 | 461 | m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count()); |
|
461 | 462 | blockModelSignals(false); |
|
462 | 463 | initializeBarFromModel(); |
|
463 | 464 | } |
|
464 | 465 | |
|
465 | 466 | void QBarModelMapperPrivate::valuesAdded(int index, int count) |
|
466 | 467 | { |
|
467 | 468 | if (m_seriesSignalsBlock) |
|
468 | 469 | return; |
|
469 | 470 | |
|
470 | 471 | if (m_count != -1) |
|
471 | 472 | m_count += count; |
|
472 | 473 | |
|
473 | 474 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
474 | 475 | |
|
475 | 476 | blockModelSignals(); |
|
476 | 477 | if (m_orientation == Qt::Vertical) |
|
477 | 478 | m_model->insertRows(index + m_first, count); |
|
478 | 479 | else |
|
479 | 480 | m_model->insertColumns(index + m_first, count); |
|
480 | 481 | |
|
481 | 482 | for (int j = index; j < index + count; j++) |
|
482 | 483 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j)); |
|
483 | 484 | |
|
484 | 485 | blockModelSignals(false); |
|
485 | 486 | initializeBarFromModel(); |
|
486 | 487 | } |
|
487 | 488 | |
|
488 | 489 | void QBarModelMapperPrivate::valuesRemoved(int index, int count) |
|
489 | 490 | { |
|
490 | 491 | if (m_seriesSignalsBlock) |
|
491 | 492 | return; |
|
492 | 493 | |
|
493 | 494 | if (m_count != -1) |
|
494 | 495 | m_count -= count; |
|
495 | 496 | |
|
496 | 497 | blockModelSignals(); |
|
497 | 498 | if (m_orientation == Qt::Vertical) |
|
498 | 499 | m_model->removeRows(index + m_first, count); |
|
499 | 500 | else |
|
500 | 501 | m_model->removeColumns(index + m_first, count); |
|
501 | 502 | |
|
502 | 503 | blockModelSignals(false); |
|
503 | 504 | initializeBarFromModel(); |
|
504 | 505 | } |
|
505 | 506 | |
|
506 | 507 | void QBarModelMapperPrivate::barLabelChanged() |
|
507 | 508 | { |
|
508 | 509 | if (m_seriesSignalsBlock) |
|
509 | 510 | return; |
|
510 | 511 | |
|
511 | 512 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
512 | 513 | |
|
513 | 514 | blockModelSignals(); |
|
514 | 515 | m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label()); |
|
515 | 516 | blockModelSignals(false); |
|
516 | 517 | initializeBarFromModel(); |
|
517 | 518 | } |
|
518 | 519 | |
|
519 | 520 | void QBarModelMapperPrivate::barValueChanged(int index) |
|
520 | 521 | { |
|
521 | 522 | if (m_seriesSignalsBlock) |
|
522 | 523 | return; |
|
523 | 524 | |
|
524 | 525 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
525 | 526 | |
|
526 | 527 | blockModelSignals(); |
|
527 | 528 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index)); |
|
528 | 529 | blockModelSignals(false); |
|
529 | 530 | initializeBarFromModel(); |
|
530 | 531 | } |
|
531 | 532 | |
|
532 | 533 | void QBarModelMapperPrivate::initializeBarFromModel() |
|
533 | 534 | { |
|
534 | 535 | if (m_model == 0 || m_series == 0) |
|
535 | 536 | return; |
|
536 | 537 | |
|
537 | 538 | blockSeriesSignals(); |
|
538 | 539 | // clear current content |
|
539 | 540 | m_series->clear(); |
|
540 | 541 | m_barSets.clear(); |
|
541 | 542 | |
|
542 | 543 | // create the initial bar sets |
|
543 | 544 | for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { |
|
544 | 545 | int posInBar = 0; |
|
545 | 546 | QModelIndex barIndex = barModelIndex(i, posInBar); |
|
546 | 547 | // check if there is such model index |
|
547 | 548 | if (barIndex.isValid()) { |
|
548 | 549 | QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString()); |
|
549 | 550 | while (barIndex.isValid()) { |
|
550 | 551 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); |
|
551 | 552 | posInBar++; |
|
552 | 553 | barIndex = barModelIndex(i, posInBar); |
|
553 | 554 | } |
|
554 | 555 | connect(barSet, SIGNAL(valuesAdded(int,int)), this, SLOT(valuesAdded(int,int))); |
|
555 | 556 | connect(barSet, SIGNAL(valuesRemoved(int,int)), this, SLOT(valuesRemoved(int,int))); |
|
556 | 557 | connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int))); |
|
557 | 558 | connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged())); |
|
558 | 559 | m_series->append(barSet); |
|
559 | 560 | m_barSets.append(barSet); |
|
560 | 561 | } else { |
|
561 | 562 | break; |
|
562 | 563 | } |
|
563 | 564 | } |
|
564 | 565 | blockSeriesSignals(false); |
|
565 | 566 | } |
|
566 | 567 | |
|
567 | 568 | #include "moc_qbarmodelmapper.cpp" |
|
568 | 569 | #include "moc_qbarmodelmapper_p.cpp" |
|
569 | 570 | |
|
570 | 571 | QT_CHARTS_END_NAMESPACE |
@@ -1,80 +1,80 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QBARMODELMAPPER_H |
|
31 | 31 | #define QBARMODELMAPPER_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtCore/QObject> |
|
35 | 35 | |
|
36 | 36 | QT_BEGIN_NAMESPACE |
|
37 | 37 | class QAbstractItemModel; |
|
38 | 38 | QT_END_NAMESPACE |
|
39 | 39 | |
|
40 | 40 | QT_CHARTS_BEGIN_NAMESPACE |
|
41 | 41 | |
|
42 | 42 | class QBarModelMapperPrivate; |
|
43 | 43 | class QAbstractBarSeries; |
|
44 | 44 | |
|
45 | 45 | class QT_CHARTS_EXPORT QBarModelMapper : public QObject |
|
46 | 46 | { |
|
47 | 47 | Q_OBJECT |
|
48 | 48 | |
|
49 | 49 | protected: |
|
50 |
explicit QBarModelMapper(QObject *parent = |
|
|
50 | explicit QBarModelMapper(QObject *parent = Q_NULLPTR); | |
|
51 | 51 | |
|
52 | 52 | QAbstractItemModel *model() const; |
|
53 | 53 | void setModel(QAbstractItemModel *model); |
|
54 | 54 | |
|
55 | 55 | QAbstractBarSeries *series() const; |
|
56 | 56 | void setSeries(QAbstractBarSeries *series); |
|
57 | 57 | |
|
58 | 58 | int first() const; |
|
59 | 59 | void setFirst(int first); |
|
60 | 60 | |
|
61 | 61 | int count() const; |
|
62 | 62 | void setCount(int count); |
|
63 | 63 | |
|
64 | 64 | int firstBarSetSection() const; |
|
65 | 65 | void setFirstBarSetSection(int firstBarSetSection); |
|
66 | 66 | |
|
67 | 67 | int lastBarSetSection() const; |
|
68 | 68 | void setLastBarSetSection(int lastBarSetSection); |
|
69 | 69 | |
|
70 | 70 | Qt::Orientation orientation() const; |
|
71 | 71 | void setOrientation(Qt::Orientation orientation); |
|
72 | 72 | |
|
73 | 73 | protected: |
|
74 | 74 | QBarModelMapperPrivate * const d_ptr; |
|
75 | 75 | Q_DECLARE_PRIVATE(QBarModelMapper) |
|
76 | 76 | }; |
|
77 | 77 | |
|
78 | 78 | QT_CHARTS_END_NAMESPACE |
|
79 | 79 | |
|
80 | 80 | #endif // QBARMODELMAPPER_H |
@@ -1,131 +1,131 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QBARSET_H |
|
31 | 31 | #define QBARSET_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtGui/QPen> |
|
35 | 35 | #include <QtGui/QBrush> |
|
36 | 36 | #include <QtGui/QFont> |
|
37 | 37 | |
|
38 | 38 | QT_CHARTS_BEGIN_NAMESPACE |
|
39 | 39 | class QBarSetPrivate; |
|
40 | 40 | |
|
41 | 41 | class QT_CHARTS_EXPORT QBarSet : public QObject |
|
42 | 42 | { |
|
43 | 43 | Q_OBJECT |
|
44 | 44 | Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) |
|
45 | 45 | Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) |
|
46 | 46 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) |
|
47 | 47 | Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged) |
|
48 | 48 | Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged) |
|
49 | 49 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
50 | 50 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
|
51 | 51 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) |
|
52 | 52 | |
|
53 | 53 | public: |
|
54 |
explicit QBarSet(const QString label, QObject *parent = |
|
|
54 | explicit QBarSet(const QString label, QObject *parent = Q_NULLPTR); | |
|
55 | 55 | virtual ~QBarSet(); |
|
56 | 56 | |
|
57 | 57 | void setLabel(const QString label); |
|
58 | 58 | QString label() const; |
|
59 | 59 | |
|
60 | 60 | void append(const qreal value); |
|
61 | 61 | void append(const QList<qreal> &values); |
|
62 | 62 | |
|
63 | 63 | QBarSet &operator << (const qreal &value); |
|
64 | 64 | |
|
65 | 65 | void insert(const int index, const qreal value); |
|
66 | 66 | void remove(const int index, const int count = 1); |
|
67 | 67 | void replace(const int index, const qreal value); |
|
68 | 68 | qreal at(const int index) const; |
|
69 | 69 | qreal operator [](const int index) const; |
|
70 | 70 | int count() const; |
|
71 | 71 | qreal sum() const; |
|
72 | 72 | |
|
73 | 73 | void setPen(const QPen &pen); |
|
74 | 74 | QPen pen() const; |
|
75 | 75 | |
|
76 | 76 | void setBrush(const QBrush &brush); |
|
77 | 77 | QBrush brush() const; |
|
78 | 78 | |
|
79 | 79 | void setLabelBrush(const QBrush &brush); |
|
80 | 80 | QBrush labelBrush() const; |
|
81 | 81 | |
|
82 | 82 | void setLabelFont(const QFont &font); |
|
83 | 83 | QFont labelFont() const; |
|
84 | 84 | |
|
85 | 85 | QColor color(); |
|
86 | 86 | void setColor(QColor color); |
|
87 | 87 | |
|
88 | 88 | QColor borderColor(); |
|
89 | 89 | void setBorderColor(QColor color); |
|
90 | 90 | |
|
91 | 91 | QColor labelColor(); |
|
92 | 92 | void setLabelColor(QColor color); |
|
93 | 93 | |
|
94 | 94 | Q_SIGNALS: |
|
95 | 95 | void clicked(int index); |
|
96 | 96 | void hovered(bool status, int index); |
|
97 | 97 | void pressed(int index); |
|
98 | 98 | void released(int index); |
|
99 | 99 | void doubleClicked(int index); |
|
100 | 100 | void penChanged(); |
|
101 | 101 | void brushChanged(); |
|
102 | 102 | void labelChanged(); |
|
103 | 103 | void labelBrushChanged(); |
|
104 | 104 | void labelFontChanged(); |
|
105 | 105 | void colorChanged(QColor color); |
|
106 | 106 | void borderColorChanged(QColor color); |
|
107 | 107 | void labelColorChanged(QColor color); |
|
108 | 108 | |
|
109 | 109 | void valuesAdded(int index, int count); |
|
110 | 110 | void valuesRemoved(int index, int count); |
|
111 | 111 | void valueChanged(int index); |
|
112 | 112 | |
|
113 | 113 | private: |
|
114 | 114 | QScopedPointer<QBarSetPrivate> d_ptr; |
|
115 | 115 | Q_DISABLE_COPY(QBarSet) |
|
116 | 116 | friend class QAbstractBarSeries; |
|
117 | 117 | friend class BarLegendMarker; |
|
118 | 118 | friend class AbstractBarChartItem; |
|
119 | 119 | friend class QAbstractBarSeriesPrivate; |
|
120 | 120 | friend class StackedBarChartItem; |
|
121 | 121 | friend class PercentBarChartItem; |
|
122 | 122 | friend class BarChartItem; |
|
123 | 123 | friend class HorizontalBarChartItem; |
|
124 | 124 | friend class HorizontalStackedBarChartItem; |
|
125 | 125 | friend class HorizontalPercentBarChartItem; |
|
126 | 126 | friend class BoxPlotChartItem; |
|
127 | 127 | }; |
|
128 | 128 | |
|
129 | 129 | QT_CHARTS_END_NAMESPACE |
|
130 | 130 | |
|
131 | 131 | #endif // QBARSET_H |
@@ -1,79 +1,79 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QHBARMODELMAPPER_H |
|
31 | 31 | #define QHBARMODELMAPPER_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QBarModelMapper> |
|
34 | 34 | |
|
35 | 35 | QT_CHARTS_BEGIN_NAMESPACE |
|
36 | 36 | /* Comment line for syncqt to generate the fwd-include correctly, due to QTBUG-22432 */ |
|
37 | 37 | class QT_CHARTS_EXPORT QHBarModelMapper : public QBarModelMapper |
|
38 | 38 | { |
|
39 | 39 | Q_OBJECT |
|
40 | 40 | Q_PROPERTY(QAbstractBarSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) |
|
41 | 41 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced) |
|
42 | 42 | Q_PROPERTY(int firstBarSetRow READ firstBarSetRow WRITE setFirstBarSetRow NOTIFY firstBarSetRowChanged) |
|
43 | 43 | Q_PROPERTY(int lastBarSetRow READ lastBarSetRow WRITE setLastBarSetRow NOTIFY lastBarSetRowChanged) |
|
44 | 44 | Q_PROPERTY(int firstColumn READ firstColumn WRITE setFirstColumn NOTIFY firstColumnChanged) |
|
45 | 45 | Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount NOTIFY columnCountChanged) |
|
46 | 46 | |
|
47 | 47 | public: |
|
48 |
explicit QHBarModelMapper(QObject *parent = |
|
|
48 | explicit QHBarModelMapper(QObject *parent = Q_NULLPTR); | |
|
49 | 49 | |
|
50 | 50 | QAbstractItemModel *model() const; |
|
51 | 51 | void setModel(QAbstractItemModel *model); |
|
52 | 52 | |
|
53 | 53 | QAbstractBarSeries *series() const; |
|
54 | 54 | void setSeries(QAbstractBarSeries *series); |
|
55 | 55 | |
|
56 | 56 | int firstBarSetRow() const; |
|
57 | 57 | void setFirstBarSetRow(int firstBarSetRow); |
|
58 | 58 | |
|
59 | 59 | int lastBarSetRow() const; |
|
60 | 60 | void setLastBarSetRow(int lastBarSetRow); |
|
61 | 61 | |
|
62 | 62 | int firstColumn() const; |
|
63 | 63 | void setFirstColumn(int firstColumn); |
|
64 | 64 | |
|
65 | 65 | int columnCount() const; |
|
66 | 66 | void setColumnCount(int columnCount); |
|
67 | 67 | |
|
68 | 68 | Q_SIGNALS: |
|
69 | 69 | void seriesReplaced(); |
|
70 | 70 | void modelReplaced(); |
|
71 | 71 | void firstBarSetRowChanged(); |
|
72 | 72 | void lastBarSetRowChanged(); |
|
73 | 73 | void firstColumnChanged(); |
|
74 | 74 | void columnCountChanged(); |
|
75 | 75 | }; |
|
76 | 76 | |
|
77 | 77 | QT_CHARTS_END_NAMESPACE |
|
78 | 78 | |
|
79 | 79 | #endif // QHBARMODELMAPPER_H |
@@ -1,79 +1,79 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QVBARMODELMAPPER_H |
|
31 | 31 | #define QVBARMODELMAPPER_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QBarModelMapper> |
|
34 | 34 | |
|
35 | 35 | QT_CHARTS_BEGIN_NAMESPACE |
|
36 | 36 | /* Comment line for syncqt to generate the fwd-include correctly, due to QTBUG-22432 */ |
|
37 | 37 | class QT_CHARTS_EXPORT QVBarModelMapper : public QBarModelMapper |
|
38 | 38 | { |
|
39 | 39 | Q_OBJECT |
|
40 | 40 | Q_PROPERTY(QAbstractBarSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) |
|
41 | 41 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced) |
|
42 | 42 | Q_PROPERTY(int firstBarSetColumn READ firstBarSetColumn WRITE setFirstBarSetColumn NOTIFY firstBarSetColumnChanged) |
|
43 | 43 | Q_PROPERTY(int lastBarSetColumn READ lastBarSetColumn WRITE setLastBarSetColumn NOTIFY lastBarSetColumnChanged) |
|
44 | 44 | Q_PROPERTY(int firstRow READ firstRow WRITE setFirstRow NOTIFY firstRowChanged) |
|
45 | 45 | Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount NOTIFY rowCountChanged) |
|
46 | 46 | |
|
47 | 47 | public: |
|
48 |
explicit QVBarModelMapper(QObject *parent = |
|
|
48 | explicit QVBarModelMapper(QObject *parent = Q_NULLPTR); | |
|
49 | 49 | |
|
50 | 50 | QAbstractItemModel *model() const; |
|
51 | 51 | void setModel(QAbstractItemModel *model); |
|
52 | 52 | |
|
53 | 53 | QAbstractBarSeries *series() const; |
|
54 | 54 | void setSeries(QAbstractBarSeries *series); |
|
55 | 55 | |
|
56 | 56 | int firstBarSetColumn() const; |
|
57 | 57 | void setFirstBarSetColumn(int firstBarSetColumn); |
|
58 | 58 | |
|
59 | 59 | int lastBarSetColumn() const; |
|
60 | 60 | void setLastBarSetColumn(int lastBarSetColumn); |
|
61 | 61 | |
|
62 | 62 | int firstRow() const; |
|
63 | 63 | void setFirstRow(int firstRow); |
|
64 | 64 | |
|
65 | 65 | int rowCount() const; |
|
66 | 66 | void setRowCount(int rowCount); |
|
67 | 67 | |
|
68 | 68 | Q_SIGNALS: |
|
69 | 69 | void seriesReplaced(); |
|
70 | 70 | void modelReplaced(); |
|
71 | 71 | void firstBarSetColumnChanged(); |
|
72 | 72 | void lastBarSetColumnChanged(); |
|
73 | 73 | void firstRowChanged(); |
|
74 | 74 | void rowCountChanged(); |
|
75 | 75 | }; |
|
76 | 76 | |
|
77 | 77 | QT_CHARTS_END_NAMESPACE |
|
78 | 78 | |
|
79 | 79 | #endif // QVBARMODELMAPPER_H |
@@ -1,54 +1,54 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QBARSERIES_H |
|
31 | 31 | #define QBARSERIES_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QAbstractBarSeries> |
|
34 | 34 | |
|
35 | 35 | QT_CHARTS_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | class QBarSeriesPrivate; |
|
38 | 38 | |
|
39 | 39 | class QT_CHARTS_EXPORT QBarSeries : public QAbstractBarSeries |
|
40 | 40 | { |
|
41 | 41 | Q_OBJECT |
|
42 | 42 | public: |
|
43 |
explicit QBarSeries(QObject *parent = |
|
|
43 | explicit QBarSeries(QObject *parent = Q_NULLPTR); | |
|
44 | 44 | ~QBarSeries(); |
|
45 | 45 | QAbstractSeries::SeriesType type() const; |
|
46 | 46 | |
|
47 | 47 | private: |
|
48 | 48 | Q_DECLARE_PRIVATE(QBarSeries) |
|
49 | 49 | Q_DISABLE_COPY(QBarSeries) |
|
50 | 50 | }; |
|
51 | 51 | |
|
52 | 52 | QT_CHARTS_END_NAMESPACE |
|
53 | 53 | |
|
54 | 54 | #endif // QBARSERIES_H |
@@ -1,55 +1,55 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QPERCENTBARSERIES_H |
|
31 | 31 | #define QPERCENTBARSERIES_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCore/QStringList> |
|
34 | 34 | #include <QtCharts/QAbstractBarSeries> |
|
35 | 35 | |
|
36 | 36 | QT_CHARTS_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | class QPercentBarSeriesPrivate; |
|
39 | 39 | |
|
40 | 40 | class QT_CHARTS_EXPORT QPercentBarSeries : public QAbstractBarSeries |
|
41 | 41 | { |
|
42 | 42 | Q_OBJECT |
|
43 | 43 | public: |
|
44 |
explicit QPercentBarSeries(QObject *parent = |
|
|
44 | explicit QPercentBarSeries(QObject *parent = Q_NULLPTR); | |
|
45 | 45 | ~QPercentBarSeries(); |
|
46 | 46 | QAbstractSeries::SeriesType type() const; |
|
47 | 47 | |
|
48 | 48 | private: |
|
49 | 49 | Q_DECLARE_PRIVATE(QPercentBarSeries) |
|
50 | 50 | Q_DISABLE_COPY(QPercentBarSeries) |
|
51 | 51 | }; |
|
52 | 52 | |
|
53 | 53 | QT_CHARTS_END_NAMESPACE |
|
54 | 54 | |
|
55 | 55 | #endif // QPERCENTBARSERIES_H |
@@ -1,55 +1,55 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QSTACKEDBARSERIES_H |
|
31 | 31 | #define QSTACKEDBARSERIES_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCore/QStringList> |
|
34 | 34 | #include <QtCharts/QAbstractBarSeries> |
|
35 | 35 | |
|
36 | 36 | QT_CHARTS_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | class QStackedBarSeriesPrivate; |
|
39 | 39 | |
|
40 | 40 | class QT_CHARTS_EXPORT QStackedBarSeries : public QAbstractBarSeries |
|
41 | 41 | { |
|
42 | 42 | Q_OBJECT |
|
43 | 43 | public: |
|
44 |
explicit QStackedBarSeries(QObject *parent = |
|
|
44 | explicit QStackedBarSeries(QObject *parent = Q_NULLPTR); | |
|
45 | 45 | ~QStackedBarSeries(); |
|
46 | 46 | QAbstractSeries::SeriesType type() const; |
|
47 | 47 | |
|
48 | 48 | private: |
|
49 | 49 | Q_DECLARE_PRIVATE(QStackedBarSeries) |
|
50 | 50 | Q_DISABLE_COPY(QStackedBarSeries) |
|
51 | 51 | }; |
|
52 | 52 | |
|
53 | 53 | QT_CHARTS_END_NAMESPACE |
|
54 | 54 | |
|
55 | 55 | #endif // QSTACKEDBARSERIES_H |
@@ -1,498 +1,499 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include <QtCharts/QBoxPlotModelMapper> |
|
31 | 31 | #include <private/qboxplotmodelmapper_p.h> |
|
32 | 32 | #include <QtCharts/QBoxPlotSeries> |
|
33 | 33 | #include <QtCharts/QBoxSet> |
|
34 | 34 | #include <QtCharts/QChart> |
|
35 | 35 | #include <QtCore/QAbstractItemModel> |
|
36 | 36 | |
|
37 | 37 | QT_CHARTS_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | QBoxPlotModelMapper::QBoxPlotModelMapper(QObject *parent) : |
|
40 | 40 | QObject(parent), |
|
41 | 41 | d_ptr(new QBoxPlotModelMapperPrivate(this)) |
|
42 | 42 | { |
|
43 | 43 | } |
|
44 | 44 | |
|
45 | 45 | QAbstractItemModel *QBoxPlotModelMapper::model() const |
|
46 | 46 | { |
|
47 | 47 | Q_D(const QBoxPlotModelMapper); |
|
48 | 48 | return d->m_model; |
|
49 | 49 | } |
|
50 | 50 | |
|
51 | 51 | void QBoxPlotModelMapper::setModel(QAbstractItemModel *model) |
|
52 | 52 | { |
|
53 | 53 | if (model == 0) |
|
54 | 54 | return; |
|
55 | 55 | |
|
56 | 56 | Q_D(QBoxPlotModelMapper); |
|
57 | 57 | if (d->m_model) |
|
58 | 58 | disconnect(d->m_model, 0, d, 0); |
|
59 | 59 | |
|
60 | 60 | d->m_model = model; |
|
61 | 61 | d->initializeBoxFromModel(); |
|
62 | 62 | // connect signals from the model |
|
63 | connect(d->m_model, SIGNAL(modelReset()), d, SLOT(initializeBoxFromModel())); | |
|
63 | 64 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
64 | 65 | connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int))); |
|
65 | 66 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
66 | 67 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
67 | 68 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
68 | 69 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); |
|
69 | 70 | connect(d->m_model, SIGNAL(destroyed()), d, SLOT(handleModelDestroyed())); |
|
70 | 71 | } |
|
71 | 72 | |
|
72 | 73 | QBoxPlotSeries *QBoxPlotModelMapper::series() const |
|
73 | 74 | { |
|
74 | 75 | Q_D(const QBoxPlotModelMapper); |
|
75 | 76 | return d->m_series; |
|
76 | 77 | } |
|
77 | 78 | |
|
78 | 79 | void QBoxPlotModelMapper::setSeries(QBoxPlotSeries *series) |
|
79 | 80 | { |
|
80 | 81 | Q_D(QBoxPlotModelMapper); |
|
81 | 82 | if (d->m_series) |
|
82 | 83 | disconnect(d->m_series, 0, d, 0); |
|
83 | 84 | |
|
84 | 85 | if (series == 0) |
|
85 | 86 | return; |
|
86 | 87 | |
|
87 | 88 | d->m_series = series; |
|
88 | 89 | d->initializeBoxFromModel(); |
|
89 | 90 | // connect the signals from the series |
|
90 | 91 | connect(d->m_series, SIGNAL(boxsetsAdded(QList<QBoxSet *>)), d, SLOT(boxSetsAdded(QList<QBoxSet *>))); |
|
91 | 92 | connect(d->m_series, SIGNAL(boxsetsRemoved(QList<QBoxSet *>)), d, SLOT(boxSetsRemoved(QList<QBoxSet *>))); |
|
92 | 93 | connect(d->m_series, SIGNAL(destroyed()), d, SLOT(handleSeriesDestroyed())); |
|
93 | 94 | } |
|
94 | 95 | |
|
95 | 96 | /*! |
|
96 | 97 | Returns which row/column of the model contains the first values of the QBoxSets in the series. |
|
97 | 98 | The default value is 0. |
|
98 | 99 | */ |
|
99 | 100 | int QBoxPlotModelMapper::first() const |
|
100 | 101 | { |
|
101 | 102 | Q_D(const QBoxPlotModelMapper); |
|
102 | 103 | return d->m_first; |
|
103 | 104 | } |
|
104 | 105 | |
|
105 | 106 | /*! |
|
106 | 107 | Sets which row/column of the model contains the \a first values of the QBoxSets in the series. |
|
107 | 108 | The default value is 0. |
|
108 | 109 | */ |
|
109 | 110 | void QBoxPlotModelMapper::setFirst(int first) |
|
110 | 111 | { |
|
111 | 112 | Q_D(QBoxPlotModelMapper); |
|
112 | 113 | d->m_first = qMax(first, 0); |
|
113 | 114 | d->initializeBoxFromModel(); |
|
114 | 115 | } |
|
115 | 116 | |
|
116 | 117 | /*! |
|
117 | 118 | Returns the number of rows/columns of the model that are mapped as the data for QBoxPlotSeries |
|
118 | 119 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
119 | 120 | */ |
|
120 | 121 | int QBoxPlotModelMapper::count() const |
|
121 | 122 | { |
|
122 | 123 | Q_D(const QBoxPlotModelMapper); |
|
123 | 124 | return d->m_count; |
|
124 | 125 | } |
|
125 | 126 | |
|
126 | 127 | /*! |
|
127 | 128 | Sets the \a count of rows/columns of the model that are mapped as the data for QBoxPlotSeries |
|
128 | 129 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
129 | 130 | */ |
|
130 | 131 | void QBoxPlotModelMapper::setCount(int count) |
|
131 | 132 | { |
|
132 | 133 | Q_D(QBoxPlotModelMapper); |
|
133 | 134 | d->m_count = qMax(count, -1); |
|
134 | 135 | d->initializeBoxFromModel(); |
|
135 | 136 | } |
|
136 | 137 | |
|
137 | 138 | /*! |
|
138 | 139 | Returns the orientation that is used when QBoxPlotModelMapper accesses the model. |
|
139 | 140 | This means whether the consecutive values of the box-and-whiskers set are read from row (Qt::Horizontal) |
|
140 | 141 | or from columns (Qt::Vertical) |
|
141 | 142 | */ |
|
142 | 143 | Qt::Orientation QBoxPlotModelMapper::orientation() const |
|
143 | 144 | { |
|
144 | 145 | Q_D(const QBoxPlotModelMapper); |
|
145 | 146 | return d->m_orientation; |
|
146 | 147 | } |
|
147 | 148 | |
|
148 | 149 | /*! |
|
149 | 150 | Returns the \a orientation that is used when QBoxPlotModelMapper accesses the model. |
|
150 | 151 | This mean whether the consecutive values of the box-and-whiskers set are read from row (Qt::Horizontal) |
|
151 | 152 | or from columns (Qt::Vertical) |
|
152 | 153 | */ |
|
153 | 154 | void QBoxPlotModelMapper::setOrientation(Qt::Orientation orientation) |
|
154 | 155 | { |
|
155 | 156 | Q_D(QBoxPlotModelMapper); |
|
156 | 157 | d->m_orientation = orientation; |
|
157 | 158 | d->initializeBoxFromModel(); |
|
158 | 159 | } |
|
159 | 160 | |
|
160 | 161 | /*! |
|
161 | 162 | Returns which section of the model is used as the data source for the first box set |
|
162 | 163 | */ |
|
163 | 164 | int QBoxPlotModelMapper::firstBoxSetSection() const |
|
164 | 165 | { |
|
165 | 166 | Q_D(const QBoxPlotModelMapper); |
|
166 | 167 | return d->m_firstBoxSetSection; |
|
167 | 168 | } |
|
168 | 169 | |
|
169 | 170 | /*! |
|
170 | 171 | Sets the model section that is used as the data source for the first box set |
|
171 | 172 | Parameter \a firstBoxSetSection specifies the section of the model. |
|
172 | 173 | */ |
|
173 | 174 | void QBoxPlotModelMapper::setFirstBoxSetSection(int firstBoxSetSection) |
|
174 | 175 | { |
|
175 | 176 | Q_D(QBoxPlotModelMapper); |
|
176 | 177 | d->m_firstBoxSetSection = qMax(-1, firstBoxSetSection); |
|
177 | 178 | d->initializeBoxFromModel(); |
|
178 | 179 | } |
|
179 | 180 | |
|
180 | 181 | /*! |
|
181 | 182 | Returns which section of the model is used as the data source for the last box set |
|
182 | 183 | */ |
|
183 | 184 | int QBoxPlotModelMapper::lastBoxSetSection() const |
|
184 | 185 | { |
|
185 | 186 | Q_D(const QBoxPlotModelMapper); |
|
186 | 187 | return d->m_lastBoxSetSection; |
|
187 | 188 | } |
|
188 | 189 | |
|
189 | 190 | /*! |
|
190 | 191 | Sets the model section that is used as the data source for the last box set |
|
191 | 192 | Parameter \a lastBoxSetSection specifies the section of the model. |
|
192 | 193 | */ |
|
193 | 194 | void QBoxPlotModelMapper::setLastBoxSetSection(int lastBoxSetSection) |
|
194 | 195 | { |
|
195 | 196 | Q_D(QBoxPlotModelMapper); |
|
196 | 197 | d->m_lastBoxSetSection = qMax(-1, lastBoxSetSection); |
|
197 | 198 | d->initializeBoxFromModel(); |
|
198 | 199 | } |
|
199 | 200 | |
|
200 | 201 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
201 | 202 | |
|
202 | 203 | QBoxPlotModelMapperPrivate::QBoxPlotModelMapperPrivate(QBoxPlotModelMapper *q) : |
|
203 | 204 | QObject(q), |
|
204 | 205 | m_series(0), |
|
205 | 206 | m_model(0), |
|
206 | 207 | m_first(0), |
|
207 | 208 | m_count(-1), |
|
208 | 209 | m_orientation(Qt::Vertical), |
|
209 | 210 | m_firstBoxSetSection(-1), |
|
210 | 211 | m_lastBoxSetSection(-1), |
|
211 | 212 | m_seriesSignalsBlock(false), |
|
212 | 213 | m_modelSignalsBlock(false), |
|
213 | 214 | q_ptr(q) |
|
214 | 215 | { |
|
215 | 216 | } |
|
216 | 217 | |
|
217 | 218 | void QBoxPlotModelMapperPrivate::blockModelSignals(bool block) |
|
218 | 219 | { |
|
219 | 220 | m_modelSignalsBlock = block; |
|
220 | 221 | } |
|
221 | 222 | |
|
222 | 223 | void QBoxPlotModelMapperPrivate::blockSeriesSignals(bool block) |
|
223 | 224 | { |
|
224 | 225 | m_seriesSignalsBlock = block; |
|
225 | 226 | } |
|
226 | 227 | |
|
227 | 228 | QBoxSet *QBoxPlotModelMapperPrivate::boxSet(QModelIndex index) |
|
228 | 229 | { |
|
229 | 230 | if (!index.isValid()) |
|
230 | 231 | return 0; |
|
231 | 232 | |
|
232 | 233 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBoxSetSection && index.column() <= m_lastBoxSetSection) { |
|
233 | 234 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) |
|
234 | 235 | return m_series->boxSets().at(index.column() - m_firstBoxSetSection); |
|
235 | 236 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBoxSetSection && index.row() <= m_lastBoxSetSection) { |
|
236 | 237 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) |
|
237 | 238 | return m_series->boxSets().at(index.row() - m_firstBoxSetSection); |
|
238 | 239 | } |
|
239 | 240 | return 0; // This part of model has not been mapped to any boxset |
|
240 | 241 | } |
|
241 | 242 | |
|
242 | 243 | QModelIndex QBoxPlotModelMapperPrivate::boxModelIndex(int boxSection, int posInBar) |
|
243 | 244 | { |
|
244 | 245 | if (m_count != -1 && posInBar >= m_count) |
|
245 | 246 | return QModelIndex(); // invalid |
|
246 | 247 | |
|
247 | 248 | if (boxSection < m_firstBoxSetSection || boxSection > m_lastBoxSetSection) |
|
248 | 249 | return QModelIndex(); // invalid |
|
249 | 250 | |
|
250 | 251 | if (m_orientation == Qt::Vertical) |
|
251 | 252 | return m_model->index(posInBar + m_first, boxSection); |
|
252 | 253 | else |
|
253 | 254 | return m_model->index(boxSection, posInBar + m_first); |
|
254 | 255 | } |
|
255 | 256 | |
|
256 | 257 | void QBoxPlotModelMapperPrivate::handleSeriesDestroyed() |
|
257 | 258 | { |
|
258 | 259 | m_series = 0; |
|
259 | 260 | } |
|
260 | 261 | |
|
261 | 262 | void QBoxPlotModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
262 | 263 | { |
|
263 | 264 | Q_UNUSED(topLeft) |
|
264 | 265 | Q_UNUSED(bottomRight) |
|
265 | 266 | |
|
266 | 267 | if (m_model == 0 || m_series == 0) |
|
267 | 268 | return; |
|
268 | 269 | |
|
269 | 270 | if (m_modelSignalsBlock) |
|
270 | 271 | return; |
|
271 | 272 | |
|
272 | 273 | blockSeriesSignals(); |
|
273 | 274 | QModelIndex index; |
|
274 | 275 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
275 | 276 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
276 | 277 | index = topLeft.sibling(row, column); |
|
277 | 278 | QBoxSet *box = boxSet(index); |
|
278 | 279 | if (box) { |
|
279 | 280 | if (m_orientation == Qt::Vertical) |
|
280 | 281 | box->setValue(row - m_first, m_model->data(index).toReal()); |
|
281 | 282 | else |
|
282 | 283 | box->setValue(column - m_first, m_model->data(index).toReal()); |
|
283 | 284 | } |
|
284 | 285 | } |
|
285 | 286 | } |
|
286 | 287 | blockSeriesSignals(false); |
|
287 | 288 | } |
|
288 | 289 | |
|
289 | 290 | void QBoxPlotModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last) |
|
290 | 291 | { |
|
291 | 292 | Q_UNUSED(orientation); |
|
292 | 293 | Q_UNUSED(first); |
|
293 | 294 | Q_UNUSED(last); |
|
294 | 295 | } |
|
295 | 296 | |
|
296 | 297 | void QBoxPlotModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
297 | 298 | { |
|
298 | 299 | Q_UNUSED(parent) |
|
299 | 300 | if (m_modelSignalsBlock) |
|
300 | 301 | return; |
|
301 | 302 | |
|
302 | 303 | blockSeriesSignals(); |
|
303 | 304 | if (m_orientation == Qt::Vertical) |
|
304 | 305 | insertData(start, end); |
|
305 | 306 | else if (start <= m_firstBoxSetSection || start <= m_lastBoxSetSection) // if the changes affect the map - reinitialize |
|
306 | 307 | initializeBoxFromModel(); |
|
307 | 308 | blockSeriesSignals(false); |
|
308 | 309 | } |
|
309 | 310 | |
|
310 | 311 | void QBoxPlotModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
311 | 312 | { |
|
312 | 313 | Q_UNUSED(parent) |
|
313 | 314 | if (m_modelSignalsBlock) |
|
314 | 315 | return; |
|
315 | 316 | |
|
316 | 317 | blockSeriesSignals(); |
|
317 | 318 | if (m_orientation == Qt::Vertical) |
|
318 | 319 | removeData(start, end); |
|
319 | 320 | else if (start <= m_firstBoxSetSection || start <= m_lastBoxSetSection) // if the changes affect the map - reinitialize |
|
320 | 321 | initializeBoxFromModel(); |
|
321 | 322 | blockSeriesSignals(false); |
|
322 | 323 | } |
|
323 | 324 | |
|
324 | 325 | void QBoxPlotModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
325 | 326 | { |
|
326 | 327 | Q_UNUSED(parent) |
|
327 | 328 | if (m_modelSignalsBlock) |
|
328 | 329 | return; |
|
329 | 330 | |
|
330 | 331 | blockSeriesSignals(); |
|
331 | 332 | if (m_orientation == Qt::Horizontal) |
|
332 | 333 | insertData(start, end); |
|
333 | 334 | else if (start <= m_firstBoxSetSection || start <= m_lastBoxSetSection) // if the changes affect the map - reinitialize |
|
334 | 335 | initializeBoxFromModel(); |
|
335 | 336 | blockSeriesSignals(false); |
|
336 | 337 | } |
|
337 | 338 | |
|
338 | 339 | void QBoxPlotModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
339 | 340 | { |
|
340 | 341 | Q_UNUSED(parent) |
|
341 | 342 | if (m_modelSignalsBlock) |
|
342 | 343 | return; |
|
343 | 344 | |
|
344 | 345 | blockSeriesSignals(); |
|
345 | 346 | if (m_orientation == Qt::Horizontal) |
|
346 | 347 | removeData(start, end); |
|
347 | 348 | else if (start <= m_firstBoxSetSection || start <= m_lastBoxSetSection) // if the changes affect the map - reinitialize |
|
348 | 349 | initializeBoxFromModel(); |
|
349 | 350 | blockSeriesSignals(false); |
|
350 | 351 | } |
|
351 | 352 | |
|
352 | 353 | void QBoxPlotModelMapperPrivate::handleModelDestroyed() |
|
353 | 354 | { |
|
354 | 355 | m_model = 0; |
|
355 | 356 | } |
|
356 | 357 | |
|
357 | 358 | void QBoxPlotModelMapperPrivate::insertData(int start, int end) |
|
358 | 359 | { |
|
359 | 360 | Q_UNUSED(end) |
|
360 | 361 | Q_UNUSED(start) |
|
361 | 362 | Q_UNUSED(end) |
|
362 | 363 | // Currently boxplotchart needs to be fully recalculated when change is made. |
|
363 | 364 | // Re-initialize |
|
364 | 365 | initializeBoxFromModel(); |
|
365 | 366 | } |
|
366 | 367 | |
|
367 | 368 | void QBoxPlotModelMapperPrivate::removeData(int start, int end) |
|
368 | 369 | { |
|
369 | 370 | Q_UNUSED(end) |
|
370 | 371 | Q_UNUSED(start) |
|
371 | 372 | Q_UNUSED(end) |
|
372 | 373 | // Currently boxplotchart needs to be fully recalculated when change is made. |
|
373 | 374 | // Re-initialize |
|
374 | 375 | initializeBoxFromModel(); |
|
375 | 376 | } |
|
376 | 377 | |
|
377 | 378 | void QBoxPlotModelMapperPrivate::boxSetsAdded(QList<QBoxSet *> sets) |
|
378 | 379 | { |
|
379 | 380 | if (m_seriesSignalsBlock) |
|
380 | 381 | return; |
|
381 | 382 | |
|
382 | 383 | if (sets.count() == 0) |
|
383 | 384 | return; |
|
384 | 385 | |
|
385 | 386 | int firstIndex = m_series->boxSets().indexOf(sets.at(0)); |
|
386 | 387 | if (firstIndex == -1) |
|
387 | 388 | return; |
|
388 | 389 | |
|
389 | 390 | int maxCount = 0; |
|
390 | 391 | for (int i = 0; i < sets.count(); i++) { |
|
391 | 392 | if (sets.at(i)->count() > m_count) |
|
392 | 393 | maxCount = sets.at(i)->count(); |
|
393 | 394 | } |
|
394 | 395 | |
|
395 | 396 | if (m_count != -1 && m_count < maxCount) |
|
396 | 397 | m_count = maxCount; |
|
397 | 398 | |
|
398 | 399 | m_lastBoxSetSection += sets.count(); |
|
399 | 400 | |
|
400 | 401 | blockModelSignals(); |
|
401 | 402 | int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first; |
|
402 | 403 | if (maxCount > modelCapacity) { |
|
403 | 404 | if (m_orientation == Qt::Vertical) |
|
404 | 405 | m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity); |
|
405 | 406 | else |
|
406 | 407 | m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity); |
|
407 | 408 | } |
|
408 | 409 | |
|
409 | 410 | if (m_orientation == Qt::Vertical) |
|
410 | 411 | m_model->insertColumns(firstIndex + m_firstBoxSetSection, sets.count()); |
|
411 | 412 | else |
|
412 | 413 | m_model->insertRows(firstIndex + m_firstBoxSetSection, sets.count()); |
|
413 | 414 | |
|
414 | 415 | |
|
415 | 416 | for (int i = firstIndex + m_firstBoxSetSection; i < firstIndex + m_firstBoxSetSection + sets.count(); i++) { |
|
416 | 417 | for (int j = 0; j < sets.at(i - firstIndex - m_firstBoxSetSection)->count(); j++) |
|
417 | 418 | m_model->setData(boxModelIndex(i, j), sets.at(i - firstIndex - m_firstBoxSetSection)->at(j)); |
|
418 | 419 | } |
|
419 | 420 | blockModelSignals(false); |
|
420 | 421 | initializeBoxFromModel(); |
|
421 | 422 | } |
|
422 | 423 | |
|
423 | 424 | void QBoxPlotModelMapperPrivate::boxSetsRemoved(QList<QBoxSet *> sets) |
|
424 | 425 | { |
|
425 | 426 | if (m_seriesSignalsBlock) |
|
426 | 427 | return; |
|
427 | 428 | |
|
428 | 429 | if (sets.count() == 0) |
|
429 | 430 | return; |
|
430 | 431 | |
|
431 | 432 | int firstIndex = m_boxSets.indexOf(sets.at(0)); |
|
432 | 433 | if (firstIndex == -1) |
|
433 | 434 | return; |
|
434 | 435 | |
|
435 | 436 | m_lastBoxSetSection -= sets.count(); |
|
436 | 437 | |
|
437 | 438 | for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--) |
|
438 | 439 | m_boxSets.removeAt(i); |
|
439 | 440 | |
|
440 | 441 | blockModelSignals(); |
|
441 | 442 | if (m_orientation == Qt::Vertical) |
|
442 | 443 | m_model->removeColumns(firstIndex + m_firstBoxSetSection, sets.count()); |
|
443 | 444 | else |
|
444 | 445 | m_model->removeRows(firstIndex + m_firstBoxSetSection, sets.count()); |
|
445 | 446 | blockModelSignals(false); |
|
446 | 447 | initializeBoxFromModel(); |
|
447 | 448 | } |
|
448 | 449 | |
|
449 | 450 | void QBoxPlotModelMapperPrivate::boxValueChanged(int index) |
|
450 | 451 | { |
|
451 | 452 | if (m_seriesSignalsBlock) |
|
452 | 453 | return; |
|
453 | 454 | |
|
454 | 455 | int boxSetIndex = m_boxSets.indexOf(qobject_cast<QBoxSet *>(QObject::sender())); |
|
455 | 456 | |
|
456 | 457 | blockModelSignals(); |
|
457 | 458 | m_model->setData(boxModelIndex(boxSetIndex + m_firstBoxSetSection, index), m_boxSets.at(boxSetIndex)->at(index)); |
|
458 | 459 | blockModelSignals(false); |
|
459 | 460 | initializeBoxFromModel(); |
|
460 | 461 | } |
|
461 | 462 | |
|
462 | 463 | void QBoxPlotModelMapperPrivate::initializeBoxFromModel() |
|
463 | 464 | { |
|
464 | 465 | if (m_model == 0 || m_series == 0) |
|
465 | 466 | return; |
|
466 | 467 | |
|
467 | 468 | blockSeriesSignals(); |
|
468 | 469 | // clear current content |
|
469 | 470 | m_series->clear(); |
|
470 | 471 | m_boxSets.clear(); |
|
471 | 472 | |
|
472 | 473 | // create the initial box-and-whiskers sets |
|
473 | 474 | for (int i = m_firstBoxSetSection; i <= m_lastBoxSetSection; i++) { |
|
474 | 475 | int posInBar = 0; |
|
475 | 476 | QModelIndex boxIndex = boxModelIndex(i, posInBar); |
|
476 | 477 | // check if there is such model index |
|
477 | 478 | if (boxIndex.isValid()) { |
|
478 | 479 | QBoxSet *boxSet = new QBoxSet(); |
|
479 | 480 | while (boxIndex.isValid()) { |
|
480 | 481 | boxSet->append(m_model->data(boxIndex, Qt::DisplayRole).toDouble()); |
|
481 | 482 | posInBar++; |
|
482 | 483 | boxIndex = boxModelIndex(i, posInBar); |
|
483 | 484 | } |
|
484 | 485 | connect(boxSet, SIGNAL(valueChanged(int)), this, SLOT(boxValueChanged(int))); |
|
485 | 486 | m_series->append(boxSet); |
|
486 | 487 | m_boxSets.append(boxSet); |
|
487 | 488 | } else { |
|
488 | 489 | break; |
|
489 | 490 | } |
|
490 | 491 | } |
|
491 | 492 | blockSeriesSignals(false); |
|
492 | 493 | } |
|
493 | 494 | |
|
494 | 495 | #include "moc_qboxplotmodelmapper.cpp" |
|
495 | 496 | #include "moc_qboxplotmodelmapper_p.cpp" |
|
496 | 497 | |
|
497 | 498 | QT_CHARTS_END_NAMESPACE |
|
498 | 499 |
@@ -1,80 +1,80 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QBOXPLOTMODELMAPPER_H |
|
31 | 31 | #define QBOXPLOTMODELMAPPER_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtCore/QObject> |
|
35 | 35 | |
|
36 | 36 | QT_BEGIN_NAMESPACE |
|
37 | 37 | class QAbstractItemModel; |
|
38 | 38 | QT_END_NAMESPACE |
|
39 | 39 | |
|
40 | 40 | QT_CHARTS_BEGIN_NAMESPACE |
|
41 | 41 | |
|
42 | 42 | class QBoxPlotModelMapperPrivate; |
|
43 | 43 | class QBoxPlotSeries; |
|
44 | 44 | |
|
45 | 45 | class QT_CHARTS_EXPORT QBoxPlotModelMapper : public QObject |
|
46 | 46 | { |
|
47 | 47 | Q_OBJECT |
|
48 | 48 | |
|
49 | 49 | protected: |
|
50 |
explicit QBoxPlotModelMapper(QObject *parent = |
|
|
50 | explicit QBoxPlotModelMapper(QObject *parent = Q_NULLPTR); | |
|
51 | 51 | |
|
52 | 52 | QAbstractItemModel *model() const; |
|
53 | 53 | void setModel(QAbstractItemModel *model); |
|
54 | 54 | |
|
55 | 55 | QBoxPlotSeries *series() const; |
|
56 | 56 | void setSeries(QBoxPlotSeries *series); |
|
57 | 57 | |
|
58 | 58 | int first() const; |
|
59 | 59 | void setFirst(int first); |
|
60 | 60 | |
|
61 | 61 | int count() const; |
|
62 | 62 | void setCount(int count); |
|
63 | 63 | |
|
64 | 64 | int firstBoxSetSection() const; |
|
65 | 65 | void setFirstBoxSetSection(int firstBoxSetSection); |
|
66 | 66 | |
|
67 | 67 | int lastBoxSetSection() const; |
|
68 | 68 | void setLastBoxSetSection(int lastBoxSetSection); |
|
69 | 69 | |
|
70 | 70 | Qt::Orientation orientation() const; |
|
71 | 71 | void setOrientation(Qt::Orientation orientation); |
|
72 | 72 | |
|
73 | 73 | protected: |
|
74 | 74 | QBoxPlotModelMapperPrivate * const d_ptr; |
|
75 | 75 | Q_DECLARE_PRIVATE(QBoxPlotModelMapper) |
|
76 | 76 | }; |
|
77 | 77 | |
|
78 | 78 | QT_CHARTS_END_NAMESPACE |
|
79 | 79 | |
|
80 | 80 | #endif // QBOXPLOTMODELMAPPER_H |
@@ -1,97 +1,97 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QBOXPLOTSERIES_H |
|
31 | 31 | #define QBOXPLOTSERIES_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtCharts/QBoxSet> |
|
35 | 35 | #include <QtCharts/QAbstractSeries> |
|
36 | 36 | |
|
37 | 37 | QT_CHARTS_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | class QBoxPlotSeriesPrivate; |
|
40 | 40 | |
|
41 | 41 | class QT_CHARTS_EXPORT QBoxPlotSeries : public QAbstractSeries |
|
42 | 42 | { |
|
43 | 43 | Q_OBJECT |
|
44 | 44 | Q_PROPERTY(bool boxOutlineVisible READ boxOutlineVisible WRITE setBoxOutlineVisible NOTIFY boxOutlineVisibilityChanged) |
|
45 | 45 | Q_PROPERTY(qreal boxWidth READ boxWidth WRITE setBoxWidth NOTIFY boxWidthChanged) |
|
46 | 46 | Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) |
|
47 | 47 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) |
|
48 | 48 | Q_PROPERTY(int count READ count NOTIFY countChanged REVISION 1) |
|
49 | 49 | public: |
|
50 |
explicit QBoxPlotSeries(QObject *parent = |
|
|
50 | explicit QBoxPlotSeries(QObject *parent = Q_NULLPTR); | |
|
51 | 51 | ~QBoxPlotSeries(); |
|
52 | 52 | |
|
53 | 53 | bool append(QBoxSet *box); |
|
54 | 54 | bool remove(QBoxSet *box); |
|
55 | 55 | bool take(QBoxSet *box); |
|
56 | 56 | bool append(QList<QBoxSet *> boxes); |
|
57 | 57 | bool insert(int index, QBoxSet *box); |
|
58 | 58 | int count() const; |
|
59 | 59 | QList<QBoxSet *> boxSets() const; |
|
60 | 60 | void clear(); |
|
61 | 61 | |
|
62 | 62 | QAbstractSeries::SeriesType type() const; |
|
63 | 63 | |
|
64 | 64 | void setBoxOutlineVisible(bool visible); |
|
65 | 65 | bool boxOutlineVisible(); |
|
66 | 66 | void setBoxWidth(qreal width); |
|
67 | 67 | qreal boxWidth(); |
|
68 | 68 | void setBrush(const QBrush &brush); |
|
69 | 69 | QBrush brush() const; |
|
70 | 70 | void setPen(const QPen &pen); |
|
71 | 71 | QPen pen() const; |
|
72 | 72 | |
|
73 | 73 | Q_SIGNALS: |
|
74 | 74 | void clicked(QBoxSet *boxset); |
|
75 | 75 | void hovered(bool status, QBoxSet *boxset); |
|
76 | 76 | void pressed(QBoxSet *boxset); |
|
77 | 77 | void released(QBoxSet *boxset); |
|
78 | 78 | void doubleClicked(QBoxSet *boxset); |
|
79 | 79 | void countChanged(); |
|
80 | 80 | void penChanged(); |
|
81 | 81 | void brushChanged(); |
|
82 | 82 | void boxOutlineVisibilityChanged(); |
|
83 | 83 | void boxWidthChanged(); |
|
84 | 84 | |
|
85 | 85 | void boxsetsAdded(QList<QBoxSet *> sets); |
|
86 | 86 | void boxsetsRemoved(QList<QBoxSet *> sets); |
|
87 | 87 | |
|
88 | 88 | private: |
|
89 | 89 | Q_DECLARE_PRIVATE(QBoxPlotSeries) |
|
90 | 90 | Q_DISABLE_COPY(QBoxPlotSeries) |
|
91 | 91 | friend class BoxPlotChartItem; |
|
92 | 92 | friend class QBoxPlotLegendMarkerPrivate; |
|
93 | 93 | }; |
|
94 | 94 | |
|
95 | 95 | QT_CHARTS_END_NAMESPACE |
|
96 | 96 | |
|
97 | 97 | #endif // QBOXPLOTSERIES_H |
@@ -1,106 +1,106 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QBOXSET_H |
|
31 | 31 | #define QBOXSET_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtGui/QPen> |
|
35 | 35 | #include <QtGui/QBrush> |
|
36 | 36 | #include <QtGui/QFont> |
|
37 | 37 | |
|
38 | 38 | QT_CHARTS_BEGIN_NAMESPACE |
|
39 | 39 | class QBoxSetPrivate; |
|
40 | 40 | |
|
41 | 41 | class QT_CHARTS_EXPORT QBoxSet : public QObject |
|
42 | 42 | { |
|
43 | 43 | Q_OBJECT |
|
44 | 44 | Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) |
|
45 | 45 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) |
|
46 | 46 | |
|
47 | 47 | public: |
|
48 | 48 | enum ValuePositions { |
|
49 | 49 | LowerExtreme, |
|
50 | 50 | LowerQuartile, |
|
51 | 51 | Median, |
|
52 | 52 | UpperQuartile, |
|
53 | 53 | UpperExtreme |
|
54 | 54 | }; |
|
55 | 55 | |
|
56 | 56 | public: |
|
57 |
explicit QBoxSet(const QString label = QString(), QObject *parent = |
|
|
58 |
explicit QBoxSet(const qreal le, const qreal lq, const qreal m, const qreal uq, const qreal ue, const QString label = QString(), QObject *parent = |
|
|
57 | explicit QBoxSet(const QString label = QString(), QObject *parent = Q_NULLPTR); | |
|
58 | explicit QBoxSet(const qreal le, const qreal lq, const qreal m, const qreal uq, const qreal ue, const QString label = QString(), QObject *parent = Q_NULLPTR); | |
|
59 | 59 | virtual ~QBoxSet(); |
|
60 | 60 | |
|
61 | 61 | void append(const qreal value); |
|
62 | 62 | void append(const QList<qreal> &values); |
|
63 | 63 | |
|
64 | 64 | void clear(); |
|
65 | 65 | |
|
66 | 66 | void setLabel(const QString label); |
|
67 | 67 | QString label() const; |
|
68 | 68 | |
|
69 | 69 | QBoxSet &operator << (const qreal &value); |
|
70 | 70 | |
|
71 | 71 | void setValue(const int index, const qreal value); |
|
72 | 72 | qreal at(const int index) const; |
|
73 | 73 | qreal operator [](const int index) const; |
|
74 | 74 | int count() const; |
|
75 | 75 | |
|
76 | 76 | void setPen(const QPen &pen); |
|
77 | 77 | QPen pen() const; |
|
78 | 78 | |
|
79 | 79 | void setBrush(const QBrush &brush); |
|
80 | 80 | QBrush brush() const; |
|
81 | 81 | |
|
82 | 82 | Q_SIGNALS: |
|
83 | 83 | void clicked(); |
|
84 | 84 | void hovered(bool status); |
|
85 | 85 | void pressed(); |
|
86 | 86 | void released(); |
|
87 | 87 | void doubleClicked(); |
|
88 | 88 | void penChanged(); |
|
89 | 89 | void brushChanged(); |
|
90 | 90 | |
|
91 | 91 | void valuesChanged(); |
|
92 | 92 | void valueChanged(int index); |
|
93 | 93 | void cleared(); |
|
94 | 94 | |
|
95 | 95 | private: |
|
96 | 96 | QScopedPointer<QBoxSetPrivate> d_ptr; |
|
97 | 97 | Q_DISABLE_COPY(QBoxSet) |
|
98 | 98 | friend class BarLegendMarker; |
|
99 | 99 | friend class BarChartItem; |
|
100 | 100 | friend class BoxPlotChartItem; |
|
101 | 101 | friend class QBoxPlotSeriesPrivate; |
|
102 | 102 | }; |
|
103 | 103 | |
|
104 | 104 | QT_CHARTS_END_NAMESPACE |
|
105 | 105 | |
|
106 | 106 | #endif // QBOXSET_H |
@@ -1,79 +1,79 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QVBOXPLOTMODELMAPPER_H |
|
31 | 31 | #define QVBOXPLOTMODELMAPPER_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QBoxPlotModelMapper> |
|
34 | 34 | |
|
35 | 35 | QT_CHARTS_BEGIN_NAMESPACE |
|
36 | 36 | /* Comment line for syncqt to generate the fwd-include correctly, due to QTBUG-22432 */ |
|
37 | 37 | class QT_CHARTS_EXPORT QVBoxPlotModelMapper : public QBoxPlotModelMapper |
|
38 | 38 | { |
|
39 | 39 | Q_OBJECT |
|
40 | 40 | Q_PROPERTY(QBoxPlotSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) |
|
41 | 41 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced) |
|
42 | 42 | Q_PROPERTY(int firstBoxSetColumn READ firstBoxSetColumn WRITE setFirstBoxSetColumn NOTIFY firstBoxSetColumnChanged) |
|
43 | 43 | Q_PROPERTY(int lastBoxSetColumn READ lastBoxSetColumn WRITE setLastBoxSetColumn NOTIFY lastBoxSetColumnChanged) |
|
44 | 44 | Q_PROPERTY(int firstRow READ firstRow WRITE setFirstRow NOTIFY firstRowChanged) |
|
45 | 45 | Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount NOTIFY rowCountChanged) |
|
46 | 46 | |
|
47 | 47 | public: |
|
48 |
explicit QVBoxPlotModelMapper(QObject *parent = |
|
|
48 | explicit QVBoxPlotModelMapper(QObject *parent = Q_NULLPTR); | |
|
49 | 49 | |
|
50 | 50 | QAbstractItemModel *model() const; |
|
51 | 51 | void setModel(QAbstractItemModel *model); |
|
52 | 52 | |
|
53 | 53 | QBoxPlotSeries *series() const; |
|
54 | 54 | void setSeries(QBoxPlotSeries *series); |
|
55 | 55 | |
|
56 | 56 | int firstBoxSetColumn() const; |
|
57 | 57 | void setFirstBoxSetColumn(int firstBoxSetColumn); |
|
58 | 58 | |
|
59 | 59 | int lastBoxSetColumn() const; |
|
60 | 60 | void setLastBoxSetColumn(int lastBoxSetColumn); |
|
61 | 61 | |
|
62 | 62 | int firstRow() const; |
|
63 | 63 | void setFirstRow(int firstRow); |
|
64 | 64 | |
|
65 | 65 | int rowCount() const; |
|
66 | 66 | void setRowCount(int rowCount); |
|
67 | 67 | |
|
68 | 68 | Q_SIGNALS: |
|
69 | 69 | void seriesReplaced(); |
|
70 | 70 | void modelReplaced(); |
|
71 | 71 | void firstBoxSetColumnChanged(); |
|
72 | 72 | void lastBoxSetColumnChanged(); |
|
73 | 73 | void firstRowChanged(); |
|
74 | 74 | void rowCountChanged(); |
|
75 | 75 | }; |
|
76 | 76 | |
|
77 | 77 | QT_CHARTS_END_NAMESPACE |
|
78 | 78 | |
|
79 | 79 | #endif // QVBOXPLOTMODELMAPPER_H |
@@ -1,100 +1,105 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include <private/charttitle_p.h> |
|
31 | 31 | #include <private/chartpresenter_p.h> |
|
32 | 32 | #include <QtGui/QFont> |
|
33 | 33 | #include <QtGui/QFontMetrics> |
|
34 | 34 | #include <QtCore/QDebug> |
|
35 | 35 | #include <QtGui/QTextDocument> |
|
36 | 36 | |
|
37 | 37 | QT_CHARTS_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | ChartTitle::ChartTitle(QGraphicsItem *parent) |
|
40 | 40 | : QGraphicsTextItem(parent) |
|
41 | 41 | { |
|
42 | 42 | document()->setDocumentMargin(ChartPresenter::textMargin()); |
|
43 | 43 | } |
|
44 | 44 | |
|
45 | 45 | ChartTitle::~ChartTitle() |
|
46 | 46 | { |
|
47 | 47 | |
|
48 | 48 | } |
|
49 | 49 | |
|
50 | 50 | void ChartTitle::setText(const QString &text) |
|
51 | 51 | { |
|
52 | 52 | m_text = text; |
|
53 | 53 | } |
|
54 | 54 | |
|
55 | 55 | QString ChartTitle::text() const |
|
56 | 56 | { |
|
57 | 57 | return m_text; |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | void ChartTitle::setGeometry(const QRectF &rect) |
|
61 | 61 | { |
|
62 | 62 | QRectF truncatedRect; |
|
63 | if (m_text.isEmpty()) { | |
|
64 | QGraphicsTextItem::setHtml(m_text); | |
|
65 | QGraphicsTextItem::setTextWidth(0.0); | |
|
66 | } else { | |
|
63 | 67 | QGraphicsTextItem::setHtml(ChartPresenter::truncatedText(font(), m_text, qreal(0.0), |
|
64 | 68 | rect.width(), rect.height(), |
|
65 | 69 | truncatedRect)); |
|
66 | 70 | QGraphicsTextItem::setTextWidth(truncatedRect.width()); |
|
71 | } | |
|
67 | 72 | setPos(rect.topLeft()); |
|
68 | 73 | } |
|
69 | 74 | |
|
70 | 75 | |
|
71 | 76 | QSizeF ChartTitle::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
72 | 77 | { |
|
73 | 78 | Q_UNUSED(constraint); |
|
74 | 79 | QSizeF sh; |
|
75 | 80 | |
|
76 | 81 | switch (which) { |
|
77 | 82 | case Qt::MinimumSize: { |
|
78 | 83 | QRectF titleRect = ChartPresenter::textBoundingRect(font(), QStringLiteral("...")); |
|
79 | 84 | sh = QSizeF(titleRect.width(), titleRect.height()); |
|
80 | 85 | break; |
|
81 | 86 | } |
|
82 | 87 | case Qt::PreferredSize: |
|
83 | 88 | case Qt::MaximumSize: { |
|
84 | 89 | QRectF titleRect = ChartPresenter::textBoundingRect(font(), m_text); |
|
85 | 90 | sh = QSizeF(titleRect.width(), titleRect.height()); |
|
86 | 91 | break; |
|
87 | 92 | } |
|
88 | 93 | case Qt::MinimumDescent: { |
|
89 | 94 | QFontMetrics fn(font()); |
|
90 | 95 | sh = QSizeF(0, fn.descent()); |
|
91 | 96 | break; |
|
92 | 97 | } |
|
93 | 98 | default: |
|
94 | 99 | break; |
|
95 | 100 | } |
|
96 | 101 | |
|
97 | 102 | return sh; |
|
98 | 103 | } |
|
99 | 104 | |
|
100 | 105 | QT_CHARTS_END_NAMESPACE |
@@ -1,214 +1,218 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include <private/abstractchartlayout_p.h> |
|
31 | 31 | #include <private/chartpresenter_p.h> |
|
32 | 32 | #include <private/qlegend_p.h> |
|
33 | 33 | #include <private/chartaxiselement_p.h> |
|
34 | 34 | #include <private/charttitle_p.h> |
|
35 | 35 | #include <private/chartbackground_p.h> |
|
36 | 36 | #include <QtCore/QDebug> |
|
37 | 37 | |
|
38 | 38 | QT_CHARTS_BEGIN_NAMESPACE |
|
39 | 39 | |
|
40 | 40 | static const qreal golden_ratio = 0.4; |
|
41 | 41 | |
|
42 | 42 | AbstractChartLayout::AbstractChartLayout(ChartPresenter *presenter) |
|
43 | 43 | : m_presenter(presenter), |
|
44 | 44 | m_margins(20, 20, 20, 20), |
|
45 | 45 | m_minChartRect(0, 0, 200, 200) |
|
46 | 46 | { |
|
47 | 47 | } |
|
48 | 48 | |
|
49 | 49 | AbstractChartLayout::~AbstractChartLayout() |
|
50 | 50 | { |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | void AbstractChartLayout::setGeometry(const QRectF &rect) |
|
54 | 54 | { |
|
55 | 55 | if (!rect.isValid()) |
|
56 | 56 | return; |
|
57 | 57 | |
|
58 | 58 | if (m_presenter->chart()->isVisible()) { |
|
59 | 59 | QList<ChartAxisElement *> axes = m_presenter->axisItems(); |
|
60 | 60 | ChartTitle *title = m_presenter->titleElement(); |
|
61 | 61 | QLegend *legend = m_presenter->legend(); |
|
62 | 62 | ChartBackground *background = m_presenter->backgroundElement(); |
|
63 | 63 | |
|
64 | 64 | QRectF contentGeometry = calculateBackgroundGeometry(rect, background); |
|
65 | 65 | |
|
66 | 66 | contentGeometry = calculateContentGeometry(contentGeometry); |
|
67 | 67 | |
|
68 |
if (title && title->isVisible() |
|
|
68 | if (title && title->isVisible()) | |
|
69 | 69 | contentGeometry = calculateTitleGeometry(contentGeometry, title); |
|
70 | 70 | |
|
71 | 71 | if (legend->isAttachedToChart() && legend->isVisible()) |
|
72 | 72 | contentGeometry = calculateLegendGeometry(contentGeometry, legend); |
|
73 | 73 | |
|
74 | 74 | contentGeometry = calculateAxisGeometry(contentGeometry, axes); |
|
75 | 75 | |
|
76 | 76 | m_presenter->setGeometry(contentGeometry); |
|
77 | 77 | if (m_presenter->chart()->chartType() == QChart::ChartTypeCartesian) |
|
78 | 78 | static_cast<QGraphicsRectItem *>(m_presenter->plotAreaElement())->setRect(contentGeometry); |
|
79 | 79 | else |
|
80 | 80 | static_cast<QGraphicsEllipseItem *>(m_presenter->plotAreaElement())->setRect(contentGeometry); |
|
81 | 81 | } |
|
82 | 82 | |
|
83 | 83 | QGraphicsLayout::setGeometry(rect); |
|
84 | 84 | } |
|
85 | 85 | |
|
86 | 86 | QRectF AbstractChartLayout::calculateContentGeometry(const QRectF &geometry) const |
|
87 | 87 | { |
|
88 | 88 | return geometry.adjusted(m_margins.left(), m_margins.top(), -m_margins.right(), -m_margins.bottom()); |
|
89 | 89 | } |
|
90 | 90 | |
|
91 | 91 | QRectF AbstractChartLayout::calculateContentMinimum(const QRectF &minimum) const |
|
92 | 92 | { |
|
93 | 93 | return minimum.adjusted(0, 0, m_margins.left() + m_margins.right(), m_margins.top() + m_margins.bottom()); |
|
94 | 94 | } |
|
95 | 95 | |
|
96 | 96 | |
|
97 | 97 | QRectF AbstractChartLayout::calculateBackgroundGeometry(const QRectF &geometry, ChartBackground *background) const |
|
98 | 98 | { |
|
99 | 99 | qreal left; |
|
100 | 100 | qreal top; |
|
101 | 101 | qreal right; |
|
102 | 102 | qreal bottom; |
|
103 | 103 | getContentsMargins(&left, &top, &right, &bottom); |
|
104 | 104 | QRectF backgroundGeometry = geometry.adjusted(left, top, -right, -bottom); |
|
105 | 105 | if (background) |
|
106 | 106 | background->setRect(backgroundGeometry); |
|
107 | 107 | return backgroundGeometry; |
|
108 | 108 | } |
|
109 | 109 | |
|
110 | 110 | QRectF AbstractChartLayout::calculateBackgroundMinimum(const QRectF &minimum) const |
|
111 | 111 | { |
|
112 | 112 | qreal left; |
|
113 | 113 | qreal top; |
|
114 | 114 | qreal right; |
|
115 | 115 | qreal bottom; |
|
116 | 116 | getContentsMargins(&left, &top, &right, &bottom); |
|
117 | 117 | return minimum.adjusted(0, 0, left + right, top + bottom); |
|
118 | 118 | } |
|
119 | 119 | |
|
120 | 120 | QRectF AbstractChartLayout::calculateLegendGeometry(const QRectF &geometry, QLegend *legend) const |
|
121 | 121 | { |
|
122 | 122 | QSizeF size = legend->effectiveSizeHint(Qt::PreferredSize, QSizeF(-1, -1)); |
|
123 | 123 | QRectF legendRect; |
|
124 | 124 | QRectF result; |
|
125 | 125 | |
|
126 | 126 | switch (legend->alignment()) { |
|
127 | 127 | case Qt::AlignTop: { |
|
128 | 128 | legendRect = QRectF(geometry.topLeft(), QSizeF(geometry.width(), size.height())); |
|
129 | 129 | result = geometry.adjusted(0, legendRect.height(), 0, 0); |
|
130 | 130 | break; |
|
131 | 131 | } |
|
132 | 132 | case Qt::AlignBottom: { |
|
133 | 133 | legendRect = QRectF(QPointF(geometry.left(), geometry.bottom() - size.height()), QSizeF(geometry.width(), size.height())); |
|
134 | 134 | result = geometry.adjusted(0, 0, 0, -legendRect.height()); |
|
135 | 135 | break; |
|
136 | 136 | } |
|
137 | 137 | case Qt::AlignLeft: { |
|
138 | 138 | qreal width = qMin(size.width(), geometry.width() * golden_ratio); |
|
139 | 139 | legendRect = QRectF(geometry.topLeft(), QSizeF(width, geometry.height())); |
|
140 | 140 | result = geometry.adjusted(width, 0, 0, 0); |
|
141 | 141 | break; |
|
142 | 142 | } |
|
143 | 143 | case Qt::AlignRight: { |
|
144 | 144 | qreal width = qMin(size.width(), geometry.width() * golden_ratio); |
|
145 | 145 | legendRect = QRectF(QPointF(geometry.right() - width, geometry.top()), QSizeF(width, geometry.height())); |
|
146 | 146 | result = geometry.adjusted(0, 0, -width, 0); |
|
147 | 147 | break; |
|
148 | 148 | } |
|
149 | 149 | default: { |
|
150 | 150 | legendRect = QRectF(0, 0, 0, 0); |
|
151 | 151 | result = geometry; |
|
152 | 152 | break; |
|
153 | 153 | } |
|
154 | 154 | } |
|
155 | 155 | |
|
156 | 156 | legend->setGeometry(legendRect); |
|
157 | 157 | |
|
158 | 158 | return result; |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | QRectF AbstractChartLayout::calculateLegendMinimum(const QRectF &geometry, QLegend *legend) const |
|
162 | 162 | { |
|
163 | 163 | QSizeF minSize = legend->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, -1)); |
|
164 | 164 | return geometry.adjusted(0, 0, minSize.width(), minSize.height()); |
|
165 | 165 | } |
|
166 | 166 | |
|
167 | 167 | QRectF AbstractChartLayout::calculateTitleGeometry(const QRectF &geometry, ChartTitle *title) const |
|
168 | 168 | { |
|
169 | 169 | title->setGeometry(geometry); |
|
170 | if (title->text().isEmpty()) { | |
|
171 | return geometry; | |
|
172 | } else { | |
|
170 | 173 | // Round to full pixel via QPoint to avoid one pixel clipping on the edge in some cases |
|
171 | 174 | QPointF center((geometry.center() - title->boundingRect().center()).toPoint()); |
|
172 | 175 | |
|
173 | 176 | title->setPos(center.x(), title->pos().y()); |
|
174 | 177 | return geometry.adjusted(0, title->boundingRect().height()+1, 0, 0); |
|
175 | 178 | } |
|
179 | } | |
|
176 | 180 | |
|
177 | 181 | QRectF AbstractChartLayout::calculateTitleMinimum(const QRectF &minimum, ChartTitle *title) const |
|
178 | 182 | { |
|
179 | 183 | QSizeF min = title->sizeHint(Qt::MinimumSize); |
|
180 | 184 | return minimum.adjusted(0, 0, min.width(), min.height()); |
|
181 | 185 | } |
|
182 | 186 | |
|
183 | 187 | QSizeF AbstractChartLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
184 | 188 | { |
|
185 | 189 | Q_UNUSED(constraint); |
|
186 | 190 | if (which == Qt::MinimumSize) { |
|
187 | 191 | QList<ChartAxisElement *> axes = m_presenter->axisItems(); |
|
188 | 192 | ChartTitle *title = m_presenter->titleElement(); |
|
189 | 193 | QLegend *legend = m_presenter->legend(); |
|
190 | 194 | QRectF minimumRect(0, 0, 0, 0); |
|
191 | 195 | minimumRect = calculateBackgroundMinimum(minimumRect); |
|
192 | 196 | minimumRect = calculateContentMinimum(minimumRect); |
|
193 | 197 | minimumRect = calculateTitleMinimum(minimumRect, title); |
|
194 | 198 | minimumRect = calculateLegendMinimum(minimumRect, legend); |
|
195 | 199 | minimumRect = calculateAxisMinimum(minimumRect, axes); |
|
196 | 200 | return minimumRect.united(m_minChartRect).size().toSize(); |
|
197 | 201 | } |
|
198 | 202 | return QSize(-1, -1); |
|
199 | 203 | } |
|
200 | 204 | |
|
201 | 205 | void AbstractChartLayout::setMargins(const QMargins &margins) |
|
202 | 206 | { |
|
203 | 207 | if (m_margins != margins) { |
|
204 | 208 | m_margins = margins; |
|
205 | 209 | updateGeometry(); |
|
206 | 210 | } |
|
207 | 211 | } |
|
208 | 212 | |
|
209 | 213 | QMargins AbstractChartLayout::margins() const |
|
210 | 214 | { |
|
211 | 215 | return m_margins; |
|
212 | 216 | } |
|
213 | 217 | |
|
214 | 218 | QT_CHARTS_END_NAMESPACE |
@@ -1,65 +1,65 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QAREALEGENDMARKER_H |
|
31 | 31 | #define QAREALEGENDMARKER_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtCharts/QLegendMarker> |
|
35 | 35 | #include <QtCharts/QAreaSeries> |
|
36 | 36 | |
|
37 | 37 | QT_CHARTS_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | class QAreaLegendMarkerPrivate; |
|
40 | 40 | |
|
41 | 41 | class QT_CHARTS_EXPORT QAreaLegendMarker : public QLegendMarker |
|
42 | 42 | { |
|
43 | 43 | Q_OBJECT |
|
44 | 44 | |
|
45 | 45 | public: |
|
46 |
explicit QAreaLegendMarker(QAreaSeries *series, QLegend *legend, QObject *parent = |
|
|
46 | explicit QAreaLegendMarker(QAreaSeries *series, QLegend *legend, QObject *parent = Q_NULLPTR); | |
|
47 | 47 | virtual ~QAreaLegendMarker(); |
|
48 | 48 | |
|
49 | 49 | virtual LegendMarkerType type() { return LegendMarkerTypeArea; } |
|
50 | 50 | |
|
51 | 51 | // Related series |
|
52 | 52 | virtual QAreaSeries* series(); |
|
53 | 53 | |
|
54 | 54 | protected: |
|
55 |
QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent = |
|
|
55 | QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent = Q_NULLPTR); | |
|
56 | 56 | |
|
57 | 57 | private: |
|
58 | 58 | Q_DECLARE_PRIVATE(QAreaLegendMarker) |
|
59 | 59 | Q_DISABLE_COPY(QAreaLegendMarker) |
|
60 | 60 | |
|
61 | 61 | }; |
|
62 | 62 | |
|
63 | 63 | QT_CHARTS_END_NAMESPACE |
|
64 | 64 | |
|
65 | 65 | #endif // QAREALEGENDMARKER_H |
@@ -1,66 +1,66 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | #ifndef QBARLEGENDMARKER_H |
|
30 | 30 | #define QBARLEGENDMARKER_H |
|
31 | 31 | |
|
32 | 32 | #include <QtCharts/QChartGlobal> |
|
33 | 33 | #include <QtCharts/QLegendMarker> |
|
34 | 34 | #include <QtCharts/QAbstractBarSeries> |
|
35 | 35 | #include <QtCharts/QBarSet> |
|
36 | 36 | |
|
37 | 37 | QT_CHARTS_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | class QLegend; |
|
40 | 40 | class QBarLegendMarkerPrivate; |
|
41 | 41 | |
|
42 | 42 | class QT_CHARTS_EXPORT QBarLegendMarker : public QLegendMarker |
|
43 | 43 | { |
|
44 | 44 | Q_OBJECT |
|
45 | 45 | public: |
|
46 |
explicit QBarLegendMarker(QAbstractBarSeries *series, QBarSet *barset, QLegend *legend, QObject *parent = |
|
|
46 | explicit QBarLegendMarker(QAbstractBarSeries *series, QBarSet *barset, QLegend *legend, QObject *parent = Q_NULLPTR); | |
|
47 | 47 | virtual ~QBarLegendMarker(); |
|
48 | 48 | |
|
49 | 49 | virtual LegendMarkerType type() { return LegendMarkerTypeBar; } |
|
50 | 50 | |
|
51 | 51 | // Related series and barset |
|
52 | 52 | virtual QAbstractBarSeries* series(); |
|
53 | 53 | QBarSet* barset(); |
|
54 | 54 | |
|
55 | 55 | protected: |
|
56 |
QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent = |
|
|
56 | QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent = Q_NULLPTR); | |
|
57 | 57 | |
|
58 | 58 | private: |
|
59 | 59 | Q_DECLARE_PRIVATE(QBarLegendMarker) |
|
60 | 60 | Q_DISABLE_COPY(QBarLegendMarker) |
|
61 | 61 | |
|
62 | 62 | }; |
|
63 | 63 | |
|
64 | 64 | QT_CHARTS_END_NAMESPACE |
|
65 | 65 | |
|
66 | 66 | #endif // QBARLEGENDMARKER_H |
@@ -1,64 +1,64 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QBOXPLOTLEGENDMARKER_H |
|
31 | 31 | #define QBOXPLOTLEGENDMARKER_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtCharts/QLegendMarker> |
|
35 | 35 | #include <QtCharts/QBoxPlotSeries> |
|
36 | 36 | |
|
37 | 37 | QT_CHARTS_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | class QBoxPlotLegendMarkerPrivate; |
|
40 | 40 | |
|
41 | 41 | class QT_CHARTS_EXPORT QBoxPlotLegendMarker : public QLegendMarker |
|
42 | 42 | { |
|
43 | 43 | Q_OBJECT |
|
44 | 44 | |
|
45 | 45 | public: |
|
46 |
explicit QBoxPlotLegendMarker(QBoxPlotSeries *series, QLegend *legend, QObject *parent = |
|
|
46 | explicit QBoxPlotLegendMarker(QBoxPlotSeries *series, QLegend *legend, QObject *parent = Q_NULLPTR); | |
|
47 | 47 | virtual ~QBoxPlotLegendMarker(); |
|
48 | 48 | |
|
49 | 49 | virtual LegendMarkerType type() { return LegendMarkerTypeBoxPlot; } |
|
50 | 50 | |
|
51 | 51 | // Related series |
|
52 | 52 | virtual QBoxPlotSeries* series(); |
|
53 | 53 | |
|
54 | 54 | protected: |
|
55 |
QBoxPlotLegendMarker(QBoxPlotLegendMarkerPrivate &d, QObject *parent = |
|
|
55 | QBoxPlotLegendMarker(QBoxPlotLegendMarkerPrivate &d, QObject *parent = Q_NULLPTR); | |
|
56 | 56 | |
|
57 | 57 | private: |
|
58 | 58 | Q_DECLARE_PRIVATE(QBoxPlotLegendMarker) |
|
59 | 59 | Q_DISABLE_COPY(QBoxPlotLegendMarker) |
|
60 | 60 | }; |
|
61 | 61 | |
|
62 | 62 | QT_CHARTS_END_NAMESPACE |
|
63 | 63 | |
|
64 | 64 | #endif // QBOXPLOTLEGENDMARKER_H |
@@ -1,125 +1,125 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QLEGEND_H |
|
31 | 31 | #define QLEGEND_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtWidgets/QGraphicsWidget> |
|
35 | 35 | #include <QtGui/QPen> |
|
36 | 36 | #include <QtGui/QBrush> |
|
37 | 37 | |
|
38 | 38 | QT_CHARTS_BEGIN_NAMESPACE |
|
39 | 39 | |
|
40 | 40 | class QChart; |
|
41 | 41 | class QLegendPrivate; |
|
42 | 42 | class QLegendMarker; |
|
43 | 43 | class QAbstractSeries; |
|
44 | 44 | |
|
45 | 45 | class QT_CHARTS_EXPORT QLegend : public QGraphicsWidget |
|
46 | 46 | { |
|
47 | 47 | Q_OBJECT |
|
48 | 48 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) |
|
49 | 49 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged) |
|
50 | 50 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
51 | 51 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
|
52 | 52 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) |
|
53 | 53 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) |
|
54 | 54 | Q_PROPERTY(bool reverseMarkers READ reverseMarkers WRITE setReverseMarkers NOTIFY reverseMarkersChanged) |
|
55 | 55 | Q_PROPERTY(bool showToolTips READ showToolTips WRITE setShowToolTips NOTIFY showToolTipsChanged) |
|
56 | 56 | |
|
57 | 57 | private: |
|
58 | 58 | explicit QLegend(QChart *chart); |
|
59 | 59 | |
|
60 | 60 | public: |
|
61 | 61 | ~QLegend(); |
|
62 | 62 | |
|
63 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = |
|
|
63 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR); | |
|
64 | 64 | |
|
65 | 65 | void setBrush(const QBrush &brush); |
|
66 | 66 | QBrush brush() const; |
|
67 | 67 | void setColor(QColor color); |
|
68 | 68 | QColor color(); |
|
69 | 69 | |
|
70 | 70 | void setPen(const QPen &pen); |
|
71 | 71 | QPen pen() const; |
|
72 | 72 | void setBorderColor(QColor color); |
|
73 | 73 | QColor borderColor(); |
|
74 | 74 | |
|
75 | 75 | void setFont(const QFont &font); |
|
76 | 76 | QFont font() const; |
|
77 | 77 | void setLabelBrush(const QBrush &brush); |
|
78 | 78 | QBrush labelBrush() const; |
|
79 | 79 | |
|
80 | 80 | void setLabelColor(QColor color); |
|
81 | 81 | QColor labelColor() const; |
|
82 | 82 | |
|
83 | 83 | void setAlignment(Qt::Alignment alignment); |
|
84 | 84 | Qt::Alignment alignment() const; |
|
85 | 85 | |
|
86 | 86 | void detachFromChart(); |
|
87 | 87 | void attachToChart(); |
|
88 | 88 | bool isAttachedToChart(); |
|
89 | 89 | |
|
90 | 90 | void setBackgroundVisible(bool visible = true); |
|
91 | 91 | bool isBackgroundVisible() const; |
|
92 | 92 | |
|
93 |
QList <QLegendMarker*> markers(QAbstractSeries *series = |
|
|
93 | QList <QLegendMarker*> markers(QAbstractSeries *series = Q_NULLPTR) const; | |
|
94 | 94 | |
|
95 | 95 | bool reverseMarkers(); |
|
96 | 96 | void setReverseMarkers(bool reverseMarkers = true); |
|
97 | 97 | |
|
98 | 98 | bool showToolTips() const; |
|
99 | 99 | void setShowToolTips(bool show); |
|
100 | 100 | protected: |
|
101 | 101 | void hideEvent(QHideEvent *event); |
|
102 | 102 | void showEvent(QShowEvent *event); |
|
103 | 103 | |
|
104 | 104 | Q_SIGNALS: |
|
105 | 105 | void backgroundVisibleChanged(bool visible); |
|
106 | 106 | void colorChanged(QColor color); |
|
107 | 107 | void borderColorChanged(QColor color); |
|
108 | 108 | void fontChanged(QFont font); |
|
109 | 109 | void labelColorChanged(QColor color); |
|
110 | 110 | void reverseMarkersChanged(bool reverseMarkers); |
|
111 | 111 | void showToolTipsChanged(bool showToolTips); |
|
112 | 112 | |
|
113 | 113 | private: |
|
114 | 114 | QScopedPointer<QLegendPrivate> d_ptr; |
|
115 | 115 | Q_DISABLE_COPY(QLegend) |
|
116 | 116 | friend class LegendScroller; |
|
117 | 117 | friend class LegendLayout; |
|
118 | 118 | friend class ChartLayout; |
|
119 | 119 | friend class LegendMarkerItem; |
|
120 | 120 | friend class QLegendMarkerPrivate; |
|
121 | 121 | }; |
|
122 | 122 | |
|
123 | 123 | QT_CHARTS_END_NAMESPACE |
|
124 | 124 | |
|
125 | 125 | #endif // QLEGEND_H |
@@ -1,116 +1,116 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QLEGENDMARKER_H |
|
31 | 31 | #define QLEGENDMARKER_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtCore/QObject> |
|
35 | 35 | #include <QtGui/QPen> |
|
36 | 36 | #include <QtGui/QBrush> |
|
37 | 37 | #include <QtGui/QFont> |
|
38 | 38 | |
|
39 | 39 | QT_CHARTS_BEGIN_NAMESPACE |
|
40 | 40 | |
|
41 | 41 | class QLegendMarkerPrivate; |
|
42 | 42 | class QAbstractSeries; |
|
43 | 43 | class QLegend; |
|
44 | 44 | |
|
45 | 45 | class QT_CHARTS_EXPORT QLegendMarker : public QObject |
|
46 | 46 | { |
|
47 | 47 | Q_OBJECT |
|
48 | 48 | |
|
49 | 49 | public: |
|
50 | 50 | enum LegendMarkerType { |
|
51 | 51 | LegendMarkerTypeArea, |
|
52 | 52 | LegendMarkerTypeBar, |
|
53 | 53 | LegendMarkerTypePie, |
|
54 | 54 | LegendMarkerTypeXY, |
|
55 | 55 | LegendMarkerTypeBoxPlot |
|
56 | 56 | }; |
|
57 | 57 | |
|
58 | 58 | Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) |
|
59 | 59 | Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged) |
|
60 | 60 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) |
|
61 | 61 | Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) |
|
62 | 62 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) |
|
63 | 63 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) |
|
64 | 64 | Q_ENUMS(LegendMarkerType) |
|
65 | 65 | |
|
66 | 66 | public: |
|
67 | 67 | virtual ~QLegendMarker(); |
|
68 | 68 | virtual LegendMarkerType type() = 0; |
|
69 | 69 | |
|
70 | 70 | QString label() const; |
|
71 | 71 | void setLabel(const QString &label); |
|
72 | 72 | |
|
73 | 73 | QBrush labelBrush() const; |
|
74 | 74 | void setLabelBrush(const QBrush &brush); |
|
75 | 75 | |
|
76 | 76 | QFont font() const; |
|
77 | 77 | void setFont(const QFont &font); |
|
78 | 78 | |
|
79 | 79 | QPen pen() const; |
|
80 | 80 | void setPen(const QPen &pen); |
|
81 | 81 | |
|
82 | 82 | QBrush brush() const; |
|
83 | 83 | void setBrush(const QBrush &brush); |
|
84 | 84 | |
|
85 | 85 | bool isVisible() const; |
|
86 | 86 | void setVisible(bool visible); |
|
87 | 87 | |
|
88 | 88 | virtual QAbstractSeries* series() = 0; |
|
89 | 89 | |
|
90 | 90 | Q_SIGNALS: |
|
91 | 91 | void clicked(); |
|
92 | 92 | void hovered(bool status); |
|
93 | 93 | void labelChanged(); |
|
94 | 94 | void labelBrushChanged(); |
|
95 | 95 | void fontChanged(); |
|
96 | 96 | void penChanged(); |
|
97 | 97 | void brushChanged(); |
|
98 | 98 | void visibleChanged(); |
|
99 | 99 | |
|
100 | 100 | protected: |
|
101 |
explicit QLegendMarker(QLegendMarkerPrivate &d, QObject *parent = |
|
|
101 | explicit QLegendMarker(QLegendMarkerPrivate &d, QObject *parent = Q_NULLPTR); | |
|
102 | 102 | |
|
103 | 103 | QScopedPointer<QLegendMarkerPrivate> d_ptr; |
|
104 | 104 | friend class QLegendPrivate; |
|
105 | 105 | friend class QLegendMarkerPrivate; |
|
106 | 106 | friend class LegendMarkerItem; |
|
107 | 107 | friend class LegendLayout; |
|
108 | 108 | friend class LegendScroller; |
|
109 | 109 | |
|
110 | 110 | private: |
|
111 | 111 | Q_DISABLE_COPY(QLegendMarker) |
|
112 | 112 | }; |
|
113 | 113 | |
|
114 | 114 | QT_CHARTS_END_NAMESPACE |
|
115 | 115 | |
|
116 | 116 | #endif // QLEGENDMARKER_H |
@@ -1,66 +1,66 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QPIELEGENDMARKER_H |
|
31 | 31 | #define QPIELEGENDMARKER_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtCharts/QLegendMarker> |
|
35 | 35 | #include <QtCharts/QPieSeries> |
|
36 | 36 | #include <QtCharts/QPieSlice> |
|
37 | 37 | |
|
38 | 38 | QT_CHARTS_BEGIN_NAMESPACE |
|
39 | 39 | |
|
40 | 40 | class QPieLegendMarkerPrivate; |
|
41 | 41 | |
|
42 | 42 | class QT_CHARTS_EXPORT QPieLegendMarker : public QLegendMarker |
|
43 | 43 | { |
|
44 | 44 | Q_OBJECT |
|
45 | 45 | |
|
46 | 46 | public: |
|
47 |
explicit QPieLegendMarker(QPieSeries *series, QPieSlice *slice, QLegend *legend, QObject *parent = |
|
|
47 | explicit QPieLegendMarker(QPieSeries *series, QPieSlice *slice, QLegend *legend, QObject *parent = Q_NULLPTR); | |
|
48 | 48 | virtual ~QPieLegendMarker(); |
|
49 | 49 | |
|
50 | 50 | virtual LegendMarkerType type() { return LegendMarkerTypePie; } |
|
51 | 51 | |
|
52 | 52 | // Related series and slice |
|
53 | 53 | virtual QPieSeries* series(); |
|
54 | 54 | QPieSlice* slice(); |
|
55 | 55 | |
|
56 | 56 | protected: |
|
57 |
QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent = |
|
|
57 | QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent = Q_NULLPTR); | |
|
58 | 58 | |
|
59 | 59 | private: |
|
60 | 60 | Q_DECLARE_PRIVATE(QPieLegendMarker) |
|
61 | 61 | Q_DISABLE_COPY(QPieLegendMarker) |
|
62 | 62 | |
|
63 | 63 | }; |
|
64 | 64 | |
|
65 | 65 | QT_CHARTS_END_NAMESPACE |
|
66 | 66 | #endif // QPIELEGENDMARKER_H |
@@ -1,64 +1,64 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QXYLEGENDMARKER_H |
|
31 | 31 | #define QXYLEGENDMARKER_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtCharts/QLegendMarker> |
|
35 | 35 | #include <QtCharts/QXYSeries> |
|
36 | 36 | |
|
37 | 37 | QT_CHARTS_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | class QXYLegendMarkerPrivate; |
|
40 | 40 | |
|
41 | 41 | class QT_CHARTS_EXPORT QXYLegendMarker : public QLegendMarker |
|
42 | 42 | { |
|
43 | 43 | Q_OBJECT |
|
44 | 44 | public: |
|
45 |
explicit QXYLegendMarker(QXYSeries *series, QLegend *legend, QObject *parent = |
|
|
45 | explicit QXYLegendMarker(QXYSeries *series, QLegend *legend, QObject *parent = Q_NULLPTR); | |
|
46 | 46 | virtual ~QXYLegendMarker(); |
|
47 | 47 | |
|
48 | 48 | virtual LegendMarkerType type() { return LegendMarkerTypeXY; } |
|
49 | 49 | |
|
50 | 50 | // Related series |
|
51 | 51 | virtual QXYSeries* series(); |
|
52 | 52 | |
|
53 | 53 | protected: |
|
54 |
QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent = |
|
|
54 | QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent = Q_NULLPTR); | |
|
55 | 55 | |
|
56 | 56 | private: |
|
57 | 57 | Q_DECLARE_PRIVATE(QXYLegendMarker) |
|
58 | 58 | Q_DISABLE_COPY(QXYLegendMarker) |
|
59 | 59 | |
|
60 | 60 | }; |
|
61 | 61 | |
|
62 | 62 | QT_CHARTS_END_NAMESPACE |
|
63 | 63 | |
|
64 | 64 | #endif // QXYLEGENDMARKER_H |
@@ -1,61 +1,61 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QLINESERIES_H |
|
31 | 31 | #define QLINESERIES_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtCharts/QXYSeries> |
|
35 | 35 | #include <QtGui/QPen> |
|
36 | 36 | |
|
37 | 37 | QT_CHARTS_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | class QLineSeriesPrivate; |
|
40 | 40 | |
|
41 | 41 | class QT_CHARTS_EXPORT QLineSeries : public QXYSeries |
|
42 | 42 | { |
|
43 | 43 | Q_OBJECT |
|
44 | 44 | |
|
45 | 45 | public: |
|
46 |
explicit QLineSeries(QObject *parent = |
|
|
46 | explicit QLineSeries(QObject *parent = Q_NULLPTR); | |
|
47 | 47 | ~QLineSeries(); |
|
48 | 48 | QAbstractSeries::SeriesType type() const; |
|
49 | 49 | |
|
50 | 50 | protected: |
|
51 |
QLineSeries(QLineSeriesPrivate &d, QObject *parent = |
|
|
51 | QLineSeries(QLineSeriesPrivate &d, QObject *parent = Q_NULLPTR); | |
|
52 | 52 | |
|
53 | 53 | private: |
|
54 | 54 | Q_DECLARE_PRIVATE(QLineSeries) |
|
55 | 55 | Q_DISABLE_COPY(QLineSeries) |
|
56 | 56 | friend class LineChartItem; |
|
57 | 57 | }; |
|
58 | 58 | |
|
59 | 59 | QT_CHARTS_END_NAMESPACE |
|
60 | 60 | |
|
61 | 61 | #endif // QLINESERIES_H |
@@ -1,79 +1,79 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QHPIEMODELMAPPER_H |
|
31 | 31 | #define QHPIEMODELMAPPER_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QPieModelMapper> |
|
34 | 34 | |
|
35 | 35 | QT_CHARTS_BEGIN_NAMESPACE |
|
36 | 36 | /* Comment line for syncqt to generate the fwd-include correctly, due to QTBUG-22432 */ |
|
37 | 37 | class QT_CHARTS_EXPORT QHPieModelMapper : public QPieModelMapper |
|
38 | 38 | { |
|
39 | 39 | Q_OBJECT |
|
40 | 40 | Q_PROPERTY(QPieSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) |
|
41 | 41 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced) |
|
42 | 42 | Q_PROPERTY(int valuesRow READ valuesRow WRITE setValuesRow NOTIFY valuesRowChanged) |
|
43 | 43 | Q_PROPERTY(int labelsRow READ labelsRow WRITE setLabelsRow NOTIFY labelsRowChanged) |
|
44 | 44 | Q_PROPERTY(int firstColumn READ firstColumn WRITE setFirstColumn NOTIFY firstColumnChanged) |
|
45 | 45 | Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount NOTIFY columnCountChanged) |
|
46 | 46 | |
|
47 | 47 | public: |
|
48 |
explicit QHPieModelMapper(QObject *parent = |
|
|
48 | explicit QHPieModelMapper(QObject *parent = Q_NULLPTR); | |
|
49 | 49 | |
|
50 | 50 | QAbstractItemModel *model() const; |
|
51 | 51 | void setModel(QAbstractItemModel *model); |
|
52 | 52 | |
|
53 | 53 | QPieSeries *series() const; |
|
54 | 54 | void setSeries(QPieSeries *series); |
|
55 | 55 | |
|
56 | 56 | int valuesRow() const; |
|
57 | 57 | void setValuesRow(int valuesRow); |
|
58 | 58 | |
|
59 | 59 | int labelsRow() const; |
|
60 | 60 | void setLabelsRow(int labelsRow); |
|
61 | 61 | |
|
62 | 62 | int firstColumn() const; |
|
63 | 63 | void setFirstColumn(int firstColumn); |
|
64 | 64 | |
|
65 | 65 | int columnCount() const; |
|
66 | 66 | void setColumnCount(int columnCount); |
|
67 | 67 | |
|
68 | 68 | Q_SIGNALS: |
|
69 | 69 | void seriesReplaced(); |
|
70 | 70 | void modelReplaced(); |
|
71 | 71 | void valuesRowChanged(); |
|
72 | 72 | void labelsRowChanged(); |
|
73 | 73 | void firstColumnChanged(); |
|
74 | 74 | void columnCountChanged(); |
|
75 | 75 | }; |
|
76 | 76 | |
|
77 | 77 | QT_CHARTS_END_NAMESPACE |
|
78 | 78 | |
|
79 | 79 | #endif // QHPIEMODELMAPPER_H |
@@ -1,577 +1,578 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include <QtCharts/QPieModelMapper> |
|
31 | 31 | #include <private/qpiemodelmapper_p.h> |
|
32 | 32 | #include <QtCharts/QPieSeries> |
|
33 | 33 | #include <QtCharts/QPieSlice> |
|
34 | 34 | #include <QtCore/QAbstractItemModel> |
|
35 | 35 | |
|
36 | 36 | QT_CHARTS_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | QPieModelMapper::QPieModelMapper(QObject *parent) |
|
39 | 39 | : QObject(parent), |
|
40 | 40 | d_ptr(new QPieModelMapperPrivate(this)) |
|
41 | 41 | { |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | QAbstractItemModel *QPieModelMapper::model() const |
|
45 | 45 | { |
|
46 | 46 | Q_D(const QPieModelMapper); |
|
47 | 47 | return d->m_model; |
|
48 | 48 | } |
|
49 | 49 | |
|
50 | 50 | void QPieModelMapper::setModel(QAbstractItemModel *model) |
|
51 | 51 | { |
|
52 | 52 | if (model == 0) |
|
53 | 53 | return; |
|
54 | 54 | |
|
55 | 55 | Q_D(QPieModelMapper); |
|
56 | 56 | if (d->m_model) { |
|
57 | 57 | disconnect(d->m_model, 0, d, 0); |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | d->m_model = model; |
|
61 | 61 | d->initializePieFromModel(); |
|
62 | 62 | // connect signals from the model |
|
63 | connect(d->m_model, SIGNAL(modelReset()), d, SLOT(initializePieFromModel())); | |
|
63 | 64 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
64 | 65 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
65 | 66 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
66 | 67 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
67 | 68 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); |
|
68 | 69 | connect(d->m_model, SIGNAL(destroyed()), d, SLOT(handleModelDestroyed())); |
|
69 | 70 | } |
|
70 | 71 | |
|
71 | 72 | QPieSeries *QPieModelMapper::series() const |
|
72 | 73 | { |
|
73 | 74 | Q_D(const QPieModelMapper); |
|
74 | 75 | return d->m_series; |
|
75 | 76 | } |
|
76 | 77 | |
|
77 | 78 | void QPieModelMapper::setSeries(QPieSeries *series) |
|
78 | 79 | { |
|
79 | 80 | Q_D(QPieModelMapper); |
|
80 | 81 | if (d->m_series) { |
|
81 | 82 | disconnect(d->m_series, 0, d, 0); |
|
82 | 83 | } |
|
83 | 84 | |
|
84 | 85 | if (series == 0) |
|
85 | 86 | return; |
|
86 | 87 | |
|
87 | 88 | d->m_series = series; |
|
88 | 89 | d->initializePieFromModel(); |
|
89 | 90 | // connect the signals from the series |
|
90 | 91 | connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>))); |
|
91 | 92 | connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>))); |
|
92 | 93 | connect(d->m_series, SIGNAL(destroyed()), d, SLOT(handleSeriesDestroyed())); |
|
93 | 94 | } |
|
94 | 95 | |
|
95 | 96 | /*! |
|
96 | 97 | Defines which row/column of the model contains the first slice value. |
|
97 | 98 | Minimal and default value is: 0 |
|
98 | 99 | */ |
|
99 | 100 | int QPieModelMapper::first() const |
|
100 | 101 | { |
|
101 | 102 | Q_D(const QPieModelMapper); |
|
102 | 103 | return d->m_first; |
|
103 | 104 | } |
|
104 | 105 | |
|
105 | 106 | /*! |
|
106 | 107 | Sets which row/column of the model contains the \a first slice value. |
|
107 | 108 | Minimal and default value is: 0 |
|
108 | 109 | */ |
|
109 | 110 | void QPieModelMapper::setFirst(int first) |
|
110 | 111 | { |
|
111 | 112 | Q_D(QPieModelMapper); |
|
112 | 113 | d->m_first = qMax(first, 0); |
|
113 | 114 | d->initializePieFromModel(); |
|
114 | 115 | } |
|
115 | 116 | |
|
116 | 117 | /*! |
|
117 | 118 | Defines the number of rows/columns of the model that are mapped as the data for QPieSeries |
|
118 | 119 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
119 | 120 | */ |
|
120 | 121 | int QPieModelMapper::count() const |
|
121 | 122 | { |
|
122 | 123 | Q_D(const QPieModelMapper); |
|
123 | 124 | return d->m_count; |
|
124 | 125 | } |
|
125 | 126 | |
|
126 | 127 | /*! |
|
127 | 128 | Defines the \a count of rows/columns of the model that are mapped as the data for QPieSeries |
|
128 | 129 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
129 | 130 | */ |
|
130 | 131 | void QPieModelMapper::setCount(int count) |
|
131 | 132 | { |
|
132 | 133 | Q_D(QPieModelMapper); |
|
133 | 134 | d->m_count = qMax(count, -1); |
|
134 | 135 | d->initializePieFromModel(); |
|
135 | 136 | } |
|
136 | 137 | |
|
137 | 138 | /*! |
|
138 | 139 | Returns the orientation that is used when QPieModelMapper accesses the model. |
|
139 | 140 | This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal) |
|
140 | 141 | or from columns (Qt::Vertical) |
|
141 | 142 | */ |
|
142 | 143 | Qt::Orientation QPieModelMapper::orientation() const |
|
143 | 144 | { |
|
144 | 145 | Q_D(const QPieModelMapper); |
|
145 | 146 | return d->m_orientation; |
|
146 | 147 | } |
|
147 | 148 | |
|
148 | 149 | /*! |
|
149 | 150 | Returns the \a orientation that is used when QPieModelMapper accesses the model. |
|
150 | 151 | This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal) |
|
151 | 152 | or from columns (Qt::Vertical) |
|
152 | 153 | */ |
|
153 | 154 | void QPieModelMapper::setOrientation(Qt::Orientation orientation) |
|
154 | 155 | { |
|
155 | 156 | Q_D(QPieModelMapper); |
|
156 | 157 | d->m_orientation = orientation; |
|
157 | 158 | d->initializePieFromModel(); |
|
158 | 159 | } |
|
159 | 160 | |
|
160 | 161 | /*! |
|
161 | 162 | Returns which section of the model is kept in sync with the values of the pie's slices |
|
162 | 163 | */ |
|
163 | 164 | int QPieModelMapper::valuesSection() const |
|
164 | 165 | { |
|
165 | 166 | Q_D(const QPieModelMapper); |
|
166 | 167 | return d->m_valuesSection; |
|
167 | 168 | } |
|
168 | 169 | |
|
169 | 170 | /*! |
|
170 | 171 | Sets the model section that is kept in sync with the pie slices values. |
|
171 | 172 | Parameter \a valuesSection specifies the section of the model. |
|
172 | 173 | */ |
|
173 | 174 | void QPieModelMapper::setValuesSection(int valuesSection) |
|
174 | 175 | { |
|
175 | 176 | Q_D(QPieModelMapper); |
|
176 | 177 | d->m_valuesSection = qMax(-1, valuesSection); |
|
177 | 178 | d->initializePieFromModel(); |
|
178 | 179 | } |
|
179 | 180 | |
|
180 | 181 | /*! |
|
181 | 182 | Returns which section of the model is kept in sync with the labels of the pie's slices |
|
182 | 183 | */ |
|
183 | 184 | int QPieModelMapper::labelsSection() const |
|
184 | 185 | { |
|
185 | 186 | Q_D(const QPieModelMapper); |
|
186 | 187 | return d->m_labelsSection; |
|
187 | 188 | } |
|
188 | 189 | |
|
189 | 190 | /*! |
|
190 | 191 | Sets the model section that is kept in sync with the pie slices labels. |
|
191 | 192 | Parameter \a labelsSection specifies the section of the model. |
|
192 | 193 | */ |
|
193 | 194 | void QPieModelMapper::setLabelsSection(int labelsSection) |
|
194 | 195 | { |
|
195 | 196 | Q_D(QPieModelMapper); |
|
196 | 197 | d->m_labelsSection = qMax(-1, labelsSection); |
|
197 | 198 | d->initializePieFromModel(); |
|
198 | 199 | } |
|
199 | 200 | |
|
200 | 201 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
201 | 202 | |
|
202 | 203 | QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) : |
|
203 | 204 | QObject(q), |
|
204 | 205 | m_series(0), |
|
205 | 206 | m_model(0), |
|
206 | 207 | m_first(0), |
|
207 | 208 | m_count(-1), |
|
208 | 209 | m_orientation(Qt::Vertical), |
|
209 | 210 | m_valuesSection(-1), |
|
210 | 211 | m_labelsSection(-1), |
|
211 | 212 | m_seriesSignalsBlock(false), |
|
212 | 213 | m_modelSignalsBlock(false), |
|
213 | 214 | q_ptr(q) |
|
214 | 215 | { |
|
215 | 216 | } |
|
216 | 217 | |
|
217 | 218 | void QPieModelMapperPrivate::blockModelSignals(bool block) |
|
218 | 219 | { |
|
219 | 220 | m_modelSignalsBlock = block; |
|
220 | 221 | } |
|
221 | 222 | |
|
222 | 223 | void QPieModelMapperPrivate::blockSeriesSignals(bool block) |
|
223 | 224 | { |
|
224 | 225 | m_seriesSignalsBlock = block; |
|
225 | 226 | } |
|
226 | 227 | |
|
227 | 228 | |
|
228 | 229 | QPieSlice *QPieModelMapperPrivate::pieSlice(QModelIndex index) const |
|
229 | 230 | { |
|
230 | 231 | if (!index.isValid()) |
|
231 | 232 | return 0; // index is invalid |
|
232 | 233 | |
|
233 | 234 | if (m_orientation == Qt::Vertical && (index.column() == m_valuesSection || index.column() == m_labelsSection)) { |
|
234 | 235 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { |
|
235 | 236 | if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) |
|
236 | 237 | return m_series->slices().at(index.row() - m_first); |
|
237 | 238 | else |
|
238 | 239 | return 0; |
|
239 | 240 | } |
|
240 | 241 | } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesSection || index.row() == m_labelsSection)) { |
|
241 | 242 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) { |
|
242 | 243 | if (m_model->index(m_valuesSection, index.column()).isValid() && m_model->index(m_labelsSection, index.column()).isValid()) |
|
243 | 244 | return m_series->slices().at(index.column() - m_first); |
|
244 | 245 | else |
|
245 | 246 | return 0; |
|
246 | 247 | } |
|
247 | 248 | } |
|
248 | 249 | return 0; // This part of model has not been mapped to any slice |
|
249 | 250 | } |
|
250 | 251 | |
|
251 | 252 | QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos) |
|
252 | 253 | { |
|
253 | 254 | if (m_count != -1 && slicePos >= m_count) |
|
254 | 255 | return QModelIndex(); // invalid |
|
255 | 256 | |
|
256 | 257 | if (m_orientation == Qt::Vertical) |
|
257 | 258 | return m_model->index(slicePos + m_first, m_valuesSection); |
|
258 | 259 | else |
|
259 | 260 | return m_model->index(m_valuesSection, slicePos + m_first); |
|
260 | 261 | } |
|
261 | 262 | |
|
262 | 263 | QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos) |
|
263 | 264 | { |
|
264 | 265 | if (m_count != -1 && slicePos >= m_count) |
|
265 | 266 | return QModelIndex(); // invalid |
|
266 | 267 | |
|
267 | 268 | if (m_orientation == Qt::Vertical) |
|
268 | 269 | return m_model->index(slicePos + m_first, m_labelsSection); |
|
269 | 270 | else |
|
270 | 271 | return m_model->index(m_labelsSection, slicePos + m_first); |
|
271 | 272 | } |
|
272 | 273 | |
|
273 | 274 | bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const |
|
274 | 275 | { |
|
275 | 276 | if (m_orientation == Qt::Vertical && index.column() == m_labelsSection) |
|
276 | 277 | return true; |
|
277 | 278 | else if (m_orientation == Qt::Horizontal && index.row() == m_labelsSection) |
|
278 | 279 | return true; |
|
279 | 280 | |
|
280 | 281 | return false; |
|
281 | 282 | } |
|
282 | 283 | |
|
283 | 284 | bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const |
|
284 | 285 | { |
|
285 | 286 | if (m_orientation == Qt::Vertical && index.column() == m_valuesSection) |
|
286 | 287 | return true; |
|
287 | 288 | else if (m_orientation == Qt::Horizontal && index.row() == m_valuesSection) |
|
288 | 289 | return true; |
|
289 | 290 | |
|
290 | 291 | return false; |
|
291 | 292 | } |
|
292 | 293 | |
|
293 | 294 | void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice *> slices) |
|
294 | 295 | { |
|
295 | 296 | if (m_seriesSignalsBlock) |
|
296 | 297 | return; |
|
297 | 298 | |
|
298 | 299 | if (slices.count() == 0) |
|
299 | 300 | return; |
|
300 | 301 | |
|
301 | 302 | int firstIndex = m_series->slices().indexOf(slices.at(0)); |
|
302 | 303 | if (firstIndex == -1) |
|
303 | 304 | return; |
|
304 | 305 | |
|
305 | 306 | if (m_count != -1) |
|
306 | 307 | m_count += slices.count(); |
|
307 | 308 | |
|
308 | 309 | for (int i = firstIndex; i < firstIndex + slices.count(); i++) { |
|
309 | 310 | m_slices.insert(i, slices.at(i - firstIndex)); |
|
310 | 311 | connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); |
|
311 | 312 | connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
312 | 313 | } |
|
313 | 314 | |
|
314 | 315 | blockModelSignals(); |
|
315 | 316 | if (m_orientation == Qt::Vertical) |
|
316 | 317 | m_model->insertRows(firstIndex + m_first, slices.count()); |
|
317 | 318 | else |
|
318 | 319 | m_model->insertColumns(firstIndex + m_first, slices.count()); |
|
319 | 320 | |
|
320 | 321 | for (int i = firstIndex; i < firstIndex + slices.count(); i++) { |
|
321 | 322 | m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value()); |
|
322 | 323 | m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label()); |
|
323 | 324 | } |
|
324 | 325 | blockModelSignals(false); |
|
325 | 326 | } |
|
326 | 327 | |
|
327 | 328 | void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice *> slices) |
|
328 | 329 | { |
|
329 | 330 | if (m_seriesSignalsBlock) |
|
330 | 331 | return; |
|
331 | 332 | |
|
332 | 333 | if (slices.count() == 0) |
|
333 | 334 | return; |
|
334 | 335 | |
|
335 | 336 | int firstIndex = m_slices.indexOf(slices.at(0)); |
|
336 | 337 | if (firstIndex == -1) |
|
337 | 338 | return; |
|
338 | 339 | |
|
339 | 340 | if (m_count != -1) |
|
340 | 341 | m_count -= slices.count(); |
|
341 | 342 | |
|
342 | 343 | for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--) |
|
343 | 344 | m_slices.removeAt(i); |
|
344 | 345 | |
|
345 | 346 | blockModelSignals(); |
|
346 | 347 | if (m_orientation == Qt::Vertical) |
|
347 | 348 | m_model->removeRows(firstIndex + m_first, slices.count()); |
|
348 | 349 | else |
|
349 | 350 | m_model->removeColumns(firstIndex + m_first, slices.count()); |
|
350 | 351 | blockModelSignals(false); |
|
351 | 352 | } |
|
352 | 353 | |
|
353 | 354 | void QPieModelMapperPrivate::sliceLabelChanged() |
|
354 | 355 | { |
|
355 | 356 | if (m_seriesSignalsBlock) |
|
356 | 357 | return; |
|
357 | 358 | |
|
358 | 359 | blockModelSignals(); |
|
359 | 360 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); |
|
360 | 361 | m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label()); |
|
361 | 362 | blockModelSignals(false); |
|
362 | 363 | } |
|
363 | 364 | |
|
364 | 365 | void QPieModelMapperPrivate::sliceValueChanged() |
|
365 | 366 | { |
|
366 | 367 | if (m_seriesSignalsBlock) |
|
367 | 368 | return; |
|
368 | 369 | |
|
369 | 370 | blockModelSignals(); |
|
370 | 371 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); |
|
371 | 372 | m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value()); |
|
372 | 373 | blockModelSignals(false); |
|
373 | 374 | } |
|
374 | 375 | |
|
375 | 376 | void QPieModelMapperPrivate::handleSeriesDestroyed() |
|
376 | 377 | { |
|
377 | 378 | m_series = 0; |
|
378 | 379 | } |
|
379 | 380 | |
|
380 | 381 | void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
381 | 382 | { |
|
382 | 383 | if (m_model == 0 || m_series == 0) |
|
383 | 384 | return; |
|
384 | 385 | |
|
385 | 386 | if (m_modelSignalsBlock) |
|
386 | 387 | return; |
|
387 | 388 | |
|
388 | 389 | blockSeriesSignals(); |
|
389 | 390 | QModelIndex index; |
|
390 | 391 | QPieSlice *slice; |
|
391 | 392 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
392 | 393 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
393 | 394 | index = topLeft.sibling(row, column); |
|
394 | 395 | slice = pieSlice(index); |
|
395 | 396 | if (slice) { |
|
396 | 397 | if (isValueIndex(index)) |
|
397 | 398 | slice->setValue(m_model->data(index, Qt::DisplayRole).toReal()); |
|
398 | 399 | if (isLabelIndex(index)) |
|
399 | 400 | slice->setLabel(m_model->data(index, Qt::DisplayRole).toString()); |
|
400 | 401 | } |
|
401 | 402 | } |
|
402 | 403 | } |
|
403 | 404 | blockSeriesSignals(false); |
|
404 | 405 | } |
|
405 | 406 | |
|
406 | 407 | |
|
407 | 408 | void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
408 | 409 | { |
|
409 | 410 | Q_UNUSED(parent); |
|
410 | 411 | if (m_modelSignalsBlock) |
|
411 | 412 | return; |
|
412 | 413 | |
|
413 | 414 | blockSeriesSignals(); |
|
414 | 415 | if (m_orientation == Qt::Vertical) |
|
415 | 416 | insertData(start, end); |
|
416 | 417 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie |
|
417 | 418 | initializePieFromModel(); |
|
418 | 419 | blockSeriesSignals(false); |
|
419 | 420 | } |
|
420 | 421 | |
|
421 | 422 | void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
422 | 423 | { |
|
423 | 424 | Q_UNUSED(parent); |
|
424 | 425 | if (m_modelSignalsBlock) |
|
425 | 426 | return; |
|
426 | 427 | |
|
427 | 428 | blockSeriesSignals(); |
|
428 | 429 | if (m_orientation == Qt::Vertical) |
|
429 | 430 | removeData(start, end); |
|
430 | 431 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie |
|
431 | 432 | initializePieFromModel(); |
|
432 | 433 | blockSeriesSignals(false); |
|
433 | 434 | } |
|
434 | 435 | |
|
435 | 436 | void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
436 | 437 | { |
|
437 | 438 | Q_UNUSED(parent); |
|
438 | 439 | if (m_modelSignalsBlock) |
|
439 | 440 | return; |
|
440 | 441 | |
|
441 | 442 | blockSeriesSignals(); |
|
442 | 443 | if (m_orientation == Qt::Horizontal) |
|
443 | 444 | insertData(start, end); |
|
444 | 445 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie |
|
445 | 446 | initializePieFromModel(); |
|
446 | 447 | blockSeriesSignals(false); |
|
447 | 448 | } |
|
448 | 449 | |
|
449 | 450 | void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
450 | 451 | { |
|
451 | 452 | Q_UNUSED(parent); |
|
452 | 453 | if (m_modelSignalsBlock) |
|
453 | 454 | return; |
|
454 | 455 | |
|
455 | 456 | blockSeriesSignals(); |
|
456 | 457 | if (m_orientation == Qt::Horizontal) |
|
457 | 458 | removeData(start, end); |
|
458 | 459 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie |
|
459 | 460 | initializePieFromModel(); |
|
460 | 461 | blockSeriesSignals(false); |
|
461 | 462 | } |
|
462 | 463 | |
|
463 | 464 | void QPieModelMapperPrivate::handleModelDestroyed() |
|
464 | 465 | { |
|
465 | 466 | m_model = 0; |
|
466 | 467 | } |
|
467 | 468 | |
|
468 | 469 | void QPieModelMapperPrivate::insertData(int start, int end) |
|
469 | 470 | { |
|
470 | 471 | if (m_model == 0 || m_series == 0) |
|
471 | 472 | return; |
|
472 | 473 | |
|
473 | 474 | if (m_count != -1 && start >= m_first + m_count) { |
|
474 | 475 | return; |
|
475 | 476 | } else { |
|
476 | 477 | int addedCount = end - start + 1; |
|
477 | 478 | if (m_count != -1 && addedCount > m_count) |
|
478 | 479 | addedCount = m_count; |
|
479 | 480 | int first = qMax(start, m_first); |
|
480 | 481 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); |
|
481 | 482 | for (int i = first; i <= last; i++) { |
|
482 | 483 | QModelIndex valueIndex = valueModelIndex(i - m_first); |
|
483 | 484 | QModelIndex labelIndex = labelModelIndex(i - m_first); |
|
484 | 485 | if (valueIndex.isValid() && labelIndex.isValid()) { |
|
485 | 486 | QPieSlice *slice = new QPieSlice; |
|
486 | 487 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
487 | 488 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); |
|
488 | 489 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); |
|
489 | 490 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
490 | 491 | m_series->insert(i - m_first, slice); |
|
491 | 492 | m_slices.insert(i - m_first, slice); |
|
492 | 493 | } |
|
493 | 494 | } |
|
494 | 495 | |
|
495 | 496 | // remove excess of slices (abouve m_count) |
|
496 | 497 | if (m_count != -1 && m_series->slices().size() > m_count) |
|
497 | 498 | for (int i = m_series->slices().size() - 1; i >= m_count; i--) { |
|
498 | 499 | m_series->remove(m_series->slices().at(i)); |
|
499 | 500 | m_slices.removeAt(i); |
|
500 | 501 | } |
|
501 | 502 | } |
|
502 | 503 | } |
|
503 | 504 | |
|
504 | 505 | void QPieModelMapperPrivate::removeData(int start, int end) |
|
505 | 506 | { |
|
506 | 507 | if (m_model == 0 || m_series == 0) |
|
507 | 508 | return; |
|
508 | 509 | |
|
509 | 510 | int removedCount = end - start + 1; |
|
510 | 511 | if (m_count != -1 && start >= m_first + m_count) { |
|
511 | 512 | return; |
|
512 | 513 | } else { |
|
513 | 514 | int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed |
|
514 | 515 | int first = qMax(start, m_first); // get the index of the first item that will be removed. |
|
515 | 516 | int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed. |
|
516 | 517 | for (int i = last; i >= first; i--) { |
|
517 | 518 | m_series->remove(m_series->slices().at(i - m_first)); |
|
518 | 519 | m_slices.removeAt(i - m_first); |
|
519 | 520 | } |
|
520 | 521 | |
|
521 | 522 | if (m_count != -1) { |
|
522 | 523 | int itemsAvailable; // check how many are available to be added |
|
523 | 524 | if (m_orientation == Qt::Vertical) |
|
524 | 525 | itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size(); |
|
525 | 526 | else |
|
526 | 527 | itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size(); |
|
527 | 528 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled. |
|
528 | 529 | int currentSize = m_series->slices().size(); |
|
529 | 530 | if (toBeAdded > 0) |
|
530 | 531 | for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) { |
|
531 | 532 | QModelIndex valueIndex = valueModelIndex(i - m_first); |
|
532 | 533 | QModelIndex labelIndex = labelModelIndex(i - m_first); |
|
533 | 534 | if (valueIndex.isValid() && labelIndex.isValid()) { |
|
534 | 535 | QPieSlice *slice = new QPieSlice; |
|
535 | 536 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
536 | 537 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); |
|
537 | 538 | m_series->insert(i, slice); |
|
538 | 539 | m_slices.insert(i, slice); |
|
539 | 540 | } |
|
540 | 541 | } |
|
541 | 542 | } |
|
542 | 543 | } |
|
543 | 544 | } |
|
544 | 545 | |
|
545 | 546 | void QPieModelMapperPrivate::initializePieFromModel() |
|
546 | 547 | { |
|
547 | 548 | if (m_model == 0 || m_series == 0) |
|
548 | 549 | return; |
|
549 | 550 | |
|
550 | 551 | blockSeriesSignals(); |
|
551 | 552 | // clear current content |
|
552 | 553 | m_series->clear(); |
|
553 | 554 | m_slices.clear(); |
|
554 | 555 | |
|
555 | 556 | // create the initial slices set |
|
556 | 557 | int slicePos = 0; |
|
557 | 558 | QModelIndex valueIndex = valueModelIndex(slicePos); |
|
558 | 559 | QModelIndex labelIndex = labelModelIndex(slicePos); |
|
559 | 560 | while (valueIndex.isValid() && labelIndex.isValid()) { |
|
560 | 561 | QPieSlice *slice = new QPieSlice; |
|
561 | 562 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); |
|
562 | 563 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
563 | 564 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); |
|
564 | 565 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
565 | 566 | m_series->append(slice); |
|
566 | 567 | m_slices.append(slice); |
|
567 | 568 | slicePos++; |
|
568 | 569 | valueIndex = valueModelIndex(slicePos); |
|
569 | 570 | labelIndex = labelModelIndex(slicePos); |
|
570 | 571 | } |
|
571 | 572 | blockSeriesSignals(false); |
|
572 | 573 | } |
|
573 | 574 | |
|
574 | 575 | #include "moc_qpiemodelmapper_p.cpp" |
|
575 | 576 | #include "moc_qpiemodelmapper.cpp" |
|
576 | 577 | |
|
577 | 578 | QT_CHARTS_END_NAMESPACE |
@@ -1,80 +1,80 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QPIEMODELMAPPER_H |
|
31 | 31 | #define QPIEMODELMAPPER_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtCore/QObject> |
|
35 | 35 | |
|
36 | 36 | QT_BEGIN_NAMESPACE |
|
37 | 37 | class QAbstractItemModel; |
|
38 | 38 | QT_END_NAMESPACE |
|
39 | 39 | |
|
40 | 40 | QT_CHARTS_BEGIN_NAMESPACE |
|
41 | 41 | |
|
42 | 42 | class QPieModelMapperPrivate; |
|
43 | 43 | class QPieSeries; |
|
44 | 44 | |
|
45 | 45 | class QT_CHARTS_EXPORT QPieModelMapper : public QObject |
|
46 | 46 | { |
|
47 | 47 | Q_OBJECT |
|
48 | 48 | |
|
49 | 49 | protected: |
|
50 |
explicit QPieModelMapper(QObject *parent = |
|
|
50 | explicit QPieModelMapper(QObject *parent = Q_NULLPTR); | |
|
51 | 51 | |
|
52 | 52 | QAbstractItemModel *model() const; |
|
53 | 53 | void setModel(QAbstractItemModel *model); |
|
54 | 54 | |
|
55 | 55 | QPieSeries *series() const; |
|
56 | 56 | void setSeries(QPieSeries *series); |
|
57 | 57 | |
|
58 | 58 | int first() const; |
|
59 | 59 | void setFirst(int first); |
|
60 | 60 | |
|
61 | 61 | int count() const; |
|
62 | 62 | void setCount(int count); |
|
63 | 63 | |
|
64 | 64 | int valuesSection() const; |
|
65 | 65 | void setValuesSection(int valuesSection); |
|
66 | 66 | |
|
67 | 67 | int labelsSection() const; |
|
68 | 68 | void setLabelsSection(int labelsSection); |
|
69 | 69 | |
|
70 | 70 | Qt::Orientation orientation() const; |
|
71 | 71 | void setOrientation(Qt::Orientation orientation); |
|
72 | 72 | |
|
73 | 73 | protected: |
|
74 | 74 | QPieModelMapperPrivate * const d_ptr; |
|
75 | 75 | Q_DECLARE_PRIVATE(QPieModelMapper) |
|
76 | 76 | }; |
|
77 | 77 | |
|
78 | 78 | QT_CHARTS_END_NAMESPACE |
|
79 | 79 | |
|
80 | 80 | #endif // QPIEMODELMAPPER_H |
@@ -1,115 +1,115 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QPIESERIES_H |
|
31 | 31 | #define QPIESERIES_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QAbstractSeries> |
|
34 | 34 | #include <QtCharts/QPieSlice> |
|
35 | 35 | |
|
36 | 36 | QT_CHARTS_BEGIN_NAMESPACE |
|
37 | 37 | class QPieSeriesPrivate; |
|
38 | 38 | |
|
39 | 39 | class QT_CHARTS_EXPORT QPieSeries : public QAbstractSeries |
|
40 | 40 | { |
|
41 | 41 | Q_OBJECT |
|
42 | 42 | Q_PROPERTY(qreal horizontalPosition READ horizontalPosition WRITE setHorizontalPosition) |
|
43 | 43 | Q_PROPERTY(qreal verticalPosition READ verticalPosition WRITE setVerticalPosition) |
|
44 | 44 | Q_PROPERTY(qreal size READ pieSize WRITE setPieSize) |
|
45 | 45 | Q_PROPERTY(qreal startAngle READ pieStartAngle WRITE setPieStartAngle) |
|
46 | 46 | Q_PROPERTY(qreal endAngle READ pieEndAngle WRITE setPieEndAngle) |
|
47 | 47 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
|
48 | 48 | Q_PROPERTY(qreal sum READ sum NOTIFY sumChanged) |
|
49 | 49 | Q_PROPERTY(qreal holeSize READ holeSize WRITE setHoleSize) |
|
50 | 50 | |
|
51 | 51 | public: |
|
52 |
explicit QPieSeries(QObject *parent = |
|
|
52 | explicit QPieSeries(QObject *parent = Q_NULLPTR); | |
|
53 | 53 | virtual ~QPieSeries(); |
|
54 | 54 | |
|
55 | 55 | QAbstractSeries::SeriesType type() const; |
|
56 | 56 | |
|
57 | 57 | bool append(QPieSlice *slice); |
|
58 | 58 | bool append(QList<QPieSlice *> slices); |
|
59 | 59 | QPieSeries &operator << (QPieSlice *slice); |
|
60 | 60 | QPieSlice *append(QString label, qreal value); |
|
61 | 61 | |
|
62 | 62 | bool insert(int index, QPieSlice *slice); |
|
63 | 63 | |
|
64 | 64 | bool remove(QPieSlice *slice); |
|
65 | 65 | bool take(QPieSlice *slice); |
|
66 | 66 | void clear(); |
|
67 | 67 | |
|
68 | 68 | QList<QPieSlice *> slices() const; |
|
69 | 69 | int count() const; |
|
70 | 70 | |
|
71 | 71 | bool isEmpty() const; |
|
72 | 72 | |
|
73 | 73 | qreal sum() const; |
|
74 | 74 | |
|
75 | 75 | void setHoleSize(qreal holeSize); |
|
76 | 76 | qreal holeSize() const; |
|
77 | 77 | |
|
78 | 78 | void setHorizontalPosition(qreal relativePosition); |
|
79 | 79 | qreal horizontalPosition() const; |
|
80 | 80 | |
|
81 | 81 | void setVerticalPosition(qreal relativePosition); |
|
82 | 82 | qreal verticalPosition() const; |
|
83 | 83 | |
|
84 | 84 | void setPieSize(qreal relativeSize); |
|
85 | 85 | qreal pieSize() const; |
|
86 | 86 | |
|
87 | 87 | void setPieStartAngle(qreal startAngle); |
|
88 | 88 | qreal pieStartAngle() const; |
|
89 | 89 | |
|
90 | 90 | void setPieEndAngle(qreal endAngle); |
|
91 | 91 | qreal pieEndAngle() const; |
|
92 | 92 | |
|
93 | 93 | void setLabelsVisible(bool visible = true); |
|
94 | 94 | void setLabelsPosition(QPieSlice::LabelPosition position); |
|
95 | 95 | |
|
96 | 96 | Q_SIGNALS: |
|
97 | 97 | void added(QList<QPieSlice *> slices); |
|
98 | 98 | void removed(QList<QPieSlice *> slices); |
|
99 | 99 | void clicked(QPieSlice *slice); |
|
100 | 100 | void hovered(QPieSlice *slice, bool state); |
|
101 | 101 | void pressed(QPieSlice *slice); |
|
102 | 102 | void released(QPieSlice *slice); |
|
103 | 103 | void doubleClicked(QPieSlice *slice); |
|
104 | 104 | void countChanged(); |
|
105 | 105 | void sumChanged(); |
|
106 | 106 | |
|
107 | 107 | private: |
|
108 | 108 | Q_DECLARE_PRIVATE(QPieSeries) |
|
109 | 109 | Q_DISABLE_COPY(QPieSeries) |
|
110 | 110 | friend class PieChartItem; |
|
111 | 111 | }; |
|
112 | 112 | |
|
113 | 113 | QT_CHARTS_END_NAMESPACE |
|
114 | 114 | |
|
115 | 115 | #endif // QPIESERIES_H |
@@ -1,159 +1,159 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QPIESLICE_H |
|
31 | 31 | #define QPIESLICE_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtCore/QObject> |
|
35 | 35 | #include <QtGui/QPen> |
|
36 | 36 | #include <QtGui/QBrush> |
|
37 | 37 | #include <QtGui/QFont> |
|
38 | 38 | |
|
39 | 39 | QT_CHARTS_BEGIN_NAMESPACE |
|
40 | 40 | class QPieSlicePrivate; |
|
41 | 41 | class QPieSeries; |
|
42 | 42 | |
|
43 | 43 | class QT_CHARTS_EXPORT QPieSlice : public QObject |
|
44 | 44 | { |
|
45 | 45 | Q_OBJECT |
|
46 | 46 | Q_ENUMS(LabelPosition) |
|
47 | 47 | Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) |
|
48 | 48 | Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged) |
|
49 | 49 | Q_PROPERTY(bool labelVisible READ isLabelVisible WRITE setLabelVisible NOTIFY labelVisibleChanged) |
|
50 | 50 | Q_PROPERTY(LabelPosition labelPosition READ labelPosition WRITE setLabelPosition) |
|
51 | 51 | Q_PROPERTY(bool exploded READ isExploded WRITE setExploded) |
|
52 | 52 | Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) |
|
53 | 53 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
|
54 | 54 | Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged) |
|
55 | 55 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) |
|
56 | 56 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
57 | 57 | Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged) |
|
58 | 58 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) |
|
59 | 59 | Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged) |
|
60 | 60 | Q_PROPERTY(qreal labelArmLengthFactor READ labelArmLengthFactor WRITE setLabelArmLengthFactor) |
|
61 | 61 | Q_PROPERTY(qreal explodeDistanceFactor READ explodeDistanceFactor WRITE setExplodeDistanceFactor) |
|
62 | 62 | Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged) |
|
63 | 63 | Q_PROPERTY(qreal startAngle READ startAngle NOTIFY startAngleChanged) |
|
64 | 64 | Q_PROPERTY(qreal angleSpan READ angleSpan NOTIFY angleSpanChanged) |
|
65 | 65 | |
|
66 | 66 | public: |
|
67 | 67 | enum LabelPosition { |
|
68 | 68 | LabelOutside, |
|
69 | 69 | LabelInsideHorizontal, |
|
70 | 70 | LabelInsideTangential, |
|
71 | 71 | LabelInsideNormal |
|
72 | 72 | }; |
|
73 | 73 | |
|
74 | 74 | public: |
|
75 |
explicit QPieSlice(QObject *parent = |
|
|
76 |
QPieSlice(QString label, qreal value, QObject *parent = |
|
|
75 | explicit QPieSlice(QObject *parent = Q_NULLPTR); | |
|
76 | QPieSlice(QString label, qreal value, QObject *parent = Q_NULLPTR); | |
|
77 | 77 | virtual ~QPieSlice(); |
|
78 | 78 | |
|
79 | 79 | void setLabel(QString label); |
|
80 | 80 | QString label() const; |
|
81 | 81 | |
|
82 | 82 | void setValue(qreal value); |
|
83 | 83 | qreal value() const; |
|
84 | 84 | |
|
85 | 85 | void setLabelVisible(bool visible = true); |
|
86 | 86 | bool isLabelVisible() const; |
|
87 | 87 | |
|
88 | 88 | LabelPosition labelPosition(); |
|
89 | 89 | void setLabelPosition(LabelPosition position); |
|
90 | 90 | |
|
91 | 91 | void setExploded(bool exploded = true); |
|
92 | 92 | bool isExploded() const; |
|
93 | 93 | |
|
94 | 94 | void setPen(const QPen &pen); |
|
95 | 95 | QPen pen() const; |
|
96 | 96 | |
|
97 | 97 | QColor borderColor(); |
|
98 | 98 | void setBorderColor(QColor color); |
|
99 | 99 | |
|
100 | 100 | int borderWidth(); |
|
101 | 101 | void setBorderWidth(int width); |
|
102 | 102 | |
|
103 | 103 | void setBrush(const QBrush &brush); |
|
104 | 104 | QBrush brush() const; |
|
105 | 105 | |
|
106 | 106 | QColor color(); |
|
107 | 107 | void setColor(QColor color); |
|
108 | 108 | |
|
109 | 109 | void setLabelBrush(const QBrush &brush); |
|
110 | 110 | QBrush labelBrush() const; |
|
111 | 111 | |
|
112 | 112 | QColor labelColor(); |
|
113 | 113 | void setLabelColor(QColor color); |
|
114 | 114 | |
|
115 | 115 | void setLabelFont(const QFont &font); |
|
116 | 116 | QFont labelFont() const; |
|
117 | 117 | |
|
118 | 118 | void setLabelArmLengthFactor(qreal factor); |
|
119 | 119 | qreal labelArmLengthFactor() const; |
|
120 | 120 | |
|
121 | 121 | void setExplodeDistanceFactor(qreal factor); |
|
122 | 122 | qreal explodeDistanceFactor() const; |
|
123 | 123 | |
|
124 | 124 | qreal percentage() const; |
|
125 | 125 | qreal startAngle() const; |
|
126 | 126 | qreal angleSpan() const; |
|
127 | 127 | |
|
128 | 128 | QPieSeries *series() const; |
|
129 | 129 | |
|
130 | 130 | Q_SIGNALS: |
|
131 | 131 | void clicked(); |
|
132 | 132 | void hovered(bool state); |
|
133 | 133 | void pressed(); |
|
134 | 134 | void released(); |
|
135 | 135 | void doubleClicked(); |
|
136 | 136 | void labelChanged(); |
|
137 | 137 | void valueChanged(); |
|
138 | 138 | void labelVisibleChanged(); |
|
139 | 139 | void penChanged(); |
|
140 | 140 | void brushChanged(); |
|
141 | 141 | void labelBrushChanged(); |
|
142 | 142 | void labelFontChanged(); |
|
143 | 143 | void percentageChanged(); |
|
144 | 144 | void startAngleChanged(); |
|
145 | 145 | void angleSpanChanged(); |
|
146 | 146 | void colorChanged(); |
|
147 | 147 | void borderColorChanged(); |
|
148 | 148 | void borderWidthChanged(); |
|
149 | 149 | void labelColorChanged(); |
|
150 | 150 | |
|
151 | 151 | private: |
|
152 | 152 | QPieSlicePrivate * const d_ptr; |
|
153 | 153 | Q_DECLARE_PRIVATE(QPieSlice) |
|
154 | 154 | Q_DISABLE_COPY(QPieSlice) |
|
155 | 155 | }; |
|
156 | 156 | |
|
157 | 157 | QT_CHARTS_END_NAMESPACE |
|
158 | 158 | |
|
159 | 159 | #endif // QPIESLICE_H |
@@ -1,79 +1,79 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QVPIEMODELMAPPER_H |
|
31 | 31 | #define QVPIEMODELMAPPER_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QPieModelMapper> |
|
34 | 34 | |
|
35 | 35 | QT_CHARTS_BEGIN_NAMESPACE |
|
36 | 36 | /* Comment line for syncqt to generate the fwd-include correctly, due to QTBUG-22432 */ |
|
37 | 37 | class QT_CHARTS_EXPORT QVPieModelMapper : public QPieModelMapper |
|
38 | 38 | { |
|
39 | 39 | Q_OBJECT |
|
40 | 40 | Q_PROPERTY(QPieSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) |
|
41 | 41 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced) |
|
42 | 42 | Q_PROPERTY(int valuesColumn READ valuesColumn WRITE setValuesColumn NOTIFY valuesColumnChanged) |
|
43 | 43 | Q_PROPERTY(int labelsColumn READ labelsColumn WRITE setLabelsColumn NOTIFY labelsColumnChanged) |
|
44 | 44 | Q_PROPERTY(int firstRow READ firstRow WRITE setFirstRow NOTIFY firstRowChanged) |
|
45 | 45 | Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount NOTIFY rowCountChanged) |
|
46 | 46 | |
|
47 | 47 | public: |
|
48 |
explicit QVPieModelMapper(QObject *parent = |
|
|
48 | explicit QVPieModelMapper(QObject *parent = Q_NULLPTR); | |
|
49 | 49 | |
|
50 | 50 | QAbstractItemModel *model() const; |
|
51 | 51 | void setModel(QAbstractItemModel *model); |
|
52 | 52 | |
|
53 | 53 | QPieSeries *series() const; |
|
54 | 54 | void setSeries(QPieSeries *series); |
|
55 | 55 | |
|
56 | 56 | int valuesColumn() const; |
|
57 | 57 | void setValuesColumn(int valuesColumn); |
|
58 | 58 | |
|
59 | 59 | int labelsColumn() const; |
|
60 | 60 | void setLabelsColumn(int labelsColumn); |
|
61 | 61 | |
|
62 | 62 | int firstRow() const; |
|
63 | 63 | void setFirstRow(int firstRow); |
|
64 | 64 | |
|
65 | 65 | int rowCount() const; |
|
66 | 66 | void setRowCount(int rowCount); |
|
67 | 67 | |
|
68 | 68 | Q_SIGNALS: |
|
69 | 69 | void seriesReplaced(); |
|
70 | 70 | void modelReplaced(); |
|
71 | 71 | void valuesColumnChanged(); |
|
72 | 72 | void labelsColumnChanged(); |
|
73 | 73 | void firstRowChanged(); |
|
74 | 74 | void rowCountChanged(); |
|
75 | 75 | }; |
|
76 | 76 | |
|
77 | 77 | QT_CHARTS_END_NAMESPACE |
|
78 | 78 | |
|
79 | 79 | #endif // QVPIEMODELMAPPER_H |
@@ -1,112 +1,112 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QABSTRACTSERIES_H |
|
31 | 31 | #define QABSTRACTSERIES_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtCharts/QAbstractAxis> |
|
35 | 35 | #include <QtCore/QObject> |
|
36 | 36 | #include <QtGui/QPen> |
|
37 | 37 | |
|
38 | 38 | QT_CHARTS_BEGIN_NAMESPACE |
|
39 | 39 | |
|
40 | 40 | class QAbstractSeriesPrivate; |
|
41 | 41 | class QChart; |
|
42 | 42 | |
|
43 | 43 | class QT_CHARTS_EXPORT QAbstractSeries : public QObject |
|
44 | 44 | { |
|
45 | 45 | Q_OBJECT |
|
46 | 46 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) |
|
47 | 47 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) |
|
48 | 48 | Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged) |
|
49 | 49 | Q_PROPERTY(SeriesType type READ type) |
|
50 | 50 | Q_PROPERTY(bool useOpenGL READ useOpenGL WRITE setUseOpenGL NOTIFY useOpenGLChanged) |
|
51 | 51 | Q_ENUMS(SeriesType) |
|
52 | 52 | |
|
53 | 53 | public: |
|
54 | 54 | enum SeriesType { |
|
55 | 55 | SeriesTypeLine, |
|
56 | 56 | SeriesTypeArea, |
|
57 | 57 | SeriesTypeBar, |
|
58 | 58 | SeriesTypeStackedBar, |
|
59 | 59 | SeriesTypePercentBar, |
|
60 | 60 | SeriesTypePie, |
|
61 | 61 | SeriesTypeScatter, |
|
62 | 62 | SeriesTypeSpline, |
|
63 | 63 | SeriesTypeHorizontalBar, |
|
64 | 64 | SeriesTypeHorizontalStackedBar, |
|
65 | 65 | SeriesTypeHorizontalPercentBar, |
|
66 | 66 | SeriesTypeBoxPlot |
|
67 | 67 | }; |
|
68 | 68 | |
|
69 | 69 | protected: |
|
70 |
QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent = |
|
|
70 | QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent = Q_NULLPTR); | |
|
71 | 71 | |
|
72 | 72 | public: |
|
73 | 73 | ~QAbstractSeries(); |
|
74 | 74 | virtual SeriesType type() const = 0; |
|
75 | 75 | |
|
76 | 76 | void setName(const QString &name); |
|
77 | 77 | QString name() const; |
|
78 | 78 | void setVisible(bool visible = true); |
|
79 | 79 | bool isVisible() const; |
|
80 | 80 | qreal opacity() const; |
|
81 | 81 | void setOpacity(qreal opacity); |
|
82 | 82 | void setUseOpenGL(bool enable = true); |
|
83 | 83 | bool useOpenGL() const; |
|
84 | 84 | |
|
85 | 85 | QChart *chart() const; |
|
86 | 86 | |
|
87 | 87 | bool attachAxis(QAbstractAxis *axis); |
|
88 | 88 | bool detachAxis(QAbstractAxis *axis); |
|
89 | 89 | QList<QAbstractAxis*> attachedAxes(); |
|
90 | 90 | |
|
91 | 91 | void show(); |
|
92 | 92 | void hide(); |
|
93 | 93 | |
|
94 | 94 | Q_SIGNALS: |
|
95 | 95 | void nameChanged(); |
|
96 | 96 | void visibleChanged(); |
|
97 | 97 | void opacityChanged(); |
|
98 | 98 | void useOpenGLChanged(); |
|
99 | 99 | |
|
100 | 100 | protected: |
|
101 | 101 | QScopedPointer<QAbstractSeriesPrivate> d_ptr; |
|
102 | 102 | friend class ChartDataSet; |
|
103 | 103 | friend class ChartPresenter; |
|
104 | 104 | friend class ChartThemeManager; |
|
105 | 105 | friend class QLegendPrivate; |
|
106 | 106 | friend class DeclarativeChart; |
|
107 | 107 | friend class QAreaSeries; |
|
108 | 108 | }; |
|
109 | 109 | |
|
110 | 110 | QT_CHARTS_END_NAMESPACE |
|
111 | 111 | |
|
112 | 112 | #endif // QABSTRACTSERIES_H |
@@ -1,203 +1,203 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QCHART_H |
|
31 | 31 | #define QCHART_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QAbstractSeries> |
|
34 | 34 | #include <QtCharts/QLegend> |
|
35 | 35 | #include <QtWidgets/QGraphicsWidget> |
|
36 | 36 | #include <QtCore/QMargins> |
|
37 | 37 | |
|
38 | 38 | QT_BEGIN_NAMESPACE |
|
39 | 39 | class QGraphicsSceneResizeEvent; |
|
40 | 40 | QT_END_NAMESPACE |
|
41 | 41 | |
|
42 | 42 | QT_CHARTS_BEGIN_NAMESPACE |
|
43 | 43 | |
|
44 | 44 | class QAbstractSeries; |
|
45 | 45 | class QAbstractAxis; |
|
46 | 46 | class QLegend; |
|
47 | 47 | class QChartPrivate; |
|
48 | 48 | class QBoxPlotSeries; |
|
49 | 49 | |
|
50 | 50 | class QT_CHARTS_EXPORT QChart : public QGraphicsWidget |
|
51 | 51 | { |
|
52 | 52 | Q_OBJECT |
|
53 | 53 | Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme) |
|
54 | 54 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
55 | 55 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible) |
|
56 | 56 | Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled) |
|
57 | 57 | Q_PROPERTY(qreal backgroundRoundness READ backgroundRoundness WRITE setBackgroundRoundness) |
|
58 | 58 | Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions) |
|
59 | 59 | Q_PROPERTY(int animationDuration READ animationDuration WRITE setAnimationDuration) |
|
60 | 60 | Q_PROPERTY(QEasingCurve animationEasingCurve READ animationEasingCurve WRITE setAnimationEasingCurve) |
|
61 | 61 | Q_PROPERTY(QMargins margins READ margins WRITE setMargins) |
|
62 | 62 | Q_PROPERTY(QChart::ChartType chartType READ chartType) |
|
63 | 63 | Q_PROPERTY(bool plotAreaBackgroundVisible READ isPlotAreaBackgroundVisible WRITE setPlotAreaBackgroundVisible) |
|
64 | 64 | Q_PROPERTY(bool localizeNumbers READ localizeNumbers WRITE setLocalizeNumbers) |
|
65 | 65 | Q_PROPERTY(QLocale locale READ locale WRITE setLocale) |
|
66 | 66 | Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged) |
|
67 | 67 | Q_ENUMS(ChartTheme) |
|
68 | 68 | Q_ENUMS(AnimationOption) |
|
69 | 69 | Q_ENUMS(ChartType) |
|
70 | 70 | |
|
71 | 71 | public: |
|
72 | 72 | enum ChartType { |
|
73 | 73 | ChartTypeUndefined = 0, |
|
74 | 74 | ChartTypeCartesian, |
|
75 | 75 | ChartTypePolar |
|
76 | 76 | }; |
|
77 | 77 | |
|
78 | 78 | enum ChartTheme { |
|
79 | 79 | ChartThemeLight = 0, |
|
80 | 80 | ChartThemeBlueCerulean, |
|
81 | 81 | ChartThemeDark, |
|
82 | 82 | ChartThemeBrownSand, |
|
83 | 83 | ChartThemeBlueNcs, |
|
84 | 84 | ChartThemeHighContrast, |
|
85 | 85 | ChartThemeBlueIcy, |
|
86 | 86 | ChartThemeQt |
|
87 | 87 | }; |
|
88 | 88 | |
|
89 | 89 | enum AnimationOption { |
|
90 | 90 | NoAnimation = 0x0, |
|
91 | 91 | GridAxisAnimations = 0x1, |
|
92 | 92 | SeriesAnimations = 0x2, |
|
93 | 93 | AllAnimations = 0x3 |
|
94 | 94 | }; |
|
95 | 95 | |
|
96 | 96 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
97 | 97 | |
|
98 | 98 | public: |
|
99 |
explicit QChart(QGraphicsItem *parent = |
|
|
99 | explicit QChart(QGraphicsItem *parent = Q_NULLPTR, Qt::WindowFlags wFlags = Qt::WindowFlags()); | |
|
100 | 100 | ~QChart(); |
|
101 | 101 | |
|
102 | 102 | void addSeries(QAbstractSeries *series); |
|
103 | 103 | void removeSeries(QAbstractSeries *series); |
|
104 | 104 | void removeAllSeries(); |
|
105 | 105 | QList<QAbstractSeries *> series() const; |
|
106 | 106 | |
|
107 | 107 | // *** deprecated *** |
|
108 |
void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = |
|
|
109 |
void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = |
|
|
110 |
QAbstractAxis *axisX(QAbstractSeries *series = |
|
|
111 |
QAbstractAxis *axisY(QAbstractSeries *series = |
|
|
108 | void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = Q_NULLPTR); | |
|
109 | void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = Q_NULLPTR); | |
|
110 | QAbstractAxis *axisX(QAbstractSeries *series = Q_NULLPTR) const; | |
|
111 | QAbstractAxis *axisY(QAbstractSeries *series = Q_NULLPTR) const; | |
|
112 | 112 | // ****************** |
|
113 | 113 | |
|
114 | 114 | void addAxis(QAbstractAxis *axis, Qt::Alignment alignment); |
|
115 | 115 | void removeAxis(QAbstractAxis *axis); |
|
116 |
QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = |
|
|
116 | QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = Q_NULLPTR) const; | |
|
117 | 117 | |
|
118 | 118 | void createDefaultAxes(); |
|
119 | 119 | |
|
120 | 120 | void setTheme(QChart::ChartTheme theme); |
|
121 | 121 | QChart::ChartTheme theme() const; |
|
122 | 122 | |
|
123 | 123 | void setTitle(const QString &title); |
|
124 | 124 | QString title() const; |
|
125 | 125 | void setTitleFont(const QFont &font); |
|
126 | 126 | QFont titleFont() const; |
|
127 | 127 | void setTitleBrush(const QBrush &brush); |
|
128 | 128 | QBrush titleBrush() const; |
|
129 | 129 | |
|
130 | 130 | void setBackgroundBrush(const QBrush &brush); |
|
131 | 131 | QBrush backgroundBrush() const; |
|
132 | 132 | void setBackgroundPen(const QPen &pen); |
|
133 | 133 | QPen backgroundPen() const; |
|
134 | 134 | void setBackgroundVisible(bool visible = true); |
|
135 | 135 | bool isBackgroundVisible() const; |
|
136 | 136 | |
|
137 | 137 | void setDropShadowEnabled(bool enabled = true); |
|
138 | 138 | bool isDropShadowEnabled() const; |
|
139 | 139 | void setBackgroundRoundness(qreal diameter); |
|
140 | 140 | qreal backgroundRoundness() const; |
|
141 | 141 | |
|
142 | 142 | void setAnimationOptions(AnimationOptions options); |
|
143 | 143 | AnimationOptions animationOptions() const; |
|
144 | 144 | void setAnimationDuration(int msecs); |
|
145 | 145 | int animationDuration() const; |
|
146 | 146 | void setAnimationEasingCurve(const QEasingCurve &curve); |
|
147 | 147 | QEasingCurve animationEasingCurve() const; |
|
148 | 148 | |
|
149 | 149 | void zoomIn(); |
|
150 | 150 | void zoomOut(); |
|
151 | 151 | |
|
152 | 152 | void zoomIn(const QRectF &rect); |
|
153 | 153 | void zoom(qreal factor); |
|
154 | 154 | void zoomReset(); |
|
155 | 155 | bool isZoomed(); |
|
156 | 156 | |
|
157 | 157 | void scroll(qreal dx, qreal dy); |
|
158 | 158 | |
|
159 | 159 | QLegend *legend() const; |
|
160 | 160 | |
|
161 | 161 | void setMargins(const QMargins &margins); |
|
162 | 162 | QMargins margins() const; |
|
163 | 163 | |
|
164 | 164 | QRectF plotArea() const; |
|
165 | 165 | void setPlotAreaBackgroundBrush(const QBrush &brush); |
|
166 | 166 | QBrush plotAreaBackgroundBrush() const; |
|
167 | 167 | void setPlotAreaBackgroundPen(const QPen &pen); |
|
168 | 168 | QPen plotAreaBackgroundPen() const; |
|
169 | 169 | void setPlotAreaBackgroundVisible(bool visible = true); |
|
170 | 170 | bool isPlotAreaBackgroundVisible() const; |
|
171 | 171 | void setLocalizeNumbers(bool localize); |
|
172 | 172 | bool localizeNumbers() const; |
|
173 | 173 | void setLocale(const QLocale &locale); |
|
174 | 174 | QLocale locale() const; |
|
175 | 175 | |
|
176 |
QPointF mapToValue(const QPointF &position, QAbstractSeries *series = |
|
|
177 |
QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = |
|
|
176 | QPointF mapToValue(const QPointF &position, QAbstractSeries *series = Q_NULLPTR); | |
|
177 | QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = Q_NULLPTR); | |
|
178 | 178 | |
|
179 | 179 | ChartType chartType() const; |
|
180 | 180 | |
|
181 | 181 | Q_SIGNALS: |
|
182 | 182 | void plotAreaChanged(const QRectF &plotArea); |
|
183 | 183 | |
|
184 | 184 | protected: |
|
185 | 185 | explicit QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags); |
|
186 | 186 | QScopedPointer<QChartPrivate> d_ptr; |
|
187 | 187 | friend class QLegend; |
|
188 | 188 | friend class DeclarativeChart; |
|
189 | 189 | friend class ChartDataSet; |
|
190 | 190 | friend class ChartPresenter; |
|
191 | 191 | friend class ChartThemeManager; |
|
192 | 192 | friend class QAbstractSeries; |
|
193 | 193 | friend class QBoxPlotSeriesPrivate; |
|
194 | 194 | |
|
195 | 195 | private: |
|
196 | 196 | Q_DISABLE_COPY(QChart) |
|
197 | 197 | }; |
|
198 | 198 | |
|
199 | 199 | QT_CHARTS_END_NAMESPACE |
|
200 | 200 | |
|
201 | 201 | Q_DECLARE_OPERATORS_FOR_FLAGS(QT_CHARTS_NAMESPACE::QChart::AnimationOptions) |
|
202 | 202 | |
|
203 | 203 | #endif // QCHART_H |
@@ -1,86 +1,86 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QCHARTVIEW_H |
|
31 | 31 | #define QCHARTVIEW_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QAbstractAxis> |
|
34 | 34 | #include <QtCharts/QAbstractSeries> |
|
35 | 35 | #include <QtCharts/QChart> |
|
36 | 36 | #include <QtWidgets/QGraphicsView> |
|
37 | 37 | |
|
38 | 38 | QT_BEGIN_NAMESPACE |
|
39 | 39 | class QGraphicsScene; |
|
40 | 40 | class QRubberBand; |
|
41 | 41 | QT_END_NAMESPACE |
|
42 | 42 | |
|
43 | 43 | QT_CHARTS_BEGIN_NAMESPACE |
|
44 | 44 | |
|
45 | 45 | class QChartViewPrivate; |
|
46 | 46 | |
|
47 | 47 | class QT_CHARTS_EXPORT QChartView : public QGraphicsView |
|
48 | 48 | { |
|
49 | 49 | Q_OBJECT |
|
50 | 50 | Q_ENUMS(RubberBand) |
|
51 | 51 | public: |
|
52 | 52 | |
|
53 | 53 | enum RubberBand { |
|
54 | 54 | NoRubberBand = 0x0, |
|
55 | 55 | VerticalRubberBand = 0x1, |
|
56 | 56 | HorizontalRubberBand = 0x2, |
|
57 | 57 | RectangleRubberBand = 0x3 |
|
58 | 58 | }; |
|
59 | 59 | |
|
60 | 60 | Q_DECLARE_FLAGS(RubberBands, RubberBand) |
|
61 | 61 | |
|
62 |
explicit QChartView(QWidget *parent = |
|
|
63 |
explicit QChartView(QChart *chart, QWidget *parent = |
|
|
62 | explicit QChartView(QWidget *parent = Q_NULLPTR); | |
|
63 | explicit QChartView(QChart *chart, QWidget *parent = Q_NULLPTR); | |
|
64 | 64 | ~QChartView(); |
|
65 | 65 | |
|
66 | 66 | void setRubberBand(const RubberBands &rubberBands); |
|
67 | 67 | RubberBands rubberBand() const; |
|
68 | 68 | |
|
69 | 69 | QChart *chart() const; |
|
70 | 70 | void setChart(QChart *chart); |
|
71 | 71 | |
|
72 | 72 | protected: |
|
73 | 73 | void resizeEvent(QResizeEvent *event); |
|
74 | 74 | void mousePressEvent(QMouseEvent *event); |
|
75 | 75 | void mouseMoveEvent(QMouseEvent *event); |
|
76 | 76 | void mouseReleaseEvent(QMouseEvent *event); |
|
77 | 77 | |
|
78 | 78 | QScopedPointer<QChartViewPrivate> d_ptr; |
|
79 | 79 | |
|
80 | 80 | private: |
|
81 | 81 | Q_DISABLE_COPY(QChartView) |
|
82 | 82 | }; |
|
83 | 83 | |
|
84 | 84 | QT_CHARTS_END_NAMESPACE |
|
85 | 85 | |
|
86 | 86 | #endif // QCHARTVIEW_H |
@@ -1,69 +1,69 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QPOLARCHART_H |
|
31 | 31 | #define QPOLARCHART_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChart> |
|
34 | 34 | |
|
35 | 35 | QT_CHARTS_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | class QAbstractSeries; |
|
38 | 38 | class QAbstractAxis; |
|
39 | 39 | |
|
40 | 40 | class QT_CHARTS_EXPORT QPolarChart : public QChart |
|
41 | 41 | { |
|
42 | 42 | Q_OBJECT |
|
43 | 43 | Q_ENUMS(PolarOrientation) |
|
44 | 44 | Q_FLAGS(PolarOrientations) |
|
45 | 45 | |
|
46 | 46 | public: |
|
47 | 47 | enum PolarOrientation { |
|
48 | 48 | PolarOrientationRadial = 0x1, |
|
49 | 49 | PolarOrientationAngular = 0x2 |
|
50 | 50 | }; |
|
51 | 51 | Q_DECLARE_FLAGS(PolarOrientations, PolarOrientation) |
|
52 | 52 | |
|
53 | 53 | public: |
|
54 |
explicit QPolarChart(QGraphicsItem *parent = |
|
|
54 | explicit QPolarChart(QGraphicsItem *parent = Q_NULLPTR, Qt::WindowFlags wFlags = Qt::WindowFlags()); | |
|
55 | 55 | ~QPolarChart(); |
|
56 | 56 | |
|
57 | 57 | void addAxis(QAbstractAxis *axis, PolarOrientation polarOrientation); |
|
58 | 58 | |
|
59 |
QList<QAbstractAxis*> axes(PolarOrientations polarOrientation = PolarOrientations(PolarOrientationRadial | PolarOrientationAngular), QAbstractSeries *series = |
|
|
59 | QList<QAbstractAxis*> axes(PolarOrientations polarOrientation = PolarOrientations(PolarOrientationRadial | PolarOrientationAngular), QAbstractSeries *series = Q_NULLPTR) const; | |
|
60 | 60 | |
|
61 | 61 | static PolarOrientation axisPolarOrientation(QAbstractAxis *axis); |
|
62 | 62 | |
|
63 | 63 | private: |
|
64 | 64 | Q_DISABLE_COPY(QPolarChart) |
|
65 | 65 | }; |
|
66 | 66 | |
|
67 | 67 | QT_CHARTS_END_NAMESPACE |
|
68 | 68 | |
|
69 | 69 | #endif // QCHART_H |
@@ -1,86 +1,86 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QSCATTERSERIES_H |
|
31 | 31 | #define QSCATTERSERIES_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtCharts/qxyseries.h> |
|
35 | 35 | |
|
36 | 36 | QT_CHARTS_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | class QScatterSeriesPrivate; |
|
39 | 39 | |
|
40 | 40 | class QT_CHARTS_EXPORT QScatterSeries : public QXYSeries |
|
41 | 41 | { |
|
42 | 42 | Q_OBJECT |
|
43 | 43 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
44 | 44 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
|
45 | 45 | Q_PROPERTY(MarkerShape markerShape READ markerShape WRITE setMarkerShape NOTIFY markerShapeChanged) |
|
46 | 46 | Q_PROPERTY(qreal markerSize READ markerSize WRITE setMarkerSize NOTIFY markerSizeChanged) |
|
47 | 47 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush) |
|
48 | 48 | Q_ENUMS(MarkerShape) |
|
49 | 49 | |
|
50 | 50 | public: |
|
51 | 51 | enum MarkerShape { |
|
52 | 52 | MarkerShapeCircle, |
|
53 | 53 | MarkerShapeRectangle |
|
54 | 54 | }; |
|
55 | 55 | |
|
56 | 56 | public: |
|
57 |
explicit QScatterSeries(QObject *parent = |
|
|
57 | explicit QScatterSeries(QObject *parent = Q_NULLPTR); | |
|
58 | 58 | ~QScatterSeries(); |
|
59 | 59 | QAbstractSeries::SeriesType type() const; |
|
60 | 60 | void setPen(const QPen &pen); |
|
61 | 61 | void setBrush(const QBrush &brush); |
|
62 | 62 | QBrush brush() const; |
|
63 | 63 | void setColor(const QColor &color); |
|
64 | 64 | QColor color() const; |
|
65 | 65 | void setBorderColor(const QColor &color); |
|
66 | 66 | QColor borderColor() const; |
|
67 | 67 | MarkerShape markerShape() const; |
|
68 | 68 | void setMarkerShape(MarkerShape shape); |
|
69 | 69 | qreal markerSize() const; |
|
70 | 70 | void setMarkerSize(qreal size); |
|
71 | 71 | |
|
72 | 72 | Q_SIGNALS: |
|
73 | 73 | void colorChanged(QColor color); |
|
74 | 74 | void borderColorChanged(QColor color); |
|
75 | 75 | void markerShapeChanged(MarkerShape shape); |
|
76 | 76 | void markerSizeChanged(qreal size); |
|
77 | 77 | |
|
78 | 78 | private: |
|
79 | 79 | Q_DECLARE_PRIVATE(QScatterSeries) |
|
80 | 80 | Q_DISABLE_COPY(QScatterSeries) |
|
81 | 81 | friend class ScatterChartItem; |
|
82 | 82 | }; |
|
83 | 83 | |
|
84 | 84 | QT_CHARTS_END_NAMESPACE |
|
85 | 85 | |
|
86 | 86 | #endif // QSCATTERSERIES_H |
@@ -1,60 +1,60 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QSPLINESERIES_H |
|
31 | 31 | #define QSPLINESERIES_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtCharts/qlineseries.h> |
|
35 | 35 | #include <QtCore/QList> |
|
36 | 36 | #include <QtCore/QPointF> |
|
37 | 37 | #include <QtCore/QtGlobal> |
|
38 | 38 | |
|
39 | 39 | QT_CHARTS_BEGIN_NAMESPACE |
|
40 | 40 | |
|
41 | 41 | class QSplineSeriesPrivate; |
|
42 | 42 | |
|
43 | 43 | class QT_CHARTS_EXPORT QSplineSeries : public QLineSeries |
|
44 | 44 | { |
|
45 | 45 | Q_OBJECT |
|
46 | 46 | |
|
47 | 47 | public: |
|
48 |
explicit QSplineSeries(QObject *parent = |
|
|
48 | explicit QSplineSeries(QObject *parent = Q_NULLPTR); | |
|
49 | 49 | ~QSplineSeries(); |
|
50 | 50 | QAbstractSeries::SeriesType type() const; |
|
51 | 51 | |
|
52 | 52 | private: |
|
53 | 53 | Q_DECLARE_PRIVATE(QSplineSeries) |
|
54 | 54 | Q_DISABLE_COPY(QSplineSeries) |
|
55 | 55 | friend class SplineChartItem; |
|
56 | 56 | }; |
|
57 | 57 | |
|
58 | 58 | QT_CHARTS_END_NAMESPACE |
|
59 | 59 | |
|
60 | 60 | #endif // QSPLINESERIES_H |
@@ -1,79 +1,79 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QHXYMODELMAPPER_H |
|
31 | 31 | #define QHXYMODELMAPPER_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QXYModelMapper> |
|
34 | 34 | |
|
35 | 35 | QT_CHARTS_BEGIN_NAMESPACE |
|
36 | 36 | /* Comment line for syncqt to generate the fwd-include correctly, due to QTBUG-22432 */ |
|
37 | 37 | class QT_CHARTS_EXPORT QHXYModelMapper : public QXYModelMapper |
|
38 | 38 | { |
|
39 | 39 | Q_OBJECT |
|
40 | 40 | Q_PROPERTY(QXYSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) |
|
41 | 41 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced) |
|
42 | 42 | Q_PROPERTY(int xRow READ xRow WRITE setXRow NOTIFY xRowChanged) |
|
43 | 43 | Q_PROPERTY(int yRow READ yRow WRITE setYRow NOTIFY yRowChanged) |
|
44 | 44 | Q_PROPERTY(int firstColumn READ firstColumn WRITE setFirstColumn NOTIFY firstColumnChanged) |
|
45 | 45 | Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount NOTIFY columnCountChanged) |
|
46 | 46 | |
|
47 | 47 | public: |
|
48 |
explicit QHXYModelMapper(QObject *parent = |
|
|
48 | explicit QHXYModelMapper(QObject *parent = Q_NULLPTR); | |
|
49 | 49 | |
|
50 | 50 | QAbstractItemModel *model() const; |
|
51 | 51 | void setModel(QAbstractItemModel *model); |
|
52 | 52 | |
|
53 | 53 | QXYSeries *series() const; |
|
54 | 54 | void setSeries(QXYSeries *series); |
|
55 | 55 | |
|
56 | 56 | int xRow() const; |
|
57 | 57 | void setXRow(int xRow); |
|
58 | 58 | |
|
59 | 59 | int yRow() const; |
|
60 | 60 | void setYRow(int yRow); |
|
61 | 61 | |
|
62 | 62 | int firstColumn() const; |
|
63 | 63 | void setFirstColumn(int firstColumn); |
|
64 | 64 | |
|
65 | 65 | int columnCount() const; |
|
66 | 66 | void setColumnCount(int columnCount); |
|
67 | 67 | |
|
68 | 68 | Q_SIGNALS: |
|
69 | 69 | void seriesReplaced(); |
|
70 | 70 | void modelReplaced(); |
|
71 | 71 | void xRowChanged(); |
|
72 | 72 | void yRowChanged(); |
|
73 | 73 | void firstColumnChanged(); |
|
74 | 74 | void columnCountChanged(); |
|
75 | 75 | }; |
|
76 | 76 | |
|
77 | 77 | QT_CHARTS_END_NAMESPACE |
|
78 | 78 | |
|
79 | 79 | #endif // QHXYMODELMAPPER_H |
@@ -1,79 +1,79 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QVXYMODELMAPPER_H |
|
31 | 31 | #define QVXYMODELMAPPER_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QXYModelMapper> |
|
34 | 34 | |
|
35 | 35 | QT_CHARTS_BEGIN_NAMESPACE |
|
36 | 36 | /* Comment line for syncqt to generate the fwd-include correctly, due to QTBUG-22432 */ |
|
37 | 37 | class QT_CHARTS_EXPORT QVXYModelMapper : public QXYModelMapper |
|
38 | 38 | { |
|
39 | 39 | Q_OBJECT |
|
40 | 40 | Q_PROPERTY(QXYSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) |
|
41 | 41 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced) |
|
42 | 42 | Q_PROPERTY(int xColumn READ xColumn WRITE setXColumn NOTIFY xColumnChanged) |
|
43 | 43 | Q_PROPERTY(int yColumn READ yColumn WRITE setYColumn NOTIFY yColumnChanged) |
|
44 | 44 | Q_PROPERTY(int firstRow READ firstRow WRITE setFirstRow NOTIFY firstRowChanged) |
|
45 | 45 | Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount NOTIFY rowCountChanged) |
|
46 | 46 | |
|
47 | 47 | public: |
|
48 |
explicit QVXYModelMapper(QObject *parent = |
|
|
48 | explicit QVXYModelMapper(QObject *parent = Q_NULLPTR); | |
|
49 | 49 | |
|
50 | 50 | QAbstractItemModel *model() const; |
|
51 | 51 | void setModel(QAbstractItemModel *model); |
|
52 | 52 | |
|
53 | 53 | QXYSeries *series() const; |
|
54 | 54 | void setSeries(QXYSeries *series); |
|
55 | 55 | |
|
56 | 56 | int xColumn() const; |
|
57 | 57 | void setXColumn(int xColumn); |
|
58 | 58 | |
|
59 | 59 | int yColumn() const; |
|
60 | 60 | void setYColumn(int yColumn); |
|
61 | 61 | |
|
62 | 62 | int firstRow() const; |
|
63 | 63 | void setFirstRow(int firstRow); |
|
64 | 64 | |
|
65 | 65 | int rowCount() const; |
|
66 | 66 | void setRowCount(int rowCount); |
|
67 | 67 | |
|
68 | 68 | Q_SIGNALS: |
|
69 | 69 | void seriesReplaced(); |
|
70 | 70 | void modelReplaced(); |
|
71 | 71 | void xColumnChanged(); |
|
72 | 72 | void yColumnChanged(); |
|
73 | 73 | void firstRowChanged(); |
|
74 | 74 | void rowCountChanged(); |
|
75 | 75 | }; |
|
76 | 76 | |
|
77 | 77 | QT_CHARTS_END_NAMESPACE |
|
78 | 78 | |
|
79 | 79 | #endif // QVXYMODELMAPPER_H |
@@ -1,80 +1,80 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QXYMODELMAPPER_H |
|
31 | 31 | #define QXYMODELMAPPER_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtCore/QObject> |
|
35 | 35 | |
|
36 | 36 | QT_BEGIN_NAMESPACE |
|
37 | 37 | class QAbstractItemModel; |
|
38 | 38 | QT_END_NAMESPACE |
|
39 | 39 | |
|
40 | 40 | QT_CHARTS_BEGIN_NAMESPACE |
|
41 | 41 | |
|
42 | 42 | class QXYModelMapperPrivate; |
|
43 | 43 | class QXYSeries; |
|
44 | 44 | |
|
45 | 45 | class QT_CHARTS_EXPORT QXYModelMapper : public QObject |
|
46 | 46 | { |
|
47 | 47 | Q_OBJECT |
|
48 | 48 | |
|
49 | 49 | protected: |
|
50 |
explicit QXYModelMapper(QObject *parent = |
|
|
50 | explicit QXYModelMapper(QObject *parent = Q_NULLPTR); | |
|
51 | 51 | |
|
52 | 52 | QAbstractItemModel *model() const; |
|
53 | 53 | void setModel(QAbstractItemModel *model); |
|
54 | 54 | |
|
55 | 55 | QXYSeries *series() const; |
|
56 | 56 | void setSeries(QXYSeries *series); |
|
57 | 57 | |
|
58 | 58 | int first() const; |
|
59 | 59 | void setFirst(int first); |
|
60 | 60 | |
|
61 | 61 | int count() const; |
|
62 | 62 | void setCount(int count); |
|
63 | 63 | |
|
64 | 64 | Qt::Orientation orientation() const; |
|
65 | 65 | void setOrientation(Qt::Orientation orientation); |
|
66 | 66 | |
|
67 | 67 | int xSection() const; |
|
68 | 68 | void setXSection(int xSection); |
|
69 | 69 | |
|
70 | 70 | int ySection() const; |
|
71 | 71 | void setYSection(int ySection); |
|
72 | 72 | |
|
73 | 73 | protected: |
|
74 | 74 | QXYModelMapperPrivate *const d_ptr; |
|
75 | 75 | Q_DECLARE_PRIVATE(QXYModelMapper) |
|
76 | 76 | }; |
|
77 | 77 | |
|
78 | 78 | QT_CHARTS_END_NAMESPACE |
|
79 | 79 | |
|
80 | 80 | #endif // QXYMODELMAPPER_H |
@@ -1,144 +1,144 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #ifndef QXYSERIES_H |
|
31 | 31 | #define QXYSERIES_H |
|
32 | 32 | |
|
33 | 33 | #include <QtCharts/QChartGlobal> |
|
34 | 34 | #include <QtCharts/QAbstractSeries> |
|
35 | 35 | #include <QtGui/QPen> |
|
36 | 36 | #include <QtGui/QBrush> |
|
37 | 37 | |
|
38 | 38 | QT_BEGIN_NAMESPACE |
|
39 | 39 | class QModelIndex; |
|
40 | 40 | QT_END_NAMESPACE |
|
41 | 41 | |
|
42 | 42 | QT_CHARTS_BEGIN_NAMESPACE |
|
43 | 43 | |
|
44 | 44 | class QXYSeriesPrivate; |
|
45 | 45 | class QXYModelMapper; |
|
46 | 46 | |
|
47 | 47 | class QT_CHARTS_EXPORT QXYSeries : public QAbstractSeries |
|
48 | 48 | { |
|
49 | 49 | Q_OBJECT |
|
50 | 50 | Q_PROPERTY(bool pointsVisible READ pointsVisible WRITE setPointsVisible) |
|
51 | 51 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
52 | 52 | Q_PROPERTY(QString pointLabelsFormat READ pointLabelsFormat WRITE setPointLabelsFormat NOTIFY pointLabelsFormatChanged) |
|
53 | 53 | Q_PROPERTY(bool pointLabelsVisible READ pointLabelsVisible WRITE setPointLabelsVisible NOTIFY pointLabelsVisibilityChanged) |
|
54 | 54 | Q_PROPERTY(QFont pointLabelsFont READ pointLabelsFont WRITE setPointLabelsFont NOTIFY pointLabelsFontChanged) |
|
55 | 55 | Q_PROPERTY(QColor pointLabelsColor READ pointLabelsColor WRITE setPointLabelsColor NOTIFY pointLabelsColorChanged) |
|
56 | 56 | Q_PROPERTY(bool pointLabelsClipping READ pointLabelsClipping WRITE setPointLabelsClipping NOTIFY pointLabelsClippingChanged) |
|
57 | 57 | |
|
58 | 58 | protected: |
|
59 |
explicit QXYSeries(QXYSeriesPrivate &d, QObject *parent = |
|
|
59 | explicit QXYSeries(QXYSeriesPrivate &d, QObject *parent = Q_NULLPTR); | |
|
60 | 60 | |
|
61 | 61 | public: |
|
62 | 62 | ~QXYSeries(); |
|
63 | 63 | void append(qreal x, qreal y); |
|
64 | 64 | void append(const QPointF &point); |
|
65 | 65 | void append(const QList<QPointF> &points); |
|
66 | 66 | void replace(qreal oldX, qreal oldY, qreal newX, qreal newY); |
|
67 | 67 | void replace(const QPointF &oldPoint, const QPointF &newPoint); |
|
68 | 68 | void replace(int index, qreal newX, qreal newY); |
|
69 | 69 | void replace(int index, const QPointF &newPoint); |
|
70 | 70 | void remove(qreal x, qreal y); |
|
71 | 71 | void remove(const QPointF &point); |
|
72 | 72 | void remove(int index); |
|
73 | 73 | void removePoints(int index, int count); |
|
74 | 74 | void insert(int index, const QPointF &point); |
|
75 | 75 | void clear(); |
|
76 | 76 | |
|
77 | 77 | int count() const; |
|
78 | 78 | QList<QPointF> points() const; |
|
79 | 79 | QVector<QPointF> pointsVector() const; |
|
80 | 80 | const QPointF &at(int index) const; |
|
81 | 81 | |
|
82 | 82 | QXYSeries &operator << (const QPointF &point); |
|
83 | 83 | QXYSeries &operator << (const QList<QPointF> &points); |
|
84 | 84 | |
|
85 | 85 | virtual void setPen(const QPen &pen); |
|
86 | 86 | QPen pen() const; |
|
87 | 87 | |
|
88 | 88 | virtual void setBrush(const QBrush &brush); |
|
89 | 89 | QBrush brush() const; |
|
90 | 90 | |
|
91 | 91 | virtual void setColor(const QColor &color); |
|
92 | 92 | virtual QColor color() const; |
|
93 | 93 | |
|
94 | 94 | void setPointsVisible(bool visible = true); |
|
95 | 95 | bool pointsVisible() const; |
|
96 | 96 | |
|
97 | 97 | void setPointLabelsFormat(const QString &format); |
|
98 | 98 | QString pointLabelsFormat() const; |
|
99 | 99 | |
|
100 | 100 | void setPointLabelsVisible(bool visible = true); |
|
101 | 101 | bool pointLabelsVisible() const; |
|
102 | 102 | |
|
103 | 103 | void setPointLabelsFont(const QFont &font); |
|
104 | 104 | QFont pointLabelsFont() const; |
|
105 | 105 | |
|
106 | 106 | void setPointLabelsColor(const QColor &color); |
|
107 | 107 | QColor pointLabelsColor() const; |
|
108 | 108 | |
|
109 | 109 | void setPointLabelsClipping(bool enabled = true); |
|
110 | 110 | bool pointLabelsClipping() const; |
|
111 | 111 | |
|
112 | 112 | void replace(QList<QPointF> points); |
|
113 | 113 | void replace(QVector<QPointF> points); |
|
114 | 114 | |
|
115 | 115 | Q_SIGNALS: |
|
116 | 116 | void clicked(const QPointF &point); |
|
117 | 117 | void hovered(const QPointF &point, bool state); |
|
118 | 118 | void pressed(const QPointF &point); |
|
119 | 119 | void released(const QPointF &point); |
|
120 | 120 | void doubleClicked(const QPointF &point); |
|
121 | 121 | void pointReplaced(int index); |
|
122 | 122 | void pointRemoved(int index); |
|
123 | 123 | void pointAdded(int index); |
|
124 | 124 | void colorChanged(QColor color); |
|
125 | 125 | void pointsReplaced(); |
|
126 | 126 | void pointLabelsFormatChanged(const QString &format); |
|
127 | 127 | void pointLabelsVisibilityChanged(bool visible); |
|
128 | 128 | void pointLabelsFontChanged(const QFont &font); |
|
129 | 129 | void pointLabelsColorChanged(const QColor &color); |
|
130 | 130 | void pointLabelsClippingChanged(bool clipping); |
|
131 | 131 | void pointsRemoved(int index, int count); |
|
132 | 132 | void penChanged(const QPen &pen); |
|
133 | 133 | |
|
134 | 134 | private: |
|
135 | 135 | Q_DECLARE_PRIVATE(QXYSeries) |
|
136 | 136 | Q_DISABLE_COPY(QXYSeries) |
|
137 | 137 | friend class QXYLegendMarkerPrivate; |
|
138 | 138 | friend class XYLegendMarker; |
|
139 | 139 | friend class XYChart; |
|
140 | 140 | }; |
|
141 | 141 | |
|
142 | 142 | QT_CHARTS_END_NAMESPACE |
|
143 | 143 | |
|
144 | 144 | #endif // QXYSERIES_H |
@@ -1,518 +1,518 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include "declarativebarseries.h" |
|
31 | 31 | #include <QtCharts/QBarSet> |
|
32 | 32 | #include <QtCharts/QVBarModelMapper> |
|
33 | 33 | #include <QtCharts/QHBarModelMapper> |
|
34 | 34 | |
|
35 | 35 | QT_CHARTS_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | DeclarativeBarSet::DeclarativeBarSet(QObject *parent) |
|
38 | 38 | : QBarSet("", parent) |
|
39 | 39 | { |
|
40 | 40 | connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int,int))); |
|
41 | 41 | connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int,int))); |
|
42 | 42 | connect(this, SIGNAL(brushChanged()), this, SLOT(handleBrushChanged())); |
|
43 | 43 | } |
|
44 | 44 | |
|
45 | 45 | void DeclarativeBarSet::handleCountChanged(int index, int count) |
|
46 | 46 | { |
|
47 | 47 | Q_UNUSED(index) |
|
48 | 48 | Q_UNUSED(count) |
|
49 | 49 | emit countChanged(QBarSet::count()); |
|
50 | 50 | } |
|
51 | 51 | |
|
52 | 52 | qreal DeclarativeBarSet::borderWidth() const |
|
53 | 53 | { |
|
54 | 54 | return pen().widthF(); |
|
55 | 55 | } |
|
56 | 56 | |
|
57 | 57 | void DeclarativeBarSet::setBorderWidth(qreal width) |
|
58 | 58 | { |
|
59 | 59 | if (width != pen().widthF()) { |
|
60 | 60 | QPen p = pen(); |
|
61 | 61 | p.setWidthF(width); |
|
62 | 62 | setPen(p); |
|
63 | 63 | emit borderWidthChanged(width); |
|
64 | 64 | } |
|
65 | 65 | } |
|
66 | 66 | |
|
67 | 67 | QVariantList DeclarativeBarSet::values() |
|
68 | 68 | { |
|
69 | 69 | QVariantList values; |
|
70 | 70 | for (int i(0); i < count(); i++) |
|
71 | 71 | values.append(QVariant(QBarSet::at(i))); |
|
72 | 72 | return values; |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | void DeclarativeBarSet::setValues(QVariantList values) |
|
76 | 76 | { |
|
77 | 77 | while (count()) |
|
78 | 78 | remove(count() - 1); |
|
79 | 79 | |
|
80 | if (values.at(0).canConvert(QVariant::Point)) { | |
|
80 | if (values.count() > 0 && values.at(0).canConvert(QVariant::Point)) { | |
|
81 | 81 | // Create list of values for appending if the first item is Qt.point |
|
82 | 82 | int maxValue = 0; |
|
83 | 83 | for (int i = 0; i < values.count(); i++) { |
|
84 | 84 | if (values.at(i).canConvert(QVariant::Point) && |
|
85 | 85 | values.at(i).toPoint().x() > maxValue) { |
|
86 | 86 | maxValue = values.at(i).toPoint().x(); |
|
87 | 87 | } |
|
88 | 88 | } |
|
89 | 89 | |
|
90 | 90 | QVector<int> indexValueList; |
|
91 | 91 | indexValueList.resize(maxValue + 1); |
|
92 | 92 | |
|
93 | 93 | for (int i = 0; i < values.count(); i++) { |
|
94 | 94 | if (values.at(i).canConvert(QVariant::Point)) { |
|
95 | 95 | indexValueList.replace(values.at(i).toPoint().x(), values.at(i).toPoint().y()); |
|
96 | 96 | } |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | for (int i = 0; i < indexValueList.count(); i++) |
|
100 | 100 | QBarSet::append(indexValueList.at(i)); |
|
101 | 101 | |
|
102 | 102 | } else { |
|
103 | 103 | for (int i(0); i < values.count(); i++) { |
|
104 | 104 | if (values.at(i).canConvert(QVariant::Double)) |
|
105 | 105 | QBarSet::append(values[i].toDouble()); |
|
106 | 106 | } |
|
107 | 107 | } |
|
108 | 108 | } |
|
109 | 109 | |
|
110 | 110 | QString DeclarativeBarSet::brushFilename() const |
|
111 | 111 | { |
|
112 | 112 | return m_brushFilename; |
|
113 | 113 | } |
|
114 | 114 | |
|
115 | 115 | void DeclarativeBarSet::setBrushFilename(const QString &brushFilename) |
|
116 | 116 | { |
|
117 | 117 | QImage brushImage(brushFilename); |
|
118 | 118 | if (QBarSet::brush().textureImage() != brushImage) { |
|
119 | 119 | QBrush brush = QBarSet::brush(); |
|
120 | 120 | brush.setTextureImage(brushImage); |
|
121 | 121 | QBarSet::setBrush(brush); |
|
122 | 122 | m_brushFilename = brushFilename; |
|
123 | 123 | m_brushImage = brushImage; |
|
124 | 124 | emit brushFilenameChanged(brushFilename); |
|
125 | 125 | } |
|
126 | 126 | } |
|
127 | 127 | |
|
128 | 128 | void DeclarativeBarSet::handleBrushChanged() |
|
129 | 129 | { |
|
130 | 130 | // If the texture image of the brush has changed along the brush |
|
131 | 131 | // the brush file name needs to be cleared. |
|
132 | 132 | if (!m_brushFilename.isEmpty() && QBarSet::brush().textureImage() != m_brushImage) { |
|
133 | 133 | m_brushFilename.clear(); |
|
134 | 134 | emit brushFilenameChanged(QString("")); |
|
135 | 135 | } |
|
136 | 136 | } |
|
137 | 137 | |
|
138 | 138 | // Declarative bar series ====================================================================================== |
|
139 | 139 | DeclarativeBarSeries::DeclarativeBarSeries(QQuickItem *parent) : |
|
140 | 140 | QBarSeries(parent), |
|
141 | 141 | m_axes(new DeclarativeAxes(this)) |
|
142 | 142 | { |
|
143 | 143 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); |
|
144 | 144 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); |
|
145 | 145 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
|
146 | 146 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
|
147 | 147 | } |
|
148 | 148 | |
|
149 | 149 | void DeclarativeBarSeries::classBegin() |
|
150 | 150 | { |
|
151 | 151 | } |
|
152 | 152 | |
|
153 | 153 | void DeclarativeBarSeries::componentComplete() |
|
154 | 154 | { |
|
155 | 155 | foreach (QObject *child, children()) { |
|
156 | 156 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
157 | 157 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
158 | 158 | } else if (qobject_cast<QVBarModelMapper *>(child)) { |
|
159 | 159 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
160 | 160 | mapper->setSeries(this); |
|
161 | 161 | } else if (qobject_cast<QHBarModelMapper *>(child)) { |
|
162 | 162 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
163 | 163 | mapper->setSeries(this); |
|
164 | 164 | } |
|
165 | 165 | } |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | QQmlListProperty<QObject> DeclarativeBarSeries::seriesChildren() |
|
169 | 169 | { |
|
170 | 170 | return QQmlListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren ,0,0,0); |
|
171 | 171 | } |
|
172 | 172 | |
|
173 | 173 | void DeclarativeBarSeries::appendSeriesChildren(QQmlListProperty<QObject> *list, QObject *element) |
|
174 | 174 | { |
|
175 | 175 | // Empty implementation; the children are parsed in componentComplete instead |
|
176 | 176 | Q_UNUSED(list); |
|
177 | 177 | Q_UNUSED(element); |
|
178 | 178 | } |
|
179 | 179 | |
|
180 | 180 | DeclarativeBarSet *DeclarativeBarSeries::at(int index) |
|
181 | 181 | { |
|
182 | 182 | QList<QBarSet *> setList = barSets(); |
|
183 | 183 | if (index >= 0 && index < setList.count()) |
|
184 | 184 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
185 | 185 | |
|
186 | 186 | return 0; |
|
187 | 187 | } |
|
188 | 188 | |
|
189 | 189 | DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values) |
|
190 | 190 | { |
|
191 | 191 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
192 | 192 | barset->setLabel(label); |
|
193 | 193 | barset->setValues(values); |
|
194 | 194 | if (QBarSeries::insert(index, barset)) |
|
195 | 195 | return barset; |
|
196 | 196 | delete barset; |
|
197 | 197 | return 0; |
|
198 | 198 | } |
|
199 | 199 | |
|
200 | 200 | // Declarative stacked bar series ============================================================================== |
|
201 | 201 | DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QQuickItem *parent) : |
|
202 | 202 | QStackedBarSeries(parent), |
|
203 | 203 | m_axes(0) |
|
204 | 204 | { |
|
205 | 205 | m_axes = new DeclarativeAxes(this); |
|
206 | 206 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); |
|
207 | 207 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); |
|
208 | 208 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
|
209 | 209 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
|
210 | 210 | } |
|
211 | 211 | |
|
212 | 212 | void DeclarativeStackedBarSeries::classBegin() |
|
213 | 213 | { |
|
214 | 214 | } |
|
215 | 215 | |
|
216 | 216 | void DeclarativeStackedBarSeries::componentComplete() |
|
217 | 217 | { |
|
218 | 218 | foreach (QObject *child, children()) { |
|
219 | 219 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
220 | 220 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
221 | 221 | } else if (qobject_cast<QVBarModelMapper *>(child)) { |
|
222 | 222 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
223 | 223 | mapper->setSeries(this); |
|
224 | 224 | } else if (qobject_cast<QHBarModelMapper *>(child)) { |
|
225 | 225 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
226 | 226 | mapper->setSeries(this); |
|
227 | 227 | } |
|
228 | 228 | } |
|
229 | 229 | } |
|
230 | 230 | |
|
231 | 231 | |
|
232 | 232 | QQmlListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren() |
|
233 | 233 | { |
|
234 | 234 | return QQmlListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren ,0,0,0); |
|
235 | 235 | } |
|
236 | 236 | |
|
237 | 237 | void DeclarativeStackedBarSeries::appendSeriesChildren(QQmlListProperty<QObject> * list, QObject *element) |
|
238 | 238 | { |
|
239 | 239 | // Empty implementation; the children are parsed in componentComplete instead |
|
240 | 240 | Q_UNUSED(list); |
|
241 | 241 | Q_UNUSED(element); |
|
242 | 242 | } |
|
243 | 243 | |
|
244 | 244 | DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index) |
|
245 | 245 | { |
|
246 | 246 | QList<QBarSet *> setList = barSets(); |
|
247 | 247 | if (index >= 0 && index < setList.count()) |
|
248 | 248 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
249 | 249 | |
|
250 | 250 | return 0; |
|
251 | 251 | } |
|
252 | 252 | |
|
253 | 253 | DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, QVariantList values) |
|
254 | 254 | { |
|
255 | 255 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
256 | 256 | barset->setLabel(label); |
|
257 | 257 | barset->setValues(values); |
|
258 | 258 | if (QStackedBarSeries::insert(index, barset)) |
|
259 | 259 | return barset; |
|
260 | 260 | delete barset; |
|
261 | 261 | return 0; |
|
262 | 262 | } |
|
263 | 263 | |
|
264 | 264 | // Declarative percent bar series ============================================================================== |
|
265 | 265 | DeclarativePercentBarSeries::DeclarativePercentBarSeries(QQuickItem *parent) : |
|
266 | 266 | QPercentBarSeries(parent), |
|
267 | 267 | m_axes(0) |
|
268 | 268 | { |
|
269 | 269 | m_axes = new DeclarativeAxes(this); |
|
270 | 270 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); |
|
271 | 271 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); |
|
272 | 272 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
|
273 | 273 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
|
274 | 274 | } |
|
275 | 275 | |
|
276 | 276 | void DeclarativePercentBarSeries::classBegin() |
|
277 | 277 | { |
|
278 | 278 | } |
|
279 | 279 | |
|
280 | 280 | void DeclarativePercentBarSeries::componentComplete() |
|
281 | 281 | { |
|
282 | 282 | foreach (QObject *child, children()) { |
|
283 | 283 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
284 | 284 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
285 | 285 | } else if (qobject_cast<QVBarModelMapper *>(child)) { |
|
286 | 286 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
287 | 287 | mapper->setSeries(this); |
|
288 | 288 | } else if (qobject_cast<QHBarModelMapper *>(child)) { |
|
289 | 289 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
290 | 290 | mapper->setSeries(this); |
|
291 | 291 | } |
|
292 | 292 | } |
|
293 | 293 | } |
|
294 | 294 | |
|
295 | 295 | QQmlListProperty<QObject> DeclarativePercentBarSeries::seriesChildren() |
|
296 | 296 | { |
|
297 | 297 | return QQmlListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren ,0,0,0); |
|
298 | 298 | } |
|
299 | 299 | |
|
300 | 300 | void DeclarativePercentBarSeries::appendSeriesChildren(QQmlListProperty<QObject> * list, QObject *element) |
|
301 | 301 | { |
|
302 | 302 | // Empty implementation; the children are parsed in componentComplete instead |
|
303 | 303 | Q_UNUSED(list); |
|
304 | 304 | Q_UNUSED(element); |
|
305 | 305 | } |
|
306 | 306 | |
|
307 | 307 | DeclarativeBarSet *DeclarativePercentBarSeries::at(int index) |
|
308 | 308 | { |
|
309 | 309 | QList<QBarSet *> setList = barSets(); |
|
310 | 310 | if (index >= 0 && index < setList.count()) |
|
311 | 311 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
312 | 312 | |
|
313 | 313 | return 0; |
|
314 | 314 | } |
|
315 | 315 | |
|
316 | 316 | DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, QVariantList values) |
|
317 | 317 | { |
|
318 | 318 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
319 | 319 | barset->setLabel(label); |
|
320 | 320 | barset->setValues(values); |
|
321 | 321 | if (QPercentBarSeries::insert(index, barset)) |
|
322 | 322 | return barset; |
|
323 | 323 | delete barset; |
|
324 | 324 | return 0; |
|
325 | 325 | } |
|
326 | 326 | |
|
327 | 327 | // Declarative horizontal bar series =========================================================================== |
|
328 | 328 | DeclarativeHorizontalBarSeries::DeclarativeHorizontalBarSeries(QQuickItem *parent) : |
|
329 | 329 | QHorizontalBarSeries(parent), |
|
330 | 330 | m_axes(0) |
|
331 | 331 | { |
|
332 | 332 | m_axes = new DeclarativeAxes(this); |
|
333 | 333 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); |
|
334 | 334 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); |
|
335 | 335 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
|
336 | 336 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
|
337 | 337 | } |
|
338 | 338 | |
|
339 | 339 | void DeclarativeHorizontalBarSeries::classBegin() |
|
340 | 340 | { |
|
341 | 341 | } |
|
342 | 342 | |
|
343 | 343 | void DeclarativeHorizontalBarSeries::componentComplete() |
|
344 | 344 | { |
|
345 | 345 | foreach (QObject *child, children()) { |
|
346 | 346 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
347 | 347 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
348 | 348 | } else if (qobject_cast<QVBarModelMapper *>(child)) { |
|
349 | 349 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
350 | 350 | mapper->setSeries(this); |
|
351 | 351 | } else if (qobject_cast<QHBarModelMapper *>(child)) { |
|
352 | 352 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
353 | 353 | mapper->setSeries(this); |
|
354 | 354 | } |
|
355 | 355 | } |
|
356 | 356 | } |
|
357 | 357 | |
|
358 | 358 | QQmlListProperty<QObject> DeclarativeHorizontalBarSeries::seriesChildren() |
|
359 | 359 | { |
|
360 | 360 | return QQmlListProperty<QObject>(this, 0, &DeclarativeHorizontalBarSeries::appendSeriesChildren ,0,0,0); |
|
361 | 361 | } |
|
362 | 362 | |
|
363 | 363 | void DeclarativeHorizontalBarSeries::appendSeriesChildren(QQmlListProperty<QObject> * list, QObject *element) |
|
364 | 364 | { |
|
365 | 365 | // Empty implementation; the children are parsed in componentComplete instead |
|
366 | 366 | Q_UNUSED(list); |
|
367 | 367 | Q_UNUSED(element); |
|
368 | 368 | } |
|
369 | 369 | |
|
370 | 370 | DeclarativeBarSet *DeclarativeHorizontalBarSeries::at(int index) |
|
371 | 371 | { |
|
372 | 372 | QList<QBarSet *> setList = barSets(); |
|
373 | 373 | if (index >= 0 && index < setList.count()) |
|
374 | 374 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
375 | 375 | |
|
376 | 376 | return 0; |
|
377 | 377 | } |
|
378 | 378 | |
|
379 | 379 | DeclarativeBarSet *DeclarativeHorizontalBarSeries::insert(int index, QString label, QVariantList values) |
|
380 | 380 | { |
|
381 | 381 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
382 | 382 | barset->setLabel(label); |
|
383 | 383 | barset->setValues(values); |
|
384 | 384 | if (QHorizontalBarSeries::insert(index, barset)) |
|
385 | 385 | return barset; |
|
386 | 386 | delete barset; |
|
387 | 387 | return 0; |
|
388 | 388 | } |
|
389 | 389 | |
|
390 | 390 | // Declarative horizontal stacked bar series =================================================================== |
|
391 | 391 | DeclarativeHorizontalStackedBarSeries::DeclarativeHorizontalStackedBarSeries(QQuickItem *parent) : |
|
392 | 392 | QHorizontalStackedBarSeries(parent), |
|
393 | 393 | m_axes(0) |
|
394 | 394 | { |
|
395 | 395 | m_axes = new DeclarativeAxes(this); |
|
396 | 396 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); |
|
397 | 397 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); |
|
398 | 398 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
|
399 | 399 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
|
400 | 400 | } |
|
401 | 401 | |
|
402 | 402 | void DeclarativeHorizontalStackedBarSeries::classBegin() |
|
403 | 403 | { |
|
404 | 404 | } |
|
405 | 405 | |
|
406 | 406 | void DeclarativeHorizontalStackedBarSeries::componentComplete() |
|
407 | 407 | { |
|
408 | 408 | foreach (QObject *child, children()) { |
|
409 | 409 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
410 | 410 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
411 | 411 | } else if (qobject_cast<QVBarModelMapper *>(child)) { |
|
412 | 412 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
413 | 413 | mapper->setSeries(this); |
|
414 | 414 | } else if (qobject_cast<QHBarModelMapper *>(child)) { |
|
415 | 415 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
416 | 416 | mapper->setSeries(this); |
|
417 | 417 | } |
|
418 | 418 | } |
|
419 | 419 | } |
|
420 | 420 | |
|
421 | 421 | QQmlListProperty<QObject> DeclarativeHorizontalStackedBarSeries::seriesChildren() |
|
422 | 422 | { |
|
423 | 423 | return QQmlListProperty<QObject>(this, 0, &DeclarativeHorizontalStackedBarSeries::appendSeriesChildren ,0,0,0); |
|
424 | 424 | } |
|
425 | 425 | |
|
426 | 426 | void DeclarativeHorizontalStackedBarSeries::appendSeriesChildren(QQmlListProperty<QObject> * list, QObject *element) |
|
427 | 427 | { |
|
428 | 428 | // Empty implementation; the children are parsed in componentComplete instead |
|
429 | 429 | Q_UNUSED(list); |
|
430 | 430 | Q_UNUSED(element); |
|
431 | 431 | } |
|
432 | 432 | |
|
433 | 433 | DeclarativeBarSet *DeclarativeHorizontalStackedBarSeries::at(int index) |
|
434 | 434 | { |
|
435 | 435 | QList<QBarSet *> setList = barSets(); |
|
436 | 436 | if (index >= 0 && index < setList.count()) |
|
437 | 437 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
438 | 438 | |
|
439 | 439 | return 0; |
|
440 | 440 | } |
|
441 | 441 | |
|
442 | 442 | DeclarativeBarSet *DeclarativeHorizontalStackedBarSeries::insert(int index, QString label, QVariantList values) |
|
443 | 443 | { |
|
444 | 444 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
445 | 445 | barset->setLabel(label); |
|
446 | 446 | barset->setValues(values); |
|
447 | 447 | if (QHorizontalStackedBarSeries::insert(index, barset)) |
|
448 | 448 | return barset; |
|
449 | 449 | delete barset; |
|
450 | 450 | return 0; |
|
451 | 451 | } |
|
452 | 452 | |
|
453 | 453 | // Declarative horizontal percent bar series =================================================================== |
|
454 | 454 | DeclarativeHorizontalPercentBarSeries::DeclarativeHorizontalPercentBarSeries(QQuickItem *parent) : |
|
455 | 455 | QHorizontalPercentBarSeries(parent), |
|
456 | 456 | m_axes(0) |
|
457 | 457 | { |
|
458 | 458 | m_axes = new DeclarativeAxes(this); |
|
459 | 459 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); |
|
460 | 460 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); |
|
461 | 461 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
|
462 | 462 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
|
463 | 463 | } |
|
464 | 464 | |
|
465 | 465 | void DeclarativeHorizontalPercentBarSeries::classBegin() |
|
466 | 466 | { |
|
467 | 467 | } |
|
468 | 468 | |
|
469 | 469 | void DeclarativeHorizontalPercentBarSeries::componentComplete() |
|
470 | 470 | { |
|
471 | 471 | foreach (QObject *child, children()) { |
|
472 | 472 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
473 | 473 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
474 | 474 | } else if (qobject_cast<QVBarModelMapper *>(child)) { |
|
475 | 475 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
476 | 476 | mapper->setSeries(this); |
|
477 | 477 | } else if (qobject_cast<QHBarModelMapper *>(child)) { |
|
478 | 478 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
479 | 479 | mapper->setSeries(this); |
|
480 | 480 | } |
|
481 | 481 | } |
|
482 | 482 | } |
|
483 | 483 | |
|
484 | 484 | QQmlListProperty<QObject> DeclarativeHorizontalPercentBarSeries::seriesChildren() |
|
485 | 485 | { |
|
486 | 486 | return QQmlListProperty<QObject>(this, 0, &DeclarativeHorizontalPercentBarSeries::appendSeriesChildren ,0,0,0); |
|
487 | 487 | } |
|
488 | 488 | |
|
489 | 489 | void DeclarativeHorizontalPercentBarSeries::appendSeriesChildren(QQmlListProperty<QObject> * list, QObject *element) |
|
490 | 490 | { |
|
491 | 491 | // Empty implementation; the children are parsed in componentComplete instead |
|
492 | 492 | Q_UNUSED(list); |
|
493 | 493 | Q_UNUSED(element); |
|
494 | 494 | } |
|
495 | 495 | |
|
496 | 496 | DeclarativeBarSet *DeclarativeHorizontalPercentBarSeries::at(int index) |
|
497 | 497 | { |
|
498 | 498 | QList<QBarSet *> setList = barSets(); |
|
499 | 499 | if (index >= 0 && index < setList.count()) |
|
500 | 500 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
501 | 501 | |
|
502 | 502 | return 0; |
|
503 | 503 | } |
|
504 | 504 | |
|
505 | 505 | DeclarativeBarSet *DeclarativeHorizontalPercentBarSeries::insert(int index, QString label, QVariantList values) |
|
506 | 506 | { |
|
507 | 507 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
508 | 508 | barset->setLabel(label); |
|
509 | 509 | barset->setValues(values); |
|
510 | 510 | if (QHorizontalPercentBarSeries::insert(index, barset)) |
|
511 | 511 | return barset; |
|
512 | 512 | delete barset; |
|
513 | 513 | return 0; |
|
514 | 514 | } |
|
515 | 515 | |
|
516 | 516 | #include "moc_declarativebarseries.cpp" |
|
517 | 517 | |
|
518 | 518 | QT_CHARTS_END_NAMESPACE |
@@ -1,1250 +1,1252 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include "declarativechart.h" |
|
31 | 31 | #include <QtGui/QPainter> |
|
32 | 32 | #include "declarativelineseries.h" |
|
33 | 33 | #include "declarativeareaseries.h" |
|
34 | 34 | #include "declarativebarseries.h" |
|
35 | 35 | #include "declarativepieseries.h" |
|
36 | 36 | #include "declarativesplineseries.h" |
|
37 | 37 | #include "declarativeboxplotseries.h" |
|
38 | 38 | #include "declarativescatterseries.h" |
|
39 | 39 | #include "declarativechartnode.h" |
|
40 | 40 | #include "declarativerendernode.h" |
|
41 | 41 | #include <QtCharts/QBarCategoryAxis> |
|
42 | 42 | #include <QtCharts/QValueAxis> |
|
43 | 43 | #include <QtCharts/QLogValueAxis> |
|
44 | 44 | #include <QtCharts/QCategoryAxis> |
|
45 | 45 | #include <private/qabstractseries_p.h> |
|
46 | 46 | #include "declarativemargins.h" |
|
47 | 47 | #include <private/chartdataset_p.h> |
|
48 | 48 | #include "declarativeaxes.h" |
|
49 | 49 | #include <private/qchart_p.h> |
|
50 | 50 | #include <private/chartpresenter_p.h> |
|
51 | 51 | #include <QtCharts/QPolarChart> |
|
52 | 52 | |
|
53 | 53 | #ifndef QT_QREAL_IS_FLOAT |
|
54 | 54 | #include <QtCharts/QDateTimeAxis> |
|
55 | 55 | #endif |
|
56 | 56 | |
|
57 | 57 | #include <QtWidgets/QGraphicsSceneMouseEvent> |
|
58 | 58 | #include <QtWidgets/QGraphicsSceneHoverEvent> |
|
59 | 59 | #include <QtWidgets/QApplication> |
|
60 | 60 | #include <QtCore/QTimer> |
|
61 | 61 | #include <QtCore/QThread> |
|
62 | 62 | |
|
63 | 63 | QT_CHARTS_BEGIN_NAMESPACE |
|
64 | 64 | |
|
65 | 65 | /*! |
|
66 | 66 | \qmltype ChartView |
|
67 | 67 | \instantiates DeclarativeChart |
|
68 | 68 | \inqmlmodule QtCharts |
|
69 | 69 | |
|
70 | 70 | \brief Chart element. |
|
71 | 71 | |
|
72 | 72 | ChartView element is the parent that is responsible for showing different chart series types. |
|
73 | 73 | |
|
74 | 74 | The following QML shows how to create a simple chart with one pie series: |
|
75 | 75 | \snippet qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
76 | 76 | \snippet qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
77 | 77 | \snippet qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
78 | 78 | |
|
79 | 79 | \beginfloatleft |
|
80 | 80 | \image examples_qmlpiechart.png |
|
81 | 81 | \endfloat |
|
82 | 82 | \clearfloat |
|
83 | 83 | */ |
|
84 | 84 | |
|
85 | 85 | /*! |
|
86 | 86 | \qmlproperty Theme ChartView::theme |
|
87 | 87 | Theme defines the visual appearance of the chart, including for example colors, fonts, line |
|
88 | 88 | widths and chart background. |
|
89 | 89 | */ |
|
90 | 90 | |
|
91 | 91 | /*! |
|
92 | 92 | \qmlproperty Animation ChartView::animationOptions |
|
93 | 93 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, |
|
94 | 94 | ChartView.SeriesAnimations or ChartView.AllAnimations. |
|
95 | 95 | */ |
|
96 | 96 | |
|
97 | 97 | /*! |
|
98 | 98 | \qmlproperty int ChartView::animationDuration |
|
99 | 99 | The duration of the animation for the chart. |
|
100 | 100 | */ |
|
101 | 101 | |
|
102 | 102 | /*! |
|
103 | 103 | \qmlproperty easing ChartView::animationEasingCurve |
|
104 | 104 | The easing curve of the animation for the chart. |
|
105 | 105 | */ |
|
106 | 106 | |
|
107 | 107 | /*! |
|
108 | 108 | \qmlproperty Font ChartView::titleFont |
|
109 | 109 | The title font of the chart. |
|
110 | 110 | |
|
111 | 111 | See the Qt documentation for more details of Font. |
|
112 | 112 | */ |
|
113 | 113 | |
|
114 | 114 | /*! |
|
115 | 115 | \qmlproperty string ChartView::title |
|
116 | 116 | The title of the chart, shown on top of the chart. |
|
117 | 117 | \sa ChartView::titleColor |
|
118 | 118 | */ |
|
119 | 119 | |
|
120 | 120 | /*! |
|
121 | 121 | \qmlproperty color ChartView::titleColor |
|
122 | 122 | The color of the title text. |
|
123 | 123 | */ |
|
124 | 124 | |
|
125 | 125 | /*! |
|
126 | 126 | \qmlproperty Legend ChartView::legend |
|
127 | 127 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. |
|
128 | 128 | */ |
|
129 | 129 | |
|
130 | 130 | /*! |
|
131 | 131 | \qmlproperty int ChartView::count |
|
132 | 132 | The count of series added to the chart. |
|
133 | 133 | */ |
|
134 | 134 | |
|
135 | 135 | /*! |
|
136 | 136 | \qmlproperty color ChartView::backgroundColor |
|
137 | 137 | The color of the chart's background. By default background color is defined by chart theme. |
|
138 | 138 | \sa ChartView::theme |
|
139 | 139 | */ |
|
140 | 140 | |
|
141 | 141 | /*! |
|
142 | 142 | \qmlproperty real ChartView::backgroundRoundness |
|
143 | 143 | The diameter of the rounding circle at the corners of the chart background. |
|
144 | 144 | */ |
|
145 | 145 | |
|
146 | 146 | /*! |
|
147 | 147 | \qmlproperty color ChartView::plotAreaColor |
|
148 | 148 | The color of the background of the chart's plot area. By default plot area background uses chart's |
|
149 | 149 | background color. |
|
150 | 150 | \sa ChartView::backgroundColor |
|
151 | 151 | */ |
|
152 | 152 | |
|
153 | 153 | /*! |
|
154 | 154 | \qmlproperty list<AbstractAxis> ChartView::axes |
|
155 | 155 | The axes of the ChartView. |
|
156 | 156 | */ |
|
157 | 157 | |
|
158 | 158 | /*! |
|
159 | 159 | \qmlproperty bool ChartView::dropShadowEnabled |
|
160 | 160 | The chart's border drop shadow. Set to true to enable drop shadow. |
|
161 | 161 | */ |
|
162 | 162 | |
|
163 | 163 | /*! |
|
164 | 164 | \qmlproperty rect ChartView::plotArea |
|
165 | 165 | The area on the ChartView that is used for drawing series. This is the ChartView rect without the |
|
166 | 166 | margins. |
|
167 | 167 | \sa ChartView::margins |
|
168 | 168 | */ |
|
169 | 169 | |
|
170 | 170 | /*! |
|
171 | 171 | \qmlproperty Margins ChartView::margins |
|
172 | 172 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins |
|
173 | 173 | area of ChartView is used for drawing title, axes and legend. |
|
174 | 174 | */ |
|
175 | 175 | |
|
176 | 176 | /*! |
|
177 | 177 | \qmlproperty bool ChartView::localizeNumbers |
|
178 | 178 | \since QtCharts 2.0 |
|
179 | 179 | When \c{true}, all generated numbers appearing in various series and axis labels will be |
|
180 | 180 | localized using the default QLocale of the application, which defaults to the system locale. |
|
181 | 181 | When \c{false}, the "C" locale is always used. |
|
182 | 182 | Defaults to \c{false}. |
|
183 | 183 | |
|
184 | 184 | \sa locale |
|
185 | 185 | */ |
|
186 | 186 | |
|
187 | 187 | /*! |
|
188 | 188 | \qmlproperty locale ChartView::locale |
|
189 | 189 | \since QtCharts 2.0 |
|
190 | 190 | Sets the locale used to format various chart labels when localizeNumbers is \c{true}. |
|
191 | 191 | This also determines the locale used to format DateTimeAxis labels regardless of |
|
192 | 192 | localizeNumbers property. |
|
193 | 193 | Defaults to application default locale at the time the chart is constructed. |
|
194 | 194 | |
|
195 | 195 | \sa localizeNumbers |
|
196 | 196 | */ |
|
197 | 197 | |
|
198 | 198 | /*! |
|
199 | 199 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
200 | 200 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
201 | 201 | the count property of the chart. |
|
202 | 202 | */ |
|
203 | 203 | |
|
204 | 204 | /*! |
|
205 | 205 | \qmlmethod AbstractSeries ChartView::series(string name) |
|
206 | 206 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. |
|
207 | 207 | */ |
|
208 | 208 | |
|
209 | 209 | /*! |
|
210 | 210 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY) |
|
211 | 211 | Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and |
|
212 | 212 | optional axis \a axisY. For example: |
|
213 | 213 | \code |
|
214 | 214 | // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes |
|
215 | 215 | var myAxisX = chartView.axisX(lineSeries); |
|
216 | 216 | var myAxisY = chartView.axisY(lineSeries); |
|
217 | 217 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY); |
|
218 | 218 | \endcode |
|
219 | 219 | */ |
|
220 | 220 | |
|
221 | 221 | /*! |
|
222 | 222 | \qmlmethod ChartView::removeSeries(AbstractSeries series) |
|
223 | 223 | Removes the \a series from the chart. The series object is also destroyed. |
|
224 | 224 | */ |
|
225 | 225 | |
|
226 | 226 | /*! |
|
227 | 227 | \qmlmethod ChartView::removeAllSeries() |
|
228 | 228 | Removes all series from the chart. All the series objects are also destroyed. |
|
229 | 229 | */ |
|
230 | 230 | |
|
231 | 231 | /*! |
|
232 | 232 | \qmlmethod Axis ChartView::axisX(AbstractSeries series) |
|
233 | 233 | The x-axis of the series. |
|
234 | 234 | */ |
|
235 | 235 | |
|
236 | 236 | /*! |
|
237 | 237 | \qmlmethod ChartView::setAxisX(AbstractAxis axis, AbstractSeries series) |
|
238 | 238 | Set the x-axis of the series. |
|
239 | 239 | */ |
|
240 | 240 | |
|
241 | 241 | /*! |
|
242 | 242 | \qmlmethod Axis ChartView::axisY(AbstractSeries series) |
|
243 | 243 | The y-axis of the series. |
|
244 | 244 | */ |
|
245 | 245 | |
|
246 | 246 | /*! |
|
247 | 247 | \qmlmethod ChartView::setAxisY(AbstractAxis axis, AbstractSeries series) |
|
248 | 248 | Set the y-axis of the series. |
|
249 | 249 | */ |
|
250 | 250 | |
|
251 | 251 | /*! |
|
252 | 252 | \qmlmethod ChartView::zoom(real factor) |
|
253 | 253 | Zooms in by \a factor on the center of the chart. |
|
254 | 254 | |
|
255 | 255 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
256 | 256 | */ |
|
257 | 257 | |
|
258 | 258 | /*! |
|
259 | 259 | \qmlmethod ChartView::zoomIn() |
|
260 | 260 | Zooms in the view by a factor of two. |
|
261 | 261 | */ |
|
262 | 262 | |
|
263 | 263 | /*! |
|
264 | 264 | \qmlmethod ChartView::zoomIn(rect rectangle) |
|
265 | 265 | Zooms in the view to a maximum level at which \a rectangle is still fully visible. |
|
266 | 266 | \note This is not supported for polar charts. |
|
267 | 267 | */ |
|
268 | 268 | |
|
269 | 269 | /*! |
|
270 | 270 | \qmlmethod ChartView::zoomOut() |
|
271 | 271 | Zooms out the view by a factor of two. |
|
272 | 272 | */ |
|
273 | 273 | |
|
274 | 274 | /*! |
|
275 | 275 | \qmlmethod ChartView::zoomReset() |
|
276 | 276 | Resets the series domains to what they were before any zoom method was called. |
|
277 | 277 | Note that this will also reset any scrolls and explicit axis range settings done between |
|
278 | 278 | the first zoom operation and calling this method. If no zoom operation has been |
|
279 | 279 | done, this method does nothing. |
|
280 | 280 | */ |
|
281 | 281 | |
|
282 | 282 | /*! |
|
283 | 283 | \qmlmethod ChartView::isZoomed() |
|
284 | 284 | Returns true if any series has a zoomed domain. |
|
285 | 285 | */ |
|
286 | 286 | |
|
287 | 287 | /*! |
|
288 | 288 | \qmlmethod ChartView::scrollLeft(real pixels) |
|
289 | 289 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. |
|
290 | 290 | */ |
|
291 | 291 | |
|
292 | 292 | /*! |
|
293 | 293 | \qmlmethod ChartView::scrollRight(real pixels) |
|
294 | 294 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. |
|
295 | 295 | */ |
|
296 | 296 | |
|
297 | 297 | /*! |
|
298 | 298 | \qmlmethod ChartView::scrollUp(real pixels) |
|
299 | 299 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. |
|
300 | 300 | */ |
|
301 | 301 | |
|
302 | 302 | /*! |
|
303 | 303 | \qmlmethod ChartView::scrollDown(real pixels) |
|
304 | 304 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. |
|
305 | 305 | */ |
|
306 | 306 | |
|
307 | 307 | /*! |
|
308 | 308 | \qmlmethod point ChartView::mapToValue(point position, AbstractSeries series) |
|
309 | 309 | Returns the value in the \a series domain that corresponds to the \a position relative to the |
|
310 | 310 | chart. |
|
311 | 311 | */ |
|
312 | 312 | |
|
313 | 313 | /*! |
|
314 | 314 | \qmlmethod point ChartView::mapToPosition(point value, AbstractSeries series) |
|
315 | 315 | Returns the position on the chart that corresponds to the \a value in the \a series domain. |
|
316 | 316 | */ |
|
317 | 317 | |
|
318 | 318 | /*! |
|
319 | 319 | \qmlsignal ChartView::seriesAdded(AbstractSeries series) |
|
320 | 320 | The \a series has been added to the chart. |
|
321 | 321 | */ |
|
322 | 322 | |
|
323 | 323 | /*! |
|
324 | 324 | \qmlsignal ChartView::seriesRemoved(AbstractSeries series) |
|
325 | 325 | The \a series has been removed from the chart. Please note that \a series is no longer a valid |
|
326 | 326 | object after the signal handler has completed. |
|
327 | 327 | */ |
|
328 | 328 | |
|
329 | 329 | DeclarativeChart::DeclarativeChart(QQuickItem *parent) |
|
330 | 330 | : QQuickItem(parent) |
|
331 | 331 | { |
|
332 | 332 | initChart(QChart::ChartTypeCartesian); |
|
333 | 333 | } |
|
334 | 334 | |
|
335 | 335 | DeclarativeChart::DeclarativeChart(QChart::ChartType type, QQuickItem *parent) |
|
336 | 336 | : QQuickItem(parent) |
|
337 | 337 | { |
|
338 | 338 | initChart(type); |
|
339 | 339 | } |
|
340 | 340 | |
|
341 | 341 | void DeclarativeChart::initChart(QChart::ChartType type) |
|
342 | 342 | { |
|
343 | 343 | m_sceneImage = 0; |
|
344 | 344 | m_sceneImageDirty = false; |
|
345 | 345 | m_sceneImageNeedsClear = false; |
|
346 | 346 | m_guiThreadId = QThread::currentThreadId(); |
|
347 | 347 | m_paintThreadId = 0; |
|
348 | 348 | m_updatePending = false; |
|
349 | 349 | |
|
350 | 350 | setFlag(ItemHasContents, true); |
|
351 | 351 | |
|
352 | 352 | if (type == QChart::ChartTypePolar) |
|
353 | 353 | m_chart = new QPolarChart(); |
|
354 | 354 | else |
|
355 | 355 | m_chart = new QChart(); |
|
356 | 356 | |
|
357 | 357 | m_chart->d_ptr->m_presenter->glSetUseWidget(false); |
|
358 | 358 | m_glXYDataManager = m_chart->d_ptr->m_dataset->glXYSeriesDataManager(); |
|
359 | 359 | |
|
360 | 360 | m_scene = new QGraphicsScene(this); |
|
361 | 361 | m_scene->addItem(m_chart); |
|
362 | 362 | |
|
363 | 363 | setAntialiasing(QQuickItem::antialiasing()); |
|
364 | 364 | connect(m_scene, &QGraphicsScene::changed, this, &DeclarativeChart::sceneChanged); |
|
365 | 365 | connect(this, &DeclarativeChart::needRender, this, &DeclarativeChart::renderScene, |
|
366 | 366 | Qt::QueuedConnection); |
|
367 | 367 | connect(this, SIGNAL(antialiasingChanged(bool)), this, SLOT(handleAntialiasingChanged(bool))); |
|
368 | 368 | |
|
369 | 369 | setAcceptedMouseButtons(Qt::AllButtons); |
|
370 | 370 | setAcceptHoverEvents(true); |
|
371 | 371 | |
|
372 | 372 | m_margins = new DeclarativeMargins(this); |
|
373 | 373 | m_margins->setTop(m_chart->margins().top()); |
|
374 | 374 | m_margins->setLeft(m_chart->margins().left()); |
|
375 | 375 | m_margins->setRight(m_chart->margins().right()); |
|
376 | 376 | m_margins->setBottom(m_chart->margins().bottom()); |
|
377 | 377 | connect(m_margins, SIGNAL(topChanged(int,int,int,int)), |
|
378 | 378 | this, SLOT(changeMargins(int,int,int,int))); |
|
379 | 379 | connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), |
|
380 | 380 | this, SLOT(changeMargins(int,int,int,int))); |
|
381 | 381 | connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), |
|
382 | 382 | this, SLOT(changeMargins(int,int,int,int))); |
|
383 | 383 | connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), |
|
384 | 384 | this, SLOT(changeMargins(int,int,int,int))); |
|
385 | 385 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
386 | 386 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
387 | 387 | connect(m_chart, &QChart::plotAreaChanged, this, &DeclarativeChart::plotAreaChanged); |
|
388 | 388 | } |
|
389 | 389 | |
|
390 | 390 | void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series) |
|
391 | 391 | { |
|
392 | 392 | emit seriesAdded(series); |
|
393 | 393 | } |
|
394 | 394 | |
|
395 | 395 | void DeclarativeChart::changeMargins(int top, int bottom, int left, int right) |
|
396 | 396 | { |
|
397 | 397 | m_chart->setMargins(QMargins(left, top, right, bottom)); |
|
398 | 398 | emit marginsChanged(); |
|
399 | 399 | } |
|
400 | 400 | |
|
401 | 401 | DeclarativeChart::~DeclarativeChart() |
|
402 | 402 | { |
|
403 | 403 | delete m_chart; |
|
404 | 404 | delete m_sceneImage; |
|
405 | 405 | } |
|
406 | 406 | |
|
407 | 407 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
408 | 408 | { |
|
409 | 409 | if (event->type() == QEvent::ChildAdded) { |
|
410 | 410 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
411 | 411 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
412 | 412 | } |
|
413 | 413 | } |
|
414 | 414 | } |
|
415 | 415 | |
|
416 | 416 | void DeclarativeChart::componentComplete() |
|
417 | 417 | { |
|
418 | 418 | foreach (QObject *child, children()) { |
|
419 | 419 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
420 | 420 | // Add series to the chart |
|
421 | 421 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child); |
|
422 | 422 | m_chart->addSeries(series); |
|
423 | 423 | |
|
424 | 424 | // Connect to axis changed signals (unless this is a pie series) |
|
425 | 425 | if (!qobject_cast<DeclarativePieSeries *>(series)) { |
|
426 | 426 | connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
427 | 427 | connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXTopSet(QAbstractAxis*))); |
|
428 | 428 | connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
429 | 429 | connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); |
|
430 | 430 | } |
|
431 | 431 | |
|
432 | 432 | initializeAxes(series); |
|
433 | 433 | } |
|
434 | 434 | } |
|
435 | 435 | |
|
436 | 436 | QQuickItem::componentComplete(); |
|
437 | 437 | } |
|
438 | 438 | |
|
439 | 439 | void DeclarativeChart::seriesAxisAttachHelper(QAbstractSeries *series, QAbstractAxis *axis, |
|
440 | 440 | Qt::Orientations orientation, |
|
441 | 441 | Qt::Alignment alignment) |
|
442 | 442 | { |
|
443 | 443 | if (!series->attachedAxes().contains(axis)) { |
|
444 | 444 | // Remove & delete old axes that are not attached to any other series |
|
445 | 445 | foreach (QAbstractAxis* oldAxis, m_chart->axes(orientation, series)) { |
|
446 | 446 | bool otherAttachments = false; |
|
447 | 447 | if (oldAxis != axis) { |
|
448 | 448 | foreach (QAbstractSeries *oldSeries, m_chart->series()) { |
|
449 | 449 | if (oldSeries != series && oldSeries->attachedAxes().contains(oldAxis)) { |
|
450 | 450 | otherAttachments = true; |
|
451 | 451 | break; |
|
452 | 452 | } |
|
453 | 453 | } |
|
454 | 454 | if (!otherAttachments) { |
|
455 | 455 | m_chart->removeAxis(oldAxis); |
|
456 | 456 | delete oldAxis; |
|
457 | 457 | } |
|
458 | 458 | } |
|
459 | 459 | } |
|
460 | 460 | if (!m_chart->axes(orientation).contains(axis)) |
|
461 | 461 | m_chart->addAxis(axis, alignment); |
|
462 | 462 | |
|
463 | 463 | series->attachAxis(axis); |
|
464 | 464 | } |
|
465 | 465 | } |
|
466 | 466 | |
|
467 | 467 | void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis) |
|
468 | 468 | { |
|
469 | 469 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
470 | 470 | if (axis && s) { |
|
471 | 471 | seriesAxisAttachHelper(s, axis, Qt::Horizontal, Qt::AlignBottom); |
|
472 | 472 | } else { |
|
473 | 473 | qWarning() << "Trying to set axisX to null."; |
|
474 | 474 | } |
|
475 | 475 | } |
|
476 | 476 | |
|
477 | 477 | void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis) |
|
478 | 478 | { |
|
479 | 479 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
480 | 480 | if (axis && s) { |
|
481 | 481 | seriesAxisAttachHelper(s, axis, Qt::Horizontal, Qt::AlignTop); |
|
482 | 482 | } else { |
|
483 | 483 | qWarning() << "Trying to set axisXTop to null."; |
|
484 | 484 | } |
|
485 | 485 | } |
|
486 | 486 | |
|
487 | 487 | void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis) |
|
488 | 488 | { |
|
489 | 489 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
490 | 490 | if (axis && s) { |
|
491 | 491 | seriesAxisAttachHelper(s, axis, Qt::Vertical, Qt::AlignLeft); |
|
492 | 492 | } else { |
|
493 | 493 | qWarning() << "Trying to set axisY to null."; |
|
494 | 494 | } |
|
495 | 495 | } |
|
496 | 496 | |
|
497 | 497 | void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis) |
|
498 | 498 | { |
|
499 | 499 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
500 | 500 | if (axis && s) { |
|
501 | 501 | seriesAxisAttachHelper(s, axis, Qt::Vertical, Qt::AlignRight); |
|
502 | 502 | } else { |
|
503 | 503 | qWarning() << "Trying to set axisYRight to null."; |
|
504 | 504 | } |
|
505 | 505 | } |
|
506 | 506 | |
|
507 | 507 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
508 | 508 | { |
|
509 | 509 | if (newGeometry.isValid()) { |
|
510 | 510 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
511 | 511 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
512 | 512 | } |
|
513 | 513 | } |
|
514 | 514 | QQuickItem::geometryChanged(newGeometry, oldGeometry); |
|
515 | 515 | } |
|
516 | 516 | |
|
517 | 517 | QSGNode *DeclarativeChart::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) |
|
518 | 518 | { |
|
519 | 519 | DeclarativeChartNode *node = static_cast<DeclarativeChartNode *>(oldNode); |
|
520 | 520 | |
|
521 | 521 | if (!node) { |
|
522 | 522 | node = new DeclarativeChartNode(window()); |
|
523 | if (node->glRenderNode()) { | |
|
523 | 524 | connect(window(), &QQuickWindow::beforeRendering, |
|
524 | 525 | node->glRenderNode(), &DeclarativeRenderNode::render); |
|
525 | 526 | } |
|
527 | } | |
|
526 | 528 | |
|
527 | 529 | const QRectF &bRect = boundingRect(); |
|
528 | 530 | |
|
529 | 531 | // Update GL data |
|
530 | if (m_glXYDataManager->dataMap().size() || m_glXYDataManager->mapDirty()) { | |
|
532 | if (node->glRenderNode() && (m_glXYDataManager->dataMap().size() || m_glXYDataManager->mapDirty())) { | |
|
531 | 533 | const QRectF &plotArea = m_chart->plotArea(); |
|
532 | 534 | const QSizeF &chartAreaSize = m_chart->size(); |
|
533 | 535 | |
|
534 | 536 | // We can't use chart's plot area directly, as graphicscene has some internal minimum size |
|
535 | 537 | const qreal normalizedX = plotArea.x() / chartAreaSize.width(); |
|
536 | 538 | const qreal normalizedY = plotArea.y() / chartAreaSize.height(); |
|
537 | 539 | const qreal normalizedWidth = plotArea.width() / chartAreaSize.width(); |
|
538 | 540 | const qreal normalizedHeight = plotArea.height() / chartAreaSize.height(); |
|
539 | 541 | |
|
540 | 542 | QRectF adjustedPlotArea(normalizedX * bRect.width(), |
|
541 | 543 | normalizedY * bRect.height(), |
|
542 | 544 | normalizedWidth * bRect.width(), |
|
543 | 545 | normalizedHeight * bRect.height()); |
|
544 | 546 | |
|
545 | 547 | const QSize &adjustedPlotSize = adjustedPlotArea.size().toSize(); |
|
546 | 548 | if (adjustedPlotSize != node->glRenderNode()->textureSize()) |
|
547 | 549 | node->glRenderNode()->setTextureSize(adjustedPlotSize); |
|
548 | 550 | |
|
549 | 551 | node->glRenderNode()->setRect(adjustedPlotArea); |
|
550 | 552 | node->glRenderNode()->setSeriesData(m_glXYDataManager->mapDirty(), |
|
551 | 553 | m_glXYDataManager->dataMap()); |
|
552 | 554 | |
|
553 | 555 | // Clear dirty flags from original xy data |
|
554 | 556 | m_glXYDataManager->clearAllDirty(); |
|
555 | 557 | } |
|
556 | 558 | |
|
557 | 559 | // Copy chart (if dirty) to chart node |
|
558 | 560 | if (m_sceneImageDirty) { |
|
559 | 561 | node->createTextureFromImage(*m_sceneImage); |
|
560 | 562 | m_sceneImageDirty = false; |
|
561 | 563 | } |
|
562 | 564 | |
|
563 | 565 | node->setRect(bRect); |
|
564 | 566 | |
|
565 | 567 | return node; |
|
566 | 568 | } |
|
567 | 569 | |
|
568 | 570 | void DeclarativeChart::sceneChanged(QList<QRectF> region) |
|
569 | 571 | { |
|
570 | 572 | const int count = region.size(); |
|
571 | 573 | const qreal limitSize = 0.01; |
|
572 | 574 | if (count && !m_updatePending) { |
|
573 | 575 | qreal totalSize = 0.0; |
|
574 | 576 | for (int i = 0; i < count; i++) { |
|
575 | 577 | const QRectF ® = region.at(i); |
|
576 | 578 | totalSize += (reg.height() * reg.width()); |
|
577 | 579 | if (totalSize >= limitSize) |
|
578 | 580 | break; |
|
579 | 581 | } |
|
580 | 582 | // Ignore region updates that change less than small fraction of a pixel, as there is |
|
581 | 583 | // little point regenerating the image in these cases. These are typically cases |
|
582 | 584 | // where OpenGL series are drawn to otherwise static chart. |
|
583 | 585 | if (totalSize >= limitSize) { |
|
584 | 586 | m_updatePending = true; |
|
585 | 587 | // Do async render to avoid some unnecessary renders. |
|
586 | 588 | emit needRender(); |
|
587 | 589 | } else { |
|
588 | 590 | // We do want to call update to trigger possible gl series updates. |
|
589 | 591 | update(); |
|
590 | 592 | } |
|
591 | 593 | } |
|
592 | 594 | } |
|
593 | 595 | |
|
594 | 596 | void DeclarativeChart::renderScene() |
|
595 | 597 | { |
|
596 | 598 | m_updatePending = false; |
|
597 | 599 | m_sceneImageDirty = true; |
|
598 | 600 | QSize chartSize = m_chart->size().toSize(); |
|
599 | 601 | if (!m_sceneImage || chartSize != m_sceneImage->size()) { |
|
600 | 602 | delete m_sceneImage; |
|
601 | 603 | qreal dpr = window() ? window()->devicePixelRatio() : 1.0; |
|
602 | 604 | m_sceneImage = new QImage(chartSize * dpr, QImage::Format_ARGB32); |
|
603 | 605 | m_sceneImage->setDevicePixelRatio(dpr); |
|
604 | 606 | m_sceneImageNeedsClear = true; |
|
605 | 607 | } |
|
606 | 608 | |
|
607 | 609 | if (m_sceneImageNeedsClear) { |
|
608 | 610 | m_sceneImage->fill(Qt::transparent); |
|
609 | 611 | // Don't clear the flag if chart background has any transparent element to it |
|
610 | 612 | if (m_chart->backgroundBrush().color().alpha() == 0xff && !m_chart->isDropShadowEnabled()) |
|
611 | 613 | m_sceneImageNeedsClear = false; |
|
612 | 614 | } |
|
613 | 615 | QPainter painter(m_sceneImage); |
|
614 | 616 | if (antialiasing()) { |
|
615 | 617 | painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing |
|
616 | 618 | | QPainter::SmoothPixmapTransform); |
|
617 | 619 | } |
|
618 | 620 | QRect renderRect(QPoint(0, 0), chartSize); |
|
619 | 621 | m_scene->render(&painter, renderRect, renderRect); |
|
620 | 622 | update(); |
|
621 | 623 | } |
|
622 | 624 | |
|
623 | 625 | void DeclarativeChart::mousePressEvent(QMouseEvent *event) |
|
624 | 626 | { |
|
625 | 627 | m_mousePressScenePoint = event->pos(); |
|
626 | 628 | m_mousePressScreenPoint = event->globalPos(); |
|
627 | 629 | m_lastMouseMoveScenePoint = m_mousePressScenePoint; |
|
628 | 630 | m_lastMouseMoveScreenPoint = m_mousePressScreenPoint; |
|
629 | 631 | m_mousePressButton = event->button(); |
|
630 | 632 | m_mousePressButtons = event->buttons(); |
|
631 | 633 | |
|
632 | 634 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMousePress); |
|
633 | 635 | mouseEvent.setWidget(0); |
|
634 | 636 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
635 | 637 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
636 | 638 | mouseEvent.setScenePos(m_mousePressScenePoint); |
|
637 | 639 | mouseEvent.setScreenPos(m_mousePressScreenPoint); |
|
638 | 640 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
639 | 641 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
640 | 642 | mouseEvent.setButtons(m_mousePressButtons); |
|
641 | 643 | mouseEvent.setButton(m_mousePressButton); |
|
642 | 644 | mouseEvent.setModifiers(event->modifiers()); |
|
643 | 645 | mouseEvent.setAccepted(false); |
|
644 | 646 | |
|
645 | 647 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
646 | 648 | } |
|
647 | 649 | |
|
648 | 650 | void DeclarativeChart::mouseReleaseEvent(QMouseEvent *event) |
|
649 | 651 | { |
|
650 | 652 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseRelease); |
|
651 | 653 | mouseEvent.setWidget(0); |
|
652 | 654 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
653 | 655 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
654 | 656 | mouseEvent.setScenePos(event->pos()); |
|
655 | 657 | mouseEvent.setScreenPos(event->globalPos()); |
|
656 | 658 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
657 | 659 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
658 | 660 | mouseEvent.setButtons(event->buttons()); |
|
659 | 661 | mouseEvent.setButton(event->button()); |
|
660 | 662 | mouseEvent.setModifiers(event->modifiers()); |
|
661 | 663 | mouseEvent.setAccepted(false); |
|
662 | 664 | |
|
663 | 665 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
664 | 666 | |
|
665 | 667 | m_mousePressButtons = event->buttons(); |
|
666 | 668 | m_mousePressButton = Qt::NoButton; |
|
667 | 669 | } |
|
668 | 670 | |
|
669 | 671 | void DeclarativeChart::hoverMoveEvent(QHoverEvent *event) |
|
670 | 672 | { |
|
671 | 673 | // Convert hover move to mouse move, since we don't seem to get actual mouse move events. |
|
672 | 674 | // QGraphicsScene generates hover events from mouse move events, so we don't need |
|
673 | 675 | // to pass hover events there. |
|
674 | 676 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); |
|
675 | 677 | mouseEvent.setWidget(0); |
|
676 | 678 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
677 | 679 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
678 | 680 | mouseEvent.setScenePos(event->pos()); |
|
679 | 681 | // Hover events do not have global pos in them, and the screen position doesn't seem to |
|
680 | 682 | // matter anyway in this use case, so just pass event pos instead of trying to |
|
681 | 683 | // calculate the real screen position. |
|
682 | 684 | mouseEvent.setScreenPos(event->pos()); |
|
683 | 685 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
684 | 686 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
685 | 687 | mouseEvent.setButtons(m_mousePressButtons); |
|
686 | 688 | mouseEvent.setButton(m_mousePressButton); |
|
687 | 689 | mouseEvent.setModifiers(event->modifiers()); |
|
688 | 690 | m_lastMouseMoveScenePoint = mouseEvent.scenePos(); |
|
689 | 691 | m_lastMouseMoveScreenPoint = mouseEvent.screenPos(); |
|
690 | 692 | mouseEvent.setAccepted(false); |
|
691 | 693 | |
|
692 | 694 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
693 | 695 | } |
|
694 | 696 | |
|
695 | 697 | void DeclarativeChart::mouseDoubleClickEvent(QMouseEvent *event) |
|
696 | 698 | { |
|
697 | 699 | m_mousePressScenePoint = event->pos(); |
|
698 | 700 | m_mousePressScreenPoint = event->globalPos(); |
|
699 | 701 | m_lastMouseMoveScenePoint = m_mousePressScenePoint; |
|
700 | 702 | m_lastMouseMoveScreenPoint = m_mousePressScreenPoint; |
|
701 | 703 | m_mousePressButton = event->button(); |
|
702 | 704 | m_mousePressButtons = event->buttons(); |
|
703 | 705 | |
|
704 | 706 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseDoubleClick); |
|
705 | 707 | mouseEvent.setWidget(0); |
|
706 | 708 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
707 | 709 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
708 | 710 | mouseEvent.setScenePos(m_mousePressScenePoint); |
|
709 | 711 | mouseEvent.setScreenPos(m_mousePressScreenPoint); |
|
710 | 712 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
711 | 713 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
712 | 714 | mouseEvent.setButtons(m_mousePressButtons); |
|
713 | 715 | mouseEvent.setButton(m_mousePressButton); |
|
714 | 716 | mouseEvent.setModifiers(event->modifiers()); |
|
715 | 717 | mouseEvent.setAccepted(false); |
|
716 | 718 | |
|
717 | 719 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
718 | 720 | } |
|
719 | 721 | |
|
720 | 722 | void DeclarativeChart::handleAntialiasingChanged(bool enable) |
|
721 | 723 | { |
|
722 | 724 | setAntialiasing(enable); |
|
723 | 725 | } |
|
724 | 726 | |
|
725 | 727 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
726 | 728 | { |
|
727 | 729 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
728 | 730 | if (chartTheme != m_chart->theme()) |
|
729 | 731 | m_chart->setTheme(chartTheme); |
|
730 | 732 | } |
|
731 | 733 | |
|
732 | 734 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
733 | 735 | { |
|
734 | 736 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
735 | 737 | } |
|
736 | 738 | |
|
737 | 739 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
738 | 740 | { |
|
739 | 741 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
740 | 742 | if (animationOptions != m_chart->animationOptions()) |
|
741 | 743 | m_chart->setAnimationOptions(animationOptions); |
|
742 | 744 | } |
|
743 | 745 | |
|
744 | 746 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
745 | 747 | { |
|
746 | 748 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
747 | 749 | return DeclarativeChart::AllAnimations; |
|
748 | 750 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
749 | 751 | return DeclarativeChart::GridAxisAnimations; |
|
750 | 752 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
751 | 753 | return DeclarativeChart::SeriesAnimations; |
|
752 | 754 | else |
|
753 | 755 | return DeclarativeChart::NoAnimation; |
|
754 | 756 | } |
|
755 | 757 | |
|
756 | 758 | void DeclarativeChart::setAnimationDuration(int msecs) |
|
757 | 759 | { |
|
758 | 760 | if (msecs != m_chart->animationDuration()) { |
|
759 | 761 | m_chart->setAnimationDuration(msecs); |
|
760 | 762 | emit animationDurationChanged(msecs); |
|
761 | 763 | } |
|
762 | 764 | } |
|
763 | 765 | |
|
764 | 766 | int DeclarativeChart::animationDuration() const |
|
765 | 767 | { |
|
766 | 768 | return m_chart->animationDuration(); |
|
767 | 769 | } |
|
768 | 770 | |
|
769 | 771 | void DeclarativeChart::setAnimationEasingCurve(const QEasingCurve &curve) |
|
770 | 772 | { |
|
771 | 773 | if (curve != m_chart->animationEasingCurve()) { |
|
772 | 774 | m_chart->setAnimationEasingCurve(curve); |
|
773 | 775 | emit animationEasingCurveChanged(curve); |
|
774 | 776 | } |
|
775 | 777 | } |
|
776 | 778 | |
|
777 | 779 | QEasingCurve DeclarativeChart::animationEasingCurve() const |
|
778 | 780 | { |
|
779 | 781 | return m_chart->animationEasingCurve(); |
|
780 | 782 | } |
|
781 | 783 | |
|
782 | 784 | void DeclarativeChart::setTitle(QString title) |
|
783 | 785 | { |
|
784 | 786 | if (title != m_chart->title()) |
|
785 | 787 | m_chart->setTitle(title); |
|
786 | 788 | } |
|
787 | 789 | QString DeclarativeChart::title() |
|
788 | 790 | { |
|
789 | 791 | return m_chart->title(); |
|
790 | 792 | } |
|
791 | 793 | |
|
792 | 794 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) |
|
793 | 795 | { |
|
794 | 796 | QList<QAbstractAxis *> axes = m_chart->axes(Qt::Horizontal, series); |
|
795 | 797 | if (axes.count()) |
|
796 | 798 | return axes[0]; |
|
797 | 799 | return 0; |
|
798 | 800 | } |
|
799 | 801 | |
|
800 | 802 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
801 | 803 | { |
|
802 | 804 | QList<QAbstractAxis *> axes = m_chart->axes(Qt::Vertical, series); |
|
803 | 805 | if (axes.count()) |
|
804 | 806 | return axes[0]; |
|
805 | 807 | return 0; |
|
806 | 808 | } |
|
807 | 809 | |
|
808 | 810 | QLegend *DeclarativeChart::legend() |
|
809 | 811 | { |
|
810 | 812 | return m_chart->legend(); |
|
811 | 813 | } |
|
812 | 814 | |
|
813 | 815 | void DeclarativeChart::setTitleColor(QColor color) |
|
814 | 816 | { |
|
815 | 817 | QBrush b = m_chart->titleBrush(); |
|
816 | 818 | if (color != b.color()) { |
|
817 | 819 | b.setColor(color); |
|
818 | 820 | m_chart->setTitleBrush(b); |
|
819 | 821 | emit titleColorChanged(color); |
|
820 | 822 | } |
|
821 | 823 | } |
|
822 | 824 | |
|
823 | 825 | QFont DeclarativeChart::titleFont() const |
|
824 | 826 | { |
|
825 | 827 | return m_chart->titleFont(); |
|
826 | 828 | } |
|
827 | 829 | |
|
828 | 830 | void DeclarativeChart::setTitleFont(const QFont &font) |
|
829 | 831 | { |
|
830 | 832 | m_chart->setTitleFont(font); |
|
831 | 833 | } |
|
832 | 834 | |
|
833 | 835 | QColor DeclarativeChart::titleColor() |
|
834 | 836 | { |
|
835 | 837 | return m_chart->titleBrush().color(); |
|
836 | 838 | } |
|
837 | 839 | |
|
838 | 840 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
839 | 841 | { |
|
840 | 842 | QBrush b = m_chart->backgroundBrush(); |
|
841 | 843 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
842 | 844 | if (color.alpha() < 0xff) |
|
843 | 845 | m_sceneImageNeedsClear = true; |
|
844 | 846 | b.setStyle(Qt::SolidPattern); |
|
845 | 847 | b.setColor(color); |
|
846 | 848 | m_chart->setBackgroundBrush(b); |
|
847 | 849 | emit backgroundColorChanged(); |
|
848 | 850 | } |
|
849 | 851 | } |
|
850 | 852 | |
|
851 | 853 | QColor DeclarativeChart::backgroundColor() |
|
852 | 854 | { |
|
853 | 855 | return m_chart->backgroundBrush().color(); |
|
854 | 856 | } |
|
855 | 857 | |
|
856 | 858 | void QtCharts::DeclarativeChart::setPlotAreaColor(QColor color) |
|
857 | 859 | { |
|
858 | 860 | QBrush b = m_chart->plotAreaBackgroundBrush(); |
|
859 | 861 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
860 | 862 | b.setStyle(Qt::SolidPattern); |
|
861 | 863 | b.setColor(color); |
|
862 | 864 | m_chart->setPlotAreaBackgroundBrush(b); |
|
863 | 865 | m_chart->setPlotAreaBackgroundVisible(true); |
|
864 | 866 | emit plotAreaColorChanged(); |
|
865 | 867 | } |
|
866 | 868 | } |
|
867 | 869 | |
|
868 | 870 | QColor QtCharts::DeclarativeChart::plotAreaColor() |
|
869 | 871 | { |
|
870 | 872 | return m_chart->plotAreaBackgroundBrush().color(); |
|
871 | 873 | } |
|
872 | 874 | |
|
873 | 875 | void DeclarativeChart::setLocalizeNumbers(bool localize) |
|
874 | 876 | { |
|
875 | 877 | if (m_chart->localizeNumbers() != localize) { |
|
876 | 878 | m_chart->setLocalizeNumbers(localize); |
|
877 | 879 | emit localizeNumbersChanged(); |
|
878 | 880 | } |
|
879 | 881 | } |
|
880 | 882 | |
|
881 | 883 | bool DeclarativeChart::localizeNumbers() const |
|
882 | 884 | { |
|
883 | 885 | return m_chart->localizeNumbers(); |
|
884 | 886 | } |
|
885 | 887 | |
|
886 | 888 | void QtCharts::DeclarativeChart::setLocale(const QLocale &locale) |
|
887 | 889 | { |
|
888 | 890 | if (m_chart->locale() != locale) { |
|
889 | 891 | m_chart->setLocale(locale); |
|
890 | 892 | emit localeChanged(); |
|
891 | 893 | } |
|
892 | 894 | } |
|
893 | 895 | |
|
894 | 896 | QLocale QtCharts::DeclarativeChart::locale() const |
|
895 | 897 | { |
|
896 | 898 | return m_chart->locale(); |
|
897 | 899 | } |
|
898 | 900 | |
|
899 | 901 | int DeclarativeChart::count() |
|
900 | 902 | { |
|
901 | 903 | return m_chart->series().count(); |
|
902 | 904 | } |
|
903 | 905 | |
|
904 | 906 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
905 | 907 | { |
|
906 | 908 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
907 | 909 | m_sceneImageNeedsClear = true; |
|
908 | 910 | m_chart->setDropShadowEnabled(enabled); |
|
909 | 911 | dropShadowEnabledChanged(enabled); |
|
910 | 912 | } |
|
911 | 913 | } |
|
912 | 914 | |
|
913 | 915 | bool DeclarativeChart::dropShadowEnabled() |
|
914 | 916 | { |
|
915 | 917 | return m_chart->isDropShadowEnabled(); |
|
916 | 918 | } |
|
917 | 919 | |
|
918 | 920 | qreal DeclarativeChart::backgroundRoundness() const |
|
919 | 921 | { |
|
920 | 922 | return m_chart->backgroundRoundness(); |
|
921 | 923 | } |
|
922 | 924 | |
|
923 | 925 | void DeclarativeChart::setBackgroundRoundness(qreal diameter) |
|
924 | 926 | { |
|
925 | 927 | if (m_chart->backgroundRoundness() != diameter) { |
|
926 | 928 | m_sceneImageNeedsClear = true; |
|
927 | 929 | m_chart->setBackgroundRoundness(diameter); |
|
928 | 930 | emit backgroundRoundnessChanged(diameter); |
|
929 | 931 | } |
|
930 | 932 | } |
|
931 | 933 | |
|
932 | 934 | void DeclarativeChart::zoom(qreal factor) |
|
933 | 935 | { |
|
934 | 936 | m_chart->zoom(factor); |
|
935 | 937 | } |
|
936 | 938 | |
|
937 | 939 | void DeclarativeChart::zoomIn() |
|
938 | 940 | { |
|
939 | 941 | m_chart->zoomIn(); |
|
940 | 942 | } |
|
941 | 943 | |
|
942 | 944 | void DeclarativeChart::zoomIn(const QRectF &rectangle) |
|
943 | 945 | { |
|
944 | 946 | m_chart->zoomIn(rectangle); |
|
945 | 947 | } |
|
946 | 948 | |
|
947 | 949 | void DeclarativeChart::zoomOut() |
|
948 | 950 | { |
|
949 | 951 | m_chart->zoomOut(); |
|
950 | 952 | } |
|
951 | 953 | |
|
952 | 954 | void DeclarativeChart::zoomReset() |
|
953 | 955 | { |
|
954 | 956 | m_chart->zoomReset(); |
|
955 | 957 | } |
|
956 | 958 | |
|
957 | 959 | bool DeclarativeChart::isZoomed() |
|
958 | 960 | { |
|
959 | 961 | return m_chart->isZoomed(); |
|
960 | 962 | } |
|
961 | 963 | |
|
962 | 964 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
963 | 965 | { |
|
964 | 966 | m_chart->scroll(-pixels, 0); |
|
965 | 967 | } |
|
966 | 968 | |
|
967 | 969 | void DeclarativeChart::scrollRight(qreal pixels) |
|
968 | 970 | { |
|
969 | 971 | m_chart->scroll(pixels, 0); |
|
970 | 972 | } |
|
971 | 973 | |
|
972 | 974 | void DeclarativeChart::scrollUp(qreal pixels) |
|
973 | 975 | { |
|
974 | 976 | m_chart->scroll(0, pixels); |
|
975 | 977 | } |
|
976 | 978 | |
|
977 | 979 | void DeclarativeChart::scrollDown(qreal pixels) |
|
978 | 980 | { |
|
979 | 981 | m_chart->scroll(0, -pixels); |
|
980 | 982 | } |
|
981 | 983 | |
|
982 | 984 | QQmlListProperty<QAbstractAxis> DeclarativeChart::axes() |
|
983 | 985 | { |
|
984 | 986 | return QQmlListProperty<QAbstractAxis>(this, 0, |
|
985 | 987 | &DeclarativeChart::axesAppendFunc, |
|
986 | 988 | &DeclarativeChart::axesCountFunc, |
|
987 | 989 | &DeclarativeChart::axesAtFunc, |
|
988 | 990 | &DeclarativeChart::axesClearFunc); |
|
989 | 991 | } |
|
990 | 992 | |
|
991 | 993 | void DeclarativeChart::axesAppendFunc(QQmlListProperty<QAbstractAxis> *list, QAbstractAxis *element) |
|
992 | 994 | { |
|
993 | 995 | // Empty implementation |
|
994 | 996 | Q_UNUSED(list); |
|
995 | 997 | Q_UNUSED(element); |
|
996 | 998 | } |
|
997 | 999 | |
|
998 | 1000 | int DeclarativeChart::axesCountFunc(QQmlListProperty<QAbstractAxis> *list) |
|
999 | 1001 | { |
|
1000 | 1002 | if (qobject_cast<DeclarativeChart *>(list->object)) { |
|
1001 | 1003 | DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object); |
|
1002 | 1004 | return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical).count(); |
|
1003 | 1005 | } |
|
1004 | 1006 | return 0; |
|
1005 | 1007 | } |
|
1006 | 1008 | |
|
1007 | 1009 | QAbstractAxis *DeclarativeChart::axesAtFunc(QQmlListProperty<QAbstractAxis> *list, int index) |
|
1008 | 1010 | { |
|
1009 | 1011 | if (qobject_cast<DeclarativeChart *>(list->object)) { |
|
1010 | 1012 | DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object); |
|
1011 | 1013 | QList<QAbstractAxis *> axes = chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]); |
|
1012 | 1014 | return axes.at(index); |
|
1013 | 1015 | } |
|
1014 | 1016 | return 0; |
|
1015 | 1017 | } |
|
1016 | 1018 | |
|
1017 | 1019 | void DeclarativeChart::axesClearFunc(QQmlListProperty<QAbstractAxis> *list) |
|
1018 | 1020 | { |
|
1019 | 1021 | // Empty implementation |
|
1020 | 1022 | Q_UNUSED(list); |
|
1021 | 1023 | } |
|
1022 | 1024 | |
|
1023 | 1025 | |
|
1024 | 1026 | QAbstractSeries *DeclarativeChart::series(int index) |
|
1025 | 1027 | { |
|
1026 | 1028 | if (index < m_chart->series().count()) { |
|
1027 | 1029 | return m_chart->series().at(index); |
|
1028 | 1030 | } |
|
1029 | 1031 | return 0; |
|
1030 | 1032 | } |
|
1031 | 1033 | |
|
1032 | 1034 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
1033 | 1035 | { |
|
1034 | 1036 | foreach (QAbstractSeries *series, m_chart->series()) { |
|
1035 | 1037 | if (series->name() == seriesName) |
|
1036 | 1038 | return series; |
|
1037 | 1039 | } |
|
1038 | 1040 | return 0; |
|
1039 | 1041 | } |
|
1040 | 1042 | |
|
1041 | 1043 | QAbstractSeries *DeclarativeChart::createSeries(int type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY) |
|
1042 | 1044 | { |
|
1043 | 1045 | QAbstractSeries *series = 0; |
|
1044 | 1046 | |
|
1045 | 1047 | switch (type) { |
|
1046 | 1048 | case DeclarativeChart::SeriesTypeLine: |
|
1047 | 1049 | series = new DeclarativeLineSeries(); |
|
1048 | 1050 | break; |
|
1049 | 1051 | case DeclarativeChart::SeriesTypeArea: { |
|
1050 | 1052 | DeclarativeAreaSeries *area = new DeclarativeAreaSeries(); |
|
1051 | 1053 | DeclarativeLineSeries *line = new DeclarativeLineSeries(); |
|
1052 | 1054 | line->setParent(area); |
|
1053 | 1055 | area->setUpperSeries(line); |
|
1054 | 1056 | series = area; |
|
1055 | 1057 | break; |
|
1056 | 1058 | } |
|
1057 | 1059 | case DeclarativeChart::SeriesTypeStackedBar: |
|
1058 | 1060 | series = new DeclarativeStackedBarSeries(); |
|
1059 | 1061 | break; |
|
1060 | 1062 | case DeclarativeChart::SeriesTypePercentBar: |
|
1061 | 1063 | series = new DeclarativePercentBarSeries(); |
|
1062 | 1064 | break; |
|
1063 | 1065 | case DeclarativeChart::SeriesTypeBar: |
|
1064 | 1066 | series = new DeclarativeBarSeries(); |
|
1065 | 1067 | break; |
|
1066 | 1068 | case DeclarativeChart::SeriesTypeHorizontalBar: |
|
1067 | 1069 | series = new DeclarativeHorizontalBarSeries(); |
|
1068 | 1070 | break; |
|
1069 | 1071 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: |
|
1070 | 1072 | series = new DeclarativeHorizontalPercentBarSeries(); |
|
1071 | 1073 | break; |
|
1072 | 1074 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: |
|
1073 | 1075 | series = new DeclarativeHorizontalStackedBarSeries(); |
|
1074 | 1076 | break; |
|
1075 | 1077 | case DeclarativeChart::SeriesTypeBoxPlot: |
|
1076 | 1078 | series = new DeclarativeBoxPlotSeries(); |
|
1077 | 1079 | break; |
|
1078 | 1080 | case DeclarativeChart::SeriesTypePie: |
|
1079 | 1081 | series = new DeclarativePieSeries(); |
|
1080 | 1082 | break; |
|
1081 | 1083 | case DeclarativeChart::SeriesTypeScatter: |
|
1082 | 1084 | series = new DeclarativeScatterSeries(); |
|
1083 | 1085 | break; |
|
1084 | 1086 | case DeclarativeChart::SeriesTypeSpline: |
|
1085 | 1087 | series = new DeclarativeSplineSeries(); |
|
1086 | 1088 | break; |
|
1087 | 1089 | default: |
|
1088 | 1090 | qWarning() << "Illegal series type"; |
|
1089 | 1091 | } |
|
1090 | 1092 | |
|
1091 | 1093 | if (series) { |
|
1092 | 1094 | // Connect to axis changed signals (unless this is a pie series) |
|
1093 | 1095 | if (!qobject_cast<DeclarativePieSeries *>(series)) { |
|
1094 | 1096 | connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
1095 | 1097 | connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
1096 | 1098 | connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
1097 | 1099 | connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); |
|
1098 | 1100 | } |
|
1099 | 1101 | |
|
1100 | 1102 | series->setName(name); |
|
1101 | 1103 | m_chart->addSeries(series); |
|
1102 | 1104 | |
|
1103 | 1105 | if (!axisX || !axisY) |
|
1104 | 1106 | initializeAxes(series); |
|
1105 | 1107 | |
|
1106 | 1108 | if (axisX) |
|
1107 | 1109 | setAxisX(axisX, series); |
|
1108 | 1110 | if (axisY) |
|
1109 | 1111 | setAxisY(axisY, series); |
|
1110 | 1112 | } |
|
1111 | 1113 | |
|
1112 | 1114 | return series; |
|
1113 | 1115 | } |
|
1114 | 1116 | |
|
1115 | 1117 | void DeclarativeChart::removeSeries(QAbstractSeries *series) |
|
1116 | 1118 | { |
|
1117 | 1119 | if (series) |
|
1118 | 1120 | m_chart->removeSeries(series); |
|
1119 | 1121 | else |
|
1120 | 1122 | qWarning("removeSeries: cannot remove null"); |
|
1121 | 1123 | } |
|
1122 | 1124 | |
|
1123 | 1125 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) |
|
1124 | 1126 | { |
|
1125 | 1127 | if (axis && series) |
|
1126 | 1128 | seriesAxisAttachHelper(series, axis, Qt::Horizontal, Qt::AlignBottom); |
|
1127 | 1129 | } |
|
1128 | 1130 | |
|
1129 | 1131 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) |
|
1130 | 1132 | { |
|
1131 | 1133 | if (axis && series) |
|
1132 | 1134 | seriesAxisAttachHelper(series, axis, Qt::Vertical, Qt::AlignLeft); |
|
1133 | 1135 | } |
|
1134 | 1136 | |
|
1135 | 1137 | QAbstractAxis *DeclarativeChart::defaultAxis(Qt::Orientation orientation, QAbstractSeries *series) |
|
1136 | 1138 | { |
|
1137 | 1139 | if (!series) { |
|
1138 | 1140 | qWarning() << "No axis type defined for null series"; |
|
1139 | 1141 | return 0; |
|
1140 | 1142 | } |
|
1141 | 1143 | |
|
1142 | 1144 | foreach (QAbstractAxis *existingAxis, m_chart->axes(orientation)) { |
|
1143 | 1145 | if (existingAxis->type() == series->d_ptr->defaultAxisType(orientation)) |
|
1144 | 1146 | return existingAxis; |
|
1145 | 1147 | } |
|
1146 | 1148 | |
|
1147 | 1149 | switch (series->d_ptr->defaultAxisType(orientation)) { |
|
1148 | 1150 | case QAbstractAxis::AxisTypeValue: |
|
1149 | 1151 | return new QValueAxis(this); |
|
1150 | 1152 | case QAbstractAxis::AxisTypeBarCategory: |
|
1151 | 1153 | return new QBarCategoryAxis(this); |
|
1152 | 1154 | case QAbstractAxis::AxisTypeCategory: |
|
1153 | 1155 | return new QCategoryAxis(this); |
|
1154 | 1156 | #ifndef QT_QREAL_IS_FLOAT |
|
1155 | 1157 | case QAbstractAxis::AxisTypeDateTime: |
|
1156 | 1158 | return new QDateTimeAxis(this); |
|
1157 | 1159 | #endif |
|
1158 | 1160 | case QAbstractAxis::AxisTypeLogValue: |
|
1159 | 1161 | return new QLogValueAxis(this); |
|
1160 | 1162 | default: |
|
1161 | 1163 | // assume AxisTypeNoAxis |
|
1162 | 1164 | return 0; |
|
1163 | 1165 | } |
|
1164 | 1166 | } |
|
1165 | 1167 | |
|
1166 | 1168 | void DeclarativeChart::initializeAxes(QAbstractSeries *series) |
|
1167 | 1169 | { |
|
1168 | 1170 | if (qobject_cast<DeclarativeLineSeries *>(series)) |
|
1169 | 1171 | doInitializeAxes(series, qobject_cast<DeclarativeLineSeries *>(series)->m_axes); |
|
1170 | 1172 | else if (qobject_cast<DeclarativeScatterSeries *>(series)) |
|
1171 | 1173 | doInitializeAxes(series, qobject_cast<DeclarativeScatterSeries *>(series)->m_axes); |
|
1172 | 1174 | else if (qobject_cast<DeclarativeSplineSeries *>(series)) |
|
1173 | 1175 | doInitializeAxes(series, qobject_cast<DeclarativeSplineSeries *>(series)->m_axes); |
|
1174 | 1176 | else if (qobject_cast<DeclarativeAreaSeries *>(series)) |
|
1175 | 1177 | doInitializeAxes(series, qobject_cast<DeclarativeAreaSeries *>(series)->m_axes); |
|
1176 | 1178 | else if (qobject_cast<DeclarativeBarSeries *>(series)) |
|
1177 | 1179 | doInitializeAxes(series, qobject_cast<DeclarativeBarSeries *>(series)->m_axes); |
|
1178 | 1180 | else if (qobject_cast<DeclarativeStackedBarSeries *>(series)) |
|
1179 | 1181 | doInitializeAxes(series, qobject_cast<DeclarativeStackedBarSeries *>(series)->m_axes); |
|
1180 | 1182 | else if (qobject_cast<DeclarativePercentBarSeries *>(series)) |
|
1181 | 1183 | doInitializeAxes(series, qobject_cast<DeclarativePercentBarSeries *>(series)->m_axes); |
|
1182 | 1184 | else if (qobject_cast<DeclarativeHorizontalBarSeries *>(series)) |
|
1183 | 1185 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalBarSeries *>(series)->m_axes); |
|
1184 | 1186 | else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)) |
|
1185 | 1187 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)->m_axes); |
|
1186 | 1188 | else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)) |
|
1187 | 1189 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)->m_axes); |
|
1188 | 1190 | else if (qobject_cast<DeclarativeBoxPlotSeries *>(series)) |
|
1189 | 1191 | doInitializeAxes(series, qobject_cast<DeclarativeBoxPlotSeries *>(series)->m_axes); |
|
1190 | 1192 | // else: do nothing |
|
1191 | 1193 | } |
|
1192 | 1194 | |
|
1193 | 1195 | void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes) |
|
1194 | 1196 | { |
|
1195 | 1197 | qreal min; |
|
1196 | 1198 | qreal max; |
|
1197 | 1199 | // Initialize axis X |
|
1198 | 1200 | if (axes->axisX()) { |
|
1199 | 1201 | axes->emitAxisXChanged(); |
|
1200 | 1202 | } else if (axes->axisXTop()) { |
|
1201 | 1203 | axes->emitAxisXTopChanged(); |
|
1202 | 1204 | } else { |
|
1203 | 1205 | axes->setAxisX(defaultAxis(Qt::Horizontal, series)); |
|
1204 | 1206 | findMinMaxForSeries(series, Qt::Horizontal, min, max); |
|
1205 | 1207 | axes->axisX()->setRange(min, max); |
|
1206 | 1208 | } |
|
1207 | 1209 | |
|
1208 | 1210 | // Initialize axis Y |
|
1209 | 1211 | if (axes->axisY()) { |
|
1210 | 1212 | axes->emitAxisYChanged(); |
|
1211 | 1213 | } else if (axes->axisYRight()) { |
|
1212 | 1214 | axes->emitAxisYRightChanged(); |
|
1213 | 1215 | } else { |
|
1214 | 1216 | axes->setAxisY(defaultAxis(Qt::Vertical, series)); |
|
1215 | 1217 | findMinMaxForSeries(series, Qt::Vertical, min, max); |
|
1216 | 1218 | axes->axisY()->setRange(min, max); |
|
1217 | 1219 | } |
|
1218 | 1220 | } |
|
1219 | 1221 | |
|
1220 | 1222 | void DeclarativeChart::findMinMaxForSeries(QAbstractSeries *series, Qt::Orientations orientation, |
|
1221 | 1223 | qreal &min, qreal &max) |
|
1222 | 1224 | { |
|
1223 | 1225 | if (!series) { |
|
1224 | 1226 | min = 0.5; |
|
1225 | 1227 | max = 0.5; |
|
1226 | 1228 | } else { |
|
1227 | 1229 | AbstractDomain *domain = series->d_ptr->domain(); |
|
1228 | 1230 | min = (orientation == Qt::Vertical) ? domain->minY() : domain->minX(); |
|
1229 | 1231 | max = (orientation == Qt::Vertical) ? domain->maxY() : domain->maxX(); |
|
1230 | 1232 | |
|
1231 | 1233 | if (min == max) { |
|
1232 | 1234 | min -= 0.5; |
|
1233 | 1235 | max += 0.5; |
|
1234 | 1236 | } |
|
1235 | 1237 | } |
|
1236 | 1238 | } |
|
1237 | 1239 | |
|
1238 | 1240 | QPointF DeclarativeChart::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
1239 | 1241 | { |
|
1240 | 1242 | return m_chart->mapToValue(position, series); |
|
1241 | 1243 | } |
|
1242 | 1244 | |
|
1243 | 1245 | QPointF DeclarativeChart::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
1244 | 1246 | { |
|
1245 | 1247 | return m_chart->mapToPosition(value, series); |
|
1246 | 1248 | } |
|
1247 | 1249 | |
|
1248 | 1250 | #include "moc_declarativechart.cpp" |
|
1249 | 1251 | |
|
1250 | 1252 | QT_CHARTS_END_NAMESPACE |
@@ -1,89 +1,89 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include "declarativechartnode.h" |
|
31 | 31 | #include "declarativerendernode.h" |
|
32 | 32 | #include <QtGui/QOpenGLContext> |
|
33 | 33 | #include <QtGui/QOpenGLFunctions> |
|
34 | 34 | #include <QtGui/QOpenGLFramebufferObjectFormat> |
|
35 | 35 | #include <QtGui/QOpenGLFramebufferObject> |
|
36 | 36 | #include <QOpenGLShaderProgram> |
|
37 | 37 | #include <QtGui/QOpenGLBuffer> |
|
38 | 38 | |
|
39 | 39 | QT_CHARTS_BEGIN_NAMESPACE |
|
40 | 40 | |
|
41 | 41 | // This node handles displaying of the chart itself |
|
42 | 42 | DeclarativeChartNode::DeclarativeChartNode(QQuickWindow *window) : |
|
43 | 43 | QSGSimpleTextureNode(), |
|
44 | 44 | m_texture(0), |
|
45 | 45 | m_window(window), |
|
46 | 46 | m_textureOptions(0), |
|
47 | 47 | m_textureSize(1, 1), |
|
48 | 48 | m_glRenderNode(0) |
|
49 | 49 | { |
|
50 | initializeOpenGLFunctions(); | |
|
51 | ||
|
52 | 50 | // Our texture node must have a texture, so use a default one pixel texture |
|
53 | GLuint defaultTexture = 0; | |
|
54 | glGenTextures(1, &defaultTexture); | |
|
55 | glBindTexture(GL_TEXTURE_2D, defaultTexture); | |
|
56 | uchar buf[4] = { 0, 0, 0, 0 }; | |
|
57 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &buf); | |
|
58 | ||
|
51 | QImage dummyImage(QSize(1, 1), QImage::Format_ARGB32); | |
|
52 | uchar *imageData = dummyImage.bits(); | |
|
53 | imageData[0] = 0; | |
|
54 | imageData[1] = 0; | |
|
55 | imageData[2] = 0; | |
|
56 | imageData[3] = 0; | |
|
59 | 57 | QQuickWindow::CreateTextureOptions defaultTextureOptions = QQuickWindow::CreateTextureOptions( |
|
60 | 58 | QQuickWindow::TextureHasAlphaChannel | QQuickWindow::TextureOwnsGLTexture); |
|
61 |
m_texture = m_window->createTextureFromI |
|
|
59 | m_texture = m_window->createTextureFromImage(dummyImage, defaultTextureOptions); | |
|
62 | 60 | |
|
63 | 61 | setTexture(m_texture); |
|
64 | 62 | setFiltering(QSGTexture::Linear); |
|
65 | 63 | |
|
64 | if (QOpenGLContext::currentContext()) { | |
|
66 | 65 | // Create child node for rendering GL graphics |
|
67 | 66 | m_glRenderNode = new DeclarativeRenderNode(m_window); |
|
68 | 67 | m_glRenderNode->setFlag(OwnedByParent); |
|
69 | 68 | appendChildNode(m_glRenderNode); |
|
70 | 69 | m_glRenderNode->setRect(0, 0, 0, 0); // Hide child node by default |
|
71 | 70 | } |
|
71 | } | |
|
72 | 72 | |
|
73 | 73 | DeclarativeChartNode::~DeclarativeChartNode() |
|
74 | 74 | { |
|
75 | 75 | delete m_texture; |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | // Must be called on render thread and in context |
|
79 | 79 | void DeclarativeChartNode::createTextureFromImage(const QImage &chartImage) |
|
80 | 80 | { |
|
81 | 81 | if (chartImage.size() != m_textureSize) |
|
82 | 82 | m_textureSize = chartImage.size(); |
|
83 | 83 | |
|
84 | 84 | delete m_texture; |
|
85 | 85 | m_texture = m_window->createTextureFromImage(chartImage, m_textureOptions); |
|
86 | 86 | setTexture(m_texture); |
|
87 | 87 | } |
|
88 | 88 | |
|
89 | 89 | QT_CHARTS_END_NAMESPACE |
@@ -1,388 +1,388 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
4 | 4 | ** Contact: https://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
9 | 9 | ** Commercial License Usage |
|
10 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
11 | 11 | ** accordance with the commercial license agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
14 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
15 | 15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
16 | 16 | ** |
|
17 | 17 | ** GNU General Public License Usage |
|
18 | 18 | ** Alternatively, this file may be used under the terms of the GNU |
|
19 | 19 | ** General Public License version 3 or (at your option) any later version |
|
20 | 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
21 | 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
22 | 22 | ** included in the packaging of this file. Please review the following |
|
23 | 23 | ** information to ensure the GNU General Public License requirements will |
|
24 | 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
25 | 25 | ** |
|
26 | 26 | ** $QT_END_LICENSE$ |
|
27 | 27 | ** |
|
28 | 28 | ****************************************************************************/ |
|
29 | 29 | |
|
30 | 30 | #include "mainwidget.h" |
|
31 | 31 | #include "dataseriedialog.h" |
|
32 | 32 | #include <QtCharts/QChartView> |
|
33 | 33 | #include <QtCharts/QPieSeries> |
|
34 | 34 | #include <QtCharts/QScatterSeries> |
|
35 | 35 | #include <QtCharts/QLineSeries> |
|
36 | 36 | #include <QtCharts/QAreaSeries> |
|
37 | 37 | #include <QtCharts/QSplineSeries> |
|
38 | 38 | #include <QtCharts/QBarSet> |
|
39 | 39 | #include <QtCharts/QBarSeries> |
|
40 | 40 | #include <QtCharts/QStackedBarSeries> |
|
41 | 41 | #include <QtCharts/QPercentBarSeries> |
|
42 | 42 | #include <QtWidgets/QPushButton> |
|
43 | 43 | #include <QtWidgets/QComboBox> |
|
44 | 44 | #include <QtWidgets/QSpinBox> |
|
45 | 45 | #include <QtWidgets/QCheckBox> |
|
46 | 46 | #include <QtWidgets/QGridLayout> |
|
47 | 47 | #include <QtWidgets/QHBoxLayout> |
|
48 | 48 | #include <QtWidgets/QLabel> |
|
49 | 49 | #include <QtWidgets/QSpacerItem> |
|
50 | 50 | #include <QtWidgets/QMessageBox> |
|
51 | 51 | #include <cmath> |
|
52 | 52 | #include <QtCore/QDebug> |
|
53 | 53 | #include <QtGui/QStandardItemModel> |
|
54 | 54 | #include <QtCharts/QBarCategoryAxis> |
|
55 | 55 | #include <QtWidgets/QOpenGLWidget> |
|
56 | 56 | |
|
57 | 57 | QT_CHARTS_USE_NAMESPACE |
|
58 | 58 | |
|
59 | 59 | MainWidget::MainWidget(QWidget *parent) : |
|
60 | 60 | QWidget(parent), |
|
61 | 61 | m_addSerieDialog(0), |
|
62 | 62 | m_chart(0) |
|
63 | 63 | { |
|
64 | 64 | m_chart = new QChart(); |
|
65 | 65 | |
|
66 | 66 | // Grid layout for the controls for configuring the chart widget |
|
67 | 67 | QGridLayout *grid = new QGridLayout(); |
|
68 | 68 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
69 | 69 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
70 | 70 | grid->addWidget(addSeriesButton, 0, 1); |
|
71 | 71 | initBackroundCombo(grid); |
|
72 | 72 | initScaleControls(grid); |
|
73 | 73 | initThemeCombo(grid); |
|
74 | 74 | initCheckboxes(grid); |
|
75 | 75 | |
|
76 | 76 | // add row with empty label to make all the other rows static |
|
77 | 77 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
78 | 78 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
79 | 79 | |
|
80 | 80 | // Create chart view with the chart |
|
81 | 81 | m_chartView = new QChartView(m_chart, this); |
|
82 | 82 | m_chartView->setRubberBand(QChartView::HorizontalRubberBand); |
|
83 | 83 | |
|
84 | 84 | // Another grid layout as a main layout |
|
85 | 85 | QGridLayout *mainLayout = new QGridLayout(); |
|
86 | 86 | mainLayout->addLayout(grid, 0, 0); |
|
87 | 87 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
88 | 88 | setLayout(mainLayout); |
|
89 | 89 | } |
|
90 | 90 | |
|
91 | 91 | // Combo box for selecting the chart's background |
|
92 | 92 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
93 | 93 | { |
|
94 | 94 | QComboBox *backgroundCombo = new QComboBox(this); |
|
95 | 95 | backgroundCombo->addItem("Color"); |
|
96 | 96 | backgroundCombo->addItem("Gradient"); |
|
97 | 97 | backgroundCombo->addItem("Image"); |
|
98 | 98 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
99 | 99 | this, SLOT(backgroundChanged(int))); |
|
100 | 100 | |
|
101 | 101 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
102 | 102 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
103 | 103 | } |
|
104 | 104 | |
|
105 | 105 | // Scale related controls (auto-scale vs. manual min-max values) |
|
106 | 106 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
107 | 107 | { |
|
108 | 108 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
109 | 109 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
110 | 110 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
111 | 111 | m_xMinSpin = new QSpinBox(); |
|
112 | 112 | m_xMinSpin->setMinimum(INT_MIN); |
|
113 | 113 | m_xMinSpin->setMaximum(INT_MAX); |
|
114 | 114 | m_xMinSpin->setValue(0); |
|
115 | 115 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
116 | 116 | m_xMaxSpin = new QSpinBox(); |
|
117 | 117 | m_xMaxSpin->setMinimum(INT_MIN); |
|
118 | 118 | m_xMaxSpin->setMaximum(INT_MAX); |
|
119 | 119 | m_xMaxSpin->setValue(10); |
|
120 | 120 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
121 | 121 | m_yMinSpin = new QSpinBox(); |
|
122 | 122 | m_yMinSpin->setMinimum(INT_MIN); |
|
123 | 123 | m_yMinSpin->setMaximum(INT_MAX); |
|
124 | 124 | m_yMinSpin->setValue(0); |
|
125 | 125 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
126 | 126 | m_yMaxSpin = new QSpinBox(); |
|
127 | 127 | m_yMaxSpin->setMinimum(INT_MIN); |
|
128 | 128 | m_yMaxSpin->setMaximum(INT_MAX); |
|
129 | 129 | m_yMaxSpin->setValue(10); |
|
130 | 130 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
131 | 131 | |
|
132 | 132 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
133 | 133 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
134 | 134 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
135 | 135 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
136 | 136 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
137 | 137 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
138 | 138 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
139 | 139 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
140 | 140 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
141 | 141 | |
|
142 | 142 | m_autoScaleCheck->setChecked(true); |
|
143 | 143 | } |
|
144 | 144 | |
|
145 | 145 | // Combo box for selecting theme |
|
146 | 146 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
147 | 147 | { |
|
148 | 148 | QComboBox *chartTheme = new QComboBox(); |
|
149 | 149 | chartTheme->addItem("Default"); |
|
150 | 150 | chartTheme->addItem("Light"); |
|
151 | 151 | chartTheme->addItem("Blue Cerulean"); |
|
152 | 152 | chartTheme->addItem("Dark"); |
|
153 | 153 | chartTheme->addItem("Brown Sand"); |
|
154 | 154 | chartTheme->addItem("Blue NCS"); |
|
155 | 155 | chartTheme->addItem("High Contrast"); |
|
156 | 156 | chartTheme->addItem("Blue Icy"); |
|
157 | 157 | chartTheme->addItem("Qt"); |
|
158 | 158 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
159 | 159 | this, SLOT(changeChartTheme(int))); |
|
160 | 160 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
161 | 161 | grid->addWidget(chartTheme, 8, 1); |
|
162 | 162 | } |
|
163 | 163 | |
|
164 | 164 | // Different check boxes for customizing chart |
|
165 | 165 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
166 | 166 | { |
|
167 | 167 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off |
|
168 | 168 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
169 | 169 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); |
|
170 | 170 | zoomCheckBox->setChecked(true); |
|
171 | 171 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
172 | 172 | |
|
173 | 173 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); |
|
174 | 174 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); |
|
175 | 175 | aliasCheckBox->setChecked(false); |
|
176 | 176 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); |
|
177 | 177 | |
|
178 | 178 | QCheckBox *openGLCheckBox = new QCheckBox("Use QOpenGLWidget"); |
|
179 | 179 | connect(openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(openGLToggled(bool))); |
|
180 | 180 | openGLCheckBox->setChecked(false); |
|
181 | 181 | grid->addWidget(openGLCheckBox, grid->rowCount(), 0); |
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | void MainWidget::antiAliasToggled(bool enabled) |
|
185 | 185 | { |
|
186 | 186 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); |
|
187 | 187 | } |
|
188 | 188 | |
|
189 | 189 | void MainWidget::openGLToggled(bool enabled) |
|
190 | 190 | { |
|
191 | 191 | if (enabled) { |
|
192 | 192 | QSurfaceFormat f = QSurfaceFormat::defaultFormat(); |
|
193 | 193 | f.setSamples(4); |
|
194 | 194 | QSurfaceFormat::setDefaultFormat(f); |
|
195 | 195 | QOpenGLWidget *g = new QOpenGLWidget(); |
|
196 | 196 | m_chartView->setViewport(g); |
|
197 | 197 | } else { |
|
198 | 198 | m_chartView->setViewport(0); |
|
199 | 199 | } |
|
200 | 200 | } |
|
201 | 201 | |
|
202 | 202 | void MainWidget::addSeries() |
|
203 | 203 | { |
|
204 | 204 | if (!m_addSerieDialog) { |
|
205 | 205 | m_addSerieDialog = new DataSerieDialog(this); |
|
206 | 206 | connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), |
|
207 | 207 | this, SLOT(addSeries(QString,int,int,QString,bool))); |
|
208 | 208 | } |
|
209 | 209 | m_addSerieDialog->exec(); |
|
210 | 210 | } |
|
211 | 211 | |
|
212 | 212 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) |
|
213 | 213 | { |
|
214 | 214 | QList<RealList> testData; |
|
215 | 215 | for (int j(0); j < columnCount; j++) { |
|
216 | 216 | QList <qreal> newColumn; |
|
217 | 217 | for (int i(0); i < rowCount; i++) { |
|
218 | 218 | if (dataCharacteristics == "Sin") { |
|
219 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
|
219 | newColumn.append(std::abs(sin(3.14159265358979 / 50 * i) * 100)); | |
|
220 | 220 | } else if (dataCharacteristics == "Sin + random") { |
|
221 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
|
221 | newColumn.append(std::abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
|
222 | 222 | } else if (dataCharacteristics == "Random") { |
|
223 | 223 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); |
|
224 | 224 | } else if (dataCharacteristics == "Linear") { |
|
225 | 225 | //newColumn.append(i * (j + 1.0)); |
|
226 | 226 | // TODO: temporary hack to make pie work; prevent zero values: |
|
227 | 227 | newColumn.append(i * (j + 1.0) + 0.1); |
|
228 | 228 | } else { // "constant" |
|
229 | 229 | newColumn.append((j + 1.0)); |
|
230 | 230 | } |
|
231 | 231 | } |
|
232 | 232 | testData.append(newColumn); |
|
233 | 233 | } |
|
234 | 234 | return testData; |
|
235 | 235 | } |
|
236 | 236 | |
|
237 | 237 | QStringList MainWidget::generateLabels(int count) |
|
238 | 238 | { |
|
239 | 239 | QStringList result; |
|
240 | 240 | for (int i(0); i < count; i++) |
|
241 | 241 | result.append("label" + QString::number(i)); |
|
242 | 242 | return result; |
|
243 | 243 | } |
|
244 | 244 | |
|
245 | 245 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) |
|
246 | 246 | { |
|
247 | 247 | qDebug() << "addSeries: " << seriesName |
|
248 | 248 | << " columnCount: " << columnCount |
|
249 | 249 | << " rowCount: " << rowCount |
|
250 | 250 | << " dataCharacteristics: " << dataCharacteristics |
|
251 | 251 | << " labels enabled: " << labelsEnabled; |
|
252 | 252 | m_defaultSeriesName = seriesName; |
|
253 | 253 | |
|
254 | 254 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); |
|
255 | 255 | |
|
256 | 256 | // Line series and scatter series use similar data |
|
257 | 257 | if (seriesName == "Line") { |
|
258 | 258 | for (int j(0); j < data.count(); j ++) { |
|
259 | 259 | QList<qreal> column = data.at(j); |
|
260 | 260 | QLineSeries *series = new QLineSeries(); |
|
261 | 261 | series->setName("line" + QString::number(j)); |
|
262 | 262 | for (int i(0); i < column.count(); i++) |
|
263 | 263 | series->append(i, column.at(i)); |
|
264 | 264 | m_chart->addSeries(series); |
|
265 | 265 | } |
|
266 | 266 | } else if (seriesName == "Area") { |
|
267 | 267 | // TODO: lower series for the area? |
|
268 | 268 | for (int j(0); j < data.count(); j ++) { |
|
269 | 269 | QList<qreal> column = data.at(j); |
|
270 | 270 | QLineSeries *lineSeries = new QLineSeries(); |
|
271 | 271 | for (int i(0); i < column.count(); i++) |
|
272 | 272 | lineSeries->append(i, column.at(i)); |
|
273 | 273 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); |
|
274 | 274 | areaSeries->setName("area" + QString::number(j)); |
|
275 | 275 | m_chart->addSeries(areaSeries); |
|
276 | 276 | } |
|
277 | 277 | } else if (seriesName == "Scatter") { |
|
278 | 278 | for (int j(0); j < data.count(); j++) { |
|
279 | 279 | QList<qreal> column = data.at(j); |
|
280 | 280 | QScatterSeries *series = new QScatterSeries(); |
|
281 | 281 | series->setName("scatter" + QString::number(j)); |
|
282 | 282 | for (int i(0); i < column.count(); i++) |
|
283 | 283 | series->append(i, column.at(i)); |
|
284 | 284 | m_chart->addSeries(series); |
|
285 | 285 | } |
|
286 | 286 | } else if (seriesName == "Pie") { |
|
287 | 287 | QStringList labels = generateLabels(rowCount); |
|
288 | 288 | for (int j(0); j < data.count(); j++) { |
|
289 | 289 | QPieSeries *series = new QPieSeries(); |
|
290 | 290 | QList<qreal> column = data.at(j); |
|
291 | 291 | for (int i(0); i < column.count(); i++) |
|
292 | 292 | series->append(labels.at(i), column.at(i)); |
|
293 | 293 | m_chart->addSeries(series); |
|
294 | 294 | } |
|
295 | 295 | } else if (seriesName == "Bar" |
|
296 | 296 | || seriesName == "Stacked bar" |
|
297 | 297 | || seriesName == "Percent bar") { |
|
298 | 298 | QStringList category; |
|
299 | 299 | QStringList labels = generateLabels(rowCount); |
|
300 | 300 | foreach (QString label, labels) |
|
301 | 301 | category << label; |
|
302 | 302 | QAbstractBarSeries* series = 0; |
|
303 | 303 | if (seriesName == "Bar") { |
|
304 | 304 | series = new QBarSeries(this); |
|
305 | 305 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
306 | 306 | axis->append(category); |
|
307 | 307 | m_chart->setAxisX(axis,series); |
|
308 | 308 | } else if (seriesName == "Stacked bar") { |
|
309 | 309 | series = new QStackedBarSeries(this); |
|
310 | 310 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
311 | 311 | axis->append(category); |
|
312 | 312 | m_chart->setAxisX(axis,series); |
|
313 | 313 | } else { |
|
314 | 314 | series = new QPercentBarSeries(this); |
|
315 | 315 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
316 | 316 | axis->append(category); |
|
317 | 317 | m_chart->setAxisX(axis,series); |
|
318 | 318 | } |
|
319 | 319 | |
|
320 | 320 | for (int j(0); j < data.count(); j++) { |
|
321 | 321 | QList<qreal> column = data.at(j); |
|
322 | 322 | QBarSet *set = new QBarSet("set" + QString::number(j)); |
|
323 | 323 | for (int i(0); i < column.count(); i++) |
|
324 | 324 | *set << column.at(i); |
|
325 | 325 | series->append(set); |
|
326 | 326 | } |
|
327 | 327 | |
|
328 | 328 | m_chart->addSeries(series); |
|
329 | 329 | } else if (seriesName == "Spline") { |
|
330 | 330 | for (int j(0); j < data.count(); j ++) { |
|
331 | 331 | QList<qreal> column = data.at(j); |
|
332 | 332 | QSplineSeries *series = new QSplineSeries(); |
|
333 | 333 | series->setName("spline" + QString::number(j)); |
|
334 | 334 | for (int i(0); i < column.count(); i++) |
|
335 | 335 | series->append(i, column.at(i)); |
|
336 | 336 | m_chart->addSeries(series); |
|
337 | 337 | } |
|
338 | 338 | } |
|
339 | 339 | m_chart->createDefaultAxes(); |
|
340 | 340 | } |
|
341 | 341 | |
|
342 | 342 | void MainWidget::backgroundChanged(int itemIndex) |
|
343 | 343 | { |
|
344 | 344 | qDebug() << "backgroundChanged: " << itemIndex; |
|
345 | 345 | } |
|
346 | 346 | |
|
347 | 347 | void MainWidget::autoScaleChanged(int value) |
|
348 | 348 | { |
|
349 | 349 | if (value) { |
|
350 | 350 | // TODO: enable auto scaling |
|
351 | 351 | } else { |
|
352 | 352 | // TODO: set scaling manually (and disable auto scaling) |
|
353 | 353 | } |
|
354 | 354 | |
|
355 | 355 | m_xMinSpin->setEnabled(!value); |
|
356 | 356 | m_xMaxSpin->setEnabled(!value); |
|
357 | 357 | m_yMinSpin->setEnabled(!value); |
|
358 | 358 | m_yMaxSpin->setEnabled(!value); |
|
359 | 359 | } |
|
360 | 360 | |
|
361 | 361 | void MainWidget::xMinChanged(int value) |
|
362 | 362 | { |
|
363 | 363 | qDebug() << "xMinChanged: " << value; |
|
364 | 364 | } |
|
365 | 365 | |
|
366 | 366 | void MainWidget::xMaxChanged(int value) |
|
367 | 367 | { |
|
368 | 368 | qDebug() << "xMaxChanged: " << value; |
|
369 | 369 | } |
|
370 | 370 | |
|
371 | 371 | void MainWidget::yMinChanged(int value) |
|
372 | 372 | { |
|
373 | 373 | qDebug() << "yMinChanged: " << value; |
|
374 | 374 | } |
|
375 | 375 | |
|
376 | 376 | void MainWidget::yMaxChanged(int value) |
|
377 | 377 | { |
|
378 | 378 | qDebug() << "yMaxChanged: " << value; |
|
379 | 379 | } |
|
380 | 380 | |
|
381 | 381 | void MainWidget::changeChartTheme(int themeIndex) |
|
382 | 382 | { |
|
383 | 383 | qDebug() << "changeChartTheme: " << themeIndex; |
|
384 | 384 | if (themeIndex == 0) |
|
385 | 385 | m_chart->setTheme(QChart::ChartThemeLight); |
|
386 | 386 | else |
|
387 | 387 | m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1)); |
|
388 | 388 | } |
General Comments 0
You need to be logged in to leave comments.
Login now