@@ -20,7 +20,7 void Bar::setPlotDomain(const PlotDomain& data) | |||||
20 | mPlotDomain = data; |
|
20 | mPlotDomain = data; | |
21 | } |
|
21 | } | |
22 |
|
22 | |||
23 |
void Bar::resize( |
|
23 | void Bar::resize( qreal w, qreal h ) | |
24 | { |
|
24 | { | |
25 | // qDebug() << "bar::resize" << w << h; |
|
25 | // qDebug() << "bar::resize" << w << h; | |
26 | mWidth = w; |
|
26 | mWidth = w; | |
@@ -46,7 +46,15 void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidg | |||||
46 | // TODO: accept brush instead of color |
|
46 | // TODO: accept brush instead of color | |
47 | QBrush brush(mColor); |
|
47 | QBrush brush(mColor); | |
48 | painter->setBrush(brush); |
|
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 :) |
|
49 | ||
|
50 | // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1. | |||
|
51 | int x0 = mXpos; | |||
|
52 | int x1 = (mXpos + mWidth); | |||
|
53 | int w = x1-x0; | |||
|
54 | int y0 = mYpos; | |||
|
55 | int y1 = (mYpos + mHeight); | |||
|
56 | int h = y1-y0; | |||
|
57 | painter->drawRect(x0, y0 ,w ,h); | |||
50 | } |
|
58 | } | |
51 |
|
59 | |||
52 | QRectF Bar::boundingRect() const |
|
60 | QRectF Bar::boundingRect() const |
@@ -13,12 +13,12 class Bar : public ChartItem | |||||
13 | public: |
|
13 | public: | |
14 | Bar(QGraphicsItem *parent=0); |
|
14 | Bar(QGraphicsItem *parent=0); | |
15 |
|
15 | |||
16 |
public: // from ChartItem |
|
16 | public: // from ChartItem | |
17 | void setSize(const QSize &size); |
|
17 | void setSize(const QSize &size); | |
18 | void setPlotDomain(const PlotDomain& data); |
|
18 | void setPlotDomain(const PlotDomain& data); | |
19 |
|
19 | |||
20 | // Layout Stuff |
|
20 | // Layout Stuff | |
21 |
void resize( |
|
21 | void resize( qreal w, qreal h ); // Size of bar. | |
22 | void setColor( QColor col ); // Color of bar |
|
22 | void setColor( QColor col ); // Color of bar | |
23 | void setPos(qreal x, qreal y); |
|
23 | void setPos(qreal x, qreal y); | |
24 |
|
24 | |||
@@ -30,8 +30,8 public: | |||||
30 |
|
30 | |||
31 | private: |
|
31 | private: | |
32 |
|
32 | |||
33 |
|
|
33 | qreal mHeight; | |
34 |
|
|
34 | qreal mWidth; | |
35 | qreal mXpos; |
|
35 | qreal mXpos; | |
36 | qreal mYpos; |
|
36 | qreal mYpos; | |
37 | QColor mColor; |
|
37 | QColor mColor; |
@@ -119,6 +119,7 void BarGroup::layoutChanged() | |||||
119 | int itemIndex(0); |
|
119 | int itemIndex(0); | |
120 | for (int column=0; column < columnCount; column++) { |
|
120 | for (int column=0; column < columnCount; column++) { | |
121 | qreal xPos = xStepPerSeries * column + ((tW + mBarDefaultWidth*rowCount)/(columnCount*2)); |
|
121 | qreal xPos = xStepPerSeries * column + ((tW + mBarDefaultWidth*rowCount)/(columnCount*2)); | |
|
122 | qreal yPos = mHeight; | |||
122 | for (int row = 0; row < rowCount; row++) { |
|
123 | for (int row = 0; row < rowCount; row++) { | |
123 | qreal barHeight = mSeries.valueAt(row, column) * scale; |
|
124 | qreal barHeight = mSeries.valueAt(row, column) * scale; | |
124 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
125 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); | |
@@ -126,7 +127,7 void BarGroup::layoutChanged() | |||||
126 | // TODO: width settable per bar? |
|
127 | // TODO: width settable per bar? | |
127 | bar->resize(mBarDefaultWidth, barHeight); |
|
128 | bar->resize(mBarDefaultWidth, barHeight); | |
128 | bar->setColor(mColors.at(row)); |
|
129 | bar->setColor(mColors.at(row)); | |
129 |
bar->setPos(xPos, |
|
130 | bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + series * mBarDefaultWidth, mHeight); | |
130 | itemIndex++; |
|
131 | itemIndex++; | |
131 | xPos += mBarDefaultWidth; |
|
132 | xPos += mBarDefaultWidth; | |
132 | } |
|
133 | } |
@@ -121,7 +121,7 void PercentBarGroup::layoutChanged() | |||||
121 | // TODO: width settable per bar? |
|
121 | // TODO: width settable per bar? | |
122 | bar->resize(mBarDefaultWidth, barHeight); |
|
122 | bar->resize(mBarDefaultWidth, barHeight); | |
123 | bar->setColor(mColors.at(row)); |
|
123 | bar->setColor(mColors.at(row)); | |
124 | bar->setPos(xPos, yPos); |
|
124 | bar->setPos(xPos, yPos-barHeight); | |
125 | itemIndex++; |
|
125 | itemIndex++; | |
126 | yPos -= barHeight; |
|
126 | yPos -= barHeight; | |
127 | } |
|
127 | } |
@@ -10,6 +10,7 StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *p | |||||
10 | ,mLayoutSet(false) |
|
10 | ,mLayoutSet(false) | |
11 | ,mLayoutDirty(true) |
|
11 | ,mLayoutDirty(true) | |
12 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready |
|
12 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready | |
|
13 | ,mTheme(0) | |||
13 | { |
|
14 | { | |
14 | dataChanged(); |
|
15 | dataChanged(); | |
15 | } |
|
16 | } | |
@@ -30,6 +31,11 void StackedBarGroup::setPlotDomain(const PlotDomain& data) | |||||
30 | // TODO: |
|
31 | // TODO: | |
31 | } |
|
32 | } | |
32 |
|
33 | |||
|
34 | void StackedBarGroup::themeChanged(ChartTheme *theme) | |||
|
35 | { | |||
|
36 | mTheme = theme; | |||
|
37 | } | |||
|
38 | ||||
33 | void StackedBarGroup::setBarWidth( int w ) |
|
39 | void StackedBarGroup::setBarWidth( int w ) | |
34 | { |
|
40 | { | |
35 | mBarDefaultWidth = w; |
|
41 | mBarDefaultWidth = w; | |
@@ -111,7 +117,7 void StackedBarGroup::layoutChanged() | |||||
111 | qreal tW = mWidth; |
|
117 | qreal tW = mWidth; | |
112 | qreal tC = count+1; |
|
118 | qreal tC = count+1; | |
113 | qreal xStep = (tW/tC); |
|
119 | qreal xStep = (tW/tC); | |
114 |
qreal xPos = ((tW/tC) |
|
120 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); | |
115 |
|
121 | |||
116 | for (int column = 0; column < mSeries.countColumns(); column++) { |
|
122 | for (int column = 0; column < mSeries.countColumns(); column++) { | |
117 | qreal yPos = h; |
|
123 | qreal yPos = h; | |
@@ -120,9 +126,11 void StackedBarGroup::layoutChanged() | |||||
120 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
126 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); | |
121 |
|
127 | |||
122 | // TODO: width settable per bar? |
|
128 | // TODO: width settable per bar? | |
|
129 | // TODO: how to get color for series(x) from theme? | |||
|
130 | // mTheme->themeForSeries(); | |||
123 | bar->resize(mBarDefaultWidth, barHeight); |
|
131 | bar->resize(mBarDefaultWidth, barHeight); | |
124 | bar->setColor(mColors.at(row)); |
|
132 | bar->setColor(mColors.at(row)); | |
125 | bar->setPos(xPos, yPos); |
|
133 | bar->setPos(xPos, yPos-barHeight); | |
126 | itemIndex++; |
|
134 | itemIndex++; | |
127 | yPos -= barHeight; |
|
135 | yPos -= barHeight; | |
128 | } |
|
136 | } |
@@ -1,6 +1,7 | |||||
1 | #ifndef STACKEDBARGROUP_H |
|
1 | #ifndef STACKEDBARGROUP_H | |
2 | #define STACKEDBARGROUP_H |
|
2 | #define STACKEDBARGROUP_H | |
3 |
|
3 | |||
|
4 | #include "charttheme_p.h" | |||
4 | #include "chartitem_p.h" |
|
5 | #include "chartitem_p.h" | |
5 | #include "bar.h" |
|
6 | #include "bar.h" | |
6 | #include "stackedbarchartseries.h" |
|
7 | #include "stackedbarchartseries.h" | |
@@ -9,7 +10,7 | |||||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
11 | |||
11 | // TODO: derive this from ChartObjectInterface, when setSize is back in ChartItem |
|
12 | // TODO: derive this from ChartObjectInterface, when setSize is back in ChartItem | |
12 | class StackedBarGroup : public ChartItem |
|
13 | class StackedBarGroup : public ChartItem, public ChartThemeObserver | |
13 | { |
|
14 | { | |
14 | public: |
|
15 | public: | |
15 | StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent = 0); |
|
16 | StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent = 0); | |
@@ -18,6 +19,9 public: // From ChartItem | |||||
18 | void setSize(const QSize &size); |
|
19 | void setSize(const QSize &size); | |
19 | void setPlotDomain(const PlotDomain& data); |
|
20 | void setPlotDomain(const PlotDomain& data); | |
20 |
|
21 | |||
|
22 | // From ChartThemeObserver | |||
|
23 | void themeChanged(ChartTheme *theme); | |||
|
24 | ||||
21 | public: // Layout "api" |
|
25 | public: // Layout "api" | |
22 | void setPos(qreal x, qreal y); |
|
26 | void setPos(qreal x, qreal y); | |
23 | void setBarWidth( int w ); // Default width for each bar |
|
27 | void setBarWidth( int w ); // Default width for each bar | |
@@ -50,6 +54,8 private: | |||||
50 |
|
54 | |||
51 | QList<QColor> mColors; // List of colors for series for now |
|
55 | QList<QColor> mColors; // List of colors for series for now | |
52 |
|
56 | |||
|
57 | ChartTheme* mTheme; | |||
|
58 | ||||
53 | }; |
|
59 | }; | |
54 |
|
60 | |||
55 | QTCOMMERCIALCHART_END_NAMESPACE |
|
61 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now