From e1c298a209aaddf293e7f8c909992777353f7aab 2012-02-29 14:19:25 From: Jani Honkonen Date: 2012-02-29 14:19:25 Subject: [PATCH] Refactor piechartdrilldown example a bit --- diff --git a/example/piechartdrilldown/main.cpp b/example/piechartdrilldown/main.cpp index e91cafa..7a2fcb4 100644 --- a/example/piechartdrilldown/main.cpp +++ b/example/piechartdrilldown/main.cpp @@ -29,7 +29,7 @@ public Q_SLOTS: void updateLabel() { QString label = m_prefix; - label += " - " + QString::number(this->value())+ "e ("; + label += " " + QString::number(this->value())+ "e ("; label += QString::number(this->percentage()*100, 'f', 1) + "%)"; setLabel(label); } @@ -83,34 +83,22 @@ int main(int argc, char *argv[]) QList months; months << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; + QList names; + names << "Jane" << "John" << "Axel" << "Mary" << "Samantha" << "Bob"; + + foreach (QString name, names) { + QPieSeries* series = new QPieSeries(drilldownChart); + series->setTitle("Sales by month - " + name); + series->setHoverHighlighting(); + + foreach (QString month, months) + *series << new DrilldownSlice(qrand() % 1000, month, yearSeries); + + QObject::connect(series, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*))); + + *yearSeries << new DrilldownSlice(series->total(), name, series); + } - int max = 1000; - - QPieSeries* monthSeriesJane = new QPieSeries(drilldownChart); - monthSeriesJane->setTitle("Sales by month - Jane"); - monthSeriesJane->setHoverHighlighting(); - foreach (QString month, months) - *monthSeriesJane << new DrilldownSlice(qrand() % max, month, yearSeries); - - QPieSeries* monthSeriesJohn = new QPieSeries(drilldownChart); - monthSeriesJohn->setTitle("Sales by month - John"); - monthSeriesJohn->setHoverHighlighting(); - foreach (QString month, months) - *monthSeriesJohn << new DrilldownSlice(qrand() % max, month, yearSeries); - - QPieSeries* monthSeriesAxel = new QPieSeries(drilldownChart); - monthSeriesAxel->setTitle("Sales by month - Axel"); - monthSeriesAxel->setHoverHighlighting(); - foreach (QString month, months) - *monthSeriesAxel << new DrilldownSlice(qrand() % max, month, yearSeries); - - *yearSeries << new DrilldownSlice(monthSeriesJane->total(), "Jane", monthSeriesJane); - *yearSeries << new DrilldownSlice(monthSeriesJohn->total(), "John", monthSeriesJohn); - *yearSeries << new DrilldownSlice(monthSeriesAxel->total(), "Axel", monthSeriesAxel); - - QObject::connect(monthSeriesJane, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*))); - QObject::connect(monthSeriesJohn, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*))); - QObject::connect(monthSeriesAxel, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*))); QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*))); drilldownChart->changeSeries(yearSeries);