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