##// END OF EJS Templates
Added a pie chart customization example and refactoring the pie interface.
Added a pie chart customization example and refactoring the pie interface.

File last commit:

r430:ec0910b997a4
r437:8d9e377a1065
Show More
main.cpp
129 lines | 3.5 KiB | text/x-c | CppLexer
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 #include <QtGui/QApplication>
sauimone
Better way to enable features to user. Do less, but expose signals to user and allow user to descide what to do.
r425 #include <QMainWindow>
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 #include <qchartglobal.h>
sauimone
Better way to enable features to user. Do less, but expose signals to user and allow user to descide what to do.
r425 #include <qchartview.h>
#include <qstackedbarseries.h>
#include <qbarset.h>
#include <qchartaxis.h>
#include <QStringList>
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 #include <QDebug>
sauimone
Better way to enable features to user. Do less, but expose signals to user and allow user to descide what to do.
r425
QTCOMMERCIALCHART_USE_NAMESPACE
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 //! [1]
class DrilldownBarSeries : public QStackedBarSeries
{
Q_OBJECT
public:
DrilldownBarSeries(QStringList categories, QObject* parent=0) : QStackedBarSeries(categories,parent) {}
/*
public Q_SLOTS:
void handleRightClick(QBarSet *barset, QString category)
{
}
*/
};
//! [1]
//! [2]
class DrilldownBarSet : public QBarSet
{
Q_OBJECT
public:
DrilldownBarSet(QString name, DrilldownBarSeries *parent) : QBarSet(name, parent), mSeries(parent) {}
DrilldownBarSeries* drilldownSeries() { return mSeries; }
private:
DrilldownBarSeries* mSeries;
};
//! [2]
//! [3]
class DrilldownChart : public QChartView
{
Q_OBJECT
public:
explicit DrilldownChart(QWidget *parent = 0) : QChartView(parent), m_currentSeries(0) {}
void changeSeries(QSeries* series)
{
if (m_currentSeries)
removeSeries(m_currentSeries);
m_currentSeries = series;
addSeries(series);
setChartTitle(series->title());
}
public Q_SLOTS:
void handleRightClick(QBarSet* barset, QString category)
{
qDebug() << "DrilldownChart::handleRightClick" << barset->name() << category;
// TODO: continue from here
// DrilldownBarSet* drilldownBarSet = static_cast<DrilldownBarSet*>(barset);
// changeSeries(drilldownBarSet->drilldownSeries());
}
private:
QSeries* m_currentSeries;
};
//! [3]
sauimone
Better way to enable features to user. Do less, but expose signals to user and allow user to descide what to do.
r425 int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow window;
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 DrilldownChart* drilldownChart = new DrilldownChart(&window);
drilldownChart->setChartTheme(QChart::ChartThemeIcy);
sauimone
Better way to enable features to user. Do less, but expose signals to user and allow user to descide what to do.
r425 //! [1]
// Define categories
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 QStringList months;
months << "Jun" << "Jul" << "Aug" << "Oct";
QStringList weeks;
weeks << "week 1" << "week 2" << "week 3" << "week 4";
QStringList plants;
plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo";
sauimone
Better way to enable features to user. Do less, but expose signals to user and allow user to descide what to do.
r425 //! [1]
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart);
seasonSeries->setTitle("Crop by month - Season");
foreach (QString plant, plants) {
DrilldownBarSet *seasonCrop = new DrilldownBarSet(plant, seasonSeries);
foreach(QString month, months) {
DrilldownBarSeries* monthSeries = new DrilldownBarSeries(weeks, drilldownChart);
DrilldownBarSet *monthCrop = new DrilldownBarSet(plant, monthSeries);
foreach(QString week, weeks) {
*monthCrop << (qrand() % 20);
}
monthSeries->addBarSet(monthCrop);
*seasonCrop << monthCrop->valueAt(plants.indexOf(plant));
}
// We want floating values!
QObject::connect(seasonCrop,SIGNAL(clicked(QString)),seasonCrop,SIGNAL(toggleFloatingValues()));
seasonSeries->addBarSet(seasonCrop);
}
QObject::connect(seasonSeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString)));
seasonSeries->setToolTipEnabled(true);
drilldownChart->addSeries(seasonSeries);
drilldownChart->axisX()->setAxisVisible(false);
drilldownChart->axisX()->setGridVisible(false);
drilldownChart->axisX()->setLabelsVisible(false);
window.setCentralWidget(drilldownChart);
sauimone
Better way to enable features to user. Do less, but expose signals to user and allow user to descide what to do.
r425 window.resize(400, 300);
window.show();
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430
sauimone
Better way to enable features to user. Do less, but expose signals to user and allow user to descide what to do.
r425 return a.exec();
}
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 #include "main.moc"