diff --git a/src/barchart/percentbargroup.cpp b/src/barchart/percentbargroup.cpp index 10017c5..72ec026 100644 --- a/src/barchart/percentbargroup.cpp +++ b/src/barchart/percentbargroup.cpp @@ -1,60 +1,53 @@ #include "percentbargroup.h" - -#include "stackedbargroup.h" #include "bar.h" #include QTCOMMERCIALCHART_BEGIN_NAMESPACE -StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent) : - ChartItem(parent) - ,mSeries(series) - ,mLayoutSet(false) - ,mLayoutDirty(true) - ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready +PercentBarGroup::PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent) : + ChartItem(parent) + ,mSeries(series) + ,mLayoutSet(false) + ,mLayoutDirty(true) + ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready { dataChanged(); } -void StackedBarGroup::setSize(const QSize& size) + +void PercentBarGroup::setSize(const QSize& size) { - qDebug() << "StackedBarGroup::setSize"; +// qDebug() << "PercentBarGroup::setSize"; mWidth = size.width(); mHeight = size.height(); layoutChanged(); mLayoutSet = true; } -void StackedBarGroup::setPlotDomain(const PlotDomain& data) +void PercentBarGroup::setPlotDomain(const PlotDomain& data) { - qDebug() << "StackedBarGroup::setPlotDomain"; + qDebug() << "PercentBarGroup::setPlotDomain"; // TODO: } -void StackedBarGroup::setTheme(ChartTheme *theme) -{ - qDebug() << "StackedBarGroup::setTheme"; - // TODO: -} - -void StackedBarGroup::setBarWidth( int w ) +void PercentBarGroup::setBarWidth( int w ) { mBarDefaultWidth = w; } -int StackedBarGroup::addColor( QColor color ) +int PercentBarGroup::addColor( QColor color ) { int colorIndex = mColors.count(); mColors.append(color); return colorIndex; } -void StackedBarGroup::resetColors() +void PercentBarGroup::resetColors() { mColors.clear(); } -void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +void PercentBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { if (!mLayoutSet) { qDebug() << "QBarChart::paint called without layout set. Aborting."; @@ -68,13 +61,13 @@ void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *o } } -QRectF StackedBarGroup::boundingRect() const +QRectF PercentBarGroup::boundingRect() const { return QRectF(0,0,mWidth,mHeight); } -void StackedBarGroup::dataChanged() +void PercentBarGroup::dataChanged() { qDebug() << "QBarChart::dataChanged mSeries"; @@ -98,7 +91,7 @@ void StackedBarGroup::dataChanged() mLayoutDirty = true; } -void StackedBarGroup::layoutChanged() +void PercentBarGroup::layoutChanged() { // Scale bars to new layout // Layout for bars: @@ -109,10 +102,6 @@ void StackedBarGroup::layoutChanged() // TODO: better way to auto-layout // Use reals for accurancy (we might get some compiler warnings... :) - qreal maxSum = mSeries.maxColumnSum(); - qreal h = mHeight; - qreal scale = (h / maxSum); - int count = mSeries.countColumns(); int itemIndex(0); qreal tW = mWidth; @@ -121,6 +110,9 @@ void StackedBarGroup::layoutChanged() qreal xPos = ((tW/tC) + mBarDefaultWidth / 2); for (int column = 0; column < mSeries.countColumns(); column++) { + qreal colSum = mSeries.columnSum(column); + qreal h = mHeight; + qreal scale = (h / colSum); qreal yPos = h; for (int row=0; row < mSeries.countRows(); row++) { qreal barHeight = mSeries.valueAt(row, column) * scale; diff --git a/src/barchart/stackedbargroup.cpp b/src/barchart/stackedbargroup.cpp index c6727bf..37d5835 100644 --- a/src/barchart/stackedbargroup.cpp +++ b/src/barchart/stackedbargroup.cpp @@ -1,58 +1,53 @@ -#include "percentbargroup.h" +#include "stackedbargroup.h" #include "bar.h" #include QTCOMMERCIALCHART_BEGIN_NAMESPACE -PercentBarGroup::PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent) : - ChartItem(parent) - ,mSeries(series) - ,mLayoutSet(false) - ,mLayoutDirty(true) - ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready +StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent) : + ChartItem(parent) + ,mSeries(series) + ,mLayoutSet(false) + ,mLayoutDirty(true) + ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready { dataChanged(); } -void PercentBarGroup::setSize(const QSize& size) + +void StackedBarGroup::setSize(const QSize& size) { - qDebug() << "PercentBarGroup::setSize"; +// qDebug() << "StackedBarGroup::setSize"; mWidth = size.width(); mHeight = size.height(); layoutChanged(); mLayoutSet = true; } -void PercentBarGroup::setPlotDomain(const PlotDomain& data) -{ - qDebug() << "PercentBarGroup::setPlotDomain"; - // TODO: -} - -void PercentBarGroup::setTheme(ChartTheme *theme) +void StackedBarGroup::setPlotDomain(const PlotDomain& data) { - qDebug() << "PercentBarGroup::setTheme"; + qDebug() << "StackedBarGroup::setPlotDomain"; // TODO: } -void PercentBarGroup::setBarWidth( int w ) +void StackedBarGroup::setBarWidth( int w ) { mBarDefaultWidth = w; } -int PercentBarGroup::addColor( QColor color ) +int StackedBarGroup::addColor( QColor color ) { int colorIndex = mColors.count(); mColors.append(color); return colorIndex; } -void PercentBarGroup::resetColors() +void StackedBarGroup::resetColors() { mColors.clear(); } -void PercentBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { if (!mLayoutSet) { qDebug() << "QBarChart::paint called without layout set. Aborting."; @@ -66,13 +61,13 @@ void PercentBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *o } } -QRectF PercentBarGroup::boundingRect() const +QRectF StackedBarGroup::boundingRect() const { return QRectF(0,0,mWidth,mHeight); } -void PercentBarGroup::dataChanged() +void StackedBarGroup::dataChanged() { qDebug() << "QBarChart::dataChanged mSeries"; @@ -96,7 +91,7 @@ void PercentBarGroup::dataChanged() mLayoutDirty = true; } -void PercentBarGroup::layoutChanged() +void StackedBarGroup::layoutChanged() { // Scale bars to new layout // Layout for bars: @@ -107,6 +102,10 @@ void PercentBarGroup::layoutChanged() // TODO: better way to auto-layout // Use reals for accurancy (we might get some compiler warnings... :) + qreal maxSum = mSeries.maxColumnSum(); + qreal h = mHeight; + qreal scale = (h / maxSum); + int count = mSeries.countColumns(); int itemIndex(0); qreal tW = mWidth; @@ -115,9 +114,6 @@ void PercentBarGroup::layoutChanged() qreal xPos = ((tW/tC) + mBarDefaultWidth / 2); for (int column = 0; column < mSeries.countColumns(); column++) { - qreal colSum = mSeries.columnSum(column); - qreal h = mHeight; - qreal scale = (h / colSum); qreal yPos = h; for (int row=0; row < mSeries.countRows(); row++) { qreal barHeight = mSeries.valueAt(row, column) * scale; diff --git a/src/qchart.cpp b/src/qchart.cpp index 2b6247e..57504c0 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -100,6 +100,14 @@ void QChart::addSeries(QChartSeries* series) m_chartObjectInterfaces << barGroup; childItems().append(barGroup); + + m_plotDataIndex = 0 ; + m_plotDomainList.resize(1); + + PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; + foreach(ChartItem* i ,m_chartItems) + i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); + break; } case QChartSeries::SeriesTypeStackedBar: { @@ -117,6 +125,13 @@ void QChart::addSeries(QChartSeries* series) m_chartObjectInterfaces << stackedBarGroup; childItems().append(stackedBarGroup); + m_plotDataIndex = 0 ; + m_plotDomainList.resize(1); + + PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; + foreach(ChartItem* i ,m_chartItems) + i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); + break; } case QChartSeries::SeriesTypePercentBar: { @@ -134,6 +149,13 @@ void QChart::addSeries(QChartSeries* series) m_chartObjectInterfaces << percentBarGroup; childItems().append(percentBarGroup); + m_plotDataIndex = 0 ; + m_plotDomainList.resize(1); + + PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; + foreach(ChartItem* i ,m_chartItems) + i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); + break; } case QChartSeries::SeriesTypeScatter: {