/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Charts module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** 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 General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \example stackedbarchartdrilldown
    \title StackedBarChart Drilldown Example
    \ingroup qtcharts_examples

    \brief The example shows how to implement drilldown using a stacked barchart.

    In the drilldown example we create a stacked bar chart, which shows the harvest of various chili
    peppers during season. In season view the harvest is grouped by month. To drill down to weekly
    view, right-click the selected month. On weekly view, the harvest of the month clicked is shown
    by week.

    The season view looks like this:
    \image examples_stackedbarchartdrilldown1.png

    Clicking on a month shows that month's harvest:
    \image examples_stackedbarchartdrilldown2.png

    First we define a drilldown series class, which adds categories to the stacked bar series and mapping for categories to other drilldown series.
    The purpose of the drilldown series is to contain knowledge of the drilldown structure. The mapDrilldownSeries function maps the category to a given series. We can request the mapping for a category with the drilldownSeries(int category) function.

    \snippet stackedbarchartdrilldown/drilldownseries.h 1

    Next we define our own drilldown chart, which implements the handler for the mouse click. All QBarSeries derived classes send out the clicked(QBarSet*, int) signal when a series is clicked with the mouse. The parameter QBarSet contains the pointer to the clicked bar set and parameter int contains the index of the clicked category.

    \snippet stackedbarchartdrilldown/drilldownchart.h 1

    Now we have our drilldown classes and we can start using them.
    First create the chart.

    \snippet stackedbarchartdrilldown/main.cpp 1

    We define the categories from which the drilldown series will be constructed.

    \snippet stackedbarchartdrilldown/main.cpp 2

    To create the drilldown structure, we first create our top level series, which we call seasonSeries. For each month in seasonSeries we create a drilldown series called weeklySeries which contains more detailed data for that month.
    In weeklySeries, we use the drilldown handler to bring us back to seasonSeries. To do so we add mapping to the series. The seasonSeries is mapped to weeklySeries for each month. Every weeklySeries is mapped back to the seasonSeries.
    To make mapping work, we connect the clicked signals from our series to the drilldownChart.

    \snippet stackedbarchartdrilldown/main.cpp 3

    When we have our drilldown structure ready, we can add the data to it. Here we generate a random crop for each plant in each week. The monthly crop is calculated from weekly crops and is set as value to the monthly series.

    \snippet stackedbarchartdrilldown/main.cpp 4

    Here we set the chart to show the top level series initially.

    \snippet stackedbarchartdrilldown/main.cpp 5
*/
