@@ -1,47 +1,47 | |||
|
1 | 1 | /*! |
|
2 | 2 | \example examples/barchart |
|
3 | 3 | \title BarChart Example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | The example shows how to create a bar chart. BarChart shows the data in sets as separate bars, which are in categories. |
|
7 | 7 | |
|
8 | 8 | \image examples_barchart.png |
|
9 | 9 | |
|
10 | 10 | The barsets are used in same way in all barcharts. |
|
11 | 11 | To illustrate difference between various barcharts, we use same data in examples. |
|
12 | 12 | Data that barchart visualizes, is defined by QBarSet instances. Here we create the sets and append data |
|
13 | 13 | to them. The data is appended here with << operator. Alternatively the append method could be used. |
|
14 | 14 | |
|
15 | 15 | \snippet ../examples/barchart/main.cpp 1 |
|
16 | 16 | |
|
17 | 17 | We create the series and append the barsets to it. The series takes ownership of the barsets. The series groups the data from sets to categories. |
|
18 |
|
|
|
18 | First values of each set are grouped together at first category second value to second category and so on. | |
|
19 | 19 | |
|
20 | 20 | \snippet ../examples/barchart/main.cpp 2 |
|
21 | 21 | |
|
22 | 22 | Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling |
|
23 | 23 | setAnimationOptions(QChart::SeriesAnimations) |
|
24 | 24 | |
|
25 | 25 | \snippet ../examples/barchart/main.cpp 3 |
|
26 | 26 | |
|
27 | 27 | To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and |
|
28 | 28 | set it to be the x-axis of the chart. The chart takes ownership of axis. For y-axis we use default axis, which is created and scaled to series data |
|
29 | 29 | by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will |
|
30 | 30 | override the category axis. |
|
31 | 31 | |
|
32 | 32 | \snippet ../examples/barchart/main.cpp 4 |
|
33 | 33 | |
|
34 |
We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting it |
|
|
34 | We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting its alignment | |
|
35 | 35 | to Qt::AlignBottom. |
|
36 | 36 | |
|
37 | 37 | \snippet ../examples/barchart/main.cpp 5 |
|
38 | 38 | |
|
39 | 39 | Finally we add the chart onto a view. We also turn on the antialiasing for the chartView. |
|
40 | 40 | |
|
41 | 41 | \snippet ../examples/barchart/main.cpp 6 |
|
42 | 42 | |
|
43 | 43 | Chart is ready to be shown. We set the chart to be central widget of the window. |
|
44 | 44 | We also set the size for the chart window and show it. |
|
45 | 45 | |
|
46 | 46 | \snippet ../examples/barchart/main.cpp 7 |
|
47 | 47 | */ |
@@ -1,57 +1,57 | |||
|
1 | 1 | /*! |
|
2 | 2 | \example examples/barmodelmapper |
|
3 | 3 | \title BarModelMapper example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | This example shows how to use QAbstractItemModel derived model as the data for the bar series. |
|
7 | 7 | |
|
8 | 8 | \image examples_barmodelmapper.png |
|
9 | 9 | |
|
10 | 10 | Let's start by creating an instance of CustomTableModel class. |
|
11 | 11 | CustomTableModel class is derived from QAbstractTableModel and it was created for the purpose of this example. |
|
12 | 12 | The constructor of this class populates the internal data store of the model with the data that is good for our chart example. |
|
13 | 13 | |
|
14 | 14 | \snippet ../examples/barmodelmapper/tablewidget.cpp 1 |
|
15 | 15 | |
|
16 | 16 | We now have a model with data that we would like to display both on the chart and in a QTableView. |
|
17 | 17 | First, we create QTableView and tell it use the model as a data source. To have the data presented nicely the minimum width of the table view is set and its headers resize mode changed to stretch. |
|
18 | 18 | |
|
19 | 19 | \snippet ../examples/barmodelmapper/tablewidget.cpp 2 |
|
20 | 20 | |
|
21 | 21 | Now we need QChart instance to display the same data on the chart. |
|
22 | 22 | We also enable animations. It makes it easier to see how modifying the model's data affect the chart. |
|
23 | 23 | |
|
24 | 24 | \snippet ../examples/barmodelmapper/tablewidget.cpp 3 |
|
25 | 25 | |
|
26 | 26 | First line of the code below creates new bar series. Variables firstRow and rowCount are used to define a custom model mapping. |
|
27 | 27 | Custom mapping allows to take only part of the data from the model. In this case data from 5 rows starting with the row with the index 3. |
|
28 | 28 | Following three lines create an instance of QVBarModelMapper class and specifie that data for the bar sets should be taken from the model's columns with indexes from 1 to 4(inclusive). |
|
29 | 29 | To create a connection between the series and the model we set both of those objects to QVBarModelMapper. |
|
30 | 30 | |
|
31 | 31 | Finally the series is added to the chart. |
|
32 | 32 | |
|
33 | 33 | \snippet ../examples/barmodelmapper/tablewidget.cpp 4 |
|
34 | 34 | |
|
35 | To show in QTableView which data coresponds with which bar set this example uses table coloring. | |
|
36 |
When series is added to the chart it is assigned a color b |
|
|
35 | To show in QTableView which data corresponds with which bar set this example uses table coloring. | |
|
36 | When series is added to the chart it is assigned a color based on the currently selected theme. | |
|
37 | 37 | Code below extracts that color from the series and uses it to create colored QTableView. |
|
38 | 38 | Coloring of the view is not a part of the QChart functionality. |
|
39 | 39 | |
|
40 | 40 | \snippet ../examples/barmodelmapper/tablewidget.cpp 5 |
|
41 | 41 | |
|
42 | 42 | We would like to have categories placed on the chart's axis that describe what the data means. |
|
43 | 43 | Next snippet shows how to do that. |
|
44 | 44 | |
|
45 | 45 | \snippet ../examples/barmodelmapper/tablewidget.cpp 6 |
|
46 | 46 | |
|
47 | 47 | To avoid setting up the QGraphicsScene we use QChartView class that does it for us. QChart object pointer is used as a parameter of the QChartView constructor. |
|
48 | 48 | To make the render look nicer Antialiasing is turned on and the minimum size of the chartView widget is set. |
|
49 | 49 | |
|
50 | 50 | \snippet ../examples/barmodelmapper/tablewidget.cpp 7 |
|
51 | 51 | |
|
52 | 52 | Finally we place both widgets in a layout and use the layout as the application layout. |
|
53 | 53 | |
|
54 | 54 | \snippet ../examples/barmodelmapper/tablewidget.cpp 8 |
|
55 | 55 | |
|
56 | 56 | Application is ready. Try modifying the data in the table view and see how it affects the chart. |
|
57 | 57 | */ |
@@ -1,37 +1,37 | |||
|
1 | 1 | /*! |
|
2 | 2 | \example examples/datetimeaxis |
|
3 | 3 | \title DateTimeAxis Example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | The example shows how to use QLineChart with QDateTimeAxis. |
|
7 | 7 | |
|
8 | 8 | \image examples_datetimeaxis.png |
|
9 | 9 | |
|
10 | 10 | To create line chart, QLineSeries instance is needed. Let's create one. |
|
11 | 11 | |
|
12 | 12 | \snippet ../examples/datetimeaxis/main.cpp 1 |
|
13 | 13 | |
|
14 | 14 | On the charts we will present how the number of sun spots changes in time. The data (by Space Weather Prediction Center) is read from a text file. |
|
15 | 15 | In the snippet below notice how QDateTime::toMSecsSinceEpoch method is used to convert the QDateTime object into a number that can be passed to QLineSeries append method. |
|
16 | 16 | |
|
17 | 17 | \snippet ../examples/datetimeaxis/main.cpp 2 |
|
18 | 18 | |
|
19 | To present the data on the char we need QChart instance. We add the series to it, hide the legend, create the default axes and set the title of the chart. | |
|
19 | To present the data on the chart we need QChart instance. We add the series to it, hide the legend, create the default axes and set the title of the chart. | |
|
20 | 20 | |
|
21 | 21 | \snippet ../examples/datetimeaxis/main.cpp 3 |
|
22 | 22 | |
|
23 |
Beca |
|
|
24 | First the instance of QDateTimeAxis is created, then the number of ticks that are to be shown is set. The number of sun spots is provided as an average for the month therfore we don't need the axis labels to contain the information about the time and the day. This is achived by setting a custom label format. | |
|
25 | Please refer to QDateTime::toString() method documntation to learn about the avaiable format options. | |
|
23 | Because we use QLineSeries calling createDefaultAxes will create QValueAxis both as X and Y axis. To use QDateTimeAxis we need to set it manually to the chart. | |
|
24 | First the instance of QDateTimeAxis is created, then the number of ticks that are to be shown is set. The number of sun spots is provided as an average for the month therefore we don't need the axis labels to contain the information about the time and the day. This is achieved by setting a custom label format. | |
|
25 | Please refer to QDateTime::toString() method documentation to learn about the available format options. | |
|
26 | 26 | |
|
27 | 27 | \snippet ../examples/datetimeaxis/main.cpp 4 |
|
28 | 28 | |
|
29 | 29 | Then we create 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. |
|
30 | 30 | |
|
31 | 31 | \snippet ../examples/datetimeaxis/main.cpp 5 |
|
32 | 32 | |
|
33 | 33 | Chart is ready to be shown. |
|
34 | 34 | |
|
35 | 35 | \snippet ../examples/datetimeaxis/main.cpp 6 |
|
36 | 36 | |
|
37 | 37 | */ |
@@ -1,48 +1,48 | |||
|
1 | 1 | /*! |
|
2 | 2 | \example examples/horizontalbarchart |
|
3 | 3 | \title HorizontalBarChart Example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | The example shows how to create a horizontal bar chart. QHorizontalBarChart shows the data in sets as separate bars, which are grouped in categories. QHorizontalBarChart works just like |
|
7 | 7 | QBarChart, except that the bars are drawn horizontally on the chart. |
|
8 | 8 | |
|
9 | 9 | \image examples_horizontalbarchart.png |
|
10 | 10 | |
|
11 | 11 | The barsets are used in same way in all barcharts. |
|
12 | 12 | To illustrate difference between various barcharts, we use same data in examples. |
|
13 | 13 | Data that barchart visualizes, is defined by QBarSet instances. Here we create the sets and append data |
|
14 | 14 | to them. The data is appended here with << operator. Alternatively the append method could be used. |
|
15 | 15 | |
|
16 | 16 | \snippet ../examples/horizontalbarchart/main.cpp 1 |
|
17 | 17 | |
|
18 | 18 | We create the series and append the barsets to it. The series takes ownership of the barsets. The series groups the data from sets to categories. |
|
19 | 19 | First value of each set are gropuped together at first category second value to second category and so on. |
|
20 | 20 | |
|
21 | 21 | \snippet ../examples/horizontalbarchart/main.cpp 2 |
|
22 | 22 | |
|
23 | 23 | Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling |
|
24 | 24 | setAnimationOptions(QChart::SeriesAnimations) |
|
25 | 25 | |
|
26 | 26 | \snippet ../examples/horizontalbarchart/main.cpp 3 |
|
27 | 27 | |
|
28 | 28 | To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and |
|
29 | 29 | set it to be the y-axis of the chart. The chart takes ownership of axis. For x-axis we use default axis, which is created and scaled to series data |
|
30 | 30 | by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will |
|
31 | 31 | override the category axis. |
|
32 | 32 | |
|
33 | 33 | \snippet ../examples/horizontalbarchart/main.cpp 4 |
|
34 | 34 | |
|
35 |
We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting it |
|
|
35 | We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting its alignment | |
|
36 | 36 | to Qt::AlignBottom. |
|
37 | 37 | |
|
38 | 38 | \snippet ../examples/horizontalbarchart/main.cpp 5 |
|
39 | 39 | |
|
40 | 40 | Finally we add the chart onto a view. We also turn on the antialiasing for the chartView. |
|
41 | 41 | |
|
42 | 42 | \snippet ../examples/horizontalbarchart/main.cpp 6 |
|
43 | 43 | |
|
44 | 44 | Chart is ready to be shown. We set the chart to be central widget of the window. |
|
45 | 45 | We also set the size for the chart window and show it. |
|
46 | 46 | |
|
47 | 47 | \snippet ../examples/horizontalbarchart/main.cpp 7 |
|
48 | 48 | */ |
@@ -1,53 +1,53 | |||
|
1 | 1 | /*! |
|
2 | 2 | \example examples/horizontalpercentbarchart |
|
3 | 3 | \title HorizontalPercentBarChart Example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | The example shows how to create simple horizontal percent bar chart. Horizontal percent bar chart shows the data in set as percentage of |
|
7 | 7 | all sets, per category. |
|
8 | 8 | |
|
9 | 9 | Creating horizontal percent bar chart is just like creating a regular \l {BarChart Example} {bar chart}, except that for a |
|
10 | 10 | horizontal percent bar chart, we use QHorizontalPercentBarSeries api instead of QBarSeries. Also, in the |
|
11 | 11 | \l {BarChart Example} {bar chart} we used nice numbers algorithm to make the y axis numbering look better. With |
|
12 | 12 | percent bar chart there is no need for that, because the maximum y-axis value is always 100. |
|
13 | 13 | |
|
14 | 14 | \image examples_horizontalpercentbarchart.png |
|
15 | 15 | |
|
16 | 16 | The barsets are used in same way in all barcharts. |
|
17 | 17 | To illustrate difference between various barcharts, we use same data in examples. |
|
18 | 18 | Data that barchart visualizes, is defined by QBarSet instances. Here we create the sets and append data |
|
19 | 19 | to them. The data is appended here with << operator. Alternatively the append method could be used. |
|
20 | 20 | |
|
21 | 21 | \snippet ../examples/horizontalpercentbarchart/main.cpp 1 |
|
22 | 22 | |
|
23 | 23 | We create the series and append the barsets to it. The series takes ownership of the barsets. The series groups the data from sets to categories. |
|
24 |
|
|
|
24 | First values of each set are grouped together at first category second value to second category and so on. | |
|
25 | 25 | |
|
26 | 26 | \snippet ../examples/horizontalpercentbarchart/main.cpp 2 |
|
27 | 27 | |
|
28 | 28 | Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling |
|
29 | 29 | setAnimationOptions(QChart::SeriesAnimations) |
|
30 | 30 | |
|
31 | 31 | \snippet ../examples/horizontalpercentbarchart/main.cpp 3 |
|
32 | 32 | |
|
33 | 33 | To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and |
|
34 | 34 | set it to be the y-axis of the chart. The chart takes ownership of axis. For x-axis we use default axis, which is created and scaled to series data |
|
35 | 35 | by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will |
|
36 | 36 | override the category axis. |
|
37 | 37 | |
|
38 | 38 | \snippet ../examples/horizontalpercentbarchart/main.cpp 4 |
|
39 | 39 | |
|
40 |
We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting it |
|
|
40 | We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting its alignment | |
|
41 | 41 | to Qt::AlignBottom. |
|
42 | 42 | |
|
43 | 43 | \snippet ../examples/horizontalpercentbarchart/main.cpp 5 |
|
44 | 44 | |
|
45 | 45 | Finally we add the chart onto a view. We also turn on the antialiasing for the chartView. |
|
46 | 46 | |
|
47 | 47 | \snippet ../examples/horizontalpercentbarchart/main.cpp 6 |
|
48 | 48 | |
|
49 | 49 | Chart is ready to be shown. We set the chart to be central widget of the window. |
|
50 | 50 | We also set the size for the chart window and show it. |
|
51 | 51 | |
|
52 | 52 | \snippet ../examples/horizontalpercentbarchart/main.cpp 7 |
|
53 | 53 | */ |
@@ -1,50 +1,50 | |||
|
1 | 1 | /*! |
|
2 | 2 | \example examples/horizontalstackedbarchart |
|
3 | 3 | \title HorizontalStackedBarChart Example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | The example shows how to create simple stacked horizontal bar chart. Stacked bar chart shows the data in sets as bars that are |
|
7 | 7 | stacked on top of each other. The stacking is done per category. |
|
8 | 8 | Creating stacked horizontal bar chart is just like creating a regular \l {BarChart Example} {bar chart}, except that for a |
|
9 | 9 | stacked horizontal bar chart, we use QHorizontalStackedBarSeries api instead of QBarSeries. |
|
10 | 10 | |
|
11 | 11 | \image examples_horizontalstackedbarchart.png |
|
12 | 12 | |
|
13 | 13 | The barsets are used in same way in all barcharts. |
|
14 | 14 | To illustrate difference between various barcharts, we use same data in examples. |
|
15 | 15 | Data that barchart visualizes, is defined by QBarSet instances. Here we create the sets and append data |
|
16 | 16 | to them. The data is appended here with << operator. Alternatively the append method could be used. |
|
17 | 17 | |
|
18 | 18 | \snippet ../examples/horizontalstackedbarchart/main.cpp 1 |
|
19 | 19 | |
|
20 | 20 | We create the series and append the barsets to it. The series takes ownership of the barsets. The series groups the data from sets to categories. |
|
21 |
|
|
|
21 | First values of each set are grouped together at first category second value to second category and so on. | |
|
22 | 22 | |
|
23 | 23 | \snippet ../examples/horizontalstackedbarchart/main.cpp 2 |
|
24 | 24 | |
|
25 | 25 | Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling |
|
26 | 26 | setAnimationOptions(QChart::SeriesAnimations) |
|
27 | 27 | |
|
28 | 28 | \snippet ../examples/horizontalstackedbarchart/main.cpp 3 |
|
29 | 29 | |
|
30 | 30 | To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and |
|
31 | 31 | set it to be the y-axis of the chart. The chart takes ownership of axis. For x-axis we use default axis, which is created and scaled to series data |
|
32 | 32 | by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will |
|
33 | 33 | override the category axis. |
|
34 | 34 | |
|
35 | 35 | \snippet ../examples/horizontalstackedbarchart/main.cpp 4 |
|
36 | 36 | |
|
37 |
We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting it |
|
|
37 | We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting its alignment | |
|
38 | 38 | to Qt::AlignBottom. |
|
39 | 39 | |
|
40 | 40 | \snippet ../examples/horizontalstackedbarchart/main.cpp 5 |
|
41 | 41 | |
|
42 | 42 | Finally we add the chart onto a view. We also turn on the antialiasing for the chartView. |
|
43 | 43 | |
|
44 | 44 | \snippet ../examples/horizontalstackedbarchart/main.cpp 6 |
|
45 | 45 | |
|
46 | 46 | Chart is ready to be shown. We set the chart to be central widget of the window. |
|
47 | 47 | We also set the size for the chart window and show it. |
|
48 | 48 | |
|
49 | 49 | \snippet ../examples/horizontalstackedbarchart/main.cpp 7 |
|
50 | 50 | */ |
@@ -1,46 +1,46 | |||
|
1 | 1 | /*! |
|
2 | 2 | \example examples/lineandbar |
|
3 | 3 | \title Line and BarChart Example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | The example shows how to combine different charts and set the axes. In the example we combine linechart with |
|
7 | 7 | barchart and use category axis as common axis for both. |
|
8 | 8 | |
|
9 | 9 | \image examples_lineandbar.png |
|
10 | 10 | |
|
11 | 11 | Here we create data for our barseries. |
|
12 | 12 | |
|
13 | 13 | \snippet ../examples/lineandbar/main.cpp 1 |
|
14 | 14 | |
|
15 | 15 | We create the barseries and append the sets to it. |
|
16 |
|
|
|
16 | First values of each set are grouped together at first category second value to second category and so on. | |
|
17 | 17 | |
|
18 | 18 | \snippet ../examples/lineandbar/main.cpp 2 |
|
19 | 19 | |
|
20 | 20 | Then we create lineseries and add data to it. To make data match with barchart we use index as an x-value for our line series, so that |
|
21 | 21 | first point is at (0,value) second at (1,value) and so on. |
|
22 | 22 | |
|
23 | 23 | \snippet ../examples/lineandbar/main.cpp 8 |
|
24 | 24 | |
|
25 | 25 | Here we create the chart and add both series to it. |
|
26 | 26 | |
|
27 | 27 | \snippet ../examples/lineandbar/main.cpp 3 |
|
28 | 28 | |
|
29 | 29 | To make chart show series properly, we have to create custom axes for series. If we don't create custom axes, then each series will get scaled to |
|
30 | 30 | use maximum area of the chart (like in single series case) and result will be incorrect. With custom axes we set the range of both series to follow same |
|
31 | 31 | axis. For x-axis we use QBarCategoryAxis and for y-axis we use QValuesAxis. |
|
32 | 32 | |
|
33 | 33 | \snippet ../examples/lineandbar/main.cpp 4 |
|
34 | 34 | |
|
35 | 35 | And we also want to show the legend. |
|
36 | 36 | |
|
37 | 37 | \snippet ../examples/lineandbar/main.cpp 5 |
|
38 | 38 | |
|
39 | 39 | Finally we add the chart onto a view. |
|
40 | 40 | |
|
41 | 41 | \snippet ../examples/lineandbar/main.cpp 6 |
|
42 | 42 | |
|
43 | 43 | And it is ready to be shown in a window. |
|
44 | 44 | |
|
45 | 45 | \snippet ../examples/lineandbar/main.cpp 7 |
|
46 | 46 | */ |
@@ -1,30 +1,30 | |||
|
1 | 1 | /*! |
|
2 | 2 | \example examples/linechart |
|
3 | 3 | \title LineChart Example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | The example shows how to create simple line chart. |
|
7 | 7 | |
|
8 | 8 | \image examples_linechart.png |
|
9 | 9 | |
|
10 | 10 | To create line chart, QLineSeries instance is needed. Let's create one. |
|
11 | 11 | |
|
12 | 12 | \snippet ../examples/linechart/main.cpp 1 |
|
13 | 13 | |
|
14 | 14 | Then we add data to series. We can use append() member function or use stream operator. |
|
15 | 15 | |
|
16 | 16 | \snippet ../examples/linechart/main.cpp 2 |
|
17 | 17 | |
|
18 | To present the data on the char we need QChart instance. We add the series to it, create the default axes and set the title of the chart. | |
|
18 | To present the data on the chart we need QChart instance. We add the series to it, create the default axes and set the title of the chart. | |
|
19 | 19 | |
|
20 | 20 | \snippet ../examples/linechart/main.cpp 3 |
|
21 | 21 | |
|
22 | 22 | Then we create 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. |
|
23 | 23 | |
|
24 | 24 | \snippet ../examples/linechart/main.cpp 4 |
|
25 | 25 | |
|
26 | 26 | Chart is ready to be shown. |
|
27 | 27 | |
|
28 | 28 | \snippet ../examples/linechart/main.cpp 5 |
|
29 | 29 | |
|
30 | 30 | */ |
@@ -1,30 +1,30 | |||
|
1 | 1 | /*! |
|
2 | 2 | \example examples/logvalueaxis |
|
3 | 3 | \title Logarithmic axis example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | The example shows how to use QLogValueAxis. |
|
7 | 7 | |
|
8 | 8 | \image examples_logvalueaxis.png |
|
9 | 9 | |
|
10 | 10 | Create QLineSeries instance and add some data to it. |
|
11 | 11 | |
|
12 | 12 | \snippet ../examples/logvalueaxis/main.cpp 1 |
|
13 | 13 | |
|
14 | To present the data on the char we need QChart instance. Add the series to it, hide the legend and set the title of the chart. | |
|
14 | To present the data on the chart we need QChart instance. Add the series to it, hide the legend and set the title of the chart. | |
|
15 | 15 | |
|
16 | 16 | \snippet ../examples/logvalueaxis/main.cpp 2 |
|
17 | 17 | |
|
18 | 18 | Create the axes. Add them to the chart and attach to the series. |
|
19 | 19 | |
|
20 | 20 | \snippet ../examples/logvalueaxis/main.cpp 3 |
|
21 | 21 | |
|
22 | 22 | Then create a QChartView object with QChart as a parameter. Enable antialiasing to have the rendered line look nicer. |
|
23 | 23 | |
|
24 | 24 | \snippet ../examples/logvalueaxis/main.cpp 4 |
|
25 | 25 | |
|
26 | 26 | Chart is ready to be shown. |
|
27 | 27 | |
|
28 | 28 | \snippet ../examples/logvalueaxis/main.cpp 5 |
|
29 | 29 | |
|
30 | 30 | */ |
@@ -1,57 +1,57 | |||
|
1 | 1 | /*! |
|
2 | 2 | \example examples/modeldata |
|
3 | 3 | \title Model data example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | This example shows how to use QAbstractItemModel derived model as the data for the series. |
|
7 | 7 | |
|
8 | 8 | \image examples_modeldata.png |
|
9 | 9 | |
|
10 | 10 | Let's start by creating an instance of CustomTableModel class. |
|
11 | 11 | CustomTableModel class is derived from QAbstractTableModel and it was created for the purpose of this example. |
|
12 | 12 | The constructor of this class populates the internal data store of the model with the data that is good for our chart example. |
|
13 | 13 | |
|
14 | 14 | \snippet ../examples/modeldata/tablewidget.cpp 1 |
|
15 | 15 | |
|
16 | 16 | We now have a model with data that we would like to display both on the chart and in a QTableView. |
|
17 | 17 | First, we create QTableView and tell it use the model as a data source. To make the data cells fill the table view we also change headers resize mode. |
|
18 | 18 | |
|
19 | 19 | \snippet ../examples/modeldata/tablewidget.cpp 2 |
|
20 | 20 | |
|
21 | 21 | Now we need QChart instance to display the same data on the chart. |
|
22 | 22 | We also enable animations. It makes it easier to see how modifying the model's data affect the chart. |
|
23 | 23 | |
|
24 | 24 | \snippet ../examples/modeldata/tablewidget.cpp 3 |
|
25 | 25 | |
|
26 | 26 | The code below creates new line series and gives it a name. Following line creates an instance of QVXYModelMapper class. |
|
27 | 27 | Next two lines specifie that x coordinates are taken from the model's column(Qt::Vertical) with index 0 and the y coordinates are taken from the model's column with index 1. |
|
28 | 28 | To create a connection between the series and the model we set both of those objects to QVXYModelMapper. |
|
29 | 29 | |
|
30 | 30 | Finally the series is added to the chart. |
|
31 | 31 | |
|
32 | 32 | \snippet ../examples/modeldata/tablewidget.cpp 4 |
|
33 | 33 | |
|
34 | To show in QTableView which data coresponds with which series this example uses table coloring. | |
|
34 | To show in QTableView which data corresponds with which series this example uses table coloring. | |
|
35 | 35 | When series is added to the chart it is assigned a color based on the currently selected theme. |
|
36 | 36 | Code below extracts that color from the series and uses it to create colored QTableView. |
|
37 | 37 | Coloring of the view is not a part of the QChart functionality. |
|
38 | 38 | |
|
39 | 39 | \snippet ../examples/modeldata/tablewidget.cpp 5 |
|
40 | 40 | |
|
41 | 41 | The same operations are done with second series. Notice that for this series different columns of the same model are mapped. |
|
42 | 42 | |
|
43 | 43 | \snippet ../examples/modeldata/tablewidget.cpp 6 |
|
44 | 44 | |
|
45 | 45 | \snippet ../examples/modeldata/tablewidget.cpp 7 |
|
46 | 46 | |
|
47 | 47 | To avoid setting up the QGraphicsScene we use QChartView class that does it for us. QChart object pointer is used as a parameter of the QChartView constructor. |
|
48 | 48 | To make the render look nicer Antialiasing is turned on and the minimum size of the chartView widget is set. |
|
49 | 49 | |
|
50 | 50 | \snippet ../examples/modeldata/tablewidget.cpp 8 |
|
51 | 51 | |
|
52 | 52 | Finally we place both widgets in a layout and use the layout as the application layout. |
|
53 | 53 | |
|
54 | 54 | \snippet ../examples/modeldata/tablewidget.cpp 9 |
|
55 | 55 | |
|
56 | 56 | Application is ready. Try modifying the data in the table view and see how it affects the chart. |
|
57 | 57 | */ |
@@ -1,53 +1,53 | |||
|
1 | 1 | /*! |
|
2 | 2 | \example examples/percentbarchart |
|
3 | 3 | \title PercentBarChart Example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | The example shows how to create simple percent bar chart. Percent bar chart shows the data in set as percentage of |
|
7 | 7 | all sets, per category. |
|
8 | 8 | |
|
9 | 9 | Creating percent bar chart is just like creating a regular \l {BarChart Example} {bar chart}, except that for a |
|
10 | 10 | percent bar chart, we use QPercentBarSeries api instead of QBarSeries. Also, in the |
|
11 | 11 | \l {BarChart Example} {bar chart} we used nice numbers algorithm to make the y axis numbering look better. With |
|
12 | 12 | percent bar chart there is no need for that, because the maximum y-axis value is always 100. |
|
13 | 13 | |
|
14 | 14 | \image examples_percentbarchart.png |
|
15 | 15 | |
|
16 | 16 | The barsets are used in same way in all barcharts. |
|
17 | 17 | To illustrate difference between various barcharts, we use same data in examples. |
|
18 | 18 | Data that barchart visualizes, is defined by QBarSet instances. Here we create the sets and append data |
|
19 | 19 | to them. The data is appended here with << operator. Alternatively the append method could be used. |
|
20 | 20 | |
|
21 | 21 | \snippet ../examples/percentbarchart/main.cpp 1 |
|
22 | 22 | |
|
23 | 23 | We create the series and append the barsets to it. The series takes ownership of the barsets. The series groups the data from sets to categories. |
|
24 |
|
|
|
24 | First values of each set are grouped together at first category second value to second category and so on. | |
|
25 | 25 | |
|
26 | 26 | \snippet ../examples/percentbarchart/main.cpp 2 |
|
27 | 27 | |
|
28 | 28 | Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling |
|
29 | 29 | setAnimationOptions(QChart::SeriesAnimations) |
|
30 | 30 | |
|
31 | 31 | \snippet ../examples/percentbarchart/main.cpp 3 |
|
32 | 32 | |
|
33 | 33 | To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and |
|
34 | 34 | set it to be the x-axis of the chart. The chart takes ownership of axis. For y-axis we use default axis, which is created and scaled to series data |
|
35 | 35 | by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will |
|
36 | 36 | override the category axis. |
|
37 | 37 | |
|
38 | 38 | \snippet ../examples/percentbarchart/main.cpp 4 |
|
39 | 39 | |
|
40 |
We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting it |
|
|
40 | We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting its alignment | |
|
41 | 41 | to Qt::AlignBottom. |
|
42 | 42 | |
|
43 | 43 | \snippet ../examples/percentbarchart/main.cpp 5 |
|
44 | 44 | |
|
45 | 45 | Finally we add the chart onto a view. We also turn on the antialiasing for the chartView. |
|
46 | 46 | |
|
47 | 47 | \snippet ../examples/percentbarchart/main.cpp 6 |
|
48 | 48 | |
|
49 | 49 | Chart is ready to be shown. We set the chart to be central widget of the window. |
|
50 | 50 | We also set the size for the chart window and show it. |
|
51 | 51 | |
|
52 | 52 | \snippet ../examples/percentbarchart/main.cpp 7 |
|
53 | 53 | */ |
@@ -1,54 +1,54 | |||
|
1 | 1 | /*! |
|
2 | 2 | \example examples/stackedbarchart |
|
3 | 3 | \title StackedBarChart Example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | The example shows how to create simple stacked bar chart. Stacked bar chart shows the data in sets as bars that are |
|
7 | 7 | stacked on top of each other. The stacking is done per category. |
|
8 | 8 | The example shows how to create simple stacked bar chart. Stacked bar chart shows the data in sets as bars that are |
|
9 | 9 | stacked on top of each other. The stacking is done per category. |
|
10 | 10 | Creating stacked bar chart is just like creating a regular \l {BarChart Example} {bar chart}, except that for a |
|
11 | 11 | stacked bar chart, we use QStackedBarSeries api instead of QBarSeries. |
|
12 | 12 | |
|
13 | 13 | \image examples_stackedbarchart.png |
|
14 | 14 | |
|
15 | 15 | The barsets are used in same way in all barcharts. |
|
16 | 16 | To illustrate difference between various barcharts, we use same data in examples. |
|
17 | 17 | Data that barchart visualizes, is defined by QBarSet instances. Here we create the sets and append data |
|
18 | 18 | to them. The data is appended here with << operator. Alternatively the append method could be used. |
|
19 | 19 | |
|
20 | 20 | \snippet ../examples/stackedbarchart/main.cpp 1 |
|
21 | 21 | |
|
22 | 22 | We create the series and append the barsets to it. The series takes ownership of the barsets. The series groups the data from sets to categories. |
|
23 |
|
|
|
23 | First values of each set are grouped together at first category second value to second category and so on. | |
|
24 | 24 | |
|
25 | 25 | \snippet ../examples/stackedbarchart/main.cpp 2 |
|
26 | 26 | |
|
27 | 27 | Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling |
|
28 | 28 | setAnimationOptions(QChart::SeriesAnimations) |
|
29 | 29 | |
|
30 | 30 | \snippet ../examples/stackedbarchart/main.cpp 3 |
|
31 | 31 | |
|
32 | 32 | To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and |
|
33 | 33 | set it to be the x-axis of the chart. The chart takes ownership of axis. For y-axis we use default axis, which is created and scaled to series data |
|
34 | 34 | by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will |
|
35 | 35 | override the category axis. |
|
36 | 36 | |
|
37 | 37 | \snippet ../examples/stackedbarchart/main.cpp 4 |
|
38 | 38 | |
|
39 |
We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting it |
|
|
39 | We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting its alignment | |
|
40 | 40 | to Qt::AlignBottom. |
|
41 | 41 | |
|
42 | 42 | \snippet ../examples/stackedbarchart/main.cpp 5 |
|
43 | 43 | |
|
44 | 44 | Finally we add the chart onto a view. We also turn on the antialiasing for the chartView. |
|
45 | 45 | |
|
46 | 46 | \snippet ../examples/stackedbarchart/main.cpp 6 |
|
47 | 47 | |
|
48 | 48 | Chart is ready to be shown. We set the chart to be central widget of the window. |
|
49 | 49 | We also set the size for the chart window and show it. |
|
50 | 50 | |
|
51 | 51 | \snippet ../examples/stackedbarchart/main.cpp 7 |
|
52 | 52 | */ |
|
53 | 53 | |
|
54 | 54 |
@@ -1,44 +1,44 | |||
|
1 | 1 | /*! |
|
2 | 2 | \example examples/temperaturerecords |
|
3 | 3 | \title Temperature records example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | The example shows how to create a bar chart with negative bars. For example purposes we use temperature data. |
|
7 | 7 | |
|
8 | 8 | \image examples_temperaturerecords.png |
|
9 | 9 | |
|
10 | 10 | First we create two barsets and append the data to them. One set represents the minimum temperatures and another maximum temperatures. |
|
11 | 11 | |
|
12 | 12 | \snippet ../examples/temperaturerecords/main.cpp 1 |
|
13 | 13 | |
|
14 | 14 | We create the series and append the barsets to it. The series takes ownership of the barsets. |
|
15 | 15 | |
|
16 | 16 | \snippet ../examples/temperaturerecords/main.cpp 2 |
|
17 | 17 | |
|
18 | 18 | Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling |
|
19 | 19 | setAnimationOptions(QChart::SeriesAnimations) |
|
20 | 20 | |
|
21 | 21 | \snippet ../examples/temperaturerecords/main.cpp 3 |
|
22 | 22 | |
|
23 | 23 | To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and |
|
24 | 24 | set it to be the x-axis of the chart. The chart takes ownership of axis. For y-axis we use default axis, which is created and scaled to series data |
|
25 | 25 | by calling createDefaultAxes of the chart. We change the range for y-axis, since in this case it gives nicer result than autoscaling. |
|
26 | 26 | |
|
27 | 27 | Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will override the category axis. |
|
28 | 28 | |
|
29 | 29 | \snippet ../examples/temperaturerecords/main.cpp 4 |
|
30 | 30 | |
|
31 |
We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting it |
|
|
31 | We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting its alignment | |
|
32 | 32 | to Qt::AlignBottom. |
|
33 | 33 | |
|
34 | 34 | \snippet ../examples/temperaturerecords/main.cpp 5 |
|
35 | 35 | |
|
36 | 36 | Finally we add the chart onto a view. We also turn on the antialiasing for the chartView. |
|
37 | 37 | |
|
38 | 38 | \snippet ../examples/temperaturerecords/main.cpp 6 |
|
39 | 39 | |
|
40 | 40 | Chart is ready to be shown. We set the chart to be central widget of the window. |
|
41 | 41 | We also set the size for the chart window and show it. |
|
42 | 42 | |
|
43 | 43 | \snippet ../examples/temperaturerecords/main.cpp 7 |
|
44 | 44 | */ |
@@ -1,654 +1,654 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 "qchart.h" |
|
22 | 22 | #include "qchart_p.h" |
|
23 | 23 | #include "legendscroller_p.h" |
|
24 | 24 | #include "qlegend_p.h" |
|
25 | 25 | #include "chartbackground_p.h" |
|
26 | 26 | #include "qabstractaxis.h" |
|
27 | 27 | #include "chartlayout_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | #include "chartpresenter_p.h" |
|
30 | 30 | #include "chartdataset_p.h" |
|
31 | 31 | #include <QGraphicsScene> |
|
32 | 32 | #include <QGraphicsSceneResizeEvent> |
|
33 | 33 | |
|
34 | 34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | 35 | |
|
36 | 36 | /*! |
|
37 | 37 | \enum QChart::ChartTheme |
|
38 | 38 | |
|
39 | 39 | This enum describes the theme used by the chart. |
|
40 | 40 | |
|
41 | 41 | \value ChartThemeLight The default theme |
|
42 | 42 | \value ChartThemeBlueCerulean |
|
43 | 43 | \value ChartThemeDark |
|
44 | 44 | \value ChartThemeBrownSand |
|
45 | 45 | \value ChartThemeBlueNcs |
|
46 | 46 | \value ChartThemeHighContrast |
|
47 | 47 | \value ChartThemeBlueIcy |
|
48 | 48 | */ |
|
49 | 49 | |
|
50 | 50 | /*! |
|
51 | 51 | \enum QChart::AnimationOption |
|
52 | 52 | |
|
53 | 53 | For enabling/disabling animations. Defaults to NoAnimation. |
|
54 | 54 | |
|
55 | 55 | \value NoAnimation |
|
56 | 56 | \value GridAxisAnimations |
|
57 | 57 | \value SeriesAnimations |
|
58 | 58 | \value AllAnimations |
|
59 | 59 | */ |
|
60 | 60 | |
|
61 | 61 | /*! |
|
62 | 62 | \class QChart |
|
63 | 63 | \brief QtCommercial chart API. |
|
64 | 64 | |
|
65 | 65 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
66 | 66 | representation of different types of series and other chart related objects like |
|
67 | 67 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the |
|
68 | 68 | convenience class QChartView instead of QChart. |
|
69 | 69 | \sa QChartView |
|
70 | 70 | */ |
|
71 | 71 | |
|
72 | 72 | /*! |
|
73 | 73 | \property QChart::animationOptions |
|
74 | 74 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
75 | 75 | */ |
|
76 | 76 | |
|
77 | 77 | /*! |
|
78 | 78 | \property QChart::backgroundVisible |
|
79 | 79 | Whether the chart background is visible or not. |
|
80 | 80 | \sa setBackgroundBrush(), setBackgroundPen() |
|
81 | 81 | */ |
|
82 | 82 | |
|
83 | 83 | /*! |
|
84 | 84 | \property QChart::dropShadowEnabled |
|
85 | 85 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
86 | 86 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
87 | 87 | */ |
|
88 | 88 | |
|
89 | 89 | /*! |
|
90 | 90 | \property QChart::minimumMargins |
|
91 | 91 | Minimum margins between the plot area (axes) and the edge of the chart widget. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \property QChart::margins |
|
96 | 96 | Minimum between the plot area (axes) and the edge of the chart widget. |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \property QChart::theme |
|
101 | 101 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
102 | 102 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few |
|
103 | 103 | different themes. |
|
104 | 104 | Note: changing the theme will overwrite all customizations previously applied to the series. |
|
105 | 105 | */ |
|
106 | 106 | |
|
107 | 107 | /*! |
|
108 | 108 | \property QChart::title |
|
109 | 109 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
114 | 114 | */ |
|
115 | 115 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
116 | 116 | : QGraphicsWidget(parent, wFlags), |
|
117 | 117 | d_ptr(new QChartPrivate(this)) |
|
118 | 118 | { |
|
119 | 119 | d_ptr->m_legend = new LegendScroller(this); |
|
120 | 120 | setTheme(QChart::ChartThemeLight); |
|
121 | 121 | setLayout(d_ptr->m_presenter->layout()); |
|
122 | 122 | } |
|
123 | 123 | |
|
124 | 124 | /*! |
|
125 | 125 | Destroys the object and it's children, like series and axis objects added to it. |
|
126 | 126 | */ |
|
127 | 127 | QChart::~QChart() |
|
128 | 128 | { |
|
129 | 129 | //start by deleting dataset, it will remove all series and axes |
|
130 | 130 | delete d_ptr->m_dataset; |
|
131 | 131 | d_ptr->m_dataset = 0; |
|
132 | 132 | } |
|
133 | 133 | |
|
134 | 134 | /*! |
|
135 | 135 | Adds the \a series onto the chart and takes the ownership of the object. |
|
136 | 136 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
137 | 137 | the y axis). |
|
138 | 138 | |
|
139 | 139 | \sa removeSeries(), removeAllSeries() |
|
140 | 140 | */ |
|
141 | 141 | void QChart::addSeries(QAbstractSeries *series) |
|
142 | 142 | { |
|
143 | 143 | Q_ASSERT(series); |
|
144 | 144 | d_ptr->m_dataset->addSeries(series); |
|
145 | 145 | } |
|
146 | 146 | |
|
147 | 147 | /*! |
|
148 | 148 | Removes the \a series specified in a perameter from the QChartView. |
|
149 | 149 | It releses its ownership of the specified QChartSeries object. |
|
150 | 150 | It does not delete the pointed QChartSeries data object |
|
151 | 151 | \sa addSeries(), removeAllSeries() |
|
152 | 152 | */ |
|
153 | 153 | void QChart::removeSeries(QAbstractSeries *series) |
|
154 | 154 | { |
|
155 | 155 | Q_ASSERT(series); |
|
156 | 156 | d_ptr->m_dataset->removeSeries(series); |
|
157 | 157 | } |
|
158 | 158 | |
|
159 | 159 | /*! |
|
160 | 160 | Removes all the QChartSeries that have been added to the QChartView |
|
161 | 161 | It also deletes the pointed QChartSeries data objects |
|
162 | 162 | \sa addSeries(), removeSeries() |
|
163 | 163 | */ |
|
164 | 164 | void QChart::removeAllSeries() |
|
165 | 165 | { |
|
166 | 166 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ |
|
167 | 167 | removeSeries(s); |
|
168 | 168 | delete s; |
|
169 | 169 | } |
|
170 | 170 | } |
|
171 | 171 | |
|
172 | 172 | /*! |
|
173 | 173 | Sets the \a brush that is used for painting the background of the chart area. |
|
174 | 174 | */ |
|
175 | 175 | void QChart::setBackgroundBrush(const QBrush &brush) |
|
176 | 176 | { |
|
177 | 177 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
178 | 178 | } |
|
179 | 179 | |
|
180 | 180 | /*! |
|
181 | 181 | Gets the brush that is used for painting the background of the chart area. |
|
182 | 182 | */ |
|
183 | 183 | QBrush QChart::backgroundBrush() const |
|
184 | 184 | { |
|
185 | 185 | return d_ptr->m_presenter->backgroundBrush(); |
|
186 | 186 | } |
|
187 | 187 | |
|
188 | 188 | /*! |
|
189 | 189 | Sets the \a pen that is used for painting the background of the chart area. |
|
190 | 190 | */ |
|
191 | 191 | void QChart::setBackgroundPen(const QPen &pen) |
|
192 | 192 | { |
|
193 | 193 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
194 | 194 | } |
|
195 | 195 | |
|
196 | 196 | /*! |
|
197 | 197 | Gets the pen that is used for painting the background of the chart area. |
|
198 | 198 | */ |
|
199 | 199 | QPen QChart::backgroundPen() const |
|
200 | 200 | { |
|
201 | 201 | return d_ptr->m_presenter->backgroundPen(); |
|
202 | 202 | } |
|
203 | 203 | |
|
204 | 204 | /*! |
|
205 | 205 | Sets the chart \a title. The description text that is drawn above the chart. |
|
206 | 206 | */ |
|
207 | 207 | void QChart::setTitle(const QString &title) |
|
208 | 208 | { |
|
209 | 209 | d_ptr->m_presenter->setTitle(title); |
|
210 | 210 | } |
|
211 | 211 | |
|
212 | 212 | /*! |
|
213 | 213 | Returns the chart title. The description text that is drawn above the chart. |
|
214 | 214 | */ |
|
215 | 215 | QString QChart::title() const |
|
216 | 216 | { |
|
217 | 217 | return d_ptr->m_presenter->title(); |
|
218 | 218 | } |
|
219 | 219 | |
|
220 | 220 | /*! |
|
221 | 221 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. |
|
222 | 222 | */ |
|
223 | 223 | void QChart::setTitleFont(const QFont &font) |
|
224 | 224 | { |
|
225 | 225 | d_ptr->m_presenter->setTitleFont(font); |
|
226 | 226 | } |
|
227 | 227 | |
|
228 | 228 | /*! |
|
229 | 229 | Gets the font that is used for drawing the chart description text that is rendered above the chart. |
|
230 | 230 | */ |
|
231 | 231 | QFont QChart::titleFont() const |
|
232 | 232 | { |
|
233 | 233 | return d_ptr->m_presenter->titleFont(); |
|
234 | 234 | } |
|
235 | 235 | |
|
236 | 236 | /*! |
|
237 | 237 | Sets the \a brush used for rendering the title text. |
|
238 | 238 | */ |
|
239 | 239 | void QChart::setTitleBrush(const QBrush &brush) |
|
240 | 240 | { |
|
241 | 241 | d_ptr->m_presenter->setTitleBrush(brush); |
|
242 | 242 | } |
|
243 | 243 | |
|
244 | 244 | /*! |
|
245 | 245 | Returns the brush used for rendering the title text. |
|
246 | 246 | */ |
|
247 | 247 | QBrush QChart::titleBrush() const |
|
248 | 248 | { |
|
249 | 249 | return d_ptr->m_presenter->titleBrush(); |
|
250 | 250 | } |
|
251 | 251 | |
|
252 | 252 | void QChart::setTheme(QChart::ChartTheme theme) |
|
253 | 253 | { |
|
254 | 254 | d_ptr->m_themeManager->setTheme(theme); |
|
255 | 255 | } |
|
256 | 256 | |
|
257 | 257 | QChart::ChartTheme QChart::theme() const |
|
258 | 258 | { |
|
259 | 259 | return d_ptr->m_themeManager->theme()->id(); |
|
260 | 260 | } |
|
261 | 261 | |
|
262 | 262 | /*! |
|
263 | 263 | Zooms in the view by a factor of 2 |
|
264 | 264 | */ |
|
265 | 265 | void QChart::zoomIn() |
|
266 | 266 | { |
|
267 | 267 | d_ptr->zoomIn(2.0); |
|
268 | 268 | } |
|
269 | 269 | |
|
270 | 270 | /*! |
|
271 | 271 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
272 | 272 | */ |
|
273 | 273 | void QChart::zoomIn(const QRectF &rect) |
|
274 | 274 | { |
|
275 | 275 | d_ptr->zoomIn(rect); |
|
276 | 276 | } |
|
277 | 277 | |
|
278 | 278 | /*! |
|
279 | 279 | Restores the view zoom level to the previous one. |
|
280 | 280 | */ |
|
281 | 281 | void QChart::zoomOut() |
|
282 | 282 | { |
|
283 | 283 | d_ptr->zoomOut(2.0); |
|
284 | 284 | } |
|
285 | 285 | |
|
286 | 286 | /*! |
|
287 | 287 | Zooms in the view by a \a factor. |
|
288 | 288 | |
|
289 | 289 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
290 | 290 | */ |
|
291 | 291 | void QChart::zoom(qreal factor) |
|
292 | 292 | { |
|
293 | 293 | if (qFuzzyCompare(factor, 0)) |
|
294 | 294 | return; |
|
295 | 295 | |
|
296 | 296 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
297 | 297 | return; |
|
298 | 298 | |
|
299 | 299 | if (factor < 0) |
|
300 | 300 | return; |
|
301 | 301 | |
|
302 | 302 | if (factor > 1.0) |
|
303 | 303 | d_ptr->zoomIn(factor); |
|
304 | 304 | else |
|
305 | 305 | d_ptr->zoomOut(1.0 / factor); |
|
306 | 306 | } |
|
307 | 307 | |
|
308 | 308 | /*! |
|
309 | 309 | Returns the pointer to the x axis object of the chart asociated with the specified \a series |
|
310 | 310 | If no series is provided then pointer to currently visible axis is provided |
|
311 | 311 | */ |
|
312 | 312 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const |
|
313 | 313 | { |
|
314 | 314 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); |
|
315 | 315 | if (axisList.count()) |
|
316 | 316 | return axisList[0]; |
|
317 | 317 | return 0; |
|
318 | 318 | } |
|
319 | 319 | |
|
320 | 320 | /*! |
|
321 | 321 | Returns the pointer to the y axis object of the chart asociated with the specified \a series |
|
322 | 322 | If no series is provided then pointer to currently visible axis is provided |
|
323 | 323 | */ |
|
324 | 324 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const |
|
325 | 325 | { |
|
326 | 326 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); |
|
327 | 327 | if (axisList.count()) |
|
328 | 328 | return axisList[0]; |
|
329 | 329 | return 0; |
|
330 | 330 | } |
|
331 | 331 | |
|
332 | 332 | /*! |
|
333 | 333 | Returns the axes added for the \a series with \a orientation. If no series is provided, then all axes with the |
|
334 | 334 | specified orientation are returned. |
|
335 | 335 | \sa addAxis(), createDefaultAxes() |
|
336 | 336 | */ |
|
337 | 337 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const |
|
338 | 338 | { |
|
339 | 339 | QList<QAbstractAxis *> result ; |
|
340 | 340 | |
|
341 | 341 | if (series) { |
|
342 | 342 | foreach (QAbstractAxis *axis, series->attachedAxes()){ |
|
343 | 343 | if (orientation.testFlag(axis->orientation())) |
|
344 | 344 | result << axis; |
|
345 | 345 | } |
|
346 | 346 | } else { |
|
347 | 347 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ |
|
348 | 348 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) |
|
349 | 349 | result << axis; |
|
350 | 350 | } |
|
351 | 351 | } |
|
352 | 352 | |
|
353 | 353 | return result; |
|
354 | 354 | } |
|
355 | 355 | |
|
356 | 356 | /*! |
|
357 | 357 | NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL. |
|
358 | 358 | |
|
359 | 359 | Creates the axes for the chart based on the series that has already been added to the chart. |
|
360 | 360 | |
|
361 | 361 | \table |
|
362 | 362 | \header |
|
363 | 363 | \o Series type |
|
364 | 364 | \o X-axis |
|
365 | 365 | \o Y-axis |
|
366 | 366 | \row |
|
367 | 367 | \o QXYSeries |
|
368 | 368 | \o QValueAxis |
|
369 | 369 | \o QValueAxis |
|
370 | 370 | \row |
|
371 | 371 | \o QBarSeries |
|
372 | 372 | \o QBarCategoryAxis |
|
373 | 373 | \o QValueAxis |
|
374 | 374 | \row |
|
375 | 375 | \o QPieSeries |
|
376 | 376 | \o None |
|
377 | 377 | \o None |
|
378 | 378 | \endtable |
|
379 | 379 | |
|
380 | 380 | If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created. |
|
381 | 381 | If there are sevaral series added of different types then each series gets its own axes pair. |
|
382 | 382 | |
|
383 | 383 | NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown. |
|
384 | 384 | |
|
385 | 385 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. |
|
386 | 386 | QPieSeries does not create any axes. |
|
387 | 387 | |
|
388 | 388 | \sa axisX(), axisY(), setAxisX(), setAxisY() |
|
389 | 389 | */ |
|
390 | 390 | void QChart::createDefaultAxes() |
|
391 | 391 | { |
|
392 | 392 | d_ptr->m_dataset->createDefaultAxes(); |
|
393 | 393 | } |
|
394 | 394 | |
|
395 | 395 | /*! |
|
396 | 396 | Returns the legend object of the chart. Ownership stays in chart. |
|
397 | 397 | */ |
|
398 | 398 | QLegend *QChart::legend() const |
|
399 | 399 | { |
|
400 | 400 | return d_ptr->m_legend; |
|
401 | 401 | } |
|
402 | 402 | |
|
403 | 403 | /*! |
|
404 | 404 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
405 | 405 | Deprecated. Use setMargins(). |
|
406 | 406 | */ |
|
407 | 407 | void QChart::setMinimumMargins(const QMargins &margins) |
|
408 | 408 | { |
|
409 | 409 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; |
|
410 | 410 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
411 | 411 | } |
|
412 | 412 | |
|
413 | 413 | /*! |
|
414 | 414 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
415 | 415 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
416 | 416 | Deprecated. Use margins(). |
|
417 | 417 | */ |
|
418 | 418 | QMargins QChart::minimumMargins() const |
|
419 | 419 | { |
|
420 | 420 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; |
|
421 | 421 | return d_ptr->m_presenter->layout()->margins(); |
|
422 | 422 | } |
|
423 | 423 | |
|
424 | 424 | /*! |
|
425 | 425 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
426 | 426 | */ |
|
427 | 427 | void QChart::setMargins(const QMargins &margins) |
|
428 | 428 | { |
|
429 | 429 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
430 | 430 | } |
|
431 | 431 | |
|
432 | 432 | /*! |
|
433 | 433 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
434 | 434 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
435 | 435 | */ |
|
436 | 436 | QMargins QChart::margins() const |
|
437 | 437 | { |
|
438 | 438 | return d_ptr->m_presenter->layout()->margins(); |
|
439 | 439 | } |
|
440 | 440 | |
|
441 | 441 | /*! |
|
442 | 442 | Returns the the rect within which the drawing of the chart is done. |
|
443 | 443 | It does not include the area defines by margins. |
|
444 | 444 | */ |
|
445 | 445 | QRectF QChart::plotArea() const |
|
446 | 446 | { |
|
447 | 447 | return d_ptr->m_presenter->geometry(); |
|
448 | 448 | } |
|
449 | 449 | |
|
450 | 450 | /*! |
|
451 | 451 | Sets animation \a options for the chart |
|
452 | 452 | */ |
|
453 | 453 | void QChart::setAnimationOptions(AnimationOptions options) |
|
454 | 454 | { |
|
455 | 455 | d_ptr->m_presenter->setAnimationOptions(options); |
|
456 | 456 | } |
|
457 | 457 | |
|
458 | 458 | QChart::AnimationOptions QChart::animationOptions() const |
|
459 | 459 | { |
|
460 | 460 | return d_ptr->m_presenter->animationOptions(); |
|
461 | 461 | } |
|
462 | 462 | |
|
463 | 463 | /*! |
|
464 | 464 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
465 | 465 | */ |
|
466 | 466 | void QChart::scroll(qreal dx, qreal dy) |
|
467 | 467 | { |
|
468 | 468 | d_ptr->scroll(dx,dy); |
|
469 | 469 | } |
|
470 | 470 | |
|
471 | 471 | void QChart::setBackgroundVisible(bool visible) |
|
472 | 472 | { |
|
473 | 473 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
474 | 474 | } |
|
475 | 475 | |
|
476 | 476 | bool QChart::isBackgroundVisible() const |
|
477 | 477 | { |
|
478 | 478 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
479 | 479 | } |
|
480 | 480 | |
|
481 | 481 | void QChart::setDropShadowEnabled(bool enabled) |
|
482 | 482 | { |
|
483 | 483 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
484 | 484 | } |
|
485 | 485 | |
|
486 | 486 | bool QChart::isDropShadowEnabled() const |
|
487 | 487 | { |
|
488 | 488 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
489 | 489 | } |
|
490 | 490 | |
|
491 | 491 | /*! |
|
492 | 492 | Returns all the series that are added to the chart. |
|
493 | 493 | |
|
494 | 494 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
495 | 495 | */ |
|
496 | 496 | QList<QAbstractSeries *> QChart::series() const |
|
497 | 497 | { |
|
498 | 498 | return d_ptr->m_dataset->series(); |
|
499 | 499 | } |
|
500 | 500 | |
|
501 | 501 | /*! |
|
502 | 502 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
503 | 503 | |
|
504 | 504 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() |
|
505 | 505 | */ |
|
506 | 506 | void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series) |
|
507 | 507 | { |
|
508 | 508 | QList<QAbstractAxis*> list = axes(Qt::Horizontal,series); |
|
509 | 509 | |
|
510 | 510 | foreach(QAbstractAxis* a, list){ |
|
511 | 511 | d_ptr->m_dataset->removeAxis(a); |
|
512 | 512 | delete a; |
|
513 | 513 | } |
|
514 | 514 | |
|
515 | 515 | if(!d_ptr->m_dataset->axes().contains(axis)) |
|
516 | 516 | d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom); |
|
517 | 517 | d_ptr->m_dataset->attachAxis(series,axis); |
|
518 | 518 | } |
|
519 | 519 | |
|
520 | 520 | /*! |
|
521 | 521 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
522 | 522 | |
|
523 | 523 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() |
|
524 | 524 | */ |
|
525 | 525 | void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series) |
|
526 | 526 | { |
|
527 | 527 | QList<QAbstractAxis*> list = axes(Qt::Vertical,series); |
|
528 | 528 | |
|
529 | 529 | foreach(QAbstractAxis* a, list) { |
|
530 | 530 | d_ptr->m_dataset->removeAxis(a); |
|
531 | 531 | delete a; |
|
532 | 532 | } |
|
533 | 533 | |
|
534 | 534 | if(!d_ptr->m_dataset->axes().contains(axis)) |
|
535 | 535 | d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft); |
|
536 | 536 | d_ptr->m_dataset->attachAxis(series,axis); |
|
537 | 537 | } |
|
538 | 538 | |
|
539 | 539 | /*! |
|
540 | 540 | Adds \a axis to the chart with \a alignment. The chart takes the ownership of the axis. |
|
541 | 541 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
542 | 542 | */ |
|
543 | 543 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) |
|
544 | 544 | { |
|
545 | 545 | d_ptr->m_dataset->addAxis(axis, alignment); |
|
546 | 546 | } |
|
547 | 547 | |
|
548 | 548 | /*! |
|
549 | 549 | Removes \a axis from the chart. The ownership is returned to the caller. |
|
550 | 550 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() |
|
551 | 551 | */ |
|
552 | 552 | void QChart::removeAxis(QAbstractAxis *axis) |
|
553 | 553 | { |
|
554 | 554 | d_ptr->m_dataset->removeAxis(axis); |
|
555 | 555 | } |
|
556 | 556 | |
|
557 | 557 | /*! |
|
558 | Returns the value in the \a series domain that coresponds to the charts widget point defines by \a position. | |
|
558 | Returns the value in the \a series domain that corresponds to the charts widget point defines by \a position. | |
|
559 | 559 | */ |
|
560 | 560 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
561 | 561 | { |
|
562 | 562 | return d_ptr->m_dataset->mapToValue(position, series); |
|
563 | 563 | } |
|
564 | 564 | |
|
565 | 565 | /*! |
|
566 | Returns the position on the charts widget that coresponds to the \a value in the \a series domain. | |
|
566 | Returns the position on the charts widget that corresponds to the \a value in the \a series domain. | |
|
567 | 567 | */ |
|
568 | 568 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
569 | 569 | { |
|
570 | 570 | return d_ptr->m_dataset->mapToPosition(value, series); |
|
571 | 571 | } |
|
572 | 572 | |
|
573 | 573 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
574 | 574 | |
|
575 | 575 | QChartPrivate::QChartPrivate(QChart *q): |
|
576 | 576 | q_ptr(q), |
|
577 | 577 | m_legend(0), |
|
578 | 578 | m_dataset(new ChartDataSet(q)), |
|
579 | 579 | m_presenter(new ChartPresenter(q)), |
|
580 | 580 | m_themeManager(new ChartThemeManager(q)) |
|
581 | 581 | { |
|
582 | 582 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
583 | 583 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
584 | 584 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
585 | 585 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
586 | 586 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
587 | 587 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
588 | 588 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
589 | 589 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
590 | 590 | } |
|
591 | 591 | |
|
592 | 592 | QChartPrivate::~QChartPrivate() |
|
593 | 593 | { |
|
594 | 594 | |
|
595 | 595 | } |
|
596 | 596 | |
|
597 | 597 | void QChartPrivate::zoomIn(qreal factor) |
|
598 | 598 | { |
|
599 | 599 | QRectF rect = m_presenter->geometry(); |
|
600 | 600 | rect.setWidth(rect.width() / factor); |
|
601 | 601 | rect.setHeight(rect.height() / factor); |
|
602 | 602 | rect.moveCenter(m_presenter->geometry().center()); |
|
603 | 603 | zoomIn(rect); |
|
604 | 604 | } |
|
605 | 605 | |
|
606 | 606 | void QChartPrivate::zoomIn(const QRectF &rect) |
|
607 | 607 | { |
|
608 | 608 | if (!rect.isValid()) |
|
609 | 609 | return; |
|
610 | 610 | |
|
611 | 611 | QRectF r = rect.normalized(); |
|
612 | 612 | const QRectF geometry = m_presenter->geometry(); |
|
613 | 613 | r.translate(-geometry.topLeft()); |
|
614 | 614 | |
|
615 | 615 | if (!r.isValid()) |
|
616 | 616 | return; |
|
617 | 617 | |
|
618 | 618 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
619 | 619 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); |
|
620 | 620 | m_dataset->zoomInDomain(r); |
|
621 | 621 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
622 | 622 | |
|
623 | 623 | } |
|
624 | 624 | |
|
625 | 625 | void QChartPrivate::zoomOut(qreal factor) |
|
626 | 626 | { |
|
627 | 627 | const QRectF geometry = m_presenter->geometry(); |
|
628 | 628 | |
|
629 | 629 | QRectF r; |
|
630 | 630 | r.setSize(geometry.size() / factor); |
|
631 | 631 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); |
|
632 | 632 | if (!r.isValid()) |
|
633 | 633 | return; |
|
634 | 634 | |
|
635 | 635 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
636 | 636 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); |
|
637 | 637 | m_dataset->zoomOutDomain(r); |
|
638 | 638 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
639 | 639 | } |
|
640 | 640 | |
|
641 | 641 | void QChartPrivate::scroll(qreal dx, qreal dy) |
|
642 | 642 | { |
|
643 | 643 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); |
|
644 | 644 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); |
|
645 | 645 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); |
|
646 | 646 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); |
|
647 | 647 | |
|
648 | 648 | m_dataset->scrollDomain(dx, dy); |
|
649 | 649 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
650 | 650 | } |
|
651 | 651 | |
|
652 | 652 | #include "moc_qchart.cpp" |
|
653 | 653 | |
|
654 | 654 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now