##// END OF EJS Templates
Fix deprecation errors from Qt5
Jani Honkonen -
r2241:9223452f638c
parent child
Show More
@@ -1,100 +1,100
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 #include "brushtool.h"
20 #include "brushtool.h"
21 #include <QPushButton>
21 #include <QPushButton>
22 #include <QFormLayout>
22 #include <QFormLayout>
23 #include <QComboBox>
23 #include <QComboBox>
24 #include <QColorDialog>
24 #include <QColorDialog>
25
25
26 BrushTool::BrushTool(QString title, QWidget *parent)
26 BrushTool::BrushTool(QString title, QWidget *parent)
27 : QWidget(parent)
27 : QWidget(parent)
28 {
28 {
29 setWindowTitle(title);
29 setWindowTitle(title);
30 setWindowFlags(Qt::Tool);
30 setWindowFlags(Qt::Tool);
31
31
32 m_colorButton = new QPushButton();
32 m_colorButton = new QPushButton();
33 m_styleCombo = new QComboBox();
33 m_styleCombo = new QComboBox();
34 m_styleCombo->addItem("Nobrush", Qt::NoBrush);
34 m_styleCombo->addItem("Nobrush", (int) Qt::NoBrush);
35 m_styleCombo->addItem("Solidpattern", Qt::SolidPattern);
35 m_styleCombo->addItem("Solidpattern", (int) Qt::SolidPattern);
36 m_styleCombo->addItem("Dense1pattern", Qt::Dense1Pattern);
36 m_styleCombo->addItem("Dense1pattern", (int) Qt::Dense1Pattern);
37 m_styleCombo->addItem("Dense2attern", Qt::Dense2Pattern);
37 m_styleCombo->addItem("Dense2attern", (int) Qt::Dense2Pattern);
38 m_styleCombo->addItem("Dense3Pattern", Qt::Dense3Pattern);
38 m_styleCombo->addItem("Dense3Pattern", (int) Qt::Dense3Pattern);
39 m_styleCombo->addItem("Dense4Pattern", Qt::Dense4Pattern);
39 m_styleCombo->addItem("Dense4Pattern", (int) Qt::Dense4Pattern);
40 m_styleCombo->addItem("Dense5Pattern", Qt::Dense5Pattern);
40 m_styleCombo->addItem("Dense5Pattern", (int) Qt::Dense5Pattern);
41 m_styleCombo->addItem("Dense6Pattern", Qt::Dense6Pattern);
41 m_styleCombo->addItem("Dense6Pattern", (int) Qt::Dense6Pattern);
42 m_styleCombo->addItem("Dense7Pattern", Qt::Dense7Pattern);
42 m_styleCombo->addItem("Dense7Pattern", (int) Qt::Dense7Pattern);
43 m_styleCombo->addItem("HorPattern", Qt::HorPattern);
43 m_styleCombo->addItem("HorPattern", (int) Qt::HorPattern);
44 m_styleCombo->addItem("VerPattern", Qt::VerPattern);
44 m_styleCombo->addItem("VerPattern", (int) Qt::VerPattern);
45 m_styleCombo->addItem("CrossPattern", Qt::CrossPattern);
45 m_styleCombo->addItem("CrossPattern", (int) Qt::CrossPattern);
46 m_styleCombo->addItem("BDiagPattern", Qt::BDiagPattern);
46 m_styleCombo->addItem("BDiagPattern", (int) Qt::BDiagPattern);
47 m_styleCombo->addItem("FDiagPattern", Qt::FDiagPattern);
47 m_styleCombo->addItem("FDiagPattern", (int) Qt::FDiagPattern);
48 m_styleCombo->addItem("DiagCrossPattern", Qt::DiagCrossPattern);
48 m_styleCombo->addItem("DiagCrossPattern", (int) Qt::DiagCrossPattern);
49
49
50 QFormLayout *layout = new QFormLayout();
50 QFormLayout *layout = new QFormLayout();
51 layout->addRow("Color", m_colorButton);
51 layout->addRow("Color", m_colorButton);
52 layout->addRow("Style", m_styleCombo);
52 layout->addRow("Style", m_styleCombo);
53 setLayout(layout);
53 setLayout(layout);
54
54
55 connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog()));
55 connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog()));
56 connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle()));
56 connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle()));
57 }
57 }
58
58
59 void BrushTool::setBrush(QBrush brush)
59 void BrushTool::setBrush(QBrush brush)
60 {
60 {
61 m_brush = brush;
61 m_brush = brush;
62 m_colorButton->setText(m_brush.color().name());
62 m_colorButton->setText(m_brush.color().name());
63 m_styleCombo->setCurrentIndex(m_brush.style()); // index matches the enum
63 m_styleCombo->setCurrentIndex(m_brush.style()); // index matches the enum
64 }
64 }
65
65
66 QBrush BrushTool::brush() const
66 QBrush BrushTool::brush() const
67 {
67 {
68 return m_brush;
68 return m_brush;
69 }
69 }
70
70
71 QString BrushTool::name()
71 QString BrushTool::name()
72 {
72 {
73 return name(m_brush);
73 return name(m_brush);
74 }
74 }
75
75
76 QString BrushTool::name(const QBrush &brush)
76 QString BrushTool::name(const QBrush &brush)
77 {
77 {
78 return brush.color().name();
78 return brush.color().name();
79 }
79 }
80
80
81 void BrushTool::showColorDialog()
81 void BrushTool::showColorDialog()
82 {
82 {
83 QColorDialog dialog(m_brush.color());
83 QColorDialog dialog(m_brush.color());
84 dialog.show();
84 dialog.show();
85 dialog.exec();
85 dialog.exec();
86 m_brush.setColor(dialog.selectedColor());
86 m_brush.setColor(dialog.selectedColor());
87 m_colorButton->setText(m_brush.color().name());
87 m_colorButton->setText(m_brush.color().name());
88 emit changed();
88 emit changed();
89 }
89 }
90
90
91 void BrushTool::updateStyle()
91 void BrushTool::updateStyle()
92 {
92 {
93 Qt::BrushStyle style = (Qt::BrushStyle) m_styleCombo->itemData(m_styleCombo->currentIndex()).toInt();
93 Qt::BrushStyle style = (Qt::BrushStyle) m_styleCombo->itemData(m_styleCombo->currentIndex()).toInt();
94 if (m_brush.style() != style) {
94 if (m_brush.style() != style) {
95 m_brush.setStyle(style);
95 m_brush.setStyle(style);
96 emit changed();
96 emit changed();
97 }
97 }
98 }
98 }
99
99
100 #include "moc_brushtool.cpp"
100 #include "moc_brushtool.cpp"
@@ -1,112 +1,117
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 "tablewidget.h"
21 #include "tablewidget.h"
22 #include "customtablemodel.h"
22 #include "customtablemodel.h"
23 #include <QGridLayout>
23 #include <QGridLayout>
24 #include <QTableView>
24 #include <QTableView>
25 #include <QChart>
25 #include <QChart>
26 #include <QChartView>
26 #include <QChartView>
27 #include <QLineSeries>
27 #include <QLineSeries>
28 #include <QVXYModelMapper>
28 #include <QVXYModelMapper>
29 #include <QBarSeries>
29 #include <QBarSeries>
30 #include <QBarSet>
30 #include <QBarSet>
31 #include <QVBarModelMapper>
31 #include <QVBarModelMapper>
32 #include <QHeaderView>
32 #include <QHeaderView>
33 #include <QBarCategoryAxis>
33 #include <QBarCategoryAxis>
34
34
35 QTCOMMERCIALCHART_USE_NAMESPACE
35 QTCOMMERCIALCHART_USE_NAMESPACE
36
36
37 TableWidget::TableWidget(QWidget *parent)
37 TableWidget::TableWidget(QWidget *parent)
38 : QWidget(parent)
38 : QWidget(parent)
39 {
39 {
40 // create simple model for storing data
40 // create simple model for storing data
41 // user's table data model
41 // user's table data model
42 //! [1]
42 //! [1]
43 CustomTableModel *model = new CustomTableModel;
43 CustomTableModel *model = new CustomTableModel;
44 //! [1]
44 //! [1]
45
45
46 //! [2]
46 //! [2]
47 // create table view and add model to it
47 // create table view and add model to it
48 QTableView *tableView = new QTableView;
48 QTableView *tableView = new QTableView;
49 tableView->setModel(model);
49 tableView->setModel(model);
50 tableView->setMinimumWidth(300);
50 tableView->setMinimumWidth(300);
51 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
52 tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
53 tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
54 #else
51 tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
55 tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
52 tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
56 tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
57 #endif
53 //! [2]
58 //! [2]
54
59
55 //! [3]
60 //! [3]
56 QChart *chart = new QChart;
61 QChart *chart = new QChart;
57 chart->setAnimationOptions(QChart::AllAnimations);
62 chart->setAnimationOptions(QChart::AllAnimations);
58 //! [3]
63 //! [3]
59
64
60 // series 1
65 // series 1
61 //! [4]
66 //! [4]
62 QBarSeries *series = new QBarSeries;
67 QBarSeries *series = new QBarSeries;
63
68
64 int first = 3;
69 int first = 3;
65 int count = 5;
70 int count = 5;
66 QVBarModelMapper *mapper = new QVBarModelMapper(this);
71 QVBarModelMapper *mapper = new QVBarModelMapper(this);
67 mapper->setFirstBarSetColumn(1);
72 mapper->setFirstBarSetColumn(1);
68 mapper->setLastBarSetColumn(4);
73 mapper->setLastBarSetColumn(4);
69 mapper->setFirstRow(first);
74 mapper->setFirstRow(first);
70 mapper->setRowCount(count);
75 mapper->setRowCount(count);
71 mapper->setSeries(series);
76 mapper->setSeries(series);
72 mapper->setModel(model);
77 mapper->setModel(model);
73 chart->addSeries(series);
78 chart->addSeries(series);
74 //! [4]
79 //! [4]
75
80
76 //! [5]
81 //! [5]
77 // for storing color hex from the series
82 // for storing color hex from the series
78 QString seriesColorHex = "#000000";
83 QString seriesColorHex = "#000000";
79
84
80 // get the color of the series and use it for showing the mapped area
85 // get the color of the series and use it for showing the mapped area
81 QList<QBarSet *> barsets = series->barSets();
86 QList<QBarSet *> barsets = series->barSets();
82 for (int i = 0; i < barsets.count(); i++) {
87 for (int i = 0; i < barsets.count(); i++) {
83 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
88 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
84 model->addMapping(seriesColorHex, QRect(1 + i, first, 1, barsets.at(i)->count()));
89 model->addMapping(seriesColorHex, QRect(1 + i, first, 1, barsets.at(i)->count()));
85 }
90 }
86 //! [5]
91 //! [5]
87
92
88 //! [6]
93 //! [6]
89 QStringList categories;
94 QStringList categories;
90 categories << "April" << "May" << "June" << "July" << "August";
95 categories << "April" << "May" << "June" << "July" << "August";
91 QBarCategoryAxis *axis = new QBarCategoryAxis();
96 QBarCategoryAxis *axis = new QBarCategoryAxis();
92 axis->append(categories);
97 axis->append(categories);
93 chart->createDefaultAxes();
98 chart->createDefaultAxes();
94 chart->setAxisX(axis, series);
99 chart->setAxisX(axis, series);
95 //! [6]
100 //! [6]
96
101
97 //! [7]
102 //! [7]
98 QChartView *chartView = new QChartView(chart);
103 QChartView *chartView = new QChartView(chart);
99 chartView->setRenderHint(QPainter::Antialiasing);
104 chartView->setRenderHint(QPainter::Antialiasing);
100 chartView->setMinimumSize(640, 480);
105 chartView->setMinimumSize(640, 480);
101 //! [7]
106 //! [7]
102
107
103 //! [8]
108 //! [8]
104 // create main layout
109 // create main layout
105 QGridLayout *mainLayout = new QGridLayout;
110 QGridLayout *mainLayout = new QGridLayout;
106 mainLayout->addWidget(tableView, 1, 0);
111 mainLayout->addWidget(tableView, 1, 0);
107 mainLayout->addWidget(chartView, 1, 1);
112 mainLayout->addWidget(chartView, 1, 1);
108 mainLayout->setColumnStretch(1, 1);
113 mainLayout->setColumnStretch(1, 1);
109 mainLayout->setColumnStretch(0, 0);
114 mainLayout->setColumnStretch(0, 0);
110 setLayout(mainLayout);
115 setLayout(mainLayout);
111 //! [8]
116 //! [8]
112 }
117 }
@@ -1,112 +1,117
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 "tablewidget.h"
21 #include "tablewidget.h"
22 #include "customtablemodel.h"
22 #include "customtablemodel.h"
23 #include <QGridLayout>
23 #include <QGridLayout>
24 #include <QTableView>
24 #include <QTableView>
25 #include <QChart>
25 #include <QChart>
26 #include <QChartView>
26 #include <QChartView>
27 #include <QLineSeries>
27 #include <QLineSeries>
28 #include <QVXYModelMapper>
28 #include <QVXYModelMapper>
29 #include <QHeaderView>
29 #include <QHeaderView>
30
30
31 QTCOMMERCIALCHART_USE_NAMESPACE
31 QTCOMMERCIALCHART_USE_NAMESPACE
32
32
33 TableWidget::TableWidget(QWidget *parent)
33 TableWidget::TableWidget(QWidget *parent)
34 : QWidget(parent)
34 : QWidget(parent)
35 {
35 {
36 // create simple model for storing data
36 // create simple model for storing data
37 // user's table data model
37 // user's table data model
38 //! [1]
38 //! [1]
39 CustomTableModel *model = new CustomTableModel;
39 CustomTableModel *model = new CustomTableModel;
40 //! [1]
40 //! [1]
41
41
42 //! [2]
42 //! [2]
43 // create table view and add model to it
43 // create table view and add model to it
44 QTableView *tableView = new QTableView;
44 QTableView *tableView = new QTableView;
45 tableView->setModel(model);
45 tableView->setModel(model);
46 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
47 tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
48 tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
49 #else
46 tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
50 tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
47 tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
51 tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
52 #endif
48 //! [2]
53 //! [2]
49
54
50 //! [3]
55 //! [3]
51 QChart *chart = new QChart;
56 QChart *chart = new QChart;
52 chart->setAnimationOptions(QChart::AllAnimations);
57 chart->setAnimationOptions(QChart::AllAnimations);
53 //! [3]
58 //! [3]
54
59
55 // series 1
60 // series 1
56 //! [4]
61 //! [4]
57 QLineSeries *series = new QLineSeries;
62 QLineSeries *series = new QLineSeries;
58 series->setName("Line 1");
63 series->setName("Line 1");
59 QVXYModelMapper *mapper = new QVXYModelMapper(this);
64 QVXYModelMapper *mapper = new QVXYModelMapper(this);
60 mapper->setXColumn(0);
65 mapper->setXColumn(0);
61 mapper->setYColumn(1);
66 mapper->setYColumn(1);
62 mapper->setSeries(series);
67 mapper->setSeries(series);
63 mapper->setModel(model);
68 mapper->setModel(model);
64 chart->addSeries(series);
69 chart->addSeries(series);
65 //! [4]
70 //! [4]
66
71
67 //! [5]
72 //! [5]
68 // for storing color hex from the series
73 // for storing color hex from the series
69 QString seriesColorHex = "#000000";
74 QString seriesColorHex = "#000000";
70
75
71 // get the color of the series and use it for showing the mapped area
76 // get the color of the series and use it for showing the mapped area
72 seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper();
77 seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper();
73 model->addMapping(seriesColorHex, QRect(0, 0, 2, model->rowCount()));
78 model->addMapping(seriesColorHex, QRect(0, 0, 2, model->rowCount()));
74 //! [5]
79 //! [5]
75
80
76
81
77 // series 2
82 // series 2
78 //! [6]
83 //! [6]
79 series = new QLineSeries;
84 series = new QLineSeries;
80 series->setName("Line 2");
85 series->setName("Line 2");
81
86
82 mapper = new QVXYModelMapper(this);
87 mapper = new QVXYModelMapper(this);
83 mapper->setXColumn(2);
88 mapper->setXColumn(2);
84 mapper->setYColumn(3);
89 mapper->setYColumn(3);
85 mapper->setSeries(series);
90 mapper->setSeries(series);
86 mapper->setModel(model);
91 mapper->setModel(model);
87 chart->addSeries(series);
92 chart->addSeries(series);
88 //! [6]
93 //! [6]
89
94
90 //! [7]
95 //! [7]
91 // get the color of the series and use it for showing the mapped area
96 // get the color of the series and use it for showing the mapped area
92 seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper();
97 seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper();
93 model->addMapping(seriesColorHex, QRect(2, 0, 2, model->rowCount()));
98 model->addMapping(seriesColorHex, QRect(2, 0, 2, model->rowCount()));
94 //! [7]
99 //! [7]
95
100
96 //! [8]
101 //! [8]
97 chart->createDefaultAxes();
102 chart->createDefaultAxes();
98 QChartView *chartView = new QChartView(chart);
103 QChartView *chartView = new QChartView(chart);
99 chartView->setRenderHint(QPainter::Antialiasing);
104 chartView->setRenderHint(QPainter::Antialiasing);
100 chartView->setMinimumSize(640, 480);
105 chartView->setMinimumSize(640, 480);
101 //! [8]
106 //! [8]
102
107
103 //! [9]
108 //! [9]
104 // create main layout
109 // create main layout
105 QGridLayout *mainLayout = new QGridLayout;
110 QGridLayout *mainLayout = new QGridLayout;
106 mainLayout->addWidget(tableView, 1, 0);
111 mainLayout->addWidget(tableView, 1, 0);
107 mainLayout->addWidget(chartView, 1, 1);
112 mainLayout->addWidget(chartView, 1, 1);
108 mainLayout->setColumnStretch(1, 1);
113 mainLayout->setColumnStretch(1, 1);
109 mainLayout->setColumnStretch(0, 0);
114 mainLayout->setColumnStretch(0, 0);
110 setLayout(mainLayout);
115 setLayout(mainLayout);
111 //! [9]
116 //! [9]
112 }
117 }
@@ -1,68 +1,68
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 "abstractbaranimation_p.h"
21 #include "abstractbaranimation_p.h"
22 #include "abstractbarchartitem_p.h"
22 #include "abstractbarchartitem_p.h"
23 #include <QTimer>
23 #include <QTimer>
24 #include <QDebug>
24 #include <QDebug>
25
25
26 Q_DECLARE_METATYPE(QVector<QRectF>)
26 Q_DECLARE_METATYPE(QVector<QRectF>)
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 AbstractBarAnimation::AbstractBarAnimation(AbstractBarChartItem *item)
30 AbstractBarAnimation::AbstractBarAnimation(AbstractBarChartItem *item)
31 : ChartAnimation(item),
31 : ChartAnimation(item),
32 m_item(item)
32 m_item(item)
33 {
33 {
34 setDuration(ChartAnimationDuration);
34 setDuration(ChartAnimationDuration);
35 setEasingCurve(QEasingCurve::OutQuart);
35 setEasingCurve(QEasingCurve::OutQuart);
36 }
36 }
37
37
38 AbstractBarAnimation::~AbstractBarAnimation()
38 AbstractBarAnimation::~AbstractBarAnimation()
39 {
39 {
40 }
40 }
41
41
42 QVariant AbstractBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
42 QVariant AbstractBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
43 {
43 {
44 Q_UNUSED(from);
44 Q_UNUSED(from);
45 Q_UNUSED(to);
45 Q_UNUSED(to);
46 Q_UNUSED(progress);
46 Q_UNUSED(progress);
47 qWarning() << "AbstractBarAnimation::interpolated called";
47 qWarning() << "AbstractBarAnimation::interpolated called";
48 return to;
48 return to;
49 }
49 }
50
50
51 void AbstractBarAnimation::updateCurrentValue(const QVariant &value)
51 void AbstractBarAnimation::updateCurrentValue(const QVariant &value)
52 {
52 {
53 QVector<QRectF> layout = qVariantValue<QVector<QRectF> >(value);
53 QVector<QRectF> layout = qvariant_cast<QVector<QRectF> >(value);
54 m_item->setLayout(layout);
54 m_item->setLayout(layout);
55 }
55 }
56
56
57 void AbstractBarAnimation::setup(const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout)
57 void AbstractBarAnimation::setup(const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout)
58 {
58 {
59 QVariantAnimation::KeyValues value;
59 QVariantAnimation::KeyValues value;
60 setKeyValues(value); //workaround for wrong interpolation call
60 setKeyValues(value); //workaround for wrong interpolation call
61 setKeyValueAt(0.0, qVariantFromValue(oldLayout));
61 setKeyValueAt(0.0, qVariantFromValue(oldLayout));
62 setKeyValueAt(1.0, qVariantFromValue(newLayout));
62 setKeyValueAt(1.0, qVariantFromValue(newLayout));
63 }
63 }
64
64
65 #include "moc_abstractbaranimation_p.cpp"
65 #include "moc_abstractbaranimation_p.cpp"
66
66
67 QTCOMMERCIALCHART_END_NAMESPACE
67 QTCOMMERCIALCHART_END_NAMESPACE
68
68
@@ -1,141 +1,141
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 "axisanimation_p.h"
21 #include "axisanimation_p.h"
22 #include "chartaxis_p.h"
22 #include "chartaxis_p.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include <QTimer>
24 #include <QTimer>
25 #include <QDebug>
25 #include <QDebug>
26
26
27 Q_DECLARE_METATYPE(QVector<qreal>)
27 Q_DECLARE_METATYPE(QVector<qreal>)
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31
31
32 AxisAnimation::AxisAnimation(ChartAxis *axis)
32 AxisAnimation::AxisAnimation(ChartAxis *axis)
33 : ChartAnimation(axis),
33 : ChartAnimation(axis),
34 m_axis(axis),
34 m_axis(axis),
35 m_type(DefaultAnimation)
35 m_type(DefaultAnimation)
36 {
36 {
37 setDuration(ChartAnimationDuration);
37 setDuration(ChartAnimationDuration);
38 setEasingCurve(QEasingCurve::OutQuart);
38 setEasingCurve(QEasingCurve::OutQuart);
39 }
39 }
40
40
41 AxisAnimation::~AxisAnimation()
41 AxisAnimation::~AxisAnimation()
42 {
42 {
43 }
43 }
44
44
45 void AxisAnimation::setAnimationType(Animation type)
45 void AxisAnimation::setAnimationType(Animation type)
46 {
46 {
47 if (state() != QAbstractAnimation::Stopped)
47 if (state() != QAbstractAnimation::Stopped)
48 stop();
48 stop();
49 m_type = type;
49 m_type = type;
50 }
50 }
51
51
52 void AxisAnimation::setAnimationPoint(const QPointF &point)
52 void AxisAnimation::setAnimationPoint(const QPointF &point)
53 {
53 {
54 if (state() != QAbstractAnimation::Stopped)
54 if (state() != QAbstractAnimation::Stopped)
55 stop();
55 stop();
56 m_point = point;
56 m_point = point;
57 }
57 }
58
58
59 void AxisAnimation::setValues(QVector<qreal> &oldLayout, QVector<qreal> &newLayout)
59 void AxisAnimation::setValues(QVector<qreal> &oldLayout, QVector<qreal> &newLayout)
60 {
60 {
61 if (state() != QAbstractAnimation::Stopped) stop();
61 if (state() != QAbstractAnimation::Stopped) stop();
62
62
63 if (newLayout.count() == 0)
63 if (newLayout.count() == 0)
64 return;
64 return;
65
65
66 switch (m_type) {
66 switch (m_type) {
67 case ZoomOutAnimation: {
67 case ZoomOutAnimation: {
68 QRectF rect = m_axis->gridGeometry();
68 QRectF rect = m_axis->gridGeometry();
69 oldLayout.resize(newLayout.count());
69 oldLayout.resize(newLayout.count());
70
70
71 for (int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) {
71 for (int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) {
72 oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.bottom();
72 oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.bottom();
73 oldLayout[j] = m_axis->orientation() == Qt::Horizontal ? rect.right() : rect.top();
73 oldLayout[j] = m_axis->orientation() == Qt::Horizontal ? rect.right() : rect.top();
74 }
74 }
75 }
75 }
76 break;
76 break;
77 case ZoomInAnimation: {
77 case ZoomInAnimation: {
78 int index = qMin(oldLayout.count() * (m_axis->orientation() == Qt::Horizontal ? m_point.x() : (1 - m_point.y())), newLayout.count() - (qreal)1.0);
78 int index = qMin(oldLayout.count() * (m_axis->orientation() == Qt::Horizontal ? m_point.x() : (1 - m_point.y())), newLayout.count() - (qreal)1.0);
79 oldLayout.resize(newLayout.count());
79 oldLayout.resize(newLayout.count());
80
80
81 for (int i = 0; i < oldLayout.count(); i++)
81 for (int i = 0; i < oldLayout.count(); i++)
82 oldLayout[i] = oldLayout[index];
82 oldLayout[i] = oldLayout[index];
83 }
83 }
84 break;
84 break;
85 case MoveForwardAnimation: {
85 case MoveForwardAnimation: {
86 oldLayout.resize(newLayout.count());
86 oldLayout.resize(newLayout.count());
87
87
88 for (int i = 0, j = i + 1; i < oldLayout.count() - 1; ++i, ++j)
88 for (int i = 0, j = i + 1; i < oldLayout.count() - 1; ++i, ++j)
89 oldLayout[i] = oldLayout[j];
89 oldLayout[i] = oldLayout[j];
90 }
90 }
91 break;
91 break;
92 case MoveBackwordAnimation: {
92 case MoveBackwordAnimation: {
93 oldLayout.resize(newLayout.count());
93 oldLayout.resize(newLayout.count());
94
94
95 for (int i = oldLayout.count() - 1, j = i - 1; i > 0; --i, --j)
95 for (int i = oldLayout.count() - 1, j = i - 1; i > 0; --i, --j)
96 oldLayout[i] = oldLayout[j];
96 oldLayout[i] = oldLayout[j];
97 }
97 }
98 break;
98 break;
99 default: {
99 default: {
100 oldLayout.resize(newLayout.count());
100 oldLayout.resize(newLayout.count());
101 QRectF rect = m_axis->gridGeometry();
101 QRectF rect = m_axis->gridGeometry();
102 for (int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j)
102 for (int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j)
103 oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.top();
103 oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.top();
104 }
104 }
105 break;
105 break;
106 }
106 }
107
107
108 QVariantAnimation::KeyValues value;
108 QVariantAnimation::KeyValues value;
109 setKeyValues(value); //workaround for wrong interpolation call
109 setKeyValues(value); //workaround for wrong interpolation call
110 setKeyValueAt(0.0, qVariantFromValue(oldLayout));
110 setKeyValueAt(0.0, qVariantFromValue(oldLayout));
111 setKeyValueAt(1.0, qVariantFromValue(newLayout));
111 setKeyValueAt(1.0, qVariantFromValue(newLayout));
112 }
112 }
113
113
114 QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const
114 QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const
115 {
115 {
116 QVector<qreal> startVector = qVariantValue<QVector<qreal> >(start);
116 QVector<qreal> startVector = qvariant_cast<QVector<qreal> >(start);
117 QVector<qreal> endVecotr = qVariantValue<QVector<qreal> >(end);
117 QVector<qreal> endVecotr = qvariant_cast<QVector<qreal> >(end);
118 QVector<qreal> result;
118 QVector<qreal> result;
119
119
120 Q_ASSERT(startVector.count() == endVecotr.count()) ;
120 Q_ASSERT(startVector.count() == endVecotr.count()) ;
121
121
122 for (int i = 0; i < startVector.count(); i++) {
122 for (int i = 0; i < startVector.count(); i++) {
123 qreal value = startVector[i] + ((endVecotr[i] - startVector[i]) * progress); //qBound(0.0, progress, 1.0));
123 qreal value = startVector[i] + ((endVecotr[i] - startVector[i]) * progress); //qBound(0.0, progress, 1.0));
124 result << value;
124 result << value;
125 }
125 }
126 return qVariantFromValue(result);
126 return qVariantFromValue(result);
127 }
127 }
128
128
129
129
130 void AxisAnimation::updateCurrentValue(const QVariant &value)
130 void AxisAnimation::updateCurrentValue(const QVariant &value)
131 {
131 {
132 if (state() != QAbstractAnimation::Stopped) { //workaround
132 if (state() != QAbstractAnimation::Stopped) { //workaround
133 QVector<qreal> vector = qVariantValue<QVector<qreal> >(value);
133 QVector<qreal> vector = qvariant_cast<QVector<qreal> >(value);
134 Q_ASSERT(vector.count() != 0);
134 Q_ASSERT(vector.count() != 0);
135 m_axis->setLayout(vector);
135 m_axis->setLayout(vector);
136 m_axis->updateGeometry();
136 m_axis->updateGeometry();
137 }
137 }
138
138
139 }
139 }
140
140
141 QTCOMMERCIALCHART_END_NAMESPACE
141 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,73 +1,73
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 = qvariant_cast<QVector<QRectF> >(from);
42 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
42 QVector<QRectF> endVector = qvariant_cast<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 QRectF start = startVector[i].normalized();
48 QRectF start = startVector[i].normalized();
49 QRectF end = endVector[i].normalized();
49 QRectF end = endVector[i].normalized();
50
50
51 qreal x = end.left();
51 qreal x = end.left();
52 qreal y;
52 qreal y;
53 qreal w = end.width();
53 qreal w = end.width();
54 qreal h;
54 qreal h;
55
55
56 if (endVector[i].height() < 0) {
56 if (endVector[i].height() < 0) {
57 // Negative bar
57 // Negative bar
58 y = end.top();
58 y = end.top();
59 h = start.height() + ((end.height() - start.height()) * progress);
59 h = start.height() + ((end.height() - start.height()) * progress);
60 } else {
60 } else {
61 h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress);
61 h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress);
62 y = endVector[i].top() + endVector[i].height() - h;
62 y = endVector[i].top() + endVector[i].height() - h;
63 }
63 }
64
64
65 QRectF value(x, y, w, h);
65 QRectF value(x, y, w, h);
66 result << value.normalized();
66 result << value.normalized();
67 }
67 }
68 return qVariantFromValue(result);
68 return qVariantFromValue(result);
69 }
69 }
70
70
71 #include "moc_baranimation_p.cpp"
71 #include "moc_baranimation_p.cpp"
72
72
73 QTCOMMERCIALCHART_END_NAMESPACE
73 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,74 +1,74
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 = qvariant_cast<QVector<QRectF> >(from);
43 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
43 QVector<QRectF> endVector = qvariant_cast<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 QRectF start = startVector[i].normalized();
49 QRectF start = startVector[i].normalized();
50 QRectF end = endVector[i].normalized();
50 QRectF end = endVector[i].normalized();
51
51
52 qreal x;
52 qreal x;
53 qreal y = end.top();
53 qreal y = end.top();
54 qreal w;
54 qreal w;
55 qreal h = end.height();
55 qreal h = end.height();
56
56
57 if (endVector[i].width() < 0) {
57 if (endVector[i].width() < 0) {
58 // Negative bar
58 // Negative bar
59 w = start.width() + ((end.width() - start.width()) * progress);
59 w = start.width() + ((end.width() - start.width()) * progress);
60 x = endVector[i].right() - endVector[i].width() - w;
60 x = endVector[i].right() - endVector[i].width() - w;
61 } else {
61 } else {
62 w = startVector[i].width() + ((endVector[i].width() - startVector[i].width()) * progress);
62 w = startVector[i].width() + ((endVector[i].width() - startVector[i].width()) * progress);
63 x = end.left();
63 x = end.left();
64 }
64 }
65
65
66 QRectF value(x, y, w, h);
66 QRectF value(x, y, w, h);
67 result << value.normalized();
67 result << value.normalized();
68 }
68 }
69 return qVariantFromValue(result);
69 return qVariantFromValue(result);
70 }
70 }
71
71
72 #include "moc_horizontalbaranimation_p.cpp"
72 #include "moc_horizontalbaranimation_p.cpp"
73
73
74 QTCOMMERCIALCHART_END_NAMESPACE
74 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 = qvariant_cast<QVector<QRectF> >(from);
43 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
43 QVector<QRectF> endVector = qvariant_cast<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.normalized();
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 = qvariant_cast<QVector<QRectF> >(from);
43 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
43 QVector<QRectF> endVector = qvariant_cast<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.normalized();
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 = qvariant_cast<QVector<QRectF> >(from);
43 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
43 QVector<QRectF> endVector = qvariant_cast<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.normalized();
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,126 +1,126
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 "piesliceanimation_p.h"
21 #include "piesliceanimation_p.h"
22 #include "piechartitem_p.h"
22 #include "piechartitem_p.h"
23
23
24 Q_DECLARE_METATYPE(QTCOMMERCIALCHART_NAMESPACE::PieSliceData)
24 Q_DECLARE_METATYPE(QTCOMMERCIALCHART_NAMESPACE::PieSliceData)
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 qreal linearPos(qreal start, qreal end, qreal pos)
28 qreal linearPos(qreal start, qreal end, qreal pos)
29 {
29 {
30 return start + ((end - start) * pos);
30 return start + ((end - start) * pos);
31 }
31 }
32
32
33 QPointF linearPos(QPointF start, QPointF end, qreal pos)
33 QPointF linearPos(QPointF start, QPointF end, qreal pos)
34 {
34 {
35 qreal x = linearPos(start.x(), end.x(), pos);
35 qreal x = linearPos(start.x(), end.x(), pos);
36 qreal y = linearPos(start.y(), end.y(), pos);
36 qreal y = linearPos(start.y(), end.y(), pos);
37 return QPointF(x, y);
37 return QPointF(x, y);
38 }
38 }
39
39
40 QPen linearPos(QPen start, QPen end, qreal pos)
40 QPen linearPos(QPen start, QPen end, qreal pos)
41 {
41 {
42 QColor c;
42 QColor c;
43 c.setRedF(linearPos(start.color().redF(), end.color().redF(), pos));
43 c.setRedF(linearPos(start.color().redF(), end.color().redF(), pos));
44 c.setGreenF(linearPos(start.color().greenF(), end.color().greenF(), pos));
44 c.setGreenF(linearPos(start.color().greenF(), end.color().greenF(), pos));
45 c.setBlueF(linearPos(start.color().blueF(), end.color().blueF(), pos));
45 c.setBlueF(linearPos(start.color().blueF(), end.color().blueF(), pos));
46 end.setColor(c);
46 end.setColor(c);
47 return end;
47 return end;
48 }
48 }
49
49
50 QBrush linearPos(QBrush start, QBrush end, qreal pos)
50 QBrush linearPos(QBrush start, QBrush end, qreal pos)
51 {
51 {
52 QColor c;
52 QColor c;
53 c.setRedF(linearPos(start.color().redF(), end.color().redF(), pos));
53 c.setRedF(linearPos(start.color().redF(), end.color().redF(), pos));
54 c.setGreenF(linearPos(start.color().greenF(), end.color().greenF(), pos));
54 c.setGreenF(linearPos(start.color().greenF(), end.color().greenF(), pos));
55 c.setBlueF(linearPos(start.color().blueF(), end.color().blueF(), pos));
55 c.setBlueF(linearPos(start.color().blueF(), end.color().blueF(), pos));
56 end.setColor(c);
56 end.setColor(c);
57 return end;
57 return end;
58 }
58 }
59
59
60 PieSliceAnimation::PieSliceAnimation(PieSliceItem *sliceItem)
60 PieSliceAnimation::PieSliceAnimation(PieSliceItem *sliceItem)
61 : ChartAnimation(sliceItem),
61 : ChartAnimation(sliceItem),
62 m_sliceItem(sliceItem)
62 m_sliceItem(sliceItem)
63 {
63 {
64 }
64 }
65
65
66 PieSliceAnimation::~PieSliceAnimation()
66 PieSliceAnimation::~PieSliceAnimation()
67 {
67 {
68 }
68 }
69
69
70 void PieSliceAnimation::setValue(const PieSliceData &startValue, const PieSliceData &endValue)
70 void PieSliceAnimation::setValue(const PieSliceData &startValue, const PieSliceData &endValue)
71 {
71 {
72 if (state() != QAbstractAnimation::Stopped)
72 if (state() != QAbstractAnimation::Stopped)
73 stop();
73 stop();
74
74
75 m_currentValue = startValue;
75 m_currentValue = startValue;
76
76
77 setKeyValueAt(0.0, qVariantFromValue(startValue));
77 setKeyValueAt(0.0, qVariantFromValue(startValue));
78 setKeyValueAt(1.0, qVariantFromValue(endValue));
78 setKeyValueAt(1.0, qVariantFromValue(endValue));
79 }
79 }
80
80
81 void PieSliceAnimation::updateValue(const PieSliceData &endValue)
81 void PieSliceAnimation::updateValue(const PieSliceData &endValue)
82 {
82 {
83 if (state() != QAbstractAnimation::Stopped)
83 if (state() != QAbstractAnimation::Stopped)
84 stop();
84 stop();
85
85
86 setKeyValueAt(0.0, qVariantFromValue(m_currentValue));
86 setKeyValueAt(0.0, qVariantFromValue(m_currentValue));
87 setKeyValueAt(1.0, qVariantFromValue(endValue));
87 setKeyValueAt(1.0, qVariantFromValue(endValue));
88 }
88 }
89
89
90 PieSliceData PieSliceAnimation::currentSliceValue()
90 PieSliceData PieSliceAnimation::currentSliceValue()
91 {
91 {
92 // NOTE:
92 // NOTE:
93 // We must use an internal current value because QVariantAnimation::currentValue() is updated
93 // We must use an internal current value because QVariantAnimation::currentValue() is updated
94 // before the animation is actually started. So if we get 2 updateValue() calls in a row the currentValue()
94 // before the animation is actually started. So if we get 2 updateValue() calls in a row the currentValue()
95 // will have the end value set from the first call and the second call will interpolate that instead of
95 // will have the end value set from the first call and the second call will interpolate that instead of
96 // the original current value as it was before the first call.
96 // the original current value as it was before the first call.
97 return m_currentValue;
97 return m_currentValue;
98 }
98 }
99
99
100 QVariant PieSliceAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const
100 QVariant PieSliceAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const
101 {
101 {
102 PieSliceData startValue = qVariantValue<PieSliceData>(start);
102 PieSliceData startValue = qvariant_cast<PieSliceData>(start);
103 PieSliceData endValue = qVariantValue<PieSliceData>(end);
103 PieSliceData endValue = qvariant_cast<PieSliceData>(end);
104
104
105 PieSliceData result;
105 PieSliceData result;
106 result = endValue;
106 result = endValue;
107 result.m_center = linearPos(startValue.m_center, endValue.m_center, progress);
107 result.m_center = linearPos(startValue.m_center, endValue.m_center, progress);
108 result.m_radius = linearPos(startValue.m_radius, endValue.m_radius, progress);
108 result.m_radius = linearPos(startValue.m_radius, endValue.m_radius, progress);
109 result.m_startAngle = linearPos(startValue.m_startAngle, endValue.m_startAngle, progress);
109 result.m_startAngle = linearPos(startValue.m_startAngle, endValue.m_startAngle, progress);
110 result.m_angleSpan = linearPos(startValue.m_angleSpan, endValue.m_angleSpan, progress);
110 result.m_angleSpan = linearPos(startValue.m_angleSpan, endValue.m_angleSpan, progress);
111 result.m_slicePen = linearPos(startValue.m_slicePen, endValue.m_slicePen, progress);
111 result.m_slicePen = linearPos(startValue.m_slicePen, endValue.m_slicePen, progress);
112 result.m_sliceBrush = linearPos(startValue.m_sliceBrush, endValue.m_sliceBrush, progress);
112 result.m_sliceBrush = linearPos(startValue.m_sliceBrush, endValue.m_sliceBrush, progress);
113 result.m_holeRadius = linearPos(startValue.m_holeRadius, endValue.m_holeRadius, progress);
113 result.m_holeRadius = linearPos(startValue.m_holeRadius, endValue.m_holeRadius, progress);
114
114
115 return qVariantFromValue(result);
115 return qVariantFromValue(result);
116 }
116 }
117
117
118 void PieSliceAnimation::updateCurrentValue(const QVariant &value)
118 void PieSliceAnimation::updateCurrentValue(const QVariant &value)
119 {
119 {
120 if (state() != QAbstractAnimation::Stopped) { //workaround
120 if (state() != QAbstractAnimation::Stopped) { //workaround
121 m_currentValue = qVariantValue<PieSliceData>(value);
121 m_currentValue = qvariant_cast<PieSliceData>(value);
122 m_sliceItem->setLayout(m_currentValue);
122 m_sliceItem->setLayout(m_currentValue);
123 }
123 }
124 }
124 }
125
125
126 QTCOMMERCIALCHART_END_NAMESPACE
126 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,204 +1,204
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 "splineanimation_p.h"
21 #include "splineanimation_p.h"
22 #include "splinechartitem_p.h"
22 #include "splinechartitem_p.h"
23 #include <QDebug>
23 #include <QDebug>
24
24
25 Q_DECLARE_METATYPE(QVector<QPointF>)
25 Q_DECLARE_METATYPE(QVector<QPointF>)
26 Q_DECLARE_METATYPE(SplineVector)
26 Q_DECLARE_METATYPE(SplineVector)
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 SplineAnimation::SplineAnimation(SplineChartItem *item)
30 SplineAnimation::SplineAnimation(SplineChartItem *item)
31 : XYAnimation(item),
31 : XYAnimation(item),
32 m_item(item),
32 m_item(item),
33 m_valid(false)
33 m_valid(false)
34 {
34 {
35 }
35 }
36
36
37 SplineAnimation::~SplineAnimation()
37 SplineAnimation::~SplineAnimation()
38 {
38 {
39 }
39 }
40
40
41 void SplineAnimation::setup(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldControlPoints, QVector<QPointF> &newControlPoints, int index)
41 void SplineAnimation::setup(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldControlPoints, QVector<QPointF> &newControlPoints, int index)
42 {
42 {
43 if (newPoints.count() * 2 - 2 != newControlPoints.count() || newControlPoints.count() < 2) {
43 if (newPoints.count() * 2 - 2 != newControlPoints.count() || newControlPoints.count() < 2) {
44 m_valid = false;
44 m_valid = false;
45 m_dirty = false;
45 m_dirty = false;
46 m_item->setGeometryPoints(newPoints);
46 m_item->setGeometryPoints(newPoints);
47 m_item->setControlGeometryPoints(newControlPoints);
47 m_item->setControlGeometryPoints(newControlPoints);
48 m_item->setDirty(false);
48 m_item->setDirty(false);
49 m_item->updateGeometry();
49 m_item->updateGeometry();
50 return;
50 return;
51 }
51 }
52
52
53 m_type = NewAnimation;
53 m_type = NewAnimation;
54
54
55 if (state() != QAbstractAnimation::Stopped) {
55 if (state() != QAbstractAnimation::Stopped) {
56 stop();
56 stop();
57 m_dirty = false;
57 m_dirty = false;
58 }
58 }
59
59
60 if (!m_dirty) {
60 if (!m_dirty) {
61 m_dirty = true;
61 m_dirty = true;
62 m_oldSpline.first = oldPoints;
62 m_oldSpline.first = oldPoints;
63 m_oldSpline.second = oldControlPoints;
63 m_oldSpline.second = oldControlPoints;
64 }
64 }
65
65
66 m_newSpline.first = newPoints;
66 m_newSpline.first = newPoints;
67 m_newSpline.second = newControlPoints;
67 m_newSpline.second = newControlPoints;
68
68
69
69
70 int x = m_oldSpline.first.count();
70 int x = m_oldSpline.first.count();
71 int y = m_newSpline.first.count();
71 int y = m_newSpline.first.count();
72
72
73 if (x - y == 1 && index >= 0 && y > 0) {
73 if (x - y == 1 && index >= 0 && y > 0) {
74 //remove point
74 //remove point
75 if (index > 0) {
75 if (index > 0) {
76 m_newSpline.first.insert(index, newPoints[index - 1]);
76 m_newSpline.first.insert(index, newPoints[index - 1]);
77 m_newSpline.second.insert((index - 1) * 2, newPoints[index - 1]);
77 m_newSpline.second.insert((index - 1) * 2, newPoints[index - 1]);
78 m_newSpline.second.insert((index - 1) * 2 + 1, newPoints[index - 1]);
78 m_newSpline.second.insert((index - 1) * 2 + 1, newPoints[index - 1]);
79 } else {
79 } else {
80 m_newSpline.first.insert(index, newPoints[index]);
80 m_newSpline.first.insert(index, newPoints[index]);
81 m_newSpline.second.insert(index * 2, newPoints[index]);
81 m_newSpline.second.insert(index * 2, newPoints[index]);
82 m_newSpline.second.insert(index * 2 + 1, newPoints[index]);
82 m_newSpline.second.insert(index * 2 + 1, newPoints[index]);
83 }
83 }
84 m_index = index;
84 m_index = index;
85 m_type = RemovePointAnimation;
85 m_type = RemovePointAnimation;
86 }
86 }
87
87
88 if (x - y == -1 && index >= 0) {
88 if (x - y == -1 && index >= 0) {
89 //add point
89 //add point
90 if (index > 0) {
90 if (index > 0) {
91 m_oldSpline.first.insert(index, newPoints[index - 1]);
91 m_oldSpline.first.insert(index, newPoints[index - 1]);
92 m_oldSpline.second.insert((index - 1) * 2, newPoints[index - 1]);
92 m_oldSpline.second.insert((index - 1) * 2, newPoints[index - 1]);
93 m_oldSpline.second.insert((index - 1) * 2 + 1, newPoints[index - 1]);
93 m_oldSpline.second.insert((index - 1) * 2 + 1, newPoints[index - 1]);
94 } else {
94 } else {
95 m_oldSpline.first.insert(index, newPoints[index]);
95 m_oldSpline.first.insert(index, newPoints[index]);
96 m_oldSpline.second.insert((index - 1) * 2, newPoints[index]);
96 m_oldSpline.second.insert((index - 1) * 2, newPoints[index]);
97 m_oldSpline.second.insert((index - 1) * 2 + 1, newPoints[index]);
97 m_oldSpline.second.insert((index - 1) * 2 + 1, newPoints[index]);
98 }
98 }
99 m_index = index;
99 m_index = index;
100 m_type = AddPointAnimation;
100 m_type = AddPointAnimation;
101 }
101 }
102
102
103 x = m_oldSpline.first.count();
103 x = m_oldSpline.first.count();
104 y = m_newSpline.first.count();
104 y = m_newSpline.first.count();
105
105
106 if (x != y) {
106 if (x != y) {
107 m_type = NewAnimation;
107 m_type = NewAnimation;
108 } else if (m_type == NewAnimation) {
108 } else if (m_type == NewAnimation) {
109 m_type = ReplacePointAnimation;
109 m_type = ReplacePointAnimation;
110 }
110 }
111
111
112
112
113 setKeyValueAt(0.0, qVariantFromValue(m_oldSpline));
113 setKeyValueAt(0.0, qVariantFromValue(m_oldSpline));
114 setKeyValueAt(1.0, qVariantFromValue(m_newSpline));
114 setKeyValueAt(1.0, qVariantFromValue(m_newSpline));
115
115
116 m_valid = true;
116 m_valid = true;
117
117
118 }
118 }
119
119
120 QVariant SplineAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const
120 QVariant SplineAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const
121 {
121 {
122
122
123 SplineVector startPair = qVariantValue< SplineVector >(start);
123 SplineVector startPair = qvariant_cast< SplineVector >(start);
124 SplineVector endPair = qVariantValue< SplineVector >(end);
124 SplineVector endPair = qvariant_cast< SplineVector >(end);
125 SplineVector result;
125 SplineVector result;
126
126
127 switch (animationType()) {
127 switch (animationType()) {
128 case RemovePointAnimation:
128 case RemovePointAnimation:
129 case AddPointAnimation:
129 case AddPointAnimation:
130 case ReplacePointAnimation: {
130 case ReplacePointAnimation: {
131 if (startPair.first.count() != endPair.first.count())
131 if (startPair.first.count() != endPair.first.count())
132 break;
132 break;
133 Q_ASSERT(startPair.first.count() * 2 - 2 == startPair.second.count());
133 Q_ASSERT(startPair.first.count() * 2 - 2 == startPair.second.count());
134 Q_ASSERT(endPair.first.count() * 2 - 2 == endPair.second.count());
134 Q_ASSERT(endPair.first.count() * 2 - 2 == endPair.second.count());
135 for (int i = 0; i < endPair.first.count(); i++) {
135 for (int i = 0; i < endPair.first.count(); i++) {
136 qreal x = startPair.first[i].x() + ((endPair.first[i].x() - startPair.first[i].x()) * progress);
136 qreal x = startPair.first[i].x() + ((endPair.first[i].x() - startPair.first[i].x()) * progress);
137 qreal y = startPair.first[i].y() + ((endPair.first[i].y() - startPair.first[i].y()) * progress);
137 qreal y = startPair.first[i].y() + ((endPair.first[i].y() - startPair.first[i].y()) * progress);
138 result.first << QPointF(x, y);
138 result.first << QPointF(x, y);
139 if (i + 1 >= endPair.first.count())
139 if (i + 1 >= endPair.first.count())
140 continue;
140 continue;
141 x = startPair.second[i * 2].x() + ((endPair.second[i * 2].x() - startPair.second[i * 2].x()) * progress);
141 x = startPair.second[i * 2].x() + ((endPair.second[i * 2].x() - startPair.second[i * 2].x()) * progress);
142 y = startPair.second[i * 2].y() + ((endPair.second[i * 2].y() - startPair.second[i * 2].y()) * progress);
142 y = startPair.second[i * 2].y() + ((endPair.second[i * 2].y() - startPair.second[i * 2].y()) * progress);
143 result.second << QPointF(x, y);
143 result.second << QPointF(x, y);
144 x = startPair.second[i * 2 + 1].x() + ((endPair.second[i * 2 + 1].x() - startPair.second[i * 2 + 1].x()) * progress);
144 x = startPair.second[i * 2 + 1].x() + ((endPair.second[i * 2 + 1].x() - startPair.second[i * 2 + 1].x()) * progress);
145 y = startPair.second[i * 2 + 1].y() + ((endPair.second[i * 2 + 1].y() - startPair.second[i * 2 + 1].y()) * progress);
145 y = startPair.second[i * 2 + 1].y() + ((endPair.second[i * 2 + 1].y() - startPair.second[i * 2 + 1].y()) * progress);
146 result.second << QPointF(x, y);
146 result.second << QPointF(x, y);
147 }
147 }
148 }
148 }
149 break;
149 break;
150 case NewAnimation: {
150 case NewAnimation: {
151 Q_ASSERT(endPair.first.count() * 2 - 2 == endPair.second.count());
151 Q_ASSERT(endPair.first.count() * 2 - 2 == endPair.second.count());
152 int count = endPair.first.count() * qBound(qreal(0), progress, qreal(1));
152 int count = endPair.first.count() * qBound(qreal(0), progress, qreal(1));
153 for (int i = 0; i < count; i++) {
153 for (int i = 0; i < count; i++) {
154 result.first << endPair.first[i];
154 result.first << endPair.first[i];
155 if (i + 1 == count)
155 if (i + 1 == count)
156 break;
156 break;
157 result.second << endPair.second[2 * i];
157 result.second << endPair.second[2 * i];
158 result.second << endPair.second[2 * i + 1];
158 result.second << endPair.second[2 * i + 1];
159 }
159 }
160 }
160 }
161 break;
161 break;
162 default:
162 default:
163 qWarning() << "Unknown type of animation";
163 qWarning() << "Unknown type of animation";
164 break;
164 break;
165 }
165 }
166
166
167 return qVariantFromValue(result);
167 return qVariantFromValue(result);
168 }
168 }
169
169
170 void SplineAnimation::updateCurrentValue(const QVariant &value)
170 void SplineAnimation::updateCurrentValue(const QVariant &value)
171 {
171 {
172 if (state() != QAbstractAnimation::Stopped && m_valid) { //workaround
172 if (state() != QAbstractAnimation::Stopped && m_valid) { //workaround
173 QPair<QVector<QPointF >, QVector<QPointF > > pair = qVariantValue< QPair< QVector<QPointF>, QVector<QPointF> > >(value);
173 QPair<QVector<QPointF >, QVector<QPointF > > pair = qvariant_cast< QPair< QVector<QPointF>, QVector<QPointF> > >(value);
174 m_item->setGeometryPoints(pair.first);
174 m_item->setGeometryPoints(pair.first);
175 m_item->setControlGeometryPoints(pair.second);
175 m_item->setControlGeometryPoints(pair.second);
176 m_item->updateGeometry();
176 m_item->updateGeometry();
177 m_item->setDirty(true);
177 m_item->setDirty(true);
178 m_dirty = false;
178 m_dirty = false;
179 }
179 }
180 }
180 }
181
181
182 void SplineAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
182 void SplineAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
183 {
183 {
184 XYAnimation::updateState(newState, oldState);
184 XYAnimation::updateState(newState, oldState);
185
185
186 if (oldState == QAbstractAnimation::Running && newState == QAbstractAnimation::Stopped) {
186 if (oldState == QAbstractAnimation::Running && newState == QAbstractAnimation::Stopped) {
187 if (m_item->isDirty() && m_type == RemovePointAnimation) {
187 if (m_item->isDirty() && m_type == RemovePointAnimation) {
188 if (!m_newSpline.first.isEmpty()) {
188 if (!m_newSpline.first.isEmpty()) {
189 m_newSpline.first.remove(m_index);
189 m_newSpline.first.remove(m_index);
190 m_newSpline.second.remove((m_index - 1) * 2);
190 m_newSpline.second.remove((m_index - 1) * 2);
191 m_newSpline.second.remove((m_index - 1) * 2);
191 m_newSpline.second.remove((m_index - 1) * 2);
192 }
192 }
193 m_item->setGeometryPoints(m_newSpline.first);
193 m_item->setGeometryPoints(m_newSpline.first);
194 m_item->setControlGeometryPoints(m_newSpline.second);
194 m_item->setControlGeometryPoints(m_newSpline.second);
195 }
195 }
196 }
196 }
197
197
198 if (oldState == QAbstractAnimation::Stopped && newState == QAbstractAnimation::Running) {
198 if (oldState == QAbstractAnimation::Stopped && newState == QAbstractAnimation::Running) {
199 if (!m_valid)
199 if (!m_valid)
200 stop();
200 stop();
201 }
201 }
202 }
202 }
203
203
204 QTCOMMERCIALCHART_END_NAMESPACE
204 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 = qvariant_cast<QVector<QRectF> >(from);
42 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
42 QVector<QRectF> endVector = qvariant_cast<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.normalized();
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
@@ -1,149 +1,149
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 "xyanimation_p.h"
21 #include "xyanimation_p.h"
22 #include "xychart_p.h"
22 #include "xychart_p.h"
23 #include <QDebug>
23 #include <QDebug>
24
24
25 Q_DECLARE_METATYPE(QVector<QPointF>)
25 Q_DECLARE_METATYPE(QVector<QPointF>)
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 XYAnimation::XYAnimation(XYChart *item)
29 XYAnimation::XYAnimation(XYChart *item)
30 : ChartAnimation(item),
30 : ChartAnimation(item),
31 m_type(NewAnimation),
31 m_type(NewAnimation),
32 m_dirty(false),
32 m_dirty(false),
33 m_index(-1),
33 m_index(-1),
34 m_item(item)
34 m_item(item)
35 {
35 {
36 setDuration(ChartAnimationDuration);
36 setDuration(ChartAnimationDuration);
37 setEasingCurve(QEasingCurve::OutQuart);
37 setEasingCurve(QEasingCurve::OutQuart);
38 }
38 }
39
39
40 XYAnimation::~XYAnimation()
40 XYAnimation::~XYAnimation()
41 {
41 {
42 }
42 }
43
43
44 void XYAnimation::setup(const QVector<QPointF> &oldPoints, const QVector<QPointF> &newPoints, int index)
44 void XYAnimation::setup(const QVector<QPointF> &oldPoints, const QVector<QPointF> &newPoints, int index)
45 {
45 {
46 m_type = NewAnimation;
46 m_type = NewAnimation;
47
47
48 if (state() != QAbstractAnimation::Stopped) {
48 if (state() != QAbstractAnimation::Stopped) {
49 stop();
49 stop();
50 m_dirty = false;
50 m_dirty = false;
51 }
51 }
52
52
53 if (!m_dirty) {
53 if (!m_dirty) {
54 m_dirty = true;
54 m_dirty = true;
55 m_oldPoints = oldPoints;
55 m_oldPoints = oldPoints;
56 }
56 }
57
57
58 m_newPoints = newPoints;
58 m_newPoints = newPoints;
59
59
60 int x = m_oldPoints.count();
60 int x = m_oldPoints.count();
61 int y = m_newPoints.count();
61 int y = m_newPoints.count();
62
62
63 if (x - y == 1 && index >= 0 && y > 0) {
63 if (x - y == 1 && index >= 0 && y > 0) {
64 //remove point
64 //remove point
65 m_newPoints.insert(index, index > 0 ? newPoints[index - 1] : newPoints[index]);
65 m_newPoints.insert(index, index > 0 ? newPoints[index - 1] : newPoints[index]);
66 m_index = index;
66 m_index = index;
67 m_type = RemovePointAnimation;
67 m_type = RemovePointAnimation;
68 }
68 }
69
69
70 if (x - y == -1 && index >= 0) {
70 if (x - y == -1 && index >= 0) {
71 //add point
71 //add point
72 m_oldPoints.insert(index, index > 0 ? newPoints[index - 1] : newPoints[index]);
72 m_oldPoints.insert(index, index > 0 ? newPoints[index - 1] : newPoints[index]);
73 m_index = index;
73 m_index = index;
74 m_type = AddPointAnimation;
74 m_type = AddPointAnimation;
75 }
75 }
76
76
77 x = m_oldPoints.count();
77 x = m_oldPoints.count();
78 y = m_newPoints.count();
78 y = m_newPoints.count();
79
79
80 if (x != y)
80 if (x != y)
81 m_type = NewAnimation;
81 m_type = NewAnimation;
82 else if (m_type == NewAnimation)
82 else if (m_type == NewAnimation)
83 m_type = ReplacePointAnimation;
83 m_type = ReplacePointAnimation;
84
84
85 setKeyValueAt(0.0, qVariantFromValue(m_oldPoints));
85 setKeyValueAt(0.0, qVariantFromValue(m_oldPoints));
86 setKeyValueAt(1.0, qVariantFromValue(m_newPoints));
86 setKeyValueAt(1.0, qVariantFromValue(m_newPoints));
87 }
87 }
88
88
89 QVariant XYAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const
89 QVariant XYAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const
90 {
90 {
91 QVector<QPointF> startVector = qVariantValue<QVector<QPointF> >(start);
91 QVector<QPointF> startVector = qvariant_cast<QVector<QPointF> >(start);
92 QVector<QPointF> endVector = qVariantValue<QVector<QPointF> >(end);
92 QVector<QPointF> endVector = qvariant_cast<QVector<QPointF> >(end);
93 QVector<QPointF> result;
93 QVector<QPointF> result;
94
94
95 switch (m_type) {
95 switch (m_type) {
96
96
97 case ReplacePointAnimation:
97 case ReplacePointAnimation:
98 case AddPointAnimation:
98 case AddPointAnimation:
99 case RemovePointAnimation: {
99 case RemovePointAnimation: {
100 if (startVector.count() != endVector.count())
100 if (startVector.count() != endVector.count())
101 break;
101 break;
102
102
103 for (int i = 0; i < startVector.count(); i++) {
103 for (int i = 0; i < startVector.count(); i++) {
104 qreal x = startVector[i].x() + ((endVector[i].x() - startVector[i].x()) * progress);
104 qreal x = startVector[i].x() + ((endVector[i].x() - startVector[i].x()) * progress);
105 qreal y = startVector[i].y() + ((endVector[i].y() - startVector[i].y()) * progress);
105 qreal y = startVector[i].y() + ((endVector[i].y() - startVector[i].y()) * progress);
106 result << QPointF(x, y);
106 result << QPointF(x, y);
107 }
107 }
108
108
109 }
109 }
110 break;
110 break;
111 case NewAnimation: {
111 case NewAnimation: {
112 for (int i = 0; i < endVector.count() * qBound(qreal(0), progress, qreal(1)); i++)
112 for (int i = 0; i < endVector.count() * qBound(qreal(0), progress, qreal(1)); i++)
113 result << endVector[i];
113 result << endVector[i];
114 }
114 }
115 break;
115 break;
116 default:
116 default:
117 qWarning() << "Unknown type of animation";
117 qWarning() << "Unknown type of animation";
118 break;
118 break;
119 }
119 }
120
120
121 return qVariantFromValue(result);
121 return qVariantFromValue(result);
122 }
122 }
123
123
124 void XYAnimation::updateCurrentValue(const QVariant &value)
124 void XYAnimation::updateCurrentValue(const QVariant &value)
125 {
125 {
126 if (state() != QAbstractAnimation::Stopped) { //workaround
126 if (state() != QAbstractAnimation::Stopped) { //workaround
127
127
128 QVector<QPointF> vector = qVariantValue<QVector<QPointF> >(value);
128 QVector<QPointF> vector = qvariant_cast<QVector<QPointF> >(value);
129 m_item->setGeometryPoints(vector);
129 m_item->setGeometryPoints(vector);
130 m_item->updateGeometry();
130 m_item->updateGeometry();
131 m_item->setDirty(true);
131 m_item->setDirty(true);
132 m_dirty = false;
132 m_dirty = false;
133
133
134 }
134 }
135 }
135 }
136
136
137 void XYAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
137 void XYAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
138 {
138 {
139 if (oldState == QAbstractAnimation::Running && newState == QAbstractAnimation::Stopped) {
139 if (oldState == QAbstractAnimation::Running && newState == QAbstractAnimation::Stopped) {
140 if (m_item->isDirty() && m_type == RemovePointAnimation) {
140 if (m_item->isDirty() && m_type == RemovePointAnimation) {
141 if (!m_newPoints.isEmpty())
141 if (!m_newPoints.isEmpty())
142 m_newPoints.remove(m_index);
142 m_newPoints.remove(m_index);
143 m_item->setGeometryPoints(m_newPoints);
143 m_item->setGeometryPoints(m_newPoints);
144 }
144 }
145 }
145 }
146 }
146 }
147
147
148 #include "moc_chartanimation_p.cpp"
148 #include "moc_chartanimation_p.cpp"
149 QTCOMMERCIALCHART_END_NAMESPACE
149 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,476 +1,476
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 "chartaxis_p.h"
21 #include "chartaxis_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "qabstractaxis_p.h"
23 #include "qabstractaxis_p.h"
24 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
25 #include "chartlayout_p.h"
25 #include "chartlayout_p.h"
26 #include "domain_p.h"
26 #include "domain_p.h"
27 #include <qmath.h>
27 #include <qmath.h>
28 #include <QDateTime>
28 #include <QDateTime>
29 #include <QValueAxis>
29 #include <QValueAxis>
30 #include <QGraphicsLayout>
30 #include <QGraphicsLayout>
31 #include <QFontMetrics>
31 #include <QFontMetrics>
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 ChartAxis::ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis)
35 ChartAxis::ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis)
36 : ChartElement(presenter),
36 : ChartElement(presenter),
37 m_chartAxis(axis),
37 m_chartAxis(axis),
38 m_labelsAngle(0),
38 m_labelsAngle(0),
39 m_grid(new QGraphicsItemGroup(presenter->rootItem())),
39 m_grid(new QGraphicsItemGroup(presenter->rootItem())),
40 m_shades(new QGraphicsItemGroup(presenter->rootItem())),
40 m_shades(new QGraphicsItemGroup(presenter->rootItem())),
41 m_labels(new QGraphicsItemGroup(presenter->rootItem())),
41 m_labels(new QGraphicsItemGroup(presenter->rootItem())),
42 m_arrow(new QGraphicsItemGroup(presenter->rootItem())),
42 m_arrow(new QGraphicsItemGroup(presenter->rootItem())),
43 m_title(new QGraphicsSimpleTextItem(presenter->rootItem())),
43 m_title(new QGraphicsSimpleTextItem(presenter->rootItem())),
44 m_min(0),
44 m_min(0),
45 m_max(0),
45 m_max(0),
46 m_animation(0),
46 m_animation(0),
47 m_labelPadding(5),
47 m_labelPadding(5),
48 m_intervalAxis(intervalAxis)
48 m_intervalAxis(intervalAxis)
49 {
49 {
50 //initial initialization
50 //initial initialization
51 m_arrow->setZValue(ChartPresenter::AxisZValue);
51 m_arrow->setZValue(ChartPresenter::AxisZValue);
52 m_arrow->setHandlesChildEvents(false);
52 m_arrow->setHandlesChildEvents(false);
53 m_labels->setZValue(ChartPresenter::AxisZValue);
53 m_labels->setZValue(ChartPresenter::AxisZValue);
54 m_shades->setZValue(ChartPresenter::ShadesZValue);
54 m_shades->setZValue(ChartPresenter::ShadesZValue);
55 m_grid->setZValue(ChartPresenter::GridZValue);
55 m_grid->setZValue(ChartPresenter::GridZValue);
56 m_title->setZValue(ChartPresenter::GridZValue);
56 m_title->setZValue(ChartPresenter::GridZValue);
57
57
58 QObject::connect(m_chartAxis->d_ptr.data(), SIGNAL(updated()), this, SLOT(handleAxisUpdated()));
58 QObject::connect(m_chartAxis->d_ptr.data(), SIGNAL(updated()), this, SLOT(handleAxisUpdated()));
59
59
60 QGraphicsSimpleTextItem item;
60 QGraphicsSimpleTextItem item;
61 m_font = item.font();
61 m_font = item.font();
62
62
63 }
63 }
64
64
65 ChartAxis::~ChartAxis()
65 ChartAxis::~ChartAxis()
66 {
66 {
67 }
67 }
68
68
69 void ChartAxis::setAnimation(AxisAnimation *animation)
69 void ChartAxis::setAnimation(AxisAnimation *animation)
70 {
70 {
71 m_animation = animation;
71 m_animation = animation;
72 }
72 }
73
73
74 void ChartAxis::setLayout(QVector<qreal> &layout)
74 void ChartAxis::setLayout(QVector<qreal> &layout)
75 {
75 {
76 m_layoutVector = layout;
76 m_layoutVector = layout;
77 }
77 }
78
78
79 void ChartAxis::createItems(int count)
79 void ChartAxis::createItems(int count)
80 {
80 {
81 if (m_arrow->children().size() == 0)
81 if (m_arrow->childItems().size() == 0)
82 m_arrow->addToGroup(new AxisItem(this, presenter()->rootItem()));
82 m_arrow->addToGroup(new AxisItem(this, presenter()->rootItem()));
83
83
84 if (m_intervalAxis && m_grid->children().size() == 0) {
84 if (m_intervalAxis && m_grid->childItems().size() == 0) {
85 for (int i = 0 ; i < 2 ; i ++)
85 for (int i = 0 ; i < 2 ; i ++)
86 m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
86 m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
87 }
87 }
88
88
89 for (int i = 0; i < count; ++i) {
89 for (int i = 0; i < count; ++i) {
90 m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
90 m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
91 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(presenter()->rootItem());
91 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(presenter()->rootItem());
92 label->setFont(m_font);
92 label->setFont(m_font);
93 m_labels->addToGroup(label);
93 m_labels->addToGroup(label);
94 m_arrow->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
94 m_arrow->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
95 if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2)
95 if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2)
96 m_shades->addToGroup(new QGraphicsRectItem(presenter()->rootItem()));
96 m_shades->addToGroup(new QGraphicsRectItem(presenter()->rootItem()));
97 }
97 }
98 }
98 }
99
99
100 void ChartAxis::deleteItems(int count)
100 void ChartAxis::deleteItems(int count)
101 {
101 {
102 QList<QGraphicsItem *> lines = m_grid->childItems();
102 QList<QGraphicsItem *> lines = m_grid->childItems();
103 QList<QGraphicsItem *> labels = m_labels->childItems();
103 QList<QGraphicsItem *> labels = m_labels->childItems();
104 QList<QGraphicsItem *> shades = m_shades->childItems();
104 QList<QGraphicsItem *> shades = m_shades->childItems();
105 QList<QGraphicsItem *> axis = m_arrow->childItems();
105 QList<QGraphicsItem *> axis = m_arrow->childItems();
106
106
107 for (int i = 0; i < count; ++i) {
107 for (int i = 0; i < count; ++i) {
108 if (lines.size() % 2 && lines.size() > 1)
108 if (lines.size() % 2 && lines.size() > 1)
109 delete(shades.takeLast());
109 delete(shades.takeLast());
110 delete(lines.takeLast());
110 delete(lines.takeLast());
111 delete(labels.takeLast());
111 delete(labels.takeLast());
112 delete(axis.takeLast());
112 delete(axis.takeLast());
113 }
113 }
114 }
114 }
115
115
116 void ChartAxis::updateLayout(QVector<qreal> &layout)
116 void ChartAxis::updateLayout(QVector<qreal> &layout)
117 {
117 {
118 int diff = m_layoutVector.size() - layout.size();
118 int diff = m_layoutVector.size() - layout.size();
119
119
120 if (diff > 0)
120 if (diff > 0)
121 deleteItems(diff);
121 deleteItems(diff);
122 else if (diff < 0)
122 else if (diff < 0)
123 createItems(-diff);
123 createItems(-diff);
124
124
125 if (diff < 0) handleAxisUpdated();
125 if (diff < 0) handleAxisUpdated();
126
126
127 if (m_animation) {
127 if (m_animation) {
128 switch (presenter()->state()) {
128 switch (presenter()->state()) {
129 case ChartPresenter::ZoomInState:
129 case ChartPresenter::ZoomInState:
130 m_animation->setAnimationType(AxisAnimation::ZoomInAnimation);
130 m_animation->setAnimationType(AxisAnimation::ZoomInAnimation);
131 m_animation->setAnimationPoint(presenter()->statePoint());
131 m_animation->setAnimationPoint(presenter()->statePoint());
132 break;
132 break;
133 case ChartPresenter::ZoomOutState:
133 case ChartPresenter::ZoomOutState:
134 m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation);
134 m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation);
135 m_animation->setAnimationPoint(presenter()->statePoint());
135 m_animation->setAnimationPoint(presenter()->statePoint());
136 break;
136 break;
137 case ChartPresenter::ScrollUpState:
137 case ChartPresenter::ScrollUpState:
138 case ChartPresenter::ScrollLeftState:
138 case ChartPresenter::ScrollLeftState:
139 m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation);
139 m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation);
140 break;
140 break;
141 case ChartPresenter::ScrollDownState:
141 case ChartPresenter::ScrollDownState:
142 case ChartPresenter::ScrollRightState:
142 case ChartPresenter::ScrollRightState:
143 m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation);
143 m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation);
144 break;
144 break;
145 case ChartPresenter::ShowState:
145 case ChartPresenter::ShowState:
146 m_animation->setAnimationType(AxisAnimation::DefaultAnimation);
146 m_animation->setAnimationType(AxisAnimation::DefaultAnimation);
147 break;
147 break;
148 }
148 }
149 m_animation->setValues(m_layoutVector, layout);
149 m_animation->setValues(m_layoutVector, layout);
150 presenter()->startAnimation(m_animation);
150 presenter()->startAnimation(m_animation);
151 } else {
151 } else {
152 setLayout(layout);
152 setLayout(layout);
153 updateGeometry();
153 updateGeometry();
154 }
154 }
155 }
155 }
156
156
157 void ChartAxis::setArrowOpacity(qreal opacity)
157 void ChartAxis::setArrowOpacity(qreal opacity)
158 {
158 {
159 m_arrow->setOpacity(opacity);
159 m_arrow->setOpacity(opacity);
160 }
160 }
161
161
162 qreal ChartAxis::arrowOpacity() const
162 qreal ChartAxis::arrowOpacity() const
163 {
163 {
164 return m_arrow->opacity();
164 return m_arrow->opacity();
165 }
165 }
166
166
167 void ChartAxis::setArrowVisibility(bool visible)
167 void ChartAxis::setArrowVisibility(bool visible)
168 {
168 {
169 m_arrow->setOpacity(visible);
169 m_arrow->setOpacity(visible);
170 }
170 }
171
171
172 void ChartAxis::setGridOpacity(qreal opacity)
172 void ChartAxis::setGridOpacity(qreal opacity)
173 {
173 {
174 m_grid->setOpacity(opacity);
174 m_grid->setOpacity(opacity);
175 }
175 }
176
176
177 qreal ChartAxis::gridOpacity() const
177 qreal ChartAxis::gridOpacity() const
178 {
178 {
179 return m_grid->opacity();
179 return m_grid->opacity();
180 }
180 }
181
181
182 void ChartAxis::setGridVisibility(bool visible)
182 void ChartAxis::setGridVisibility(bool visible)
183 {
183 {
184 m_grid->setOpacity(visible);
184 m_grid->setOpacity(visible);
185 }
185 }
186
186
187 void ChartAxis::setLabelsOpacity(qreal opacity)
187 void ChartAxis::setLabelsOpacity(qreal opacity)
188 {
188 {
189 m_labels->setOpacity(opacity);
189 m_labels->setOpacity(opacity);
190 }
190 }
191
191
192 qreal ChartAxis::labelsOpacity() const
192 qreal ChartAxis::labelsOpacity() const
193 {
193 {
194 return m_labels->opacity();
194 return m_labels->opacity();
195 }
195 }
196
196
197 void ChartAxis::setLabelsVisibility(bool visible)
197 void ChartAxis::setLabelsVisibility(bool visible)
198 {
198 {
199 m_labels->setOpacity(visible);
199 m_labels->setOpacity(visible);
200 }
200 }
201
201
202 void ChartAxis::setShadesOpacity(qreal opacity)
202 void ChartAxis::setShadesOpacity(qreal opacity)
203 {
203 {
204 m_shades->setOpacity(opacity);
204 m_shades->setOpacity(opacity);
205 }
205 }
206
206
207 qreal ChartAxis::shadesOpacity() const
207 qreal ChartAxis::shadesOpacity() const
208 {
208 {
209 return m_shades->opacity();
209 return m_shades->opacity();
210 }
210 }
211
211
212 void ChartAxis::setShadesVisibility(bool visible)
212 void ChartAxis::setShadesVisibility(bool visible)
213 {
213 {
214 m_shades->setVisible(visible);
214 m_shades->setVisible(visible);
215 }
215 }
216
216
217 void ChartAxis::setLabelsAngle(int angle)
217 void ChartAxis::setLabelsAngle(int angle)
218 {
218 {
219 foreach (QGraphicsItem *item, m_labels->childItems())
219 foreach (QGraphicsItem *item, m_labels->childItems())
220 item->setRotation(angle);
220 item->setRotation(angle);
221
221
222 m_labelsAngle = angle;
222 m_labelsAngle = angle;
223 }
223 }
224
224
225 void ChartAxis::setLabelsPen(const QPen &pen)
225 void ChartAxis::setLabelsPen(const QPen &pen)
226 {
226 {
227 foreach (QGraphicsItem *item , m_labels->childItems())
227 foreach (QGraphicsItem *item , m_labels->childItems())
228 static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen);
228 static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen);
229 }
229 }
230
230
231 void ChartAxis::setLabelsBrush(const QBrush &brush)
231 void ChartAxis::setLabelsBrush(const QBrush &brush)
232 {
232 {
233 foreach (QGraphicsItem *item , m_labels->childItems())
233 foreach (QGraphicsItem *item , m_labels->childItems())
234 static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush);
234 static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush);
235 }
235 }
236
236
237 void ChartAxis::setLabelsFont(const QFont &font)
237 void ChartAxis::setLabelsFont(const QFont &font)
238 {
238 {
239 if (m_font != font) {
239 if (m_font != font) {
240 m_font = font;
240 m_font = font;
241 foreach (QGraphicsItem *item , m_labels->childItems())
241 foreach (QGraphicsItem *item , m_labels->childItems())
242 static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font);
242 static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font);
243 QGraphicsLayoutItem::updateGeometry();
243 QGraphicsLayoutItem::updateGeometry();
244 presenter()->layout()->invalidate();
244 presenter()->layout()->invalidate();
245 }
245 }
246 }
246 }
247
247
248 void ChartAxis::setShadesBrush(const QBrush &brush)
248 void ChartAxis::setShadesBrush(const QBrush &brush)
249 {
249 {
250 foreach (QGraphicsItem *item , m_shades->childItems())
250 foreach (QGraphicsItem *item , m_shades->childItems())
251 static_cast<QGraphicsRectItem *>(item)->setBrush(brush);
251 static_cast<QGraphicsRectItem *>(item)->setBrush(brush);
252 }
252 }
253
253
254 void ChartAxis::setShadesPen(const QPen &pen)
254 void ChartAxis::setShadesPen(const QPen &pen)
255 {
255 {
256 foreach (QGraphicsItem *item , m_shades->childItems())
256 foreach (QGraphicsItem *item , m_shades->childItems())
257 static_cast<QGraphicsRectItem *>(item)->setPen(pen);
257 static_cast<QGraphicsRectItem *>(item)->setPen(pen);
258 }
258 }
259
259
260 void ChartAxis::setArrowPen(const QPen &pen)
260 void ChartAxis::setArrowPen(const QPen &pen)
261 {
261 {
262 foreach (QGraphicsItem *item , m_arrow->childItems())
262 foreach (QGraphicsItem *item , m_arrow->childItems())
263 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
263 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
264 }
264 }
265
265
266 void ChartAxis::setGridPen(const QPen &pen)
266 void ChartAxis::setGridPen(const QPen &pen)
267 {
267 {
268 foreach (QGraphicsItem *item , m_grid->childItems())
268 foreach (QGraphicsItem *item , m_grid->childItems())
269 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
269 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
270 }
270 }
271
271
272 void ChartAxis::setLabelPadding(int padding)
272 void ChartAxis::setLabelPadding(int padding)
273 {
273 {
274 m_labelPadding = padding;
274 m_labelPadding = padding;
275 }
275 }
276
276
277 bool ChartAxis::isEmpty()
277 bool ChartAxis::isEmpty()
278 {
278 {
279 return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyIsNull(m_min - m_max);
279 return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyIsNull(m_min - m_max);
280 }
280 }
281
281
282 void ChartAxis::handleDomainUpdated()
282 void ChartAxis::handleDomainUpdated()
283 {
283 {
284 Domain *domain = qobject_cast<Domain *>(sender());
284 Domain *domain = qobject_cast<Domain *>(sender());
285 qreal min(0);
285 qreal min(0);
286 qreal max(0);
286 qreal max(0);
287
287
288 if (m_chartAxis->orientation() == Qt::Horizontal) {
288 if (m_chartAxis->orientation() == Qt::Horizontal) {
289 min = domain->minX();
289 min = domain->minX();
290 max = domain->maxX();
290 max = domain->maxX();
291 } else if (m_chartAxis->orientation() == Qt::Vertical) {
291 } else if (m_chartAxis->orientation() == Qt::Vertical) {
292 min = domain->minY();
292 min = domain->minY();
293 max = domain->maxY();
293 max = domain->maxY();
294 }
294 }
295
295
296 if (!qFuzzyIsNull(m_min - min) || !qFuzzyIsNull(m_max - max)) {
296 if (!qFuzzyIsNull(m_min - min) || !qFuzzyIsNull(m_max - max)) {
297 m_min = min;
297 m_min = min;
298 m_max = max;
298 m_max = max;
299
299
300 if (!isEmpty()) {
300 if (!isEmpty()) {
301
301
302 QVector<qreal> layout = calculateLayout();
302 QVector<qreal> layout = calculateLayout();
303 updateLayout(layout);
303 updateLayout(layout);
304 QSizeF before = effectiveSizeHint(Qt::PreferredSize);
304 QSizeF before = effectiveSizeHint(Qt::PreferredSize);
305 QSizeF after = sizeHint(Qt::PreferredSize);
305 QSizeF after = sizeHint(Qt::PreferredSize);
306
306
307 if (before != after) {
307 if (before != after) {
308 QGraphicsLayoutItem::updateGeometry();
308 QGraphicsLayoutItem::updateGeometry();
309 //we don't want to call invalidate on layout, since it will change minimum size of component,
309 //we don't want to call invalidate on layout, since it will change minimum size of component,
310 //which we would like to avoid since it causes nasty flips when scrolling or zooming,
310 //which we would like to avoid since it causes nasty flips when scrolling or zooming,
311 //instead recalculate layout and use plotArea for extra space.
311 //instead recalculate layout and use plotArea for extra space.
312 presenter()->layout()->setGeometry(presenter()->layout()->geometry());
312 presenter()->layout()->setGeometry(presenter()->layout()->geometry());
313 }
313 }
314 }
314 }
315 }
315 }
316 }
316 }
317
317
318 void ChartAxis::handleAxisUpdated()
318 void ChartAxis::handleAxisUpdated()
319 {
319 {
320 if (isEmpty())
320 if (isEmpty())
321 return;
321 return;
322
322
323 bool visible = m_chartAxis->isVisible();
323 bool visible = m_chartAxis->isVisible();
324
324
325 //TODO: split this into separate signal/slots ?
325 //TODO: split this into separate signal/slots ?
326 setArrowVisibility(visible && m_chartAxis->isLineVisible());
326 setArrowVisibility(visible && m_chartAxis->isLineVisible());
327 setGridVisibility(visible && m_chartAxis->isGridLineVisible());
327 setGridVisibility(visible && m_chartAxis->isGridLineVisible());
328 setLabelsVisibility(visible && m_chartAxis->labelsVisible());
328 setLabelsVisibility(visible && m_chartAxis->labelsVisible());
329 setShadesVisibility(visible && m_chartAxis->shadesVisible());
329 setShadesVisibility(visible && m_chartAxis->shadesVisible());
330 setLabelsAngle(m_chartAxis->labelsAngle());
330 setLabelsAngle(m_chartAxis->labelsAngle());
331 setArrowPen(m_chartAxis->linePen());
331 setArrowPen(m_chartAxis->linePen());
332 setLabelsPen(m_chartAxis->labelsPen());
332 setLabelsPen(m_chartAxis->labelsPen());
333 setLabelsBrush(m_chartAxis->labelsBrush());
333 setLabelsBrush(m_chartAxis->labelsBrush());
334 setLabelsFont(m_chartAxis->labelsFont());
334 setLabelsFont(m_chartAxis->labelsFont());
335 setGridPen(m_chartAxis->gridLinePen());
335 setGridPen(m_chartAxis->gridLinePen());
336 setShadesPen(m_chartAxis->shadesPen());
336 setShadesPen(m_chartAxis->shadesPen());
337 setShadesBrush(m_chartAxis->shadesBrush());
337 setShadesBrush(m_chartAxis->shadesBrush());
338 setTitleText(m_chartAxis->title());
338 setTitleText(m_chartAxis->title());
339 setTitleFont(m_chartAxis->titleFont());
339 setTitleFont(m_chartAxis->titleFont());
340 setTitlePen(m_chartAxis->titlePen());
340 setTitlePen(m_chartAxis->titlePen());
341 setTitleBrush(m_chartAxis->titleBrush());
341 setTitleBrush(m_chartAxis->titleBrush());
342 }
342 }
343
343
344 void ChartAxis::setTitleText(const QString &title)
344 void ChartAxis::setTitleText(const QString &title)
345 {
345 {
346 if (m_titleText != title) {
346 if (m_titleText != title) {
347 m_titleText = title;
347 m_titleText = title;
348 QGraphicsLayoutItem::updateGeometry();
348 QGraphicsLayoutItem::updateGeometry();
349 presenter()->layout()->invalidate();
349 presenter()->layout()->invalidate();
350 }
350 }
351 }
351 }
352
352
353 void ChartAxis::setTitlePen(const QPen &pen)
353 void ChartAxis::setTitlePen(const QPen &pen)
354 {
354 {
355 m_title->setPen(pen);
355 m_title->setPen(pen);
356 }
356 }
357
357
358 void ChartAxis::setTitleBrush(const QBrush &brush)
358 void ChartAxis::setTitleBrush(const QBrush &brush)
359 {
359 {
360 m_title->setBrush(brush);
360 m_title->setBrush(brush);
361 }
361 }
362
362
363 void ChartAxis::setTitleFont(const QFont &font)
363 void ChartAxis::setTitleFont(const QFont &font)
364 {
364 {
365 if(m_title->font() != font){
365 if(m_title->font() != font){
366 m_title->setFont(font);
366 m_title->setFont(font);
367 QGraphicsLayoutItem::updateGeometry();
367 QGraphicsLayoutItem::updateGeometry();
368 presenter()->layout()->invalidate();
368 presenter()->layout()->invalidate();
369 }
369 }
370 }
370 }
371
371
372 QFont ChartAxis::titleFont() const
372 QFont ChartAxis::titleFont() const
373 {
373 {
374 return m_title->font();
374 return m_title->font();
375 }
375 }
376
376
377 void ChartAxis::hide()
377 void ChartAxis::hide()
378 {
378 {
379 setArrowVisibility(false);
379 setArrowVisibility(false);
380 setGridVisibility(false);
380 setGridVisibility(false);
381 setLabelsVisibility(false);
381 setLabelsVisibility(false);
382 setShadesVisibility(false);
382 setShadesVisibility(false);
383 }
383 }
384
384
385 void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
385 void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
386 {
386 {
387 m_gridRect = grid;
387 m_gridRect = grid;
388 m_axisRect = axis;
388 m_axisRect = axis;
389
389
390 if (isEmpty())
390 if (isEmpty())
391 return;
391 return;
392
392
393 QVector<qreal> layout = calculateLayout();
393 QVector<qreal> layout = calculateLayout();
394 updateLayout(layout);
394 updateLayout(layout);
395
395
396 }
396 }
397
397
398 void ChartAxis::axisSelected()
398 void ChartAxis::axisSelected()
399 {
399 {
400 //TODO: axis clicked;
400 //TODO: axis clicked;
401 }
401 }
402
402
403 Qt::Orientation ChartAxis::orientation() const
403 Qt::Orientation ChartAxis::orientation() const
404 {
404 {
405 return m_chartAxis->orientation();
405 return m_chartAxis->orientation();
406 }
406 }
407
407
408 Qt::Alignment ChartAxis::alignment() const
408 Qt::Alignment ChartAxis::alignment() const
409 {
409 {
410 return m_chartAxis->alignment();
410 return m_chartAxis->alignment();
411 }
411 }
412
412
413 bool ChartAxis::isVisible()
413 bool ChartAxis::isVisible()
414 {
414 {
415 return m_chartAxis->isVisible();
415 return m_chartAxis->isVisible();
416 }
416 }
417
417
418 void ChartAxis::setLabels(const QStringList &labels)
418 void ChartAxis::setLabels(const QStringList &labels)
419 {
419 {
420 m_labelsList = labels;
420 m_labelsList = labels;
421 }
421 }
422
422
423 QStringList ChartAxis::createValueLabels(int ticks) const
423 QStringList ChartAxis::createValueLabels(int ticks) const
424 {
424 {
425 Q_ASSERT(m_max > m_min);
425 Q_ASSERT(m_max > m_min);
426 Q_ASSERT(ticks > 1);
426 Q_ASSERT(ticks > 1);
427
427
428 QStringList labels;
428 QStringList labels;
429
429
430 int n = qMax(int(-qFloor(log10((m_max - m_min) / (ticks - 1)))), 0);
430 int n = qMax(int(-qFloor(log10((m_max - m_min) / (ticks - 1)))), 0);
431 n++;
431 n++;
432
432
433 QValueAxis *axis = qobject_cast<QValueAxis *>(m_chartAxis);
433 QValueAxis *axis = qobject_cast<QValueAxis *>(m_chartAxis);
434
434
435 QString format = axis->labelFormat();
435 QString format = axis->labelFormat();
436
436
437 if (format.isNull()) {
437 if (format.isNull()) {
438 for (int i = 0; i < ticks; i++) {
438 for (int i = 0; i < ticks; i++) {
439 qreal value = m_min + (i * (m_max - m_min) / (ticks - 1));
439 qreal value = m_min + (i * (m_max - m_min) / (ticks - 1));
440 labels << QString::number(value, 'f', n);
440 labels << QString::number(value, 'f', n);
441 }
441 }
442 } else {
442 } else {
443 QByteArray array = format.toAscii();
443 QByteArray array = format.toLatin1();
444 for (int i = 0; i < ticks; i++) {
444 for (int i = 0; i < ticks; i++) {
445 qreal value = m_min + (i * (m_max - m_min) / (ticks - 1));
445 qreal value = m_min + (i * (m_max - m_min) / (ticks - 1));
446 labels << QString().sprintf(array, value);
446 labels << QString().sprintf(array, value);
447 }
447 }
448 }
448 }
449
449
450 return labels;
450 return labels;
451 }
451 }
452
452
453 QStringList ChartAxis::createDateTimeLabels(const QString &format, int ticks) const
453 QStringList ChartAxis::createDateTimeLabels(const QString &format, int ticks) const
454 {
454 {
455 Q_ASSERT(m_max > m_min);
455 Q_ASSERT(m_max > m_min);
456 Q_ASSERT(ticks > 1);
456 Q_ASSERT(ticks > 1);
457 QStringList labels;
457 QStringList labels;
458 int n = qMax(int(-floor(log10((m_max - m_min) / (ticks - 1)))), 0);
458 int n = qMax(int(-floor(log10((m_max - m_min) / (ticks - 1)))), 0);
459 n++;
459 n++;
460 for (int i = 0; i < ticks; i++) {
460 for (int i = 0; i < ticks; i++) {
461 qreal value = m_min + (i * (m_max - m_min) / (ticks - 1));
461 qreal value = m_min + (i * (m_max - m_min) / (ticks - 1));
462 labels << QDateTime::fromMSecsSinceEpoch(value).toString(format);
462 labels << QDateTime::fromMSecsSinceEpoch(value).toString(format);
463 }
463 }
464 return labels;
464 return labels;
465 }
465 }
466
466
467 QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
467 QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
468 {
468 {
469 Q_UNUSED(which);
469 Q_UNUSED(which);
470 Q_UNUSED(constraint);
470 Q_UNUSED(constraint);
471 return QSizeF();
471 return QSizeF();
472 }
472 }
473
473
474 #include "moc_chartaxis_p.cpp"
474 #include "moc_chartaxis_p.cpp"
475
475
476 QTCOMMERCIALCHART_END_NAMESPACE
476 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,189 +1,189
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 <QPainter>
21 #include <QPainter>
22 #include <QGraphicsSceneEvent>
22 #include <QGraphicsSceneEvent>
23 #include <QGraphicsSimpleTextItem>
23 #include <QGraphicsSimpleTextItem>
24
24
25 #include "qlegend.h"
25 #include "qlegend.h"
26 #include "qlegend_p.h"
26 #include "qlegend_p.h"
27 #include "qlegendmarker.h"
27 #include "qlegendmarker.h"
28 #include "qlegendmarker_p.h"
28 #include "qlegendmarker_p.h"
29 #include "legendmarkeritem_p.h"
29 #include "legendmarkeritem_p.h"
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) :
33 LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) :
34 QGraphicsObject(parent),
34 QGraphicsObject(parent),
35 m_marker(marker),
35 m_marker(marker),
36 m_markerRect(0,0,10.0,10.0),
36 m_markerRect(0,0,10.0,10.0),
37 m_boundingRect(0,0,0,0),
37 m_boundingRect(0,0,0,0),
38 m_textItem(new QGraphicsSimpleTextItem(this)),
38 m_textItem(new QGraphicsSimpleTextItem(this)),
39 m_rectItem(new QGraphicsRectItem(this)),
39 m_rectItem(new QGraphicsRectItem(this)),
40 m_margin(4),
40 m_margin(4),
41 m_space(4),
41 m_space(4),
42 m_hovering(false),
42 m_hovering(false),
43 m_pressPos(0, 0)
43 m_pressPos(0, 0)
44 {
44 {
45 m_rectItem->setRect(m_markerRect);
45 m_rectItem->setRect(m_markerRect);
46 setAcceptsHoverEvents(true);
46 setAcceptHoverEvents(true);
47 }
47 }
48
48
49 LegendMarkerItem::~LegendMarkerItem()
49 LegendMarkerItem::~LegendMarkerItem()
50 {
50 {
51 if (m_hovering) {
51 if (m_hovering) {
52 emit m_marker->q_ptr->hovered(false);
52 emit m_marker->q_ptr->hovered(false);
53 }
53 }
54 }
54 }
55
55
56 void LegendMarkerItem::setPen(const QPen &pen)
56 void LegendMarkerItem::setPen(const QPen &pen)
57 {
57 {
58 m_rectItem->setPen(pen);
58 m_rectItem->setPen(pen);
59 }
59 }
60
60
61 QPen LegendMarkerItem::pen() const
61 QPen LegendMarkerItem::pen() const
62 {
62 {
63 return m_rectItem->pen();
63 return m_rectItem->pen();
64 }
64 }
65
65
66 void LegendMarkerItem::setBrush(const QBrush &brush)
66 void LegendMarkerItem::setBrush(const QBrush &brush)
67 {
67 {
68 m_rectItem->setBrush(brush);
68 m_rectItem->setBrush(brush);
69 }
69 }
70
70
71 QBrush LegendMarkerItem::brush() const
71 QBrush LegendMarkerItem::brush() const
72 {
72 {
73 return m_rectItem->brush();
73 return m_rectItem->brush();
74 }
74 }
75
75
76 void LegendMarkerItem::setFont(const QFont &font)
76 void LegendMarkerItem::setFont(const QFont &font)
77 {
77 {
78 m_textItem->setFont(font);
78 m_textItem->setFont(font);
79 QFontMetrics fn(font);
79 QFontMetrics fn(font);
80 m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2);
80 m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2);
81 updateGeometry();
81 updateGeometry();
82 }
82 }
83
83
84 QFont LegendMarkerItem::font() const
84 QFont LegendMarkerItem::font() const
85 {
85 {
86 return m_textItem->font();
86 return m_textItem->font();
87 }
87 }
88
88
89 void LegendMarkerItem::setLabel(const QString label)
89 void LegendMarkerItem::setLabel(const QString label)
90 {
90 {
91 m_label = label;
91 m_label = label;
92 updateGeometry();
92 updateGeometry();
93 }
93 }
94
94
95 QString LegendMarkerItem::label() const
95 QString LegendMarkerItem::label() const
96 {
96 {
97 return m_label;
97 return m_label;
98 }
98 }
99
99
100 void LegendMarkerItem::setLabelBrush(const QBrush &brush)
100 void LegendMarkerItem::setLabelBrush(const QBrush &brush)
101 {
101 {
102 m_textItem->setBrush(brush);
102 m_textItem->setBrush(brush);
103 }
103 }
104
104
105 QBrush LegendMarkerItem::labelBrush() const
105 QBrush LegendMarkerItem::labelBrush() const
106 {
106 {
107 return m_textItem->brush();
107 return m_textItem->brush();
108 }
108 }
109
109
110 void LegendMarkerItem::setGeometry(const QRectF &rect)
110 void LegendMarkerItem::setGeometry(const QRectF &rect)
111 {
111 {
112 QFontMetrics fn (m_font);
112 QFontMetrics fn (m_font);
113
113
114 int width = rect.width();
114 int width = rect.width();
115 qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
115 qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
116 qreal y = qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin);
116 qreal y = qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin);
117
117
118 if (fn.boundingRect(m_label).width() + x > width)
118 if (fn.boundingRect(m_label).width() + x > width)
119 {
119 {
120 QString string = m_label + "...";
120 QString string = m_label + "...";
121 while(fn.boundingRect(string).width() + x > width && string.length() > 3)
121 while(fn.boundingRect(string).width() + x > width && string.length() > 3)
122 string.remove(string.length() - 4, 1);
122 string.remove(string.length() - 4, 1);
123 m_textItem->setText(string);
123 m_textItem->setText(string);
124 }
124 }
125 else
125 else
126 m_textItem->setText(m_label);
126 m_textItem->setText(m_label);
127
127
128 const QRectF &textRect = m_textItem->boundingRect();
128 const QRectF &textRect = m_textItem->boundingRect();
129
129
130
130
131 m_textItem->setPos(x-m_margin,y/2 - textRect.height()/2);
131 m_textItem->setPos(x-m_margin,y/2 - textRect.height()/2);
132 m_rectItem->setRect(m_markerRect);
132 m_rectItem->setRect(m_markerRect);
133 m_rectItem->setPos(m_margin,y/2 - m_markerRect.height()/2);
133 m_rectItem->setPos(m_margin,y/2 - m_markerRect.height()/2);
134
134
135 prepareGeometryChange();
135 prepareGeometryChange();
136 m_boundingRect = QRectF(0,0,x+textRect.width()+m_margin,y);
136 m_boundingRect = QRectF(0,0,x+textRect.width()+m_margin,y);
137 }
137 }
138
138
139 QRectF LegendMarkerItem::boundingRect() const
139 QRectF LegendMarkerItem::boundingRect() const
140 {
140 {
141 return m_boundingRect;
141 return m_boundingRect;
142 }
142 }
143
143
144 void LegendMarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
144 void LegendMarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
145 {
145 {
146 Q_UNUSED(option)
146 Q_UNUSED(option)
147 Q_UNUSED(widget)
147 Q_UNUSED(widget)
148 Q_UNUSED(painter)
148 Q_UNUSED(painter)
149 }
149 }
150
150
151 QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
151 QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
152 {
152 {
153 Q_UNUSED(constraint)
153 Q_UNUSED(constraint)
154
154
155 QFontMetrics fn(m_textItem->font());
155 QFontMetrics fn(m_textItem->font());
156 QSizeF sh;
156 QSizeF sh;
157
157
158 switch (which) {
158 switch (which) {
159 case Qt::MinimumSize:
159 case Qt::MinimumSize:
160 sh = QSizeF(fn.boundingRect("...").width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
160 sh = QSizeF(fn.boundingRect("...").width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
161 break;
161 break;
162 case Qt::PreferredSize:
162 case Qt::PreferredSize:
163 sh = QSizeF(fn.boundingRect(m_label).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
163 sh = QSizeF(fn.boundingRect(m_label).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
164 break;
164 break;
165 default:
165 default:
166 break;
166 break;
167 }
167 }
168
168
169 return sh;
169 return sh;
170 }
170 }
171
171
172 void LegendMarkerItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
172 void LegendMarkerItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
173 {
173 {
174 Q_UNUSED(event)
174 Q_UNUSED(event)
175 m_hovering = true;
175 m_hovering = true;
176 emit m_marker->q_ptr->hovered(true);
176 emit m_marker->q_ptr->hovered(true);
177 }
177 }
178
178
179 void LegendMarkerItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
179 void LegendMarkerItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
180 {
180 {
181 Q_UNUSED(event)
181 Q_UNUSED(event)
182 m_hovering = false;
182 m_hovering = false;
183 emit m_marker->q_ptr->hovered(false);
183 emit m_marker->q_ptr->hovered(false);
184 }
184 }
185
185
186
186
187 #include "moc_legendmarkeritem_p.cpp"
187 #include "moc_legendmarkeritem_p.cpp"
188
188
189 QTCOMMERCIALCHART_END_NAMESPACE
189 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,70 +1,81
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 #ifndef TST_DEFINITIONS_H
21 #ifndef TST_DEFINITIONS_H
22 #define TST_DEFINITIONS_H
22 #define TST_DEFINITIONS_H
23
23
24 #include <QtTest/QtTest>
24 #include <QtTest/QtTest>
25 #include <QPushButton>
25 #include <QPushButton>
26
26
27 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
28 namespace QTest
29 {
30 // This was deprecated in Qt5. This is a small hack for the sake of compatibility.
31 inline static bool qWaitForWindowShown(QWidget *window)
32 {
33 return QTest::qWaitForWindowExposed(window);
34 }
35 }
36 #endif
37
27 #define TRY_COMPARE(actual, expected) { \
38 #define TRY_COMPARE(actual, expected) { \
28 do { \
39 do { \
29 const int timeout(1000); \
40 const int timeout(1000); \
30 const int waitStep(30); \
41 const int waitStep(30); \
31 /* always wait before comparing to catch possible extra signals */ \
42 /* always wait before comparing to catch possible extra signals */ \
32 QTest::qWait(waitStep); \
43 QTest::qWait(waitStep); \
33 for (int time(0); (actual != expected) && (time < timeout); time += waitStep) \
44 for (int time(0); (actual != expected) && (time < timeout); time += waitStep) \
34 QTest::qWait(waitStep); \
45 QTest::qWait(waitStep); \
35 QCOMPARE(actual, expected); \
46 QCOMPARE(actual, expected); \
36 } while (0); \
47 } while (0); \
37 }
48 }
38
49
39 // Some bamboo clients have trouble passing mouse events to the test application.
50 // Some bamboo clients have trouble passing mouse events to the test application.
40 // This can be used to skip those tests so that they don't show up as a failure
51 // This can be used to skip those tests so that they don't show up as a failure
41 // in the test report.
52 // in the test report.
42 #ifdef QT5_QUICK_1
53 #ifdef QT5_QUICK_1
43 #define SKIP_IF_CANNOT_TEST_MOUSE_EVENTS() { \
54 #define SKIP_IF_CANNOT_TEST_MOUSE_EVENTS() { \
44 do { \
55 do { \
45 QPushButton b; \
56 QPushButton b; \
46 b.resize(100, 100); \
57 b.resize(100, 100); \
47 b.show(); \
58 b.show(); \
48 QTest::qWaitForWindowShown(&b); \
59 QTest::qWaitForWindowShown(&b); \
49 QSignalSpy spy(&b, SIGNAL(clicked())); \
60 QSignalSpy spy(&b, SIGNAL(clicked())); \
50 QTest::mouseClick(&b, Qt::LeftButton, 0, b.rect().center()); \
61 QTest::mouseClick(&b, Qt::LeftButton, 0, b.rect().center()); \
51 if (spy.count() == 0) \
62 if (spy.count() == 0) \
52 QSKIP("Cannot test mouse events in this environment"); \
63 QSKIP("Cannot test mouse events in this environment"); \
53 } while (0); \
64 } while (0); \
54 }
65 }
55 #else
66 #else
56 #define SKIP_IF_CANNOT_TEST_MOUSE_EVENTS() { \
67 #define SKIP_IF_CANNOT_TEST_MOUSE_EVENTS() { \
57 do { \
68 do { \
58 QPushButton b; \
69 QPushButton b; \
59 b.resize(100, 100); \
70 b.resize(100, 100); \
60 b.show(); \
71 b.show(); \
61 QTest::qWaitForWindowShown(&b); \
72 QTest::qWaitForWindowShown(&b); \
62 QSignalSpy spy(&b, SIGNAL(clicked())); \
73 QSignalSpy spy(&b, SIGNAL(clicked())); \
63 QTest::mouseClick(&b, Qt::LeftButton, 0, b.rect().center()); \
74 QTest::mouseClick(&b, Qt::LeftButton, 0, b.rect().center()); \
64 if (spy.count() == 0) \
75 if (spy.count() == 0) \
65 QSKIP("Cannot test mouse events in this environment", SkipAll); \
76 QSKIP("Cannot test mouse events in this environment", SkipAll); \
66 } while (0); \
77 } while (0); \
67 }
78 }
68 #endif
79 #endif
69
80
70 #endif // TST_DEFINITIONS_H
81 #endif // TST_DEFINITIONS_H
@@ -1,519 +1,520
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 <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qbarset.h>
22 #include <qbarset.h>
23 #include <qbarseries.h>
23 #include <qbarseries.h>
24 #include <qchartview.h>
24 #include <qchartview.h>
25 #include "tst_definitions.h"
25
26
26 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
27
28
28 class tst_QBarSet : public QObject
29 class tst_QBarSet : public QObject
29 {
30 {
30 Q_OBJECT
31 Q_OBJECT
31
32
32 public slots:
33 public slots:
33 void initTestCase();
34 void initTestCase();
34 void cleanupTestCase();
35 void cleanupTestCase();
35 void init();
36 void init();
36 void cleanup();
37 void cleanup();
37
38
38 private slots:
39 private slots:
39 void qbarset_data();
40 void qbarset_data();
40 void qbarset();
41 void qbarset();
41 void label_data();
42 void label_data();
42 void label();
43 void label();
43 void append_data();
44 void append_data();
44 void append();
45 void append();
45 void appendOperator_data();
46 void appendOperator_data();
46 void appendOperator();
47 void appendOperator();
47 void insert_data();
48 void insert_data();
48 void insert();
49 void insert();
49 void remove_data();
50 void remove_data();
50 void remove();
51 void remove();
51 void replace_data();
52 void replace_data();
52 void replace();
53 void replace();
53 void at_data();
54 void at_data();
54 void at();
55 void at();
55 void atOperator_data();
56 void atOperator_data();
56 void atOperator();
57 void atOperator();
57 void count_data();
58 void count_data();
58 void count();
59 void count();
59 void sum_data();
60 void sum_data();
60 void sum();
61 void sum();
61 void customize();
62 void customize();
62
63
63 private:
64 private:
64 QBarSet* m_barset;
65 QBarSet* m_barset;
65 };
66 };
66
67
67 void tst_QBarSet::initTestCase()
68 void tst_QBarSet::initTestCase()
68 {
69 {
69 }
70 }
70
71
71 void tst_QBarSet::cleanupTestCase()
72 void tst_QBarSet::cleanupTestCase()
72 {
73 {
73 }
74 }
74
75
75 void tst_QBarSet::init()
76 void tst_QBarSet::init()
76 {
77 {
77 m_barset = new QBarSet(QString("label"));
78 m_barset = new QBarSet(QString("label"));
78 }
79 }
79
80
80 void tst_QBarSet::cleanup()
81 void tst_QBarSet::cleanup()
81 {
82 {
82 delete m_barset;
83 delete m_barset;
83 m_barset = 0;
84 m_barset = 0;
84 }
85 }
85
86
86 void tst_QBarSet::qbarset_data()
87 void tst_QBarSet::qbarset_data()
87 {
88 {
88 }
89 }
89
90
90 void tst_QBarSet::qbarset()
91 void tst_QBarSet::qbarset()
91 {
92 {
92 QBarSet barset(QString("label"));
93 QBarSet barset(QString("label"));
93 QCOMPARE(barset.label(), QString("label"));
94 QCOMPARE(barset.label(), QString("label"));
94 QCOMPARE(barset.count(), 0);
95 QCOMPARE(barset.count(), 0);
95 QVERIFY(qFuzzyIsNull(barset.sum()));
96 QVERIFY(qFuzzyIsNull(barset.sum()));
96 }
97 }
97
98
98 void tst_QBarSet::label_data()
99 void tst_QBarSet::label_data()
99 {
100 {
100 QTest::addColumn<QString> ("label");
101 QTest::addColumn<QString> ("label");
101 QTest::addColumn<QString> ("result");
102 QTest::addColumn<QString> ("result");
102 QTest::newRow("label0") << QString("label0") << QString("label0");
103 QTest::newRow("label0") << QString("label0") << QString("label0");
103 QTest::newRow("label1") << QString("label1") << QString("label1");
104 QTest::newRow("label1") << QString("label1") << QString("label1");
104 }
105 }
105
106
106 void tst_QBarSet::label()
107 void tst_QBarSet::label()
107 {
108 {
108 QFETCH(QString, label);
109 QFETCH(QString, label);
109 QFETCH(QString, result);
110 QFETCH(QString, result);
110
111
111 QSignalSpy labelSpy(m_barset,SIGNAL(labelChanged()));
112 QSignalSpy labelSpy(m_barset,SIGNAL(labelChanged()));
112 m_barset->setLabel(label);
113 m_barset->setLabel(label);
113 QCOMPARE(m_barset->label(), result);
114 QCOMPARE(m_barset->label(), result);
114 QVERIFY(labelSpy.count() == 1);
115 QVERIFY(labelSpy.count() == 1);
115 }
116 }
116
117
117 void tst_QBarSet::append_data()
118 void tst_QBarSet::append_data()
118 {
119 {
119 QTest::addColumn<int> ("count");
120 QTest::addColumn<int> ("count");
120 QTest::newRow("0") << 0;
121 QTest::newRow("0") << 0;
121 QTest::newRow("5") << 5;
122 QTest::newRow("5") << 5;
122 QTest::newRow("100") << 100;
123 QTest::newRow("100") << 100;
123 QTest::newRow("1000") << 1000;
124 QTest::newRow("1000") << 1000;
124 }
125 }
125
126
126 void tst_QBarSet::append()
127 void tst_QBarSet::append()
127 {
128 {
128 QFETCH(int, count);
129 QFETCH(int, count);
129
130
130 QCOMPARE(m_barset->count(), 0);
131 QCOMPARE(m_barset->count(), 0);
131 QVERIFY(qFuzzyIsNull(m_barset->sum()));
132 QVERIFY(qFuzzyIsNull(m_barset->sum()));
132
133
133 QSignalSpy valueSpy(m_barset, SIGNAL(valuesAdded(int,int)));
134 QSignalSpy valueSpy(m_barset, SIGNAL(valuesAdded(int,int)));
134
135
135 qreal sum(0.0);
136 qreal sum(0.0);
136 qreal value(0.0);
137 qreal value(0.0);
137
138
138 for (int i=0; i<count; i++) {
139 for (int i=0; i<count; i++) {
139 m_barset->append(value);
140 m_barset->append(value);
140 QCOMPARE(m_barset->at(i), value);
141 QCOMPARE(m_barset->at(i), value);
141 sum += value;
142 sum += value;
142 value += 1.0;
143 value += 1.0;
143 }
144 }
144
145
145 QCOMPARE(m_barset->count(), count);
146 QCOMPARE(m_barset->count(), count);
146 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
147 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
147
148
148 QCOMPARE(valueSpy.count(), count);
149 QCOMPARE(valueSpy.count(), count);
149 }
150 }
150
151
151 void tst_QBarSet::appendOperator_data()
152 void tst_QBarSet::appendOperator_data()
152 {
153 {
153 append_data();
154 append_data();
154 }
155 }
155
156
156 void tst_QBarSet::appendOperator()
157 void tst_QBarSet::appendOperator()
157 {
158 {
158 QFETCH(int, count);
159 QFETCH(int, count);
159
160
160 QCOMPARE(m_barset->count(), 0);
161 QCOMPARE(m_barset->count(), 0);
161 QVERIFY(qFuzzyIsNull(m_barset->sum()));
162 QVERIFY(qFuzzyIsNull(m_barset->sum()));
162
163
163 QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int)));
164 QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int)));
164
165
165 qreal sum(0.0);
166 qreal sum(0.0);
166 qreal value(0.0);
167 qreal value(0.0);
167
168
168 for (int i=0; i<count; i++) {
169 for (int i=0; i<count; i++) {
169 *m_barset << value;
170 *m_barset << value;
170 QCOMPARE(m_barset->at(i), value);
171 QCOMPARE(m_barset->at(i), value);
171 sum += value;
172 sum += value;
172 value += 1.0;
173 value += 1.0;
173 }
174 }
174
175
175 QCOMPARE(m_barset->count(), count);
176 QCOMPARE(m_barset->count(), count);
176 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
177 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
177 QCOMPARE(valueSpy.count(), count);
178 QCOMPARE(valueSpy.count(), count);
178 }
179 }
179
180
180 void tst_QBarSet::insert_data()
181 void tst_QBarSet::insert_data()
181 {
182 {
182 }
183 }
183
184
184 void tst_QBarSet::insert()
185 void tst_QBarSet::insert()
185 {
186 {
186 QCOMPARE(m_barset->count(), 0);
187 QCOMPARE(m_barset->count(), 0);
187 QVERIFY(qFuzzyIsNull(m_barset->sum()));
188 QVERIFY(qFuzzyIsNull(m_barset->sum()));
188 QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int)));
189 QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int)));
189
190
190 m_barset->insert(0, 1.0); // 1.0
191 m_barset->insert(0, 1.0); // 1.0
191 QCOMPARE(m_barset->at(0), 1.0);
192 QCOMPARE(m_barset->at(0), 1.0);
192 QCOMPARE(m_barset->count(), 1);
193 QCOMPARE(m_barset->count(), 1);
193 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)1.0));
194 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)1.0));
194
195
195 m_barset->insert(0, 2.0); // 2.0 1.0
196 m_barset->insert(0, 2.0); // 2.0 1.0
196 QCOMPARE(m_barset->at(0), 2.0);
197 QCOMPARE(m_barset->at(0), 2.0);
197 QCOMPARE(m_barset->at(1), 1.0);
198 QCOMPARE(m_barset->at(1), 1.0);
198 QCOMPARE(m_barset->count(), 2);
199 QCOMPARE(m_barset->count(), 2);
199 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)3.0));
200 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)3.0));
200
201
201 m_barset->insert(1, 3.0); // 2.0 3.0 1.0
202 m_barset->insert(1, 3.0); // 2.0 3.0 1.0
202 QCOMPARE(m_barset->at(1), 3.0);
203 QCOMPARE(m_barset->at(1), 3.0);
203 QCOMPARE(m_barset->at(0), 2.0);
204 QCOMPARE(m_barset->at(0), 2.0);
204 QCOMPARE(m_barset->at(2), 1.0);
205 QCOMPARE(m_barset->at(2), 1.0);
205 QCOMPARE(m_barset->count(), 3);
206 QCOMPARE(m_barset->count(), 3);
206 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)6.0));
207 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)6.0));
207 QCOMPARE(valueSpy.count(), 3);
208 QCOMPARE(valueSpy.count(), 3);
208 }
209 }
209
210
210 void tst_QBarSet::remove_data()
211 void tst_QBarSet::remove_data()
211 {
212 {
212 }
213 }
213
214
214 void tst_QBarSet::remove()
215 void tst_QBarSet::remove()
215 {
216 {
216 QCOMPARE(m_barset->count(), 0);
217 QCOMPARE(m_barset->count(), 0);
217 QVERIFY(qFuzzyIsNull(m_barset->sum()));
218 QVERIFY(qFuzzyIsNull(m_barset->sum()));
218
219
219 QSignalSpy valueSpy(m_barset,SIGNAL(valuesRemoved(int,int)));
220 QSignalSpy valueSpy(m_barset,SIGNAL(valuesRemoved(int,int)));
220
221
221 m_barset->append(1.0);
222 m_barset->append(1.0);
222 m_barset->append(2.0);
223 m_barset->append(2.0);
223 m_barset->append(3.0);
224 m_barset->append(3.0);
224 m_barset->append(4.0);
225 m_barset->append(4.0);
225
226
226 QCOMPARE(m_barset->count(), 4);
227 QCOMPARE(m_barset->count(), 4);
227 QCOMPARE(m_barset->sum(), 10.0);
228 QCOMPARE(m_barset->sum(), 10.0);
228
229
229 // Remove middle
230 // Remove middle
230 m_barset->remove(2); // 1.0 2.0 4.0
231 m_barset->remove(2); // 1.0 2.0 4.0
231 QCOMPARE(m_barset->at(0), 1.0);
232 QCOMPARE(m_barset->at(0), 1.0);
232 QCOMPARE(m_barset->at(1), 2.0);
233 QCOMPARE(m_barset->at(1), 2.0);
233 QCOMPARE(m_barset->at(2), 4.0);
234 QCOMPARE(m_barset->at(2), 4.0);
234 QCOMPARE(m_barset->count(), 3);
235 QCOMPARE(m_barset->count(), 3);
235 QCOMPARE(m_barset->sum(), 7.0);
236 QCOMPARE(m_barset->sum(), 7.0);
236 QCOMPARE(valueSpy.count(), 1);
237 QCOMPARE(valueSpy.count(), 1);
237
238
238 QList<QVariant> valueSpyArg = valueSpy.takeFirst();
239 QList<QVariant> valueSpyArg = valueSpy.takeFirst();
239 // Verify index of removed signal
240 // Verify index of removed signal
240 QVERIFY(valueSpyArg.at(0).type() == QVariant::Int);
241 QVERIFY(valueSpyArg.at(0).type() == QVariant::Int);
241 QVERIFY(valueSpyArg.at(0).toInt() == 2);
242 QVERIFY(valueSpyArg.at(0).toInt() == 2);
242 // Verify count of removed signal
243 // Verify count of removed signal
243 QVERIFY(valueSpyArg.at(1).type() == QVariant::Int);
244 QVERIFY(valueSpyArg.at(1).type() == QVariant::Int);
244 QVERIFY(valueSpyArg.at(1).toInt() == 1);
245 QVERIFY(valueSpyArg.at(1).toInt() == 1);
245
246
246 // Remove first
247 // Remove first
247 m_barset->remove(0); // 2.0 4.0
248 m_barset->remove(0); // 2.0 4.0
248 QCOMPARE(m_barset->at(0), 2.0);
249 QCOMPARE(m_barset->at(0), 2.0);
249 QCOMPARE(m_barset->at(1), 4.0);
250 QCOMPARE(m_barset->at(1), 4.0);
250 QCOMPARE(m_barset->count(), 2);
251 QCOMPARE(m_barset->count(), 2);
251 QCOMPARE(m_barset->sum(), 6.0);
252 QCOMPARE(m_barset->sum(), 6.0);
252
253
253 QCOMPARE(valueSpy.count(), 1);
254 QCOMPARE(valueSpy.count(), 1);
254 valueSpyArg = valueSpy.takeFirst();
255 valueSpyArg = valueSpy.takeFirst();
255 // Verify index of removed signal
256 // Verify index of removed signal
256 QVERIFY(valueSpyArg.at(0).type() == QVariant::Int);
257 QVERIFY(valueSpyArg.at(0).type() == QVariant::Int);
257 QVERIFY(valueSpyArg.at(0).toInt() == 0);
258 QVERIFY(valueSpyArg.at(0).toInt() == 0);
258 // Verify count of removed signal
259 // Verify count of removed signal
259 QVERIFY(valueSpyArg.at(1).type() == QVariant::Int);
260 QVERIFY(valueSpyArg.at(1).type() == QVariant::Int);
260 QVERIFY(valueSpyArg.at(1).toInt() == 1);
261 QVERIFY(valueSpyArg.at(1).toInt() == 1);
261
262
262
263
263 // Illegal indexes
264 // Illegal indexes
264 m_barset->remove(4);
265 m_barset->remove(4);
265 QCOMPARE(m_barset->count(), 2);
266 QCOMPARE(m_barset->count(), 2);
266 QCOMPARE(m_barset->sum(), 6.0);
267 QCOMPARE(m_barset->sum(), 6.0);
267 m_barset->remove(-1);
268 m_barset->remove(-1);
268 QCOMPARE(m_barset->count(), 2);
269 QCOMPARE(m_barset->count(), 2);
269 QCOMPARE(m_barset->sum(), 6.0);
270 QCOMPARE(m_barset->sum(), 6.0);
270
271
271 // nothing removed, no signals should be emitted
272 // nothing removed, no signals should be emitted
272 QCOMPARE(valueSpy.count(), 0);
273 QCOMPARE(valueSpy.count(), 0);
273
274
274 // Remove more items than list has
275 // Remove more items than list has
275 m_barset->remove(0,312);
276 m_barset->remove(0,312);
276 QCOMPARE(m_barset->count(), 0);
277 QCOMPARE(m_barset->count(), 0);
277 QVERIFY(qFuzzyIsNull(m_barset->sum()));
278 QVERIFY(qFuzzyIsNull(m_barset->sum()));
278
279
279 QCOMPARE(valueSpy.count(), 1);
280 QCOMPARE(valueSpy.count(), 1);
280 valueSpyArg = valueSpy.takeFirst();
281 valueSpyArg = valueSpy.takeFirst();
281
282
282 // Verify index of removed signal
283 // Verify index of removed signal
283 QVERIFY(valueSpyArg.at(0).type() == QVariant::Int);
284 QVERIFY(valueSpyArg.at(0).type() == QVariant::Int);
284 QVERIFY(valueSpyArg.at(0).toInt() == 0);
285 QVERIFY(valueSpyArg.at(0).toInt() == 0);
285 // Verify count of removed signal (expect 2 values removed, because list had only 2 items)
286 // Verify count of removed signal (expect 2 values removed, because list had only 2 items)
286 QVERIFY(valueSpyArg.at(1).type() == QVariant::Int);
287 QVERIFY(valueSpyArg.at(1).type() == QVariant::Int);
287 QVERIFY(valueSpyArg.at(1).toInt() == 2);
288 QVERIFY(valueSpyArg.at(1).toInt() == 2);
288 }
289 }
289
290
290 void tst_QBarSet::replace_data()
291 void tst_QBarSet::replace_data()
291 {
292 {
292
293
293 }
294 }
294
295
295 void tst_QBarSet::replace()
296 void tst_QBarSet::replace()
296 {
297 {
297 QCOMPARE(m_barset->count(), 0);
298 QCOMPARE(m_barset->count(), 0);
298 QVERIFY(qFuzzyIsNull(m_barset->sum()));
299 QVERIFY(qFuzzyIsNull(m_barset->sum()));
299 QSignalSpy valueSpy(m_barset,SIGNAL(valueChanged(int)));
300 QSignalSpy valueSpy(m_barset,SIGNAL(valueChanged(int)));
300
301
301 m_barset->append(1.0);
302 m_barset->append(1.0);
302 m_barset->append(2.0);
303 m_barset->append(2.0);
303 m_barset->append(3.0);
304 m_barset->append(3.0);
304 m_barset->append(4.0);
305 m_barset->append(4.0);
305
306
306 QCOMPARE(m_barset->count(), 4);
307 QCOMPARE(m_barset->count(), 4);
307 QCOMPARE(m_barset->sum(), 10.0);
308 QCOMPARE(m_barset->sum(), 10.0);
308
309
309 // Replace first
310 // Replace first
310 m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0
311 m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0
311 QCOMPARE(m_barset->count(), 4);
312 QCOMPARE(m_barset->count(), 4);
312 QCOMPARE(m_barset->sum(), 14.0);
313 QCOMPARE(m_barset->sum(), 14.0);
313 QCOMPARE(m_barset->at(0), 5.0);
314 QCOMPARE(m_barset->at(0), 5.0);
314
315
315 // Replace last
316 // Replace last
316 m_barset->replace(3, 6.0);
317 m_barset->replace(3, 6.0);
317 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
318 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
318 QCOMPARE(m_barset->sum(), 16.0);
319 QCOMPARE(m_barset->sum(), 16.0);
319 QCOMPARE(m_barset->at(0), 5.0);
320 QCOMPARE(m_barset->at(0), 5.0);
320 QCOMPARE(m_barset->at(1), 2.0);
321 QCOMPARE(m_barset->at(1), 2.0);
321 QCOMPARE(m_barset->at(2), 3.0);
322 QCOMPARE(m_barset->at(2), 3.0);
322 QCOMPARE(m_barset->at(3), 6.0);
323 QCOMPARE(m_barset->at(3), 6.0);
323
324
324 // Illegal indexes
325 // Illegal indexes
325 m_barset->replace(4, 6.0);
326 m_barset->replace(4, 6.0);
326 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
327 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
327 QCOMPARE(m_barset->sum(), 16.0);
328 QCOMPARE(m_barset->sum(), 16.0);
328 m_barset->replace(-1, 6.0);
329 m_barset->replace(-1, 6.0);
329 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
330 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
330 QCOMPARE(m_barset->sum(), 16.0);
331 QCOMPARE(m_barset->sum(), 16.0);
331 m_barset->replace(4, 1.0);
332 m_barset->replace(4, 1.0);
332 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
333 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
333 QCOMPARE(m_barset->sum(), 16.0);
334 QCOMPARE(m_barset->sum(), 16.0);
334 m_barset->replace(-1, 1.0);
335 m_barset->replace(-1, 1.0);
335 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
336 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
336 QCOMPARE(m_barset->sum(), 16.0);
337 QCOMPARE(m_barset->sum(), 16.0);
337
338
338 QVERIFY(valueSpy.count() == 2);
339 QVERIFY(valueSpy.count() == 2);
339 }
340 }
340
341
341 void tst_QBarSet::at_data()
342 void tst_QBarSet::at_data()
342 {
343 {
343
344
344 }
345 }
345
346
346 void tst_QBarSet::at()
347 void tst_QBarSet::at()
347 {
348 {
348 QCOMPARE(m_barset->count(), 0);
349 QCOMPARE(m_barset->count(), 0);
349 QVERIFY(qFuzzyIsNull(m_barset->sum()));
350 QVERIFY(qFuzzyIsNull(m_barset->sum()));
350
351
351 m_barset->append(1.0);
352 m_barset->append(1.0);
352 m_barset->append(2.0);
353 m_barset->append(2.0);
353 m_barset->append(3.0);
354 m_barset->append(3.0);
354 m_barset->append(4.0);
355 m_barset->append(4.0);
355
356
356 QCOMPARE(m_barset->at(0), 1.0);
357 QCOMPARE(m_barset->at(0), 1.0);
357 QCOMPARE(m_barset->at(1), 2.0);
358 QCOMPARE(m_barset->at(1), 2.0);
358 QCOMPARE(m_barset->at(2), 3.0);
359 QCOMPARE(m_barset->at(2), 3.0);
359 QCOMPARE(m_barset->at(3), 4.0);
360 QCOMPARE(m_barset->at(3), 4.0);
360 }
361 }
361
362
362 void tst_QBarSet::atOperator_data()
363 void tst_QBarSet::atOperator_data()
363 {
364 {
364
365
365 }
366 }
366
367
367 void tst_QBarSet::atOperator()
368 void tst_QBarSet::atOperator()
368 {
369 {
369 QCOMPARE(m_barset->count(), 0);
370 QCOMPARE(m_barset->count(), 0);
370 QVERIFY(qFuzzyIsNull(m_barset->sum()));
371 QVERIFY(qFuzzyIsNull(m_barset->sum()));
371
372
372 m_barset->append(1.0);
373 m_barset->append(1.0);
373 m_barset->append(2.0);
374 m_barset->append(2.0);
374 m_barset->append(3.0);
375 m_barset->append(3.0);
375 m_barset->append(4.0);
376 m_barset->append(4.0);
376
377
377 QCOMPARE(m_barset->operator [](0), 1.0);
378 QCOMPARE(m_barset->operator [](0), 1.0);
378 QCOMPARE(m_barset->operator [](1), 2.0);
379 QCOMPARE(m_barset->operator [](1), 2.0);
379 QCOMPARE(m_barset->operator [](2), 3.0);
380 QCOMPARE(m_barset->operator [](2), 3.0);
380 QCOMPARE(m_barset->operator [](3), 4.0);
381 QCOMPARE(m_barset->operator [](3), 4.0);
381 }
382 }
382
383
383 void tst_QBarSet::count_data()
384 void tst_QBarSet::count_data()
384 {
385 {
385
386
386 }
387 }
387
388
388 void tst_QBarSet::count()
389 void tst_QBarSet::count()
389 {
390 {
390 QCOMPARE(m_barset->count(), 0);
391 QCOMPARE(m_barset->count(), 0);
391 QVERIFY(qFuzzyIsNull(m_barset->sum()));
392 QVERIFY(qFuzzyIsNull(m_barset->sum()));
392
393
393 m_barset->append(1.0);
394 m_barset->append(1.0);
394 QCOMPARE(m_barset->count(),1);
395 QCOMPARE(m_barset->count(),1);
395 m_barset->append(2.0);
396 m_barset->append(2.0);
396 QCOMPARE(m_barset->count(),2);
397 QCOMPARE(m_barset->count(),2);
397 m_barset->append(3.0);
398 m_barset->append(3.0);
398 QCOMPARE(m_barset->count(),3);
399 QCOMPARE(m_barset->count(),3);
399 m_barset->append(4.0);
400 m_barset->append(4.0);
400 QCOMPARE(m_barset->count(),4);
401 QCOMPARE(m_barset->count(),4);
401 }
402 }
402
403
403 void tst_QBarSet::sum_data()
404 void tst_QBarSet::sum_data()
404 {
405 {
405
406
406 }
407 }
407
408
408 void tst_QBarSet::sum()
409 void tst_QBarSet::sum()
409 {
410 {
410 QCOMPARE(m_barset->count(), 0);
411 QCOMPARE(m_barset->count(), 0);
411 QVERIFY(qFuzzyIsNull(m_barset->sum()));
412 QVERIFY(qFuzzyIsNull(m_barset->sum()));
412
413
413 m_barset->append(1.0);
414 m_barset->append(1.0);
414 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)1.0));
415 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)1.0));
415 m_barset->append(2.0);
416 m_barset->append(2.0);
416 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)3.0));
417 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)3.0));
417 m_barset->append(3.0);
418 m_barset->append(3.0);
418 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)6.0));
419 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)6.0));
419 m_barset->append(4.0);
420 m_barset->append(4.0);
420 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)10.0));
421 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)10.0));
421 }
422 }
422
423
423 void tst_QBarSet::customize()
424 void tst_QBarSet::customize()
424 {
425 {
425 // Create sets
426 // Create sets
426 QBarSet *set1 = new QBarSet("set1");
427 QBarSet *set1 = new QBarSet("set1");
427 QBarSet *set2 = new QBarSet("set2");
428 QBarSet *set2 = new QBarSet("set2");
428
429
429 // Append set1 to series
430 // Append set1 to series
430 QBarSeries *series = new QBarSeries();
431 QBarSeries *series = new QBarSeries();
431 bool success = series->append(set1);
432 bool success = series->append(set1);
432 QVERIFY(success);
433 QVERIFY(success);
433
434
434 // Add series to the chart
435 // Add series to the chart
435 QChartView view(new QChart());
436 QChartView view(new QChart());
436 view.resize(200, 200);
437 view.resize(200, 200);
437 view.chart()->addSeries(series);
438 view.chart()->addSeries(series);
438 view.show();
439 view.show();
439 QTest::qWaitForWindowShown(&view);
440 QTest::qWaitForWindowShown(&view);
440
441
441 // Test adding data to the sets
442 // Test adding data to the sets
442 *set1 << 1 << 2 << 1 << 3;
443 *set1 << 1 << 2 << 1 << 3;
443 *set2 << 2 << 1 << 3 << 1;
444 *set2 << 2 << 1 << 3 << 1;
444
445
445 // Remove sets from series
446 // Remove sets from series
446 series->take(set1);
447 series->take(set1);
447 series->take(set2);
448 series->take(set2);
448
449
449 // Test pen
450 // Test pen
450 QVERIFY(set1->pen() != QPen());
451 QVERIFY(set1->pen() != QPen());
451 QVERIFY(set2->pen() == QPen());
452 QVERIFY(set2->pen() == QPen());
452 QPen pen(QColor(128,128,128,128));
453 QPen pen(QColor(128,128,128,128));
453 set1->setPen(pen);
454 set1->setPen(pen);
454
455
455 // Add sets back to series
456 // Add sets back to series
456 series->append(set1);
457 series->append(set1);
457 series->append(set2);
458 series->append(set2);
458
459
459 QVERIFY(set1->pen() == pen); // Should be customized
460 QVERIFY(set1->pen() == pen); // Should be customized
460 QVERIFY(set2->pen() != QPen()); // Should be decorated by theme
461 QVERIFY(set2->pen() != QPen()); // Should be decorated by theme
461
462
462 // Remove sets from series
463 // Remove sets from series
463 series->take(set1);
464 series->take(set1);
464 series->take(set2);
465 series->take(set2);
465
466
466 // Test brush
467 // Test brush
467 set2->setBrush(QBrush());
468 set2->setBrush(QBrush());
468 QVERIFY(set1->brush() != QBrush());
469 QVERIFY(set1->brush() != QBrush());
469 QVERIFY(set2->brush() == QBrush());
470 QVERIFY(set2->brush() == QBrush());
470 QBrush brush(QColor(128,128,128,128));
471 QBrush brush(QColor(128,128,128,128));
471 set1->setBrush(brush);
472 set1->setBrush(brush);
472
473
473 // Add sets back to series
474 // Add sets back to series
474 series->append(set1);
475 series->append(set1);
475 series->append(set2);
476 series->append(set2);
476
477
477 QVERIFY(set1->brush() == brush); // Should be customized
478 QVERIFY(set1->brush() == brush); // Should be customized
478 QVERIFY(set2->brush() != QBrush()); // Should be decorated by theme
479 QVERIFY(set2->brush() != QBrush()); // Should be decorated by theme
479
480
480 // Remove sets from series
481 // Remove sets from series
481 series->take(set1);
482 series->take(set1);
482 series->take(set2);
483 series->take(set2);
483
484
484 // Test label brush
485 // Test label brush
485 set2->setLabelBrush(QBrush());
486 set2->setLabelBrush(QBrush());
486 QVERIFY(set1->labelBrush() != QBrush());
487 QVERIFY(set1->labelBrush() != QBrush());
487 QVERIFY(set2->labelBrush() == QBrush());
488 QVERIFY(set2->labelBrush() == QBrush());
488 set1->setLabelBrush(brush);
489 set1->setLabelBrush(brush);
489
490
490 series->append(set1);
491 series->append(set1);
491 series->append(set2);
492 series->append(set2);
492 QVERIFY(set1->labelBrush() == brush); // Should be customized
493 QVERIFY(set1->labelBrush() == brush); // Should be customized
493 QVERIFY(set2->labelBrush() != QBrush()); // Should be decorated by theme
494 QVERIFY(set2->labelBrush() != QBrush()); // Should be decorated by theme
494
495
495 // Test label font
496 // Test label font
496 // Note: QFont empty constructor creates font with application's default font, so the font may or may not be the
497 // Note: QFont empty constructor creates font with application's default font, so the font may or may not be the
497 // same for the set added to the series (depending on the QChart's theme configuration)
498 // same for the set added to the series (depending on the QChart's theme configuration)
498 QVERIFY(set1->labelFont() != QFont() || set1->labelFont() == QFont());
499 QVERIFY(set1->labelFont() != QFont() || set1->labelFont() == QFont());
499 QVERIFY(set2->labelFont() == QFont());
500 QVERIFY(set2->labelFont() == QFont());
500 QFont font;
501 QFont font;
501 font.setBold(true);
502 font.setBold(true);
502 font.setItalic(true);
503 font.setItalic(true);
503 set1->setLabelFont(font);
504 set1->setLabelFont(font);
504 QVERIFY(set1->labelFont() == font);
505 QVERIFY(set1->labelFont() == font);
505 QVERIFY(set2->labelFont() == QFont());
506 QVERIFY(set2->labelFont() == QFont());
506
507
507 // Test adding data to the sets
508 // Test adding data to the sets
508 *set1 << 1 << 2 << 1 << 3;
509 *set1 << 1 << 2 << 1 << 3;
509 *set2 << 2 << 1 << 3 << 1;
510 *set2 << 2 << 1 << 3 << 1;
510
511
511 }
512 }
512
513
513
514
514
515
515
516
516 QTEST_MAIN(tst_QBarSet)
517 QTEST_MAIN(tst_QBarSet)
517
518
518 #include "tst_qbarset.moc"
519 #include "tst_qbarset.moc"
519
520
@@ -1,794 +1,795
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 <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qchartview.h>
22 #include <qchartview.h>
23 #include <qlineseries.h>
23 #include <qlineseries.h>
24 #include <qareaseries.h>
24 #include <qareaseries.h>
25 #include <qscatterseries.h>
25 #include <qscatterseries.h>
26 #include <qsplineseries.h>
26 #include <qsplineseries.h>
27 #include <qpieseries.h>
27 #include <qpieseries.h>
28 #include <qabstractbarseries.h>
28 #include <qabstractbarseries.h>
29 #include <qbarseries.h>
29 #include <qbarseries.h>
30 #include <qpercentbarseries.h>
30 #include <qpercentbarseries.h>
31 #include <qstackedbarseries.h>
31 #include <qstackedbarseries.h>
32 #include <qvalueaxis.h>
32 #include <qvalueaxis.h>
33 #include <qbarcategoryaxis.h>
33 #include <qbarcategoryaxis.h>
34 #include "tst_definitions.h"
34
35
35 QTCOMMERCIALCHART_USE_NAMESPACE
36 QTCOMMERCIALCHART_USE_NAMESPACE
36
37
37 Q_DECLARE_METATYPE(QAbstractAxis *)
38 Q_DECLARE_METATYPE(QAbstractAxis *)
38 Q_DECLARE_METATYPE(QValueAxis *)
39 Q_DECLARE_METATYPE(QValueAxis *)
39 Q_DECLARE_METATYPE(QBarCategoryAxis *)
40 Q_DECLARE_METATYPE(QBarCategoryAxis *)
40 Q_DECLARE_METATYPE(QAbstractSeries *)
41 Q_DECLARE_METATYPE(QAbstractSeries *)
41 Q_DECLARE_METATYPE(QChart::AnimationOption)
42 Q_DECLARE_METATYPE(QChart::AnimationOption)
42 Q_DECLARE_METATYPE(QBrush)
43 Q_DECLARE_METATYPE(QBrush)
43 Q_DECLARE_METATYPE(QPen)
44 Q_DECLARE_METATYPE(QPen)
44 Q_DECLARE_METATYPE(QChart::ChartTheme)
45 Q_DECLARE_METATYPE(QChart::ChartTheme)
45
46
46 class tst_QChart : public QObject
47 class tst_QChart : public QObject
47 {
48 {
48 Q_OBJECT
49 Q_OBJECT
49
50
50 public slots:
51 public slots:
51 void initTestCase();
52 void initTestCase();
52 void cleanupTestCase();
53 void cleanupTestCase();
53 void init();
54 void init();
54 void cleanup();
55 void cleanup();
55
56
56 private slots:
57 private slots:
57 void qchart_data();
58 void qchart_data();
58 void qchart();
59 void qchart();
59 void addSeries_data();
60 void addSeries_data();
60 void addSeries();
61 void addSeries();
61 void animationOptions_data();
62 void animationOptions_data();
62 void animationOptions();
63 void animationOptions();
63 void axisX_data();
64 void axisX_data();
64 void axisX();
65 void axisX();
65 void axisY_data();
66 void axisY_data();
66 void axisY();
67 void axisY();
67 void backgroundBrush_data();
68 void backgroundBrush_data();
68 void backgroundBrush();
69 void backgroundBrush();
69 void backgroundPen_data();
70 void backgroundPen_data();
70 void backgroundPen();
71 void backgroundPen();
71 void isBackgroundVisible_data();
72 void isBackgroundVisible_data();
72 void isBackgroundVisible();
73 void isBackgroundVisible();
73 void legend_data();
74 void legend_data();
74 void legend();
75 void legend();
75 void plotArea_data();
76 void plotArea_data();
76 void plotArea();
77 void plotArea();
77 void removeAllSeries_data();
78 void removeAllSeries_data();
78 void removeAllSeries();
79 void removeAllSeries();
79 void removeSeries_data();
80 void removeSeries_data();
80 void removeSeries();
81 void removeSeries();
81 void scroll_right_data();
82 void scroll_right_data();
82 void scroll_right();
83 void scroll_right();
83 void scroll_left_data();
84 void scroll_left_data();
84 void scroll_left();
85 void scroll_left();
85 void scroll_up_data();
86 void scroll_up_data();
86 void scroll_up();
87 void scroll_up();
87 void scroll_down_data();
88 void scroll_down_data();
88 void scroll_down();
89 void scroll_down();
89 void theme_data();
90 void theme_data();
90 void theme();
91 void theme();
91 void title_data();
92 void title_data();
92 void title();
93 void title();
93 void titleBrush_data();
94 void titleBrush_data();
94 void titleBrush();
95 void titleBrush();
95 void titleFont_data();
96 void titleFont_data();
96 void titleFont();
97 void titleFont();
97 void zoomIn_data();
98 void zoomIn_data();
98 void zoomIn();
99 void zoomIn();
99 void zoomOut_data();
100 void zoomOut_data();
100 void zoomOut();
101 void zoomOut();
101
102
102 private:
103 private:
103 void createTestData();
104 void createTestData();
104
105
105 private:
106 private:
106 QChartView* m_view;
107 QChartView* m_view;
107 QChart* m_chart;
108 QChart* m_chart;
108 };
109 };
109
110
110 void tst_QChart::initTestCase()
111 void tst_QChart::initTestCase()
111 {
112 {
112
113
113 }
114 }
114
115
115 void tst_QChart::cleanupTestCase()
116 void tst_QChart::cleanupTestCase()
116 {
117 {
117
118
118 }
119 }
119
120
120 void tst_QChart::init()
121 void tst_QChart::init()
121 {
122 {
122 m_view = new QChartView(new QChart());
123 m_view = new QChartView(new QChart());
123 m_chart = m_view->chart();
124 m_chart = m_view->chart();
124 }
125 }
125
126
126 void tst_QChart::cleanup()
127 void tst_QChart::cleanup()
127 {
128 {
128 delete m_view;
129 delete m_view;
129 m_view = 0;
130 m_view = 0;
130 m_chart = 0;
131 m_chart = 0;
131 }
132 }
132
133
133
134
134 void tst_QChart::createTestData()
135 void tst_QChart::createTestData()
135 {
136 {
136 QLineSeries* series0 = new QLineSeries(this);
137 QLineSeries* series0 = new QLineSeries(this);
137 *series0 << QPointF(0, 0) << QPointF(100, 100);
138 *series0 << QPointF(0, 0) << QPointF(100, 100);
138 m_chart->addSeries(series0);
139 m_chart->addSeries(series0);
139 m_view->show();
140 m_view->show();
140 QTest::qWaitForWindowShown(m_view);
141 QTest::qWaitForWindowShown(m_view);
141 }
142 }
142
143
143 void tst_QChart::qchart_data()
144 void tst_QChart::qchart_data()
144 {
145 {
145 }
146 }
146
147
147 void tst_QChart::qchart()
148 void tst_QChart::qchart()
148 {
149 {
149 QVERIFY(m_chart);
150 QVERIFY(m_chart);
150 QVERIFY(m_chart->legend());
151 QVERIFY(m_chart->legend());
151 QVERIFY(m_chart->legend()->isVisible());
152 QVERIFY(m_chart->legend()->isVisible());
152
153
153 QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation);
154 QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation);
154 QVERIFY(!m_chart->axisX());
155 QVERIFY(!m_chart->axisX());
155 QVERIFY(!m_chart->axisY());
156 QVERIFY(!m_chart->axisY());
156 QVERIFY(m_chart->backgroundBrush()!=QBrush());
157 QVERIFY(m_chart->backgroundBrush()!=QBrush());
157 QVERIFY(m_chart->backgroundPen()!=QPen());
158 QVERIFY(m_chart->backgroundPen()!=QPen());
158 QCOMPARE(m_chart->isBackgroundVisible(), true);
159 QCOMPARE(m_chart->isBackgroundVisible(), true);
159 QVERIFY(m_chart->plotArea().top()==0);
160 QVERIFY(m_chart->plotArea().top()==0);
160 QVERIFY(m_chart->plotArea().left()==0);
161 QVERIFY(m_chart->plotArea().left()==0);
161 QVERIFY(m_chart->plotArea().right()==0);
162 QVERIFY(m_chart->plotArea().right()==0);
162 QVERIFY(m_chart->plotArea().bottom()==0);
163 QVERIFY(m_chart->plotArea().bottom()==0);
163 QCOMPARE(m_chart->theme(), QChart::ChartThemeLight);
164 QCOMPARE(m_chart->theme(), QChart::ChartThemeLight);
164 QCOMPARE(m_chart->title(), QString());
165 QCOMPARE(m_chart->title(), QString());
165
166
166 //QCOMPARE(m_chart->titleBrush(),QBrush());
167 //QCOMPARE(m_chart->titleBrush(),QBrush());
167 //QCOMPARE(m_chart->titleFont(),QFont());
168 //QCOMPARE(m_chart->titleFont(),QFont());
168
169
169 m_chart->removeAllSeries();
170 m_chart->removeAllSeries();
170 m_chart->scroll(0,0);
171 m_chart->scroll(0,0);
171
172
172 m_chart->zoomIn();
173 m_chart->zoomIn();
173 m_chart->zoomIn(QRectF());
174 m_chart->zoomIn(QRectF());
174 m_chart->zoomOut();
175 m_chart->zoomOut();
175
176
176 m_view->show();
177 m_view->show();
177
178
178 QVERIFY(m_chart->plotArea().top()>0);
179 QVERIFY(m_chart->plotArea().top()>0);
179 QVERIFY(m_chart->plotArea().left()>0);
180 QVERIFY(m_chart->plotArea().left()>0);
180 QVERIFY(m_chart->plotArea().right()>0);
181 QVERIFY(m_chart->plotArea().right()>0);
181 QVERIFY(m_chart->plotArea().bottom()>0);
182 QVERIFY(m_chart->plotArea().bottom()>0);
182 }
183 }
183
184
184 void tst_QChart::addSeries_data()
185 void tst_QChart::addSeries_data()
185 {
186 {
186 QTest::addColumn<QAbstractSeries *>("series");
187 QTest::addColumn<QAbstractSeries *>("series");
187
188
188 QAbstractSeries* line = new QLineSeries(this);
189 QAbstractSeries* line = new QLineSeries(this);
189 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
190 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
190 QAbstractSeries* scatter = new QScatterSeries(this);
191 QAbstractSeries* scatter = new QScatterSeries(this);
191 QAbstractSeries* spline = new QSplineSeries(this);
192 QAbstractSeries* spline = new QSplineSeries(this);
192 QAbstractSeries* pie = new QPieSeries(this);
193 QAbstractSeries* pie = new QPieSeries(this);
193 QAbstractSeries* bar = new QBarSeries(this);
194 QAbstractSeries* bar = new QBarSeries(this);
194 QAbstractSeries* percent = new QPercentBarSeries(this);
195 QAbstractSeries* percent = new QPercentBarSeries(this);
195 QAbstractSeries* stacked = new QStackedBarSeries(this);
196 QAbstractSeries* stacked = new QStackedBarSeries(this);
196
197
197 QTest::newRow("lineSeries") << line;
198 QTest::newRow("lineSeries") << line;
198 QTest::newRow("areaSeries") << area;
199 QTest::newRow("areaSeries") << area;
199 QTest::newRow("scatterSeries") << scatter;
200 QTest::newRow("scatterSeries") << scatter;
200 QTest::newRow("splineSeries") << spline;
201 QTest::newRow("splineSeries") << spline;
201 QTest::newRow("pieSeries") << pie;
202 QTest::newRow("pieSeries") << pie;
202 QTest::newRow("barSeries") << bar;
203 QTest::newRow("barSeries") << bar;
203 QTest::newRow("percentBarSeries") << percent;
204 QTest::newRow("percentBarSeries") << percent;
204 QTest::newRow("stackedBarSeries") << stacked;
205 QTest::newRow("stackedBarSeries") << stacked;
205
206
206 }
207 }
207
208
208 void tst_QChart::addSeries()
209 void tst_QChart::addSeries()
209 {
210 {
210 QFETCH(QAbstractSeries *, series);
211 QFETCH(QAbstractSeries *, series);
211 m_view->show();
212 m_view->show();
212 QTest::qWaitForWindowShown(m_view);
213 QTest::qWaitForWindowShown(m_view);
213 QVERIFY(!series->chart());
214 QVERIFY(!series->chart());
214 QCOMPARE(m_chart->series().count(), 0);
215 QCOMPARE(m_chart->series().count(), 0);
215 m_chart->addSeries(series);
216 m_chart->addSeries(series);
216 QCOMPARE(m_chart->series().count(), 1);
217 QCOMPARE(m_chart->series().count(), 1);
217 QCOMPARE(m_chart->series().first(), series);
218 QCOMPARE(m_chart->series().first(), series);
218 QVERIFY(series->chart() == m_chart);
219 QVERIFY(series->chart() == m_chart);
219 m_chart->createDefaultAxes();
220 m_chart->createDefaultAxes();
220 if(series->type()!=QAbstractSeries::SeriesTypePie){
221 if(series->type()!=QAbstractSeries::SeriesTypePie){
221 QVERIFY(m_chart->axisY(series));
222 QVERIFY(m_chart->axisY(series));
222 QVERIFY(m_chart->axisX(series));
223 QVERIFY(m_chart->axisX(series));
223 }else{
224 }else{
224 QVERIFY(!m_chart->axisY(series));
225 QVERIFY(!m_chart->axisY(series));
225 QVERIFY(!m_chart->axisX(series));
226 QVERIFY(!m_chart->axisX(series));
226 }
227 }
227 m_chart->removeSeries(series);
228 m_chart->removeSeries(series);
228 QVERIFY(!series->chart());
229 QVERIFY(!series->chart());
229 QCOMPARE(m_chart->series().count(), 0);
230 QCOMPARE(m_chart->series().count(), 0);
230 }
231 }
231
232
232 void tst_QChart::animationOptions_data()
233 void tst_QChart::animationOptions_data()
233 {
234 {
234 QTest::addColumn<QChart::AnimationOption>("animationOptions");
235 QTest::addColumn<QChart::AnimationOption>("animationOptions");
235 QTest::newRow("AllAnimations") << QChart::AllAnimations;
236 QTest::newRow("AllAnimations") << QChart::AllAnimations;
236 QTest::newRow("NoAnimation") << QChart::NoAnimation;
237 QTest::newRow("NoAnimation") << QChart::NoAnimation;
237 QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations;
238 QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations;
238 QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations;
239 QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations;
239 }
240 }
240
241
241 void tst_QChart::animationOptions()
242 void tst_QChart::animationOptions()
242 {
243 {
243 createTestData();
244 createTestData();
244 QFETCH(QChart::AnimationOption, animationOptions);
245 QFETCH(QChart::AnimationOption, animationOptions);
245 m_chart->setAnimationOptions(animationOptions);
246 m_chart->setAnimationOptions(animationOptions);
246 QCOMPARE(m_chart->animationOptions(), animationOptions);
247 QCOMPARE(m_chart->animationOptions(), animationOptions);
247 }
248 }
248
249
249 void tst_QChart::axisX_data()
250 void tst_QChart::axisX_data()
250 {
251 {
251
252
252 QTest::addColumn<QAbstractAxis*>("axis");
253 QTest::addColumn<QAbstractAxis*>("axis");
253 QTest::addColumn<QAbstractSeries *>("series");
254 QTest::addColumn<QAbstractSeries *>("series");
254
255
255 QTest::newRow("categories,lineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QLineSeries(this);
256 QTest::newRow("categories,lineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QLineSeries(this);
256 QTest::newRow("categories,areaSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this));
257 QTest::newRow("categories,areaSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this));
257 QTest::newRow("categories,scatterSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QScatterSeries(this);
258 QTest::newRow("categories,scatterSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QScatterSeries(this);
258 QTest::newRow("categories,splineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QSplineSeries(this);
259 QTest::newRow("categories,splineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QSplineSeries(this);
259 QTest::newRow("categories,pieSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPieSeries(this);
260 QTest::newRow("categories,pieSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPieSeries(this);
260 QTest::newRow("categories,barSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QBarSeries(this);
261 QTest::newRow("categories,barSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QBarSeries(this);
261 QTest::newRow("categories,percentBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPercentBarSeries(this);
262 QTest::newRow("categories,percentBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPercentBarSeries(this);
262 QTest::newRow("categories,stackedBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QStackedBarSeries(this);
263 QTest::newRow("categories,stackedBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QStackedBarSeries(this);
263
264
264 QTest::newRow("value,lineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QLineSeries(this);
265 QTest::newRow("value,lineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QLineSeries(this);
265 QTest::newRow("value,areaSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this));
266 QTest::newRow("value,areaSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this));
266 QTest::newRow("value,scatterSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QScatterSeries(this);
267 QTest::newRow("value,scatterSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QScatterSeries(this);
267 QTest::newRow("value,splineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QSplineSeries(this);
268 QTest::newRow("value,splineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QSplineSeries(this);
268 QTest::newRow("value,pieSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPieSeries(this);
269 QTest::newRow("value,pieSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPieSeries(this);
269 QTest::newRow("value,barSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QBarSeries(this);
270 QTest::newRow("value,barSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QBarSeries(this);
270 QTest::newRow("value,percentBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPercentBarSeries(this);
271 QTest::newRow("value,percentBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPercentBarSeries(this);
271 QTest::newRow("value,stackedBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QStackedBarSeries(this);
272 QTest::newRow("value,stackedBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QStackedBarSeries(this);
272
273
273 }
274 }
274
275
275 void tst_QChart::axisX()
276 void tst_QChart::axisX()
276 {
277 {
277 QFETCH(QAbstractAxis*, axis);
278 QFETCH(QAbstractAxis*, axis);
278 QFETCH(QAbstractSeries*, series);
279 QFETCH(QAbstractSeries*, series);
279 QVERIFY(!m_chart->axisX());
280 QVERIFY(!m_chart->axisX());
280 m_view->show();
281 m_view->show();
281 QTest::qWaitForWindowShown(m_view);
282 QTest::qWaitForWindowShown(m_view);
282 m_chart->addSeries(series);
283 m_chart->addSeries(series);
283 m_chart->setAxisX(axis,series);
284 m_chart->setAxisX(axis,series);
284 QVERIFY(m_chart->axisX(series)==axis);
285 QVERIFY(m_chart->axisX(series)==axis);
285 }
286 }
286
287
287 void tst_QChart::axisY_data()
288 void tst_QChart::axisY_data()
288 {
289 {
289 axisX_data();
290 axisX_data();
290 }
291 }
291
292
292
293
293 void tst_QChart::axisY()
294 void tst_QChart::axisY()
294 {
295 {
295 QFETCH(QAbstractAxis*, axis);
296 QFETCH(QAbstractAxis*, axis);
296 QFETCH(QAbstractSeries*, series);
297 QFETCH(QAbstractSeries*, series);
297 QVERIFY(!m_chart->axisY());
298 QVERIFY(!m_chart->axisY());
298 m_view->show();
299 m_view->show();
299 QTest::qWaitForWindowShown(m_view);
300 QTest::qWaitForWindowShown(m_view);
300 m_chart->addSeries(series);
301 m_chart->addSeries(series);
301 m_chart->setAxisY(axis,series);
302 m_chart->setAxisY(axis,series);
302 QVERIFY(m_chart->axisY(series)==axis);
303 QVERIFY(m_chart->axisY(series)==axis);
303 }
304 }
304
305
305 void tst_QChart::backgroundBrush_data()
306 void tst_QChart::backgroundBrush_data()
306 {
307 {
307 QTest::addColumn<QBrush>("backgroundBrush");
308 QTest::addColumn<QBrush>("backgroundBrush");
308 QTest::newRow("null") << QBrush();
309 QTest::newRow("null") << QBrush();
309 QTest::newRow("blue") << QBrush(Qt::blue);
310 QTest::newRow("blue") << QBrush(Qt::blue);
310 QTest::newRow("white") << QBrush(Qt::white);
311 QTest::newRow("white") << QBrush(Qt::white);
311 QTest::newRow("black") << QBrush(Qt::black);
312 QTest::newRow("black") << QBrush(Qt::black);
312 }
313 }
313
314
314 void tst_QChart::backgroundBrush()
315 void tst_QChart::backgroundBrush()
315 {
316 {
316 QFETCH(QBrush, backgroundBrush);
317 QFETCH(QBrush, backgroundBrush);
317 m_chart->setBackgroundBrush(backgroundBrush);
318 m_chart->setBackgroundBrush(backgroundBrush);
318 QCOMPARE(m_chart->backgroundBrush(), backgroundBrush);
319 QCOMPARE(m_chart->backgroundBrush(), backgroundBrush);
319 }
320 }
320
321
321 void tst_QChart::backgroundPen_data()
322 void tst_QChart::backgroundPen_data()
322 {
323 {
323 QTest::addColumn<QPen>("backgroundPen");
324 QTest::addColumn<QPen>("backgroundPen");
324 QTest::newRow("null") << QPen();
325 QTest::newRow("null") << QPen();
325 QTest::newRow("blue") << QPen(Qt::blue);
326 QTest::newRow("blue") << QPen(Qt::blue);
326 QTest::newRow("white") << QPen(Qt::white);
327 QTest::newRow("white") << QPen(Qt::white);
327 QTest::newRow("black") << QPen(Qt::black);
328 QTest::newRow("black") << QPen(Qt::black);
328 }
329 }
329
330
330
331
331 void tst_QChart::backgroundPen()
332 void tst_QChart::backgroundPen()
332 {
333 {
333 QFETCH(QPen, backgroundPen);
334 QFETCH(QPen, backgroundPen);
334 m_chart->setBackgroundPen(backgroundPen);
335 m_chart->setBackgroundPen(backgroundPen);
335 QCOMPARE(m_chart->backgroundPen(), backgroundPen);
336 QCOMPARE(m_chart->backgroundPen(), backgroundPen);
336 }
337 }
337
338
338 void tst_QChart::isBackgroundVisible_data()
339 void tst_QChart::isBackgroundVisible_data()
339 {
340 {
340 QTest::addColumn<bool>("isBackgroundVisible");
341 QTest::addColumn<bool>("isBackgroundVisible");
341 QTest::newRow("true") << true;
342 QTest::newRow("true") << true;
342 QTest::newRow("false") << false;
343 QTest::newRow("false") << false;
343 }
344 }
344
345
345 void tst_QChart::isBackgroundVisible()
346 void tst_QChart::isBackgroundVisible()
346 {
347 {
347 QFETCH(bool, isBackgroundVisible);
348 QFETCH(bool, isBackgroundVisible);
348 m_chart->setBackgroundVisible(isBackgroundVisible);
349 m_chart->setBackgroundVisible(isBackgroundVisible);
349 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
350 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
350 }
351 }
351
352
352 void tst_QChart::legend_data()
353 void tst_QChart::legend_data()
353 {
354 {
354
355
355 }
356 }
356
357
357 void tst_QChart::legend()
358 void tst_QChart::legend()
358 {
359 {
359 QLegend *legend = m_chart->legend();
360 QLegend *legend = m_chart->legend();
360 QVERIFY(legend);
361 QVERIFY(legend);
361
362
362 // Colors related signals
363 // Colors related signals
363 QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor)));
364 QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor)));
364 QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor)));
365 QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor)));
365 QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor)));
366 QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor)));
366
367
367 // colorChanged
368 // colorChanged
368 legend->setColor(QColor("aliceblue"));
369 legend->setColor(QColor("aliceblue"));
369 QCOMPARE(colorSpy.count(), 1);
370 QCOMPARE(colorSpy.count(), 1);
370 QBrush b = legend->brush();
371 QBrush b = legend->brush();
371 b.setColor(QColor("aqua"));
372 b.setColor(QColor("aqua"));
372 legend->setBrush(b);
373 legend->setBrush(b);
373 QCOMPARE(colorSpy.count(), 2);
374 QCOMPARE(colorSpy.count(), 2);
374
375
375 // borderColorChanged
376 // borderColorChanged
376 legend->setBorderColor(QColor("aliceblue"));
377 legend->setBorderColor(QColor("aliceblue"));
377 QCOMPARE(borderColorSpy.count(), 1);
378 QCOMPARE(borderColorSpy.count(), 1);
378 QPen p = legend->pen();
379 QPen p = legend->pen();
379 p.setColor(QColor("aqua"));
380 p.setColor(QColor("aqua"));
380 legend->setPen(p);
381 legend->setPen(p);
381 QCOMPARE(borderColorSpy.count(), 2);
382 QCOMPARE(borderColorSpy.count(), 2);
382
383
383 // labelColorChanged
384 // labelColorChanged
384 legend->setLabelColor(QColor("lightsalmon"));
385 legend->setLabelColor(QColor("lightsalmon"));
385 QCOMPARE(labelColorSpy.count(), 1);
386 QCOMPARE(labelColorSpy.count(), 1);
386 b = legend->labelBrush();
387 b = legend->labelBrush();
387 b.setColor(QColor("lightseagreen"));
388 b.setColor(QColor("lightseagreen"));
388 legend->setLabelBrush(b);
389 legend->setLabelBrush(b);
389 QCOMPARE(labelColorSpy.count(), 2);
390 QCOMPARE(labelColorSpy.count(), 2);
390
391
391 // fontChanged
392 // fontChanged
392 QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont)));
393 QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont)));
393 QFont f = legend->font();
394 QFont f = legend->font();
394 f.setBold(!f.bold());
395 f.setBold(!f.bold());
395 legend->setFont(f);
396 legend->setFont(f);
396 QCOMPARE(fontSpy.count(), 1);
397 QCOMPARE(fontSpy.count(), 1);
397 }
398 }
398
399
399 void tst_QChart::plotArea_data()
400 void tst_QChart::plotArea_data()
400 {
401 {
401
402
402 }
403 }
403
404
404 void tst_QChart::plotArea()
405 void tst_QChart::plotArea()
405 {
406 {
406 createTestData();
407 createTestData();
407 QRectF rect = m_chart->geometry();
408 QRectF rect = m_chart->geometry();
408 QVERIFY(m_chart->plotArea().isValid());
409 QVERIFY(m_chart->plotArea().isValid());
409 QVERIFY(m_chart->plotArea().height() < rect.height());
410 QVERIFY(m_chart->plotArea().height() < rect.height());
410 QVERIFY(m_chart->plotArea().width() < rect.width());
411 QVERIFY(m_chart->plotArea().width() < rect.width());
411 }
412 }
412
413
413 void tst_QChart::removeAllSeries_data()
414 void tst_QChart::removeAllSeries_data()
414 {
415 {
415
416
416 }
417 }
417
418
418 void tst_QChart::removeAllSeries()
419 void tst_QChart::removeAllSeries()
419 {
420 {
420 QLineSeries* series0 = new QLineSeries(this);
421 QLineSeries* series0 = new QLineSeries(this);
421 QLineSeries* series1 = new QLineSeries(this);
422 QLineSeries* series1 = new QLineSeries(this);
422 QLineSeries* series2 = new QLineSeries(this);
423 QLineSeries* series2 = new QLineSeries(this);
423 QSignalSpy deleteSpy1(series0, SIGNAL(destroyed()));
424 QSignalSpy deleteSpy1(series0, SIGNAL(destroyed()));
424 QSignalSpy deleteSpy2(series1, SIGNAL(destroyed()));
425 QSignalSpy deleteSpy2(series1, SIGNAL(destroyed()));
425 QSignalSpy deleteSpy3(series2, SIGNAL(destroyed()));
426 QSignalSpy deleteSpy3(series2, SIGNAL(destroyed()));
426
427
427 m_chart->addSeries(series0);
428 m_chart->addSeries(series0);
428 m_chart->addSeries(series1);
429 m_chart->addSeries(series1);
429 m_chart->addSeries(series2);
430 m_chart->addSeries(series2);
430 m_view->show();
431 m_view->show();
431 QTest::qWaitForWindowShown(m_view);
432 QTest::qWaitForWindowShown(m_view);
432 m_chart->createDefaultAxes();
433 m_chart->createDefaultAxes();
433 QVERIFY(m_chart->axisY(series0)!=0);
434 QVERIFY(m_chart->axisY(series0)!=0);
434 QVERIFY(m_chart->axisY(series1)!=0);
435 QVERIFY(m_chart->axisY(series1)!=0);
435 QVERIFY(m_chart->axisY(series2)!=0);
436 QVERIFY(m_chart->axisY(series2)!=0);
436
437
437 m_chart->removeAllSeries();
438 m_chart->removeAllSeries();
438 QVERIFY(m_chart->axisY(series0)==0);
439 QVERIFY(m_chart->axisY(series0)==0);
439 QVERIFY(m_chart->axisY(series1)==0);
440 QVERIFY(m_chart->axisY(series1)==0);
440 QVERIFY(m_chart->axisY(series2)==0);
441 QVERIFY(m_chart->axisY(series2)==0);
441 QCOMPARE(deleteSpy1.count(), 1);
442 QCOMPARE(deleteSpy1.count(), 1);
442 QCOMPARE(deleteSpy2.count(), 1);
443 QCOMPARE(deleteSpy2.count(), 1);
443 QCOMPARE(deleteSpy3.count(), 1);
444 QCOMPARE(deleteSpy3.count(), 1);
444 }
445 }
445
446
446 void tst_QChart::removeSeries_data()
447 void tst_QChart::removeSeries_data()
447 {
448 {
448 axisX_data();
449 axisX_data();
449 }
450 }
450
451
451 void tst_QChart::removeSeries()
452 void tst_QChart::removeSeries()
452 {
453 {
453 QFETCH(QAbstractAxis *, axis);
454 QFETCH(QAbstractAxis *, axis);
454 QFETCH(QAbstractSeries *, series);
455 QFETCH(QAbstractSeries *, series);
455 QSignalSpy deleteSpy(series, SIGNAL(destroyed()));
456 QSignalSpy deleteSpy(series, SIGNAL(destroyed()));
456 m_view->show();
457 m_view->show();
457 QTest::qWaitForWindowShown(m_view);
458 QTest::qWaitForWindowShown(m_view);
458 if(!axis) axis = m_chart->axisY();
459 if(!axis) axis = m_chart->axisY();
459 m_chart->addSeries(series);
460 m_chart->addSeries(series);
460 m_chart->setAxisY(axis,series);
461 m_chart->setAxisY(axis,series);
461 QCOMPARE(m_chart->axisY(series),axis);
462 QCOMPARE(m_chart->axisY(series),axis);
462 m_chart->removeSeries(series);
463 m_chart->removeSeries(series);
463 QVERIFY(m_chart->axisY(series)==0);
464 QVERIFY(m_chart->axisY(series)==0);
464 QCOMPARE(deleteSpy.count(), 0);
465 QCOMPARE(deleteSpy.count(), 0);
465 }
466 }
466
467
467 void tst_QChart::scroll_right_data()
468 void tst_QChart::scroll_right_data()
468 {
469 {
469 QTest::addColumn<QAbstractSeries *>("series");
470 QTest::addColumn<QAbstractSeries *>("series");
470
471
471 QLineSeries* series0 = new QLineSeries(this);
472 QLineSeries* series0 = new QLineSeries(this);
472 *series0 << QPointF(0, 0) << QPointF(100, 100);
473 *series0 << QPointF(0, 0) << QPointF(100, 100);
473
474
474 QTest::newRow("lineSeries") << (QAbstractSeries*) series0;
475 QTest::newRow("lineSeries") << (QAbstractSeries*) series0;
475
476
476
477
477 }
478 }
478
479
479 void tst_QChart::scroll_right()
480 void tst_QChart::scroll_right()
480 {
481 {
481 QFETCH(QAbstractSeries *, series);
482 QFETCH(QAbstractSeries *, series);
482 m_chart->addSeries(series);
483 m_chart->addSeries(series);
483 m_chart->createDefaultAxes();
484 m_chart->createDefaultAxes();
484 m_view->show();
485 m_view->show();
485 QTest::qWaitForWindowShown(m_view);
486 QTest::qWaitForWindowShown(m_view);
486 QAbstractAxis * axis = m_chart->axisX();
487 QAbstractAxis * axis = m_chart->axisX();
487 QVERIFY(axis!=0);
488 QVERIFY(axis!=0);
488
489
489 switch(axis->type())
490 switch(axis->type())
490 {
491 {
491 case QAbstractAxis::AxisTypeValue:{
492 case QAbstractAxis::AxisTypeValue:{
492 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
493 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
493 QVERIFY(vaxis!=0);
494 QVERIFY(vaxis!=0);
494 qreal min = vaxis->min();
495 qreal min = vaxis->min();
495 qreal max = vaxis->max();
496 qreal max = vaxis->max();
496 QVERIFY(max>min);
497 QVERIFY(max>min);
497 m_chart->scroll(50, 0);
498 m_chart->scroll(50, 0);
498 QVERIFY(min<vaxis->min());
499 QVERIFY(min<vaxis->min());
499 QVERIFY(max<vaxis->max());
500 QVERIFY(max<vaxis->max());
500 break;
501 break;
501 }
502 }
502 case QAbstractAxis::AxisTypeBarCategory:{
503 case QAbstractAxis::AxisTypeBarCategory:{
503 QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis);
504 QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis);
504 QVERIFY(caxis!=0);
505 QVERIFY(caxis!=0);
505 qreal min = caxis->min().toDouble();
506 qreal min = caxis->min().toDouble();
506 qreal max = caxis->max().toDouble();
507 qreal max = caxis->max().toDouble();
507 m_chart->scroll(50, 0);
508 m_chart->scroll(50, 0);
508 QVERIFY(min<caxis->min().toDouble());
509 QVERIFY(min<caxis->min().toDouble());
509 QVERIFY(max<caxis->max().toDouble());
510 QVERIFY(max<caxis->max().toDouble());
510 break;
511 break;
511 }
512 }
512 default:
513 default:
513 qFatal("Unsupported type");
514 qFatal("Unsupported type");
514 break;
515 break;
515 }
516 }
516 }
517 }
517
518
518 void tst_QChart::scroll_left_data()
519 void tst_QChart::scroll_left_data()
519 {
520 {
520 scroll_right_data();
521 scroll_right_data();
521 }
522 }
522
523
523 void tst_QChart::scroll_left()
524 void tst_QChart::scroll_left()
524 {
525 {
525 QFETCH(QAbstractSeries *, series);
526 QFETCH(QAbstractSeries *, series);
526 m_chart->addSeries(series);
527 m_chart->addSeries(series);
527 m_chart->createDefaultAxes();
528 m_chart->createDefaultAxes();
528 m_view->show();
529 m_view->show();
529 QTest::qWaitForWindowShown(m_view);
530 QTest::qWaitForWindowShown(m_view);
530 QAbstractAxis * axis = m_chart->axisX();
531 QAbstractAxis * axis = m_chart->axisX();
531 QVERIFY(axis!=0);
532 QVERIFY(axis!=0);
532
533
533 switch(axis->type())
534 switch(axis->type())
534 {
535 {
535 case QAbstractAxis::AxisTypeValue:{
536 case QAbstractAxis::AxisTypeValue:{
536 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
537 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
537 QVERIFY(vaxis!=0);
538 QVERIFY(vaxis!=0);
538 qreal min = vaxis->min();
539 qreal min = vaxis->min();
539 qreal max = vaxis->max();
540 qreal max = vaxis->max();
540 m_chart->scroll(-50, 0);
541 m_chart->scroll(-50, 0);
541 QVERIFY(min>vaxis->min());
542 QVERIFY(min>vaxis->min());
542 QVERIFY(max>vaxis->max());
543 QVERIFY(max>vaxis->max());
543 break;
544 break;
544 }
545 }
545 case QAbstractAxis::AxisTypeBarCategory:{
546 case QAbstractAxis::AxisTypeBarCategory:{
546 QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis);
547 QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis);
547 QVERIFY(caxis!=0);
548 QVERIFY(caxis!=0);
548 qreal min = caxis->min().toDouble();
549 qreal min = caxis->min().toDouble();
549 qreal max = caxis->max().toDouble();
550 qreal max = caxis->max().toDouble();
550 m_chart->scroll(-50, 0);
551 m_chart->scroll(-50, 0);
551 QVERIFY(min>caxis->min().toDouble());
552 QVERIFY(min>caxis->min().toDouble());
552 QVERIFY(max>caxis->max().toDouble());
553 QVERIFY(max>caxis->max().toDouble());
553 break;
554 break;
554 }
555 }
555 default:
556 default:
556 qFatal("Unsupported type");
557 qFatal("Unsupported type");
557 break;
558 break;
558 }
559 }
559 }
560 }
560
561
561 void tst_QChart::scroll_up_data()
562 void tst_QChart::scroll_up_data()
562 {
563 {
563 scroll_right_data();
564 scroll_right_data();
564 }
565 }
565
566
566 void tst_QChart::scroll_up()
567 void tst_QChart::scroll_up()
567 {
568 {
568 QFETCH(QAbstractSeries *, series);
569 QFETCH(QAbstractSeries *, series);
569 m_chart->addSeries(series);
570 m_chart->addSeries(series);
570 m_chart->createDefaultAxes();
571 m_chart->createDefaultAxes();
571 m_view->show();
572 m_view->show();
572 QTest::qWaitForWindowShown(m_view);
573 QTest::qWaitForWindowShown(m_view);
573 QAbstractAxis * axis = m_chart->axisY();
574 QAbstractAxis * axis = m_chart->axisY();
574 QVERIFY(axis!=0);
575 QVERIFY(axis!=0);
575
576
576 switch(axis->type())
577 switch(axis->type())
577 {
578 {
578 case QAbstractAxis::AxisTypeValue:{
579 case QAbstractAxis::AxisTypeValue:{
579 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
580 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
580 QVERIFY(vaxis!=0);
581 QVERIFY(vaxis!=0);
581 qreal min = vaxis->min();
582 qreal min = vaxis->min();
582 qreal max = vaxis->max();
583 qreal max = vaxis->max();
583 m_chart->scroll(0, 50);
584 m_chart->scroll(0, 50);
584 QVERIFY(min<vaxis->min());
585 QVERIFY(min<vaxis->min());
585 QVERIFY(max<vaxis->max());
586 QVERIFY(max<vaxis->max());
586 break;
587 break;
587 }
588 }
588 case QAbstractAxis::AxisTypeBarCategory:{
589 case QAbstractAxis::AxisTypeBarCategory:{
589 QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis);
590 QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis);
590 QVERIFY(caxis!=0);
591 QVERIFY(caxis!=0);
591 qreal min = caxis->min().toDouble();
592 qreal min = caxis->min().toDouble();
592 qreal max = caxis->max().toDouble();
593 qreal max = caxis->max().toDouble();
593 m_chart->scroll(0, 50);
594 m_chart->scroll(0, 50);
594 QVERIFY(min<caxis->min().toDouble());
595 QVERIFY(min<caxis->min().toDouble());
595 QVERIFY(max<caxis->max().toDouble());
596 QVERIFY(max<caxis->max().toDouble());
596 break;
597 break;
597 }
598 }
598 default:
599 default:
599 qFatal("Unsupported type");
600 qFatal("Unsupported type");
600 break;
601 break;
601 }
602 }
602 }
603 }
603
604
604 void tst_QChart::scroll_down_data()
605 void tst_QChart::scroll_down_data()
605 {
606 {
606 scroll_right_data();
607 scroll_right_data();
607 }
608 }
608
609
609 void tst_QChart::scroll_down()
610 void tst_QChart::scroll_down()
610 {
611 {
611 QFETCH(QAbstractSeries *, series);
612 QFETCH(QAbstractSeries *, series);
612 m_chart->addSeries(series);
613 m_chart->addSeries(series);
613 m_chart->createDefaultAxes();
614 m_chart->createDefaultAxes();
614 m_view->show();
615 m_view->show();
615 QTest::qWaitForWindowShown(m_view);
616 QTest::qWaitForWindowShown(m_view);
616 QAbstractAxis * axis = m_chart->axisY();
617 QAbstractAxis * axis = m_chart->axisY();
617 QVERIFY(axis!=0);
618 QVERIFY(axis!=0);
618
619
619 switch(axis->type())
620 switch(axis->type())
620 {
621 {
621 case QAbstractAxis::AxisTypeValue:{
622 case QAbstractAxis::AxisTypeValue:{
622 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
623 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
623 QVERIFY(vaxis!=0);
624 QVERIFY(vaxis!=0);
624 qreal min = vaxis->min();
625 qreal min = vaxis->min();
625 qreal max = vaxis->max();
626 qreal max = vaxis->max();
626 m_chart->scroll(0, -50);
627 m_chart->scroll(0, -50);
627 QVERIFY(min>vaxis->min());
628 QVERIFY(min>vaxis->min());
628 QVERIFY(max>vaxis->max());
629 QVERIFY(max>vaxis->max());
629 break;
630 break;
630 }
631 }
631 case QAbstractAxis::AxisTypeBarCategory:{
632 case QAbstractAxis::AxisTypeBarCategory:{
632 QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis);
633 QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis);
633 QVERIFY(caxis!=0);
634 QVERIFY(caxis!=0);
634 qreal min = caxis->min().toDouble();
635 qreal min = caxis->min().toDouble();
635 qreal max = caxis->max().toDouble();
636 qreal max = caxis->max().toDouble();
636 m_chart->scroll(0, -50);
637 m_chart->scroll(0, -50);
637 QVERIFY(min>caxis->min().toDouble());
638 QVERIFY(min>caxis->min().toDouble());
638 QVERIFY(max>caxis->max().toDouble());
639 QVERIFY(max>caxis->max().toDouble());
639 break;
640 break;
640 }
641 }
641 default:
642 default:
642 qFatal("Unsupported type");
643 qFatal("Unsupported type");
643 break;
644 break;
644 }
645 }
645 }
646 }
646
647
647 void tst_QChart::theme_data()
648 void tst_QChart::theme_data()
648 {
649 {
649 QTest::addColumn<QChart::ChartTheme>("theme");
650 QTest::addColumn<QChart::ChartTheme>("theme");
650 QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean;
651 QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean;
651 QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy;
652 QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy;
652 QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs;
653 QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs;
653 QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand;
654 QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand;
654 QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark;
655 QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark;
655 QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast;
656 QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast;
656 QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight;
657 QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight;
657 }
658 }
658
659
659 void tst_QChart::theme()
660 void tst_QChart::theme()
660 {
661 {
661 QFETCH(QChart::ChartTheme, theme);
662 QFETCH(QChart::ChartTheme, theme);
662 createTestData();
663 createTestData();
663 m_chart->setTheme(theme);
664 m_chart->setTheme(theme);
664 QVERIFY(m_chart->theme()==theme);
665 QVERIFY(m_chart->theme()==theme);
665 }
666 }
666
667
667 void tst_QChart::title_data()
668 void tst_QChart::title_data()
668 {
669 {
669 QTest::addColumn<QString>("title");
670 QTest::addColumn<QString>("title");
670 QTest::newRow("null") << QString();
671 QTest::newRow("null") << QString();
671 QTest::newRow("foo") << QString("foo");
672 QTest::newRow("foo") << QString("foo");
672 }
673 }
673
674
674 void tst_QChart::title()
675 void tst_QChart::title()
675 {
676 {
676 QFETCH(QString, title);
677 QFETCH(QString, title);
677 m_chart->setTitle(title);
678 m_chart->setTitle(title);
678 QCOMPARE(m_chart->title(), title);
679 QCOMPARE(m_chart->title(), title);
679 }
680 }
680
681
681 void tst_QChart::titleBrush_data()
682 void tst_QChart::titleBrush_data()
682 {
683 {
683 QTest::addColumn<QBrush>("titleBrush");
684 QTest::addColumn<QBrush>("titleBrush");
684 QTest::newRow("null") << QBrush();
685 QTest::newRow("null") << QBrush();
685 QTest::newRow("blue") << QBrush(Qt::blue);
686 QTest::newRow("blue") << QBrush(Qt::blue);
686 QTest::newRow("white") << QBrush(Qt::white);
687 QTest::newRow("white") << QBrush(Qt::white);
687 QTest::newRow("black") << QBrush(Qt::black);
688 QTest::newRow("black") << QBrush(Qt::black);
688 }
689 }
689
690
690 void tst_QChart::titleBrush()
691 void tst_QChart::titleBrush()
691 {
692 {
692 QFETCH(QBrush, titleBrush);
693 QFETCH(QBrush, titleBrush);
693 m_chart->setTitleBrush(titleBrush);
694 m_chart->setTitleBrush(titleBrush);
694 QCOMPARE(m_chart->titleBrush(), titleBrush);
695 QCOMPARE(m_chart->titleBrush(), titleBrush);
695 }
696 }
696
697
697 void tst_QChart::titleFont_data()
698 void tst_QChart::titleFont_data()
698 {
699 {
699 QTest::addColumn<QFont>("titleFont");
700 QTest::addColumn<QFont>("titleFont");
700 QTest::newRow("null") << QFont();
701 QTest::newRow("null") << QFont();
701 QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true);
702 QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true);
702 }
703 }
703
704
704 void tst_QChart::titleFont()
705 void tst_QChart::titleFont()
705 {
706 {
706 QFETCH(QFont, titleFont);
707 QFETCH(QFont, titleFont);
707 m_chart->setTitleFont(titleFont);
708 m_chart->setTitleFont(titleFont);
708 QCOMPARE(m_chart->titleFont(), titleFont);
709 QCOMPARE(m_chart->titleFont(), titleFont);
709 }
710 }
710
711
711 void tst_QChart::zoomIn_data()
712 void tst_QChart::zoomIn_data()
712 {
713 {
713 QTest::addColumn<QRectF>("rect");
714 QTest::addColumn<QRectF>("rect");
714 QTest::newRow("null") << QRectF();
715 QTest::newRow("null") << QRectF();
715 QTest::newRow("100x100") << QRectF(10,10,100,100);
716 QTest::newRow("100x100") << QRectF(10,10,100,100);
716 QTest::newRow("200x200") << QRectF(10,10,200,200);
717 QTest::newRow("200x200") << QRectF(10,10,200,200);
717 }
718 }
718
719
719
720
720 void tst_QChart::zoomIn()
721 void tst_QChart::zoomIn()
721 {
722 {
722
723
723 QFETCH(QRectF, rect);
724 QFETCH(QRectF, rect);
724 createTestData();
725 createTestData();
725 m_chart->createDefaultAxes();
726 m_chart->createDefaultAxes();
726 QRectF marigns = m_chart->plotArea();
727 QRectF marigns = m_chart->plotArea();
727 rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom());
728 rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom());
728 QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX());
729 QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX());
729 QVERIFY(axisX!=0);
730 QVERIFY(axisX!=0);
730 QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY());
731 QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY());
731 QVERIFY(axisY!=0);
732 QVERIFY(axisY!=0);
732 qreal minX = axisX->min();
733 qreal minX = axisX->min();
733 qreal minY = axisY->min();
734 qreal minY = axisY->min();
734 qreal maxX = axisX->max();
735 qreal maxX = axisX->max();
735 qreal maxY = axisY->max();
736 qreal maxY = axisY->max();
736 m_chart->zoomIn(rect);
737 m_chart->zoomIn(rect);
737 if(rect.isValid()){
738 if(rect.isValid()){
738 QVERIFY(minX<axisX->min());
739 QVERIFY(minX<axisX->min());
739 QVERIFY(maxX>axisX->max());
740 QVERIFY(maxX>axisX->max());
740 QVERIFY(minY<axisY->min());
741 QVERIFY(minY<axisY->min());
741 QVERIFY(maxY>axisY->max());
742 QVERIFY(maxY>axisY->max());
742 }
743 }
743
744
744 }
745 }
745
746
746 void tst_QChart::zoomOut_data()
747 void tst_QChart::zoomOut_data()
747 {
748 {
748
749
749 }
750 }
750
751
751 void tst_QChart::zoomOut()
752 void tst_QChart::zoomOut()
752 {
753 {
753 createTestData();
754 createTestData();
754 m_chart->createDefaultAxes();
755 m_chart->createDefaultAxes();
755
756
756 QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX());
757 QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX());
757 QVERIFY(axisX!=0);
758 QVERIFY(axisX!=0);
758 QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY());
759 QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY());
759 QVERIFY(axisY!=0);
760 QVERIFY(axisY!=0);
760
761
761 qreal minX = axisX->min();
762 qreal minX = axisX->min();
762 qreal minY = axisY->min();
763 qreal minY = axisY->min();
763 qreal maxX = axisX->max();
764 qreal maxX = axisX->max();
764 qreal maxY = axisY->max();
765 qreal maxY = axisY->max();
765
766
766 m_chart->zoomIn();
767 m_chart->zoomIn();
767
768
768 QVERIFY(minX < axisX->min());
769 QVERIFY(minX < axisX->min());
769 QVERIFY(maxX > axisX->max());
770 QVERIFY(maxX > axisX->max());
770 QVERIFY(minY < axisY->min());
771 QVERIFY(minY < axisY->min());
771 QVERIFY(maxY > axisY->max());
772 QVERIFY(maxY > axisY->max());
772
773
773 m_chart->zoomOut();
774 m_chart->zoomOut();
774
775
775 // min x may be a zero value
776 // min x may be a zero value
776 if (qFuzzyIsNull(minX))
777 if (qFuzzyIsNull(minX))
777 QVERIFY(qFuzzyIsNull(axisX->min()));
778 QVERIFY(qFuzzyIsNull(axisX->min()));
778 else
779 else
779 QCOMPARE(minX, axisX->min());
780 QCOMPARE(minX, axisX->min());
780
781
781 // min y may be a zero value
782 // min y may be a zero value
782 if (qFuzzyIsNull(minY))
783 if (qFuzzyIsNull(minY))
783 QVERIFY(qFuzzyIsNull(axisY->min()));
784 QVERIFY(qFuzzyIsNull(axisY->min()));
784 else
785 else
785 QCOMPARE(minY, axisY->min());
786 QCOMPARE(minY, axisY->min());
786
787
787 QVERIFY(maxX == axisX->max());
788 QVERIFY(maxX == axisX->max());
788 QVERIFY(maxY == axisY->max());
789 QVERIFY(maxY == axisY->max());
789
790
790 }
791 }
791
792
792 QTEST_MAIN(tst_QChart)
793 QTEST_MAIN(tst_QChart)
793 #include "tst_qchart.moc"
794 #include "tst_qchart.moc"
794
795
General Comments 0
You need to be logged in to leave comments. Login now