##// END OF EJS Templates
Make splinechart compile
Jani Honkonen -
r832:6772dd97cfaa
parent child
Show More
@@ -1,29 +1,29
1 1 TEMPLATE = subdirs
2 2 SUBDIRS += \
3 3 areachart \
4 4 barchart \
5 5 #chartview \
6 6 customchart \
7 7 #dynamiclinechart \
8 8 #ekgchart \
9 9 linechart \
10 10 #multichart \
11 11 percentbarchart \
12 12 piechart \
13 13 piechartdrilldown \
14 14 #presenterchart \
15 15 scatterchart \
16 16 scatterinteractions \
17 #splinechart \
17 splinechart \
18 18 stackedbarchart \
19 19 stackedbarchartdrilldown \
20 20 #tablemodelchart \
21 21 zoomlinechart
22 22
23 23
24 24
25 25
26 26
27 27
28 28
29 29
@@ -1,136 +1,137
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 #include "splinewidget.h"
22 22 #include "qchartview.h"
23 23 #include "qlineseries.h"
24 24 #include <QGridLayout>
25 25 #include <QPushButton>
26 26 #include "qchartaxis.h"
27 27 #include <qmath.h>
28 28 #include <QTime>
29 29
30 30 QTCOMMERCIALCHART_USE_NAMESPACE
31 31
32 32 SplineWidget::SplineWidget(QWidget *parent)
33 33 : QWidget(parent)
34 34 {
35 35 // qsrand(time(NULL));
36 36 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
37 37 //! [1]
38 38 //create QSplineSeries
39 39 series = new QSplineSeries(this);
40 40 //! [1]
41 41
42 42 //! [2]
43 43 // customize the series presentation settings
44 44 QPen seriesPen(Qt::blue);
45 45 seriesPen.setWidth(3);
46 46 // series->setPen(seriesPen);
47 47 //! [2]
48 48
49 49 //! [add points to series]
50 50 //add data points to the series
51 51 series->append(QPointF(150, 100));
52 52 series->append(QPointF(200, 130));
53 53 series->append(QPointF(250, 120));
54 54 series->append(QPointF(300, 140));
55 55 series->append(QPointF(350, 160));
56 56 //! [add points to series]
57 57
58 58 QSplineSeries* series2 = new QSplineSeries;
59 59
60 60 series2->append(QPointF(400, 120));
61 61 series2->append(QPointF(450, 150));
62 62 series2->append(QPointF(500, 145));
63 63 series2->append(QPointF(550, 170));
64 64
65 65 // series->append(QPointF(600, 190));
66 66 // series->append(QPointF(650, 210));
67 67 // series->append(QPointF(700, 190));
68 68 // series->append(QPointF(750, 180));
69 69 // series->append(QPointF(800, 170));
70 70 QSplineSeries* series3 = new QSplineSeries;
71 71 series3->append(QPointF(600, 190));
72 72 series3->append(QPointF(650, 210));
73 73 series3->append(QPointF(700, 190));
74 74 series3->append(QPointF(750, 180));
75 75 series3->append(QPointF(800, 170));
76 76
77 77 //! [3]
78 78 // create chart view
79 QChartView* chart = new QChartView;
79 QChart* chart = new QChart;
80 80 chart->addSeries(series);
81 81 chart->addSeries(series2);
82 82 chart->addSeries(series3);
83 83
84 chart->setChartTitle("Spline chart example");
84 chart->setTitle("Spline chart example");
85 85 chart->axisX()->setMax(1500);
86 86 chart->axisY()->setMax(500);
87 87
88 88 chart->setMinimumSize(800,600);
89 89 //! [3]
90 90
91 91 //! [4]
92 92 //add new data point button
93 93 QPushButton* addButton = new QPushButton("Add new point");
94 94 connect(addButton, SIGNAL(clicked()), this, SLOT(addNewPoint()));
95 95
96 96 // remove the last data point in the series
97 97 QPushButton* removeButton = new QPushButton("Remove point");
98 98 connect(removeButton, SIGNAL(clicked()), this, SLOT(removePoint()));
99 99 //! [4]
100 100
101 101 //! [5]
102 102 //butttons layout
103 103 QVBoxLayout* buttonsLayout = new QVBoxLayout;
104 104 buttonsLayout->addWidget(addButton);
105 105 buttonsLayout->addWidget(removeButton);
106 106 buttonsLayout->addStretch();
107 107
108 108 QGridLayout* mainLayout = new QGridLayout;
109 mainLayout->addWidget(chart, 1, 0);
109 QChartView *chartView = new QChartView(chart);
110 mainLayout->addWidget(chartView, 1, 0);
110 111 mainLayout->addLayout(buttonsLayout, 1, 1);
111 112 setLayout(mainLayout);
112 113 //! [5]
113 114 }
114 115
115 116 //! [add point]
116 117 void SplineWidget::addNewPoint()
117 118 {
118 119 if (series->count() > 0)
119 120 series->append(QPointF(series->x(series->count() - 1) + 40 + qrand()%40, qAbs(series->y(series->count() - 1) - 50 + qrand()%100)));
120 121 else
121 122 series->append(QPointF(50, 50 + qrand()%50));
122 123 }
123 124 //! [add point]
124 125
125 126 //! [remove point]
126 127 void SplineWidget::removePoint()
127 128 {
128 129 if (series->count() > 0)
129 130 series->remove(QPointF(series->x(series->count() - 1), series->y(series->count() - 1)));
130 131 }
131 132 //! [remove point]
132 133
133 134 SplineWidget::~SplineWidget()
134 135 {
135 136
136 137 }
General Comments 0
You need to be logged in to leave comments. Login now