##// END OF EJS Templates
Spit&polish public headers
Spit&polish public headers

File last commit:

r1618:fab18ef35094
r2046:eee7dbc18b27
Show More
examples-barmodelmapper.qdoc
57 lines | 3.1 KiB | text/plain | TextLexer
/ doc / src / examples-barmodelmapper.qdoc
Marek Rosa
Added documentation for BarModelMapper example
r1369 /*!
\example examples/barmodelmapper
\title BarModelMapper example
\subtitle
This example shows how to use QAbstractItemModel derived model as the data for the bar series.
Marek Rosa
BarModelMapper example updated
r1393 \image examples_barmodelmapper.png
Marek Rosa
Added documentation for BarModelMapper example
r1369 Let's start by creating an instance of CustomTableModel class.
CustomTableModel class is derived from QAbstractTableModel and it was created for the purpose of this example.
The constructor of this class populates the internal data store of the model with the data that is good for our chart example.
\snippet ../examples/barmodelmapper/tablewidget.cpp 1
We now have a model with data that we would like to display both on the chart and in a QTableView.
Marek Rosa
BarModelMapper example updated
r1393 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.
Marek Rosa
Added documentation for BarModelMapper example
r1369
\snippet ../examples/barmodelmapper/tablewidget.cpp 2
Now we need QChart instance to display the same data on the chart.
We also enable animations. It makes it easier to see how modifying the model's data affect the chart.
\snippet ../examples/barmodelmapper/tablewidget.cpp 3
sauimone
documentation update
r1618 First line of the code below creates new bar series. Variables firstRow and rowCount are used to define a custom model mapping.
Marek Rosa
Added documentation for BarModelMapper example
r1369 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.
Marek Rosa
Minor updates to barModelMapper example and its docs
r1406 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).
Marek Rosa
Added documentation for BarModelMapper example
r1369 To create a connection between the series and the model we set both of those objects to QVBarModelMapper.
Finally the series is added to the chart.
\snippet ../examples/barmodelmapper/tablewidget.cpp 4
Marek Rosa
Minor updates to barModelMapper example and its docs
r1406 To show in QTableView which data coresponds with which bar set this example uses table coloring.
Marek Rosa
Added documentation for BarModelMapper example
r1369 When series is added to the chart it is assigned a color beased on the currently selected theme.
Code below extracts that color from the series and uses it to create colored QTableView.
Coloring of the view is not a part of the QChart functionality.
\snippet ../examples/barmodelmapper/tablewidget.cpp 5
We would like to have categories placed on the chart's axis that describe what the data means.
Next snippet shows how to do that.
\snippet ../examples/barmodelmapper/tablewidget.cpp 6
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.
To make the render look nicer Antialiasing is turned on and the minimum size of the chartView widget is set.
\snippet ../examples/barmodelmapper/tablewidget.cpp 7
Finally we place both widgets in a layout and use the layout as the application layout.
\snippet ../examples/barmodelmapper/tablewidget.cpp 8
Application is ready. Try modifying the data in the table view and see how it affects the chart.
*/