@@ -1,27 +1,26 | |||||
1 | TEMPLATE = subdirs |
|
1 | TEMPLATE = subdirs | |
2 | SUBDIRS += \ |
|
2 | SUBDIRS += \ | |
3 | areachart \ |
|
3 | areachart \ | |
4 | barchart \ |
|
4 | barchart \ | |
5 | customchart \ |
|
5 | customchart \ | |
6 | ekgchart \ |
|
6 | ekgchart \ | |
7 | linechart \ |
|
7 | linechart \ | |
8 | percentbarchart \ |
|
8 | percentbarchart \ | |
9 | piechart \ |
|
9 | piechart \ | |
10 | piechartdrilldown \ |
|
10 | piechartdrilldown \ | |
11 | presenterchart \ |
|
11 | presenterchart \ | |
12 | scatterchart \ |
|
12 | scatterchart \ | |
13 | scatterinteractions \ |
|
13 | scatterinteractions \ | |
14 | splinechart \ |
|
14 | splinechart \ | |
15 | stackedbarchart \ |
|
15 | stackedbarchart \ | |
16 | stackedbarchartdrilldown \ |
|
16 | stackedbarchartdrilldown \ | |
17 | tablemodelchart \ |
|
|||
18 | zoomlinechart \ |
|
17 | zoomlinechart \ | |
19 | modeldata |
|
18 | modeldata | |
20 |
|
19 | |||
21 |
|
20 | |||
22 |
|
21 | |||
23 |
|
22 | |||
24 |
|
23 | |||
25 |
|
24 | |||
26 |
|
25 | |||
27 |
|
26 |
@@ -1,65 +1,65 | |||||
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 | #ifndef SPLINECHARTITEM_P_H |
|
21 | #ifndef SPLINECHARTITEM_P_H | |
22 | #define SPLINECHARTITEM_P_H |
|
22 | #define SPLINECHARTITEM_P_H | |
23 |
|
23 | |||
24 | #include "qsplineseries.h" |
|
24 | #include "qsplineseries.h" | |
25 | #include "xychartitem_p.h" |
|
25 | #include "xychartitem_p.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | class SplineChartItem : public XYChartItem |
|
29 | class SplineChartItem : public XYChartItem | |
30 | { |
|
30 | { | |
31 | Q_OBJECT |
|
31 | Q_OBJECT | |
32 | public: |
|
32 | public: | |
33 | SplineChartItem(QSplineSeries *series, ChartPresenter *presenter); |
|
33 | SplineChartItem(QSplineSeries *series, ChartPresenter *presenter); | |
34 |
|
34 | |||
35 | //from QGraphicsItem |
|
35 | //from QGraphicsItem | |
36 | QRectF boundingRect() const; |
|
36 | QRectF boundingRect() const; | |
37 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
37 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
38 | QPainterPath shape() const; |
|
38 | QPainterPath shape() const; | |
39 |
|
39 | |||
40 | public Q_SLOTS: |
|
40 | public Q_SLOTS: | |
41 | void handleUpdated(); |
|
41 | void handleUpdated(); | |
42 |
|
42 | |||
43 | protected: |
|
43 | protected: | |
44 | void setLayout(QVector<QPointF> &points); |
|
44 | void setLayout(QVector<QPointF> &points); | |
45 | void setLayout(QVector<QPointF> &points,QVector<QPointF> &controlPoints); |
|
45 | void setLayout(QVector<QPointF> &points,QVector<QPointF> &controlPoints); | |
46 | void updateLayout(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index); |
|
46 | void updateLayout(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index); | |
47 |
|
47 | |||
48 | private: |
|
48 | private: | |
49 | QPointF calculateGeometryControlPoint(int index) const; |
|
49 | QPointF calculateGeometryControlPoint(int index) const; | |
50 |
|
50 | |||
51 | private: |
|
51 | private: | |
52 |
QSplineSeries* |
|
52 | QSplineSeries *m_series; | |
53 | QPainterPath m_path; |
|
53 | QPainterPath m_path; | |
54 | QRectF m_rect; |
|
54 | QRectF m_rect; | |
55 | QPen m_linePen; |
|
55 | QPen m_linePen; | |
56 | QPen m_pointPen; |
|
56 | QPen m_pointPen; | |
57 | bool m_pointsVisible; |
|
57 | bool m_pointsVisible; | |
58 | QVector<QPointF> m_controlPoints; |
|
58 | QVector<QPointF> m_controlPoints; | |
59 |
|
59 | |||
60 | friend class SplineAnimation; |
|
60 | friend class SplineAnimation; | |
61 | }; |
|
61 | }; | |
62 |
|
62 | |||
63 | QTCOMMERCIALCHART_END_NAMESPACE |
|
63 | QTCOMMERCIALCHART_END_NAMESPACE | |
64 |
|
64 | |||
65 | #endif // SPLINECHARTITEM_P_H |
|
65 | #endif // SPLINECHARTITEM_P_H |
@@ -1,660 +1,660 | |||||
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 <QAbstractItemModel> |
|
25 | #include <QAbstractItemModel> | |
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 | /*! |
|
34 | /*! | |
35 | \fn QPen QXYSeries::pen() const |
|
35 | \fn QPen QXYSeries::pen() const | |
36 | \brief Returns pen used to draw points for series. |
|
36 | \brief Returns pen used to draw points for series. | |
37 | \sa setPen() |
|
37 | \sa setPen() | |
38 | */ |
|
38 | */ | |
39 |
|
39 | |||
40 | /*! |
|
40 | /*! | |
41 | \fn QBrush QXYSeries::brush() const |
|
41 | \fn QBrush QXYSeries::brush() const | |
42 | \brief Returns brush used to draw points for series. |
|
42 | \brief Returns brush used to draw points for series. | |
43 | \sa setBrush() |
|
43 | \sa setBrush() | |
44 | */ |
|
44 | */ | |
45 |
|
45 | |||
46 | /*! |
|
46 | /*! | |
47 | \fn void QXYSeries::clicked(const QPointF& point) |
|
47 | \fn void QXYSeries::clicked(const QPointF& point) | |
48 | \brief Signal is emitted when user clicks the \a point on chart. |
|
48 | \brief Signal is emitted when user clicks the \a point on chart. | |
49 | */ |
|
49 | */ | |
50 |
|
50 | |||
51 | /*! |
|
51 | /*! | |
52 | \fn void QXYSeriesPrivate::pointReplaced(int index) |
|
52 | \fn void QXYSeriesPrivate::pointReplaced(int index) | |
53 | \brief \internal \a index |
|
53 | \brief \internal \a index | |
54 | */ |
|
54 | */ | |
55 |
|
55 | |||
56 | /*! |
|
56 | /*! | |
57 | \fn void QXYSeriesPrivate::pointAdded(int index) |
|
57 | \fn void QXYSeriesPrivate::pointAdded(int index) | |
58 | \brief \internal \a index |
|
58 | \brief \internal \a index | |
59 | */ |
|
59 | */ | |
60 |
|
60 | |||
61 | /*! |
|
61 | /*! | |
62 | \fn void QXYSeriesPrivate::pointRemoved(int index) |
|
62 | \fn void QXYSeriesPrivate::pointRemoved(int index) | |
63 | \brief \internal \a index |
|
63 | \brief \internal \a index | |
64 | */ |
|
64 | */ | |
65 |
|
65 | |||
66 | /*! |
|
66 | /*! | |
67 | \fn void QXYSeriesPrivate::updated() |
|
67 | \fn void QXYSeriesPrivate::updated() | |
68 | \brief \internal |
|
68 | \brief \internal | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \fn int QXYSeries::mapFirst() const |
|
72 | \fn int QXYSeries::mapFirst() const | |
73 | Returns the index of the model's item that is used as a first one for the series. |
|
73 | Returns the index of the model's item that is used as a first one for the series. | |
74 | \sa mapCount() |
|
74 | \sa mapCount() | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 | \fn int QXYSeries::mapCount() const |
|
78 | \fn int QXYSeries::mapCount() const | |
79 | Returns the number of the items that are taken from the model. |
|
79 | Returns the number of the items that are taken from the model. | |
80 | If -1 it means all the items of the model following the first one are used. |
|
80 | If -1 it means all the items of the model following the first one are used. | |
81 | \sa mapFirst() |
|
81 | \sa mapFirst() | |
82 | */ |
|
82 | */ | |
83 |
|
83 | |||
84 | /*! |
|
84 | /*! | |
85 | Constructs empty series object which is a child of \a parent. |
|
85 | Constructs empty series object which is a child of \a parent. | |
86 | When series object is added to QChartView or QChart instance ownerships is transfered. |
|
86 | When series object is added to QChartView or QChart instance ownerships is transfered. | |
87 | */ |
|
87 | */ | |
88 | QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent):QSeries(d,parent) |
|
88 | QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent):QSeries(d,parent) | |
89 | { |
|
89 | { | |
90 |
|
90 | |||
91 | } |
|
91 | } | |
92 | /*! |
|
92 | /*! | |
93 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
93 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
94 | and are deleted when mentioned object are destroyed. |
|
94 | and are deleted when mentioned object are destroyed. | |
95 | */ |
|
95 | */ | |
96 | QXYSeries::~QXYSeries() |
|
96 | QXYSeries::~QXYSeries() | |
97 | { |
|
97 | { | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
101 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. | |
102 | */ |
|
102 | */ | |
103 | void QXYSeries::append(qreal x,qreal y) |
|
103 | void QXYSeries::append(qreal x,qreal y) | |
104 | { |
|
104 | { | |
105 | Q_D(QXYSeries); |
|
105 | Q_D(QXYSeries); | |
106 | Q_ASSERT(d->m_x.size() == d->m_y.size()); |
|
106 | Q_ASSERT(d->m_x.size() == d->m_y.size()); | |
107 | d->m_x<<x; |
|
107 | d->m_x<<x; | |
108 | d->m_y<<y; |
|
108 | d->m_y<<y; | |
109 | emit d->pointAdded(d->m_x.size()-1); |
|
109 | emit d->pointAdded(d->m_x.size()-1); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | This is an overloaded function. |
|
113 | This is an overloaded function. | |
114 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
114 | Adds data \a point to the series. Points are connected with lines on the chart. | |
115 | */ |
|
115 | */ | |
116 | void QXYSeries::append(const QPointF &point) |
|
116 | void QXYSeries::append(const QPointF &point) | |
117 | { |
|
117 | { | |
118 | append(point.x(),point.y()); |
|
118 | append(point.x(),point.y()); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | /*! |
|
121 | /*! | |
122 | This is an overloaded function. |
|
122 | This is an overloaded function. | |
123 | Adds list of data \a points to the series. Points are connected with lines on the chart. |
|
123 | Adds list of data \a points to the series. Points are connected with lines on the chart. | |
124 | */ |
|
124 | */ | |
125 | void QXYSeries::append(const QList<QPointF> points) |
|
125 | void QXYSeries::append(const QList<QPointF> points) | |
126 | { |
|
126 | { | |
127 | foreach(const QPointF& point , points) { |
|
127 | foreach(const QPointF& point , points) { | |
128 | append(point.x(),point.y()); |
|
128 | append(point.x(),point.y()); | |
129 | } |
|
129 | } | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | Modifies \a y value for given \a x a value. |
|
133 | Modifies \a y value for given \a x a value. | |
134 | */ |
|
134 | */ | |
135 | void QXYSeries::replace(qreal x,qreal y) |
|
135 | void QXYSeries::replace(qreal x,qreal y) | |
136 | { |
|
136 | { | |
137 | Q_D(QXYSeries); |
|
137 | Q_D(QXYSeries); | |
138 | int index = d->m_x.indexOf(x); |
|
138 | int index = d->m_x.indexOf(x); | |
139 | d->m_x[index] = x; |
|
139 | d->m_x[index] = x; | |
140 | d->m_y[index] = y; |
|
140 | d->m_y[index] = y; | |
141 | emit d->pointReplaced(index); |
|
141 | emit d->pointReplaced(index); | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | This is an overloaded function. |
|
145 | This is an overloaded function. | |
146 | Replaces current y value of for given \a point x value with \a point y value. |
|
146 | Replaces current y value of for given \a point x value with \a point y value. | |
147 | */ |
|
147 | */ | |
148 | void QXYSeries::replace(const QPointF &point) |
|
148 | void QXYSeries::replace(const QPointF &point) | |
149 | { |
|
149 | { | |
150 | replace(point.x(),point.y()); |
|
150 | replace(point.x(),point.y()); | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | /*! |
|
153 | /*! | |
154 | Removes first \a x value and related y value. |
|
154 | Removes first \a x value and related y value. | |
155 | */ |
|
155 | */ | |
156 | void QXYSeries::remove(qreal x) |
|
156 | void QXYSeries::remove(qreal x) | |
157 | { |
|
157 | { | |
158 | Q_D(QXYSeries); |
|
158 | Q_D(QXYSeries); | |
159 | int index = d->m_x.indexOf(x); |
|
159 | int index = d->m_x.indexOf(x); | |
160 |
|
160 | |||
161 | if (index == -1) return; |
|
161 | if (index == -1) return; | |
162 |
|
162 | |||
163 | d->m_x.remove(index); |
|
163 | d->m_x.remove(index); | |
164 | d->m_y.remove(index); |
|
164 | d->m_y.remove(index); | |
165 |
|
165 | |||
166 | emit d->pointRemoved(index); |
|
166 | emit d->pointRemoved(index); | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | /*! |
|
169 | /*! | |
170 | Removes current \a x and \a y value. |
|
170 | Removes current \a x and \a y value. | |
171 | */ |
|
171 | */ | |
172 | void QXYSeries::remove(qreal x,qreal y) |
|
172 | void QXYSeries::remove(qreal x,qreal y) | |
173 | { |
|
173 | { | |
174 | Q_D(QXYSeries); |
|
174 | Q_D(QXYSeries); | |
175 | int index =-1; |
|
175 | int index =-1; | |
176 | do { |
|
176 | do { | |
177 | index = d->m_x.indexOf(x,index+1); |
|
177 | index = d->m_x.indexOf(x,index+1); | |
178 | } while (index !=-1 && d->m_y.at(index)!=y); |
|
178 | } while (index !=-1 && d->m_y.at(index)!=y); | |
179 |
|
179 | |||
180 | if (index==-1) return; |
|
180 | if (index==-1) return; | |
181 |
|
181 | |||
182 | d->m_x.remove(index); |
|
182 | d->m_x.remove(index); | |
183 | d->m_y.remove(index); |
|
183 | d->m_y.remove(index); | |
184 | emit d->pointRemoved(index); |
|
184 | emit d->pointRemoved(index); | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | /*! |
|
187 | /*! | |
188 | Removes current \a point x value. Note \a point y value is ignored. |
|
188 | Removes current \a point x value. Note \a point y value is ignored. | |
189 | */ |
|
189 | */ | |
190 | void QXYSeries::remove(const QPointF &point) |
|
190 | void QXYSeries::remove(const QPointF &point) | |
191 | { |
|
191 | { | |
192 | remove(point.x(),point.y()); |
|
192 | remove(point.x(),point.y()); | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | /*! |
|
195 | /*! | |
196 | Removes all data points from the series. |
|
196 | Removes all data points from the series. | |
197 | */ |
|
197 | */ | |
198 | void QXYSeries::removeAll() |
|
198 | void QXYSeries::removeAll() | |
199 | { |
|
199 | { | |
200 | Q_D(QXYSeries); |
|
200 | Q_D(QXYSeries); | |
201 | d->m_x.clear(); |
|
201 | d->m_x.clear(); | |
202 | d->m_y.clear(); |
|
202 | d->m_y.clear(); | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | /*! |
|
205 | /*! | |
206 | \internal \a pos |
|
206 | \internal \a pos | |
207 | */ |
|
207 | */ | |
208 | qreal QXYSeries::x(int pos) const |
|
208 | qreal QXYSeries::x(int pos) const | |
209 | { |
|
209 | { | |
210 | Q_D(const QXYSeries); |
|
210 | Q_D(const QXYSeries); | |
211 | if (d->m_model) { |
|
211 | if (d->m_model) { | |
212 | if (d->m_mapOrientation == Qt::Vertical) |
|
212 | if (d->m_mapOrientation == Qt::Vertical) | |
213 | // consecutive data is read from model's column |
|
213 | // consecutive data is read from model's column | |
214 | return d->m_model->data(d->m_model->index(pos + d->m_mapFirst, d->m_mapX), Qt::DisplayRole).toDouble(); |
|
214 | return d->m_model->data(d->m_model->index(pos + d->m_mapFirst, d->m_mapX), Qt::DisplayRole).toDouble(); | |
215 | else |
|
215 | else | |
216 | // consecutive data is read from model's row |
|
216 | // consecutive data is read from model's row | |
217 | return d->m_model->data(d->m_model->index(d->m_mapX, pos + d->m_mapFirst), Qt::DisplayRole).toDouble(); |
|
217 | return d->m_model->data(d->m_model->index(d->m_mapX, pos + d->m_mapFirst), Qt::DisplayRole).toDouble(); | |
218 | } else { |
|
218 | } else { | |
219 | // model is not specified, return the data from series' internal data store |
|
219 | // model is not specified, return the data from series' internal data store | |
220 | return d->m_x.at(pos); |
|
220 | return d->m_x.at(pos); | |
221 | } |
|
221 | } | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | /*! |
|
224 | /*! | |
225 | \internal \a pos |
|
225 | \internal \a pos | |
226 | */ |
|
226 | */ | |
227 | qreal QXYSeries::y(int pos) const |
|
227 | qreal QXYSeries::y(int pos) const | |
228 | { |
|
228 | { | |
229 | Q_D(const QXYSeries); |
|
229 | Q_D(const QXYSeries); | |
230 | if (d->m_model) { |
|
230 | if (d->m_model) { | |
231 | if (d->m_mapOrientation == Qt::Vertical) |
|
231 | if (d->m_mapOrientation == Qt::Vertical) | |
232 | // consecutive data is read from model's column |
|
232 | // consecutive data is read from model's column | |
233 | return d->m_model->data(d->m_model->index(pos + d->m_mapFirst, d->m_mapY), Qt::DisplayRole).toDouble(); |
|
233 | return d->m_model->data(d->m_model->index(pos + d->m_mapFirst, d->m_mapY), Qt::DisplayRole).toDouble(); | |
234 | else |
|
234 | else | |
235 | // consecutive data is read from model's row |
|
235 | // consecutive data is read from model's row | |
236 | return d->m_model->data(d->m_model->index(d->m_mapY, pos + d->m_mapFirst), Qt::DisplayRole).toDouble(); |
|
236 | return d->m_model->data(d->m_model->index(d->m_mapY, pos + d->m_mapFirst), Qt::DisplayRole).toDouble(); | |
237 | } else { |
|
237 | } else { | |
238 | // model is not specified, return the data from series' internal data store |
|
238 | // model is not specified, return the data from series' internal data store | |
239 | return d->m_y.at(pos); |
|
239 | return d->m_y.at(pos); | |
240 | } |
|
240 | } | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | /*! |
|
243 | /*! | |
244 | Returns number of data points within series. |
|
244 | Returns number of data points within series. | |
245 | */ |
|
245 | */ | |
246 | int QXYSeries::count() const |
|
246 | int QXYSeries::count() const | |
247 | { |
|
247 | { | |
248 | Q_D(const QXYSeries); |
|
248 | Q_D(const QXYSeries); | |
249 |
|
249 | |||
250 | Q_ASSERT(d->m_x.size() == d->m_y.size()); |
|
250 | Q_ASSERT(d->m_x.size() == d->m_y.size()); | |
251 |
|
251 | |||
252 | if (d->m_model) { |
|
252 | if (d->m_model) { | |
253 | if (d->m_mapOrientation == Qt::Vertical) { |
|
253 | if (d->m_mapOrientation == Qt::Vertical) { | |
254 | // data is in a column. Return the number of mapped items if the model's column have enough items |
|
254 | // data is in a column. Return the number of mapped items if the model's column have enough items | |
255 | // or the number of items that can be mapped |
|
255 | // or the number of items that can be mapped | |
256 | if (d->m_mapLimited) |
|
256 | if (d->m_mapLimited) | |
257 | return qMin(d->m_mapCount, qMax(d->m_model->rowCount() - d->m_mapFirst, 0)); |
|
257 | return qMin(d->m_mapCount, qMax(d->m_model->rowCount() - d->m_mapFirst, 0)); | |
258 | else |
|
258 | else | |
259 | return qMax(d->m_model->rowCount() - d->m_mapFirst, 0); |
|
259 | return qMax(d->m_model->rowCount() - d->m_mapFirst, 0); | |
260 | } else { |
|
260 | } else { | |
261 | // data is in a row. Return the number of mapped items if the model's row have enough items |
|
261 | // data is in a row. Return the number of mapped items if the model's row have enough items | |
262 | // or the number of items that can be mapped |
|
262 | // or the number of items that can be mapped | |
263 | if (d->m_mapLimited) |
|
263 | if (d->m_mapLimited) | |
264 | return qMin(d->m_mapCount, qMax(d->m_model->columnCount() - d->m_mapFirst, 0)); |
|
264 | return qMin(d->m_mapCount, qMax(d->m_model->columnCount() - d->m_mapFirst, 0)); | |
265 | else |
|
265 | else | |
266 | return qMax(d->m_model->columnCount() - d->m_mapFirst, 0); |
|
266 | return qMax(d->m_model->columnCount() - d->m_mapFirst, 0); | |
267 | } |
|
267 | } | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | // model is not specified, return the number of points in the series internal data store |
|
270 | // model is not specified, return the number of points in the series internal data store | |
271 | return d->m_x.size(); |
|
271 | return d->m_x.size(); | |
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 | /*! |
|
274 | /*! | |
275 | Returns the data points of the series. |
|
275 | Returns the data points of the series. | |
276 | */ |
|
276 | */ | |
277 | QList<QPointF> QXYSeries::data() |
|
277 | QList<QPointF> QXYSeries::data() | |
278 | { |
|
278 | { | |
279 | Q_D(QXYSeries); |
|
279 | Q_D(QXYSeries); | |
280 | QList<QPointF> data; |
|
280 | QList<QPointF> data; | |
281 | for (int i(0); i < d->m_x.count() && i < d->m_y.count(); i++) |
|
281 | for (int i(0); i < d->m_x.count() && i < d->m_y.count(); i++) | |
282 | data.append(QPointF(d->m_x.at(i), d->m_y.at(i))); |
|
282 | data.append(QPointF(d->m_x.at(i), d->m_y.at(i))); | |
283 | return data; |
|
283 | return data; | |
284 | } |
|
284 | } | |
285 |
|
285 | |||
286 |
|
286 | |||
287 | /*! |
|
287 | /*! | |
288 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
288 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the | |
289 | pen from chart theme is used. |
|
289 | pen from chart theme is used. | |
290 | \sa QChart::setTheme() |
|
290 | \sa QChart::setTheme() | |
291 | */ |
|
291 | */ | |
292 | void QXYSeries::setPen(const QPen &pen) |
|
292 | void QXYSeries::setPen(const QPen &pen) | |
293 | { |
|
293 | { | |
294 | Q_D(QXYSeries); |
|
294 | Q_D(QXYSeries); | |
295 | if (d->m_pen!=pen) { |
|
295 | if (d->m_pen!=pen) { | |
296 | d->m_pen = pen; |
|
296 | d->m_pen = pen; | |
297 | emit d->updated(); |
|
297 | emit d->updated(); | |
298 | } |
|
298 | } | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | QPen QXYSeries::pen() const |
|
301 | QPen QXYSeries::pen() const | |
302 | { |
|
302 | { | |
303 | Q_D(const QXYSeries); |
|
303 | Q_D(const QXYSeries); | |
304 | return d->m_pen; |
|
304 | return d->m_pen; | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 | /*! |
|
307 | /*! | |
308 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
308 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush | |
309 | from chart theme setting is used. |
|
309 | from chart theme setting is used. | |
310 | \sa QChart::setTheme() |
|
310 | \sa QChart::setTheme() | |
311 | */ |
|
311 | */ | |
312 | void QXYSeries::setBrush(const QBrush &brush) |
|
312 | void QXYSeries::setBrush(const QBrush &brush) | |
313 | { |
|
313 | { | |
314 | Q_D(QXYSeries); |
|
314 | Q_D(QXYSeries); | |
315 | if (d->m_brush!=brush) { |
|
315 | if (d->m_brush!=brush) { | |
316 | d->m_brush = brush; |
|
316 | d->m_brush = brush; | |
317 | emit d->updated(); |
|
317 | emit d->updated(); | |
318 | } |
|
318 | } | |
319 | } |
|
319 | } | |
320 |
|
320 | |||
321 | QBrush QXYSeries::brush() const |
|
321 | QBrush QXYSeries::brush() const | |
322 | { |
|
322 | { | |
323 | Q_D(const QXYSeries); |
|
323 | Q_D(const QXYSeries); | |
324 | return d->m_brush; |
|
324 | return d->m_brush; | |
325 | } |
|
325 | } | |
326 |
|
326 | |||
327 |
|
327 | |||
328 | /*! |
|
328 | /*! | |
329 | Sets if data points are \a visible and should be drawn on line. |
|
329 | Sets if data points are \a visible and should be drawn on line. | |
330 | */ |
|
330 | */ | |
331 | void QXYSeries::setPointsVisible(bool visible) |
|
331 | void QXYSeries::setPointsVisible(bool visible) | |
332 | { |
|
332 | { | |
333 | Q_D(QXYSeries); |
|
333 | Q_D(QXYSeries); | |
334 | if (d->m_pointsVisible != visible){ |
|
334 | if (d->m_pointsVisible != visible){ | |
335 | d->m_pointsVisible = visible; |
|
335 | d->m_pointsVisible = visible; | |
336 | emit d->updated(); |
|
336 | emit d->updated(); | |
337 | } |
|
337 | } | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 |
|
340 | |||
341 | bool QXYSeries::pointsVisible() const |
|
341 | bool QXYSeries::pointsVisible() const | |
342 | { |
|
342 | { | |
343 | Q_D(const QXYSeries); |
|
343 | Q_D(const QXYSeries); | |
344 | return d->m_pointsVisible; |
|
344 | return d->m_pointsVisible; | |
345 | } |
|
345 | } | |
346 |
|
346 | |||
347 |
|
347 | |||
348 | /*! |
|
348 | /*! | |
349 | Stream operator for adding a data \a point to the series. |
|
349 | Stream operator for adding a data \a point to the series. | |
350 | \sa append() |
|
350 | \sa append() | |
351 | */ |
|
351 | */ | |
352 | QXYSeries& QXYSeries::operator<< (const QPointF &point) |
|
352 | QXYSeries& QXYSeries::operator<< (const QPointF &point) | |
353 | { |
|
353 | { | |
354 | append(point); |
|
354 | append(point); | |
355 | return *this; |
|
355 | return *this; | |
356 | } |
|
356 | } | |
357 |
|
357 | |||
358 |
|
358 | |||
359 | /*! |
|
359 | /*! | |
360 | Stream operator for adding a list of \a points to the series. |
|
360 | Stream operator for adding a list of \a points to the series. | |
361 | \sa append() |
|
361 | \sa append() | |
362 | */ |
|
362 | */ | |
363 |
|
363 | |||
364 | QXYSeries& QXYSeries::operator<< (const QList<QPointF> points) |
|
364 | QXYSeries& QXYSeries::operator<< (const QList<QPointF> points) | |
365 | { |
|
365 | { | |
366 | append(points); |
|
366 | append(points); | |
367 | return *this; |
|
367 | return *this; | |
368 | } |
|
368 | } | |
369 |
|
369 | |||
370 | /*! |
|
370 | /*! | |
371 | \internal |
|
371 | \internal | |
372 | */ |
|
372 | */ | |
373 | void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
373 | void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
374 | { |
|
374 | { | |
375 | Q_UNUSED(bottomRight) |
|
375 | Q_UNUSED(bottomRight) | |
376 | Q_D(QXYSeries); |
|
376 | Q_D(QXYSeries); | |
377 | if (d->m_mapOrientation == Qt::Vertical) { |
|
377 | if (d->m_mapOrientation == Qt::Vertical) { | |
378 | if (topLeft.row() >= d->m_mapFirst && (!d->m_mapLimited || topLeft.row() < d->m_mapFirst + d->m_mapCount)) |
|
378 | if (topLeft.row() >= d->m_mapFirst && (!d->m_mapLimited || topLeft.row() < d->m_mapFirst + d->m_mapCount)) | |
379 | emit d->pointReplaced(topLeft.row() - d->m_mapFirst); |
|
379 | emit d->pointReplaced(topLeft.row() - d->m_mapFirst); | |
380 | } else { |
|
380 | } else { | |
381 | if (topLeft.column() >= d->m_mapFirst && (!d->m_mapLimited || topLeft.column() < d->m_mapFirst + d->m_mapCount)) |
|
381 | if (topLeft.column() >= d->m_mapFirst && (!d->m_mapLimited || topLeft.column() < d->m_mapFirst + d->m_mapCount)) | |
382 | emit d->pointReplaced(topLeft.column() - d->m_mapFirst); |
|
382 | emit d->pointReplaced(topLeft.column() - d->m_mapFirst); | |
383 | } |
|
383 | } | |
384 | } |
|
384 | } | |
385 |
|
385 | |||
386 | /*! |
|
386 | /*! | |
387 | \internal |
|
387 | \internal | |
388 | */ |
|
388 | */ | |
389 | void QXYSeries::modelDataAboutToBeAdded(QModelIndex parent, int start, int end) |
|
389 | void QXYSeries::modelDataAboutToBeAdded(QModelIndex parent, int start, int end) | |
390 | { |
|
390 | { | |
391 | Q_UNUSED(parent) |
|
391 | Q_UNUSED(parent) | |
392 | // Q_UNUSED(end) |
|
392 | // Q_UNUSED(end) | |
393 | Q_D(QXYSeries); |
|
393 | Q_D(QXYSeries); | |
394 | if (d->m_mapLimited) { |
|
394 | if (d->m_mapLimited) { | |
395 | if (start >= d->m_mapFirst + d->m_mapCount) { |
|
395 | if (start >= d->m_mapFirst + d->m_mapCount) { | |
396 | // the added data is below mapped area |
|
396 | // the added data is below mapped area | |
397 | // therefore it has no relevance |
|
397 | // therefore it has no relevance | |
398 | return; |
|
398 | return; | |
399 | } else { |
|
399 | } else { | |
400 | // the added data is in the mapped area or before it and update is needed |
|
400 | // the added data is in the mapped area or before it and update is needed | |
401 |
|
401 | |||
402 | // check how many mapped items there is currently (before new items are added) |
|
402 | // check how many mapped items there is currently (before new items are added) | |
403 | // if the number of items currently is equal the m_mapCount then some needs to be removed from xychartitem |
|
403 | // if the number of items currently is equal the m_mapCount then some needs to be removed from xychartitem | |
404 | // internal storage before new ones can be added |
|
404 | // internal storage before new ones can be added | |
405 |
|
405 | |||
406 | int itemsToRemove = qMin(count() - qMax(start - d->m_mapFirst, 0), end - start + 1); |
|
406 | int itemsToRemove = qMin(count() - qMax(start - d->m_mapFirst, 0), end - start + 1); | |
407 | if (d->m_mapCount == count()) { |
|
407 | if (d->m_mapCount == count()) { | |
408 | for (int i = 0; i < itemsToRemove; i++) |
|
408 | for (int i = 0; i < itemsToRemove; i++) | |
409 | emit d->pointRemoved(qMin(end, count()) - i); |
|
409 | emit d->pointRemoved(qMin(end, count()) - i); | |
410 | } |
|
410 | } | |
411 | } |
|
411 | } | |
412 | } else { |
|
412 | } else { | |
413 | // map is not limited (it includes all the items starting from m_mapFirst till the end of model) |
|
413 | // map is not limited (it includes all the items starting from m_mapFirst till the end of model) | |
414 | // nothing to do |
|
414 | // nothing to do | |
415 | // emit pointAdded(qMax(start - m_mapFirst, 0)); |
|
415 | // emit pointAdded(qMax(start - m_mapFirst, 0)); | |
416 | } |
|
416 | } | |
417 | } |
|
417 | } | |
418 |
|
418 | |||
419 | /*! |
|
419 | /*! | |
420 | \internal |
|
420 | \internal | |
421 | */ |
|
421 | */ | |
422 | void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end) |
|
422 | void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end) | |
423 | { |
|
423 | { | |
424 | Q_UNUSED(parent) |
|
424 | Q_UNUSED(parent) | |
425 | // Q_UNUSED(end) |
|
425 | // Q_UNUSED(end) | |
426 | Q_D(QXYSeries); |
|
426 | Q_D(QXYSeries); | |
427 | if (d->m_mapLimited) { |
|
427 | if (d->m_mapLimited) { | |
428 | if (start >= d->m_mapFirst + d->m_mapCount) { |
|
428 | if (start >= d->m_mapFirst + d->m_mapCount) { | |
429 | // the added data is below mapped area |
|
429 | // the added data is below mapped area | |
430 | // therefore it has no relevance |
|
430 | // therefore it has no relevance | |
431 | return; |
|
431 | return; | |
432 | } else { |
|
432 | } else { | |
433 | // the added data is in the mapped area or before it |
|
433 | // the added data is in the mapped area or before it | |
434 | // update needed |
|
434 | // update needed | |
435 | if (count() > 0) { |
|
435 | if (count() > 0) { | |
436 | int toBeAdded = qMin(d->m_mapCount - (start - d->m_mapFirst), end - start + 1); |
|
436 | int toBeAdded = qMin(d->m_mapCount - (start - d->m_mapFirst), end - start + 1); | |
437 | for (int i = 0; i < toBeAdded; i++) |
|
437 | for (int i = 0; i < toBeAdded; i++) | |
438 | if (start + i >= d->m_mapFirst) |
|
438 | if (start + i >= d->m_mapFirst) | |
439 | emit d->pointAdded(start + i); |
|
439 | emit d->pointAdded(start + i); | |
440 | } |
|
440 | } | |
441 | } |
|
441 | } | |
442 | } else { |
|
442 | } else { | |
443 | // map is not limited (it included all the items starting from m_mapFirst till the end of model) |
|
443 | // map is not limited (it included all the items starting from m_mapFirst till the end of model) | |
444 | for (int i = 0; i < end - start + 1; i++) |
|
444 | for (int i = 0; i < end - start + 1; i++) | |
445 | emit d->pointAdded(start + i); |
|
445 | emit d->pointAdded(start + i); | |
446 | } |
|
446 | } | |
447 | } |
|
447 | } | |
448 |
|
448 | |||
449 | /*! |
|
449 | /*! | |
450 | \internal |
|
450 | \internal | |
451 | */ |
|
451 | */ | |
452 | void QXYSeries::modelDataAboutToBeRemoved(QModelIndex parent, int start, int end) |
|
452 | void QXYSeries::modelDataAboutToBeRemoved(QModelIndex parent, int start, int end) | |
453 | { |
|
453 | { | |
454 | Q_UNUSED(parent) |
|
454 | Q_UNUSED(parent) | |
455 | // Q_UNUSED(end) |
|
455 | // Q_UNUSED(end) | |
456 | Q_D(QXYSeries); |
|
456 | Q_D(QXYSeries); | |
457 | if (d->m_mapLimited) { |
|
457 | if (d->m_mapLimited) { | |
458 | if (start >= d->m_mapFirst + d->m_mapCount) { |
|
458 | if (start >= d->m_mapFirst + d->m_mapCount) { | |
459 | // the removed data is below mapped area |
|
459 | // the removed data is below mapped area | |
460 | // therefore it has no relevance |
|
460 | // therefore it has no relevance | |
461 | return; |
|
461 | return; | |
462 | } else { |
|
462 | } else { | |
463 | // the removed data is in the mapped area or before it |
|
463 | // the removed data is in the mapped area or before it | |
464 | // update needed |
|
464 | // update needed | |
465 |
|
465 | |||
466 | // check how many items need to be removed from the xychartitem storage |
|
466 | // check how many items need to be removed from the xychartitem storage | |
467 | // the number equals the number of items that are removed and that lay before |
|
467 | // the number equals the number of items that are removed and that lay before | |
468 | // or in the mapped area. Items that lay beyond the map do not count |
|
468 | // or in the mapped area. Items that lay beyond the map do not count | |
469 | // the max is the current number of items in storage (count()) |
|
469 | // the max is the current number of items in storage (count()) | |
470 | int itemsToRemove = qMin(count(), qMin(end, d->m_mapFirst + d->m_mapCount - 1) - start + 1); |
|
470 | int itemsToRemove = qMin(count(), qMin(end, d->m_mapFirst + d->m_mapCount - 1) - start + 1); | |
471 | for (int i = 0; i < itemsToRemove; i++) |
|
471 | for (int i = 0; i < itemsToRemove; i++) | |
472 | emit d->pointRemoved(start); |
|
472 | emit d->pointRemoved(start); | |
473 | } |
|
473 | } | |
474 | } else { |
|
474 | } else { | |
475 | // map is not limited (it included all the items starting from m_mapFirst till the end of model) |
|
475 | // map is not limited (it included all the items starting from m_mapFirst till the end of model) | |
476 | for (int i = 0; i < end - start + 1; i++) |
|
476 | for (int i = 0; i < end - start + 1; i++) | |
477 | emit d->pointRemoved(start); |
|
477 | emit d->pointRemoved(start); | |
478 | } |
|
478 | } | |
479 | } |
|
479 | } | |
480 |
|
480 | |||
481 | /*! |
|
481 | /*! | |
482 | \internal |
|
482 | \internal | |
483 | */ |
|
483 | */ | |
484 | void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end) |
|
484 | void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |
485 | { |
|
485 | { | |
486 |
|
486 | |||
487 | Q_UNUSED(parent) |
|
487 | Q_UNUSED(parent) | |
488 | Q_UNUSED(end) |
|
488 | Q_UNUSED(end) | |
489 | Q_D(QXYSeries); |
|
489 | Q_D(QXYSeries); | |
490 | // how many items there were before data was removed |
|
490 | // how many items there were before data was removed | |
491 | // int oldCount = count() - 1; |
|
491 | // int oldCount = count() - 1; | |
492 |
|
492 | |||
493 | if (d->m_mapLimited) { |
|
493 | if (d->m_mapLimited) { | |
494 | if (start >= d->m_mapFirst + d->m_mapCount) { |
|
494 | if (start >= d->m_mapFirst + d->m_mapCount) { | |
495 | // the removed data is below mapped area |
|
495 | // the removed data is below mapped area | |
496 | // therefore it has no relevance |
|
496 | // therefore it has no relevance | |
497 | return; |
|
497 | return; | |
498 | } else { |
|
498 | } else { | |
499 | // if the current items count in the whole model is bigger than the index of the last item |
|
499 | // if the current items count in the whole model is bigger than the index of the last item | |
500 | // that was removed than it means there are some extra items available |
|
500 | // that was removed than it means there are some extra items available | |
501 |
|
501 | |||
502 | int removedItemsCount = qMin(count(), qMin(end, d->m_mapFirst + d->m_mapCount - 1) - start + 1); |
|
502 | int removedItemsCount = qMin(count(), qMin(end, d->m_mapFirst + d->m_mapCount - 1) - start + 1); | |
503 | int extraItemsAvailable = 0; |
|
503 | int extraItemsAvailable = 0; | |
504 | if (d->m_mapOrientation == Qt::Vertical) { |
|
504 | if (d->m_mapOrientation == Qt::Vertical) { | |
505 | extraItemsAvailable = qMax(d->m_model->rowCount() + (end - start + 1) - qMax(end + 1, d->m_mapFirst + d->m_mapCount), 0); |
|
505 | extraItemsAvailable = qMax(d->m_model->rowCount() + (end - start + 1) - qMax(end + 1, d->m_mapFirst + d->m_mapCount), 0); | |
506 | } else { |
|
506 | } else { | |
507 | extraItemsAvailable = qMax(d->m_model->columnCount() + (end - start + 1) - qMax(end + 1, d->m_mapFirst + d->m_mapCount), 0); |
|
507 | extraItemsAvailable = qMax(d->m_model->columnCount() + (end - start + 1) - qMax(end + 1, d->m_mapFirst + d->m_mapCount), 0); | |
508 | } |
|
508 | } | |
509 |
|
509 | |||
510 | // if there are excess items available (below the mapped area) use them to repopulate mapped area |
|
510 | // if there are excess items available (below the mapped area) use them to repopulate mapped area | |
511 | int toBeAdded = qMin(extraItemsAvailable, removedItemsCount); |
|
511 | int toBeAdded = qMin(extraItemsAvailable, removedItemsCount); | |
512 | for (int k = 0; k < toBeAdded; k++) |
|
512 | for (int k = 0; k < toBeAdded; k++) | |
513 | emit d->pointAdded(d->m_mapFirst + d->m_mapCount - removedItemsCount + k); |
|
513 | emit d->pointAdded(d->m_mapFirst + d->m_mapCount - removedItemsCount + k); | |
514 | } |
|
514 | } | |
515 | } else { |
|
515 | } else { | |
516 | // data was removed from XYSeries interal storage. Nothing more to do |
|
516 | // data was removed from XYSeries interal storage. Nothing more to do | |
517 | } |
|
517 | } | |
518 | } |
|
518 | } | |
519 |
|
519 | |||
520 | /*! |
|
520 | /*! | |
521 | \fn bool QXYSeries::setModel(QAbstractItemModel *model) |
|
521 | \fn bool QXYSeries::setModel(QAbstractItemModel *model) | |
522 | Sets the \a model to be used as a data source |
|
522 | Sets the \a model to be used as a data source | |
523 | \sa setModelMapping(), setModelMappingRange() |
|
523 | \sa setModelMapping(), setModelMappingRange() | |
524 | */ |
|
524 | */ | |
525 | bool QXYSeries::setModel(QAbstractItemModel *model) |
|
525 | bool QXYSeries::setModel(QAbstractItemModel *model) | |
526 | { |
|
526 | { | |
527 | Q_D(QXYSeries); |
|
527 | Q_D(QXYSeries); | |
528 | // disconnect signals from old model |
|
528 | // disconnect signals from old model | |
529 | if (d->m_model) { |
|
529 | if (d->m_model) { | |
530 | QObject::disconnect(d->m_model, 0, this, 0); |
|
530 | QObject::disconnect(d->m_model, 0, this, 0); | |
531 | d->m_mapX = -1; |
|
531 | d->m_mapX = -1; | |
532 | d->m_mapY = -1; |
|
532 | d->m_mapY = -1; | |
533 | d->m_mapFirst = 0; |
|
533 | d->m_mapFirst = 0; | |
534 | d->m_mapCount = 0; |
|
534 | d->m_mapCount = 0; | |
535 | d->m_mapLimited = false; |
|
535 | d->m_mapLimited = false; | |
536 | d->m_mapOrientation = Qt::Vertical; |
|
536 | d->m_mapOrientation = Qt::Vertical; | |
537 | } |
|
537 | } | |
538 |
|
538 | |||
539 | // set new model |
|
539 | // set new model | |
540 | if (model) { |
|
540 | if (model) { | |
541 | d->m_model = model; |
|
541 | d->m_model = model; | |
542 | return true; |
|
542 | return true; | |
543 | } else { |
|
543 | } else { | |
544 | d->m_model = 0; |
|
544 | d->m_model = 0; | |
545 | return false; |
|
545 | return false; | |
546 | } |
|
546 | } | |
547 | } |
|
547 | } | |
548 |
|
548 | |||
549 | /*! |
|
549 | /*! | |
550 | \fn bool QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) |
|
550 | \fn bool QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) | |
551 | Sets the \a modelX to be used as a data source for x coordinate and \a modelY to be used |
|
551 | Sets the \a modelX to be used as a data source for x coordinate and \a modelY to be used | |
552 | as a data source for y coordinate. The \a orientation paramater specifies whether the data |
|
552 | as a data source for y coordinate. The \a orientation paramater specifies whether the data | |
553 | is in columns or in rows. |
|
553 | is in columns or in rows. | |
554 | \sa setModel(), setModelMappingRange() |
|
554 | \sa setModel(), setModelMappingRange() | |
555 | */ |
|
555 | */ | |
556 | void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) |
|
556 | void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) | |
557 | { |
|
557 | { | |
558 | Q_D(QXYSeries); |
|
558 | Q_D(QXYSeries); | |
559 | if (d->m_model == 0) |
|
559 | if (d->m_model == 0) | |
560 | return; |
|
560 | return; | |
561 | d->m_mapX = modelX; |
|
561 | d->m_mapX = modelX; | |
562 | d->m_mapY = modelY; |
|
562 | d->m_mapY = modelY; | |
563 | d->m_mapFirst = 0; |
|
563 | d->m_mapFirst = 0; | |
564 | d->m_mapOrientation = orientation; |
|
564 | d->m_mapOrientation = orientation; | |
565 | if (d->m_mapOrientation == Qt::Vertical) { |
|
565 | if (d->m_mapOrientation == Qt::Vertical) { | |
566 | connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
566 | connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
567 | connect(d->m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); |
|
567 | connect(d->m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); | |
568 | connect(d->m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
568 | connect(d->m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
569 | connect(d->m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); |
|
569 | connect(d->m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); | |
570 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
570 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
571 | } else { |
|
571 | } else { | |
572 | connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
572 | connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
573 | connect(d->m_model,SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); |
|
573 | connect(d->m_model,SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); | |
574 | connect(d->m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
574 | connect(d->m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
575 | connect(d->m_model, SIGNAL(columnsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); |
|
575 | connect(d->m_model, SIGNAL(columnsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); | |
576 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
576 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
577 | } |
|
577 | } | |
578 | } |
|
578 | } | |
579 |
|
579 | |||
580 | /*! |
|
580 | /*! | |
581 | \fn bool QXYSeries::setModelMappingRange(int first, int count) |
|
581 | \fn bool QXYSeries::setModelMappingRange(int first, int count) | |
582 | Allows limiting the model mapping. |
|
582 | Allows limiting the model mapping. | |
583 | Parameter \a first specifies which element of the model should be used as a first one of the series. |
|
583 | Parameter \a first specifies which element of the model should be used as a first one of the series. | |
584 | Parameter \a count specifies how many elements should be mapped. If count is not specified (defaults to -1) |
|
584 | Parameter \a count specifies how many elements should be mapped. If count is not specified (defaults to -1) | |
585 | then all the items following \a first item in a model are used. |
|
585 | then all the items following \a first item in a model are used. | |
586 | \sa setModel(), setModelMapping() |
|
586 | \sa setModel(), setModelMapping() | |
587 | */ |
|
587 | */ | |
588 | void QXYSeries::setModelMappingRange(int first, int count) |
|
588 | void QXYSeries::setModelMappingRange(int first, int count) | |
589 | { |
|
589 | { | |
590 | Q_D(QXYSeries); |
|
590 | Q_D(QXYSeries); | |
591 | d->m_mapFirst = first; |
|
591 | d->m_mapFirst = first; | |
592 | if (count == 0) { |
|
592 | if (count == 0) { | |
593 | d->m_mapLimited = false; |
|
593 | d->m_mapLimited = false; | |
594 | } else { |
|
594 | } else { | |
595 | d->m_mapCount = count; |
|
595 | d->m_mapCount = count; | |
596 | d->m_mapLimited = true; |
|
596 | d->m_mapLimited = true; | |
597 | } |
|
597 | } | |
598 | } |
|
598 | } | |
599 |
|
599 | |||
600 | int QXYSeries::mapFirst() const |
|
600 | int QXYSeries::mapFirst() const | |
601 | { |
|
601 | { | |
602 | Q_D(const QXYSeries); |
|
602 | Q_D(const QXYSeries); | |
603 | return d->m_mapFirst; |
|
603 | return d->m_mapFirst; | |
604 | } |
|
604 | } | |
605 |
|
605 | |||
606 | int QXYSeries::mapCount() const |
|
606 | int QXYSeries::mapCount() const | |
607 | { |
|
607 | { | |
608 | Q_D(const QXYSeries); |
|
608 | Q_D(const QXYSeries); | |
609 | return d->m_mapCount; |
|
609 | return d->m_mapCount; | |
610 | } |
|
610 | } | |
611 |
|
611 | |||
612 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
612 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
613 |
|
613 | |||
614 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q): QSeriesPrivate(q), |
|
614 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q): QSeriesPrivate(q), | |
615 | m_mapX(-1), |
|
615 | m_mapX(-1), | |
616 | m_mapY(-1), |
|
616 | m_mapY(-1), | |
617 | m_mapFirst(0), |
|
617 | m_mapFirst(0), | |
618 | m_mapCount(0), |
|
618 | m_mapCount(0), | |
619 | m_mapLimited(false), |
|
619 | m_mapLimited(false), | |
620 | m_mapOrientation( Qt::Vertical), |
|
620 | m_mapOrientation( Qt::Vertical), | |
621 | m_pointsVisible(false) |
|
621 | m_pointsVisible(false) | |
622 | { |
|
622 | { | |
623 |
|
623 | |||
624 | } |
|
624 | } | |
625 |
|
625 | |||
626 | void QXYSeriesPrivate::scaleDomain(Domain& domain) |
|
626 | void QXYSeriesPrivate::scaleDomain(Domain& domain) | |
627 | { |
|
627 | { | |
628 | qreal minX(domain.minX()); |
|
628 | qreal minX(domain.minX()); | |
629 | qreal minY(domain.minY()); |
|
629 | qreal minY(domain.minY()); | |
630 | qreal maxX(domain.maxX()); |
|
630 | qreal maxX(domain.maxX()); | |
631 | qreal maxY(domain.maxY()); |
|
631 | qreal maxY(domain.maxY()); | |
632 | int tickXCount(domain.tickXCount()); |
|
632 | int tickXCount(domain.tickXCount()); | |
633 | int tickYCount(domain.tickYCount()); |
|
633 | int tickYCount(domain.tickYCount()); | |
634 |
|
634 | |||
635 | Q_Q(QXYSeries); |
|
635 | Q_Q(QXYSeries); | |
636 | for (int i = 0; i < q->count(); i++) |
|
636 | for (int i = 0; i < q->count(); i++) | |
637 | { |
|
637 | { | |
638 | qreal x = q->x(i); |
|
638 | qreal x = q->x(i); | |
639 | qreal y = q->y(i); |
|
639 | qreal y = q->y(i); | |
640 | minX = qMin(minX, x); |
|
640 | minX = qMin(minX, x); | |
641 | minY = qMin(minY, y); |
|
641 | minY = qMin(minY, y); | |
642 | maxX = qMax(maxX, x); |
|
642 | maxX = qMax(maxX, x); | |
643 | maxY = qMax(maxY, y); |
|
643 | maxY = qMax(maxY, y); | |
644 | } |
|
644 | } | |
645 |
|
645 | |||
646 | domain.setRangeX(minX,maxX,tickXCount); |
|
646 | domain.setRangeX(minX,maxX,tickXCount); | |
647 | domain.setRangeY(minY,maxY,tickYCount); |
|
647 | domain.setRangeY(minY,maxY,tickYCount); | |
648 | } |
|
648 | } | |
649 |
|
649 | |||
650 | QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend) |
|
650 | QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend) | |
651 | { |
|
651 | { | |
652 | Q_Q(QXYSeries); |
|
652 | Q_Q(QXYSeries); | |
653 | QList<LegendMarker*> list; |
|
653 | QList<LegendMarker*> list; | |
654 | return list << new XYLegendMarker(q,legend); |
|
654 | return list << new XYLegendMarker(q,legend); | |
655 | } |
|
655 | } | |
656 |
|
656 | |||
657 | #include "moc_qxyseries.cpp" |
|
657 | #include "moc_qxyseries.cpp" | |
658 | #include "moc_qxyseries_p.cpp" |
|
658 | #include "moc_qxyseries_p.cpp" | |
659 |
|
659 | |||
660 | QTCOMMERCIALCHART_END_NAMESPACE |
|
660 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,196 +1,202 | |||||
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 "xychartitem_p.h" |
|
21 | #include "xychartitem_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 "chartanimator_p.h" |
|
25 | #include "chartanimator_p.h" | |
26 | #include <QPainter> |
|
26 | #include <QPainter> | |
27 | #include <QGraphicsSceneMouseEvent> |
|
27 | #include <QGraphicsSceneMouseEvent> | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | //TODO: optimize : remove points which are not visible |
|
32 | //TODO: optimize : remove points which are not visible | |
33 |
|
33 | |||
34 | XYChartItem::XYChartItem(QXYSeries *series, ChartPresenter *presenter):ChartItem(presenter), |
|
34 | XYChartItem::XYChartItem(QXYSeries *series, ChartPresenter *presenter):ChartItem(presenter), | |
35 | m_minX(0), |
|
35 | m_minX(0), | |
36 | m_maxX(0), |
|
36 | m_maxX(0), | |
37 | m_minY(0), |
|
37 | m_minY(0), | |
38 | m_maxY(0), |
|
38 | m_maxY(0), | |
39 | m_series(series) |
|
39 | m_series(series) | |
40 | { |
|
40 | { | |
41 | connect(series->d_func(),SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int))); |
|
41 | connect(series->d_func(),SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int))); | |
42 | connect(series->d_func(),SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int))); |
|
42 | connect(series->d_func(),SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int))); | |
43 | connect(series->d_func(),SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int))); |
|
43 | connect(series->d_func(),SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int))); | |
44 | connect(this,SIGNAL(clicked(const QPointF&)),series,SIGNAL(clicked(const QPointF&))); |
|
44 | connect(this,SIGNAL(clicked(const QPointF&)),series,SIGNAL(clicked(const QPointF&))); | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | QPointF XYChartItem::calculateGeometryPoint(const QPointF &point) const |
|
47 | QPointF XYChartItem::calculateGeometryPoint(const QPointF &point) const | |
48 | { |
|
48 | { | |
49 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); |
|
49 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); | |
50 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); |
|
50 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); | |
51 | qreal x = (point.x() - m_minX)* deltaX; |
|
51 | qreal x = (point.x() - m_minX)* deltaX; | |
52 | qreal y = (point.y() - m_minY)*-deltaY + m_size.height(); |
|
52 | qreal y = (point.y() - m_minY)*-deltaY + m_size.height(); | |
53 | return QPointF(x,y); |
|
53 | return QPointF(x,y); | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 |
|
56 | |||
57 | QPointF XYChartItem::calculateGeometryPoint(int index) const |
|
57 | QPointF XYChartItem::calculateGeometryPoint(int index) const | |
58 | { |
|
58 | { | |
59 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); |
|
59 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); | |
60 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); |
|
60 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); | |
61 | qreal x = (m_series->x(index) - m_minX)* deltaX; |
|
61 | qreal x = (m_series->x(index) - m_minX)* deltaX; | |
62 | qreal y = (m_series->y(index) - m_minY)*-deltaY + m_size.height(); |
|
62 | qreal y = (m_series->y(index) - m_minY)*-deltaY + m_size.height(); | |
63 | return QPointF(x,y); |
|
63 | return QPointF(x,y); | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | QVector<QPointF> XYChartItem::calculateGeometryPoints() const |
|
66 | QVector<QPointF> XYChartItem::calculateGeometryPoints() const | |
67 | { |
|
67 | { | |
68 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); |
|
68 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); | |
69 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); |
|
69 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); | |
70 |
|
70 | |||
71 | QVector<QPointF> points; |
|
71 | QVector<QPointF> points; | |
72 | points.reserve(m_series->count()); |
|
72 | points.reserve(m_series->count()); | |
73 | for (int i = 0; i < m_series->count(); ++i) { |
|
73 | for (int i = 0; i < m_series->count(); ++i) { | |
74 | qreal x = (m_series->x(i) - m_minX)* deltaX; |
|
74 | qreal x = (m_series->x(i) - m_minX)* deltaX; | |
75 | qreal y = (m_series->y(i) - m_minY)*-deltaY + m_size.height(); |
|
75 | qreal y = (m_series->y(i) - m_minY)*-deltaY + m_size.height(); | |
76 | points << QPointF(x,y); |
|
76 | points << QPointF(x,y); | |
77 | } |
|
77 | } | |
78 | return points; |
|
78 | return points; | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | QPointF XYChartItem::calculateDomainPoint(const QPointF &point) const |
|
81 | QPointF XYChartItem::calculateDomainPoint(const QPointF &point) const | |
82 | { |
|
82 | { | |
83 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); |
|
83 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); | |
84 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); |
|
84 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); | |
85 | qreal x = point.x()/deltaX +m_minX; |
|
85 | qreal x = point.x()/deltaX +m_minX; | |
86 | qreal y = (point.y()-m_size.height())/(-deltaY)+ m_minY; |
|
86 | qreal y = (point.y()-m_size.height())/(-deltaY)+ m_minY; | |
87 | return QPointF(x,y); |
|
87 | return QPointF(x,y); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void XYChartItem::updateLayout(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index) |
|
90 | void XYChartItem::updateLayout(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index) | |
91 | { |
|
91 | { | |
92 | if (animator()) { |
|
92 | if (animator()) { | |
93 | animator()->updateLayout(this,oldPoints,newPoints,index); |
|
93 | animator()->updateLayout(this,oldPoints,newPoints,index); | |
94 | } else { |
|
94 | } else { | |
95 | setLayout(newPoints); |
|
95 | setLayout(newPoints); | |
96 | } |
|
96 | } | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void XYChartItem::setLayout(QVector<QPointF> &points) |
|
99 | void XYChartItem::setLayout(QVector<QPointF> &points) | |
100 | { |
|
100 | { | |
101 | m_points = points; |
|
101 | m_points = points; | |
102 | update(); |
|
102 | update(); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | //handlers |
|
105 | //handlers | |
106 |
|
106 | |||
107 | void XYChartItem::handlePointAdded(int index) |
|
107 | void XYChartItem::handlePointAdded(int index) | |
108 | { |
|
108 | { | |
109 | QVector<QPointF> points = m_points; |
|
109 | QVector<QPointF> points = m_points; | |
110 | QPointF point; |
|
110 | QPointF point; | |
111 | if (m_series->model()) { |
|
111 | if (m_series->model()) { | |
112 | point = calculateGeometryPoint(index - m_series->mapFirst()); |
|
112 | point = calculateGeometryPoint(index - m_series->mapFirst()); | |
113 |
|
|
113 | if (index < m_series->mapFirst()) { | |
114 | updateLayout(m_points, points, index - m_series->mapFirst()); |
|
114 | points.insert(0, point); | |
|
115 | updateLayout(m_points, points, 0); | |||
|
116 | } | |||
|
117 | else { | |||
|
118 | points.insert(index - m_series->mapFirst(), point); | |||
|
119 | updateLayout(m_points, points, index - m_series->mapFirst()); | |||
|
120 | } | |||
115 | } |
|
121 | } | |
116 | else { |
|
122 | else { | |
117 | // this checks do not work correctly if model is set |
|
123 | // this checks do not work correctly if model is set | |
118 | Q_ASSERT(index<m_series->count()); |
|
124 | Q_ASSERT(index<m_series->count()); | |
119 | Q_ASSERT(index>=0); |
|
125 | Q_ASSERT(index>=0); | |
120 | point = calculateGeometryPoint(index); |
|
126 | point = calculateGeometryPoint(index); | |
121 | points.insert(index, point); |
|
127 | points.insert(index, point); | |
122 | updateLayout(m_points, points, index); |
|
128 | updateLayout(m_points, points, index); | |
123 | } |
|
129 | } | |
124 | update(); |
|
130 | update(); | |
125 | } |
|
131 | } | |
126 | void XYChartItem::handlePointRemoved(int index) |
|
132 | void XYChartItem::handlePointRemoved(int index) | |
127 | { |
|
133 | { | |
128 | QVector<QPointF> points = m_points; |
|
134 | QVector<QPointF> points = m_points; | |
129 | if (m_series->model()) { |
|
135 | if (m_series->model()) { | |
130 | if (index < m_series->mapFirst()) |
|
136 | if (index < m_series->mapFirst()) | |
131 | points.remove(0); |
|
137 | points.remove(0); | |
132 | else |
|
138 | else | |
133 | points.remove(index - m_series->mapFirst()); |
|
139 | points.remove(index - m_series->mapFirst()); | |
134 | updateLayout(m_points, points, index - m_series->mapFirst()); |
|
140 | updateLayout(m_points, points, index - m_series->mapFirst()); | |
135 | } |
|
141 | } | |
136 | else { |
|
142 | else { | |
137 | // this checks do not work correctly if model is set |
|
143 | // this checks do not work correctly if model is set | |
138 | Q_ASSERT(index<m_series->count() + 1); |
|
144 | Q_ASSERT(index<m_series->count() + 1); | |
139 | Q_ASSERT(index>=0); |
|
145 | Q_ASSERT(index>=0); | |
140 | points.remove(index); |
|
146 | points.remove(index); | |
141 | updateLayout(m_points, points, index); |
|
147 | updateLayout(m_points, points, index); | |
142 | } |
|
148 | } | |
143 | update(); |
|
149 | update(); | |
144 | } |
|
150 | } | |
145 |
|
151 | |||
146 | void XYChartItem::handlePointReplaced(int index) |
|
152 | void XYChartItem::handlePointReplaced(int index) | |
147 | { |
|
153 | { | |
148 | Q_ASSERT(index<m_series->count()); |
|
154 | Q_ASSERT(index<m_series->count()); | |
149 | Q_ASSERT(index>=0); |
|
155 | Q_ASSERT(index>=0); | |
150 | QPointF point = calculateGeometryPoint(index); |
|
156 | QPointF point = calculateGeometryPoint(index); | |
151 | QVector<QPointF> points = m_points; |
|
157 | QVector<QPointF> points = m_points; | |
152 | points.replace(index,point); |
|
158 | points.replace(index,point); | |
153 | updateLayout(m_points,points,index); |
|
159 | updateLayout(m_points,points,index); | |
154 | update(); |
|
160 | update(); | |
155 | } |
|
161 | } | |
156 |
|
162 | |||
157 | void XYChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
163 | void XYChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
158 | { |
|
164 | { | |
159 | m_minX=minX; |
|
165 | m_minX=minX; | |
160 | m_maxX=maxX; |
|
166 | m_maxX=maxX; | |
161 | m_minY=minY; |
|
167 | m_minY=minY; | |
162 | m_maxY=maxY; |
|
168 | m_maxY=maxY; | |
163 |
|
169 | |||
164 | if (isEmpty()) return; |
|
170 | if (isEmpty()) return; | |
165 | QVector<QPointF> points = calculateGeometryPoints(); |
|
171 | QVector<QPointF> points = calculateGeometryPoints(); | |
166 | updateLayout(m_points,points); |
|
172 | updateLayout(m_points,points); | |
167 | update(); |
|
173 | update(); | |
168 | } |
|
174 | } | |
169 |
|
175 | |||
170 | void XYChartItem::handleGeometryChanged(const QRectF &rect) |
|
176 | void XYChartItem::handleGeometryChanged(const QRectF &rect) | |
171 | { |
|
177 | { | |
172 | Q_ASSERT(rect.isValid()); |
|
178 | Q_ASSERT(rect.isValid()); | |
173 | m_size=rect.size(); |
|
179 | m_size=rect.size(); | |
174 | m_clipRect=rect.translated(-rect.topLeft()); |
|
180 | m_clipRect=rect.translated(-rect.topLeft()); | |
175 | setPos(rect.topLeft()); |
|
181 | setPos(rect.topLeft()); | |
176 |
|
182 | |||
177 | if (isEmpty()) return; |
|
183 | if (isEmpty()) return; | |
178 | QVector<QPointF> points = calculateGeometryPoints(); |
|
184 | QVector<QPointF> points = calculateGeometryPoints(); | |
179 | updateLayout(m_points,points); |
|
185 | updateLayout(m_points,points); | |
180 | update(); |
|
186 | update(); | |
181 | } |
|
187 | } | |
182 |
|
188 | |||
183 |
|
189 | |||
184 | bool XYChartItem::isEmpty() |
|
190 | bool XYChartItem::isEmpty() | |
185 | { |
|
191 | { | |
186 | return !m_clipRect.isValid() || qFuzzyIsNull(m_maxX - m_minX) || qFuzzyIsNull(m_maxY - m_minY); |
|
192 | return !m_clipRect.isValid() || qFuzzyIsNull(m_maxX - m_minX) || qFuzzyIsNull(m_maxY - m_minY); | |
187 | } |
|
193 | } | |
188 |
|
194 | |||
189 | void XYChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
195 | void XYChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
190 | { |
|
196 | { | |
191 | emit clicked(calculateDomainPoint(event->pos())); |
|
197 | emit clicked(calculateDomainPoint(event->pos())); | |
192 | } |
|
198 | } | |
193 |
|
199 | |||
194 | #include "moc_xychartitem_p.cpp" |
|
200 | #include "moc_xychartitem_p.cpp" | |
195 |
|
201 | |||
196 | QTCOMMERCIALCHART_END_NAMESPACE |
|
202 | QTCOMMERCIALCHART_END_NAMESPACE |
1 | NO CONTENT: file renamed from examples/tablemodelchart/customtablemodel.cpp to test/tablemodelchart/customtablemodel.cpp |
|
NO CONTENT: file renamed from examples/tablemodelchart/customtablemodel.cpp to test/tablemodelchart/customtablemodel.cpp |
1 | NO CONTENT: file renamed from examples/tablemodelchart/customtablemodel.h to test/tablemodelchart/customtablemodel.h |
|
NO CONTENT: file renamed from examples/tablemodelchart/customtablemodel.h to test/tablemodelchart/customtablemodel.h |
1 | NO CONTENT: file renamed from examples/tablemodelchart/main.cpp to test/tablemodelchart/main.cpp |
|
NO CONTENT: file renamed from examples/tablemodelchart/main.cpp to test/tablemodelchart/main.cpp |
@@ -1,22 +1,16 | |||||
1 | #------------------------------------------------- |
|
1 | !include( ../test.pri ) { | |
2 | # |
|
2 | error( "Couldn't find the test.pri file!" ) | |
3 | # Project created by QtCreator 2012-03-08T14:30:24 |
|
|||
4 | # |
|
|||
5 | #------------------------------------------------- |
|
|||
6 |
|
||||
7 | !include( ../examples.pri ) { |
|
|||
8 | error( "Couldn't find the examples.pri file!" ) |
|
|||
9 | } |
|
3 | } | |
10 |
|
4 | |||
11 | QT += core gui |
|
5 | QT += core gui | |
12 |
|
6 | |||
13 | TARGET = tablemodelchart |
|
7 | TARGET = tablemodelchart | |
14 | TEMPLATE = app |
|
8 | TEMPLATE = app | |
15 |
|
9 | |||
16 |
|
10 | |||
17 | SOURCES += main.cpp\ |
|
11 | SOURCES += main.cpp\ | |
18 | tablewidget.cpp \ |
|
12 | tablewidget.cpp \ | |
19 | customtablemodel.cpp |
|
13 | customtablemodel.cpp | |
20 |
|
14 | |||
21 | HEADERS += tablewidget.h \ |
|
15 | HEADERS += tablewidget.h \ | |
22 | customtablemodel.h |
|
16 | customtablemodel.h |
1 | NO CONTENT: file renamed from examples/tablemodelchart/tablewidget.cpp to test/tablemodelchart/tablewidget.cpp |
|
NO CONTENT: file renamed from examples/tablemodelchart/tablewidget.cpp to test/tablemodelchart/tablewidget.cpp |
1 | NO CONTENT: file renamed from examples/tablemodelchart/tablewidget.h to test/tablemodelchart/tablewidget.h |
|
NO CONTENT: file renamed from examples/tablemodelchart/tablewidget.h to test/tablemodelchart/tablewidget.h |
General Comments 0
You need to be logged in to leave comments.
Login now