##// END OF EJS Templates
Adds tst_chart draft
Adds tst_chart draft

File last commit:

r891:3583c695b95e
r896:d007baef4c4a
Show More
main.cpp
173 lines | 5.3 KiB | text/x-c | CppLexer
Jani Honkonen
Add/modify license headers
r830 /****************************************************************************
**
** Copyright (C) 2012 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
** This file is part of the Qt Commercial Charts Add-on.
**
** $QT_BEGIN_LICENSE$
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.digia.com
** $QT_END_LICENSE$
**
****************************************************************************/
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>
Jani Honkonen
include headers without the .h in examples
r838 #include <QChartView>
#include <QStackedBarSeries>
#include <QBarSet>
sauimone
turned legend on in barchart examples
r891 #include <QLegend>
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:
Jani Honkonen
include headers without the .h in examples
r838 DrilldownBarSeries(QStringList categories, QObject *parent = 0)
:QStackedBarSeries(categories, parent)
{
}
sauimone
updating drilldown example. Needs some more thinking
r438
sauimone
Documentation for stacked barchart drilldown example
r462 void mapDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries)
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 {
sauimone
Drilldown example using stacked barchart.
r449 mDrilldownSeries[category] = drilldownSeries;
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 }
sauimone
updating drilldown example. Needs some more thinking
r438
DrilldownBarSeries* drilldownSeries(QString category)
sauimone
Drilldown example using stacked barchart.
r449 {
return mDrilldownSeries[category];
}
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 private:
sauimone
Drilldown example using stacked barchart.
r449 QMap<QString, DrilldownBarSeries*> mDrilldownSeries;
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 };
sauimone
Drilldown example using stacked barchart.
r449 //! [1]
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430
sauimone
Drilldown example using stacked barchart.
r449 //! [2]
Jani Honkonen
Make stackedbarchartdrilldown compile
r829 class DrilldownChart : public QChart
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 {
Q_OBJECT
public:
Jani Honkonen
include headers without the .h in examples
r838 explicit DrilldownChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0)
:QChart(parent, wFlags),
m_currentSeries(0)
{
}
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430
void changeSeries(QSeries* series)
{
if (m_currentSeries)
removeSeries(m_currentSeries);
m_currentSeries = series;
addSeries(series);
Jani Honkonen
Make stackedbarchartdrilldown compile
r829 setTitle(series->name());
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 }
public Q_SLOTS:
Jani Honkonen
Make stackedbarchartdrilldown compile
r829 void handleClicked(QBarSet *barset, QString category, Qt::MouseButtons button)
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 {
Tero Ahola
A few more warnings removed from examples
r613 Q_UNUSED(barset)
Jani Honkonen
include headers without the .h in examples
r838 Q_UNUSED(button)
sauimone
Drilldown example using stacked barchart.
r449 DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender());
changeSeries(series->drilldownSeries(category));
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 }
private:
QSeries* m_currentSeries;
};
sauimone
Drilldown example using stacked barchart.
r449 //! [2]
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 int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow window;
Jani Honkonen
Make stackedbarchartdrilldown compile
r829 DrilldownChart* drilldownChart = new DrilldownChart();
drilldownChart->setTheme(QChart::ChartThemeBlueIcy);
drilldownChart->setAnimationOptions(QChart::SeriesAnimations);
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430
sauimone
Drilldown example using stacked barchart.
r449 //! [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 // Define categories
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 QStringList months;
sauimone
Documentation for stacked barchart drilldown example
r462 months << "May" << "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
Drilldown example using stacked barchart.
r449 //! [3]
sauimone
updating drilldown example. Needs some more thinking
r438 //! [4]
sauimone
Drilldown example using stacked barchart.
r449 // Create drilldown structure
DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart);
Tero Ahola
Fixed build error caused by QSeries name change
r733 seasonSeries->setName("Crop by month - Season");
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
Drilldown example using stacked barchart.
r449 // Each month in season series has drilldown series for weekly data
foreach (QString month, months) {
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430
sauimone
Drilldown example using stacked barchart.
r449 // Create drilldown series for every week
sauimone
updating drilldown example. Needs some more thinking
r438 DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart);
sauimone
Documentation for stacked barchart drilldown example
r462 seasonSeries->mapDrilldownSeries(month, weeklySeries);
sauimone
updating drilldown example. Needs some more thinking
r438
sauimone
Drilldown example using stacked barchart.
r449 // Drilling down from weekly data brings us back to season data.
foreach (QString week, weeks) {
sauimone
Documentation for stacked barchart drilldown example
r462 weeklySeries->mapDrilldownSeries(week, seasonSeries);
Tero Ahola
Fixed build error caused by QSeries name change
r733 weeklySeries->setName(QString("Crop by week - " + month));
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 }
sauimone
Drilldown example using stacked barchart.
r449 // Use right click signal to implement drilldown
Jani Honkonen
Make stackedbarchartdrilldown compile
r829 QObject::connect(weeklySeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons)));
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430 }
sauimone
Documentation for stacked barchart drilldown example
r462
// Enable drilldown from season series using right click.
Jani Honkonen
Make stackedbarchartdrilldown compile
r829 QObject::connect(seasonSeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons)));
sauimone
Drilldown example using stacked barchart.
r449 //! [4]
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430
sauimone
Drilldown example using stacked barchart.
r449 //! [5]
// Fill monthly and weekly series with data
sauimone
updating drilldown example. Needs some more thinking
r438 foreach (QString plant, plants) {
sauimone
Drilldown example using stacked barchart.
r449 QBarSet* monthlyCrop = new QBarSet(plant);
foreach (QString month, months) {
QBarSet* weeklyCrop = new QBarSet(plant);
Jani Honkonen
Make stackedbarchartdrilldown compile
r829 foreach (QString week, weeks )
sauimone
updating drilldown example. Needs some more thinking
r438 *weeklyCrop << (qrand() % 20);
sauimone
Documentation for stacked barchart drilldown example
r462 // Get the drilldown series from season series and add crop to it.
Jani Honkonen
Make stackedbarchartdrilldown compile
r829 seasonSeries->drilldownSeries(month)->appendBarSet(weeklyCrop);
sauimone
Drilldown example using stacked barchart.
r449 seasonSeries->drilldownSeries(month)->setToolTipEnabled(true);
sauimone
updating drilldown example. Needs some more thinking
r438 *monthlyCrop << weeklyCrop->total();
}
Jani Honkonen
Make stackedbarchartdrilldown compile
r829 seasonSeries->appendBarSet(monthlyCrop);
sauimone
updating drilldown example. Needs some more thinking
r438 }
sauimone
Drilldown example using stacked barchart.
r449 //! [5]
seasonSeries->setToolTipEnabled(true);
sauimone
Documentation for stacked barchart drilldown example
r462 //! [6]
sauimone
Drilldown example using stacked barchart.
r449 // Show season series in initial view
drilldownChart->changeSeries(seasonSeries);
Jani Honkonen
Make stackedbarchartdrilldown compile
r829 drilldownChart->setTitle(seasonSeries->name());
sauimone
Documentation for stacked barchart drilldown example
r462 //! [6]
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430
Michal Klocek
Renames Grid to GridLine
r535 drilldownChart->axisX()->setGridLineVisible(false);
sauimone
turned legend on in barchart examples
r891 drilldownChart->legend()->setVisible(true);
drilldownChart->legend()->setAlignmnent(QLegend::AlignmentBottom);
sauimone
Drilldown example for barcharts continuing. Still some bugs
r430
Jani Honkonen
Make stackedbarchartdrilldown compile
r829 QChartView *chartView = new QChartView(drilldownChart);
window.setCentralWidget(chartView);
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"