@@ -1,96 +1,96 | |||
|
1 | 1 | #include "barpresenter_p.h" |
|
2 | 2 | #include "bar_p.h" |
|
3 | 3 | #include "barvalue_p.h" |
|
4 | 4 | #include "separator_p.h" |
|
5 | 5 | #include "qbarset.h" |
|
6 | 6 | #include <QDebug> |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | BarPresenter::BarPresenter(QBarSeries *series, QChart *parent) : |
|
11 | 11 | BarPresenterBase(series, parent) |
|
12 | 12 | { |
|
13 | 13 | } |
|
14 | 14 | |
|
15 | 15 | void BarPresenter::layoutChanged() |
|
16 | 16 | { |
|
17 | 17 | // Scale bars to new layout |
|
18 | 18 | // Layout for bars: |
|
19 | 19 | if (mSeries->barsetCount() <= 0) { |
|
20 | 20 | qDebug() << "No sets in model!"; |
|
21 | 21 | return; |
|
22 | 22 | } |
|
23 | 23 | |
|
24 | 24 | if (childItems().count() == 0) { |
|
25 | 25 | qDebug() << "WARNING: BarPresenter::layoutChanged called before graphics items are created!"; |
|
26 | 26 | return; |
|
27 | 27 | } |
|
28 | 28 | |
|
29 | 29 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
30 | 30 | int categoryCount = mSeries->categoryCount(); |
|
31 | 31 | int setCount = mSeries->barsetCount(); |
|
32 | 32 | |
|
33 | 33 | qreal tW = mWidth; |
|
34 | 34 | qreal tH = mHeight; |
|
35 | 35 | qreal tM = mSeries->max(); |
|
36 | 36 | qreal scale = (tH/tM); |
|
37 | 37 | qreal tC = categoryCount + 1; |
|
38 | 38 | qreal categoryWidth = tW/tC; |
|
39 | 39 | mBarWidth = categoryWidth / (setCount+1); |
|
40 | 40 | |
|
41 | 41 | int itemIndex(0); |
|
42 | 42 | for (int category=0; category < categoryCount; category++) { |
|
43 | qreal xPos = categoryWidth * category + categoryWidth /2; | |
|
43 | qreal xPos = categoryWidth * category + categoryWidth /2 + mBarWidth/2; | |
|
44 | 44 | qreal yPos = mHeight; |
|
45 | 45 | for (int set = 0; set < setCount; set++) { |
|
46 | 46 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
47 | 47 | Bar* bar = mBars.at(itemIndex); |
|
48 | 48 | |
|
49 | 49 | // TODO: width settable per bar? |
|
50 | 50 | bar->resize(mBarWidth, barHeight); |
|
51 | 51 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
52 | 52 | bar->setPos(xPos, yPos-barHeight); |
|
53 | 53 | itemIndex++; |
|
54 | 54 | xPos += mBarWidth; |
|
55 | 55 | } |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | // Position separators |
|
59 |
qreal xPos = categoryWidth + categoryWidth/2 |
|
|
59 | qreal xPos = categoryWidth + categoryWidth/2; | |
|
60 | 60 | for (int s=0; s < mSeparators.count(); s++) { |
|
61 | 61 | Separator* sep = mSeparators.at(s); |
|
62 | 62 | sep->setPos(xPos,0); |
|
63 | 63 | sep->setSize(QSizeF(1,mHeight)); |
|
64 | 64 | sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme |
|
65 | 65 | xPos += categoryWidth; |
|
66 | 66 | } |
|
67 | 67 | |
|
68 | 68 | // Position floating values |
|
69 | 69 | itemIndex = 0; |
|
70 | 70 | for (int category=0; category < mSeries->categoryCount(); category++) { |
|
71 |
qreal xPos = categoryWidth * category + categoryWidth/2 + mBarWidth |
|
|
71 | qreal xPos = categoryWidth * category + categoryWidth/2 + mBarWidth; | |
|
72 | 72 | qreal yPos = mHeight; |
|
73 | 73 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
74 | 74 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
75 | 75 | BarValue* value = mFloatingValues.at(itemIndex); |
|
76 | 76 | |
|
77 | 77 | QBarSet* barSet = mSeries->barsetAt(set); |
|
78 | 78 | value->resize(100,50); // TODO: proper layout for this. |
|
79 | 79 | value->setPos(xPos, yPos-barHeight/2); |
|
80 | 80 | value->setPen(barSet->floatingValuePen()); |
|
81 | 81 | |
|
82 | 82 | if (mSeries->valueAt(set,category) != 0) { |
|
83 | 83 | value->setValueString(QString::number(mSeries->valueAt(set,category))); |
|
84 | 84 | } else { |
|
85 | 85 | value->setValueString(QString("")); |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | itemIndex++; |
|
89 | 89 | xPos += mBarWidth; |
|
90 | 90 | } |
|
91 | 91 | } |
|
92 | 92 | } |
|
93 | 93 | |
|
94 | 94 | #include "moc_barpresenter_p.cpp" |
|
95 | 95 | |
|
96 | 96 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now