##// END OF EJS Templates
updating drilldown example. Needs some more thinking
updating drilldown example. Needs some more thinking

File last commit:

r438:c46e1ae6bddd
r438:c46e1ae6bddd
Show More
main.cpp
160 lines | 5.1 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:
sauimone
updating drilldown example. Needs some more thinking
r438 DrilldownBarSeries(QStringList categories, QObject* parent = 0) : QStackedBarSeries(categories,parent) {}
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430
public Q_SLOTS:
void handleRightClick(QBarSet *barset, QString category)
{
sauimone
updating drilldown example. Needs some more thinking
r438 qDebug() << "DrilldownBarSeries::handleRightClick" << barset->name() << category;
// mChart->changeSeries(this);
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 }
sauimone
updating drilldown example. Needs some more thinking
r438
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 };
//! [1]
//! [2]
class DrilldownBarSet : public QBarSet
{
Q_OBJECT
public:
sauimone
updating drilldown example. Needs some more thinking
r438 DrilldownBarSet(QString name, DrilldownBarSeries* drilldownSeries) : QBarSet(name) , mSeries(drilldownSeries) {}
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430
sauimone
updating drilldown example. Needs some more thinking
r438 DrilldownBarSeries* drilldownSeries(QString category)
{
return mSeries;
}
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430
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:
sauimone
updating drilldown example. Needs some more thinking
r438 void handleRightClick(QBarSet *barset, QString category)
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 {
qDebug() << "DrilldownChart::handleRightClick" << barset->name() << category;
// TODO: continue from here
sauimone
updating drilldown example. Needs some more thinking
r438 DrilldownBarSet* drilldownBarSet = static_cast<DrilldownBarSet*>(barset);
changeSeries(drilldownBarSet->drilldownSeries(category));
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 }
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
updating drilldown example. Needs some more thinking
r438 //! [4]
sauimone
Better way to enable features to user. Do less, but expose signals to user and allow user to descide what to do.
r425 // Define categories
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 QStringList months;
sauimone
updating drilldown example. Needs some more thinking
r438 months << "Jun" << "Jul" << "Aug" << "Sep";
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 QStringList weeks;
weeks << "week 1" << "week 2" << "week 3" << "week 4";
QStringList plants;
plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo";
sauimone
updating drilldown example. Needs some more thinking
r438 //! [4]
sauimone
Better way to enable features to user. Do less, but expose signals to user and allow user to descide what to do.
r425
sauimone
updating drilldown example. Needs some more thinking
r438 DrilldownBarSeries* monthlySeries = new DrilldownBarSeries(months, drilldownChart);
monthlySeries->setTitle("Crop by month - Season");
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430
foreach (QString plant, plants) {
sauimone
updating drilldown example. Needs some more thinking
r438 DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart);
DrilldownBarSet* monthlyCrop = new DrilldownBarSet(plant,weeklySeries);
weeklySeries->setTitle("Crop by week - Month");
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 foreach(QString month, months) {
sauimone
updating drilldown example. Needs some more thinking
r438 DrilldownBarSet* weeklyCrop = new DrilldownBarSet(plant,monthlySeries);
foreach (QString week, weeks ) {
*weeklyCrop << (qrand() % 20);
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 }
sauimone
updating drilldown example. Needs some more thinking
r438
weeklySeries->addBarSet(weeklyCrop);
weeklySeries->setToolTipEnabled(true);
*monthlyCrop << weeklyCrop->total();
QObject::connect(weeklyCrop,SIGNAL(clicked(QString)),weeklyCrop,SIGNAL(toggleFloatingValues()));
QObject::connect(weeklySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString)));
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 }
sauimone
updating drilldown example. Needs some more thinking
r438 QObject::connect(monthlyCrop,SIGNAL(clicked(QString)),monthlyCrop,SIGNAL(toggleFloatingValues()));
monthlySeries->addBarSet(monthlyCrop);
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 }
sauimone
updating drilldown example. Needs some more thinking
r438 /*
foreach (QString plant, plants) {
DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart);
DrilldownBarSet* monthlyCrop = new DrilldownBarSet(plant,weeklySeries);
weeklySeries->setTitle("Crop by week - Month");
foreach(QString month, months) {
DrilldownBarSet* weeklyCrop = new DrilldownBarSet(plant,monthlySeries);
foreach (QString week, weeks ) {
*weeklyCrop << (qrand() % 20);
}
weeklySeries->addBarSet(weeklyCrop);
weeklySeries->setToolTipEnabled(true);
*monthlyCrop << weeklyCrop->total();
QObject::connect(weeklyCrop,SIGNAL(clicked(QString)),weeklyCrop,SIGNAL(toggleFloatingValues()));
QObject::connect(weeklySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString)));
}
QObject::connect(monthlyCrop,SIGNAL(clicked(QString)),monthlyCrop,SIGNAL(toggleFloatingValues()));
monthlySeries->addBarSet(monthlyCrop);
}
*/
QObject::connect(monthlySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString)));
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430
sauimone
updating drilldown example. Needs some more thinking
r438 monthlySeries->setToolTipEnabled(true);
drilldownChart->changeSeries(monthlySeries);
drilldownChart->setChartTitle(monthlySeries->title());
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430
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"