##// END OF EJS Templates
Change headers to qt ones in some examples
Michal Klocek -
r632:936476785a4d
parent child
Show More
@@ -1,59 +1,57
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartview.h>
3 #include <QChartView>
4 #include <qlineseries.h>
4 #include <QLineSeries>
5 #include <qareaseries.h>
5 #include <QAreaSeries>
6 #include <qchart.h>
7 #include <qchartaxis.h>
8 #include <cmath>
6 #include <cmath>
9
7
10 QTCOMMERCIALCHART_USE_NAMESPACE
8 QTCOMMERCIALCHART_USE_NAMESPACE
11
9
12 int main(int argc, char *argv[])
10 int main(int argc, char *argv[])
13 {
11 {
14 QApplication a(argc, argv);
12 QApplication a(argc, argv);
15
13
16 //![1]
14 //![1]
17
15
18 QLineSeries* series0 = new QLineSeries();
16 QLineSeries* series0 = new QLineSeries();
19 QLineSeries* series1 = new QLineSeries();
17 QLineSeries* series1 = new QLineSeries();
20
18
21 //![1]
19 //![1]
22
20
23 //![2]
21 //![2]
24 *series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) << QPointF(12,6) << QPointF(16,7) << QPointF(18,5);
22 *series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) << QPointF(12,6) << QPointF(16,7) << QPointF(18,5);
25 *series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) << QPointF(12,3) << QPointF(16,4) << QPointF(18,3);
23 *series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) << QPointF(12,3) << QPointF(16,4) << QPointF(18,3);
26 //![2]
24 //![2]
27 //![3]
25 //![3]
28
26
29 QAreaSeries* series = new QAreaSeries(series0,series1);
27 QAreaSeries* series = new QAreaSeries(series0,series1);
30 QPen pen(0x059605);
28 QPen pen(0x059605);
31 pen.setWidth(3);
29 pen.setWidth(3);
32 series->setPen(pen);
30 series->setPen(pen);
33
31
34 QLinearGradient gradient(QPointF(0, 0), QPointF(0, 1));
32 QLinearGradient gradient(QPointF(0, 0), QPointF(0, 1));
35 gradient.setColorAt(0.0,0x3cc63c);
33 gradient.setColorAt(0.0,0x3cc63c);
36 gradient.setColorAt(1.0, 0x26f626);
34 gradient.setColorAt(1.0, 0x26f626);
37 gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
35 gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
38 series->setBrush(gradient);
36 series->setBrush(gradient);
39
37
40 //![3]
38 //![3]
41 //![4]
39 //![4]
42 QMainWindow window;
40 QMainWindow window;
43 QChartView* chartView = new QChartView(&window);
41 QChartView* chartView = new QChartView(&window);
44
42
45 chartView->setChartTitle("Basic area chart example");
43 chartView->setChartTitle("Simple area chart example");
46 chartView->setRenderHint(QPainter::Antialiasing);
44 chartView->setRenderHint(QPainter::Antialiasing);
47
45
48 chartView->addSeries(series);
46 chartView->addSeries(series);
49 chartView->axisX()->setRange(0,20);
47 chartView->axisX()->setRange(0,20);
50 chartView->axisY()->setRange(0,10);
48 chartView->axisY()->setRange(0,10);
51 //![4]
49 //![4]
52 //![5]
50 //![5]
53 window.setCentralWidget(chartView);
51 window.setCentralWidget(chartView);
54 window.resize(400, 300);
52 window.resize(400, 300);
55 window.show();
53 window.show();
56 //![5]
54 //![5]
57
55
58 return a.exec();
56 return a.exec();
59 }
57 }
@@ -1,58 +1,58
1 #include "chartview.h"
1 #include "chartview.h"
2 #include <QSplineSeries>
2 #include <QSplineSeries>
3 #include <QTime>
3 #include <QTime>
4
4
5 ChartView::ChartView(QWidget* parent):QChartView(parent),
5 ChartView::ChartView(QWidget* parent):QChartView(parent),
6 m_step(1),
6 m_step(1),
7 m_x(0),
7 m_x(0),
8 m_y(1)
8 m_y(1)
9 {
9 {
10 QTime now = QTime::currentTime();
10 QTime now = QTime::currentTime();
11 qsrand((uint)now.msec());
11 qsrand((uint)now.msec());
12 setChartTitle("Three random line charts");
12 setChartTitle("Three random line charts");
13
13
14 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
14 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
15 m_timer.setInterval(3000);
15 m_timer.setInterval(3000);
16
16
17 m_series0 = new QLineSeries(this);
17 m_series0 = new QLineSeries(this);
18 QPen blue(Qt::blue);
18 QPen blue(Qt::blue);
19 blue.setWidth(3);
19 blue.setWidth(3);
20 m_series0->setPen(blue);
20 m_series0->setPen(blue);
21
21
22
22
23 m_series1 = new QSplineSeries(this);
23 m_series1 = new QSplineSeries(this);
24 QPen green(Qt::green);
24 QPen green(Qt::green);
25 green.setWidth(3);
25 green.setWidth(3);
26 m_series1->setPen(green);
26 m_series1->setPen(green);
27
27
28
28
29 m_series0->add(m_x,m_y);
29 m_series0->add(m_x,m_y);
30 m_series1->add(m_x,m_y);
30 m_series1->add(m_x,m_y);
31
31
32 setChartTitle("Simple EKG exmaple");
32 setChartTitle("Simple EKG example");
33 addSeries(m_series0);
33 addSeries(m_series0);
34 addSeries(m_series1);
34 addSeries(m_series1);
35 axisY()->setRange(-5,5);
35 axisY()->setRange(-5,5);
36 axisX()->setRange(-9,1);
36 axisX()->setRange(-9,1);
37 axisX()->setTicksCount(11);
37 axisX()->setTicksCount(11);
38 m_timer.start();
38 m_timer.start();
39 }
39 }
40
40
41 ChartView::~ChartView()
41 ChartView::~ChartView()
42 {
42 {
43
43
44 }
44 }
45
45
46 void ChartView::handleTimeout()
46 void ChartView::handleTimeout()
47 {
47 {
48 m_x+=m_step;
48 m_x+=m_step;
49 m_y = qrand() % 5 - 2.5;
49 m_y = qrand() % 5 - 2.5;
50 m_series0->add(m_x,m_y);
50 m_series0->add(m_x,m_y);
51 m_series1->add(m_x,m_y);
51 m_series1->add(m_x,m_y);
52 if(m_x>=10)
52 if(m_x>=10)
53 {
53 {
54 m_series0->remove(m_x-10);
54 m_series0->remove(m_x-10);
55 m_series1->remove(m_x-10);
55 m_series1->remove(m_x-10);
56 }
56 }
57 scrollRight();
57 scrollRight();
58 }
58 }
@@ -1,53 +1,52
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartview.h>
3 #include <QChartView>
4 #include <qlineseries.h>
4 #include <QLineSeries>
5 #include <qchart.h>
6 #include <cmath>
5 #include <cmath>
7
6
8 QTCOMMERCIALCHART_USE_NAMESPACE
7 QTCOMMERCIALCHART_USE_NAMESPACE
9
8
10 int main(int argc, char *argv[])
9 int main(int argc, char *argv[])
11 {
10 {
12 QApplication a(argc, argv);
11 QApplication a(argc, argv);
13
12
14 //![1]
13 //![1]
15
14
16 QLineSeries* series0 = new QLineSeries();
15 QLineSeries* series0 = new QLineSeries();
17 QPen blue(Qt::blue);
16 QPen blue(Qt::blue);
18 blue.setWidth(3);
17 blue.setWidth(3);
19 series0->setPen(blue);
18 series0->setPen(blue);
20
19
21 QLineSeries* series1 = new QLineSeries();
20 QLineSeries* series1 = new QLineSeries();
22 QPen red(Qt::red);
21 QPen red(Qt::red);
23 red.setWidth(3);
22 red.setWidth(3);
24 series1->setPen(red);
23 series1->setPen(red);
25 //![1]
24 //![1]
26
25
27 //![2]
26 //![2]
28 series0->add(0, 6);
27 series0->add(0, 6);
29 series0->add(2, 4);
28 series0->add(2, 4);
30 series0->add(3, 8);
29 series0->add(3, 8);
31 series0->add(7, 4);
30 series0->add(7, 4);
32 series0->add(10,5);
31 series0->add(10,5);
33
32
34 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10,2);
33 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10,2);
35 //![2]
34 //![2]
36 //![3]
35 //![3]
37 QMainWindow window;
36 QMainWindow window;
38 QChartView* chartView = new QChartView(&window);
37 QChartView* chartView = new QChartView(&window);
39
38
40 chartView->setChartTitle("Basic line chart example");
39 chartView->setChartTitle("Basic line chart example");
41 chartView->setRenderHint(QPainter::Antialiasing);
40 chartView->setRenderHint(QPainter::Antialiasing);
42
41
43 chartView->addSeries(series0);
42 chartView->addSeries(series0);
44 chartView->addSeries(series1);
43 chartView->addSeries(series1);
45 //![3]
44 //![3]
46 //![4]
45 //![4]
47 window.setCentralWidget(chartView);
46 window.setCentralWidget(chartView);
48 window.resize(400, 300);
47 window.resize(400, 300);
49 window.show();
48 window.show();
50 //![4]
49 //![4]
51
50
52 return a.exec();
51 return a.exec();
53 }
52 }
@@ -1,97 +1,97
1 #include "chartview.h"
1 #include "chartview.h"
2 #include <qlineseries.h>
2 #include <QLineSeries>
3 #include <qscatterseries.h>
3 #include <QScatterSeries>
4 #include <qsplineseries.h>
4 #include <QSplineSeries>
5 #include <qareaseries.h>
5 #include <QAreaSeries>
6 #include <QTime>
6 #include <QTime>
7
7
8 ChartView::ChartView(QWidget* parent):QChartView(parent),
8 ChartView::ChartView(QWidget* parent):QChartView(parent),
9 m_index(0)
9 m_index(0)
10 {
10 {
11 setChartTitle("Four charts");
11 setChartTitle("Charts presenter");
12 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
12 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
13 m_timer.setInterval(3000);
13 m_timer.setInterval(3000);
14
14
15 //![1]
15 //![1]
16 QLineSeries* series0 = new QLineSeries(this);
16 QLineSeries* series0 = new QLineSeries(this);
17 QPen blue(Qt::blue);
17 QPen blue(Qt::blue);
18 blue.setWidth(3);
18 blue.setWidth(3);
19 series0->setPen(blue);
19 series0->setPen(blue);
20
20
21 QScatterSeries* series1 = new QScatterSeries(this);
21 QScatterSeries* series1 = new QScatterSeries(this);
22 QPen red(Qt::red);
22 QPen red(Qt::red);
23 red.setWidth(3);
23 red.setWidth(3);
24 series1->setPen(red);
24 series1->setPen(red);
25 series1->setBrush(Qt::white);
25 series1->setBrush(Qt::white);
26
26
27 QSplineSeries* series2 = new QSplineSeries(this);
27 QSplineSeries* series2 = new QSplineSeries(this);
28 QPen green(Qt::green);
28 QPen green(Qt::green);
29 green.setWidth(3);
29 green.setWidth(3);
30 series2->setPen(green);
30 series2->setPen(green);
31
31
32 QAreaSeries* series3 = new QAreaSeries(series0);
32 QAreaSeries* series3 = new QAreaSeries(series0);
33 QPen yellow(Qt::black);
33 QPen yellow(Qt::black);
34 yellow.setWidth(3);
34 yellow.setWidth(3);
35 series3->setPen(yellow);
35 series3->setPen(yellow);
36 series3->setBrush(Qt::yellow);
36 series3->setBrush(Qt::yellow);
37 //![1]
37 //![1]
38
38
39 //![2]
39 //![2]
40 int numPoints = 10;
40 int numPoints = 10;
41
41
42 for (int x = 0; x <= numPoints; ++x) {
42 for (int x = 0; x <= numPoints; ++x) {
43 qreal y = qrand() % 100;
43 qreal y = qrand() % 100;
44 series0->add(x,y);
44 series0->add(x,y);
45 series1->add(x,y);
45 series1->add(x,y);
46 series2->add(x,y);
46 series2->add(x,y);
47 }
47 }
48 //![2]
48 //![2]
49
49
50 //![3]
50 //![3]
51 m_series<<series0;
51 m_series<<series0;
52 m_titles<<chartTitle()+": LineChart";
52 m_titles<<chartTitle()+": LineChart";
53 m_series<<series1;
53 m_series<<series1;
54 m_titles<<chartTitle()+": ScatterChart";
54 m_titles<<chartTitle()+": ScatterChart";
55 m_series<<series2;
55 m_series<<series2;
56 m_titles<<chartTitle()+": SplineChart";
56 m_titles<<chartTitle()+": SplineChart";
57 m_series<<series3;
57 m_series<<series3;
58 m_titles<<chartTitle()+": AreaChart";
58 m_titles<<chartTitle()+": AreaChart";
59 //![3]
59 //![3]
60
60
61 addSeries(series0);
61 addSeries(series0);
62 setChartTitle(m_titles.at(0));
62 setChartTitle(m_titles.at(0));
63
63
64 //![4]
64 //![4]
65 foreach (QSeries* series, m_series) {
65 foreach (QSeries* series, m_series) {
66 QObject::connect(series,SIGNAL(clicked(const QPointF&)),this,SLOT(handlePointClicked(const QPointF&)));
66 QObject::connect(series,SIGNAL(clicked(const QPointF&)),this,SLOT(handlePointClicked(const QPointF&)));
67 }
67 }
68 //![4]
68 //![4]
69
69
70 m_timer.start();
70 m_timer.start();
71 }
71 }
72
72
73 ChartView::~ChartView()
73 ChartView::~ChartView()
74 {
74 {
75 if(m_series.size()==0) return;
75 if(m_series.size()==0) return;
76 removeSeries(m_series.at(m_index));
76 removeSeries(m_series.at(m_index));
77 qDeleteAll(m_series);
77 qDeleteAll(m_series);
78 }
78 }
79
79
80 //![5]
80 //![5]
81 void ChartView::handleTimeout()
81 void ChartView::handleTimeout()
82 {
82 {
83 if(m_series.size()==0) return;
83 if(m_series.size()==0) return;
84 removeSeries(m_series.at(m_index));
84 removeSeries(m_series.at(m_index));
85 m_index++;
85 m_index++;
86 m_index=m_index%m_series.size();
86 m_index=m_index%m_series.size();
87 addSeries(m_series.at(m_index));
87 addSeries(m_series.at(m_index));
88 setChartTitle(m_titles.at(m_index));
88 setChartTitle(m_titles.at(m_index));
89 }
89 }
90 //![5]
90 //![5]
91
91
92 //![6]
92 //![6]
93 void ChartView::handlePointClicked(const QPointF& point)
93 void ChartView::handlePointClicked(const QPointF& point)
94 {
94 {
95 setChartTitle(m_titles.at(m_index) + QString(" x: %1 y: %2").arg(point.x()).arg(point.y()));
95 setChartTitle(m_titles.at(m_index) + QString(" x: %1 y: %2").arg(point.x()).arg(point.y()));
96 }
96 }
97 //![6]
97 //![6]
@@ -1,29 +1,29
1 #ifndef CHARTVIEW_H_
1 #ifndef CHARTVIEW_H_
2 #define CHARTVIEW_H_
2 #define CHARTVIEW_H_
3
3
4 #include <qchartview.h>
4 #include <QChartView>
5 #include <QTimer>
5 #include <QTimer>
6
6
7 QTCOMMERCIALCHART_USE_NAMESPACE
7 QTCOMMERCIALCHART_USE_NAMESPACE
8
8
9 //![1]
9 //![1]
10 class ChartView: public QChartView
10 class ChartView: public QChartView
11 {
11 {
12 Q_OBJECT
12 Q_OBJECT
13 public:
13 public:
14 ChartView(QWidget* parent=0);
14 ChartView(QWidget* parent=0);
15 virtual ~ChartView();
15 virtual ~ChartView();
16
16
17 public slots:
17 public slots:
18 void handleTimeout();
18 void handleTimeout();
19 void handlePointClicked(const QPointF& point);
19 void handlePointClicked(const QPointF& point);
20
20
21 private:
21 private:
22 QTimer m_timer;
22 QTimer m_timer;
23 QList<QSeries*> m_series;
23 QList<QSeries*> m_series;
24 QStringList m_titles;
24 QStringList m_titles;
25 int m_index;
25 int m_index;
26 };
26 };
27 //![1]
27 //![1]
28
28
29 #endif /* CHARTVIEW_H_ */
29 #endif /* CHARTVIEW_H_ */
@@ -1,49 +1,48
1 #include <QtGui/QApplication>
1 #include <QtGui/QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartglobal.h>
3 #include <QChartView>
4 #include <qchartview.h>
4 #include <QScatterSeries>
5 #include <qscatterseries.h>
6
5
7 QTCOMMERCIALCHART_USE_NAMESPACE
6 QTCOMMERCIALCHART_USE_NAMESPACE
8
7
9 int main(int argc, char *argv[])
8 int main(int argc, char *argv[])
10 {
9 {
11 QApplication a(argc, argv);
10 QApplication a(argc, argv);
12
11
13 //! [1]
12 //! [1]
14 QScatterSeries *scatter = new QScatterSeries();
13 QScatterSeries *scatter = new QScatterSeries();
15
14
16 QBrush brush(Qt::red);
15 QBrush brush(Qt::red);
17 QPen pen(Qt::black);
16 QPen pen(Qt::black);
18 pen.setWidth(2);
17 pen.setWidth(2);
19
18
20 scatter->setPen(pen);
19 scatter->setPen(pen);
21 scatter->setBrush(brush);
20 scatter->setBrush(brush);
22 scatter->setShape(QScatterSeries::MarkerShapeCircle);
21 scatter->setShape(QScatterSeries::MarkerShapeCircle);
23 scatter->setSize(15.0);
22 scatter->setSize(15.0);
24 //! [1]
23 //! [1]
25
24
26 //! [2]
25 //! [2]
27 for (qreal i(0.0); i < 20; i += 0.5) {
26 for (qreal i(0.0); i < 20; i += 0.5) {
28 qreal x = i + (qreal) (rand() % 100) / 100.0;
27 qreal x = i + (qreal) (rand() % 100) / 100.0;
29 qreal y = i + (qreal) (rand() % 100) / 100.0;
28 qreal y = i + (qreal) (rand() % 100) / 100.0;
30 scatter->add(x, y);
29 scatter->add(x, y);
31 }
30 }
32 *scatter << QPointF(2.0, 5.5) << QPointF(2.2, 5.4);
31 *scatter << QPointF(2.0, 5.5) << QPointF(2.2, 5.4);
33 //! [2]
32 //! [2]
34
33
35 //! [3]
34 //! [3]
36 QMainWindow window;
35 QMainWindow window;
37 QChartView *chartView = new QChartView(&window);
36 QChartView *chartView = new QChartView(&window);
38 chartView->setRenderHint(QPainter::Antialiasing);
37 chartView->setRenderHint(QPainter::Antialiasing);
39 chartView->setChartTitle("Basic scatter chart example");
38 chartView->setChartTitle("Simple scatter chart example");
40 chartView->addSeries(scatter);
39 chartView->addSeries(scatter);
41 //! [3]
40 //! [3]
42
41
43 //! [4]
42 //! [4]
44 window.setCentralWidget(chartView);
43 window.setCentralWidget(chartView);
45 window.resize(400, 300);
44 window.resize(400, 300);
46 window.show();
45 window.show();
47 //! [4]
46 //! [4]
48 return a.exec();
47 return a.exec();
49 }
48 }
@@ -1,45 +1,45
1 #include "chartwidget.h"
1 #include "chartwidget.h"
2 #include <QApplication>
2 #include <QApplication>
3 #include <QMainWindow>
3 #include <QMainWindow>
4 #include <qlineseries.h>
4 #include <QLineSeries>
5 #include <cmath>
5 #include <cmath>
6
6
7 QTCOMMERCIALCHART_USE_NAMESPACE
7 QTCOMMERCIALCHART_USE_NAMESPACE
8
8
9 #define PI 3.14159265358979
9 #define PI 3.14159265358979
10
10
11 int main(int argc, char *argv[])
11 int main(int argc, char *argv[])
12 {
12 {
13 QApplication a(argc, argv);
13 QApplication a(argc, argv);
14
14
15 QMainWindow window;
15 QMainWindow window;
16
16
17 QLineSeries* series0 = new QLineSeries();
17 QLineSeries* series0 = new QLineSeries();
18 QPen blue(Qt::blue);
18 QPen blue(Qt::blue);
19 blue.setWidth(3);
19 blue.setWidth(3);
20 series0->setPen(blue);
20 series0->setPen(blue);
21 QLineSeries* series1 = new QLineSeries();
21 QLineSeries* series1 = new QLineSeries();
22 QPen red(Qt::red);
22 QPen red(Qt::red);
23 red.setWidth(3);
23 red.setWidth(3);
24 series1->setPen(red);
24 series1->setPen(red);
25
25
26 int numPoints = 100;
26 int numPoints = 100;
27
27
28 for (int x = 0; x <= numPoints; ++x) {
28 for (int x = 0; x <= numPoints; ++x) {
29 series0->add(x, fabs(sin(PI/50*x)*100));
29 series0->add(x, fabs(sin(PI/50*x)*100));
30 series1->add(x, fabs(cos(PI/50*x)*100));
30 series1->add(x, fabs(cos(PI/50*x)*100));
31 }
31 }
32
32
33 ChartWidget* chartWidget = new ChartWidget(&window);
33 ChartWidget* chartWidget = new ChartWidget(&window);
34 chartWidget->setRenderHint(QPainter::Antialiasing);
34 chartWidget->setRenderHint(QPainter::Antialiasing);
35 chartWidget->setChartTitle("Zoom in/out line chart example");
35 chartWidget->setChartTitle("Zoom in/out line chart example");
36 chartWidget->setAnimationOptions(QChart::AllAnimations);
36 chartWidget->setAnimationOptions(QChart::AllAnimations);
37 chartWidget->addSeries(series0);
37 chartWidget->addSeries(series0);
38 chartWidget->addSeries(series1);
38 chartWidget->addSeries(series1);
39
39
40 window.setCentralWidget(chartWidget);
40 window.setCentralWidget(chartWidget);
41 window.resize(400, 300);
41 window.resize(400, 300);
42 window.show();
42 window.show();
43
43
44 return a.exec();
44 return a.exec();
45 }
45 }
General Comments 0
You need to be logged in to leave comments. Login now