@@ -3,7 +3,9 | |||
|
3 | 3 | #include <QParallelAnimationGroup> |
|
4 | 4 | #include <QTimer> |
|
5 | 5 | |
|
6 |
Q_DECLARE_METATYPE(QVector<Q |
|
|
6 | Q_DECLARE_METATYPE(QVector<QRectF>) | |
|
7 | //Q_DECLARE_METATYPE(BarLayout) // TODO? | |
|
8 | ||
|
7 | 9 | |
|
8 | 10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 11 | |
@@ -17,31 +19,35 BarAnimation::~BarAnimation() | |||
|
17 | 19 | { |
|
18 | 20 | } |
|
19 | 21 | |
|
20 |
void BarAnimation::updateValues(const |
|
|
22 | void BarAnimation::updateValues(const QVector<QRectF>& layout) | |
|
21 | 23 | { |
|
22 | // TODO: | |
|
23 | qDebug() << "BarAnimation::updateValues"; | |
|
24 | // TODO?: | |
|
25 | // qDebug() << "BarAnimation::updateValues" << layout.count(); | |
|
24 | 26 | } |
|
25 | 27 | |
|
26 | 28 | |
|
27 | 29 | QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const |
|
28 | 30 | { |
|
29 |
QVector<Q |
|
|
30 |
QVector<Q |
|
|
31 |
QVector<Q |
|
|
31 | QVector<QRectF> startVector = qVariantValue<QVector<QRectF> > (from); | |
|
32 | QVector<QRectF> endVector = qVariantValue<QVector<QRectF> > (to); | |
|
33 | QVector<QRectF> result; | |
|
32 | 34 | |
|
33 | 35 | Q_ASSERT(startVector.count() == endVector.count()) ; |
|
34 | 36 | |
|
35 | 37 | for(int i =0 ;i< startVector.count();i++){ |
|
36 |
|
|
|
37 | result << value; | |
|
38 | //QRectF value = startVector[i] + ((endVector[i] - startVector[i]) * progress); | |
|
39 | QPointF topLeft = startVector[i].topLeft() + ((endVector[i].topLeft() - startVector[i].topLeft()) * progress); | |
|
40 | QSizeF size = startVector[i].size() + ((endVector[i].size() - startVector[i].size()) * progress); | |
|
41 | QRectF value(topLeft,size); | |
|
42 | result << value; | |
|
38 | 43 | } |
|
39 | 44 | return qVariantFromValue(result); |
|
40 | 45 | } |
|
41 | 46 | |
|
42 | void BarAnimation::updateCurrentValue(const QVariant &) | |
|
47 | void BarAnimation::updateCurrentValue(const QVariant &value) | |
|
43 | 48 | { |
|
44 | // TODO? | |
|
49 | QVector<QRectF> layout = qVariantValue<QVector<QRectF> >(value); | |
|
50 | m_item->setLayout(layout); | |
|
45 | 51 | } |
|
46 | 52 | |
|
47 | 53 | #include "moc_baranimation_p.cpp" |
@@ -18,7 +18,7 public: | |||
|
18 | 18 | BarAnimation(BarChartItem *item); |
|
19 | 19 | ~BarAnimation(); |
|
20 | 20 | |
|
21 |
void updateValues(const |
|
|
21 | void updateValues(const QVector<QRectF>& layout); | |
|
22 | 22 | |
|
23 | 23 | public: // from QVariantAnimation |
|
24 | 24 | virtual QVariant interpolated (const QVariant & from, const QVariant & to, qreal progress ) const; |
@@ -13,6 +13,7 | |||
|
13 | 13 | |
|
14 | 14 | Q_DECLARE_METATYPE(QVector<QPointF>) |
|
15 | 15 | Q_DECLARE_METATYPE(QVector<qreal>) |
|
16 | Q_DECLARE_METATYPE(QVector<QRectF>) | |
|
16 | 17 | |
|
17 | 18 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
18 | 19 | |
@@ -267,12 +268,16 void ChartAnimator::updateLayout(PieChartItem* item, QPieSlice *slice, const Pie | |||
|
267 | 268 | animation->updateValue(slice, sliceData); |
|
268 | 269 | } |
|
269 | 270 | |
|
270 |
void ChartAnimator::updateLayout(BarChartItem* item, const |
|
|
271 | void ChartAnimator::updateLayout(BarChartItem* item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout) | |
|
271 | 272 | { |
|
272 | 273 | qDebug() << "ChartAnimator::updateLayout"; |
|
273 | 274 | BarAnimation* animation = static_cast<BarAnimation*>(m_animations.value(item)); |
|
274 | 275 | Q_ASSERT(animation); |
|
275 | animation->updateValues(layout); | |
|
276 | // animation->updateValues(layout); | |
|
277 | animation->setDuration(duration); | |
|
278 | animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); | |
|
279 | animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); | |
|
280 | QTimer::singleShot(0,animation,SLOT(start())); | |
|
276 | 281 | } |
|
277 | 282 | |
|
278 | 283 |
@@ -43,7 +43,7 public: | |||
|
43 | 43 | void updateLayout(PieChartItem* item, const PieLayout &layout); |
|
44 | 44 | void updateLayout(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData); |
|
45 | 45 | |
|
46 |
void updateLayout(BarChartItem* item, const |
|
|
46 | void updateLayout(BarChartItem* item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); | |
|
47 | 47 | |
|
48 | 48 | void setState(State state,const QPointF& point = QPointF()); |
|
49 | 49 |
@@ -20,7 +20,7 BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |||
|
20 | 20 | mSeries(series) |
|
21 | 21 | { |
|
22 | 22 | connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString))); |
|
23 | connect(series, SIGNAL(updatedBars()), this, SLOT(layoutChanged())); | |
|
23 | connect(series, SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); | |
|
24 | 24 | //TODO: connect(series,SIGNAL("position or size has changed"), this, SLOT(handleLayoutChanged())); |
|
25 | 25 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); |
|
26 | 26 | setZValue(ChartPresenter::BarSeriesZValue); |
@@ -59,6 +59,7 void BarChartItem::dataChanged() | |||
|
59 | 59 | |
|
60 | 60 | mBars.clear(); |
|
61 | 61 | mFloatingValues.clear(); |
|
62 | mLayout.clear(); | |
|
62 | 63 | |
|
63 | 64 | // Create new graphic items for bars |
|
64 | 65 | for (int c=0; c<mSeries->categoryCount(); c++) { |
@@ -72,6 +73,7 void BarChartItem::dataChanged() | |||
|
72 | 73 | connect(bar,SIGNAL(rightClicked(QString)),set,SIGNAL(rightClicked(QString))); |
|
73 | 74 | connect(bar,SIGNAL(hoverEntered(QPoint)),set,SLOT(barHoverEnterEvent(QPoint))); |
|
74 | 75 | connect(bar,SIGNAL(hoverLeaved()),set,SLOT(barHoverLeaveEvent())); |
|
76 | mLayout.append(QRectF(0,0,0,0)); | |
|
75 | 77 | } |
|
76 | 78 | } |
|
77 | 79 | |
@@ -86,9 +88,11 void BarChartItem::dataChanged() | |||
|
86 | 88 | } |
|
87 | 89 | } |
|
88 | 90 | } |
|
89 | ||
|
91 | /* | |
|
90 | 92 | void BarChartItem::layoutChanged() |
|
91 | 93 |
|
|
94 | qDebug() << "Deprecated BarChartItem::layoutChanged called. aborting"; | |
|
95 | return; | |
|
92 | 96 | // Scale bars to new layout |
|
93 | 97 | // Layout for bars: |
|
94 | 98 | if (mSeries->barsetCount() <= 0) { |
@@ -118,6 +122,8 void BarChartItem::layoutChanged() | |||
|
118 | 122 | qreal categoryWidth = width/categoryCount; |
|
119 | 123 | qreal barWidth = categoryWidth / (setCount+1); |
|
120 | 124 |
|
|
125 | BarLayout layout; | |
|
126 | ||
|
121 | 127 | int itemIndex(0); |
|
122 | 128 | for (int category=0; category < categoryCount; category++) { |
|
123 | 129 | qreal xPos = categoryWidth * category + barWidth/2; |
@@ -126,11 +132,18 void BarChartItem::layoutChanged() | |||
|
126 | 132 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
127 | 133 | Bar* bar = mBars.at(itemIndex); |
|
128 | 134 |
|
|
135 | QRectF rect(xPos,yPos-barHeight,mBarWidth,barHeight); | |
|
136 | layout.insert(bar,rect); | |
|
129 | 137 | // TODO: width settable per bar? |
|
130 | 138 | bar->setRect(xPos, yPos-barHeight,barWidth, barHeight); |
|
131 | 139 | bar->setPen(mSeries->barsetAt(set)->pen()); |
|
132 | 140 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
133 | 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); | |
|
134 | 147 | itemIndex++; |
|
135 | 148 | xPos += barWidth; |
|
136 | 149 | } |
@@ -160,32 +173,106 void BarChartItem::layoutChanged() | |||
|
160 | 173 | xPos += barWidth; |
|
161 | 174 | } |
|
162 | 175 | } |
|
163 | update(); | |
|
176 | // update(); | |
|
164 | 177 |
|
|
165 | ||
|
166 |
|
|
|
178 | */ | |
|
179 | QVector<QRectF> BarChartItem::calculateLayout() | |
|
167 | 180 | { |
|
181 | // layoutChanged(); | |
|
182 | /* | |
|
168 | 183 | BarLayout layout; |
|
169 | 184 | foreach(Bar* bar, mBars) { |
|
170 | 185 | layout.insert(bar,bar->boundingRect()); |
|
171 | 186 | } |
|
187 | */ | |
|
188 | QVector<QRectF> layout; | |
|
189 | ||
|
190 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
|
191 | int categoryCount = mSeries->categoryCount(); | |
|
192 | int setCount = mSeries->barsetCount(); | |
|
193 | ||
|
194 | qreal tW = mWidth; | |
|
195 | qreal tH = mHeight; | |
|
196 | qreal tM = mSeries->max(); | |
|
197 | ||
|
198 | // Domain: | |
|
199 | if (mDomainMaxY > tM) { | |
|
200 | tM = mDomainMaxY; | |
|
201 | } | |
|
202 | ||
|
203 | qreal scale = (tH/tM); | |
|
204 | qreal tC = categoryCount + 1; | |
|
205 | qreal categoryWidth = tW/tC; | |
|
206 | mBarWidth = categoryWidth / (setCount+1); | |
|
207 | ||
|
208 | int itemIndex(0); | |
|
209 | for (int category=0; category < categoryCount; category++) { | |
|
210 | qreal xPos = categoryWidth * category + categoryWidth /2 + mBarWidth/2; | |
|
211 | qreal yPos = mHeight; | |
|
212 | for (int set = 0; set < setCount; set++) { | |
|
213 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
|
214 | Bar* bar = mBars.at(itemIndex); | |
|
215 | ||
|
216 | QRectF rect(xPos,yPos-barHeight,mBarWidth,barHeight); | |
|
217 | //layout.insert(bar,rect); | |
|
218 | layout.append(rect); | |
|
219 | // TODO: width settable per bar? | |
|
220 | // bar->resize(mBarWidth, barHeight); | |
|
221 | // layout.insert(bar,QSizeF(mBarWidth,barHeight)); | |
|
222 | bar->setPen(mSeries->barsetAt(set)->pen()); | |
|
223 | bar->setBrush(mSeries->barsetAt(set)->brush()); | |
|
224 | // bar->setPos(xPos, yPos-barHeight); | |
|
225 | itemIndex++; | |
|
226 | xPos += mBarWidth; | |
|
227 | } | |
|
228 | } | |
|
229 | ||
|
230 | // Position floating values | |
|
231 | itemIndex = 0; | |
|
232 | for (int category=0; category < mSeries->categoryCount(); category++) { | |
|
233 | qreal xPos = categoryWidth * category + categoryWidth/2 + mBarWidth; | |
|
234 | qreal yPos = mHeight; | |
|
235 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
|
236 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
|
237 | BarValue* value = mFloatingValues.at(itemIndex); | |
|
238 | ||
|
239 | QBarSet* barSet = mSeries->barsetAt(set); | |
|
240 | value->resize(100,50); // TODO: proper layout for this. | |
|
241 | value->setPos(xPos, yPos-barHeight/2); | |
|
242 | value->setPen(barSet->floatingValuePen()); | |
|
243 | ||
|
244 | if (mSeries->valueAt(set,category) != 0) { | |
|
245 | value->setValueString(QString::number(mSeries->valueAt(set,category))); | |
|
246 | } else { | |
|
247 | value->setValueString(QString("")); | |
|
248 | } | |
|
249 | ||
|
250 | itemIndex++; | |
|
251 | xPos += mBarWidth; | |
|
252 | } | |
|
253 | } | |
|
172 | 254 | |
|
173 | 255 | return layout; |
|
174 | 256 | } |
|
175 | 257 | |
|
176 |
void BarChartItem::applyLayout(const |
|
|
258 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) | |
|
177 | 259 | { |
|
178 | 260 | if (animator()) |
|
179 | animator()->updateLayout(this, layout); | |
|
261 | animator()->updateLayout(this, mLayout, layout); | |
|
180 | 262 | else |
|
181 | 263 | setLayout(layout); |
|
182 | 264 | } |
|
183 | 265 | |
|
184 |
void BarChartItem::setLayout(const |
|
|
266 | void BarChartItem::setLayout(const QVector<QRectF> &layout) | |
|
185 | 267 | { |
|
186 | foreach (Bar *bar, layout.keys()) { | |
|
187 | bar->setRect(layout.value(bar)); | |
|
268 | mLayout = layout; | |
|
269 | ||
|
270 | 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 | mBars.at(i)->setRect(layout.at(i)); | |
|
188 | 274 | } |
|
275 | ||
|
189 | 276 | update(); |
|
190 | 277 | } |
|
191 | 278 | |
@@ -218,7 +305,7 void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal | |||
|
218 | 305 | mDomainMaxX = maxX; |
|
219 | 306 | mDomainMinY = minY; |
|
220 | 307 | mDomainMaxY = maxY; |
|
221 | layoutChanged(); | |
|
308 | handleLayoutChanged(); | |
|
222 | 309 | |
|
223 | 310 | /* |
|
224 | 311 | int count = mSeries->categoryCount(); |
@@ -249,7 +336,8 void BarChartItem::handleGeometryChanged(const QRectF& rect) | |||
|
249 | 336 | |
|
250 | 337 | void BarChartItem::handleLayoutChanged() |
|
251 | 338 | { |
|
252 | BarLayout layout = calculateLayout(); | |
|
339 | qDebug() << "BarChartItem::handleLayoutChanged"; | |
|
340 | QVector<QRectF> layout = calculateLayout(); | |
|
253 | 341 | applyLayout(layout); |
|
254 | 342 | update(); |
|
255 | 343 | } |
@@ -14,7 +14,7 class BarValue; | |||
|
14 | 14 | class QChartAxisCategories; |
|
15 | 15 | class QChart; |
|
16 | 16 | |
|
17 |
typedef Q |
|
|
17 | //typedef QVector<QRectF> BarLayout; | |
|
18 | 18 | |
|
19 | 19 | class BarChartItem : public ChartItem |
|
20 | 20 | { |
@@ -34,12 +34,13 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 | |
|
37 | //virtual void layoutChanged(); // layout has changed -> need to recalculate bar sizes | |
|
38 | 38 | |
|
39 | 39 | public: |
|
40 |
|
|
|
41 |
void applyLayout(const |
|
|
42 |
void setLayout(const |
|
|
40 | QVector<QRectF> calculateLayout(); | |
|
41 | void applyLayout(const QVector<QRectF> &layout); | |
|
42 | void setLayout(const QVector<QRectF> &layout); | |
|
43 | void updateLayout(const QVector<QRectF> &layout); | |
|
43 | 44 | |
|
44 | 45 | QRectF geometry() const { return m_rect;} |
|
45 | 46 | |
@@ -65,6 +66,7 protected: | |||
|
65 | 66 | |
|
66 | 67 | QRectF m_rect; |
|
67 | 68 | bool mLayoutSet; // True, if component has been laid out. |
|
69 | QVector<QRectF> mLayout; | |
|
68 | 70 | |
|
69 | 71 | // Not owned. |
|
70 | 72 | QBarSeries* mSeries; |
@@ -51,10 +51,12 QBarSeries::QBarSeries(QStringList categories, QObject *parent) | |||
|
51 | 51 | */ |
|
52 | 52 | void QBarSeries::addBarSet(QBarSet *set) |
|
53 | 53 | { |
|
54 | qDebug() << "add bar set"; | |
|
54 | 55 | mModel->addBarSet(set); |
|
55 | 56 | connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); |
|
56 | 57 | connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); |
|
57 | 58 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); |
|
59 | emit updatedBars(); | |
|
58 | 60 | } |
|
59 | 61 | |
|
60 | 62 | /*! |
@@ -67,6 +69,7 void QBarSeries::removeBarSet(QBarSet *set) | |||
|
67 | 69 | disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); |
|
68 | 70 | disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); |
|
69 | 71 | mModel->removeBarSet(set); |
|
72 | emit updatedBars(); | |
|
70 | 73 | } |
|
71 | 74 | |
|
72 | 75 | void QBarSeries::insertBarSet(int i, QBarSet *set) |
General Comments 0
You need to be logged in to leave comments.
Login now