@@ -11,7 +11,6 Bar::Bar(ChartItem *parent) | |||
|
11 | 11 | |
|
12 | 12 | void Bar::setSize(const QSize& size) |
|
13 | 13 | { |
|
14 | //mSize = size; | |
|
15 | 14 | mWidth = size.width(); |
|
16 | 15 | mHeight = size.height(); |
|
17 | 16 | } |
@@ -23,7 +22,7 void Bar::setPlotDomain(const PlotDomain& data) | |||
|
23 | 22 | |
|
24 | 23 | void Bar::resize( int w, int h ) |
|
25 | 24 | { |
|
26 | qDebug() << "bar::resize" << w << h; | |
|
25 | // qDebug() << "bar::resize" << w << h; | |
|
27 | 26 | mWidth = w; |
|
28 | 27 | mHeight = h; |
|
29 | 28 | } |
@@ -34,7 +33,7 void Bar::setColor( QColor col ) | |||
|
34 | 33 | } |
|
35 | 34 | void Bar::setPos(qreal x, qreal y) |
|
36 | 35 | { |
|
37 |
|
|
|
36 | // qDebug() << "Bar::setpos" << x << y; | |
|
38 | 37 | mXpos = x; |
|
39 | 38 | mYpos = y; |
|
40 | 39 | } |
@@ -44,15 +43,10 void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidg | |||
|
44 | 43 | if (0 == mHeight) { |
|
45 | 44 | return; |
|
46 | 45 | } |
|
47 | // Set color for bar. TODO: gradients, textures etc | |
|
48 | QPen pen = painter->pen(); | |
|
49 | pen.setColor( mColor ); | |
|
50 | pen.setWidth( mWidth ); | |
|
51 | painter->setPen(pen); | |
|
52 | ||
|
53 | // Draw bar | |
|
54 | painter->drawLine(mXpos, mYpos, | |
|
55 | mXpos, mYpos - mHeight); | |
|
46 | // TODO: accept brush instead of color | |
|
47 | QBrush brush(mColor); | |
|
48 | painter->setBrush(brush); | |
|
49 | painter->drawRect(mXpos-mWidth, mYpos-mHeight ,mWidth ,mHeight); // Evil inverse rect, because we want bars to grow from bottom to top :) | |
|
56 | 50 | } |
|
57 | 51 | |
|
58 | 52 | QRectF Bar::boundingRect() const |
@@ -1,4 +1,5 | |||
|
1 | 1 | #include <limits.h> |
|
2 | #include <QDebug> | |
|
2 | 3 | #include "stackedbarchartseries.h" |
|
3 | 4 | |
|
4 | 5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -60,12 +61,13 int StackedBarChartSeries::maxColumnSum() | |||
|
60 | 61 | |
|
61 | 62 | int max = INT_MIN; |
|
62 | 63 | |
|
63 |
for (int col=0; col <mModel-> |
|
|
64 | for (int col=0; col <mModel->columnCount(); col++) { | |
|
64 | 65 | int sum = columnSum(col); |
|
65 | 66 | if (sum > max) { |
|
66 | 67 | max = sum; |
|
67 | 68 | } |
|
68 | 69 | } |
|
70 | qDebug() << "maxColumnSum" << max; | |
|
69 | 71 | return max; |
|
70 | 72 | } |
|
71 | 73 | |
@@ -98,6 +100,7 int StackedBarChartSeries::columnSum(int column) | |||
|
98 | 100 | for (int row = 0; row < count; row++) { |
|
99 | 101 | sum += mModel->data(mModel->index(row,column)).toInt(); |
|
100 | 102 | } |
|
103 | qDebug() << "sum for column" << column << "=" << sum; | |
|
101 | 104 | return sum; |
|
102 | 105 | } |
|
103 | 106 |
@@ -9,7 +9,7 StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *p | |||
|
9 | 9 | ,mSeries(series) |
|
10 | 10 | ,mLayoutSet(false) |
|
11 | 11 | ,mLayoutDirty(true) |
|
12 |
,mBarDefaultWidth( |
|
|
12 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready | |
|
13 | 13 | { |
|
14 | 14 | dataChanged(); |
|
15 | 15 | } |
@@ -110,11 +110,10 void StackedBarGroup::layoutChanged() | |||
|
110 | 110 | int posStepX = (mWidth / (count+1)); |
|
111 | 111 | |
|
112 | 112 | int itemIndex(0); |
|
113 |
int xPos = (mWidth / (count+1)) - mSeries.count |
|
|
113 | int xPos = (mWidth / (count+1)) - mSeries.countRows() * mBarDefaultWidth /2; | |
|
114 | 114 | for (int column = 0; column < mSeries.countColumns(); column++) { |
|
115 | 115 | int yPos = mHeight; |
|
116 | 116 | for (int row=0; row < mSeries.countRows(); row++) { |
|
117 | qDebug() << itemIndex; | |
|
118 | 117 | int barHeight = mSeries.valueAt(row, column) * scale; |
|
119 | 118 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
120 | 119 | |
@@ -122,8 +121,9 void StackedBarGroup::layoutChanged() | |||
|
122 | 121 | bar->resize(mBarDefaultWidth, barHeight); |
|
123 | 122 | bar->setColor(mColors.at(row)); |
|
124 | 123 | bar->setPos(xPos, yPos); |
|
124 | qDebug() << itemIndex << "pos" << xPos << yPos; | |
|
125 | 125 | itemIndex++; |
|
126 |
yPos |
|
|
126 | yPos -= barHeight; | |
|
127 | 127 | } |
|
128 | 128 | xPos += posStepX; |
|
129 | 129 | } |
General Comments 0
You need to be logged in to leave comments.
Login now