diff --git a/doc/src/examples-stackedbarchartdrilldown.qdoc b/doc/src/examples-stackedbarchartdrilldown.qdoc index 47bdee3..3c6a6d4 100644 --- a/doc/src/examples-stackedbarchartdrilldown.qdoc +++ b/doc/src/examples-stackedbarchartdrilldown.qdoc @@ -11,32 +11,35 @@ Mouse button clicked on a month, shows the harvest from that month: \image examples_stackedbarchartdrilldown2.png - Here we define a drilldown series, which adds mapping for categories to other drilldown series. - Purpose of drilldown series is to contain knowledge of the drilldown structure. The mapDrilldownSeries function maps the category to given series. We can ask the mapping for category with drilldownSeries(QString category) function. + First we define a drilldown series class, which adds categories to stacked bar series and mapping for categories to other drilldown series. + Purpose of drilldown series is to contain knowledge of the drilldown structure. The mapDrilldownSeries function maps the category to given series. We can ask the mapping for category with drilldownSeries(int category) function. - \snippet ../examples/stackedbarchartdrilldown/main.cpp 1 + \snippet ../examples/stackedbarchartdrilldown/drilldownseries.h 1 - To enable drilldown we create own view, which implements handler for right click. All QBarSeries derived classes send out rightClicked(QBarSet*, QString) signal when series is clicked with right mouse button. The parameters QBarSet and QString contain the pointer to clicked bar set and name of category, where click occurred. + Next we define our own drilldown chart, which implements handler for mouse click. All QBarSeries derived classes send out clicked(QBarSet*, int) signal when series is clicked with mouse. The parameter QBarSet contains pointer to clicked bar set and parameter int contains the index of clicked category. + + \snippet ../examples/stackedbarchartdrilldown/drilldownchart.h 1 - In our DrilldownChart we implement handler, which selects the drilldown chart with the category. + Now we have our drilldown classes and we can start using them. + First create the chart. + + \snippet ../examples/stackedbarchartdrilldown/main.cpp 1 + We define categories, from wich the drilldown series will be constructed. + \snippet ../examples/stackedbarchartdrilldown/main.cpp 2 - - Here we define data, which we use to construct the chart. - - \snippet ../examples/stackedbarchartdrilldown/main.cpp 3 - + 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 this 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 rightClicked signals from our series to the drilldownChart. + To make mapping work, we connect the clicked signals from our series to the drilldownChart. - \snippet ../examples/stackedbarchartdrilldown/main.cpp 4 + \snippet ../examples/stackedbarchartdrilldown/main.cpp 3 - When we have our drilldown structure ready, we can add the data to it. Here we generate random crop for each plant in each week. The monthly crop is calculated from weekly crops. To enable floating values, we connect the clicked signal to toggle the value of corresponding set. + When we have our drilldown structure ready, we can add the data to it. Here we generate random crop for each plant in each week. The monthly crop is calculated from weekly crops and is set as value to monthly series. - \snippet ../examples/stackedbarchartdrilldown/main.cpp 5 + \snippet ../examples/stackedbarchartdrilldown/main.cpp 4 Here we set the chart to show top level series initially. - \snippet ../examples/stackedbarchartdrilldown/main.cpp 6 + \snippet ../examples/stackedbarchartdrilldown/main.cpp 5 */ diff --git a/examples/stackedbarchartdrilldown/drilldownchart.h b/examples/stackedbarchartdrilldown/drilldownchart.h index 5ef34e3..7e68b5a 100644 --- a/examples/stackedbarchartdrilldown/drilldownchart.h +++ b/examples/stackedbarchartdrilldown/drilldownchart.h @@ -26,7 +26,7 @@ QTCOMMERCIALCHART_USE_NAMESPACE -//! [2] +//! [1] class DrilldownChart : public QChart { Q_OBJECT @@ -41,6 +41,6 @@ public Q_SLOTS: private: DrilldownBarSeries* m_currentSeries; }; -//! [2] +//! [1] #endif // DRILLDOWNCHART_H diff --git a/examples/stackedbarchartdrilldown/main.cpp b/examples/stackedbarchartdrilldown/main.cpp index ee81b9d..b116f8d 100644 --- a/examples/stackedbarchartdrilldown/main.cpp +++ b/examples/stackedbarchartdrilldown/main.cpp @@ -30,18 +30,16 @@ QTCOMMERCIALCHART_USE_NAMESPACE int main(int argc, char *argv[]) { -//! [1] QApplication a(argc, argv); QMainWindow window; -//! [1] -//! [2] +//! [1] DrilldownChart* drilldownChart = new DrilldownChart(); drilldownChart->setTheme(QChart::ChartThemeBlueIcy); drilldownChart->setAnimationOptions(QChart::SeriesAnimations); -//! [2] +//! [1] -//! [3] +//! [2] // Define categories QStringList months; months << "May" << "Jun" << "Jul" << "Aug" << "Sep"; @@ -49,9 +47,9 @@ int main(int argc, char *argv[]) weeks << "week 1" << "week 2" << "week 3" << "week 4"; QStringList plants; plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo"; -//! [3] +//! [2] -//! [4] +//! [3] // Create drilldown structure DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart); seasonSeries->setName("Crop by month - Season"); @@ -75,9 +73,9 @@ int main(int argc, char *argv[]) // Enable drilldown from season series using right click. QObject::connect(seasonSeries, SIGNAL(clicked(QBarSet*,int)), drilldownChart, SLOT(handleClicked(QBarSet*,int))); -//! [4] +//! [3] -//! [5] +//! [4] // Fill monthly and weekly series with data foreach (QString plant, plants) { QBarSet* monthlyCrop = new QBarSet(plant); @@ -92,20 +90,20 @@ int main(int argc, char *argv[]) } seasonSeries->append(monthlyCrop); } -//! [5] +//! [4] -//! [6] +//! [5] // Show season series in initial view drilldownChart->changeSeries(seasonSeries); drilldownChart->setTitle(seasonSeries->name()); -//! [6] +//! [5] -//! [7] +//! [6] drilldownChart->axisX()->setGridLineVisible(false); drilldownChart->axisY()->setNiceNumbersEnabled(true); drilldownChart->legend()->setVisible(true); drilldownChart->legend()->setAlignment(Qt::AlignBottom); -//! [7] +//! [6] QChartView *chartView = new QChartView(drilldownChart); window.setCentralWidget(chartView);