##// END OF EJS Templates
fix to baranimations leaving crap on screen with negative bars
sauimone -
r1824:4fa1dedc5aa7
parent child
Show More
@@ -1,93 +1,94
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QApplication>
21 #include <QApplication>
22 #include <QMainWindow>
22 #include <QMainWindow>
23 #include <QChartView>
23 #include <QChartView>
24 #include <QBarSeries>
24 #include <QBarSeries>
25 #include <QBarSet>
25 #include <QBarSet>
26 #include <QLegend>
26 #include <QLegend>
27 #include <QBarCategoryAxis>
27 #include <QBarCategoryAxis>
28 #include <QHorizontalBarSeries>
28 #include <QHorizontalBarSeries>
29
29
30 QTCOMMERCIALCHART_USE_NAMESPACE
30 QTCOMMERCIALCHART_USE_NAMESPACE
31
31
32 int main(int argc, char *argv[])
32 int main(int argc, char *argv[])
33 {
33 {
34 QApplication a(argc, argv);
34 QApplication a(argc, argv);
35
35
36 //![1]
36 //![1]
37 QBarSet *male = new QBarSet("Male");
37 QBarSet *male = new QBarSet("Male");
38 QBarSet *female = new QBarSet("Female");
38 QBarSet *female = new QBarSet("Female");
39
39
40 // From wikipedia
40 // From wikipedia
41 *male << -145596 << -149894 << -167327 << -164118 << -170710 << -169408 << -158395 << -176975 << -191803 << -191198 << -196815
41 *male << -145596 << -149894 << -167327 << -164118 << -170710 << -169408 << -158395 << -176975 << -191803 << -191198 << -196815
42 << -207826 << -145517 << -113204 << -90986 << -70909 << -40013 << -15887 << -5769;
42 << -207826 << -145517 << -113204 << -90986 << -70909 << -40013 << -15887 << -5769;
43
43
44 *female << 139353 << 143522 << 161212 << 156824 << 163226 << 161766 << 150595 << 170779 << 185979 << 187897 << 196158
44 *female << 139353 << 143522 << 161212 << 156824 << 163226 << 161766 << 150595 << 170779 << 185979 << 187897 << 196158
45 << 209062 << 152460 << 129230 << 114778 << 109611 << 83845 << 44605 << 22328;
45 << 209062 << 152460 << 129230 << 114778 << 109611 << 83845 << 44605 << 22328;
46
46
47 //![1]
47 //![1]
48
48
49 //![2]
49 //![2]
50 QHorizontalBarSeries *series = new QHorizontalBarSeries();
50 QHorizontalBarSeries *series = new QHorizontalBarSeries();
51 series->append(male);
51 series->append(male);
52 series->append(female);
52 series->append(female);
53 series->setBarWidth(0.5);
53 series->setBarWidth(0.5);
54 series->setGrouping(false);
54 series->setGrouping(false);
55 //![2]
55 //![2]
56
56
57 //![3]
57 //![3]
58 QChart* chart = new QChart();
58 QChart* chart = new QChart();
59 chart->addSeries(series);
59 chart->addSeries(series);
60 chart->setTitle("Population of Finland in 2005 by age group");
60 chart->setTitle("Population of Finland in 2005 by age group");
61 chart->createDefaultAxes();
61 chart->createDefaultAxes();
62 chart->setAnimationOptions(QChart::SeriesAnimations);
62 chart->setAnimationOptions(QChart::SeriesAnimations);
63 //![3]
63 //![3]
64
64
65 //![4]
65 //![4]
66 QStringList categories;
66 QStringList categories;
67 categories << "0-4" << "5-9" << "10-14" << "15-19" << "20-24" << "25-29" << "30-34" << "35-39" << "40-44" << "45-49"
67 categories << "0-4" << "5-9" << "10-14" << "15-19" << "20-24" << "25-29" << "30-34" << "35-39" << "40-44" << "45-49"
68 << "50-54" << "55-59" << "60-64" << "65-69" << "70-74" << "75-79" << "80-84" << "85-89" << "90-";
68 << "50-54" << "55-59" << "60-64" << "65-69" << "70-74" << "75-79" << "80-84" << "85-89" << "90-";
69
69
70 QBarCategoryAxis* axis = new QBarCategoryAxis();
70 QBarCategoryAxis* axis = new QBarCategoryAxis();
71 axis->append(categories);
71 axis->append(categories);
72 chart->setAxisY(axis,series);
72 chart->setAxisY(axis,series);
73 chart->axisX(series)->setRange(-210000,210000);
73 //![4]
74 //![4]
74
75
75 //![5]
76 //![5]
76 chart->legend()->setVisible(true);
77 chart->legend()->setVisible(true);
77 chart->legend()->setAlignment(Qt::AlignBottom);
78 chart->legend()->setAlignment(Qt::AlignBottom);
78 //![5]
79 //![5]
79
80
80 //![6]
81 //![6]
81 QChartView* chartView = new QChartView(chart);
82 QChartView* chartView = new QChartView(chart);
82 chartView->setRenderHint(QPainter::Antialiasing);
83 chartView->setRenderHint(QPainter::Antialiasing);
83 //![6]
84 //![6]
84
85
85 //![7]
86 //![7]
86 QMainWindow window;
87 QMainWindow window;
87 window.setCentralWidget(chartView);
88 window.setCentralWidget(chartView);
88 window.resize(400, 800);
89 window.resize(400, 800);
89 window.show();
90 window.show();
90 //![7]
91 //![7]
91
92
92 return a.exec();
93 return a.exec();
93 }
94 }
@@ -1,61 +1,61
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "baranimation_p.h"
21 #include "baranimation_p.h"
22 #include "abstractbarchartitem_p.h"
22 #include "abstractbarchartitem_p.h"
23 #include <QTimer>
23 #include <QTimer>
24
24
25 Q_DECLARE_METATYPE(QVector<QRectF>)
25 Q_DECLARE_METATYPE(QVector<QRectF>)
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 BarAnimation::BarAnimation(AbstractBarChartItem *item)
29 BarAnimation::BarAnimation(AbstractBarChartItem *item)
30 :AbstractBarAnimation(item)
30 :AbstractBarAnimation(item)
31 {
31 {
32
32
33 }
33 }
34
34
35 BarAnimation::~BarAnimation()
35 BarAnimation::~BarAnimation()
36 {
36 {
37 }
37 }
38
38
39 QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
39 QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
40 {
40 {
41 QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from);
41 QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from);
42 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
42 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
43 QVector<QRectF> result;
43 QVector<QRectF> result;
44
44
45 Q_ASSERT(startVector.count() == endVector.count());
45 Q_ASSERT(startVector.count() == endVector.count());
46
46
47 for(int i = 0; i < startVector.count(); i++) {
47 for(int i = 0; i < startVector.count(); i++) {
48 qreal w = endVector[i].width();
48 qreal w = endVector[i].width();
49 qreal h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress);
49 qreal h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress);
50 qreal x = endVector[i].topLeft().x();
50 qreal x = endVector[i].topLeft().x();
51 qreal y = endVector[i].topLeft().y() + endVector[i].height() - h;
51 qreal y = endVector[i].topLeft().y() + endVector[i].height() - h;
52
52
53 QRectF value(x,y,w,h);
53 QRectF value(x,y,w,h);
54 result << value;
54 result << value.normalized();
55 }
55 }
56 return qVariantFromValue(result);
56 return qVariantFromValue(result);
57 }
57 }
58
58
59 #include "moc_baranimation_p.cpp"
59 #include "moc_baranimation_p.cpp"
60
60
61 QTCOMMERCIALCHART_END_NAMESPACE
61 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,62 +1,62
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "horizontalbaranimation_p.h"
21 #include "horizontalbaranimation_p.h"
22 #include "abstractbarchartitem_p.h"
22 #include "abstractbarchartitem_p.h"
23 #include <QTimer>
23 #include <QTimer>
24
24
25 Q_DECLARE_METATYPE(QVector<QRectF>)
25 Q_DECLARE_METATYPE(QVector<QRectF>)
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 HorizontalBarAnimation::HorizontalBarAnimation(AbstractBarChartItem *item) :
29 HorizontalBarAnimation::HorizontalBarAnimation(AbstractBarChartItem *item) :
30 AbstractBarAnimation(item)
30 AbstractBarAnimation(item)
31 {
31 {
32 }
32 }
33
33
34 HorizontalBarAnimation::~HorizontalBarAnimation()
34 HorizontalBarAnimation::~HorizontalBarAnimation()
35 {
35 {
36
36
37 }
37 }
38
38
39
39
40 QVariant HorizontalBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
40 QVariant HorizontalBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
41 {
41 {
42 QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from);
42 QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from);
43 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
43 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
44 QVector<QRectF> result;
44 QVector<QRectF> result;
45
45
46 Q_ASSERT(startVector.count() == endVector.count());
46 Q_ASSERT(startVector.count() == endVector.count());
47
47
48 for(int i = 0; i < startVector.count(); i++) {
48 for(int i = 0; i < startVector.count(); i++) {
49 qreal h = endVector[i].height();
49 qreal h = endVector[i].height();
50 qreal w = startVector[i].width() + ((endVector[i].width() - startVector[i].width()) * progress);
50 qreal w = startVector[i].width() + ((endVector[i].width() - startVector[i].width()) * progress);
51 qreal x = endVector[i].left();
51 qreal x = endVector[i].left();
52 qreal y = endVector[i].top();
52 qreal y = endVector[i].top();
53
53
54 QRectF value(x,y,w,h);
54 QRectF value(x,y,w,h);
55 result << value;
55 result << value.normalized();
56 }
56 }
57 return qVariantFromValue(result);
57 return qVariantFromValue(result);
58 }
58 }
59
59
60 #include "moc_horizontalbaranimation_p.cpp"
60 #include "moc_horizontalbaranimation_p.cpp"
61
61
62 QTCOMMERCIALCHART_END_NAMESPACE
62 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,64 +1,64
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "horizontalpercentbaranimation_p.h"
21 #include "horizontalpercentbaranimation_p.h"
22 #include "abstractbarchartitem_p.h"
22 #include "abstractbarchartitem_p.h"
23 #include <QTimer>
23 #include <QTimer>
24
24
25 Q_DECLARE_METATYPE(QVector<QRectF>)
25 Q_DECLARE_METATYPE(QVector<QRectF>)
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 HorizontalPercentBarAnimation::HorizontalPercentBarAnimation(AbstractBarChartItem *item) :
29 HorizontalPercentBarAnimation::HorizontalPercentBarAnimation(AbstractBarChartItem *item) :
30 AbstractBarAnimation(item)
30 AbstractBarAnimation(item)
31 {
31 {
32 }
32 }
33
33
34 HorizontalPercentBarAnimation::~HorizontalPercentBarAnimation()
34 HorizontalPercentBarAnimation::~HorizontalPercentBarAnimation()
35 {
35 {
36
36
37 }
37 }
38
38
39
39
40 QVariant HorizontalPercentBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
40 QVariant HorizontalPercentBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
41 {
41 {
42 QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from);
42 QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from);
43 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
43 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
44 QVector<QRectF> result;
44 QVector<QRectF> result;
45
45
46 Q_ASSERT(startVector.count() == endVector.count());
46 Q_ASSERT(startVector.count() == endVector.count());
47
47
48 qreal xAxis = m_item->geometry().x();
48 qreal xAxis = m_item->geometry().x();
49
49
50 for(int i = 0; i < startVector.count(); i++) {
50 for(int i = 0; i < startVector.count(); i++) {
51 qreal h = endVector[i].height();
51 qreal h = endVector[i].height();
52 qreal w = endVector[i].width() * progress;
52 qreal w = endVector[i].width() * progress;
53 qreal x = xAxis + ((endVector[i].left() - xAxis) * progress);
53 qreal x = xAxis + ((endVector[i].left() - xAxis) * progress);
54 qreal y = endVector[i].top();
54 qreal y = endVector[i].top();
55
55
56 QRectF value(x,y,w,h);
56 QRectF value(x,y,w,h);
57 result << value;
57 result << value.normalized();
58 }
58 }
59 return qVariantFromValue(result);
59 return qVariantFromValue(result);
60 }
60 }
61
61
62 #include "moc_horizontalpercentbaranimation_p.cpp"
62 #include "moc_horizontalpercentbaranimation_p.cpp"
63
63
64 QTCOMMERCIALCHART_END_NAMESPACE
64 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,64 +1,64
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "horizontalstackedbaranimation_p.h"
21 #include "horizontalstackedbaranimation_p.h"
22 #include "abstractbarchartitem_p.h"
22 #include "abstractbarchartitem_p.h"
23 #include <QTimer>
23 #include <QTimer>
24
24
25 Q_DECLARE_METATYPE(QVector<QRectF>)
25 Q_DECLARE_METATYPE(QVector<QRectF>)
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 HorizontalStackedBarAnimation::HorizontalStackedBarAnimation(AbstractBarChartItem *item) :
29 HorizontalStackedBarAnimation::HorizontalStackedBarAnimation(AbstractBarChartItem *item) :
30 AbstractBarAnimation(item)
30 AbstractBarAnimation(item)
31 {
31 {
32 }
32 }
33
33
34 HorizontalStackedBarAnimation::~HorizontalStackedBarAnimation()
34 HorizontalStackedBarAnimation::~HorizontalStackedBarAnimation()
35 {
35 {
36
36
37 }
37 }
38
38
39
39
40 QVariant HorizontalStackedBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
40 QVariant HorizontalStackedBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
41 {
41 {
42 QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from);
42 QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from);
43 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
43 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
44 QVector<QRectF> result;
44 QVector<QRectF> result;
45
45
46 Q_ASSERT(startVector.count() == endVector.count());
46 Q_ASSERT(startVector.count() == endVector.count());
47
47
48 qreal xAxis = m_item->geometry().x();
48 qreal xAxis = m_item->geometry().x();
49
49
50 for(int i = 0; i < startVector.count(); i++) {
50 for(int i = 0; i < startVector.count(); i++) {
51 qreal h = endVector[i].height();
51 qreal h = endVector[i].height();
52 qreal w = endVector[i].width() * progress;
52 qreal w = endVector[i].width() * progress;
53 qreal x = xAxis + ((endVector[i].left() - xAxis) * progress);
53 qreal x = xAxis + ((endVector[i].left() - xAxis) * progress);
54 qreal y = endVector[i].top();
54 qreal y = endVector[i].top();
55
55
56 QRectF value(x,y,w,h);
56 QRectF value(x,y,w,h);
57 result << value;
57 result << value.normalized();
58 }
58 }
59 return qVariantFromValue(result);
59 return qVariantFromValue(result);
60 }
60 }
61
61
62 #include "moc_horizontalstackedbaranimation_p.cpp"
62 #include "moc_horizontalstackedbaranimation_p.cpp"
63
63
64 QTCOMMERCIALCHART_END_NAMESPACE
64 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,64 +1,64
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "percentbaranimation_p.h"
21 #include "percentbaranimation_p.h"
22 #include "percentbarchartitem_p.h"
22 #include "percentbarchartitem_p.h"
23 #include <QTimer>
23 #include <QTimer>
24
24
25 Q_DECLARE_METATYPE(QVector<QRectF>)
25 Q_DECLARE_METATYPE(QVector<QRectF>)
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 PercentBarAnimation::PercentBarAnimation(PercentBarChartItem *item)
29 PercentBarAnimation::PercentBarAnimation(PercentBarChartItem *item)
30 :AbstractBarAnimation(item)
30 :AbstractBarAnimation(item)
31 {
31 {
32 setDuration(ChartAnimationDuration);
32 setDuration(ChartAnimationDuration);
33 setEasingCurve(QEasingCurve::OutQuart);
33 setEasingCurve(QEasingCurve::OutQuart);
34 }
34 }
35
35
36 PercentBarAnimation::~PercentBarAnimation()
36 PercentBarAnimation::~PercentBarAnimation()
37 {
37 {
38 }
38 }
39
39
40 QVariant PercentBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
40 QVariant PercentBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
41 {
41 {
42 QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from);
42 QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from);
43 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
43 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
44 QVector<QRectF> result;
44 QVector<QRectF> result;
45
45
46 Q_ASSERT(startVector.count() == endVector.count());
46 Q_ASSERT(startVector.count() == endVector.count());
47
47
48 qreal yAxis = m_item->geometry().height() + m_item->geometry().y();
48 qreal yAxis = m_item->geometry().height() + m_item->geometry().y();
49
49
50 for(int i = 0; i < startVector.count(); i++) {
50 for(int i = 0; i < startVector.count(); i++) {
51 qreal w = endVector[i].width();
51 qreal w = endVector[i].width();
52 qreal h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress);
52 qreal h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress);
53 qreal x = endVector[i].topLeft().x();
53 qreal x = endVector[i].topLeft().x();
54 qreal y = yAxis + ((endVector[i].topLeft().y() - yAxis) * progress);
54 qreal y = yAxis + ((endVector[i].topLeft().y() - yAxis) * progress);
55
55
56 QRectF value(x,y,w,h);
56 QRectF value(x,y,w,h);
57 result << value;
57 result << value.normalized();
58 }
58 }
59 return qVariantFromValue(result);
59 return qVariantFromValue(result);
60 }
60 }
61
61
62 #include "moc_percentbaranimation_p.cpp"
62 #include "moc_percentbaranimation_p.cpp"
63
63
64 QTCOMMERCIALCHART_END_NAMESPACE
64 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,63 +1,63
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "stackedbaranimation_p.h"
21 #include "stackedbaranimation_p.h"
22 #include "stackedbarchartitem_p.h"
22 #include "stackedbarchartitem_p.h"
23 #include <QTimer>
23 #include <QTimer>
24
24
25 Q_DECLARE_METATYPE(QVector<QRectF>)
25 Q_DECLARE_METATYPE(QVector<QRectF>)
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 StackedBarAnimation::StackedBarAnimation(StackedBarChartItem *item)
29 StackedBarAnimation::StackedBarAnimation(StackedBarChartItem *item)
30 :AbstractBarAnimation(item)
30 :AbstractBarAnimation(item)
31 {
31 {
32 setEasingCurve(QEasingCurve::OutQuart);
32 setEasingCurve(QEasingCurve::OutQuart);
33 }
33 }
34
34
35 StackedBarAnimation::~StackedBarAnimation()
35 StackedBarAnimation::~StackedBarAnimation()
36 {
36 {
37 }
37 }
38
38
39 QVariant StackedBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
39 QVariant StackedBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
40 {
40 {
41 QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from);
41 QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from);
42 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
42 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
43 QVector<QRectF> result;
43 QVector<QRectF> result;
44
44
45 Q_ASSERT(startVector.count() == endVector.count());
45 Q_ASSERT(startVector.count() == endVector.count());
46
46
47 qreal yAxis = m_item->geometry().height() + m_item->geometry().y();
47 qreal yAxis = m_item->geometry().height() + m_item->geometry().y();
48
48
49 for(int i = 0; i < startVector.count(); i++) {
49 for(int i = 0; i < startVector.count(); i++) {
50 qreal w = endVector[i].width();
50 qreal w = endVector[i].width();
51 qreal h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress);
51 qreal h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress);
52 qreal x = endVector[i].topLeft().x();
52 qreal x = endVector[i].topLeft().x();
53 qreal y = yAxis + ((endVector[i].topLeft().y() - yAxis) * progress);
53 qreal y = yAxis + ((endVector[i].topLeft().y() - yAxis) * progress);
54
54
55 QRectF value(x,y,w,h);
55 QRectF value(x,y,w,h);
56 result << value;
56 result << value.normalized();
57 }
57 }
58 return qVariantFromValue(result);
58 return qVariantFromValue(result);
59 }
59 }
60
60
61 #include "moc_stackedbaranimation_p.cpp"
61 #include "moc_stackedbaranimation_p.cpp"
62
62
63 QTCOMMERCIALCHART_END_NAMESPACE
63 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now