@@ -1,94 +1,95 | |||||
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 <QBarCategoriesAxis> |
|
27 | #include <QBarCategoriesAxis> | |
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 *set0 = new QBarSet("Jane"); |
|
37 | QBarSet *set0 = new QBarSet("Jane"); | |
38 | QBarSet *set1 = new QBarSet("John"); |
|
38 | QBarSet *set1 = new QBarSet("John"); | |
39 | QBarSet *set2 = new QBarSet("Axel"); |
|
39 | QBarSet *set2 = new QBarSet("Axel"); | |
40 | QBarSet *set3 = new QBarSet("Mary"); |
|
40 | QBarSet *set3 = new QBarSet("Mary"); | |
41 | QBarSet *set4 = new QBarSet("Samantha"); |
|
41 | QBarSet *set4 = new QBarSet("Samantha"); | |
42 |
|
42 | |||
43 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
43 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
44 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
44 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
45 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
45 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
46 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
46 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
47 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
47 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
48 | //![1] |
|
48 | //![1] | |
49 |
|
49 | |||
50 | //![2] |
|
50 | //![2] | |
51 | QHorizontalBarSeries *series = new QHorizontalBarSeries(); |
|
51 | QHorizontalBarSeries *series = new QHorizontalBarSeries(); | |
52 | series->append(set0); |
|
52 | series->append(set0); | |
53 | series->append(set1); |
|
53 | series->append(set1); | |
54 | series->append(set2); |
|
54 | series->append(set2); | |
55 | series->append(set3); |
|
55 | series->append(set3); | |
56 | series->append(set4); |
|
56 | series->append(set4); | |
57 |
|
57 | |||
58 | //![2] |
|
58 | //![2] | |
59 |
|
59 | |||
60 | //![3] |
|
60 | //![3] | |
61 | QChart* chart = new QChart(); |
|
61 | QChart* chart = new QChart(); | |
62 | chart->addSeries(series); |
|
62 | chart->addSeries(series); | |
63 | chart->setTitle("Simple horizontal barchart example"); |
|
63 | chart->setTitle("Simple horizontal barchart example"); | |
64 | chart->createDefaultAxes(); |
|
64 | chart->createDefaultAxes(); | |
|
65 | chart->setAnimationOptions(QChart::SeriesAnimations); | |||
65 | //![3] |
|
66 | //![3] | |
66 |
|
67 | |||
67 | //![4] |
|
68 | //![4] | |
68 | QStringList categories; |
|
69 | QStringList categories; | |
69 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
70 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
70 | QBarCategoriesAxis* axis = new QBarCategoriesAxis(); |
|
71 | QBarCategoriesAxis* axis = new QBarCategoriesAxis(); | |
71 | axis->append(categories); |
|
72 | axis->append(categories); | |
72 | chart->createDefaultAxes(); |
|
73 | chart->createDefaultAxes(); | |
73 | chart->setAxisY(axis,series); |
|
74 | chart->setAxisY(axis,series); | |
74 | //![4] |
|
75 | //![4] | |
75 |
|
76 | |||
76 | //![5] |
|
77 | //![5] | |
77 | chart->legend()->setVisible(true); |
|
78 | chart->legend()->setVisible(true); | |
78 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
79 | chart->legend()->setAlignment(Qt::AlignBottom); | |
79 | //![5] |
|
80 | //![5] | |
80 |
|
81 | |||
81 | //![6] |
|
82 | //![6] | |
82 | QChartView* chartView = new QChartView(chart); |
|
83 | QChartView* chartView = new QChartView(chart); | |
83 | chartView->setRenderHint(QPainter::Antialiasing); |
|
84 | chartView->setRenderHint(QPainter::Antialiasing); | |
84 | //![6] |
|
85 | //![6] | |
85 |
|
86 | |||
86 | //![7] |
|
87 | //![7] | |
87 | QMainWindow window; |
|
88 | QMainWindow window; | |
88 | window.setCentralWidget(chartView); |
|
89 | window.setCentralWidget(chartView); | |
89 | window.resize(400, 300); |
|
90 | window.resize(400, 300); | |
90 | window.show(); |
|
91 | window.show(); | |
91 | //![7] |
|
92 | //![7] | |
92 |
|
93 | |||
93 | return a.exec(); |
|
94 | return a.exec(); | |
94 | } |
|
95 | } |
@@ -1,51 +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 | // TODO: |
|
42 | QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from); | |
43 | Q_UNUSED(from); |
|
43 | QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to); | |
44 | Q_UNUSED(to); |
|
44 | QVector<QRectF> result; | |
45 | Q_UNUSED(progress); |
|
45 | ||
46 | return to; |
|
46 | Q_ASSERT(startVector.count() == endVector.count()); | |
|
47 | ||||
|
48 | for(int i = 0; i < startVector.count(); i++) { | |||
|
49 | qreal h = endVector[i].height(); | |||
|
50 | qreal w = startVector[i].width() + ((endVector[i].width() - startVector[i].width()) * progress); | |||
|
51 | qreal x = endVector[i].topLeft().x(); | |||
|
52 | qreal y = endVector[i].topLeft().y(); | |||
|
53 | ||||
|
54 | QRectF value(x,y,w,h); | |||
|
55 | result << value; | |||
|
56 | } | |||
|
57 | return qVariantFromValue(result); | |||
47 | } |
|
58 | } | |
48 |
|
59 | |||
49 | #include "moc_horizontalbaranimation_p.cpp" |
|
60 | #include "moc_horizontalbaranimation_p.cpp" | |
50 |
|
61 | |||
51 | QTCOMMERCIALCHART_END_NAMESPACE |
|
62 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now