/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
     \example modeldata
     \title Model Data Example
     \ingroup qtcharts_examples

     \brief This example shows how to use the QAbstractItemModel derived model as the data for the
     series.

     \image examples_modeldata.png

    \include examples-run.qdocinc

    \section1 Using Model Data

     Let's start by creating an instance of the CustomTableModel class.
     The 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 suitable for our chart example.

     \snippet modeldata/tablewidget.cpp 1

     We now have a model with data that we would like to display both on the chart and in a QTableView.
     First, we create QTableView and tell it to use the model as a data source. To make the data cells fill the table view we also change headers resize mode.

     \snippet modeldata/tablewidget.cpp 2

     Now we need the 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 modeldata/tablewidget.cpp 3

     The code below creates new line series and gives it a name. The following line creates an instance of QVXYModelMapper class.
     The next two lines specify that X-coordinates are taken from the model's column(Qt::Vertical) with index 0. The Y-coordinates are taken from the model's column with index 1.
     To create a connection between the series and the model we set both of those objects to QVXYModelMapper.

     Finally, the series is added to the chart.

     \snippet modeldata/tablewidget.cpp 4

     To show in QTableView which data corresponds with which series this example uses table coloring.
     When a series is added to the chart it is assigned a color based on the currently selected theme.
     The code below extracts that color from the series and uses it to create a colored QTableView.
     The coloring of the view is not a part of the QChart functionality.

     \snippet modeldata/tablewidget.cpp 5

     The same operations are done with a second series. Notice that for this series different columns of the same model are mapped.

     \snippet modeldata/tablewidget.cpp 6

     \snippet modeldata/tablewidget.cpp 7

     To avoid setting up the QGraphicsScene we use the QChartView class that does it for us.
     QChart object pointer is used as a parameter of the QChartView constructor.
     To make the chart look nicer, Antialiasing is turned on and the minimum size of the chartView widget is set.

     \snippet modeldata/tablewidget.cpp 8

     Finally we place both widgets in a layout and use the layout as the application layout.

     \snippet modeldata/tablewidget.cpp 9

     The application is ready. Try modifying the data in the table view and see how it affects the chart.
*/
