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