From 9f20814aa978d65ac5e2a2f75bda26a4cba1e3eb 2012-01-27 13:19:43 From: sauimone Date: 2012-01-27 13:19:43 Subject: [PATCH] added example for stacked bar chart. --- diff --git a/example/example.pro b/example/example.pro index 1ce070d..67e438d 100644 --- a/example/example.pro +++ b/example/example.pro @@ -2,4 +2,5 @@ TEMPLATE = subdirs SUBDIRS += linechart \ zoomlinechart \ colorlinechart \ - barchart + barchart \ + stackedbarchart diff --git a/src/barchart/barchartseries.h b/src/barchart/barchartseries.h index 6ca8d7d..b43cbc3 100644 --- a/src/barchart/barchartseries.h +++ b/src/barchart/barchartseries.h @@ -2,7 +2,6 @@ #define BARCHARTSERIES_H #include -//#include #include #include "qchartseries.h" #include "qchartglobal.h" @@ -35,9 +34,6 @@ public: public Q_SLOTS: - // TODO: wrong place for this... series don't know anything about layout -// void chartSizeChanged(QRectF rect); - private: QAbstractItemModel* mModel; diff --git a/src/qchart.cpp b/src/qchart.cpp index d0f21ea..ddb081c 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -7,6 +7,8 @@ #include "qchartaxis.h" #include "barchartseries.h" #include "bargroup.h" +#include "stackedbarchartseries.h" +#include "stackedbargroup.h" #include "xylinechartitem_p.h" #include "plotdomain_p.h" @@ -96,6 +98,23 @@ void QChart::addSeries(QChartSeries* series) childItems().append(barGroup); break; } + case QChartSeries::SeriesTypeStackedBar: { + + qDebug() << "barSeries added"; + StackedBarChartSeries* stackedBarSeries = static_cast(series); + StackedBarGroup* stackedBarGroup = new StackedBarGroup(*stackedBarSeries,this); + + // Add some fugly colors for 5 fist series... + stackedBarGroup->addColor(QColor(255,0,0,128)); + stackedBarGroup->addColor(QColor(255,255,0,128)); + stackedBarGroup->addColor(QColor(0,255,0,128)); + stackedBarGroup->addColor(QColor(0,0,255,128)); + stackedBarGroup->addColor(QColor(255,128,0,128)); + + m_chartItems<(series); scatterSeries->d->setParentItem(this); @@ -141,6 +160,10 @@ QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) series = new BarChartSeries(this); break; } + case QChartSeries::SeriesTypeStackedBar: { + series = new StackedBarChartSeries(this); + break; + } case QChartSeries::SeriesTypeScatter: { series = new QScatterSeries(this); break; diff --git a/src/src.pro b/src/src.pro index 0345e1c..cb12945 100644 --- a/src/src.pro +++ b/src/src.pro @@ -15,6 +15,8 @@ SOURCES += \ barchart/barchartseries.cpp \ barchart/bargroup.cpp \ barchart/bar.cpp \ + barchart/stackedbarchartseries.cpp \ + barchart/stackedbargroup.cpp \ xylinechart/qxychartseries.cpp \ xylinechart/xylinechartitem.cpp \ plotdomain.cpp \ @@ -26,9 +28,7 @@ SOURCES += \ pieslice.cpp \ qchartview.cpp \ qchartseries.cpp \ - qchartaxis.cpp \ - barchart/stackedbarchartseries.cpp \ - barchart/stackedbargroup.cpp + qchartaxis.cpp PRIVATE_HEADERS += \ xylinechart/xylinechartitem_p.h \ @@ -48,12 +48,12 @@ PUBLIC_HEADERS += \ xylinechart/qxychartseries.h \ barchart/barchartseries.h \ barchart/bargroup.h \ + barchart/stackedbarchartseries.h \ + barchart/stackedbargroup.h \ qchartview.h \ qchartaxis.h -HEADERS += $$PUBLIC_HEADERS \ - barchart/stackedbarchartseries.h \ - barchart/stackedbargroup.h +HEADERS += $$PUBLIC_HEADERS HEADERS += $$PRIVATE_HEADERS INCLUDEPATH += xylinechart \