@@ -2,6 +2,7 | |||
|
2 | 2 | #include "bar_p.h" |
|
3 | 3 | #include "barlabel_p.h" |
|
4 | 4 | #include <QDebug> |
|
5 | #include <QPainter> | |
|
5 | 6 | |
|
6 | 7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | 8 | |
@@ -12,14 +13,18 StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *p | |||
|
12 | 13 | ,mLayoutDirty(true) |
|
13 | 14 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready |
|
14 | 15 | ,mTheme(0) |
|
16 | ,mSeparatorsVisible(true) | |
|
15 | 17 | { |
|
16 | 18 | dataChanged(); |
|
17 | 19 | } |
|
18 | 20 | |
|
21 | void StackedBarGroup::setSeparatorsVisible(bool visible) | |
|
22 | { | |
|
23 | mSeparatorsVisible = visible; | |
|
24 | } | |
|
19 | 25 | |
|
20 | 26 | void StackedBarGroup::setSize(const QSizeF& size) |
|
21 | 27 | { |
|
22 | // qDebug() << "StackedBarGroup::setSize"; | |
|
23 | 28 | mWidth = size.width(); |
|
24 | 29 | mHeight = size.height(); |
|
25 | 30 | layoutChanged(); |
@@ -65,8 +70,17 void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *o | |||
|
65 | 70 | foreach(QGraphicsItem* i, childItems()) { |
|
66 | 71 | i->paint(painter,option,widget); |
|
67 | 72 | } |
|
68 | mLayoutDirty = false; | |
|
69 | //TODO: draw labels. | |
|
73 | if (mSeparatorsVisible) { | |
|
74 | //TODO: own class for separators (graphicsitem), because they may have style etc later. | |
|
75 | // this is just to see that the positions are calculated correctly. | |
|
76 | QPen pen(QColor(0,0,255,255)); | |
|
77 | painter->setPen(pen); | |
|
78 | for (int i=0; i<mSeparatorPositions.count(); i++ ) { | |
|
79 | qreal xp = mSeparatorPositions.at(i); | |
|
80 | painter->drawLine(xp,0,xp,mHeight); | |
|
81 | } | |
|
82 | } | |
|
83 | // mLayoutDirty = false; | |
|
70 | 84 | } |
|
71 | 85 | |
|
72 | 86 | } |
@@ -79,7 +93,7 QRectF StackedBarGroup::boundingRect() const | |||
|
79 | 93 | |
|
80 | 94 | void StackedBarGroup::dataChanged() |
|
81 | 95 | { |
|
82 |
qDebug() << "QBarChart::dataChanged |
|
|
96 | qDebug() << "QBarChart::dataChanged"; | |
|
83 | 97 | |
|
84 | 98 | // Find out maximum and minimum of all series |
|
85 | 99 | mMax = mSeries.max(); |
@@ -107,6 +121,8 void StackedBarGroup::dataChanged() | |||
|
107 | 121 | childItems().append(label); |
|
108 | 122 | } |
|
109 | 123 | |
|
124 | mSeparatorPositions.clear(); | |
|
125 | ||
|
110 | 126 | // TODO: if (autolayout) { layoutChanged() } or something |
|
111 | 127 | mLayoutDirty = true; |
|
112 | 128 | } |
@@ -120,16 +136,21 void StackedBarGroup::layoutChanged() | |||
|
120 | 136 | return; |
|
121 | 137 | } |
|
122 | 138 | |
|
139 | if (mSeries.countColumns() == 0) { | |
|
140 | // Nothing to do | |
|
141 | return; | |
|
142 | } | |
|
143 | ||
|
123 | 144 | // TODO: better way to auto-layout |
|
124 | 145 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
146 | // TODO: use temp variable for column count... | |
|
125 | 147 | qreal maxSum = mSeries.maxColumnSum(); |
|
126 | 148 | qreal h = mHeight; |
|
127 | 149 | qreal scale = (h / maxSum); |
|
128 | 150 | |
|
129 | int count = mSeries.countColumns(); | |
|
130 | 151 | int itemIndex(0); |
|
131 | 152 | qreal tW = mWidth; |
|
132 | qreal tC = count+1; | |
|
153 | qreal tC = mSeries.countColumns() + 1; | |
|
133 | 154 | qreal xStep = (tW/tC); |
|
134 | 155 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); |
|
135 | 156 | int labelIndex = mSeries.countColumns() * mSeries.countRows(); |
@@ -157,6 +178,14 void StackedBarGroup::layoutChanged() | |||
|
157 | 178 | xPos += xStep; |
|
158 | 179 | } |
|
159 | 180 | |
|
181 | // Position separators | |
|
182 | mSeparatorPositions.clear(); | |
|
183 | xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left. | |
|
184 | for (int s=0; s < mSeries.countColumns() - 1; s++) { | |
|
185 | mSeparatorPositions.append(xPos); | |
|
186 | xPos += xStep; | |
|
187 | } | |
|
188 | ||
|
160 | 189 | mLayoutDirty = true; |
|
161 | 190 | } |
|
162 | 191 |
@@ -16,6 +16,9 class StackedBarGroup : public ChartItem, public ChartThemeObserver | |||
|
16 | 16 | public: |
|
17 | 17 | StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent = 0); |
|
18 | 18 | |
|
19 | // Bar chart spesific | |
|
20 | void setSeparatorsVisible(bool visible = true); | |
|
21 | ||
|
19 | 22 | public: // From ChartItem |
|
20 | 23 | void setSize(const QSizeF &size); |
|
21 | 24 | void setPlotDomain(const PlotDomain& data); |
@@ -56,7 +59,8 private: | |||
|
56 | 59 | QList<QColor> mColors; // List of colors for series for now |
|
57 | 60 | |
|
58 | 61 | ChartTheme* mTheme; |
|
59 | // QList<BarLabel*> mLabels; | |
|
62 | bool mSeparatorsVisible; | |
|
63 | QList<qreal> mSeparatorPositions; | |
|
60 | 64 | |
|
61 | 65 | }; |
|
62 | 66 |
@@ -99,6 +99,7 void QChart::addSeries(QChartSeries* series) | |||
|
99 | 99 | domain.m_minY = qMin(domain.m_minY,y); |
|
100 | 100 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
101 | 101 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
102 | m_axisXItem->setVisible(false); | |
|
102 | 103 | break; |
|
103 | 104 | } |
|
104 | 105 | case QChartSeries::SeriesTypeStackedBar: { |
@@ -123,6 +124,7 void QChart::addSeries(QChartSeries* series) | |||
|
123 | 124 | domain.m_minY = qMin(domain.m_minY,y); |
|
124 | 125 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
125 | 126 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
127 | m_axisXItem->setVisible(false); | |
|
126 | 128 | break; |
|
127 | 129 | } |
|
128 | 130 | case QChartSeries::SeriesTypePercentBar: { |
@@ -146,6 +148,7 void QChart::addSeries(QChartSeries* series) | |||
|
146 | 148 | domain.m_minY = 0; |
|
147 | 149 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
148 | 150 | domain.m_maxY = 100; |
|
151 | m_axisXItem->setVisible(false); | |
|
149 | 152 | break; |
|
150 | 153 | } |
|
151 | 154 | case QChartSeries::SeriesTypeScatter: { |
General Comments 0
You need to be logged in to leave comments.
Login now