From e7f551f0831be06a0544b22eb81f5bf9bb1dd474 2012-01-27 14:41:40 From: sauimone Date: 2012-01-27 14:41:40 Subject: [PATCH] fixing layout bug on stacked bar chart --- diff --git a/src/barchart/stackedbarchartseries.cpp b/src/barchart/stackedbarchartseries.cpp index 020b3fa..405a4ba 100644 --- a/src/barchart/stackedbarchartseries.cpp +++ b/src/barchart/stackedbarchartseries.cpp @@ -67,7 +67,6 @@ int StackedBarChartSeries::maxColumnSum() max = sum; } } - qDebug() << "maxColumnSum" << max; return max; } @@ -100,7 +99,6 @@ 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 d2e855c..1aec87f 100644 --- a/src/barchart/stackedbargroup.cpp +++ b/src/barchart/stackedbargroup.cpp @@ -107,25 +107,26 @@ void StackedBarGroup::layoutChanged() qreal scale = (h / maxSum); int count = mSeries.countColumns(); - int posStepX = (mWidth / (count+1)); - int itemIndex(0); - int xPos = (mWidth / (count+1)) - mSeries.countRows() * mBarDefaultWidth /2; + qreal tW = mWidth; + qreal tC = count+1; + qreal xStep = (tW/tC); + qreal xPos = ((tW/tC) + mBarDefaultWidth / 2); + for (int column = 0; column < mSeries.countColumns(); column++) { - int yPos = mHeight; + qreal yPos = h; for (int row=0; row < mSeries.countRows(); row++) { - int barHeight = mSeries.valueAt(row, column) * scale; + qreal barHeight = mSeries.valueAt(row, column) * scale; Bar* bar = reinterpret_cast (childItems().at(itemIndex)); // TODO: width settable per bar? bar->resize(mBarDefaultWidth, barHeight); bar->setColor(mColors.at(row)); bar->setPos(xPos, yPos); - qDebug() << itemIndex << "pos" << xPos << yPos; itemIndex++; yPos -= barHeight; } - xPos += posStepX; + xPos += xStep; } mLayoutDirty = true; }