@@ -69,7 +69,7 int main(int argc, char *argv[]) | |||||
69 | //! [5] |
|
69 | //! [5] | |
70 |
|
70 | |||
71 | //! [6] |
|
71 | //! [6] | |
72 | chartView->axisX()->setAxisVisible(false); |
|
72 | //chartView->axisX()->setAxisVisible(false); | |
73 | chartView->axisX()->setGridLineVisible(false); |
|
73 | chartView->axisX()->setGridLineVisible(false); | |
74 | chartView->axisX()->setLabelsVisible(false); |
|
74 | chartView->axisX()->setLabelsVisible(false); | |
75 | //! [6] |
|
75 | //! [6] |
@@ -103,15 +103,17 protected: | |||||
103 |
|
103 | |||
104 | QRectF boundingRect() const |
|
104 | QRectF boundingRect() const | |
105 | { |
|
105 | { | |
106 | return QGraphicsLineItem::boundingRect().adjusted(0,0,m_axis->axisType()!=Axis::X_AXIS?10:0,m_axis->axisType()!=Axis::Y_AXIS?10:0); |
|
106 | return shape().boundingRect(); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | QPainterPath shape() const |
|
109 | QPainterPath shape() const | |
110 | { |
|
110 | { | |
111 | QPainterPath path; |
|
111 | QPainterPath path = QGraphicsLineItem::shape(); | |
112 |
path. |
|
112 | QRectF rect = path.boundingRect(); | |
|
113 | path.addRect(rect.adjusted(0,0,m_axis->axisType()!=Axis::X_AXIS?8:0,m_axis->axisType()!=Axis::Y_AXIS?8:0)); | |||
113 | return path; |
|
114 | return path; | |
114 | } |
|
115 | } | |
|
116 | ||||
115 | private: |
|
117 | private: | |
116 | Axis* m_axis; |
|
118 | Axis* m_axis; | |
117 |
|
119 |
@@ -6,75 +6,13 | |||||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | Bar::Bar(QString category, QGraphicsItem *parent) |
|
8 | Bar::Bar(QString category, QGraphicsItem *parent) | |
9 |
: QGraphics |
|
9 | : QGraphicsRectItem(parent), | |
10 | mXpos(0), |
|
|||
11 | mYpos(0), |
|
|||
12 | mWidth(0), |
|
|||
13 | mHeight(0), |
|
|||
14 | mBrush(QBrush()), |
|
|||
15 | mPen(QPen()), |
|
|||
16 | mCategory(category) |
|
10 | mCategory(category) | |
17 | { |
|
11 | { | |
18 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
12 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); | |
19 | setAcceptHoverEvents(true); |
|
13 | setAcceptHoverEvents(true); | |
20 | } |
|
14 | } | |
21 |
|
15 | |||
22 | void Bar::setSize(const QSizeF& size) |
|
|||
23 | { |
|
|||
24 | mWidth = size.width(); |
|
|||
25 | mHeight = size.height(); |
|
|||
26 | } |
|
|||
27 |
|
||||
28 |
|
||||
29 | void Bar::resize( qreal w, qreal h ) |
|
|||
30 | { |
|
|||
31 | mWidth = w; |
|
|||
32 | mHeight = h; |
|
|||
33 | } |
|
|||
34 |
|
||||
35 | void Bar::setPos(qreal x, qreal y) |
|
|||
36 | { |
|
|||
37 | mXpos = x; |
|
|||
38 | mYpos = y; |
|
|||
39 | } |
|
|||
40 |
|
||||
41 | void Bar::setPen(QPen pen) |
|
|||
42 | { |
|
|||
43 | mPen = pen; |
|
|||
44 | } |
|
|||
45 |
|
||||
46 | void Bar::setBrush(QBrush brush) |
|
|||
47 | { |
|
|||
48 | mBrush = brush; |
|
|||
49 | } |
|
|||
50 |
|
||||
51 | void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
|||
52 | { |
|
|||
53 | Q_UNUSED(option) |
|
|||
54 | Q_UNUSED(widget) |
|
|||
55 |
|
||||
56 | if (0 == mHeight) { |
|
|||
57 | return; |
|
|||
58 | } |
|
|||
59 | painter->setPen(mPen); |
|
|||
60 | painter->setBrush(mBrush); |
|
|||
61 |
|
||||
62 | // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1. |
|
|||
63 | int x0 = mXpos; |
|
|||
64 | int x1 = (mXpos + mWidth); |
|
|||
65 | int w = x1-x0; |
|
|||
66 | int y0 = mYpos; |
|
|||
67 | int y1 = (mYpos + mHeight); |
|
|||
68 | int h = y1-y0; |
|
|||
69 | painter->drawRect(x0, y0 ,w ,h); |
|
|||
70 | } |
|
|||
71 |
|
||||
72 | QRectF Bar::boundingRect() const |
|
|||
73 | { |
|
|||
74 | QRectF r(mXpos, mYpos, mWidth, mHeight); |
|
|||
75 | return r; |
|
|||
76 | } |
|
|||
77 |
|
||||
78 | void Bar::mousePressEvent(QGraphicsSceneMouseEvent* event) |
|
16 | void Bar::mousePressEvent(QGraphicsSceneMouseEvent* event) | |
79 | { |
|
17 | { | |
80 | if (event->button() == Qt::LeftButton) { |
|
18 | if (event->button() == Qt::LeftButton) { |
@@ -2,32 +2,18 | |||||
2 | #define BAR_H |
|
2 | #define BAR_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 |
#include <QGraphics |
|
5 | #include <QGraphicsRectItem> | |
6 | #include <QPen> |
|
|||
7 | #include <QBrush> |
|
|||
8 |
|
6 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
8 | |||
11 | // Single visual bar item of chart |
|
9 | // Single visual bar item of chart | |
12 |
class Bar : public QGraphics |
|
10 | class Bar : public QObject, public QGraphicsRectItem | |
13 | { |
|
11 | { | |
14 | Q_OBJECT |
|
12 | Q_OBJECT | |
15 | public: |
|
13 | public: | |
16 | Bar(QString category, QGraphicsItem *parent=0); |
|
14 | Bar(QString category, QGraphicsItem *parent=0); | |
17 |
|
15 | |||
18 | public: // from ChartItem |
|
|||
19 | void setSize(const QSizeF &size); |
|
|||
20 |
|
||||
21 | // Layout Stuff |
|
|||
22 | void resize(qreal w, qreal h); |
|
|||
23 | void setPos(qreal x, qreal y); |
|
|||
24 | void setPen(QPen pen); |
|
|||
25 | void setBrush(QBrush brush); |
|
|||
26 |
|
||||
27 | public: |
|
16 | public: | |
28 | // From QGraphicsItem |
|
|||
29 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
|||
30 | QRectF boundingRect() const; |
|
|||
31 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
17 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
32 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); |
|
18 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); | |
33 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); |
|
19 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); | |
@@ -39,15 +25,6 Q_SIGNALS: | |||||
39 | void hoverLeaved(); |
|
25 | void hoverLeaved(); | |
40 |
|
26 | |||
41 | private: |
|
27 | private: | |
42 |
|
||||
43 | qreal mXpos; |
|
|||
44 | qreal mYpos; |
|
|||
45 | qreal mWidth; |
|
|||
46 | qreal mHeight; |
|
|||
47 |
|
||||
48 | QBrush mBrush; |
|
|||
49 | QPen mPen; |
|
|||
50 |
|
||||
51 | QString mCategory; |
|
28 | QString mCategory; | |
52 | }; |
|
29 | }; | |
53 |
|
30 |
@@ -8,6 +8,7 | |||||
8 | #include "qchartaxiscategories.h" |
|
8 | #include "qchartaxiscategories.h" | |
9 | #include "chartpresenter_p.h" |
|
9 | #include "chartpresenter_p.h" | |
10 | #include "chartanimator_p.h" |
|
10 | #include "chartanimator_p.h" | |
|
11 | #include "chartdataset_p.h" | |||
11 | #include <QDebug> |
|
12 | #include <QDebug> | |
12 | #include <QToolTip> |
|
13 | #include <QToolTip> | |
13 |
|
14 | |||
@@ -15,8 +16,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
15 |
|
16 | |||
16 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
17 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
17 | ChartItem(presenter), |
|
18 | ChartItem(presenter), | |
18 | mHeight(0), |
|
|||
19 | mWidth(0), |
|
|||
20 | mLayoutSet(false), |
|
19 | mLayoutSet(false), | |
21 | mSeries(series) |
|
20 | mSeries(series) | |
22 | { |
|
21 | { | |
@@ -47,7 +46,7 void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti | |||||
47 |
|
46 | |||
48 | QRectF BarChartItem::boundingRect() const |
|
47 | QRectF BarChartItem::boundingRect() const | |
49 | { |
|
48 | { | |
50 | return QRectF(0, 0, mWidth, mHeight); |
|
49 | return m_rect; | |
51 | } |
|
50 | } | |
52 |
|
51 | |||
53 | void BarChartItem::dataChanged() |
|
52 | void BarChartItem::dataChanged() | |
@@ -102,47 +101,46 void BarChartItem::layoutChanged() | |||||
102 | return; |
|
101 | return; | |
103 | } |
|
102 | } | |
104 |
|
103 | |||
105 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
|||
106 | int categoryCount = mSeries->categoryCount(); |
|
|||
107 | int setCount = mSeries->barsetCount(); |
|
|||
108 |
|
104 | |||
109 | qreal tW = mWidth; |
|
105 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
110 | qreal tH = mHeight; |
|
106 | qreal categoryCount = mSeries->categoryCount(); | |
111 |
qreal |
|
107 | qreal setCount = mSeries->barsetCount(); | |
|
108 | qreal max = mSeries->max(); | |||
112 |
|
109 | |||
113 | // Domain: |
|
110 | // Domain: | |
114 |
if (mDomainMaxY > |
|
111 | if (mDomainMaxY > max) { | |
115 |
|
|
112 | max = mDomainMaxY; | |
116 | } |
|
113 | } | |
117 |
|
114 | |||
118 | qreal scale = (tH/tM); |
|
115 | qreal width = geometry().width(); | |
119 | qreal tC = categoryCount + 1; |
|
116 | qreal height = geometry().height(); | |
120 |
qreal |
|
117 | qreal scale = (height/max); | |
121 |
|
|
118 | qreal categoryWidth = width/categoryCount; | |
|
119 | qreal barWidth = categoryWidth / (setCount+1); | |||
122 |
|
120 | |||
123 | int itemIndex(0); |
|
121 | int itemIndex(0); | |
124 | for (int category=0; category < categoryCount; category++) { |
|
122 | for (int category=0; category < categoryCount; category++) { | |
125 |
qreal xPos = categoryWidth * category + |
|
123 | qreal xPos = categoryWidth * category + barWidth/2; | |
126 |
qreal yPos = |
|
124 | qreal yPos = height; | |
127 | for (int set = 0; set < setCount; set++) { |
|
125 | for (int set = 0; set < setCount; set++) { | |
128 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
126 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
129 | Bar* bar = mBars.at(itemIndex); |
|
127 | Bar* bar = mBars.at(itemIndex); | |
130 |
|
128 | |||
131 | // TODO: width settable per bar? |
|
129 | // TODO: width settable per bar? | |
132 |
bar-> |
|
130 | bar->setRect(xPos, yPos-barHeight,barWidth, barHeight); | |
133 | bar->setPen(mSeries->barsetAt(set)->pen()); |
|
131 | bar->setPen(mSeries->barsetAt(set)->pen()); | |
134 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
132 | bar->setBrush(mSeries->barsetAt(set)->brush()); | |
135 | bar->setPos(xPos, yPos-barHeight); |
|
133 | ||
136 | itemIndex++; |
|
134 | itemIndex++; | |
137 |
xPos += |
|
135 | xPos += barWidth; | |
138 | } |
|
136 | } | |
139 | } |
|
137 | } | |
140 |
|
138 | |||
141 | // Position floating values |
|
139 | // Position floating values | |
142 | itemIndex = 0; |
|
140 | itemIndex = 0; | |
143 | for (int category=0; category < mSeries->categoryCount(); category++) { |
|
141 | for (int category=0; category < mSeries->categoryCount(); category++) { | |
144 |
qreal xPos = categoryWidth * category + categoryWidth/2 + |
|
142 | qreal xPos = categoryWidth * category + categoryWidth/2 + barWidth; | |
145 |
qreal yPos = |
|
143 | qreal yPos = height; | |
146 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
144 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
147 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
145 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
148 | BarValue* value = mFloatingValues.at(itemIndex); |
|
146 | BarValue* value = mFloatingValues.at(itemIndex); | |
@@ -159,7 +157,7 void BarChartItem::layoutChanged() | |||||
159 | } |
|
157 | } | |
160 |
|
158 | |||
161 | itemIndex++; |
|
159 | itemIndex++; | |
162 |
xPos += |
|
160 | xPos += barWidth; | |
163 | } |
|
161 | } | |
164 | } |
|
162 | } | |
165 | update(); |
|
163 | update(); | |
@@ -169,7 +167,7 BarLayout BarChartItem::calculateLayout() | |||||
169 | { |
|
167 | { | |
170 | BarLayout layout; |
|
168 | BarLayout layout; | |
171 | foreach(Bar* bar, mBars) { |
|
169 | foreach(Bar* bar, mBars) { | |
172 |
layout.insert(bar,bar->boundingRect() |
|
170 | layout.insert(bar,bar->boundingRect()); | |
173 | } |
|
171 | } | |
174 |
|
172 | |||
175 | return layout; |
|
173 | return layout; | |
@@ -177,8 +175,8 BarLayout BarChartItem::calculateLayout() | |||||
177 |
|
175 | |||
178 | void BarChartItem::applyLayout(const BarLayout &layout) |
|
176 | void BarChartItem::applyLayout(const BarLayout &layout) | |
179 | { |
|
177 | { | |
180 |
if ( |
|
178 | if (animator()) | |
181 |
|
|
179 | animator()->updateLayout(this, layout); | |
182 | else |
|
180 | else | |
183 | setLayout(layout); |
|
181 | setLayout(layout); | |
184 | } |
|
182 | } | |
@@ -186,7 +184,7 void BarChartItem::applyLayout(const BarLayout &layout) | |||||
186 | void BarChartItem::setLayout(const BarLayout &layout) |
|
184 | void BarChartItem::setLayout(const BarLayout &layout) | |
187 | { |
|
185 | { | |
188 | foreach (Bar *bar, layout.keys()) { |
|
186 | foreach (Bar *bar, layout.keys()) { | |
189 |
bar->set |
|
187 | bar->setRect(layout.value(bar)); | |
190 | } |
|
188 | } | |
191 | update(); |
|
189 | update(); | |
192 | } |
|
190 | } | |
@@ -198,23 +196,12 void BarChartItem::initAxisLabels() | |||||
198 | return; |
|
196 | return; | |
199 | } |
|
197 | } | |
200 |
|
198 | |||
201 | mChart->axisX()->setTicksCount(count+2); |
|
199 | Domain* domain = presenter()->dataSet()->domain(mSeries); | |
202 |
|
200 | |||
203 | qreal min = 0; |
|
201 | qreal min = 0; | |
204 | qreal max = count+1; |
|
202 | qreal max = count+1; | |
205 |
|
203 | |||
206 | mChart->axisX()->setMin(min); |
|
204 | domain->setRangeX(min,max,count+1); | |
207 | mChart->axisX()->setMax(max); |
|
|||
208 |
|
||||
209 | QChartAxisCategories* categories = mChart->axisX()->categories(); |
|
|||
210 | categories->clear(); |
|
|||
211 | for (int i=0; i<count; i++) { |
|
|||
212 | categories->insert(i+1,mSeries->categoryName(i)); |
|
|||
213 | } |
|
|||
214 |
|
||||
215 |
|
||||
216 |
|
||||
217 | mChart->axisX()->setLabelsVisible(true); |
|
|||
218 | } |
|
205 | } | |
219 |
|
206 | |||
220 | //handlers |
|
207 | //handlers | |
@@ -254,8 +241,7 void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal | |||||
254 |
|
241 | |||
255 | void BarChartItem::handleGeometryChanged(const QRectF& rect) |
|
242 | void BarChartItem::handleGeometryChanged(const QRectF& rect) | |
256 | { |
|
243 | { | |
257 | mWidth = rect.width(); |
|
244 | m_rect=rect; | |
258 | mHeight = rect.height(); |
|
|||
259 | layoutChanged(); |
|
245 | layoutChanged(); | |
260 | mLayoutSet = true; |
|
246 | mLayoutSet = true; | |
261 | setPos(rect.topLeft()); |
|
247 | setPos(rect.topLeft()); |
@@ -14,9 +14,9 class BarValue; | |||||
14 | class QChartAxisCategories; |
|
14 | class QChartAxisCategories; | |
15 | class QChart; |
|
15 | class QChart; | |
16 |
|
16 | |||
17 |
typedef QHash<Bar*, Q |
|
17 | typedef QHash<Bar*, QRectF> BarLayout; | |
18 |
|
18 | |||
19 |
class BarChartItem : public |
|
19 | class BarChartItem : public ChartItem | |
20 | { |
|
20 | { | |
21 | Q_OBJECT |
|
21 | Q_OBJECT | |
22 | public: |
|
22 | public: | |
@@ -41,6 +41,8 public: | |||||
41 | void applyLayout(const BarLayout &layout); |
|
41 | void applyLayout(const BarLayout &layout); | |
42 | void setLayout(const BarLayout &layout); |
|
42 | void setLayout(const BarLayout &layout); | |
43 |
|
43 | |||
|
44 | QRectF geometry() const { return m_rect;} | |||
|
45 | ||||
44 | protected: |
|
46 | protected: | |
45 | void initAxisLabels(); |
|
47 | void initAxisLabels(); | |
46 |
|
48 | |||
@@ -56,15 +58,12 public slots: | |||||
56 | protected: |
|
58 | protected: | |
57 |
|
59 | |||
58 | // TODO: consider these. |
|
60 | // TODO: consider these. | |
59 | int mHeight; // Layout spesific |
|
|||
60 | int mWidth; |
|
|||
61 | qreal mBarWidth; |
|
|||
62 |
|
||||
63 | qreal mDomainMinX; |
|
61 | qreal mDomainMinX; | |
64 | qreal mDomainMaxX; |
|
62 | qreal mDomainMaxX; | |
65 | qreal mDomainMinY; |
|
63 | qreal mDomainMinY; | |
66 | qreal mDomainMaxY; |
|
64 | qreal mDomainMaxY; | |
67 |
|
65 | |||
|
66 | QRectF m_rect; | |||
68 | bool mLayoutSet; // True, if component has been laid out. |
|
67 | bool mLayoutSet; // True, if component has been laid out. | |
69 |
|
68 | |||
70 | // Not owned. |
|
69 | // Not owned. |
@@ -27,28 +27,29 void PercentBarChartItem::layoutChanged() | |||||
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
29 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
30 | qreal tW = mWidth; |
|
30 | qreal width = geometry().width(); | |
31 | qreal tC = mSeries->categoryCount() + 1; |
|
31 | qreal height = geometry().height(); | |
32 | qreal cC = mSeries->categoryCount() * 2 + 1; |
|
32 | ||
33 | mBarWidth = tW / cC; |
|
33 | qreal categoryCount = mSeries->categoryCount(); | |
34 | qreal xStep = (tW/tC); |
|
34 | qreal barWidth = width / (mSeries->categoryCount() * 2); | |
35 | qreal xPos = ((tW/tC) - mBarWidth / 2); |
|
35 | qreal xStep = width/categoryCount; | |
36 | qreal h = mHeight; |
|
36 | qreal xPos = xStep/2 - barWidth / 2; | |
37 |
|
37 | |||
38 | int itemIndex(0); |
|
38 | int itemIndex(0); | |
39 |
for (int category = 0; category < |
|
39 | for (int category = 0; category < categoryCount ; category++) { | |
40 | qreal colSum = mSeries->categorySum(category); |
|
40 | qreal colSum = mSeries->categorySum(category); | |
41 | qreal scale = (h / colSum); |
|
41 | qreal scale = (height / colSum); | |
42 | qreal yPos = h; |
|
42 | qreal yPos = height; | |
43 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
43 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
44 | qreal barHeight = mSeries->valueAt(set, category) * scale; |
|
44 | qreal barHeight = mSeries->valueAt(set, category) * scale; | |
45 | Bar* bar = mBars.at(itemIndex); |
|
45 | Bar* bar = mBars.at(itemIndex); | |
46 |
|
46 | |||
47 | // TODO: width settable per bar? |
|
47 | // TODO: width settable per bar? | |
48 | bar->resize(mBarWidth, barHeight); |
|
48 | ||
49 | bar->setPen(mSeries->barsetAt(set)->pen()); |
|
49 | bar->setPen(mSeries->barsetAt(set)->pen()); | |
|
50 | bar->setRect(xPos, yPos-barHeight,barWidth, barHeight); | |||
50 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
51 | bar->setBrush(mSeries->barsetAt(set)->brush()); | |
51 | bar->setPos(xPos, yPos-barHeight); |
|
52 | ||
52 | itemIndex++; |
|
53 | itemIndex++; | |
53 | yPos -= barHeight; |
|
54 | yPos -= barHeight; | |
54 | } |
|
55 | } | |
@@ -57,11 +58,11 void PercentBarChartItem::layoutChanged() | |||||
57 |
|
58 | |||
58 | // Position floating values |
|
59 | // Position floating values | |
59 | itemIndex = 0; |
|
60 | itemIndex = 0; | |
60 |
xPos = ( |
|
61 | xPos = (width/categoryCount); | |
61 | for (int category=0; category < mSeries->categoryCount(); category++) { |
|
62 | for (int category=0; category < mSeries->categoryCount(); category++) { | |
62 | qreal yPos = h; |
|
63 | qreal yPos = height; | |
63 | qreal colSum = mSeries->categorySum(category); |
|
64 | qreal colSum = mSeries->categorySum(category); | |
64 | qreal scale = (h / colSum); |
|
65 | qreal scale = (height / colSum); | |
65 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
66 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
66 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
67 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
67 | BarValue* value = mFloatingValues.at(itemIndex); |
|
68 | BarValue* value = mFloatingValues.at(itemIndex); |
@@ -12,7 +12,7 class PercentBarChartItem : public BarChartItem | |||||
12 | { |
|
12 | { | |
13 | Q_OBJECT |
|
13 | Q_OBJECT | |
14 | public: |
|
14 | public: | |
15 |
PercentBarChartItem(QBarSeries *series, |
|
15 | PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter); | |
16 |
|
16 | |||
17 | private: |
|
17 | private: | |
18 |
|
18 |
@@ -38,32 +38,31 void StackedBarChartItem::layoutChanged() | |||||
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
40 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
|
41 | ||||
41 | qreal maxSum = mSeries->maxCategorySum(); |
|
42 | qreal maxSum = mSeries->maxCategorySum(); | |
42 | // Domain: |
|
43 | // Domain: | |
43 | if (mDomainMaxY > maxSum) { |
|
44 | if (mDomainMaxY > maxSum) { | |
44 | maxSum = mDomainMaxY; |
|
45 | maxSum = mDomainMaxY; | |
45 | } |
|
46 | } | |
46 |
|
47 | |||
47 | qreal h = mHeight; |
|
48 | qreal height = geometry().height(); | |
48 | qreal scale = (h / maxSum); |
|
49 | qreal width = geometry().width(); | |
49 | qreal tW = mWidth; |
|
50 | qreal scale = (height / mSeries->maxCategorySum()); | |
50 |
qreal tC = mSeries->categoryCount() |
|
51 | qreal categotyCount = mSeries->categoryCount(); | |
51 |
qreal |
|
52 | qreal barWidth = width / (categotyCount *2); | |
52 | mBarWidth = tW / cC; |
|
53 | qreal xStep = width/categotyCount; | |
53 |
qreal x |
|
54 | qreal xPos = xStep/2 - barWidth/2; | |
54 | qreal xPos = ((tW/tC) - mBarWidth / 2); |
|
55 | ||
55 |
|
56 | |||
56 | int itemIndex(0); |
|
57 | int itemIndex(0); | |
57 |
for (int category = 0; category < |
|
58 | for (int category = 0; category < categotyCount; category++) { | |
58 | qreal yPos = h; |
|
59 | qreal yPos = height; | |
59 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
60 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
60 | qreal barHeight = mSeries->valueAt(set, category) * scale; |
|
61 | qreal barHeight = mSeries->valueAt(set, category) * scale; | |
61 | Bar* bar = mBars.at(itemIndex); |
|
62 | Bar* bar = mBars.at(itemIndex); | |
62 |
|
||||
63 | bar->resize(mBarWidth, barHeight); |
|
|||
64 | bar->setPen(mSeries->barsetAt(set)->pen()); |
|
63 | bar->setPen(mSeries->barsetAt(set)->pen()); | |
65 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
64 | bar->setBrush(mSeries->barsetAt(set)->brush()); | |
66 |
bar->set |
|
65 | bar->setRect(xPos, yPos-barHeight,barWidth, barHeight); | |
67 | itemIndex++; |
|
66 | itemIndex++; | |
68 | yPos -= barHeight; |
|
67 | yPos -= barHeight; | |
69 | } |
|
68 | } | |
@@ -72,9 +71,9 void StackedBarChartItem::layoutChanged() | |||||
72 |
|
71 | |||
73 | // Position floating values |
|
72 | // Position floating values | |
74 | itemIndex = 0; |
|
73 | itemIndex = 0; | |
75 |
xPos = ( |
|
74 | xPos = (width/categotyCount); | |
76 | for (int category=0; category < mSeries->categoryCount(); category++) { |
|
75 | for (int category=0; category < mSeries->categoryCount(); category++) { | |
77 | qreal yPos = h; |
|
76 | qreal yPos = height; | |
78 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
77 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
79 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
78 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
80 | BarValue* value = mFloatingValues.at(itemIndex); |
|
79 | BarValue* value = mFloatingValues.at(itemIndex); |
@@ -11,7 +11,7 class StackedBarChartItem : public BarChartItem | |||||
11 | { |
|
11 | { | |
12 | Q_OBJECT |
|
12 | Q_OBJECT | |
13 | public: |
|
13 | public: | |
14 |
StackedBarChartItem(QBarSeries *series, |
|
14 | StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter); | |
15 | ~StackedBarChartItem(); |
|
15 | ~StackedBarChartItem(); | |
16 |
|
16 | |||
17 | private: |
|
17 | private: |
@@ -35,7 +35,7 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY,int tickXCo | |||||
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | if(m_tickXCount!=tickYCount) { |
|
37 | if(m_tickXCount!=tickYCount) { | |
38 |
m_tick |
|
38 | m_tickYCount=tickYCount; | |
39 | tickYChanged=true; |
|
39 | tickYChanged=true; | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
@@ -74,11 +74,22 void Domain::setRangeX(qreal min, qreal max) | |||||
74 | { |
|
74 | { | |
75 | setRange(min,max,m_minY, m_maxY); |
|
75 | setRange(min,max,m_minY, m_maxY); | |
76 | } |
|
76 | } | |
|
77 | ||||
|
78 | void Domain::setRangeX(qreal min, qreal max, int tickCount) | |||
|
79 | { | |||
|
80 | setRange(min,max,m_minY, m_maxY,tickCount,m_tickYCount); | |||
|
81 | } | |||
|
82 | ||||
77 | void Domain::setRangeY(qreal min, qreal max) |
|
83 | void Domain::setRangeY(qreal min, qreal max) | |
78 | { |
|
84 | { | |
79 | setRange(m_minX, m_maxX, min, max); |
|
85 | setRange(m_minX, m_maxX, min, max); | |
80 | } |
|
86 | } | |
81 |
|
87 | |||
|
88 | void Domain::setRangeY(qreal min, qreal max,int tickCount) | |||
|
89 | { | |||
|
90 | setRange(m_minX, m_maxX, min, max,m_tickXCount,tickCount); | |||
|
91 | } | |||
|
92 | ||||
82 | void Domain::setMinX(qreal min) |
|
93 | void Domain::setMinX(qreal min) | |
83 | { |
|
94 | { | |
84 | setRange(min, m_maxX, m_minY, m_maxY); |
|
95 | setRange(min, m_maxX, m_minY, m_maxY); | |
@@ -239,7 +250,7 bool operator!= (const Domain &domain1, const Domain &domain2) | |||||
239 |
|
250 | |||
240 | QDebug operator<<(QDebug dbg, const Domain &domain) |
|
251 | QDebug operator<<(QDebug dbg, const Domain &domain) | |
241 | { |
|
252 | { | |
242 | dbg.nospace() << "Domain("<<domain.m_minX<<','<<domain.m_maxX<<','<<domain.m_minY<<','<<domain.m_maxY<<')'; |
|
253 | dbg.nospace() << "Domain("<<domain.m_minX<<','<<domain.m_maxX<<','<<domain.m_minY<<','<<domain.m_maxY<<')' << domain.m_tickXCount << "," << domain.m_tickYCount ; | |
243 | return dbg.maybeSpace(); |
|
254 | return dbg.maybeSpace(); | |
244 | } |
|
255 | } | |
245 |
|
256 |
@@ -16,7 +16,9 public: | |||||
16 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
16 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
17 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY, int tickXCount, int tickYCount); |
|
17 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY, int tickXCount, int tickYCount); | |
18 | void setRangeX(qreal min, qreal max); |
|
18 | void setRangeX(qreal min, qreal max); | |
|
19 | void setRangeX(qreal min, qreal max, int tickCount); | |||
19 | void setRangeY(qreal min, qreal max); |
|
20 | void setRangeY(qreal min, qreal max); | |
|
21 | void setRangeY(qreal min, qreal max, int tickCount); | |||
20 | void setMinX(qreal min); |
|
22 | void setMinX(qreal min); | |
21 | void setMaxX(qreal max); |
|
23 | void setMaxX(qreal max); | |
22 | void setMinY(qreal min); |
|
24 | void setMinY(qreal min); |
@@ -63,8 +63,8 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices) | |||||
63 |
|
63 | |||
64 | PieSliceData data = sliceData(s); |
|
64 | PieSliceData data = sliceData(s); | |
65 |
|
65 | |||
66 |
if ( |
|
66 | if (animator()) | |
67 |
|
|
67 | animator()->addAnimation(this, s, data, isEmpty); | |
68 | else |
|
68 | else | |
69 | setLayout(s, data); |
|
69 | setLayout(s, data); | |
70 | } |
|
70 | } | |
@@ -155,8 +155,8 void PieChartItem::applyLayout(const PieLayout &layout) | |||||
155 |
|
155 | |||
156 | void PieChartItem::updateLayout(QPieSlice *slice, const PieSliceData &sliceData) |
|
156 | void PieChartItem::updateLayout(QPieSlice *slice, const PieSliceData &sliceData) | |
157 | { |
|
157 | { | |
158 |
if ( |
|
158 | if (animator()) | |
159 |
|
|
159 | animator()->updateLayout(this, slice, sliceData); | |
160 | else |
|
160 | else | |
161 | setLayout(slice, sliceData); |
|
161 | setLayout(slice, sliceData); | |
162 | } |
|
162 | } |
General Comments 0
You need to be logged in to leave comments.
Login now