|
@@
-1,93
+1,93
|
|
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
|
import QtQuick 1.1
|
|
22
|
22
|
import QtCommercial.Chart 1.1
|
|
23
|
23
|
|
|
24
|
24
|
Rectangle {
|
|
25
|
|
width: 360
|
|
26
|
|
height: 360
|
|
|
25
|
width: 400
|
|
|
26
|
height: 300
|
|
27
|
27
|
property int currentIndex: -1
|
|
28
|
28
|
|
|
29
|
29
|
//![1]
|
|
30
|
30
|
ChartView {
|
|
31
|
31
|
id: chartView
|
|
32
|
32
|
title: "Driver Speeds, lap 1"
|
|
33
|
33
|
anchors.fill: parent
|
|
34
|
34
|
legend.alignment: Qt.AlignTop
|
|
35
|
35
|
animationOptions: ChartView.SeriesAnimations
|
|
36
|
36
|
}
|
|
37
|
37
|
//![1]
|
|
38
|
38
|
|
|
39
|
39
|
//![2]
|
|
40
|
40
|
// An example XmlListModel containing F1 legend drivers' speeds at speed traps
|
|
41
|
41
|
SpeedsXml {
|
|
42
|
42
|
id: speedsXml
|
|
43
|
43
|
onStatusChanged: {
|
|
44
|
44
|
if (status == XmlListModel.Ready) {
|
|
45
|
45
|
timer.start();
|
|
46
|
46
|
}
|
|
47
|
47
|
}
|
|
48
|
48
|
}
|
|
49
|
49
|
//![2]
|
|
50
|
50
|
|
|
51
|
51
|
//![3]
|
|
52
|
52
|
// A timer to mimic refreshing the data dynamically
|
|
53
|
53
|
Timer {
|
|
54
|
54
|
id: timer
|
|
55
|
55
|
interval: 700
|
|
56
|
56
|
repeat: true
|
|
57
|
57
|
triggeredOnStart: true
|
|
58
|
58
|
running: false
|
|
59
|
59
|
onTriggered: {
|
|
60
|
60
|
currentIndex++;
|
|
61
|
61
|
if (currentIndex < speedsXml.count) {
|
|
62
|
62
|
// Check if there is a series for the data already (we are using driver name to identify series)
|
|
63
|
63
|
var lineSeries = chartView.series(speedsXml.get(currentIndex).driver);
|
|
64
|
64
|
if (!lineSeries) {
|
|
65
|
65
|
lineSeries = chartView.createSeries(ChartView.SeriesTypeLine, speedsXml.get(currentIndex).driver);
|
|
66
|
66
|
chartView.axisY().min = 0;
|
|
67
|
67
|
chartView.axisY().max = 250;
|
|
68
|
68
|
chartView.axisY().tickCount = 6;
|
|
69
|
69
|
chartView.axisY().titleText = "speed (kph)";
|
|
70
|
70
|
chartView.axisX().titleText = "speed trap";
|
|
71
|
71
|
chartView.axisX().labelFormat = "%.0f";
|
|
72
|
72
|
}
|
|
73
|
73
|
lineSeries.append(speedsXml.get(currentIndex).speedTrap, speedsXml.get(currentIndex).speed);
|
|
74
|
74
|
|
|
75
|
75
|
if (speedsXml.get(currentIndex).speedTrap > 3) {
|
|
76
|
76
|
chartView.axisX().max = Number(speedsXml.get(currentIndex).speedTrap) + 1;
|
|
77
|
77
|
chartView.axisX().min = chartView.axisX().max - 5;
|
|
78
|
78
|
} else {
|
|
79
|
79
|
chartView.axisX().max = 5;
|
|
80
|
80
|
chartView.axisX().min = 0;
|
|
81
|
81
|
}
|
|
82
|
82
|
chartView.axisX().tickCount = chartView.axisX().max - chartView.axisX().min + 1;
|
|
83
|
83
|
} else {
|
|
84
|
84
|
// No more data, change x-axis range to show all the data
|
|
85
|
85
|
timer.stop();
|
|
86
|
86
|
chartView.animationOptions = ChartView.AllAnimations;
|
|
87
|
87
|
chartView.axisX().min = 0;
|
|
88
|
88
|
chartView.axisX().max = speedsXml.get(currentIndex - 1).speedTrap;
|
|
89
|
89
|
}
|
|
90
|
90
|
}
|
|
91
|
91
|
}
|
|
92
|
92
|
//![3]
|
|
93
|
93
|
}
|