##// END OF EJS Templates
Updated spline chart example documentation and added some more docs to barseries
Marek Rosa -
r901:087f347c6433
parent child
Show More
@@ -9,34 +9,25
9
9
10 To create spline chart we need to put our data into QSplineSeries. QSplineSeries automatically calculates spline segment control points that are needed to properly draw the spline.
10 To create spline chart we need to put our data into QSplineSeries. QSplineSeries automatically calculates spline segment control points that are needed to properly draw the spline.
11
11
12 \snippet ../examples/splinechart/splinewidget.cpp 1
12 \snippet ../examples/splinechart/main.cpp 1
13
13
14 Customize the look of the spline, by setting its pen's color and pen's width
14 Customize the look of the spline, by setting its pen's color and pen's width
15
15
16 \snippet ../examples/splinechart/splinewidget.cpp 2
16 \snippet ../examples/splinechart/main.cpp 2
17
17
18 Now lets add some data points to the series.
18 Now lets add some data points to the series.
19
19
20 \snippet ../examples/splinechart/splinewidget.cpp add points to series
20 \snippet ../examples/splinechart/main.cpp 3
21
21
22 The data series has been populated. To display it on a chart we create QChartView object and add the data series to it. We also set the ranges on both axises, so that our chart is fully visible and there is some excess of space for adding more data points.
22 The data series has been populated. To display it on a chart we create QChart object and add the data series to it. We also set the title and the values range on y axis, so that our chart is better visible.
23
23
24 \snippet ../examples/splinechart/splinewidget.cpp 3
24 \snippet ../examples/splinechart/main.cpp 4
25
25
26 Then we add two buttons for adding and removing data points. Buttons clicked() signals are connected to handler functions.
26 Then we created a QChartView object with QChart as a parameter. This way we don't need to create QGraphicsView scene ourselves. We also set the Antialiasing on to have the rendered lines look nicer.
27
27
28 \snippet ../examples/splinechart/splinewidget.cpp 4
28 \snippet ../examples/splinechart/main.cpp 5
29
29
30 In the end we add the chart and the buttons to the widget's layout.
30 In the end we set the QChartView as the windows's central widget.
31
32 \snippet ../examples/splinechart/splinewidget.cpp 5
33
34 Here is the handler function for add new data point button:
35
36 \snippet ../examples/splinechart/splinewidget.cpp add point
37
38 And here is one for remove the last data point in the series:
39
40 \snippet ../examples/splinechart/splinewidget.cpp remove point
41
31
32 \snippet ../examples/splinechart/main.cpp 6
42 */
33 */
@@ -31,38 +31,41 int main(int argc, char *argv[])
31
31
32 //![1]
32 //![1]
33 QSplineSeries* series = new QSplineSeries();
33 QSplineSeries* series = new QSplineSeries();
34 //![1]
35
36 //![2]
34 QPen red(Qt::red);
37 QPen red(Qt::red);
35 red.setWidth(3);
38 red.setWidth(3);
36 series->setPen(red);
39 series->setPen(red);
37 //![1]
38
39 //![2]
40 //![2]
41
42 //![3]
40 series->append(0, 6);
43 series->append(0, 6);
41 series->append(2, 4);
44 series->append(2, 4);
42 series->append(3, 8);
45 series->append(3, 8);
43 series->append(7, 4);
46 series->append(7, 4);
44 series->append(10, 5);
47 series->append(10, 5);
45 *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2);
48 *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2);
46 //![2]
47
48 //![3]
49 //![3]
50
51 //![4]
49 QChart* chart = new QChart();
52 QChart* chart = new QChart();
50 chart->addSeries(series);
53 chart->addSeries(series);
51 chart->setTitle("Simple spline chart example");
54 chart->setTitle("Simple spline chart example");
52 chart->axisY()->setRange(0, 10);
55 chart->axisY()->setRange(0, 10);
53 //![3]
54
55 //![4]
56 //![4]
57
58 //![5]
56 QChartView* chartView = new QChartView(chart);
59 QChartView* chartView = new QChartView(chart);
57 chartView->setRenderHint(QPainter::Antialiasing);
60 chartView->setRenderHint(QPainter::Antialiasing);
58 //![4]
59
60 //![5]
61 //![5]
62
63 //![6]
61 QMainWindow window;
64 QMainWindow window;
62 window.setCentralWidget(chartView);
65 window.setCentralWidget(chartView);
63 window.resize(400, 300);
66 window.resize(400, 300);
64 window.show();
67 window.show();
65 //![5]
68 //![6]
66
69
67 return a.exec();
70 return a.exec();
68 }
71 }
@@ -108,7 +108,7 void QBarSeries::appendBarSets(QList<QBarSet* > sets)
108 }
108 }
109
109
110 /*!
110 /*!
111 Removes a list of barsets from series. Releases ownership of \a set. Doesnt delete \a sets.
111 Removes a list of barsets from series. Releases ownership of \a sets. Doesnt delete \a sets.
112 Disconnects the clicked(QString, Qt::MouseButtons) signal
112 Disconnects the clicked(QString, Qt::MouseButtons) signal
113 of \a sets from this series
113 of \a sets from this series
114 */
114 */
@@ -121,17 +121,30 void QBarSeries::removeBarSets(QList<QBarSet* > sets)
121 emit restructuredBars();
121 emit restructuredBars();
122 }
122 }
123
123
124 /*!
125 Inserts new \a set on the \a i position.
126 The barset that is currently at this postion is moved to postion i + 1
127 */
124 void QBarSeries::insertBarSet(int i, QBarSet *set)
128 void QBarSeries::insertBarSet(int i, QBarSet *set)
125 {
129 {
126 m_internalModel->insertBarSet(i, set);
130 m_internalModel->insertBarSet(i, set);
127 // emit barsetChanged();
131 // emit barsetChanged();
128 }
132 }
129
133
134 /*!
135 Inserts new \a category on the \a i position.
136 The category that is currently at this postion is moved to postion i + 1
137 \sa removeCategory()
138 */
130 void QBarSeries::insertCategory(int i, QString category)
139 void QBarSeries::insertCategory(int i, QString category)
131 {
140 {
132 m_internalModel->insertCategory(i, category);
141 m_internalModel->insertCategory(i, category);
133 }
142 }
134
143
144 /*!
145 Removes the category specified by \a i
146 \sa insertCategory()
147 */
135 void QBarSeries::removeCategory(int i)
148 void QBarSeries::removeCategory(int i)
136 {
149 {
137 m_internalModel->removeCategory(i);
150 m_internalModel->removeCategory(i);
@@ -102,11 +102,20 QBarSet& QBarSet::operator << (const qreal &value)
102 return *this;
102 return *this;
103 }
103 }
104
104
105 /*!
106 Inserts new \a value on the \a i position.
107 The value that is currently at this postion is moved to postion i + 1
108 \sa removeValue()
109 */
105 void QBarSet::insertValue(int i, qreal value)
110 void QBarSet::insertValue(int i, qreal value)
106 {
111 {
107 m_values.insert(i, value);
112 m_values.insert(i, value);
108 }
113 }
109
114
115 /*!
116 Removes the value specified by \a i
117 \sa insertValue()
118 */
110 void QBarSet::removeValue(int i)
119 void QBarSet::removeValue(int i)
111 {
120 {
112 m_values.removeAt(i);
121 m_values.removeAt(i);
General Comments 0
You need to be logged in to leave comments. Login now