From 7618c8da3444f1f699843ab0a5c0d5aec785dcef 2012-08-29 07:28:11 From: Jani Honkonen Date: 2012-08-29 07:28:11 Subject: [PATCH] Update donutbreakdown example docs --- diff --git a/doc/src/examples-donutbreakdown.qdoc b/doc/src/examples-donutbreakdown.qdoc index 0d6e973..a1753c0 100644 --- a/doc/src/examples-donutbreakdown.qdoc +++ b/doc/src/examples-donutbreakdown.qdoc @@ -5,48 +5,31 @@ This example shows how to use create a donut breakdown chart using QPieSeries API. - Let's start by creating a QChartView instance and enabling the Antialiasing on it. Last line enables the animations of the chart. + Let's start by defining some data for the chart. - \snippet ../examples/donutbreakdown/widget.cpp 1 + \snippet ../examples/donutbreakdown/main.cpp 1 - PieSeries is used to present the general data. + Then we create a chart where we add the data. Note that this this is our own chart derived from QChart. - \snippet ../examples/donutbreakdown/widget.cpp 2 + \snippet ../examples/donutbreakdown/main.cpp 2 - Following block of code creates the slices for the mainData QPieSeries. - Then for every created slice a new series is created that stores the detailed data. - The details series is set to be a donut. Its size is adjusted so that it wraps around the mainData pie. - Next two signals from the mainData pie's slices are connected. This is used to keep the mainData slices agligned with their respective details series. + Our own chart works so that in the constructor we create a main series + which aggregates the data provided by the breakdown series. This is the piechart in the center. - \snippet ../examples/donutbreakdown/widget.cpp 3 + \snippet ../examples/donutbreakdown/donutbreakdownchart.cpp 1 - Set the labels of the mainData to enabled and their postion to Outside. - Then add the mainData and detailedData series to the chart. + When a breakdown series is added the data is used to create a slice in the main series and the + breakdown series itself is used to create a segment of a donut positioned so that it is aligned + with the corresponding slice in the main series. - \snippet ../examples/donutbreakdown/widget.cpp 4 + \snippet ../examples/donutbreakdown/donutbreakdownchart.cpp 2 - Finally the widget is placed in a layout used by the application. + Here's how the start and end angles for the donut segments are calculated. - \snippet ../examples/donutbreakdown/widget.cpp 5 + \snippet ../examples/donutbreakdown/donutbreakdownchart.cpp 3 - To show that the detailed data stays aligned with the main data every 2.5 sec. one of the slices is modified. - It should be noted that int this example the mainData slices should not be modified directly as the change - cannot be applied to the detailed slices without the extra knowledge on how the split looks like. + And now that we have our chart defined we can finally create a QChartView and show the chart. - \snippet ../examples/donutbreakdown/widget.cpp 6 - - When the mainData slice layout is changed the detailed data layout has to be modified accordingly. - This is achived by setting the start and end angle of the detailed series. - - \snippet ../examples/donutbreakdown/widget.cpp 7 - - Highlight slot selects a random slice for the modification. - The slice is set to exploded to notify the user that its going to be changed. - The actual data modification is delayed by 1 sec to give a user a chance to focus on the slice. - - Then the slice is modified. Respective mainData slice is modified as well to contain as the value the sum of the detailed series slices values. - Finally the slice exploded state is set to false. - - \snippet ../examples/donutbreakdown/widget.cpp 8 + \snippet ../examples/donutbreakdown/main.cpp 3 */ diff --git a/doc/src/examples.qdoc b/doc/src/examples.qdoc index d264026..1d4044c 100644 --- a/doc/src/examples.qdoc +++ b/doc/src/examples.qdoc @@ -28,8 +28,7 @@
  • Pie chart
  • Donut chart
  • Pie chart drilldown
  • -
  • Nested donuts chart
  • -
  • Donut chart drilldown
  • +
  • Donut breakdown chart
  • Presenter chart
  • Scatter chart
  • Scatter interactions
  • diff --git a/examples/donutbreakdown/donutbreakdownchart.cpp b/examples/donutbreakdown/donutbreakdownchart.cpp index 5c6325a..8300778 100644 --- a/examples/donutbreakdown/donutbreakdownchart.cpp +++ b/examples/donutbreakdown/donutbreakdownchart.cpp @@ -10,7 +10,7 @@ DonutBreakdownChart::DonutBreakdownChart(QGraphicsItem *parent, Qt::WindowFlags // create the series for main center pie mainSeries = new QPieSeries(); mainSeries->setPieSize(0.7); - addSeries(mainSeries); + QChart::addSeries(mainSeries); } //![1] @@ -38,13 +38,14 @@ void DonutBreakdownChart::addBreakdownSeries(QPieSeries *breakdownSeries, QColor } // add the series to the chart - addSeries(breakdownSeries); + QChart::addSeries(breakdownSeries); // recalculate breakdown donut segments recalculateAngles(); } //![2] +//![3] void DonutBreakdownChart::recalculateAngles() { qreal angle = 0; @@ -52,16 +53,18 @@ void DonutBreakdownChart::recalculateAngles() QPieSeries *s = find(slice->label()); if (s) { s->setPieStartAngle(angle); - angle += slice->percentage() * 360.0; + angle += slice->percentage() * 360.0; // full pie is 360.0 s->setPieEndAngle(angle); } } } +//![3] +//![4] QPieSeries *DonutBreakdownChart::find(QString seriesName) const { // find pieseries by name - foreach (QAbstractSeries *series, this->series()) { + foreach (QAbstractSeries *series, QChart::series()) { QPieSeries *s = qobject_cast(series); if (!s) continue; @@ -70,4 +73,4 @@ QPieSeries *DonutBreakdownChart::find(QString seriesName) const } return 0; } - +//![4] diff --git a/examples/donutbreakdown/main.cpp b/examples/donutbreakdown/main.cpp index 8f0bc26..beda28c 100644 --- a/examples/donutbreakdown/main.cpp +++ b/examples/donutbreakdown/main.cpp @@ -9,9 +9,9 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); + //![1] // Data from http://www.stat.fi/til/ekul/2010/ekul_2010_2011-12-13_tie_001_en.html - //![1] QPieSeries *series1 = new QPieSeries(); series1->setName("Fossil"); series1->append("Oil", 353295);