@@ -1,57 +1,57 | |||||
1 | /*! |
|
1 | /*! | |
2 | \example examples/modeldata |
|
2 | \example examples/modeldata | |
3 | \title Model data example |
|
3 | \title Model data example | |
4 | \subtitle |
|
4 | \subtitle | |
5 |
|
5 | |||
6 | This example shows how to use QAbstractItemModel derived model as the data for the series. |
|
6 | This example shows how to use QAbstractItemModel derived model as the data for the series. | |
7 |
|
7 | |||
8 | \image examples_modeldata.png |
|
8 | \image examples_modeldata.png | |
9 |
|
9 | |||
10 | Let's start by creating an instance of CustomTableModel class. |
|
10 | Let's start by creating an instance of CustomTableModel class. | |
11 | CustomTableModel class is derived from QAbstractTableModel and it was created for the purpose of this example. |
|
11 | CustomTableModel class is derived from QAbstractTableModel and it was created for the purpose of this example. | |
12 | The constructor of this class populates the internal data store of the model with the data that is good for our chart example. |
|
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 | \snippet ../examples/modeldata/tablewidget.cpp 1 |
|
14 | \snippet ../examples/modeldata/tablewidget.cpp 1 | |
15 |
|
15 | |||
16 | We now have a model with data that we would like to display both on the chart and in a QTableView. |
|
16 | We now have a model with data that we would like to display both on the chart and in a QTableView. | |
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. |
|
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 | \snippet ../examples/modeldata/tablewidget.cpp 2 |
|
19 | \snippet ../examples/modeldata/tablewidget.cpp 2 | |
20 |
|
20 | |||
21 | Now we need QChart instance to display the same data on the chart. |
|
21 | Now we need QChart instance to display the same data on the chart. | |
22 | We also enable animations. It makes it easier to see how modifying the model's data affect the chart. |
|
22 | We also enable animations. It makes it easier to see how modifying the model's data affect the chart. | |
23 |
|
23 | |||
24 | \snippet ../examples/modeldata/tablewidget.cpp 3 |
|
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 | 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. |
|
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 | To create a connection between the series and the model we set both of those objects to QVXYModelMapper. |
|
28 | To create a connection between the series and the model we set both of those objects to QVXYModelMapper. | |
29 |
|
29 | |||
30 | Finally the series is added to the chart. |
|
30 | Finally the series is added to the chart. | |
31 |
|
31 | |||
32 | \snippet ../examples/modeldata/tablewidget.cpp 4 |
|
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 coresponds with which series this example uses table coloring. | |
35 |
When series is added to the chart it is assigned a color b |
|
35 | When series is added to the chart it is assigned a color based on the currently selected theme. | |
36 | Code below extracts that color from the series and uses it to create colored QTableView. |
|
36 | Code below extracts that color from the series and uses it to create colored QTableView. | |
37 | Coloring of the view is not a part of the QChart functionality. |
|
37 | Coloring of the view is not a part of the QChart functionality. | |
38 |
|
38 | |||
39 | \snippet ../examples/modeldata/tablewidget.cpp 5 |
|
39 | \snippet ../examples/modeldata/tablewidget.cpp 5 | |
40 |
|
40 | |||
41 | The same operations are done with second series. Notice that for this series different columns of the same model are mapped. |
|
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 | \snippet ../examples/modeldata/tablewidget.cpp 6 |
|
43 | \snippet ../examples/modeldata/tablewidget.cpp 6 | |
44 |
|
44 | |||
45 | \snippet ../examples/modeldata/tablewidget.cpp 7 |
|
45 | \snippet ../examples/modeldata/tablewidget.cpp 7 | |
46 |
|
46 | |||
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. |
|
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 | To make the render look nicer Antialiasing is turned on and the minimum size of the chartView widget is set. |
|
48 | To make the render look nicer Antialiasing is turned on and the minimum size of the chartView widget is set. | |
49 |
|
49 | |||
50 | \snippet ../examples/modeldata/tablewidget.cpp 8 |
|
50 | \snippet ../examples/modeldata/tablewidget.cpp 8 | |
51 |
|
51 | |||
52 | Finally we place both widgets in a layout and use the layout as the application layout. |
|
52 | Finally we place both widgets in a layout and use the layout as the application layout. | |
53 |
|
53 | |||
54 | \snippet ../examples/modeldata/tablewidget.cpp 9 |
|
54 | \snippet ../examples/modeldata/tablewidget.cpp 9 | |
55 |
|
55 | |||
56 | Application is ready. Try modifying the data in the table view and see how it affects the chart. |
|
56 | Application is ready. Try modifying the data in the table view and see how it affects the chart. | |
57 | */ |
|
57 | */ |
General Comments 0
You need to be logged in to leave comments.
Login now