@@ -88,103 +88,8 void BarChartItem::dataChanged() | |||
|
88 | 88 | } |
|
89 | 89 | } |
|
90 | 90 | } |
|
91 | /* | |
|
92 | void BarChartItem::layoutChanged() | |
|
93 | { | |
|
94 | qDebug() << "Deprecated BarChartItem::layoutChanged called. aborting"; | |
|
95 | return; | |
|
96 | // Scale bars to new layout | |
|
97 | // Layout for bars: | |
|
98 | if (mSeries->barsetCount() <= 0) { | |
|
99 | qDebug() << "No sets in model!"; | |
|
100 | return; | |
|
101 | } | |
|
102 | ||
|
103 | if (childItems().count() == 0) { | |
|
104 | qDebug() << "WARNING: BarChartitem::layoutChanged called before graphics items are created!"; | |
|
105 | return; | |
|
106 | } | |
|
107 | ||
|
108 | ||
|
109 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
|
110 | qreal categoryCount = mSeries->categoryCount(); | |
|
111 | qreal setCount = mSeries->barsetCount(); | |
|
112 | qreal max = mSeries->max(); | |
|
113 | ||
|
114 | // Domain: | |
|
115 | if (mDomainMaxY > max) { | |
|
116 | max = mDomainMaxY; | |
|
117 | } | |
|
118 | ||
|
119 | qreal width = geometry().width(); | |
|
120 | qreal height = geometry().height(); | |
|
121 | qreal scale = (height/max); | |
|
122 | qreal categoryWidth = width/categoryCount; | |
|
123 | qreal barWidth = categoryWidth / (setCount+1); | |
|
124 | ||
|
125 | BarLayout layout; | |
|
126 | ||
|
127 | int itemIndex(0); | |
|
128 | for (int category=0; category < categoryCount; category++) { | |
|
129 | qreal xPos = categoryWidth * category + barWidth/2; | |
|
130 | qreal yPos = height; | |
|
131 | for (int set = 0; set < setCount; set++) { | |
|
132 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
|
133 | Bar* bar = mBars.at(itemIndex); | |
|
134 | ||
|
135 | QRectF rect(xPos,yPos-barHeight,mBarWidth,barHeight); | |
|
136 | layout.insert(bar,rect); | |
|
137 | // TODO: width settable per bar? | |
|
138 | bar->setRect(xPos, yPos-barHeight,barWidth, barHeight); | |
|
139 | bar->setPen(mSeries->barsetAt(set)->pen()); | |
|
140 | bar->setBrush(mSeries->barsetAt(set)->brush()); | |
|
141 | ||
|
142 | // bar->resize(mBarWidth, barHeight); | |
|
143 | // layout.insert(bar,QSizeF(mBarWidth,barHeight)); | |
|
144 | bar->setPen(mSeries->barsetAt(set)->pen()); | |
|
145 | bar->setBrush(mSeries->barsetAt(set)->brush()); | |
|
146 | // bar->setPos(xPos, yPos-barHeight); | |
|
147 | itemIndex++; | |
|
148 | xPos += barWidth; | |
|
149 | } | |
|
150 | } | |
|
151 | ||
|
152 | // Position floating values | |
|
153 | itemIndex = 0; | |
|
154 | for (int category=0; category < mSeries->categoryCount(); category++) { | |
|
155 | qreal xPos = categoryWidth * category + categoryWidth/2 + barWidth; | |
|
156 | qreal yPos = height; | |
|
157 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
|
158 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
|
159 | BarValue* value = mFloatingValues.at(itemIndex); | |
|
160 | ||
|
161 | QBarSet* barSet = mSeries->barsetAt(set); | |
|
162 | value->resize(100,50); // TODO: proper layout for this. | |
|
163 | value->setPos(xPos, yPos-barHeight/2); | |
|
164 | value->setPen(barSet->floatingValuePen()); | |
|
165 | ||
|
166 | if (mSeries->valueAt(set,category) != 0) { | |
|
167 | value->setValueString(QString::number(mSeries->valueAt(set,category))); | |
|
168 | } else { | |
|
169 | value->setValueString(QString("")); | |
|
170 | } | |
|
171 | ||
|
172 | itemIndex++; | |
|
173 | xPos += barWidth; | |
|
174 | } | |
|
175 | } | |
|
176 | // update(); | |
|
177 | } | |
|
178 | */ | |
|
179 | 91 | QVector<QRectF> BarChartItem::calculateLayout() |
|
180 | 92 | { |
|
181 | // layoutChanged(); | |
|
182 | /* | |
|
183 | BarLayout layout; | |
|
184 | foreach(Bar* bar, mBars) { | |
|
185 | layout.insert(bar,bar->boundingRect()); | |
|
186 | } | |
|
187 | */ | |
|
188 | 93 | QVector<QRectF> layout; |
|
189 | 94 | |
|
190 | 95 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
@@ -214,14 +119,9 QVector<QRectF> BarChartItem::calculateLayout() | |||
|
214 | 119 | Bar* bar = mBars.at(itemIndex); |
|
215 | 120 | |
|
216 | 121 | QRectF rect(xPos,yPos-barHeight,barWidth,barHeight); |
|
217 | //layout.insert(bar,rect); | |
|
218 | 122 | layout.append(rect); |
|
219 | // TODO: width settable per bar? | |
|
220 | // bar->resize(mBarWidth, barHeight); | |
|
221 | // layout.insert(bar,QSizeF(mBarWidth,barHeight)); | |
|
222 | 123 | bar->setPen(mSeries->barsetAt(set)->pen()); |
|
223 | 124 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
224 | // bar->setPos(xPos, yPos-barHeight); | |
|
225 | 125 | itemIndex++; |
|
226 | 126 | xPos += barWidth; |
|
227 | 127 | } |
@@ -268,8 +168,6 void BarChartItem::setLayout(const QVector<QRectF> &layout) | |||
|
268 | 168 | mLayout = layout; |
|
269 | 169 | |
|
270 | 170 | for (int i=0; i<mBars.count(); i++) { |
|
271 | //mBars.at(i)->setSize(layout.at(i).size()); | |
|
272 | //mBars.at(i)->setPos(layout.at(i).topLeft()); | |
|
273 | 171 | mBars.at(i)->setRect(layout.at(i)); |
|
274 | 172 | } |
|
275 | 173 |
@@ -34,10 +34,9 public: | |||
|
34 | 34 | // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it |
|
35 | 35 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes |
|
36 | 36 | private slots: |
|
37 | //virtual void layoutChanged(); // layout has changed -> need to recalculate bar sizes | |
|
38 | 37 | |
|
39 | 38 | public: |
|
40 | QVector<QRectF> calculateLayout(); | |
|
39 | virtual QVector<QRectF> calculateLayout(); | |
|
41 | 40 | void applyLayout(const QVector<QRectF> &layout); |
|
42 | 41 | void setLayout(const QVector<QRectF> &layout); |
|
43 | 42 | void updateLayout(const QVector<QRectF> &layout); |
@@ -11,20 +11,9 PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter* pre | |||
|
11 | 11 | { |
|
12 | 12 | } |
|
13 | 13 | |
|
14 |
|
|
|
14 | QVector<QRectF> PercentBarChartItem::calculateLayout() | |
|
15 | 15 | { |
|
16 | // Scale bars to new layout | |
|
17 | // Layout for bars: | |
|
18 | if (mSeries->barsetCount() <= 0) { | |
|
19 | qDebug() << "No sets in model!"; | |
|
20 | // Nothing to do. | |
|
21 | return; | |
|
22 | } | |
|
23 | ||
|
24 | if (childItems().count() == 0) { | |
|
25 | qDebug() << "WARNING: PercentBarChartItem::layoutChanged called before graphics items are created!"; | |
|
26 | return; | |
|
27 | } | |
|
16 | QVector<QRectF> layout; | |
|
28 | 17 | |
|
29 | 18 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
30 | 19 | qreal width = geometry().width(); |
@@ -43,13 +32,10 void PercentBarChartItem::layoutChanged() | |||
|
43 | 32 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
44 | 33 | qreal barHeight = mSeries->valueAt(set, category) * scale; |
|
45 | 34 | Bar* bar = mBars.at(itemIndex); |
|
46 | ||
|
47 | // TODO: width settable per bar? | |
|
48 | ||
|
49 | 35 | bar->setPen(mSeries->barsetAt(set)->pen()); |
|
50 | bar->setRect(xPos, yPos-barHeight,barWidth, barHeight); | |
|
51 | 36 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
52 | ||
|
37 | QRectF rect(xPos, yPos-barHeight,barWidth, barHeight); | |
|
38 | layout.append(rect); | |
|
53 | 39 | itemIndex++; |
|
54 | 40 | yPos -= barHeight; |
|
55 | 41 | } |
@@ -87,6 +73,7 void PercentBarChartItem::layoutChanged() | |||
|
87 | 73 | } |
|
88 | 74 | xPos += xStep; |
|
89 | 75 | } |
|
76 | return layout; | |
|
90 | 77 | } |
|
91 | 78 | |
|
92 | 79 | #include "moc_percentbarchartitem_p.cpp" |
@@ -15,8 +15,7 public: | |||
|
15 | 15 | PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter); |
|
16 | 16 | |
|
17 | 17 | private: |
|
18 | ||
|
19 | void layoutChanged(); // layout has changed -> need to recalculate bar sizes | |
|
18 | virtual QVector<QRectF> calculateLayout(); | |
|
20 | 19 | |
|
21 | 20 | private: |
|
22 | 21 |
@@ -16,27 +16,9 StackedBarChartItem::~StackedBarChartItem() | |||
|
16 | 16 | } |
|
17 | 17 | |
|
18 | 18 | |
|
19 |
|
|
|
19 | QVector<QRectF> StackedBarChartItem::calculateLayout() | |
|
20 | 20 | { |
|
21 | // Scale bars to new layout | |
|
22 | // Layout for bars: | |
|
23 | if (mSeries->barsetCount() <= 0) { | |
|
24 | qDebug() << "No sets in model!"; | |
|
25 | // Nothing to do. | |
|
26 | return; | |
|
27 | } | |
|
28 | ||
|
29 | if (mSeries->categoryCount() == 0) { | |
|
30 | qDebug() << "No categories in model!"; | |
|
31 | // Nothing to do | |
|
32 | return; | |
|
33 | } | |
|
34 | ||
|
35 | if (childItems().count() == 0) { | |
|
36 | qDebug() << "WARNING: StackedBarChartItem::layoutChanged called before graphics items are created!"; | |
|
37 | return; | |
|
38 | } | |
|
39 | ||
|
21 | QVector<QRectF> layout; | |
|
40 | 22 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
41 | 23 | |
|
42 | 24 | qreal maxSum = mSeries->maxCategorySum(); |
@@ -53,7 +35,6 void StackedBarChartItem::layoutChanged() | |||
|
53 | 35 | qreal xStep = width/categotyCount; |
|
54 | 36 | qreal xPos = xStep/2 - barWidth/2; |
|
55 | 37 | |
|
56 | ||
|
57 | 38 | int itemIndex(0); |
|
58 | 39 | for (int category = 0; category < categotyCount; category++) { |
|
59 | 40 | qreal yPos = height; |
@@ -62,7 +43,8 void StackedBarChartItem::layoutChanged() | |||
|
62 | 43 | Bar* bar = mBars.at(itemIndex); |
|
63 | 44 | bar->setPen(mSeries->barsetAt(set)->pen()); |
|
64 | 45 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
65 |
|
|
|
46 | QRectF rect(xPos,yPos-barHeight,barWidth,barHeight); | |
|
47 | layout.append(rect); | |
|
66 | 48 | itemIndex++; |
|
67 | 49 | yPos -= barHeight; |
|
68 | 50 | } |
@@ -94,6 +76,7 void StackedBarChartItem::layoutChanged() | |||
|
94 | 76 | } |
|
95 | 77 | xPos += xStep; |
|
96 | 78 | } |
|
79 | return layout; | |
|
97 | 80 | } |
|
98 | 81 | |
|
99 | 82 | #include "moc_stackedbarchartitem_p.cpp" |
General Comments 0
You need to be logged in to leave comments.
Login now