diff --git a/src/barchart/bar.cpp b/src/barchart/bar.cpp index fedf723..8121311 100644 --- a/src/barchart/bar.cpp +++ b/src/barchart/bar.cpp @@ -11,7 +11,6 @@ Bar::Bar(ChartItem *parent) void Bar::setSize(const QSize& size) { - //mSize = size; mWidth = size.width(); mHeight = size.height(); } @@ -23,7 +22,7 @@ void Bar::setPlotDomain(const PlotDomain& data) void Bar::resize( int w, int h ) { - qDebug() << "bar::resize" << w << h; +// qDebug() << "bar::resize" << w << h; mWidth = w; mHeight = h; } @@ -34,7 +33,7 @@ void Bar::setColor( QColor col ) } void Bar::setPos(qreal x, qreal y) { - qDebug() << "Bar::setpos" << x << y; + // qDebug() << "Bar::setpos" << x << y; mXpos = x; mYpos = y; } @@ -44,15 +43,10 @@ void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidg if (0 == mHeight) { return; } - // Set color for bar. TODO: gradients, textures etc - QPen pen = painter->pen(); - pen.setColor( mColor ); - pen.setWidth( mWidth ); - painter->setPen(pen); - - // Draw bar - painter->drawLine(mXpos, mYpos, - mXpos, mYpos - mHeight); + // TODO: accept brush instead of color + QBrush brush(mColor); + painter->setBrush(brush); + painter->drawRect(mXpos-mWidth, mYpos-mHeight ,mWidth ,mHeight); // Evil inverse rect, because we want bars to grow from bottom to top :) } QRectF Bar::boundingRect() const diff --git a/src/barchart/stackedbarchartseries.cpp b/src/barchart/stackedbarchartseries.cpp index 16c3526..020b3fa 100644 --- a/src/barchart/stackedbarchartseries.cpp +++ b/src/barchart/stackedbarchartseries.cpp @@ -1,4 +1,5 @@ #include +#include #include "stackedbarchartseries.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -60,12 +61,13 @@ int StackedBarChartSeries::maxColumnSum() int max = INT_MIN; - for (int col=0; col rowCount(); col++) { + for (int col=0; col columnCount(); col++) { int sum = columnSum(col); if (sum > max) { max = sum; } } + qDebug() << "maxColumnSum" << max; return max; } @@ -98,6 +100,7 @@ int StackedBarChartSeries::columnSum(int column) for (int row = 0; row < count; row++) { sum += mModel->data(mModel->index(row,column)).toInt(); } + qDebug() << "sum for column" << column << "=" << sum; return sum; } diff --git a/src/barchart/stackedbargroup.cpp b/src/barchart/stackedbargroup.cpp index bcf4048..d2e855c 100644 --- a/src/barchart/stackedbargroup.cpp +++ b/src/barchart/stackedbargroup.cpp @@ -9,7 +9,7 @@ StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *p ,mSeries(series) ,mLayoutSet(false) ,mLayoutDirty(true) - ,mBarDefaultWidth(10) // TODO: remove hard coding, when we have layout code ready + ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready { dataChanged(); } @@ -110,11 +110,10 @@ void StackedBarGroup::layoutChanged() int posStepX = (mWidth / (count+1)); int itemIndex(0); - int xPos = (mWidth / (count+1)) - mSeries.countColumns() * mBarDefaultWidth /2; + int xPos = (mWidth / (count+1)) - mSeries.countRows() * mBarDefaultWidth /2; for (int column = 0; column < mSeries.countColumns(); column++) { int yPos = mHeight; for (int row=0; row < mSeries.countRows(); row++) { - qDebug() << itemIndex; int barHeight = mSeries.valueAt(row, column) * scale; Bar* bar = reinterpret_cast (childItems().at(itemIndex)); @@ -122,8 +121,9 @@ void StackedBarGroup::layoutChanged() bar->resize(mBarDefaultWidth, barHeight); bar->setColor(mColors.at(row)); bar->setPos(xPos, yPos); + qDebug() << itemIndex << "pos" << xPos << yPos; itemIndex++; - yPos += barHeight; + yPos -= barHeight; } xPos += posStepX; }