@@ -2,6 +2,7 | |||||
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barlabel_p.h" |
|
3 | #include "barlabel_p.h" | |
4 | #include <QDebug> |
|
4 | #include <QDebug> | |
|
5 | #include <QPainter> | |||
5 |
|
6 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
8 | |||
@@ -12,14 +13,18 StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *p | |||||
12 | ,mLayoutDirty(true) |
|
13 | ,mLayoutDirty(true) | |
13 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready |
|
14 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready | |
14 | ,mTheme(0) |
|
15 | ,mTheme(0) | |
|
16 | ,mSeparatorsVisible(true) | |||
15 | { |
|
17 | { | |
16 | dataChanged(); |
|
18 | dataChanged(); | |
17 | } |
|
19 | } | |
18 |
|
20 | |||
|
21 | void StackedBarGroup::setSeparatorsVisible(bool visible) | |||
|
22 | { | |||
|
23 | mSeparatorsVisible = visible; | |||
|
24 | } | |||
19 |
|
25 | |||
20 | void StackedBarGroup::setSize(const QSizeF& size) |
|
26 | void StackedBarGroup::setSize(const QSizeF& size) | |
21 | { |
|
27 | { | |
22 | // qDebug() << "StackedBarGroup::setSize"; |
|
|||
23 | mWidth = size.width(); |
|
28 | mWidth = size.width(); | |
24 | mHeight = size.height(); |
|
29 | mHeight = size.height(); | |
25 | layoutChanged(); |
|
30 | layoutChanged(); | |
@@ -65,8 +70,17 void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *o | |||||
65 | foreach(QGraphicsItem* i, childItems()) { |
|
70 | foreach(QGraphicsItem* i, childItems()) { | |
66 | i->paint(painter,option,widget); |
|
71 | i->paint(painter,option,widget); | |
67 | } |
|
72 | } | |
68 | mLayoutDirty = false; |
|
73 | if (mSeparatorsVisible) { | |
69 | //TODO: draw labels. |
|
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 | void StackedBarGroup::dataChanged() |
|
94 | void StackedBarGroup::dataChanged() | |
81 | { |
|
95 | { | |
82 |
qDebug() << "QBarChart::dataChanged |
|
96 | qDebug() << "QBarChart::dataChanged"; | |
83 |
|
97 | |||
84 | // Find out maximum and minimum of all series |
|
98 | // Find out maximum and minimum of all series | |
85 | mMax = mSeries.max(); |
|
99 | mMax = mSeries.max(); | |
@@ -107,6 +121,8 void StackedBarGroup::dataChanged() | |||||
107 | childItems().append(label); |
|
121 | childItems().append(label); | |
108 | } |
|
122 | } | |
109 |
|
123 | |||
|
124 | mSeparatorPositions.clear(); | |||
|
125 | ||||
110 | // TODO: if (autolayout) { layoutChanged() } or something |
|
126 | // TODO: if (autolayout) { layoutChanged() } or something | |
111 | mLayoutDirty = true; |
|
127 | mLayoutDirty = true; | |
112 | } |
|
128 | } | |
@@ -120,16 +136,21 void StackedBarGroup::layoutChanged() | |||||
120 | return; |
|
136 | return; | |
121 | } |
|
137 | } | |
122 |
|
138 | |||
|
139 | if (mSeries.countColumns() == 0) { | |||
|
140 | // Nothing to do | |||
|
141 | return; | |||
|
142 | } | |||
|
143 | ||||
123 | // TODO: better way to auto-layout |
|
144 | // TODO: better way to auto-layout | |
124 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
145 | // Use reals for accurancy (we might get some compiler warnings... :) | |
|
146 | // TODO: use temp variable for column count... | |||
125 | qreal maxSum = mSeries.maxColumnSum(); |
|
147 | qreal maxSum = mSeries.maxColumnSum(); | |
126 | qreal h = mHeight; |
|
148 | qreal h = mHeight; | |
127 | qreal scale = (h / maxSum); |
|
149 | qreal scale = (h / maxSum); | |
128 |
|
150 | |||
129 | int count = mSeries.countColumns(); |
|
|||
130 | int itemIndex(0); |
|
151 | int itemIndex(0); | |
131 | qreal tW = mWidth; |
|
152 | qreal tW = mWidth; | |
132 | qreal tC = count+1; |
|
153 | qreal tC = mSeries.countColumns() + 1; | |
133 | qreal xStep = (tW/tC); |
|
154 | qreal xStep = (tW/tC); | |
134 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); |
|
155 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); | |
135 | int labelIndex = mSeries.countColumns() * mSeries.countRows(); |
|
156 | int labelIndex = mSeries.countColumns() * mSeries.countRows(); | |
@@ -157,6 +178,14 void StackedBarGroup::layoutChanged() | |||||
157 | xPos += xStep; |
|
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 | mLayoutDirty = true; |
|
189 | mLayoutDirty = true; | |
161 | } |
|
190 | } | |
162 |
|
191 |
@@ -16,6 +16,9 class StackedBarGroup : public ChartItem, public ChartThemeObserver | |||||
16 | public: |
|
16 | public: | |
17 | StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent = 0); |
|
17 | StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent = 0); | |
18 |
|
18 | |||
|
19 | // Bar chart spesific | |||
|
20 | void setSeparatorsVisible(bool visible = true); | |||
|
21 | ||||
19 | public: // From ChartItem |
|
22 | public: // From ChartItem | |
20 | void setSize(const QSizeF &size); |
|
23 | void setSize(const QSizeF &size); | |
21 | void setPlotDomain(const PlotDomain& data); |
|
24 | void setPlotDomain(const PlotDomain& data); | |
@@ -56,7 +59,8 private: | |||||
56 | QList<QColor> mColors; // List of colors for series for now |
|
59 | QList<QColor> mColors; // List of colors for series for now | |
57 |
|
60 | |||
58 | ChartTheme* mTheme; |
|
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 | domain.m_minY = qMin(domain.m_minY,y); |
|
99 | domain.m_minY = qMin(domain.m_minY,y); | |
100 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
100 | domain.m_maxX = qMax(domain.m_maxX,x); | |
101 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
101 | domain.m_maxY = qMax(domain.m_maxY,y); | |
|
102 | m_axisXItem->setVisible(false); | |||
102 | break; |
|
103 | break; | |
103 | } |
|
104 | } | |
104 | case QChartSeries::SeriesTypeStackedBar: { |
|
105 | case QChartSeries::SeriesTypeStackedBar: { | |
@@ -123,6 +124,7 void QChart::addSeries(QChartSeries* series) | |||||
123 | domain.m_minY = qMin(domain.m_minY,y); |
|
124 | domain.m_minY = qMin(domain.m_minY,y); | |
124 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
125 | domain.m_maxX = qMax(domain.m_maxX,x); | |
125 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
126 | domain.m_maxY = qMax(domain.m_maxY,y); | |
|
127 | m_axisXItem->setVisible(false); | |||
126 | break; |
|
128 | break; | |
127 | } |
|
129 | } | |
128 | case QChartSeries::SeriesTypePercentBar: { |
|
130 | case QChartSeries::SeriesTypePercentBar: { | |
@@ -146,6 +148,7 void QChart::addSeries(QChartSeries* series) | |||||
146 | domain.m_minY = 0; |
|
148 | domain.m_minY = 0; | |
147 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
149 | domain.m_maxX = qMax(domain.m_maxX,x); | |
148 | domain.m_maxY = 100; |
|
150 | domain.m_maxY = 100; | |
|
151 | m_axisXItem->setVisible(false); | |||
149 | break; |
|
152 | break; | |
150 | } |
|
153 | } | |
151 | case QChartSeries::SeriesTypeScatter: { |
|
154 | case QChartSeries::SeriesTypeScatter: { |
General Comments 0
You need to be logged in to leave comments.
Login now