1 | NO CONTENT: modified file |
|
NO CONTENT: modified file |
@@ -1,235 +1,233 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qsplineseries.h" |
|
21 | #include "qsplineseries.h" | |
22 | #include "qsplineseries_p.h" |
|
22 | #include "qsplineseries_p.h" | |
23 | #include "splinechartitem_p.h" |
|
23 | #include "splinechartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "splineanimation_p.h" |
|
26 | #include "splineanimation_p.h" | |
27 |
|
27 | |||
28 | /*! |
|
28 | /*! | |
29 | \class QSplineSeries |
|
29 | \class QSplineSeries | |
30 | \brief Series type used to store data needed to draw a spline. |
|
30 | \brief Series type used to store data needed to draw a spline. | |
31 |
|
31 | |||
32 | QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline |
|
32 | QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline | |
33 | Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn. |
|
33 | Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn. | |
34 |
|
34 | |||
35 | \image examples_splinechart.png |
|
35 | \image examples_splinechart.png | |
36 |
|
36 | |||
37 | Creating basic spline chart is simple: |
|
37 | Creating basic spline chart is simple: | |
38 | \code |
|
38 | \code | |
39 | QSplineSeries* series = new QSplineSeries(); |
|
39 | QSplineSeries* series = new QSplineSeries(); | |
40 | series->append(0, 6); |
|
40 | series->append(0, 6); | |
41 | series->append(2, 4); |
|
41 | series->append(2, 4); | |
42 | ... |
|
42 | ... | |
43 | chart->addSeries(series); |
|
43 | chart->addSeries(series); | |
44 | \endcode |
|
44 | \endcode | |
45 | */ |
|
45 | */ | |
46 |
|
46 | |||
47 | /*! |
|
47 | /*! | |
48 | \qmlclass SplineSeries QSplineSeries |
|
48 | \qmlclass SplineSeries QSplineSeries | |
49 | \inherits XYSeries |
|
49 | \inherits XYSeries | |
50 |
|
50 | |||
51 | The following QML shows how to create a simple spline chart: |
|
51 | The following QML shows how to create a simple spline chart: | |
52 | \snippet ../demos/qmlchart/qml/qmlchart/View3.qml 1 |
|
52 | \snippet ../demos/qmlchart/qml/qmlchart/View3.qml 1 | |
53 | \beginfloatleft |
|
53 | \beginfloatleft | |
54 | \image demos_qmlchart3.png |
|
54 | \image demos_qmlchart3.png | |
55 | \endfloat |
|
55 | \endfloat | |
56 | \clearfloat |
|
56 | \clearfloat | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | \fn QSeriesType QSplineSeries::type() const |
|
60 | \fn QSeriesType QSplineSeries::type() const | |
61 | Returns the type of the series |
|
61 | Returns the type of the series | |
62 | */ |
|
62 | */ | |
63 |
|
63 | |||
64 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
64 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
65 |
|
65 | |||
66 | /*! |
|
66 | /*! | |
67 | Constructs empty series object which is a child of \a parent. |
|
67 | Constructs empty series object which is a child of \a parent. | |
68 | When series object is added to QChartView or QChart instance then the ownerships is transferred. |
|
68 | When series object is added to QChartView or QChart instance then the ownerships is transferred. | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | QSplineSeries::QSplineSeries(QObject *parent) : |
|
71 | QSplineSeries::QSplineSeries(QObject *parent) : | |
72 | QLineSeries(*new QSplineSeriesPrivate(this),parent) |
|
72 | QLineSeries(*new QSplineSeriesPrivate(this),parent) | |
73 | { |
|
73 | { | |
74 | Q_D(QSplineSeries); |
|
74 | Q_D(QSplineSeries); | |
75 | QObject::connect(this,SIGNAL(pointAdded(int)), d, SLOT(updateControlPoints())); |
|
75 | QObject::connect(this,SIGNAL(pointAdded(int)), d, SLOT(updateControlPoints())); | |
76 | QObject::connect(this,SIGNAL(pointRemoved(int)), d, SLOT(updateControlPoints())); |
|
76 | QObject::connect(this,SIGNAL(pointRemoved(int)), d, SLOT(updateControlPoints())); | |
77 | QObject::connect(this,SIGNAL(pointReplaced(int)), d, SLOT(updateControlPoints())); |
|
77 | QObject::connect(this,SIGNAL(pointReplaced(int)), d, SLOT(updateControlPoints())); | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | Destroys the object. |
|
81 | Destroys the object. | |
82 | */ |
|
82 | */ | |
83 | QSplineSeries::~QSplineSeries() |
|
83 | QSplineSeries::~QSplineSeries() | |
84 | { |
|
84 | { | |
85 | Q_D(QSplineSeries); |
|
85 | Q_D(QSplineSeries); | |
86 | if(d->m_dataset){ |
|
86 | if(d->m_dataset){ | |
87 | d->m_dataset->removeSeries(this); |
|
87 | d->m_dataset->removeSeries(this); | |
88 | } |
|
88 | } | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | QAbstractSeries::SeriesType QSplineSeries::type() const |
|
91 | QAbstractSeries::SeriesType QSplineSeries::type() const | |
92 | { |
|
92 | { | |
93 | return QAbstractSeries::SeriesTypeSpline; |
|
93 | return QAbstractSeries::SeriesTypeSpline; | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
96 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
97 |
|
97 | |||
98 | QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries* q):QLineSeriesPrivate(q) |
|
98 | QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries* q):QLineSeriesPrivate(q) | |
99 | { |
|
99 | { | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | /*! |
|
102 | /*! | |
103 | Calculates control points which are needed by QPainterPath.cubicTo function to draw the cubic Bezier cureve between two points. |
|
103 | Calculates control points which are needed by QPainterPath.cubicTo function to draw the cubic Bezier cureve between two points. | |
104 | */ |
|
104 | */ | |
105 | void QSplineSeriesPrivate::calculateControlPoints() |
|
105 | void QSplineSeriesPrivate::calculateControlPoints() | |
106 | { |
|
106 | { | |
107 | Q_Q(QSplineSeries); |
|
107 | Q_Q(QSplineSeries); | |
108 |
|
108 | |||
109 | const QList<QPointF>& points = q->points(); |
|
109 | const QList<QPointF>& points = q->points(); | |
110 |
|
110 | |||
111 | int n = points.count() - 1; |
|
111 | int n = points.count() - 1; | |
112 |
|
112 | |||
113 | if (n == 1) |
|
113 | if (n == 1) | |
114 | { |
|
114 | { | |
115 | //for n==1 |
|
115 | //for n==1 | |
116 | m_controlPoints[0].setX((2 * points[0].x() + points[1].x()) / 3); |
|
116 | m_controlPoints[0].setX((2 * points[0].x() + points[1].x()) / 3); | |
117 | m_controlPoints[0].setY((2 * points[0].y() + points[1].y()) / 3); |
|
117 | m_controlPoints[0].setY((2 * points[0].y() + points[1].y()) / 3); | |
118 | m_controlPoints[1].setX(2 * m_controlPoints[0].x() - points[0].x()); |
|
118 | m_controlPoints[1].setX(2 * m_controlPoints[0].x() - points[0].x()); | |
119 | m_controlPoints[1].setY(2 * m_controlPoints[0].y() - points[0].y()); |
|
119 | m_controlPoints[1].setY(2 * m_controlPoints[0].y() - points[0].y()); | |
120 | return; |
|
120 | return; | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | // Calculate first Bezier control points |
|
123 | // Calculate first Bezier control points | |
124 | // Set of equations for P0 to Pn points. |
|
124 | // Set of equations for P0 to Pn points. | |
125 | // |
|
125 | // | |
126 | // | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 | |
|
126 | // | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 | | |
127 | // | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 | |
|
127 | // | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 | | |
128 | // | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 | |
|
128 | // | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 | | |
129 | // | . . . . . . . . . . . . | | ... | | ... | |
|
129 | // | . . . . . . . . . . . . | | ... | | ... | | |
130 | // | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi | |
|
130 | // | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi | | |
131 | // | . . . . . . . . . . . . | | ... | | ... | |
|
131 | // | . . . . . . . . . . . . | | ... | | ... | | |
132 | // | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) | |
|
132 | // | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) | | |
133 | // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn | |
|
133 | // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn | | |
134 | // |
|
134 | // | |
135 | QVector<qreal> vector; |
|
135 | QVector<qreal> vector; | |
136 | vector.resize(n); |
|
136 | vector.resize(n); | |
137 |
|
137 | |||
138 | vector[0] = points[0].x() + 2 * points[1].x(); |
|
138 | vector[0] = points[0].x() + 2 * points[1].x(); | |
139 |
|
139 | |||
140 |
|
140 | |||
141 | for (int i = 1; i < n - 1; ++i){ |
|
141 | for (int i = 1; i < n - 1; ++i){ | |
142 | vector[i] = 4 * points[i].x() + 2 * points[i + 1].x(); |
|
142 | vector[i] = 4 * points[i].x() + 2 * points[i + 1].x(); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | vector[n - 1] = (8 * points[n-1].x() + points[n].x()) / 2.0; |
|
145 | vector[n - 1] = (8 * points[n-1].x() + points[n].x()) / 2.0; | |
146 |
|
146 | |||
147 | QVector<qreal> xControl = firstControlPoints(vector); |
|
147 | QVector<qreal> xControl = firstControlPoints(vector); | |
148 |
|
148 | |||
149 | vector[0] = points[0].y() + 2 * points[1].y(); |
|
149 | vector[0] = points[0].y() + 2 * points[1].y(); | |
150 |
|
150 | |||
151 | for (int i = 1; i < n - 1; ++i) { |
|
151 | for (int i = 1; i < n - 1; ++i) { | |
152 | vector[i] = 4 * points[i].y() + 2 * points[i + 1].y(); |
|
152 | vector[i] = 4 * points[i].y() + 2 * points[i + 1].y(); | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | vector[n - 1] = (8 * points[n-1].y() + points[n].y()) / 2.0; |
|
155 | vector[n - 1] = (8 * points[n-1].y() + points[n].y()) / 2.0; | |
156 |
|
156 | |||
157 | QVector<qreal> yControl = firstControlPoints(vector); |
|
157 | QVector<qreal> yControl = firstControlPoints(vector); | |
158 |
|
158 | |||
159 | for (int i = 0,j =0; i < n; ++i, ++j) { |
|
159 | for (int i = 0,j =0; i < n; ++i, ++j) { | |
160 |
|
160 | |||
161 | m_controlPoints[j].setX(xControl[i]); |
|
161 | m_controlPoints[j].setX(xControl[i]); | |
162 | m_controlPoints[j].setY(yControl[i]); |
|
162 | m_controlPoints[j].setY(yControl[i]); | |
163 |
|
163 | |||
164 | j++; |
|
164 | j++; | |
165 |
|
165 | |||
166 | if (i < n - 1){ |
|
166 | if (i < n - 1){ | |
167 | m_controlPoints[j].setX(2 * points[i+1].x() - xControl[i + 1]); |
|
167 | m_controlPoints[j].setX(2 * points[i+1].x() - xControl[i + 1]); | |
168 | m_controlPoints[j].setY(2 * points[i+1].y() - yControl[i + 1]); |
|
168 | m_controlPoints[j].setY(2 * points[i+1].y() - yControl[i + 1]); | |
169 | }else{ |
|
169 | }else{ | |
170 | m_controlPoints[j].setX((points[n].x() + xControl[n - 1]) / 2); |
|
170 | m_controlPoints[j].setX((points[n].x() + xControl[n - 1]) / 2); | |
171 | m_controlPoints[j].setY((points[n].y() + yControl[n - 1]) / 2); |
|
171 | m_controlPoints[j].setY((points[n].y() + yControl[n - 1]) / 2); | |
172 | } |
|
172 | } | |
173 | } |
|
173 | } | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | QVector<qreal> QSplineSeriesPrivate::firstControlPoints(const QVector<qreal>& vector) |
|
176 | QVector<qreal> QSplineSeriesPrivate::firstControlPoints(const QVector<qreal>& vector) | |
177 | { |
|
177 | { | |
178 | QVector<qreal> result; |
|
178 | QVector<qreal> result; | |
179 |
|
179 | |||
180 | int count = vector.count(); |
|
180 | int count = vector.count(); | |
181 | result.resize(count); |
|
181 | result.resize(count); | |
182 | result[0] = vector[0] / 2.0; |
|
182 | result[0] = vector[0] / 2.0; | |
183 |
|
183 | |||
184 | QVector<qreal> temp; |
|
184 | QVector<qreal> temp; | |
185 | temp.resize(count); |
|
185 | temp.resize(count); | |
186 | temp[0] = 0; |
|
186 | temp[0] = 0; | |
187 |
|
187 | |||
188 | qreal b = 2.0; |
|
188 | qreal b = 2.0; | |
189 |
|
189 | |||
190 | for (int i = 1; i < count; i++) { |
|
190 | for (int i = 1; i < count; i++) { | |
191 | temp[i] = 1 / b; |
|
191 | temp[i] = 1 / b; | |
192 | b = (i < count - 1 ? 4.0 : 3.5) - temp[i]; |
|
192 | b = (i < count - 1 ? 4.0 : 3.5) - temp[i]; | |
193 | result[i]=(vector[i] - result[i - 1]) / b; |
|
193 | result[i]=(vector[i] - result[i - 1]) / b; | |
194 | } |
|
194 | } | |
195 | for (int i = 1; i < count; i++) |
|
195 | for (int i = 1; i < count; i++) | |
196 | result[count - i - 1] -= temp[count - i] * result[count - i]; |
|
196 | result[count - i - 1] -= temp[count - i] * result[count - i]; | |
197 |
|
197 | |||
198 | return result; |
|
198 | return result; | |
199 | } |
|
199 | } | |
200 |
|
200 | |||
201 | QPointF QSplineSeriesPrivate::controlPoint(int index) const |
|
201 | QPointF QSplineSeriesPrivate::controlPoint(int index) const | |
202 | { |
|
202 | { | |
203 | // Q_D(const QSplineSeries); |
|
|||
204 | // return d->m_controlPoints[index]; |
|
|||
205 | return m_controlPoints[index]; |
|
203 | return m_controlPoints[index]; | |
206 | } |
|
204 | } | |
207 |
|
205 | |||
208 | /*! |
|
206 | /*! | |
209 | Updates the control points, besed on currently avaiable knots. |
|
207 | Updates the control points, besed on currently avaiable knots. | |
210 | */ |
|
208 | */ | |
211 | void QSplineSeriesPrivate::updateControlPoints() |
|
209 | void QSplineSeriesPrivate::updateControlPoints() | |
212 | { |
|
210 | { | |
213 | Q_Q(QSplineSeries); |
|
211 | Q_Q(QSplineSeries); | |
214 | if (q->count() > 1) { |
|
212 | if (q->count() > 1) { | |
215 | m_controlPoints.resize(2*q->count()-2); |
|
213 | m_controlPoints.resize(2*q->count()-2); | |
216 | calculateControlPoints(); |
|
214 | calculateControlPoints(); | |
217 | } |
|
215 | } | |
218 | } |
|
216 | } | |
219 |
|
217 | |||
220 | ChartElement* QSplineSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
218 | ChartElement* QSplineSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
221 | { |
|
219 | { | |
222 | Q_Q(QSplineSeries); |
|
220 | Q_Q(QSplineSeries); | |
223 | SplineChartItem* spline = new SplineChartItem(q,presenter); |
|
221 | SplineChartItem* spline = new SplineChartItem(q,presenter); | |
224 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
222 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
225 | spline->setAnimation(new SplineAnimation(spline)); |
|
223 | spline->setAnimation(new SplineAnimation(spline)); | |
226 | } |
|
224 | } | |
227 |
|
225 | |||
228 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
226 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
229 | return spline; |
|
227 | return spline; | |
230 | } |
|
228 | } | |
231 |
|
229 | |||
232 | #include "moc_qsplineseries.cpp" |
|
230 | #include "moc_qsplineseries.cpp" | |
233 | #include "moc_qsplineseries_p.cpp" |
|
231 | #include "moc_qsplineseries_p.cpp" | |
234 |
|
232 | |||
235 | QTCOMMERCIALCHART_END_NAMESPACE |
|
233 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,172 +1,171 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "splinechartitem_p.h" |
|
21 | #include "splinechartitem_p.h" | |
22 | #include "qsplineseries_p.h" |
|
22 | #include "qsplineseries_p.h" | |
23 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
24 | #include "splineanimation_p.h" |
|
24 | #include "splineanimation_p.h" | |
25 | #include <QPainter> |
|
25 | #include <QPainter> | |
26 | #include <QGraphicsSceneMouseEvent> |
|
26 | #include <QGraphicsSceneMouseEvent> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | SplineChartItem::SplineChartItem(QSplineSeries *series, ChartPresenter *presenter) : |
|
30 | SplineChartItem::SplineChartItem(QSplineSeries *series, ChartPresenter *presenter) : | |
31 | XYChart(series, presenter), |
|
31 | XYChart(series, presenter), | |
32 | QGraphicsItem(presenter ? presenter->rootItem() : 0), |
|
32 | QGraphicsItem(presenter ? presenter->rootItem() : 0), | |
33 | m_series(series), |
|
33 | m_series(series), | |
34 | m_pointsVisible(false), |
|
34 | m_pointsVisible(false), | |
35 | m_animation(0) |
|
35 | m_animation(0) | |
36 | { |
|
36 | { | |
37 | setZValue(ChartPresenter::SplineChartZValue); |
|
37 | setZValue(ChartPresenter::SplineChartZValue); | |
38 | QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); |
|
38 | QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); | |
39 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); |
|
39 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); | |
40 | handleUpdated(); |
|
40 | handleUpdated(); | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | QRectF SplineChartItem::boundingRect() const |
|
43 | QRectF SplineChartItem::boundingRect() const | |
44 | { |
|
44 | { | |
45 | return m_rect; |
|
45 | return m_rect; | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | QPainterPath SplineChartItem::shape() const |
|
48 | QPainterPath SplineChartItem::shape() const | |
49 | { |
|
49 | { | |
50 | return m_path; |
|
50 | return m_path; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | void SplineChartItem::setAnimation(SplineAnimation* animation) |
|
53 | void SplineChartItem::setAnimation(SplineAnimation* animation) | |
54 | { |
|
54 | { | |
55 | m_animation=animation; |
|
55 | m_animation=animation; | |
56 | XYChart::setAnimation(animation); |
|
56 | XYChart::setAnimation(animation); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | ChartAnimation* SplineChartItem::animation() const |
|
59 | ChartAnimation* SplineChartItem::animation() const | |
60 | { |
|
60 | { | |
61 | return m_animation; |
|
61 | return m_animation; | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void SplineChartItem::setControlGeometryPoints(QVector<QPointF>& points) |
|
64 | void SplineChartItem::setControlGeometryPoints(QVector<QPointF>& points) | |
65 | { |
|
65 | { | |
66 | m_controlPoints=points; |
|
66 | m_controlPoints=points; | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | QVector<QPointF> SplineChartItem::controlGeometryPoints() const |
|
69 | QVector<QPointF> SplineChartItem::controlGeometryPoints() const | |
70 | { |
|
70 | { | |
71 | return m_controlPoints; |
|
71 | return m_controlPoints; | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | void SplineChartItem::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index) |
|
74 | void SplineChartItem::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index) | |
75 | { |
|
75 | { | |
76 | QVector<QPointF> controlPoints; |
|
76 | QVector<QPointF> controlPoints; | |
77 |
|
77 | |||
78 | if(newPoints.count()>=2) { |
|
78 | if(newPoints.count()>=2) { | |
79 | controlPoints.resize(newPoints.count()*2-2); |
|
79 | controlPoints.resize(newPoints.count()*2-2); | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | for (int i = 0; i < newPoints.size() - 1; i++) { |
|
82 | for (int i = 0; i < newPoints.size() - 1; i++) { | |
83 | controlPoints[2*i] = calculateGeometryControlPoint(2 * i); |
|
83 | controlPoints[2*i] = calculateGeometryControlPoint(2 * i); | |
84 | controlPoints[2 * i + 1] = calculateGeometryControlPoint(2 * i + 1); |
|
84 | controlPoints[2 * i + 1] = calculateGeometryControlPoint(2 * i + 1); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 |
if (m_animation) |
|
87 | if (m_animation) | |
88 | m_animation->setup(oldPoints,newPoints,m_controlPoints,controlPoints,index); |
|
88 | m_animation->setup(oldPoints, newPoints, m_controlPoints, controlPoints, index); | |
89 | } |
|
|||
90 |
|
89 | |||
91 |
|
|
90 | m_points = newPoints; | |
92 | setControlGeometryPoints(controlPoints); |
|
91 | m_controlPoints = controlPoints; | |
93 | setDirty(false); |
|
92 | setDirty(false); | |
94 |
|
93 | |||
95 | if (m_animation) { |
|
94 | if (m_animation) { | |
96 | presenter()->startAnimation(m_animation); |
|
95 | presenter()->startAnimation(m_animation); | |
97 | } else { |
|
96 | } else { | |
98 | updateGeometry(); |
|
97 | updateGeometry(); | |
99 | } |
|
98 | } | |
100 | } |
|
99 | } | |
101 |
|
100 | |||
102 | QPointF SplineChartItem::calculateGeometryControlPoint(int index) const |
|
101 | QPointF SplineChartItem::calculateGeometryControlPoint(int index) const | |
103 | { |
|
102 | { | |
104 | return XYChart::calculateGeometryPoint(m_series->d_func()->controlPoint(index)); |
|
103 | return XYChart::calculateGeometryPoint(m_series->d_func()->controlPoint(index)); | |
105 | } |
|
104 | } | |
106 |
|
105 | |||
107 | void SplineChartItem::updateGeometry() |
|
106 | void SplineChartItem::updateGeometry() | |
108 | { |
|
107 | { | |
109 |
const QVector<QPointF> &points = |
|
108 | const QVector<QPointF> &points = m_points; | |
110 |
const QVector<QPointF> &controlPoints = control |
|
109 | const QVector<QPointF> &controlPoints = m_controlPoints; | |
111 |
|
110 | |||
112 | if ((points.size()<2) || (controlPoints.size()<2)) { |
|
111 | if ((points.size()<2) || (controlPoints.size()<2)) { | |
113 | prepareGeometryChange(); |
|
112 | prepareGeometryChange(); | |
114 | m_path = QPainterPath(); |
|
113 | m_path = QPainterPath(); | |
115 | m_rect = QRect(); |
|
114 | m_rect = QRect(); | |
116 | return; |
|
115 | return; | |
117 | } |
|
116 | } | |
118 |
|
117 | |||
119 | Q_ASSERT(points.count()*2-2 == controlPoints.count()); |
|
118 | Q_ASSERT(points.count()*2-2 == controlPoints.count()); | |
120 |
|
119 | |||
121 | QPainterPath splinePath(points.at(0)); |
|
120 | QPainterPath splinePath(points.at(0)); | |
122 |
|
121 | |||
123 | for (int i = 0; i < points.size() - 1; i++) { |
|
122 | for (int i = 0; i < points.size() - 1; i++) { | |
124 | const QPointF& point = points.at(i + 1); |
|
123 | const QPointF& point = points.at(i + 1); | |
125 | splinePath.cubicTo(controlPoints[2*i],controlPoints[2 * i + 1],point); |
|
124 | splinePath.cubicTo(controlPoints[2*i],controlPoints[2 * i + 1],point); | |
126 | } |
|
125 | } | |
127 |
|
126 | |||
128 | prepareGeometryChange(); |
|
127 | prepareGeometryChange(); | |
129 | m_path = splinePath; |
|
128 | m_path = splinePath; | |
130 | m_rect = splinePath.boundingRect(); |
|
129 | m_rect = splinePath.boundingRect(); | |
131 | setPos(origin()); |
|
130 | setPos(origin()); | |
132 | } |
|
131 | } | |
133 |
|
132 | |||
134 | //handlers |
|
133 | //handlers | |
135 |
|
134 | |||
136 | void SplineChartItem::handleUpdated() |
|
135 | void SplineChartItem::handleUpdated() | |
137 | { |
|
136 | { | |
138 | setVisible(m_series->isVisible()); |
|
137 | setVisible(m_series->isVisible()); | |
139 | m_pointsVisible = m_series->pointsVisible(); |
|
138 | m_pointsVisible = m_series->pointsVisible(); | |
140 | m_linePen = m_series->pen(); |
|
139 | m_linePen = m_series->pen(); | |
141 | m_pointPen = m_series->pen(); |
|
140 | m_pointPen = m_series->pen(); | |
142 | m_pointPen.setWidthF(2*m_pointPen.width()); |
|
141 | m_pointPen.setWidthF(2*m_pointPen.width()); | |
143 | update(); |
|
142 | update(); | |
144 | } |
|
143 | } | |
145 |
|
144 | |||
146 | //painter |
|
145 | //painter | |
147 |
|
146 | |||
148 | void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
147 | void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
149 | { |
|
148 | { | |
150 | Q_UNUSED(widget) |
|
149 | Q_UNUSED(widget) | |
151 | Q_UNUSED(option) |
|
150 | Q_UNUSED(option) | |
152 |
|
151 | |||
153 | painter->save(); |
|
152 | painter->save(); | |
154 | painter->setClipRect(clipRect()); |
|
153 | painter->setClipRect(clipRect()); | |
155 | painter->setPen(m_linePen); |
|
154 | painter->setPen(m_linePen); | |
156 | painter->drawPath(m_path); |
|
155 | painter->drawPath(m_path); | |
157 | if (m_pointsVisible) { |
|
156 | if (m_pointsVisible) { | |
158 | painter->setPen(m_pointPen); |
|
157 | painter->setPen(m_pointPen); | |
159 | painter->drawPoints(geometryPoints()); |
|
158 | painter->drawPoints(geometryPoints()); | |
160 | } |
|
159 | } | |
161 | painter->restore(); |
|
160 | painter->restore(); | |
162 | } |
|
161 | } | |
163 |
|
162 | |||
164 | void SplineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
163 | void SplineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
165 | { |
|
164 | { | |
166 | emit XYChart::clicked(calculateDomainPoint(event->pos())); |
|
165 | emit XYChart::clicked(calculateDomainPoint(event->pos())); | |
167 | QGraphicsItem::mousePressEvent(event); |
|
166 | QGraphicsItem::mousePressEvent(event); | |
168 | } |
|
167 | } | |
169 |
|
168 | |||
170 | #include "moc_splinechartitem_p.cpp" |
|
169 | #include "moc_splinechartitem_p.cpp" | |
171 |
|
170 | |||
172 | QTCOMMERCIALCHART_END_NAMESPACE |
|
171 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,449 +1,448 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qxyseries.h" |
|
21 | #include "qxyseries.h" | |
22 | #include "qxyseries_p.h" |
|
22 | #include "qxyseries_p.h" | |
23 | #include "domain_p.h" |
|
23 | #include "domain_p.h" | |
24 | #include "legendmarker_p.h" |
|
24 | #include "legendmarker_p.h" | |
25 | #include "qvaluesaxis.h" |
|
25 | #include "qvaluesaxis.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | /*! |
|
29 | /*! | |
30 | \class QXYSeries |
|
30 | \class QXYSeries | |
31 | \brief The QXYSeries class is a base class for line, spline and scatter series. |
|
31 | \brief The QXYSeries class is a base class for line, spline and scatter series. | |
32 | */ |
|
32 | */ | |
33 | /*! |
|
33 | /*! | |
34 | \qmlclass XYSeries |
|
34 | \qmlclass XYSeries | |
35 | \inherits AbstractSeries |
|
35 | \inherits AbstractSeries | |
36 | The XYSeries class is a base class for line, spline and scatter series. |
|
36 | The XYSeries class is a base class for line, spline and scatter series. | |
37 |
|
37 | |||
38 | The class cannot be instantiated directly. |
|
38 | The class cannot be instantiated directly. | |
39 | */ |
|
39 | */ | |
40 |
|
40 | |||
41 | /*! |
|
41 | /*! | |
42 | \property QXYSeries::pointsVisible |
|
42 | \property QXYSeries::pointsVisible | |
43 | Controls if the data points are visible and should be drawn. |
|
43 | Controls if the data points are visible and should be drawn. | |
44 | */ |
|
44 | */ | |
45 | /*! |
|
45 | /*! | |
46 | \qmlproperty bool XYSeries::pointsVisible |
|
46 | \qmlproperty bool XYSeries::pointsVisible | |
47 | Controls if the data points are visible and should be drawn. |
|
47 | Controls if the data points are visible and should be drawn. | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | \fn QPen QXYSeries::pen() const |
|
51 | \fn QPen QXYSeries::pen() const | |
52 | \brief Returns pen used to draw points for series. |
|
52 | \brief Returns pen used to draw points for series. | |
53 | \sa setPen() |
|
53 | \sa setPen() | |
54 | */ |
|
54 | */ | |
55 |
|
55 | |||
56 | /*! |
|
56 | /*! | |
57 | \fn QBrush QXYSeries::brush() const |
|
57 | \fn QBrush QXYSeries::brush() const | |
58 | \brief Returns brush used to draw points for series. |
|
58 | \brief Returns brush used to draw points for series. | |
59 | \sa setBrush() |
|
59 | \sa setBrush() | |
60 | */ |
|
60 | */ | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | \property QXYSeries::color |
|
63 | \property QXYSeries::color | |
64 | The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and |
|
64 | The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and | |
65 | fill (brush) color in case of QScatterSeries or QAreaSeries. |
|
65 | fill (brush) color in case of QScatterSeries or QAreaSeries. | |
66 | \sa QXYSeries::pen(), QXYSeries::brush() |
|
66 | \sa QXYSeries::pen(), QXYSeries::brush() | |
67 | */ |
|
67 | */ | |
68 | /*! |
|
68 | /*! | |
69 | \qmlproperty color XYSeries::color |
|
69 | \qmlproperty color XYSeries::color | |
70 | The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and |
|
70 | The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and | |
71 | fill (brush) color in case of ScatterSeries or AreaSeries. |
|
71 | fill (brush) color in case of ScatterSeries or AreaSeries. | |
72 | */ |
|
72 | */ | |
73 |
|
73 | |||
74 | /*! |
|
74 | /*! | |
75 | \fn void QXYSeries::clicked(const QPointF& point) |
|
75 | \fn void QXYSeries::clicked(const QPointF& point) | |
76 | \brief Signal is emitted when user clicks the \a point on chart. |
|
76 | \brief Signal is emitted when user clicks the \a point on chart. | |
77 | */ |
|
77 | */ | |
78 | /*! |
|
78 | /*! | |
79 | \qmlsignal XYSeries::onClicked(QPointF point) |
|
79 | \qmlsignal XYSeries::onClicked(QPointF point) | |
80 | Signal is emitted when user clicks the \a point on chart. For example: |
|
80 | Signal is emitted when user clicks the \a point on chart. For example: | |
81 | \code |
|
81 | \code | |
82 | LineSeries { |
|
82 | LineSeries { | |
83 | XYPoint { x: 0; y: 0 } |
|
83 | XYPoint { x: 0; y: 0 } | |
84 | XYPoint { x: 1.1; y: 2.1 } |
|
84 | XYPoint { x: 1.1; y: 2.1 } | |
85 | onClicked: console.log("onClicked: " + point.x + ", " + point.y); |
|
85 | onClicked: console.log("onClicked: " + point.x + ", " + point.y); | |
86 | } |
|
86 | } | |
87 | \endcode |
|
87 | \endcode | |
88 | */ |
|
88 | */ | |
89 |
|
89 | |||
90 | /*! |
|
90 | /*! | |
91 | \fn void QXYSeries::pointReplaced(int index) |
|
91 | \fn void QXYSeries::pointReplaced(int index) | |
92 | Signal is emitted when a point has been replaced at \a index. |
|
92 | Signal is emitted when a point has been replaced at \a index. | |
93 | \sa replace() |
|
93 | \sa replace() | |
94 | */ |
|
94 | */ | |
95 | /*! |
|
95 | /*! | |
96 | \qmlsignal XYSeries::onPointReplaced(int index) |
|
96 | \qmlsignal XYSeries::onPointReplaced(int index) | |
97 | Signal is emitted when a point has been replaced at \a index. |
|
97 | Signal is emitted when a point has been replaced at \a index. | |
98 | */ |
|
98 | */ | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | \fn void QXYSeries::pointAdded(int index) |
|
101 | \fn void QXYSeries::pointAdded(int index) | |
102 | Signal is emitted when a point has been added at \a index. |
|
102 | Signal is emitted when a point has been added at \a index. | |
103 | \sa append(), insert() |
|
103 | \sa append(), insert() | |
104 | */ |
|
104 | */ | |
105 | /*! |
|
105 | /*! | |
106 | \qmlsignal XYSeries::onPointAdded(int index) |
|
106 | \qmlsignal XYSeries::onPointAdded(int index) | |
107 | Signal is emitted when a point has been added at \a index. |
|
107 | Signal is emitted when a point has been added at \a index. | |
108 | */ |
|
108 | */ | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | \fn void QXYSeries::pointRemoved(int index) |
|
111 | \fn void QXYSeries::pointRemoved(int index) | |
112 | Signal is emitted when a point has been removed from \a index. |
|
112 | Signal is emitted when a point has been removed from \a index. | |
113 | \sa remove() |
|
113 | \sa remove() | |
114 | */ |
|
114 | */ | |
115 | /*! |
|
115 | /*! | |
116 | \qmlsignal XYSeries::onPointRemoved(int index) |
|
116 | \qmlsignal XYSeries::onPointRemoved(int index) | |
117 | Signal is emitted when a point has been removed from \a index. |
|
117 | Signal is emitted when a point has been removed from \a index. | |
118 | */ |
|
118 | */ | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | \fn void QXYSeries::colorChanged(QColor color) |
|
121 | \fn void QXYSeries::colorChanged(QColor color) | |
122 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
122 | \brief Signal is emitted when the line (pen) color has changed to \a color. | |
123 | */ |
|
123 | */ | |
124 | /*! |
|
124 | /*! | |
125 | \qmlsignal XYSeries::onColorChanged(color color) |
|
125 | \qmlsignal XYSeries::onColorChanged(color color) | |
126 | Signal is emitted when the line (pen) color has changed to \a color. |
|
126 | Signal is emitted when the line (pen) color has changed to \a color. | |
127 | */ |
|
127 | */ | |
128 |
|
128 | |||
129 | /*! |
|
129 | /*! | |
130 | \fn void QXYSeriesPrivate::updated() |
|
130 | \fn void QXYSeriesPrivate::updated() | |
131 | \brief \internal |
|
131 | \brief \internal | |
132 | */ |
|
132 | */ | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | \qmlmethod XYSeries::append(real x, real y) |
|
135 | \qmlmethod XYSeries::append(real x, real y) | |
136 | Append point (\a x, \a y) to the series |
|
136 | Append point (\a x, \a y) to the series | |
137 | */ |
|
137 | */ | |
138 |
|
138 | |||
139 | /*! |
|
139 | /*! | |
140 | \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY) |
|
140 | \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY) | |
141 | Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not |
|
141 | Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not | |
142 | exist. |
|
142 | exist. | |
143 | */ |
|
143 | */ | |
144 |
|
144 | |||
145 | /*! |
|
145 | /*! | |
146 | \qmlmethod XYSeries::remove(real x, real y) |
|
146 | \qmlmethod XYSeries::remove(real x, real y) | |
147 | Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist. |
|
147 | Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist. | |
148 | */ |
|
148 | */ | |
149 |
|
149 | |||
150 | /*! |
|
150 | /*! | |
151 | \qmlmethod XYSeries::insert(int index, real x, real y) |
|
151 | \qmlmethod XYSeries::insert(int index, real x, real y) | |
152 | Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of |
|
152 | Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of | |
153 | points. If index is the same as or bigger than count, the point is appended to the list of points. |
|
153 | points. If index is the same as or bigger than count, the point is appended to the list of points. | |
154 | */ |
|
154 | */ | |
155 |
|
155 | |||
156 | /*! |
|
156 | /*! | |
157 | \qmlmethod QPointF XYSeries::at(int index) |
|
157 | \qmlmethod QPointF XYSeries::at(int index) | |
158 | Returns point at \a index. Returns (0, 0) if the index is not valid. |
|
158 | Returns point at \a index. Returns (0, 0) if the index is not valid. | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | \internal |
|
162 | \internal | |
163 |
|
163 | |||
164 | Constructs empty series object which is a child of \a parent. |
|
164 | Constructs empty series object which is a child of \a parent. | |
165 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
165 | When series object is added to QChartView or QChart instance ownerships is transferred. | |
166 | */ |
|
166 | */ | |
167 | QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent) |
|
167 | QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent) | |
168 | { |
|
168 | { | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | /*! |
|
171 | /*! | |
172 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
172 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
173 | and are deleted when mentioned object are destroyed. |
|
173 | and are deleted when mentioned object are destroyed. | |
174 | */ |
|
174 | */ | |
175 | QXYSeries::~QXYSeries() |
|
175 | QXYSeries::~QXYSeries() | |
176 | { |
|
176 | { | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | /*! |
|
179 | /*! | |
180 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
180 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. | |
181 | */ |
|
181 | */ | |
182 | void QXYSeries::append(qreal x,qreal y) |
|
182 | void QXYSeries::append(qreal x,qreal y) | |
183 | { |
|
183 | { | |
184 | append(QPointF(x,y)); |
|
184 | append(QPointF(x,y)); | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | /*! |
|
187 | /*! | |
188 | This is an overloaded function. |
|
188 | This is an overloaded function. | |
189 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
189 | Adds data \a point to the series. Points are connected with lines on the chart. | |
190 | */ |
|
190 | */ | |
191 | void QXYSeries::append(const QPointF &point) |
|
191 | void QXYSeries::append(const QPointF &point) | |
192 | { |
|
192 | { | |
193 | Q_D(QXYSeries); |
|
193 | Q_D(QXYSeries); | |
194 | d->m_points<<point; |
|
194 | d->m_points<<point; | |
195 | // emit d->pointAdded(d->m_points.count()-1); |
|
195 | // emit d->pointAdded(d->m_points.count()-1); | |
196 | emit pointAdded(d->m_points.count()-1); |
|
196 | emit pointAdded(d->m_points.count()-1); | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | /*! |
|
199 | /*! | |
200 | This is an overloaded function. |
|
200 | This is an overloaded function. | |
201 | Adds list of data \a points to the series. Points are connected with lines on the chart. |
|
201 | Adds list of data \a points to the series. Points are connected with lines on the chart. | |
202 | */ |
|
202 | */ | |
203 | void QXYSeries::append(const QList<QPointF> &points) |
|
203 | void QXYSeries::append(const QList<QPointF> &points) | |
204 | { |
|
204 | { | |
205 | foreach(const QPointF& point , points) { |
|
205 | foreach(const QPointF& point , points) { | |
206 | append(point); |
|
206 | append(point); | |
207 | } |
|
207 | } | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | /*! |
|
210 | /*! | |
211 | Replaces data point \a oldX \a oldY with data point \a newX \a newY. |
|
211 | Replaces data point \a oldX \a oldY with data point \a newX \a newY. | |
212 | */ |
|
212 | */ | |
213 | void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY) |
|
213 | void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY) | |
214 | { |
|
214 | { | |
215 | replace(QPointF(oldX,oldY),QPointF(newX,newY)); |
|
215 | replace(QPointF(oldX,oldY),QPointF(newX,newY)); | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | /*! |
|
218 | /*! | |
219 | Replaces \a oldPoint with \a newPoint. |
|
219 | Replaces \a oldPoint with \a newPoint. | |
220 | */ |
|
220 | */ | |
221 | void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint) |
|
221 | void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint) | |
222 | { |
|
222 | { | |
223 | Q_D(QXYSeries); |
|
223 | Q_D(QXYSeries); | |
224 | int index = d->m_points.indexOf(oldPoint); |
|
224 | int index = d->m_points.indexOf(oldPoint); | |
225 | if(index==-1) return; |
|
225 | if(index==-1) return; | |
226 | d->m_points[index] = newPoint; |
|
226 | d->m_points[index] = newPoint; | |
227 | // emit d->pointReplaced(index); |
|
|||
228 | emit pointReplaced(index); |
|
227 | emit pointReplaced(index); | |
229 | } |
|
228 | } | |
230 |
|
229 | |||
231 | /*! |
|
230 | /*! | |
232 | Removes current \a x and \a y value. |
|
231 | Removes current \a x and \a y value. | |
233 | */ |
|
232 | */ | |
234 | void QXYSeries::remove(qreal x,qreal y) |
|
233 | void QXYSeries::remove(qreal x,qreal y) | |
235 | { |
|
234 | { | |
236 | remove(QPointF(x,y)); |
|
235 | remove(QPointF(x,y)); | |
237 | } |
|
236 | } | |
238 |
|
237 | |||
239 | /*! |
|
238 | /*! | |
240 | Removes current \a point x value. |
|
239 | Removes current \a point x value. | |
241 |
|
240 | |||
242 | Note: point y value is ignored. |
|
241 | Note: point y value is ignored. | |
243 | */ |
|
242 | */ | |
244 | void QXYSeries::remove(const QPointF &point) |
|
243 | void QXYSeries::remove(const QPointF &point) | |
245 | { |
|
244 | { | |
246 | Q_D(QXYSeries); |
|
245 | Q_D(QXYSeries); | |
247 | int index = d->m_points.indexOf(point); |
|
246 | int index = d->m_points.indexOf(point); | |
248 | if(index==-1) return; |
|
247 | if(index==-1) return; | |
249 | d->m_points.remove(index); |
|
248 | d->m_points.remove(index); | |
250 | // emit d->pointRemoved(index); |
|
249 | // emit d->pointRemoved(index); | |
251 | emit pointRemoved(index); |
|
250 | emit pointRemoved(index); | |
252 | } |
|
251 | } | |
253 |
|
252 | |||
254 | /*! |
|
253 | /*! | |
255 | Inserts a \a point in the series at \a index position. |
|
254 | Inserts a \a point in the series at \a index position. | |
256 | */ |
|
255 | */ | |
257 | void QXYSeries::insert(int index, const QPointF &point) |
|
256 | void QXYSeries::insert(int index, const QPointF &point) | |
258 | { |
|
257 | { | |
259 | Q_D(QXYSeries); |
|
258 | Q_D(QXYSeries); | |
260 | d->m_points.insert(index, point); |
|
259 | d->m_points.insert(index, point); | |
261 | // emit d->pointAdded(index); |
|
260 | // emit d->pointAdded(index); | |
262 | emit pointAdded(index); |
|
261 | emit pointAdded(index); | |
263 | } |
|
262 | } | |
264 |
|
263 | |||
265 | /*! |
|
264 | /*! | |
266 | Removes all points from the series. |
|
265 | Removes all points from the series. | |
267 | */ |
|
266 | */ | |
268 | void QXYSeries::clear() |
|
267 | void QXYSeries::clear() | |
269 | { |
|
268 | { | |
270 | Q_D(QXYSeries); |
|
269 | Q_D(QXYSeries); | |
271 | for (int i = d->m_points.size() - 1; i >= 0; i--) |
|
270 | for (int i = d->m_points.size() - 1; i >= 0; i--) | |
272 | remove(d->m_points.at(i)); |
|
271 | remove(d->m_points.at(i)); | |
273 | } |
|
272 | } | |
274 |
|
273 | |||
275 | /*! |
|
274 | /*! | |
276 | Returns list of points in the series. |
|
275 | Returns list of points in the series. | |
277 | */ |
|
276 | */ | |
278 | QList<QPointF> QXYSeries::points() const |
|
277 | QList<QPointF> QXYSeries::points() const | |
279 | { |
|
278 | { | |
280 | Q_D(const QXYSeries); |
|
279 | Q_D(const QXYSeries); | |
281 | return d->m_points.toList(); |
|
280 | return d->m_points.toList(); | |
282 | } |
|
281 | } | |
283 |
|
282 | |||
284 | /*! |
|
283 | /*! | |
285 | Returns number of data points within series. |
|
284 | Returns number of data points within series. | |
286 | */ |
|
285 | */ | |
287 | int QXYSeries::count() const |
|
286 | int QXYSeries::count() const | |
288 | { |
|
287 | { | |
289 | Q_D(const QXYSeries); |
|
288 | Q_D(const QXYSeries); | |
290 | return d->m_points.count(); |
|
289 | return d->m_points.count(); | |
291 | } |
|
290 | } | |
292 |
|
291 | |||
293 |
|
292 | |||
294 | /*! |
|
293 | /*! | |
295 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
294 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the | |
296 | pen from chart theme is used. |
|
295 | pen from chart theme is used. | |
297 | \sa QChart::setTheme() |
|
296 | \sa QChart::setTheme() | |
298 | */ |
|
297 | */ | |
299 | void QXYSeries::setPen(const QPen &pen) |
|
298 | void QXYSeries::setPen(const QPen &pen) | |
300 | { |
|
299 | { | |
301 | Q_D(QXYSeries); |
|
300 | Q_D(QXYSeries); | |
302 | if (d->m_pen != pen) { |
|
301 | if (d->m_pen != pen) { | |
303 | bool emitColorChanged = d->m_pen.color() != pen.color(); |
|
302 | bool emitColorChanged = d->m_pen.color() != pen.color(); | |
304 | d->m_pen = pen; |
|
303 | d->m_pen = pen; | |
305 | emit d->updated(); |
|
304 | emit d->updated(); | |
306 | if (emitColorChanged) |
|
305 | if (emitColorChanged) | |
307 | emit colorChanged(pen.color()); |
|
306 | emit colorChanged(pen.color()); | |
308 | } |
|
307 | } | |
309 | } |
|
308 | } | |
310 |
|
309 | |||
311 | QPen QXYSeries::pen() const |
|
310 | QPen QXYSeries::pen() const | |
312 | { |
|
311 | { | |
313 | Q_D(const QXYSeries); |
|
312 | Q_D(const QXYSeries); | |
314 | return d->m_pen; |
|
313 | return d->m_pen; | |
315 | } |
|
314 | } | |
316 |
|
315 | |||
317 | /*! |
|
316 | /*! | |
318 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
317 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush | |
319 | from chart theme setting is used. |
|
318 | from chart theme setting is used. | |
320 | \sa QChart::setTheme() |
|
319 | \sa QChart::setTheme() | |
321 | */ |
|
320 | */ | |
322 | void QXYSeries::setBrush(const QBrush &brush) |
|
321 | void QXYSeries::setBrush(const QBrush &brush) | |
323 | { |
|
322 | { | |
324 | Q_D(QXYSeries); |
|
323 | Q_D(QXYSeries); | |
325 | if (d->m_brush!=brush) { |
|
324 | if (d->m_brush!=brush) { | |
326 | d->m_brush = brush; |
|
325 | d->m_brush = brush; | |
327 | emit d->updated(); |
|
326 | emit d->updated(); | |
328 | } |
|
327 | } | |
329 | } |
|
328 | } | |
330 |
|
329 | |||
331 | QBrush QXYSeries::brush() const |
|
330 | QBrush QXYSeries::brush() const | |
332 | { |
|
331 | { | |
333 | Q_D(const QXYSeries); |
|
332 | Q_D(const QXYSeries); | |
334 | return d->m_brush; |
|
333 | return d->m_brush; | |
335 | } |
|
334 | } | |
336 |
|
335 | |||
337 | void QXYSeries::setColor(const QColor &color) |
|
336 | void QXYSeries::setColor(const QColor &color) | |
338 | { |
|
337 | { | |
339 | QPen p = pen(); |
|
338 | QPen p = pen(); | |
340 | if (p.color() != color) { |
|
339 | if (p.color() != color) { | |
341 | p.setColor(color); |
|
340 | p.setColor(color); | |
342 | setPen(p); |
|
341 | setPen(p); | |
343 | } |
|
342 | } | |
344 | } |
|
343 | } | |
345 |
|
344 | |||
346 | QColor QXYSeries::color() const |
|
345 | QColor QXYSeries::color() const | |
347 | { |
|
346 | { | |
348 | return pen().color(); |
|
347 | return pen().color(); | |
349 | } |
|
348 | } | |
350 |
|
349 | |||
351 | void QXYSeries::setPointsVisible(bool visible) |
|
350 | void QXYSeries::setPointsVisible(bool visible) | |
352 | { |
|
351 | { | |
353 | Q_D(QXYSeries); |
|
352 | Q_D(QXYSeries); | |
354 | if (d->m_pointsVisible != visible){ |
|
353 | if (d->m_pointsVisible != visible){ | |
355 | d->m_pointsVisible = visible; |
|
354 | d->m_pointsVisible = visible; | |
356 | emit d->updated(); |
|
355 | emit d->updated(); | |
357 | } |
|
356 | } | |
358 | } |
|
357 | } | |
359 |
|
358 | |||
360 | bool QXYSeries::pointsVisible() const |
|
359 | bool QXYSeries::pointsVisible() const | |
361 | { |
|
360 | { | |
362 | Q_D(const QXYSeries); |
|
361 | Q_D(const QXYSeries); | |
363 | return d->m_pointsVisible; |
|
362 | return d->m_pointsVisible; | |
364 | } |
|
363 | } | |
365 |
|
364 | |||
366 |
|
365 | |||
367 | /*! |
|
366 | /*! | |
368 | Stream operator for adding a data \a point to the series. |
|
367 | Stream operator for adding a data \a point to the series. | |
369 | \sa append() |
|
368 | \sa append() | |
370 | */ |
|
369 | */ | |
371 | QXYSeries& QXYSeries::operator<< (const QPointF &point) |
|
370 | QXYSeries& QXYSeries::operator<< (const QPointF &point) | |
372 | { |
|
371 | { | |
373 | append(point); |
|
372 | append(point); | |
374 | return *this; |
|
373 | return *this; | |
375 | } |
|
374 | } | |
376 |
|
375 | |||
377 |
|
376 | |||
378 | /*! |
|
377 | /*! | |
379 | Stream operator for adding a list of \a points to the series. |
|
378 | Stream operator for adding a list of \a points to the series. | |
380 | \sa append() |
|
379 | \sa append() | |
381 | */ |
|
380 | */ | |
382 |
|
381 | |||
383 | QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points) |
|
382 | QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points) | |
384 | { |
|
383 | { | |
385 | append(points); |
|
384 | append(points); | |
386 | return *this; |
|
385 | return *this; | |
387 | } |
|
386 | } | |
388 |
|
387 | |||
389 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
388 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
390 |
|
389 | |||
391 |
|
390 | |||
392 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : |
|
391 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : | |
393 | QAbstractSeriesPrivate(q), |
|
392 | QAbstractSeriesPrivate(q), | |
394 | m_pointsVisible(false) |
|
393 | m_pointsVisible(false) | |
395 | { |
|
394 | { | |
396 | } |
|
395 | } | |
397 |
|
396 | |||
398 | void QXYSeriesPrivate::scaleDomain(Domain& domain) |
|
397 | void QXYSeriesPrivate::scaleDomain(Domain& domain) | |
399 | { |
|
398 | { | |
400 | qreal minX(0); |
|
399 | qreal minX(0); | |
401 | qreal minY(0); |
|
400 | qreal minY(0); | |
402 | qreal maxX(1); |
|
401 | qreal maxX(1); | |
403 | qreal maxY(1); |
|
402 | qreal maxY(1); | |
404 |
|
403 | |||
405 | Q_Q(QXYSeries); |
|
404 | Q_Q(QXYSeries); | |
406 |
|
405 | |||
407 | const QList<QPointF>& points = q->points(); |
|
406 | const QList<QPointF>& points = q->points(); | |
408 |
|
407 | |||
409 | if (!points.isEmpty()){ |
|
408 | if (!points.isEmpty()){ | |
410 | minX = points[0].x(); |
|
409 | minX = points[0].x(); | |
411 | minY = points[0].y(); |
|
410 | minY = points[0].y(); | |
412 | maxX = minX; |
|
411 | maxX = minX; | |
413 | maxY = minY; |
|
412 | maxY = minY; | |
414 |
|
413 | |||
415 | for (int i = 0; i < points.count(); i++) { |
|
414 | for (int i = 0; i < points.count(); i++) { | |
416 | qreal x = points[i].x(); |
|
415 | qreal x = points[i].x(); | |
417 | qreal y = points[i].y(); |
|
416 | qreal y = points[i].y(); | |
418 | minX = qMin(minX, x); |
|
417 | minX = qMin(minX, x); | |
419 | minY = qMin(minY, y); |
|
418 | minY = qMin(minY, y); | |
420 | maxX = qMax(maxX, x); |
|
419 | maxX = qMax(maxX, x); | |
421 | maxY = qMax(maxY, y); |
|
420 | maxY = qMax(maxY, y); | |
422 | } |
|
421 | } | |
423 | } |
|
422 | } | |
424 |
|
423 | |||
425 | domain.setRange(minX,maxX,minY,maxY); |
|
424 | domain.setRange(minX,maxX,minY,maxY); | |
426 | } |
|
425 | } | |
427 |
|
426 | |||
428 | QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend) |
|
427 | QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend) | |
429 | { |
|
428 | { | |
430 | Q_Q(QXYSeries); |
|
429 | Q_Q(QXYSeries); | |
431 | QList<LegendMarker*> list; |
|
430 | QList<LegendMarker*> list; | |
432 | return list << new XYLegendMarker(q,legend); |
|
431 | return list << new XYLegendMarker(q,legend); | |
433 | } |
|
432 | } | |
434 |
|
433 | |||
435 | void QXYSeriesPrivate::initializeAxis(QAbstractAxis* axis) |
|
434 | void QXYSeriesPrivate::initializeAxis(QAbstractAxis* axis) | |
436 | { |
|
435 | { | |
437 | Q_UNUSED(axis); |
|
436 | Q_UNUSED(axis); | |
438 | } |
|
437 | } | |
439 |
|
438 | |||
440 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
439 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
441 | { |
|
440 | { | |
442 | Q_UNUSED(orientation); |
|
441 | Q_UNUSED(orientation); | |
443 | return QAbstractAxis::AxisTypeValues; |
|
442 | return QAbstractAxis::AxisTypeValues; | |
444 | } |
|
443 | } | |
445 |
|
444 | |||
446 | #include "moc_qxyseries.cpp" |
|
445 | #include "moc_qxyseries.cpp" | |
447 | #include "moc_qxyseries_p.cpp" |
|
446 | #include "moc_qxyseries_p.cpp" | |
448 |
|
447 | |||
449 | QTCOMMERCIALCHART_END_NAMESPACE |
|
448 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,222 +1,219 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "xychart_p.h" |
|
21 | #include "xychart_p.h" | |
22 | #include "qxyseries.h" |
|
22 | #include "qxyseries.h" | |
23 | #include "qxyseries_p.h" |
|
23 | #include "qxyseries_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "qxymodelmapper.h" |
|
26 | #include "qxymodelmapper.h" | |
27 | #include <QPainter> |
|
27 | #include <QPainter> | |
28 | #include <QAbstractItemModel> |
|
28 | #include <QAbstractItemModel> | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | //TODO: optimize : remove points which are not visible |
|
33 | //TODO: optimize : remove points which are not visible | |
34 |
|
34 | |||
35 | XYChart::XYChart(QXYSeries *series, ChartPresenter *presenter):ChartElement(presenter), |
|
35 | XYChart::XYChart(QXYSeries *series, ChartPresenter *presenter):ChartElement(presenter), | |
36 | m_minX(0), |
|
36 | m_minX(0), | |
37 | m_maxX(0), |
|
37 | m_maxX(0), | |
38 | m_minY(0), |
|
38 | m_minY(0), | |
39 | m_maxY(0), |
|
39 | m_maxY(0), | |
40 | m_series(series), |
|
40 | m_series(series), | |
41 | m_animation(0), |
|
41 | m_animation(0), | |
42 | m_dirty(true) |
|
42 | m_dirty(true) | |
43 | { |
|
43 | { | |
44 | // QObject::connect(series->d_func(),SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int))); |
|
|||
45 | // QObject::connect(series->d_func(),SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int))); |
|
|||
46 | // QObject::connect(series->d_func(),SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int))); |
|
|||
47 | QObject::connect(series, SIGNAL(pointReplaced(int)), this,SLOT(handlePointReplaced(int))); |
|
44 | QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int))); | |
48 | QObject::connect(series, SIGNAL(pointAdded(int)), this,SLOT(handlePointAdded(int))); |
|
45 | QObject::connect(series, SIGNAL(pointAdded(int)), this, SLOT(handlePointAdded(int))); | |
49 | QObject::connect(series, SIGNAL(pointRemoved(int)), this,SLOT(handlePointRemoved(int))); |
|
46 | QObject::connect(series, SIGNAL(pointRemoved(int)), this, SLOT(handlePointRemoved(int))); | |
50 | QObject::connect(this, SIGNAL(clicked(QPointF)), series,SIGNAL(clicked(QPointF))); |
|
47 | QObject::connect(this, SIGNAL(clicked(QPointF)), series, SIGNAL(clicked(QPointF))); | |
51 | } |
|
48 | } | |
52 |
|
49 | |||
53 | void XYChart::setGeometryPoints(const QVector<QPointF>& points) |
|
50 | void XYChart::setGeometryPoints(const QVector<QPointF>& points) | |
54 | { |
|
51 | { | |
55 | m_points = points; |
|
52 | m_points = points; | |
56 | } |
|
53 | } | |
57 |
|
54 | |||
58 | void XYChart::setClipRect(const QRectF &rect) |
|
55 | void XYChart::setClipRect(const QRectF &rect) | |
59 | { |
|
56 | { | |
60 | m_clipRect = rect; |
|
57 | m_clipRect = rect; | |
61 | } |
|
58 | } | |
62 |
|
59 | |||
63 | void XYChart::setAnimation(XYAnimation* animation) |
|
60 | void XYChart::setAnimation(XYAnimation* animation) | |
64 | { |
|
61 | { | |
65 | m_animation=animation; |
|
62 | m_animation=animation; | |
66 | } |
|
63 | } | |
67 |
|
64 | |||
68 | void XYChart::setDirty(bool dirty) |
|
65 | void XYChart::setDirty(bool dirty) | |
69 | { |
|
66 | { | |
70 | m_dirty=dirty; |
|
67 | m_dirty=dirty; | |
71 | } |
|
68 | } | |
72 |
|
69 | |||
73 | QPointF XYChart::calculateGeometryPoint(const QPointF &point) const |
|
70 | QPointF XYChart::calculateGeometryPoint(const QPointF &point) const | |
74 | { |
|
71 | { | |
75 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); |
|
72 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); | |
76 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); |
|
73 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); | |
77 | qreal x = (point.x() - m_minX)* deltaX; |
|
74 | qreal x = (point.x() - m_minX)* deltaX; | |
78 | qreal y = (point.y() - m_minY)*-deltaY + m_size.height(); |
|
75 | qreal y = (point.y() - m_minY)*-deltaY + m_size.height(); | |
79 | return QPointF(x,y); |
|
76 | return QPointF(x,y); | |
80 | } |
|
77 | } | |
81 |
|
78 | |||
82 | QPointF XYChart::calculateGeometryPoint(int index) const |
|
79 | QPointF XYChart::calculateGeometryPoint(int index) const | |
83 | { |
|
80 | { | |
84 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); |
|
81 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); | |
85 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); |
|
82 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); | |
86 | const QList<QPointF>& vector = m_series->points(); |
|
83 | const QList<QPointF>& vector = m_series->points(); | |
87 | qreal x = (vector[index].x() - m_minX)* deltaX; |
|
84 | qreal x = (vector[index].x() - m_minX)* deltaX; | |
88 | qreal y = (vector[index].y() - m_minY)*-deltaY + m_size.height(); |
|
85 | qreal y = (vector[index].y() - m_minY)*-deltaY + m_size.height(); | |
89 | return QPointF(x,y); |
|
86 | return QPointF(x,y); | |
90 | } |
|
87 | } | |
91 |
|
88 | |||
92 | QVector<QPointF> XYChart::calculateGeometryPoints() const |
|
89 | QVector<QPointF> XYChart::calculateGeometryPoints() const | |
93 | { |
|
90 | { | |
94 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); |
|
91 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); | |
95 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); |
|
92 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); | |
96 |
|
93 | |||
97 | QVector<QPointF> result; |
|
94 | QVector<QPointF> result; | |
98 | result.resize(m_series->count()); |
|
95 | result.resize(m_series->count()); | |
99 | const QList<QPointF>& vector = m_series->points(); |
|
96 | const QList<QPointF>& vector = m_series->points(); | |
100 | for (int i = 0; i < m_series->count(); ++i) { |
|
97 | for (int i = 0; i < m_series->count(); ++i) { | |
101 | qreal x = (vector[i].x() - m_minX)* deltaX; |
|
98 | qreal x = (vector[i].x() - m_minX)* deltaX; | |
102 | qreal y = (vector[i].y() - m_minY)*-deltaY + m_size.height(); |
|
99 | qreal y = (vector[i].y() - m_minY)*-deltaY + m_size.height(); | |
103 | result[i].setX(x); |
|
100 | result[i].setX(x); | |
104 | result[i].setY(y); |
|
101 | result[i].setY(y); | |
105 | } |
|
102 | } | |
106 | return result; |
|
103 | return result; | |
107 | } |
|
104 | } | |
108 |
|
105 | |||
109 | QPointF XYChart::calculateDomainPoint(const QPointF &point) const |
|
106 | QPointF XYChart::calculateDomainPoint(const QPointF &point) const | |
110 | { |
|
107 | { | |
111 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); |
|
108 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); | |
112 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); |
|
109 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); | |
113 | qreal x = point.x()/deltaX +m_minX; |
|
110 | qreal x = point.x()/deltaX +m_minX; | |
114 | qreal y = (point.y()-m_size.height())/(-deltaY)+ m_minY; |
|
111 | qreal y = (point.y()-m_size.height())/(-deltaY)+ m_minY; | |
115 | return QPointF(x,y); |
|
112 | return QPointF(x,y); | |
116 | } |
|
113 | } | |
117 |
|
114 | |||
118 | void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index) |
|
115 | void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index) | |
119 | { |
|
116 | { | |
120 |
|
117 | |||
121 | if (m_animation) { |
|
118 | if (m_animation) { | |
122 | m_animation->setup(oldPoints, newPoints, index); |
|
119 | m_animation->setup(oldPoints, newPoints, index); | |
123 |
|
|
120 | m_points = newPoints; | |
124 | setDirty(false); |
|
121 | setDirty(false); | |
125 | presenter()->startAnimation(m_animation); |
|
122 | presenter()->startAnimation(m_animation); | |
126 | } |
|
123 | } | |
127 | else { |
|
124 | else { | |
128 |
|
|
125 | m_points = newPoints; | |
129 | updateGeometry(); |
|
126 | updateGeometry(); | |
130 | } |
|
127 | } | |
131 | } |
|
128 | } | |
132 |
|
129 | |||
133 | //handlers |
|
130 | //handlers | |
134 |
|
131 | |||
135 | void XYChart::handlePointAdded(int index) |
|
132 | void XYChart::handlePointAdded(int index) | |
136 | { |
|
133 | { | |
137 | Q_ASSERT(index<m_series->count()); |
|
134 | Q_ASSERT(index<m_series->count()); | |
138 | Q_ASSERT(index>=0); |
|
135 | Q_ASSERT(index>=0); | |
139 |
|
136 | |||
140 | QVector<QPointF> points; |
|
137 | QVector<QPointF> points; | |
141 |
|
138 | |||
142 | if(m_dirty) { |
|
139 | if(m_dirty) { | |
143 | points = calculateGeometryPoints(); |
|
140 | points = calculateGeometryPoints(); | |
144 | } else { |
|
141 | } else { | |
145 | points = m_points; |
|
142 | points = m_points; | |
146 | QPointF point = calculateGeometryPoint(index); |
|
143 | QPointF point = calculateGeometryPoint(index); | |
147 | points.insert(index, point); |
|
144 | points.insert(index, point); | |
148 | } |
|
145 | } | |
149 |
|
146 | |||
150 | updateChart(m_points,points,index); |
|
147 | updateChart(m_points,points,index); | |
151 | } |
|
148 | } | |
152 |
|
149 | |||
153 | void XYChart::handlePointRemoved(int index) |
|
150 | void XYChart::handlePointRemoved(int index) | |
154 | { |
|
151 | { | |
155 | Q_ASSERT(index<=m_series->count()); |
|
152 | Q_ASSERT(index<=m_series->count()); | |
156 | Q_ASSERT(index>=0); |
|
153 | Q_ASSERT(index>=0); | |
157 |
|
154 | |||
158 | QVector<QPointF> points; |
|
155 | QVector<QPointF> points; | |
159 |
|
156 | |||
160 | if(m_dirty) { |
|
157 | if(m_dirty) { | |
161 | points = calculateGeometryPoints(); |
|
158 | points = calculateGeometryPoints(); | |
162 | } else { |
|
159 | } else { | |
163 | points = m_points; |
|
160 | points = m_points; | |
164 | points.remove(index); |
|
161 | points.remove(index); | |
165 | } |
|
162 | } | |
166 |
|
163 | |||
167 | updateChart(m_points,points,index); |
|
164 | updateChart(m_points,points,index); | |
168 | } |
|
165 | } | |
169 |
|
166 | |||
170 | void XYChart::handlePointReplaced(int index) |
|
167 | void XYChart::handlePointReplaced(int index) | |
171 | { |
|
168 | { | |
172 | Q_ASSERT(index<m_series->count()); |
|
169 | Q_ASSERT(index<m_series->count()); | |
173 | Q_ASSERT(index>=0); |
|
170 | Q_ASSERT(index>=0); | |
174 |
|
171 | |||
175 | QVector<QPointF> points; |
|
172 | QVector<QPointF> points; | |
176 |
|
173 | |||
177 | if(m_dirty) { |
|
174 | if(m_dirty) { | |
178 | points = calculateGeometryPoints(); |
|
175 | points = calculateGeometryPoints(); | |
179 | } else { |
|
176 | } else { | |
180 | QPointF point = calculateGeometryPoint(index); |
|
177 | QPointF point = calculateGeometryPoint(index); | |
181 | points = m_points; |
|
178 | points = m_points; | |
182 | points.replace(index,point); |
|
179 | points.replace(index,point); | |
183 | } |
|
180 | } | |
184 |
|
181 | |||
185 | updateChart(m_points,points,index); |
|
182 | updateChart(m_points,points,index); | |
186 | } |
|
183 | } | |
187 |
|
184 | |||
188 | void XYChart::handleDomainUpdated() |
|
185 | void XYChart::handleDomainUpdated() | |
189 | { |
|
186 | { | |
190 | m_minX=domain()->minX(); |
|
187 | m_minX=domain()->minX(); | |
191 | m_maxX=domain()->maxX(); |
|
188 | m_maxX=domain()->maxX(); | |
192 | m_minY=domain()->minY(); |
|
189 | m_minY=domain()->minY(); | |
193 | m_maxY=domain()->maxY(); |
|
190 | m_maxY=domain()->maxY(); | |
194 | if (isEmpty()) return; |
|
191 | if (isEmpty()) return; | |
195 |
|
192 | |||
196 | QVector<QPointF> points = calculateGeometryPoints(); |
|
193 | QVector<QPointF> points = calculateGeometryPoints(); | |
197 |
|
194 | |||
198 | updateChart(m_points,points); |
|
195 | updateChart(m_points,points); | |
199 | } |
|
196 | } | |
200 |
|
197 | |||
201 | void XYChart::handleGeometryChanged(const QRectF &rect) |
|
198 | void XYChart::handleGeometryChanged(const QRectF &rect) | |
202 | { |
|
199 | { | |
203 | Q_ASSERT(rect.isValid()); |
|
200 | Q_ASSERT(rect.isValid()); | |
204 | m_size=rect.size(); |
|
201 | m_size=rect.size(); | |
205 | m_clipRect=rect.translated(-rect.topLeft()); |
|
202 | m_clipRect=rect.translated(-rect.topLeft()); | |
206 | m_origin=rect.topLeft(); |
|
203 | m_origin=rect.topLeft(); | |
207 |
|
204 | |||
208 | if (isEmpty()) return; |
|
205 | if (isEmpty()) return; | |
209 |
|
206 | |||
210 | QVector<QPointF> points = calculateGeometryPoints(); |
|
207 | QVector<QPointF> points = calculateGeometryPoints(); | |
211 |
|
208 | |||
212 | updateChart(m_points,points); |
|
209 | updateChart(m_points,points); | |
213 | } |
|
210 | } | |
214 |
|
211 | |||
215 | bool XYChart::isEmpty() |
|
212 | bool XYChart::isEmpty() | |
216 | { |
|
213 | { | |
217 | return !m_clipRect.isValid() || qFuzzyIsNull(m_maxX - m_minX) || qFuzzyIsNull(m_maxY - m_minY) || m_series->points().isEmpty(); |
|
214 | return !m_clipRect.isValid() || qFuzzyIsNull(m_maxX - m_minX) || qFuzzyIsNull(m_maxY - m_minY) || m_series->points().isEmpty(); | |
218 | } |
|
215 | } | |
219 |
|
216 | |||
220 | #include "moc_xychart_p.cpp" |
|
217 | #include "moc_xychart_p.cpp" | |
221 |
|
218 | |||
222 | QTCOMMERCIALCHART_END_NAMESPACE |
|
219 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,106 +1,106 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef XYCHARTITEM_H |
|
30 | #ifndef XYCHARTITEM_H | |
31 | #define XYCHARTITEM_H |
|
31 | #define XYCHARTITEM_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "chartitem_p.h" |
|
34 | #include "chartitem_p.h" | |
35 | #include "xyanimation_p.h" |
|
35 | #include "xyanimation_p.h" | |
36 | #include "qvaluesaxis.h" |
|
36 | #include "qvaluesaxis.h" | |
37 | #include <QPen> |
|
37 | #include <QPen> | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | class ChartPresenter; |
|
41 | class ChartPresenter; | |
42 | class QXYSeries; |
|
42 | class QXYSeries; | |
43 |
|
43 | |||
44 | class XYChart : public ChartElement |
|
44 | class XYChart : public ChartElement | |
45 | { |
|
45 | { | |
46 | Q_OBJECT |
|
46 | Q_OBJECT | |
47 | public: |
|
47 | public: | |
48 | explicit XYChart(QXYSeries *series, ChartPresenter *presenter); |
|
48 | explicit XYChart(QXYSeries *series, ChartPresenter *presenter); | |
49 |
~XYChart(){} |
|
49 | ~XYChart() {} | |
50 |
|
50 | |||
51 | void setGeometryPoints(const QVector<QPointF>& points); |
|
51 | void setGeometryPoints(const QVector<QPointF>& points); | |
52 | QVector<QPointF> geometryPoints() const { return m_points; } |
|
52 | QVector<QPointF> geometryPoints() const { return m_points; } | |
53 |
|
53 | |||
54 | void setClipRect(const QRectF &rect); |
|
54 | void setClipRect(const QRectF &rect); | |
55 | QRectF clipRect() const { return m_clipRect; } |
|
55 | QRectF clipRect() const { return m_clipRect; } | |
56 |
|
56 | |||
57 | QSizeF size() const { return m_size; } |
|
57 | QSizeF size() const { return m_size; } | |
58 | QPointF origin() const { return m_origin; } |
|
58 | QPointF origin() const { return m_origin; } | |
59 |
|
59 | |||
60 | void setAnimation(XYAnimation* animation); |
|
60 | void setAnimation(XYAnimation* animation); | |
61 | ChartAnimation* animation() const { return m_animation; } |
|
61 | ChartAnimation* animation() const { return m_animation; } | |
62 | virtual void updateGeometry() = 0; |
|
62 | virtual void updateGeometry() = 0; | |
63 |
|
63 | |||
64 | bool isDirty() const { return m_dirty; } |
|
64 | bool isDirty() const { return m_dirty; } | |
65 | void setDirty(bool dirty); |
|
65 | void setDirty(bool dirty); | |
66 |
|
66 | |||
67 | public Q_SLOTS: |
|
67 | public Q_SLOTS: | |
68 | void handlePointAdded(int index); |
|
68 | void handlePointAdded(int index); | |
69 | void handlePointRemoved(int index); |
|
69 | void handlePointRemoved(int index); | |
70 | void handlePointReplaced(int index); |
|
70 | void handlePointReplaced(int index); | |
71 | void handleDomainUpdated(); |
|
71 | void handleDomainUpdated(); | |
72 | void handleGeometryChanged(const QRectF &size); |
|
72 | void handleGeometryChanged(const QRectF &size); | |
73 |
|
73 | |||
74 | Q_SIGNALS: |
|
74 | Q_SIGNALS: | |
75 | void clicked(const QPointF& point); |
|
75 | void clicked(const QPointF& point); | |
76 |
|
76 | |||
77 | protected: |
|
77 | protected: | |
78 | virtual void updateChart(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index = -1); |
|
78 | virtual void updateChart(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index = -1); | |
79 | QPointF calculateGeometryPoint(const QPointF &point) const; |
|
79 | QPointF calculateGeometryPoint(const QPointF &point) const; | |
80 | QPointF calculateGeometryPoint(int index) const; |
|
80 | QPointF calculateGeometryPoint(int index) const; | |
81 | QPointF calculateDomainPoint(const QPointF &point) const; |
|
81 | QPointF calculateDomainPoint(const QPointF &point) const; | |
82 | QVector<QPointF> calculateGeometryPoints() const; |
|
82 | QVector<QPointF> calculateGeometryPoints() const; | |
83 |
|
83 | |||
84 | private: |
|
84 | private: | |
85 | inline bool isEmpty(); |
|
85 | inline bool isEmpty(); | |
86 |
|
86 | |||
87 | private: |
|
87 | protected: | |
88 | qreal m_minX; |
|
88 | qreal m_minX; | |
89 | qreal m_maxX; |
|
89 | qreal m_maxX; | |
90 | qreal m_minY; |
|
90 | qreal m_minY; | |
91 | qreal m_maxY; |
|
91 | qreal m_maxY; | |
92 | QXYSeries* m_series; |
|
92 | QXYSeries* m_series; | |
93 | QSizeF m_size; |
|
93 | QSizeF m_size; | |
94 | QPointF m_origin; |
|
94 | QPointF m_origin; | |
95 | QRectF m_clipRect; |
|
95 | QRectF m_clipRect; | |
96 | QVector<QPointF> m_points; |
|
96 | QVector<QPointF> m_points; | |
97 | XYAnimation* m_animation; |
|
97 | XYAnimation* m_animation; | |
98 | bool m_dirty; |
|
98 | bool m_dirty; | |
99 |
|
99 | |||
100 | friend class AreaChartItem; |
|
100 | friend class AreaChartItem; | |
101 |
|
101 | |||
102 | }; |
|
102 | }; | |
103 |
|
103 | |||
104 | QTCOMMERCIALCHART_END_NAMESPACE |
|
104 | QTCOMMERCIALCHART_END_NAMESPACE | |
105 |
|
105 | |||
106 | #endif |
|
106 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now