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