##// END OF EJS Templates
Added a new QXYSeries::replace override for performance reasons....
Tero Ahola -
r1783:86f3ac473a35
parent child
Show More
@@ -0,0 +1,55
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "datasource.h"
22 #include <QXYSeries>
23 #include <QDebug>
24
25 QTCOMMERCIALCHART_USE_NAMESPACE
26
27 DataSource::DataSource(QObject *parent) :
28 QObject(parent),
29 m_index(0)
30 {
31 const int rowCount = 5;
32 const int colCount = 1024;
33
34 for (int i(0); i < rowCount; i++) {
35 QList<QPointF> points;
36 for (int j(0); j < colCount; j++) {
37 qreal x = j;
38 qreal y = sin(3.14159265358979 / 50 * x) + 0.5 + (qreal) rand() / (qreal) RAND_MAX;
39 points.append(QPointF(x, y));
40 }
41 m_data.append(points);
42 }
43 }
44
45 void DataSource::update(QAbstractSeries *series)
46 {
47 QXYSeries *xySeries = qobject_cast<QXYSeries *>(series);
48 Q_ASSERT(xySeries);
49
50 QList<QPointF> points = m_data.at(m_index);
51 //xySeries->clear();
52 //xySeries->append(points);
53 xySeries->replace(points);
54 m_index = (m_index + 1) % m_data.count();
55 }
@@ -0,0 +1,45
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #ifndef DATASOURCE_H
22 #define DATASOURCE_H
23
24 #include <QObject>
25 #include <QAbstractSeries>
26
27 QTCOMMERCIALCHART_USE_NAMESPACE
28
29 class DataSource : public QObject
30 {
31 Q_OBJECT
32 public:
33 explicit DataSource(QObject *parent = 0);
34
35 signals:
36
37 public slots:
38 void update(QAbstractSeries *series);
39
40 private:
41 QList<QList<QPointF> > m_data;
42 int m_index;
43 };
44
45 #endif // DATASOURCE_H
@@ -0,0 +1,42
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include <QtGui/QApplication>
22 #include <QDeclarativeEngine>
23 #include <QDeclarativeContext>
24 #include <QGLWidget>
25 #include "qmlapplicationviewer.h"
26 #include "datasource.h"
27
28 Q_DECL_EXPORT int main(int argc, char *argv[])
29 {
30 QScopedPointer<QApplication> app(createApplication(argc, argv));
31 QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
32
33 DataSource dataSource;
34 viewer->rootContext()->setContextProperty("dataSource", &dataSource);
35
36 viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
37 viewer->setSource(QUrl("qrc:/qml/qmloscilloscope/main.qml"));
38 viewer->setViewport(new QGLWidget());
39 viewer->showExpanded();
40
41 return app->exec();
42 }
@@ -0,0 +1,72
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
23
24 Rectangle {
25 width: 400
26 height: 300
27
28 ChartView {
29 id: chartView
30 anchors.fill: parent
31 title: "Oscilloscope"
32 animationOptions: ChartView.NoAnimation
33
34 ValuesAxis {
35 id: axisY
36 min: -1
37 max: 3
38 }
39
40 ValuesAxis {
41 id: axisX
42 min: 0
43 max: 1000
44 }
45
46 LineSeries {
47 id: lineSeries1
48 name: "signal 1"
49 }
50 LineSeries {
51 id: lineSeries2
52 name: "signal 2"
53 }
54 }
55
56 Timer {
57 interval: 16 // 60 Hz
58 running: true
59 repeat: true
60 onTriggered: {
61 dataSource.update(lineSeries1);
62 dataSource.update(lineSeries2);
63 }
64 }
65
66 Component.onCompleted: {
67 chartView.setAxisX(axisX, lineSeries1);
68 chartView.setAxisY(axisY, lineSeries1);
69 chartView.setAxisX(axisX, lineSeries2);
70 chartView.setAxisY(axisY, lineSeries2);
71 }
72 }
@@ -0,0 +1,200
1 // checksum 0x78c version 0x60010
2 /*
3 This file was generated by the Qt Quick Application wizard of Qt Creator.
4 QmlApplicationViewer is a convenience class containing mobile device specific
5 code such as screen orientation handling. Also QML paths and debugging are
6 handled here.
7 It is recommended not to modify this file, since newer versions of Qt Creator
8 may offer an updated version of it.
9 */
10
11 #include "qmlapplicationviewer.h"
12
13 #include <QtCore/QDir>
14 #include <QtCore/QFileInfo>
15 #include <QtDeclarative/QDeclarativeComponent>
16 #include <QtDeclarative/QDeclarativeEngine>
17 #include <QtDeclarative/QDeclarativeContext>
18 #include <QtGui/QApplication>
19
20 #include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN
21
22 #ifdef HARMATTAN_BOOSTER
23 #include <MDeclarativeCache>
24 #endif
25
26 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
27
28 #include <qt_private/qdeclarativedebughelper_p.h>
29
30 #if !defined(NO_JSDEBUGGER)
31 #include <jsdebuggeragent.h>
32 #endif
33 #if !defined(NO_QMLOBSERVER)
34 #include <qdeclarativeviewobserver.h>
35 #endif
36
37 // Enable debugging before any QDeclarativeEngine is created
38 struct QmlJsDebuggingEnabler
39 {
40 QmlJsDebuggingEnabler()
41 {
42 QDeclarativeDebugHelper::enableDebugging();
43 }
44 };
45
46 // Execute code in constructor before first QDeclarativeEngine is instantiated
47 static QmlJsDebuggingEnabler enableDebuggingHelper;
48
49 #endif // QMLJSDEBUGGER
50
51 class QmlApplicationViewerPrivate
52 {
53 QmlApplicationViewerPrivate(QDeclarativeView *view_) : view(view_) {}
54
55 QString mainQmlFile;
56 QDeclarativeView *view;
57 friend class QmlApplicationViewer;
58 QString adjustPath(const QString &path);
59 };
60
61 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
62 {
63 #ifdef Q_OS_UNIX
64 #ifdef Q_OS_MAC
65 if (!QDir::isAbsolutePath(path))
66 return QCoreApplication::applicationDirPath()
67 + QLatin1String("/../Resources/") + path;
68 #else
69 QString pathInInstallDir;
70 const QString applicationDirPath = QCoreApplication::applicationDirPath();
71 pathInInstallDir = QString::fromAscii("%1/../%2").arg(applicationDirPath, path);
72
73 if (QFileInfo(pathInInstallDir).exists())
74 return pathInInstallDir;
75 #endif
76 #endif
77 return path;
78 }
79
80 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent)
81 : QDeclarativeView(parent)
82 , d(new QmlApplicationViewerPrivate(this))
83 {
84 connect(engine(), SIGNAL(quit()), SLOT(close()));
85 setResizeMode(QDeclarativeView::SizeRootObjectToView);
86 // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
87 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
88 #if !defined(NO_JSDEBUGGER)
89 new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
90 #endif
91 #if !defined(NO_QMLOBSERVER)
92 new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
93 #endif
94 #endif
95 }
96
97 QmlApplicationViewer::QmlApplicationViewer(QDeclarativeView *view, QWidget *parent)
98 : QDeclarativeView(parent)
99 , d(new QmlApplicationViewerPrivate(view))
100 {
101 connect(view->engine(), SIGNAL(quit()), view, SLOT(close()));
102 view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
103 // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
104 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
105 #if !defined(NO_JSDEBUGGER)
106 new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
107 #endif
108 #if !defined(NO_QMLOBSERVER)
109 new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
110 #endif
111 #endif
112 }
113
114 QmlApplicationViewer::~QmlApplicationViewer()
115 {
116 delete d;
117 }
118
119 QmlApplicationViewer *QmlApplicationViewer::create()
120 {
121 #ifdef HARMATTAN_BOOSTER
122 return new QmlApplicationViewer(MDeclarativeCache::qDeclarativeView(), 0);
123 #else
124 return new QmlApplicationViewer();
125 #endif
126 }
127
128 void QmlApplicationViewer::setMainQmlFile(const QString &file)
129 {
130 d->mainQmlFile = d->adjustPath(file);
131 d->view->setSource(QUrl::fromLocalFile(d->mainQmlFile));
132 }
133
134 void QmlApplicationViewer::addImportPath(const QString &path)
135 {
136 d->view->engine()->addImportPath(d->adjustPath(path));
137 }
138
139 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
140 {
141 #if defined(Q_OS_SYMBIAN)
142 // If the version of Qt on the device is < 4.7.2, that attribute won't work
143 if (orientation != ScreenOrientationAuto) {
144 const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
145 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
146 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
147 return;
148 }
149 }
150 #endif // Q_OS_SYMBIAN
151
152 Qt::WidgetAttribute attribute;
153 switch (orientation) {
154 #if QT_VERSION < 0x040702
155 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
156 case ScreenOrientationLockPortrait:
157 attribute = static_cast<Qt::WidgetAttribute>(128);
158 break;
159 case ScreenOrientationLockLandscape:
160 attribute = static_cast<Qt::WidgetAttribute>(129);
161 break;
162 default:
163 case ScreenOrientationAuto:
164 attribute = static_cast<Qt::WidgetAttribute>(130);
165 break;
166 #else // QT_VERSION < 0x040702
167 case ScreenOrientationLockPortrait:
168 attribute = Qt::WA_LockPortraitOrientation;
169 break;
170 case ScreenOrientationLockLandscape:
171 attribute = Qt::WA_LockLandscapeOrientation;
172 break;
173 default:
174 case ScreenOrientationAuto:
175 attribute = Qt::WA_AutoOrientation;
176 break;
177 #endif // QT_VERSION < 0x040702
178 };
179 setAttribute(attribute, true);
180 }
181
182 void QmlApplicationViewer::showExpanded()
183 {
184 #if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR)
185 d->view->showFullScreen();
186 #elif defined(Q_WS_MAEMO_5)
187 d->view->showMaximized();
188 #else
189 d->view->show();
190 #endif
191 }
192
193 QApplication *createApplication(int &argc, char **argv)
194 {
195 #ifdef HARMATTAN_BOOSTER
196 return MDeclarativeCache::qApplication(argc, argv);
197 #else
198 return new QApplication(argc, argv);
199 #endif
200 }
@@ -0,0 +1,47
1 // checksum 0x82ed version 0x60010
2 /*
3 This file was generated by the Qt Quick Application wizard of Qt Creator.
4 QmlApplicationViewer is a convenience class containing mobile device specific
5 code such as screen orientation handling. Also QML paths and debugging are
6 handled here.
7 It is recommended not to modify this file, since newer versions of Qt Creator
8 may offer an updated version of it.
9 */
10
11 #ifndef QMLAPPLICATIONVIEWER_H
12 #define QMLAPPLICATIONVIEWER_H
13
14 #include <QtDeclarative/QDeclarativeView>
15
16 class QmlApplicationViewer : public QDeclarativeView
17 {
18 Q_OBJECT
19
20 public:
21 enum ScreenOrientation {
22 ScreenOrientationLockPortrait,
23 ScreenOrientationLockLandscape,
24 ScreenOrientationAuto
25 };
26
27 explicit QmlApplicationViewer(QWidget *parent = 0);
28 virtual ~QmlApplicationViewer();
29
30 static QmlApplicationViewer *create();
31
32 void setMainQmlFile(const QString &file);
33 void addImportPath(const QString &path);
34
35 // Note that this will only have an effect on Symbian and Fremantle.
36 void setOrientation(ScreenOrientation orientation);
37
38 void showExpanded();
39
40 private:
41 explicit QmlApplicationViewer(QDeclarativeView *view, QWidget *parent);
42 class QmlApplicationViewerPrivate *d;
43 };
44
45 QApplication *createApplication(int &argc, char **argv);
46
47 #endif // QMLAPPLICATIONVIEWER_H
@@ -0,0 +1,13
1 QT += declarative
2
3 SOURCES += $$PWD/qmlapplicationviewer.cpp
4 HEADERS += $$PWD/qmlapplicationviewer.h
5 INCLUDEPATH += $$PWD
6
7 # Include JS debugger library if QMLJSDEBUGGER_PATH is set
8 !isEmpty(QMLJSDEBUGGER_PATH) {
9 include($$QMLJSDEBUGGER_PATH/qmljsdebugger-lib.pri)
10 } else {
11 DEFINES -= QMLJSDEBUGGER
12 }
13
@@ -0,0 +1,13
1 !include( ../demos.pri ) {
2 error( "Couldn't find the demos.pri file!" )
3 }
4
5 QT += opengl
6 RESOURCES += resources.qrc
7 SOURCES += main.cpp \
8 datasource.cpp
9
10 include(qmlapplicationviewer/qmlapplicationviewer.pri)
11
12 HEADERS += \
13 datasource.h
@@ -0,0 +1,5
1 <RCC>
2 <qresource prefix="/">
3 <file>qml/qmloscilloscope/main.qml</file>
4 </qresource>
5 </RCC>
@@ -12,4 +12,5 SUBDIRS += chartthemes \
12 qmlf1legends \
12 qmlf1legends \
13 qmlcustomizations \
13 qmlcustomizations \
14 qmlcustommodel \
14 qmlcustommodel \
15 qmloscilloscope \
15 chartviewer
16 chartviewer
@@ -75,6 +75,7 QSplineSeries::QSplineSeries(QObject *parent) :
75 QObject::connect(this,SIGNAL(pointAdded(int)), d, SLOT(updateControlPoints()));
75 QObject::connect(this,SIGNAL(pointAdded(int)), d, SLOT(updateControlPoints()));
76 QObject::connect(this,SIGNAL(pointRemoved(int)), d, SLOT(updateControlPoints()));
76 QObject::connect(this,SIGNAL(pointRemoved(int)), d, SLOT(updateControlPoints()));
77 QObject::connect(this,SIGNAL(pointReplaced(int)), d, SLOT(updateControlPoints()));
77 QObject::connect(this,SIGNAL(pointReplaced(int)), d, SLOT(updateControlPoints()));
78 QObject::connect(this,SIGNAL(pointsReplaced()), d, SLOT(updateControlPoints()));
78 }
79 }
79
80
80 /*!
81 /*!
@@ -98,6 +98,15 QTCOMMERCIALCHART_BEGIN_NAMESPACE
98 */
98 */
99
99
100 /*!
100 /*!
101 \fn void QXYSeries::pointsReplaced()
102 Signal is emitted when all points have been replaced with another points.
103 \sa replace()
104 */
105 /*!
106 \qmlsignal XYSeries::onPointsReplaced()
107 */
108
109 /*!
101 \fn void QXYSeries::pointAdded(int index)
110 \fn void QXYSeries::pointAdded(int index)
102 Signal is emitted when a point has been added at \a index.
111 Signal is emitted when a point has been added at \a index.
103 \sa append(), insert()
112 \sa append(), insert()
@@ -192,7 +201,6 void QXYSeries::append(const QPointF &point)
192 {
201 {
193 Q_D(QXYSeries);
202 Q_D(QXYSeries);
194 d->m_points<<point;
203 d->m_points<<point;
195 // emit d->pointAdded(d->m_points.count()-1);
196 emit pointAdded(d->m_points.count()-1);
204 emit pointAdded(d->m_points.count()-1);
197 }
205 }
198
206
@@ -209,6 +217,7 void QXYSeries::append(const QList<QPointF> &points)
209
217
210 /*!
218 /*!
211 Replaces data point \a oldX \a oldY with data point \a newX \a newY.
219 Replaces data point \a oldX \a oldY with data point \a newX \a newY.
220 \sa QXYSeries::pointReplaced()
212 */
221 */
213 void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY)
222 void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY)
214 {
223 {
@@ -217,6 +226,7 void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY)
217
226
218 /*!
227 /*!
219 Replaces \a oldPoint with \a newPoint.
228 Replaces \a oldPoint with \a newPoint.
229 \sa QXYSeries::pointReplaced()
220 */
230 */
221 void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint)
231 void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint)
222 {
232 {
@@ -228,6 +238,19 void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint)
228 }
238 }
229
239
230 /*!
240 /*!
241 Replaces the current points with \a points. This is faster than replacing data points one by one,
242 or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced()
243 when the points have been replaced.
244 \sa QXYSeries::pointsReplaced()
245 */
246 void QXYSeries::replace(QList<QPointF> points)
247 {
248 Q_D(QXYSeries);
249 d->m_points = points.toVector();
250 emit pointsReplaced();
251 }
252
253 /*!
231 Removes current \a x and \a y value.
254 Removes current \a x and \a y value.
232 */
255 */
233 void QXYSeries::remove(qreal x,qreal y)
256 void QXYSeries::remove(qreal x,qreal y)
@@ -246,7 +269,6 void QXYSeries::remove(const QPointF &point)
246 int index = d->m_points.indexOf(point);
269 int index = d->m_points.indexOf(point);
247 if(index==-1) return;
270 if(index==-1) return;
248 d->m_points.remove(index);
271 d->m_points.remove(index);
249 // emit d->pointRemoved(index);
250 emit pointRemoved(index);
272 emit pointRemoved(index);
251 }
273 }
252
274
@@ -257,7 +279,6 void QXYSeries::insert(int index, const QPointF &point)
257 {
279 {
258 Q_D(QXYSeries);
280 Q_D(QXYSeries);
259 d->m_points.insert(index, point);
281 d->m_points.insert(index, point);
260 // emit d->pointAdded(index);
261 emit pointAdded(index);
282 emit pointAdded(index);
262 }
283 }
263
284
@@ -72,12 +72,15 public:
72 void setPointsVisible(bool visible = true);
72 void setPointsVisible(bool visible = true);
73 bool pointsVisible() const;
73 bool pointsVisible() const;
74
74
75 void replace(QList<QPointF> points);
76
75 Q_SIGNALS:
77 Q_SIGNALS:
76 void clicked(const QPointF &point);
78 void clicked(const QPointF &point);
77 void pointReplaced(int index);
79 void pointReplaced(int index);
78 void pointRemoved(int index);
80 void pointRemoved(int index);
79 void pointAdded(int index);
81 void pointAdded(int index);
80 void colorChanged(QColor color);
82 void colorChanged(QColor color);
83 void pointsReplaced();
81
84
82 private:
85 private:
83 Q_DECLARE_PRIVATE(QXYSeries)
86 Q_DECLARE_PRIVATE(QXYSeries)
@@ -42,6 +42,7 m_animation(0),
42 m_dirty(true)
42 m_dirty(true)
43 {
43 {
44 QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int)));
44 QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int)));
45 QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced()));
45 QObject::connect(series, SIGNAL(pointAdded(int)), this, SLOT(handlePointAdded(int)));
46 QObject::connect(series, SIGNAL(pointAdded(int)), this, SLOT(handlePointAdded(int)));
46 QObject::connect(series, SIGNAL(pointRemoved(int)), this, SLOT(handlePointRemoved(int)));
47 QObject::connect(series, SIGNAL(pointRemoved(int)), this, SLOT(handlePointRemoved(int)));
47 QObject::connect(this, SIGNAL(clicked(QPointF)), series, SIGNAL(clicked(QPointF)));
48 QObject::connect(this, SIGNAL(clicked(QPointF)), series, SIGNAL(clicked(QPointF)));
@@ -182,6 +183,13 void XYChart::handlePointReplaced(int index)
182 updateChart(m_points,points,index);
183 updateChart(m_points,points,index);
183 }
184 }
184
185
186 void XYChart::handlePointsReplaced()
187 {
188 // All the points were replaced -> recalculate
189 QVector<QPointF> points = calculateGeometryPoints();
190 updateChart(m_points, points, -1);
191 }
192
185 void XYChart::handleDomainUpdated()
193 void XYChart::handleDomainUpdated()
186 {
194 {
187 m_minX=domain()->minX();
195 m_minX=domain()->minX();
@@ -68,6 +68,7 public Q_SLOTS:
68 void handlePointAdded(int index);
68 void handlePointAdded(int index);
69 void handlePointRemoved(int index);
69 void handlePointRemoved(int index);
70 void handlePointReplaced(int index);
70 void handlePointReplaced(int index);
71 void handlePointsReplaced();
71 void handleDomainUpdated();
72 void handleDomainUpdated();
72 void handleGeometryChanged(const QRectF &size);
73 void handleGeometryChanged(const QRectF &size);
73
74
@@ -254,27 +254,37 void tst_QXYSeries::replace_raw_data()
254 void tst_QXYSeries::replace_raw()
254 void tst_QXYSeries::replace_raw()
255 {
255 {
256 QFETCH(QList<QPointF>, points);
256 QFETCH(QList<QPointF>, points);
257 QSignalSpy replacedSpy(m_series, SIGNAL(pointReplaced(int)));
257 QSignalSpy pointReplacedSpy(m_series, SIGNAL(pointReplaced(int)));
258 QSignalSpy pointsReplacedSpy(m_series, SIGNAL(pointsReplaced()));
258 m_series->append(points);
259 m_series->append(points);
259 TRY_COMPARE(replacedSpy.count(), 0);
260 TRY_COMPARE(pointReplacedSpy.count(), 0);
261 TRY_COMPARE(pointsReplacedSpy.count(), 0);
260 QCOMPARE(m_series->points(), points);
262 QCOMPARE(m_series->points(), points);
261
263
262 foreach(const QPointF& point, points)
264 foreach(const QPointF& point, points)
263 m_series->replace(point.x(),point.y(),point.x(),0);
265 m_series->replace(point.x(),point.y(),point.x(),0);
264 TRY_COMPARE(replacedSpy.count(), points.count());
266 TRY_COMPARE(pointReplacedSpy.count(), points.count());
267 TRY_COMPARE(pointsReplacedSpy.count(), 0);
265
268
266 // Replace a point that does not exist
269 // Replace a point that does not exist
267 m_series->replace(-123, 999, 0, 0);
270 m_series->replace(-123, 999, 0, 0);
268 TRY_COMPARE(replacedSpy.count(), points.count());
271 TRY_COMPARE(pointReplacedSpy.count(), points.count());
272 TRY_COMPARE(pointsReplacedSpy.count(), 0);
269
273
270 QList<QPointF> newPoints = m_series->points();
274 QList<QPointF> newPoints = m_series->points();
271
272 QCOMPARE(newPoints.count(), points.count());
275 QCOMPARE(newPoints.count(), points.count());
273
274 for(int i =0 ; i<points.count() ; ++i) {
276 for(int i =0 ; i<points.count() ; ++i) {
275 QCOMPARE(points[i].x(), newPoints[i].x());
277 QCOMPARE(points[i].x(), newPoints[i].x());
276 QCOMPARE(newPoints[i].y(), 0.0);
278 QCOMPARE(newPoints[i].y(), 0.0);
277 }
279 }
280
281 // Replace all points
282 QList<QPointF> allPoints;
283 for (int i = 0; i < 10; i++)
284 allPoints.append(QPointF(i, (qreal) rand() / (qreal) RAND_MAX));
285 m_series->replace(allPoints);
286 TRY_COMPARE(pointReplacedSpy.count(), points.count());
287 TRY_COMPARE(pointsReplacedSpy.count(), 1);
278 }
288 }
279
289
280
290
General Comments 0
You need to be logged in to leave comments. Login now