##// END OF EJS Templates
Fixed presenter and scatter examples and their documentation.
Tero Ahola -
r1015:5ddcd5974481
parent child
Show More
@@ -0,0 +1,34
1 #include "chartview.h"
2 #include <QScatterSeries>
3
4 ChartView::ChartView(QWidget *parent) :
5 QChartView(new QChart(), parent)
6 {
7 //![1]
8 QScatterSeries *series0 = new QScatterSeries();
9 series0->setShape(QScatterSeries::MarkerShapeCircle);
10 series0->setSize(15.0);
11
12 QScatterSeries *series1 = new QScatterSeries();
13 series1->setShape(QScatterSeries::MarkerShapeCircle);
14 series1->setSize(20.0);
15 //![1]
16
17 //![2]
18 series0->append(0, 6);
19 series0->append(2, 4);
20 series0->append(3, 8);
21 series0->append(7, 4);
22 series0->append(10, 5);
23
24 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2);
25 //![2]
26
27 //![3]
28 setRenderHint(QPainter::Antialiasing);
29 chart()->addSeries(series0);
30 chart()->addSeries(series1);
31 chart()->setTitle("Simple scatterchart example");
32 chart()->setBackgroundDropShadowEnabled(false);
33 //![3]
34 }
@@ -0,0 +1,20
1 #ifndef CHARTVIEW_H
2 #define CHARTVIEW_H
3
4 #include <QChartView>
5
6 QTCOMMERCIALCHART_USE_NAMESPACE
7
8 class ChartView : public QChartView
9 {
10 Q_OBJECT
11 public:
12 explicit ChartView(QWidget *parent = 0);
13
14 signals:
15
16 public slots:
17
18 };
19
20 #endif // CHARTVIEW_H
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -12,11 +12,11
12 \image examples_presenterchart2.png
12 \image examples_presenterchart2.png
13 \image examples_presenterchart3.png
13 \image examples_presenterchart3.png
14 \image examples_presenterchart4.png
14 \image examples_presenterchart4.png
15
15
16 We create simple ChartView class which derives form QChartView.
16 We create simple ChartView class which derives form QChartView.
17
17
18 \snippet ../examples/presenterchart/chartview.h 1
18 \snippet ../examples/presenterchart/chartview.h 1
19
19
20 Class will implement \c handleTimeout() slot which we are going to use to trigger switching between different chart presentations.
20 Class will implement \c handleTimeout() slot which we are going to use to trigger switching between different chart presentations.
21 We are also going to provide \c handlePoitClicked() slot which will show clicked point on the chart.
21 We are also going to provide \c handlePoitClicked() slot which will show clicked point on the chart.
22 Class members \c m_series and \c m_titles are going to store series and related titles. In example we are going to present data as a line chart
22 Class members \c m_series and \c m_titles are going to store series and related titles. In example we are going to present data as a line chart
@@ -32,17 +32,8
32 In the end we store references all the created series and matching titles.
32 In the end we store references all the created series and matching titles.
33
33
34 \snippet ../examples/presenterchart/chartview.cpp 3
34 \snippet ../examples/presenterchart/chartview.cpp 3
35
35
36 We connect \c clicked() signals from each series with our \c handlePointClciked() slot.
37
38 \snippet ../examples/presenterchart/chartview.cpp 4
39
40 In \c handleTimeout() slot we change currently displayed chart by removing previous series and adding next series from the \c m_series list. We also set proper title.
36 In \c handleTimeout() slot we change currently displayed chart by removing previous series and adding next series from the \c m_series list. We also set proper title.
41
37
42 \snippet ../examples/presenterchart/chartview.cpp 5
38 \snippet ../examples/presenterchart/chartview.cpp 4
43
44 In \c handlePointClciked() slot we set the chart's title to show clicked point x and y coordinates.
45
46 \snippet ../examples/presenterchart/chartview.cpp 6
47
48 */
39 */
@@ -9,18 +9,19
9
9
10 To create scatter charts, QScatterSeries instance is needed. Here we create scatter series instance and we set the type, color and width of outline for scatter points.
10 To create scatter charts, QScatterSeries instance is needed. Here we create scatter series instance and we set the type, color and width of outline for scatter points.
11
11
12 \snippet ../examples/scatterchart/main.cpp 1
12 \snippet ../examples/scatterchart/chartview.cpp 1
13
13
14 We add data to be shown. We can use add() member function or use stream operator.
14 We add data to be shown. We can use add() member function or use stream operator.
15
15
16 \snippet ../examples/scatterchart/main.cpp 2
16 \snippet ../examples/scatterchart/chartview.cpp 2
17
17
18 In the end we create QChartView instance, set title, set anti-aliasing and add scatter series.
18 In the end we enable anti-aliasing, set the chart title and add the scatter series onto the chart. We also disable
19 drop shadow, because it would not look good on an application with only chart view shown.
19
20
20 \snippet ../examples/scatterchart/main.cpp 3
21 \snippet ../examples/scatterchart/chartview.cpp 3
21
22
22 Chart is ready to be shown.
23 Chart is ready to be shown.
23
24
24 \snippet ../examples/scatterchart/main.cpp 4
25 \snippet ../examples/scatterchart/main.cpp 4
25
26
26 */
27 */
@@ -29,6 +29,7 ChartView::ChartView(QChart* chart,QWidget* parent):QChartView(chart,parent),
29 m_index(-1),m_chart(chart)
29 m_index(-1),m_chart(chart)
30 {
30 {
31 m_chart->setTitle("Charts presenter");
31 m_chart->setTitle("Charts presenter");
32 m_chart->setBackgroundDropShadowEnabled(false);
32 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
33 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
33 m_timer.setInterval(3000);
34 m_timer.setInterval(3000);
34
35
@@ -78,11 +79,6 m_index(-1),m_chart(chart)
78 m_titles<< m_chart->title()+": AreaChart";
79 m_titles<< m_chart->title()+": AreaChart";
79 //![3]
80 //![3]
80
81
81 //![4]
82 foreach (QAbstractSeries* series, m_series) {
83 QObject::connect(series,SIGNAL(clicked(QPointF)),this,SLOT(handlePointClicked(QPointF)));
84 }
85 //![4]
86 m_timer.start();
82 m_timer.start();
87 handleTimeout();
83 handleTimeout();
88 }
84 }
@@ -95,7 +91,7 ChartView::~ChartView()
95 qDeleteAll(m_series);
91 qDeleteAll(m_series);
96 }
92 }
97
93
98 //![5]
94 //![4]
99 void ChartView::handleTimeout()
95 void ChartView::handleTimeout()
100 {
96 {
101 if(m_series.size()==0) return;
97 if(m_series.size()==0) return;
@@ -106,11 +102,4 void ChartView::handleTimeout()
106 m_chart->addSeries(m_series.at(m_index));
102 m_chart->addSeries(m_series.at(m_index));
107 m_chart->setTitle(m_titles.at(m_index));
103 m_chart->setTitle(m_titles.at(m_index));
108 }
104 }
109 //![5]
105 //![4]
110
111 //![6]
112 void ChartView::handlePointClicked(const QPointF& point)
113 {
114 m_chart->setTitle(m_titles.at(m_index) + QString(" x: %1 y: %2").arg(point.x()).arg(point.y()));
115 }
116 //![6]
@@ -36,7 +36,6 public:
36
36
37 public slots:
37 public slots:
38 void handleTimeout();
38 void handleTimeout();
39 void handlePointClicked(const QPointF& point);
40
39
41 private:
40 private:
42 QTimer m_timer;
41 QTimer m_timer;
@@ -31,7 +31,7 int main(int argc, char *argv[])
31 chart->axisY()->setNiceNumbersEnabled(true);
31 chart->axisY()->setNiceNumbersEnabled(true);
32 ChartView chartView(chart,&window);
32 ChartView chartView(chart,&window);
33 chartView.setRenderHint(QPainter::Antialiasing);
33 chartView.setRenderHint(QPainter::Antialiasing);
34 chart->setAnimationOptions(QChart::AllAnimations);
34 chart->setAnimationOptions(QChart::SeriesAnimations);
35 window.setCentralWidget(&chartView);
35 window.setCentralWidget(&chartView);
36 window.resize(400, 300);
36 window.resize(400, 300);
37 window.show();
37 window.show();
@@ -20,8 +20,7
20
20
21 #include <QtGui/QApplication>
21 #include <QtGui/QApplication>
22 #include <QMainWindow>
22 #include <QMainWindow>
23 #include <QChartView>
23 #include "chartview.h"
24 #include <QScatterSeries>
25
24
26 QTCOMMERCIALCHART_USE_NAMESPACE
25 QTCOMMERCIALCHART_USE_NAMESPACE
27
26
@@ -29,54 +28,13 int main(int argc, char *argv[])
29 {
28 {
30 QApplication a(argc, argv);
29 QApplication a(argc, argv);
31
30
32 //![1]
33 QPen pen(Qt::black);
34 pen.setWidth(2);
35 QBrush blue(Qt::blue);
36 QBrush red(Qt::red);
37
38 QScatterSeries *series0 = new QScatterSeries();
39 series0->setPen(pen);
40 series0->setBrush(blue);
41 series0->setShape(QScatterSeries::MarkerShapeCircle);
42 series0->setSize(15.0);
43
44 QScatterSeries *series1 = new QScatterSeries();
45 series1->setPen(pen);
46 series1->setBrush(red);
47 series1->setShape(QScatterSeries::MarkerShapeCircle);
48 series1->setSize(15.0);
49 //![1]
50
51 //![2]
52 series0->append(0, 6);
53 series0->append(2, 4);
54 series0->append(3, 8);
55 series0->append(7, 4);
56 series0->append(10, 5);
57
58 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2);
59 //![2]
60
61 //![3]
62 QChart* chart = new QChart();
63
64 chart->addSeries(series0);
65 chart->addSeries(series1);
66 chart->setTitle("Simple scatterchart example");
67 //![3]
68
69 //![4]
70 QChartView* chartView = new QChartView(chart);
71 chartView->setRenderHint(QPainter::Antialiasing);
72 //![4]
31 //![4]
73
32 ChartView* chartView = new ChartView();
74 //![5]
75 QMainWindow window;
33 QMainWindow window;
76 window.setCentralWidget(chartView);
34 window.setCentralWidget(chartView);
77 window.resize(400, 300);
35 window.resize(400, 300);
78 window.show();
36 window.show();
79 //![5]
37 //![4]
80
38
81 return a.exec();
39 return a.exec();
82 }
40 }
@@ -2,4 +2,8
2 error( "Couldn't find the examples.pri file!" )
2 error( "Couldn't find the examples.pri file!" )
3 }
3 }
4 TARGET = scatterchart
4 TARGET = scatterchart
5 SOURCES += main.cpp
5 SOURCES += main.cpp \
6 chartview.cpp
7
8 HEADERS += \
9 chartview.h
General Comments 0
You need to be logged in to leave comments. Login now