@@ -1,110 +1,110 | |||
|
1 | 1 | #include "percentbarpresenter_p.h" |
|
2 | 2 | #include "bar_p.h" |
|
3 | 3 | #include "barlabel_p.h" |
|
4 | 4 | #include "barvalue_p.h" |
|
5 | 5 | #include "separator_p.h" |
|
6 | 6 | #include "qbarset.h" |
|
7 | 7 | #include <QDebug> |
|
8 | 8 | |
|
9 | 9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | 10 | |
|
11 | 11 | |
|
12 | 12 | PercentBarPresenter::PercentBarPresenter(QBarSeries *series, QGraphicsItem *parent) : |
|
13 | 13 | BarPresenterBase(series, parent) |
|
14 | 14 | { |
|
15 | 15 | } |
|
16 | 16 | |
|
17 | 17 | void PercentBarPresenter::layoutChanged() |
|
18 | 18 | { |
|
19 | 19 | // Scale bars to new layout |
|
20 | 20 | // Layout for bars: |
|
21 | 21 | if (mSeries->barsetCount() <= 0) { |
|
22 | 22 | qDebug() << "No sets in model!"; |
|
23 | 23 | // Nothing to do. |
|
24 | 24 | return; |
|
25 | 25 | } |
|
26 | 26 | |
|
27 | 27 | if (childItems().count() == 0) { |
|
28 | 28 | qDebug() << "WARNING: PercentBarPresenter::layoutChanged called before graphics items are created!"; |
|
29 | 29 | return; |
|
30 | 30 | } |
|
31 | 31 | |
|
32 | 32 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
33 | 33 | qreal tW = mWidth; |
|
34 | 34 | qreal tC = mSeries->categoryCount() + 1; |
|
35 | 35 | qreal cC = mSeries->categoryCount() * 2 + 1; |
|
36 | 36 | mBarWidth = tW / cC; |
|
37 | 37 | qreal xStep = (tW/tC); |
|
38 | 38 | qreal xPos = ((tW/tC) - mBarWidth / 2); |
|
39 | 39 | qreal h = mHeight; |
|
40 | 40 | |
|
41 | 41 | int itemIndex(0); |
|
42 | 42 | int labelIndex(0); |
|
43 | 43 | for (int category = 0; category < mSeries->categoryCount(); category++) { |
|
44 | 44 | qreal colSum = mSeries->categorySum(category); |
|
45 | 45 | qreal scale = (h / colSum); |
|
46 | 46 | qreal yPos = h; |
|
47 | 47 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
48 | 48 | qreal barHeight = mSeries->valueAt(set, category) * scale; |
|
49 | 49 | Bar* bar = mBars.at(itemIndex); |
|
50 | 50 | |
|
51 | 51 | // TODO: width settable per bar? |
|
52 | 52 | bar->resize(mBarWidth, barHeight); |
|
53 | 53 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
54 | 54 | bar->setPos(xPos, yPos-barHeight); |
|
55 | 55 | itemIndex++; |
|
56 | 56 | yPos -= barHeight; |
|
57 | 57 | } |
|
58 | 58 | |
|
59 | 59 | // TODO: Layout for labels, remove magic number |
|
60 | 60 | BarLabel* label = mLabels.at(labelIndex); |
|
61 | 61 | label->setPos(xPos, mHeight + 20); |
|
62 | 62 | labelIndex++; |
|
63 | 63 | xPos += xStep; |
|
64 | 64 | } |
|
65 | 65 | |
|
66 | 66 | // Position separators |
|
67 | 67 | xPos = xStep + xStep/2; |
|
68 | 68 | for (int s=0; s < mSeries->categoryCount() - 1; s++) { |
|
69 | 69 | Separator* sep = mSeparators.at(s); |
|
70 | 70 | sep->setPos(xPos,0); |
|
71 | 71 | sep->setSize(QSizeF(1,mHeight)); |
|
72 | 72 | xPos += xStep; |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | // Position floating values |
|
76 | 76 | itemIndex = 0; |
|
77 |
xPos = ( |
|
|
77 | xPos = (tW/tC); | |
|
78 | 78 | for (int category=0; category < mSeries->categoryCount(); category++) { |
|
79 | 79 | qreal yPos = h; |
|
80 | 80 | qreal colSum = mSeries->categorySum(category); |
|
81 | 81 | qreal scale = (h / colSum); |
|
82 | 82 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
83 | 83 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
84 | 84 | BarValue* value = mFloatingValues.at(itemIndex); |
|
85 | 85 | |
|
86 | 86 | // TODO: remove hard coding, apply layout |
|
87 | 87 | value->resize(100,50); |
|
88 | 88 | value->setPos(xPos, yPos-barHeight/2); |
|
89 | 89 | value->setPen(QPen(QColor(255,255,255,255))); |
|
90 | 90 | |
|
91 | 91 | if (mSeries->valueAt(set,category) != 0) { |
|
92 | 92 | int p = mSeries->percentageAt(set,category) * 100; |
|
93 | 93 | QString vString(QString::number(p)); |
|
94 | 94 | vString.truncate(3); |
|
95 | 95 | vString.append("%"); |
|
96 | 96 | value->setValueString(vString); |
|
97 | 97 | } else { |
|
98 | 98 | value->setValueString(QString("")); |
|
99 | 99 | } |
|
100 | 100 | |
|
101 | 101 | itemIndex++; |
|
102 | 102 | yPos -= barHeight; |
|
103 | 103 | } |
|
104 | 104 | xPos += xStep; |
|
105 | 105 | } |
|
106 | 106 | } |
|
107 | 107 | |
|
108 | 108 | #include "moc_percentbarpresenter_p.cpp" |
|
109 | 109 | |
|
110 | 110 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,113 +1,113 | |||
|
1 | 1 | #include "stackedbarpresenter_p.h" |
|
2 | 2 | #include "bar_p.h" |
|
3 | 3 | #include "barlabel_p.h" |
|
4 | 4 | #include "barvalue_p.h" |
|
5 | 5 | #include "separator_p.h" |
|
6 | 6 | #include "qbarset.h" |
|
7 | 7 | #include <QDebug> |
|
8 | 8 | |
|
9 | 9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | 10 | |
|
11 | 11 | StackedBarPresenter::StackedBarPresenter(QBarSeries *series, QGraphicsItem *parent) : |
|
12 | 12 | BarPresenterBase(series,parent) |
|
13 | 13 | { |
|
14 | 14 | } |
|
15 | 15 | |
|
16 | 16 | StackedBarPresenter::~StackedBarPresenter() |
|
17 | 17 | { |
|
18 | 18 | } |
|
19 | 19 | |
|
20 | 20 | |
|
21 | 21 | void StackedBarPresenter::layoutChanged() |
|
22 | 22 | { |
|
23 | 23 | // Scale bars to new layout |
|
24 | 24 | // Layout for bars: |
|
25 | 25 | if (mSeries->barsetCount() <= 0) { |
|
26 | 26 | qDebug() << "No sets in model!"; |
|
27 | 27 | // Nothing to do. |
|
28 | 28 | return; |
|
29 | 29 | } |
|
30 | 30 | |
|
31 | 31 | if (mSeries->categoryCount() == 0) { |
|
32 | 32 | qDebug() << "No categories in model!"; |
|
33 | 33 | // Nothing to do |
|
34 | 34 | return; |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | if (childItems().count() == 0) { |
|
38 | 38 | qDebug() << "WARNING: StackedBarPresenter::layoutChanged called before graphics items are created!"; |
|
39 | 39 | return; |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
43 | 43 | qreal maxSum = mSeries->maxCategorySum(); |
|
44 | 44 | qreal h = mHeight; |
|
45 | 45 | qreal scale = (h / maxSum); |
|
46 | 46 | qreal tW = mWidth; |
|
47 | 47 | qreal tC = mSeries->categoryCount() + 1; |
|
48 | 48 | qreal cC = mSeries->categoryCount() * 2 + 1; |
|
49 | 49 | mBarWidth = tW / cC; |
|
50 | 50 | qreal xStep = (tW/tC); |
|
51 | 51 | qreal xPos = ((tW/tC) - mBarWidth / 2); |
|
52 | 52 | |
|
53 | 53 | int itemIndex(0); |
|
54 | 54 | int labelIndex(0); |
|
55 | 55 | for (int category = 0; category < mSeries->categoryCount(); category++) { |
|
56 | 56 | qreal yPos = h; |
|
57 | 57 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
58 | 58 | qreal barHeight = mSeries->valueAt(set, category) * scale; |
|
59 | 59 | Bar* bar = mBars.at(itemIndex); |
|
60 | 60 | |
|
61 | 61 | bar->resize(mBarWidth, barHeight); |
|
62 | 62 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
63 | 63 | bar->setPos(xPos, yPos-barHeight); |
|
64 | 64 | itemIndex++; |
|
65 | 65 | yPos -= barHeight; |
|
66 | 66 | } |
|
67 | 67 | |
|
68 | 68 | // TODO: Layout for labels, remove magic number |
|
69 | 69 | BarLabel* label = mLabels.at(labelIndex); |
|
70 | 70 | label->setPos(xPos, mHeight + 20); |
|
71 | 71 | labelIndex++; |
|
72 | 72 | xPos += xStep; |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | // Position separators |
|
76 | 76 | xPos = xStep + xStep/2; |
|
77 | 77 | for (int s=0; s < mSeries->categoryCount() - 1; s++) { |
|
78 | 78 | Separator* sep = mSeparators.at(s); |
|
79 | 79 | sep->setPos(xPos,0); |
|
80 | 80 | sep->setSize(QSizeF(1,mHeight)); |
|
81 | 81 | xPos += xStep; |
|
82 | 82 | } |
|
83 | 83 | |
|
84 | 84 | // Position floating values |
|
85 | 85 | itemIndex = 0; |
|
86 |
xPos = ( |
|
|
86 | xPos = (tW/tC); | |
|
87 | 87 | for (int category=0; category < mSeries->categoryCount(); category++) { |
|
88 | 88 | qreal yPos = h; |
|
89 | 89 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
90 | 90 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
91 | 91 | BarValue* value = mFloatingValues.at(itemIndex); |
|
92 | 92 | |
|
93 | 93 | // TODO: remove hard coding, apply layout |
|
94 | 94 | value->resize(100,50); |
|
95 | 95 | value->setPos(xPos, yPos-barHeight/2); |
|
96 | 96 | value->setPen(QPen(QColor(255,255,255,255))); |
|
97 | 97 | |
|
98 | 98 | if (mSeries->valueAt(set,category) != 0) { |
|
99 | 99 | value->setValueString(QString::number(mSeries->valueAt(set,category))); |
|
100 | 100 | } else { |
|
101 | 101 | value->setValueString(QString("")); |
|
102 | 102 | } |
|
103 | 103 | |
|
104 | 104 | itemIndex++; |
|
105 | 105 | yPos -= barHeight; |
|
106 | 106 | } |
|
107 | 107 | xPos += xStep; |
|
108 | 108 | } |
|
109 | 109 | } |
|
110 | 110 | |
|
111 | 111 | #include "moc_stackedbarpresenter_p.cpp" |
|
112 | 112 | |
|
113 | 113 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now