##// END OF EJS Templates
zoomlinechart example: update docs and series data
Jani Honkonen -
r1388:7e919ffb09aa
parent child
Show More
@@ -3,7 +3,8
3 \title Zoom line example
3 \title Zoom line example
4 \subtitle
4 \subtitle
5
5
6 The example shows how to create your own custom zooming effect with QRubberBand.
6 The example shows how to create your own custom zooming effect with QRubberBand by using a mouse
7 and how to use touch gestures for paning and zooming.
7 \image examples_zoomlinechart1.png
8 \image examples_zoomlinechart1.png
8 \image examples_zoomlinechart2.png
9 \image examples_zoomlinechart2.png
9
10
@@ -19,4 +20,12
19 Then we implement a custom logic for mouse and key events. For example pressing '+' key will zoom in and pressing
20 Then we implement a custom logic for mouse and key events. For example pressing '+' key will zoom in and pressing
20 the '-' key will zoom out.
21 the '-' key will zoom out.
21 \snippet ../examples/zoomlinechart/chartview.cpp 1
22 \snippet ../examples/zoomlinechart/chartview.cpp 1
23
24 We also create our own QChart:
25 \snippet ../examples/zoomlinechart/chart.h 1
26
27 Where we can handle the gestures:
28 \snippet ../examples/zoomlinechart/chart.cpp 1
29
30 Note that you will need to call grabGesture() to both QMainWindow and QChart.
22 */
31 */
@@ -37,6 +37,7 Chart::~Chart()
37
37
38 }
38 }
39
39
40 //![1]
40 bool Chart::sceneEvent(QEvent *event)
41 bool Chart::sceneEvent(QEvent *event)
41 {
42 {
42 if (event->type() == QEvent::Gesture)
43 if (event->type() == QEvent::Gesture)
@@ -48,14 +49,15 bool Chart::gestureEvent(QGestureEvent* event)
48 {
49 {
49 if (QGesture *gesture = event->gesture(Qt::PanGesture)) {
50 if (QGesture *gesture = event->gesture(Qt::PanGesture)) {
50 QPanGesture *pan = static_cast<QPanGesture *>(gesture);
51 QPanGesture *pan = static_cast<QPanGesture *>(gesture);
51 scroll(pan->delta());
52 QChart::scroll(pan->delta());
52 }
53 }
53
54
54 if (QGesture *gesture = event->gesture(Qt::PinchGesture)) {
55 if (QGesture *gesture = event->gesture(Qt::PinchGesture)) {
55 QPinchGesture *pinch = static_cast<QPinchGesture *>(gesture);
56 QPinchGesture *pinch = static_cast<QPinchGesture *>(gesture);
56 if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged)
57 if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged)
57 zoom(pinch->scaleFactor());
58 QChart::zoom(pinch->scaleFactor());
58 }
59 }
59
60
60 return true;
61 return true;
61 }
62 }
63 //![1]
@@ -25,7 +25,9
25
25
26 QTCOMMERCIALCHART_USE_NAMESPACE
26 QTCOMMERCIALCHART_USE_NAMESPACE
27
27
28 //![1]
28 class Chart : public QChart
29 class Chart : public QChart
30 //![1]
29 {
31 {
30 public:
32 public:
31 explicit Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
33 explicit Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
@@ -22,6 +22,7
22 #include "chartview.h"
22 #include "chartview.h"
23 #include <QApplication>
23 #include <QApplication>
24 #include <QMainWindow>
24 #include <QMainWindow>
25 #include <qmath.h>
25 #include <QLineSeries>
26 #include <QLineSeries>
26
27
27 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
@@ -32,12 +33,10 int main(int argc, char *argv[])
32
33
33 //![1]
34 //![1]
34 QLineSeries* series = new QLineSeries();
35 QLineSeries* series = new QLineSeries();
35 series->setName("line");
36 for (int i=0; i < 500; i++) {
36 qreal yValue = 0.0;
37 QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100);
37 for (int i(0); i < 500; i++) {
38 p.ry() += qrand() % 20;
38 yValue = yValue + (qreal) (qrand() % 10) / 500.0;
39 *series << p;
39 QPointF value((i + (qreal) rand() / (qreal) RAND_MAX) * (10.0 / 500.0), yValue);
40 *series << value;
41 }
40 }
42 //![1]
41 //![1]
43
42
@@ -45,6 +44,7 int main(int argc, char *argv[])
45 chart->addSeries(series);
44 chart->addSeries(series);
46 chart->setTitle("Zoom in/out example");
45 chart->setTitle("Zoom in/out example");
47 chart->setAnimationOptions(QChart::SeriesAnimations);
46 chart->setAnimationOptions(QChart::SeriesAnimations);
47 chart->legend()->hide();
48
48
49 ChartView* chartView = new ChartView(chart);
49 ChartView* chartView = new ChartView(chart);
50 chartView->setRenderHint(QPainter::Antialiasing);
50 chartView->setRenderHint(QPainter::Antialiasing);
General Comments 0
You need to be logged in to leave comments. Login now