@@ -1,112 +1,112 | |||||
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 <Q |
|
29 | #include <QBarSeries> | |
30 | #include <QBarSet> |
|
30 | #include <QBarSet> | |
31 | #include <QVBarModelMapper> |
|
31 | #include <QVBarModelMapper> | |
32 | #include <QHeaderView> |
|
32 | #include <QHeaderView> | |
33 | #include <QCategoriesAxis> |
|
33 | #include <QCategoriesAxis> | |
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 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); |
|
51 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); | |
52 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); |
|
52 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); | |
53 | //! [2] |
|
53 | //! [2] | |
54 |
|
54 | |||
55 | //! [3] |
|
55 | //! [3] | |
56 | QChart *chart = new QChart; |
|
56 | QChart *chart = new QChart; | |
57 | chart->setAnimationOptions(QChart::AllAnimations); |
|
57 | chart->setAnimationOptions(QChart::AllAnimations); | |
58 | //! [3] |
|
58 | //! [3] | |
59 |
|
59 | |||
60 | // series 1 |
|
60 | // series 1 | |
61 | //! [4] |
|
61 | //! [4] | |
62 |
Q |
|
62 | QBarSeries *series = new QBarSeries; | |
63 |
|
63 | |||
64 | int first = 3; |
|
64 | int first = 3; | |
65 | int count = 5; |
|
65 | int count = 5; | |
66 | QVBarModelMapper *mapper = new QVBarModelMapper(this); |
|
66 | QVBarModelMapper *mapper = new QVBarModelMapper(this); | |
67 | mapper->setFirstBarSetColumn(1); |
|
67 | mapper->setFirstBarSetColumn(1); | |
68 | mapper->setLastBarSetColumn(4); |
|
68 | mapper->setLastBarSetColumn(4); | |
69 | mapper->setFirstRow(first); |
|
69 | mapper->setFirstRow(first); | |
70 | mapper->setRowCount(count); |
|
70 | mapper->setRowCount(count); | |
71 | mapper->setSeries(series); |
|
71 | mapper->setSeries(series); | |
72 | mapper->setModel(model); |
|
72 | mapper->setModel(model); | |
73 | chart->addSeries(series); |
|
73 | chart->addSeries(series); | |
74 | //! [4] |
|
74 | //! [4] | |
75 |
|
75 | |||
76 | //! [5] |
|
76 | //! [5] | |
77 | // for storing color hex from the series |
|
77 | // for storing color hex from the series | |
78 | QString seriesColorHex = "#000000"; |
|
78 | QString seriesColorHex = "#000000"; | |
79 |
|
79 | |||
80 | // get the color of the series and use it for showing the mapped area |
|
80 | // get the color of the series and use it for showing the mapped area | |
81 | QList<QBarSet*> barsets = series->barSets(); |
|
81 | QList<QBarSet*> barsets = series->barSets(); | |
82 | for (int i = 0; i < barsets.count(); i++) { |
|
82 | for (int i = 0; i < barsets.count(); i++) { | |
83 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); |
|
83 | 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())); |
|
84 | model->addMapping(seriesColorHex, QRect(1 + i, first, 1, barsets.at(i)->count())); | |
85 | } |
|
85 | } | |
86 | //! [5] |
|
86 | //! [5] | |
87 |
|
87 | |||
88 | //! [6] |
|
88 | //! [6] | |
89 | QStringList categories; |
|
89 | QStringList categories; | |
90 | categories << "April" << "May" << "June" << "July" << "August"; |
|
90 | categories << "April" << "May" << "June" << "July" << "August"; | |
91 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
91 | QCategoriesAxis* axis = new QCategoriesAxis(); | |
92 | axis->append(categories); |
|
92 | axis->append(categories); | |
93 | chart->createDefaultAxes(); |
|
93 | chart->createDefaultAxes(); | |
94 | chart->setAxisX(axis, series); |
|
94 | chart->setAxisX(axis, series); | |
95 | //! [6] |
|
95 | //! [6] | |
96 |
|
96 | |||
97 | //! [7] |
|
97 | //! [7] | |
98 | QChartView *chartView = new QChartView(chart); |
|
98 | QChartView *chartView = new QChartView(chart); | |
99 | chartView->setRenderHint(QPainter::Antialiasing); |
|
99 | chartView->setRenderHint(QPainter::Antialiasing); | |
100 | chartView->setMinimumSize(640, 480); |
|
100 | chartView->setMinimumSize(640, 480); | |
101 | //! [7] |
|
101 | //! [7] | |
102 |
|
102 | |||
103 | //! [8] |
|
103 | //! [8] | |
104 | // create main layout |
|
104 | // create main layout | |
105 | QGridLayout* mainLayout = new QGridLayout; |
|
105 | QGridLayout* mainLayout = new QGridLayout; | |
106 | mainLayout->addWidget(tableView, 1, 0); |
|
106 | mainLayout->addWidget(tableView, 1, 0); | |
107 | mainLayout->addWidget(chartView, 1, 1); |
|
107 | mainLayout->addWidget(chartView, 1, 1); | |
108 | mainLayout->setColumnStretch(1, 1); |
|
108 | mainLayout->setColumnStretch(1, 1); | |
109 | mainLayout->setColumnStretch(0, 0); |
|
109 | mainLayout->setColumnStretch(0, 0); | |
110 | setLayout(mainLayout); |
|
110 | setLayout(mainLayout); | |
111 | //! [8] |
|
111 | //! [8] | |
112 | } |
|
112 | } |
@@ -1,92 +1,92 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 |
#include <Q |
|
24 | #include <QBarSeries> | |
25 | #include <QBarSet> |
|
25 | #include <QBarSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 | #include <QCategoriesAxis> |
|
27 | #include <QCategoriesAxis> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | QTCOMMERCIALCHART_USE_NAMESPACE | |
30 |
|
30 | |||
31 | int main(int argc, char *argv[]) |
|
31 | int main(int argc, char *argv[]) | |
32 | { |
|
32 | { | |
33 | QApplication a(argc, argv); |
|
33 | QApplication a(argc, argv); | |
34 |
|
34 | |||
35 | //![1] |
|
35 | //![1] | |
36 | QBarSet *set0 = new QBarSet("Jane"); |
|
36 | QBarSet *set0 = new QBarSet("Jane"); | |
37 | QBarSet *set1 = new QBarSet("John"); |
|
37 | QBarSet *set1 = new QBarSet("John"); | |
38 | QBarSet *set2 = new QBarSet("Axel"); |
|
38 | QBarSet *set2 = new QBarSet("Axel"); | |
39 | QBarSet *set3 = new QBarSet("Mary"); |
|
39 | QBarSet *set3 = new QBarSet("Mary"); | |
40 | QBarSet *set4 = new QBarSet("Samantha"); |
|
40 | QBarSet *set4 = new QBarSet("Samantha"); | |
41 |
|
41 | |||
42 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
42 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
43 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
43 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
44 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
44 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
45 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
45 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
46 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
46 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
47 | //![1] |
|
47 | //![1] | |
48 |
|
48 | |||
49 | //![2] |
|
49 | //![2] | |
50 |
Q |
|
50 | QBarSeries* series = new QBarSeries(); | |
51 | series->append(set0); |
|
51 | series->append(set0); | |
52 | series->append(set1); |
|
52 | series->append(set1); | |
53 | series->append(set2); |
|
53 | series->append(set2); | |
54 | series->append(set3); |
|
54 | series->append(set3); | |
55 | series->append(set4); |
|
55 | series->append(set4); | |
56 |
|
56 | |||
57 | //![2] |
|
57 | //![2] | |
58 |
|
58 | |||
59 | //![3] |
|
59 | //![3] | |
60 | QChart* chart = new QChart(); |
|
60 | QChart* chart = new QChart(); | |
61 | chart->addSeries(series); |
|
61 | chart->addSeries(series); | |
62 |
chart->setTitle("Simple |
|
62 | chart->setTitle("Simple barchart example"); | |
63 | chart->createDefaultAxes(); |
|
63 | chart->createDefaultAxes(); | |
64 | //![3] |
|
64 | //![3] | |
65 |
|
65 | |||
66 | //![4] |
|
66 | //![4] | |
67 | QStringList categories; |
|
67 | QStringList categories; | |
68 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
68 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
69 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
69 | QCategoriesAxis* axis = new QCategoriesAxis(); | |
70 | axis->append(categories); |
|
70 | axis->append(categories); | |
71 | chart->setAxisX(axis,series); |
|
71 | chart->setAxisX(axis,series); | |
72 | //![4] |
|
72 | //![4] | |
73 |
|
73 | |||
74 | //![5] |
|
74 | //![5] | |
75 | chart->legend()->setVisible(true); |
|
75 | chart->legend()->setVisible(true); | |
76 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
76 | chart->legend()->setAlignment(Qt::AlignBottom); | |
77 | //![5] |
|
77 | //![5] | |
78 |
|
78 | |||
79 | //![6] |
|
79 | //![6] | |
80 | QChartView* chartView = new QChartView(chart); |
|
80 | QChartView* chartView = new QChartView(chart); | |
81 | chartView->setRenderHint(QPainter::Antialiasing); |
|
81 | chartView->setRenderHint(QPainter::Antialiasing); | |
82 | //![6] |
|
82 | //![6] | |
83 |
|
83 | |||
84 | //![7] |
|
84 | //![7] | |
85 | QMainWindow window; |
|
85 | QMainWindow window; | |
86 | window.setCentralWidget(chartView); |
|
86 | window.setCentralWidget(chartView); | |
87 | window.resize(400, 300); |
|
87 | window.resize(400, 300); | |
88 | window.show(); |
|
88 | window.show(); | |
89 | //![7] |
|
89 | //![7] | |
90 |
|
90 | |||
91 | return a.exec(); |
|
91 | return a.exec(); | |
92 | } |
|
92 | } |
@@ -1,262 +1,262 | |||||
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 "mainwidget.h" |
|
21 | #include "mainwidget.h" | |
22 | #include <QChart> |
|
22 | #include <QChart> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QPushButton> |
|
24 | #include <QPushButton> | |
25 | #include <QLabel> |
|
25 | #include <QLabel> | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
27 | #include <QBarSet> |
|
27 | #include <QBarSet> | |
28 |
#include <Q |
|
28 | #include <QBarSeries> | |
29 | #include <QLegend> |
|
29 | #include <QLegend> | |
30 | #include <QFormLayout> |
|
30 | #include <QFormLayout> | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
32 | QTCOMMERCIALCHART_USE_NAMESPACE | |
33 |
|
33 | |||
34 | MainWidget::MainWidget(QWidget *parent) : |
|
34 | MainWidget::MainWidget(QWidget *parent) : | |
35 | QWidget(parent) |
|
35 | QWidget(parent) | |
36 | { |
|
36 | { | |
37 | // Create buttons for ui |
|
37 | // Create buttons for ui | |
38 | m_buttonLayout = new QGridLayout(); |
|
38 | m_buttonLayout = new QGridLayout(); | |
39 | QPushButton *detachLegendButton = new QPushButton("detach legend"); |
|
39 | QPushButton *detachLegendButton = new QPushButton("detach legend"); | |
40 | connect(detachLegendButton, SIGNAL(clicked()), this, SLOT(detachLegend())); |
|
40 | connect(detachLegendButton, SIGNAL(clicked()), this, SLOT(detachLegend())); | |
41 | m_buttonLayout->addWidget(detachLegendButton, 0, 0); |
|
41 | m_buttonLayout->addWidget(detachLegendButton, 0, 0); | |
42 | QPushButton *attachLegendButton = new QPushButton("attach legend"); |
|
42 | QPushButton *attachLegendButton = new QPushButton("attach legend"); | |
43 | connect(attachLegendButton, SIGNAL(clicked()), this, SLOT(attachLegend())); |
|
43 | connect(attachLegendButton, SIGNAL(clicked()), this, SLOT(attachLegend())); | |
44 | m_buttonLayout->addWidget(attachLegendButton, 1, 0); |
|
44 | m_buttonLayout->addWidget(attachLegendButton, 1, 0); | |
45 |
|
45 | |||
46 | QPushButton *addSetButton = new QPushButton("add barset"); |
|
46 | QPushButton *addSetButton = new QPushButton("add barset"); | |
47 | connect(addSetButton, SIGNAL(clicked()), this, SLOT(addBarset())); |
|
47 | connect(addSetButton, SIGNAL(clicked()), this, SLOT(addBarset())); | |
48 | m_buttonLayout->addWidget(addSetButton, 2, 0); |
|
48 | m_buttonLayout->addWidget(addSetButton, 2, 0); | |
49 | QPushButton *removeBarsetButton = new QPushButton("remove barset"); |
|
49 | QPushButton *removeBarsetButton = new QPushButton("remove barset"); | |
50 | connect(removeBarsetButton, SIGNAL(clicked()), this, SLOT(removeBarset())); |
|
50 | connect(removeBarsetButton, SIGNAL(clicked()), this, SLOT(removeBarset())); | |
51 | m_buttonLayout->addWidget(removeBarsetButton, 3, 0); |
|
51 | m_buttonLayout->addWidget(removeBarsetButton, 3, 0); | |
52 |
|
52 | |||
53 | QPushButton *leftButton = new QPushButton("Align legend left"); |
|
53 | QPushButton *leftButton = new QPushButton("Align legend left"); | |
54 | connect(leftButton, SIGNAL(clicked()), this, SLOT(setLegendLeft())); |
|
54 | connect(leftButton, SIGNAL(clicked()), this, SLOT(setLegendLeft())); | |
55 | m_buttonLayout->addWidget(leftButton, 4, 0); |
|
55 | m_buttonLayout->addWidget(leftButton, 4, 0); | |
56 |
|
56 | |||
57 | QPushButton *rightButton = new QPushButton("Align legend right"); |
|
57 | QPushButton *rightButton = new QPushButton("Align legend right"); | |
58 | connect(rightButton, SIGNAL(clicked()), this, SLOT(setLegendRight())); |
|
58 | connect(rightButton, SIGNAL(clicked()), this, SLOT(setLegendRight())); | |
59 | m_buttonLayout->addWidget(rightButton, 5, 0); |
|
59 | m_buttonLayout->addWidget(rightButton, 5, 0); | |
60 |
|
60 | |||
61 | QPushButton *topButton = new QPushButton("Align legend top"); |
|
61 | QPushButton *topButton = new QPushButton("Align legend top"); | |
62 | connect(topButton, SIGNAL(clicked()), this, SLOT(setLegendTop())); |
|
62 | connect(topButton, SIGNAL(clicked()), this, SLOT(setLegendTop())); | |
63 | m_buttonLayout->addWidget(topButton, 6, 0); |
|
63 | m_buttonLayout->addWidget(topButton, 6, 0); | |
64 |
|
64 | |||
65 | QPushButton *bottomButton = new QPushButton("Align legend bottom"); |
|
65 | QPushButton *bottomButton = new QPushButton("Align legend bottom"); | |
66 | connect(bottomButton, SIGNAL(clicked()), this, SLOT(setLegendBottom())); |
|
66 | connect(bottomButton, SIGNAL(clicked()), this, SLOT(setLegendBottom())); | |
67 | m_buttonLayout->addWidget(bottomButton, 7, 0); |
|
67 | m_buttonLayout->addWidget(bottomButton, 7, 0); | |
68 |
|
68 | |||
69 | QPushButton *boldButton = new QPushButton("Toggle bold"); |
|
69 | QPushButton *boldButton = new QPushButton("Toggle bold"); | |
70 | connect(boldButton, SIGNAL(clicked()), this, SLOT(toggleBold())); |
|
70 | connect(boldButton, SIGNAL(clicked()), this, SLOT(toggleBold())); | |
71 | m_buttonLayout->addWidget(boldButton, 8, 0); |
|
71 | m_buttonLayout->addWidget(boldButton, 8, 0); | |
72 |
|
72 | |||
73 | QPushButton *italicButton = new QPushButton("Toggle italic"); |
|
73 | QPushButton *italicButton = new QPushButton("Toggle italic"); | |
74 | connect(italicButton, SIGNAL(clicked()), this, SLOT(toggleItalic())); |
|
74 | connect(italicButton, SIGNAL(clicked()), this, SLOT(toggleItalic())); | |
75 | m_buttonLayout->addWidget(italicButton, 9, 0); |
|
75 | m_buttonLayout->addWidget(italicButton, 9, 0); | |
76 |
|
76 | |||
77 | m_legendPosX = new QDoubleSpinBox(); |
|
77 | m_legendPosX = new QDoubleSpinBox(); | |
78 | m_legendPosY = new QDoubleSpinBox(); |
|
78 | m_legendPosY = new QDoubleSpinBox(); | |
79 | m_legendWidth = new QDoubleSpinBox(); |
|
79 | m_legendWidth = new QDoubleSpinBox(); | |
80 | m_legendHeight = new QDoubleSpinBox(); |
|
80 | m_legendHeight = new QDoubleSpinBox(); | |
81 |
|
81 | |||
82 | connect(m_legendPosX, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
82 | connect(m_legendPosX, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); | |
83 | connect(m_legendPosY, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
83 | connect(m_legendPosY, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); | |
84 | connect(m_legendWidth, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
84 | connect(m_legendWidth, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); | |
85 | connect(m_legendHeight, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
85 | connect(m_legendHeight, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); | |
86 |
|
86 | |||
87 | QFormLayout* legendLayout = new QFormLayout(); |
|
87 | QFormLayout* legendLayout = new QFormLayout(); | |
88 | legendLayout->addRow("Horizontal position", m_legendPosX); |
|
88 | legendLayout->addRow("Horizontal position", m_legendPosX); | |
89 | legendLayout->addRow("Vertical position", m_legendPosY); |
|
89 | legendLayout->addRow("Vertical position", m_legendPosY); | |
90 | legendLayout->addRow("Width", m_legendWidth); |
|
90 | legendLayout->addRow("Width", m_legendWidth); | |
91 | legendLayout->addRow("Height", m_legendHeight); |
|
91 | legendLayout->addRow("Height", m_legendHeight); | |
92 | m_legendSettings = new QGroupBox("Detached legend"); |
|
92 | m_legendSettings = new QGroupBox("Detached legend"); | |
93 | m_legendSettings->setLayout(legendLayout); |
|
93 | m_legendSettings->setLayout(legendLayout); | |
94 | m_buttonLayout->addWidget(m_legendSettings); |
|
94 | m_buttonLayout->addWidget(m_legendSettings); | |
95 | m_legendSettings->setVisible(false); |
|
95 | m_legendSettings->setVisible(false); | |
96 |
|
96 | |||
97 | // Create chart view with the chart |
|
97 | // Create chart view with the chart | |
98 | m_chart = new QChart(); |
|
98 | m_chart = new QChart(); | |
99 | m_chartView = new QChartView(m_chart, this); |
|
99 | m_chartView = new QChartView(m_chart, this); | |
100 |
|
100 | |||
101 | // Create spinbox to modify font size |
|
101 | // Create spinbox to modify font size | |
102 | m_fontSize = new QDoubleSpinBox(); |
|
102 | m_fontSize = new QDoubleSpinBox(); | |
103 | m_fontSize->setValue(m_chart->legend()->font().pointSizeF()); |
|
103 | m_fontSize->setValue(m_chart->legend()->font().pointSizeF()); | |
104 | connect(m_fontSize, SIGNAL(valueChanged(double)), this, SLOT(fontSizeChanged())); |
|
104 | connect(m_fontSize, SIGNAL(valueChanged(double)), this, SLOT(fontSizeChanged())); | |
105 |
|
105 | |||
106 | QFormLayout* fontLayout = new QFormLayout(); |
|
106 | QFormLayout* fontLayout = new QFormLayout(); | |
107 | fontLayout->addRow("Legend font size", m_fontSize); |
|
107 | fontLayout->addRow("Legend font size", m_fontSize); | |
108 |
|
108 | |||
109 | // Create layout for grid and detached legend |
|
109 | // Create layout for grid and detached legend | |
110 | m_mainLayout = new QGridLayout(); |
|
110 | m_mainLayout = new QGridLayout(); | |
111 | m_mainLayout->addLayout(m_buttonLayout, 0, 0); |
|
111 | m_mainLayout->addLayout(m_buttonLayout, 0, 0); | |
112 | m_mainLayout->addLayout(fontLayout,1,0); |
|
112 | m_mainLayout->addLayout(fontLayout,1,0); | |
113 | m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
113 | m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |
114 | setLayout(m_mainLayout); |
|
114 | setLayout(m_mainLayout); | |
115 |
|
115 | |||
116 | createSeries(); |
|
116 | createSeries(); | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | void MainWidget::createSeries() |
|
119 | void MainWidget::createSeries() | |
120 | { |
|
120 | { | |
121 |
m_series = new Q |
|
121 | m_series = new QBarSeries(); | |
122 | addBarset(); |
|
122 | addBarset(); | |
123 | addBarset(); |
|
123 | addBarset(); | |
124 | addBarset(); |
|
124 | addBarset(); | |
125 | addBarset(); |
|
125 | addBarset(); | |
126 |
|
126 | |||
127 | m_chart->addSeries(m_series); |
|
127 | m_chart->addSeries(m_series); | |
128 | m_chart->setTitle("Legend detach example"); |
|
128 | m_chart->setTitle("Legend detach example"); | |
129 | m_chart->createDefaultAxes(); |
|
129 | m_chart->createDefaultAxes(); | |
130 | //![1] |
|
130 | //![1] | |
131 | m_chart->legend()->setVisible(true); |
|
131 | m_chart->legend()->setVisible(true); | |
132 | m_chart->legend()->setAlignment(Qt::AlignBottom); |
|
132 | m_chart->legend()->setAlignment(Qt::AlignBottom); | |
133 | //![1] |
|
133 | //![1] | |
134 |
|
134 | |||
135 | //TODO:m_chart->axisY()->setNiceNumbersEnabled(true); |
|
135 | //TODO:m_chart->axisY()->setNiceNumbersEnabled(true); | |
136 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
136 | m_chartView->setRenderHint(QPainter::Antialiasing); | |
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | void MainWidget::showLegendSpinbox() |
|
139 | void MainWidget::showLegendSpinbox() | |
140 | { |
|
140 | { | |
141 | m_legendSettings->setVisible(true); |
|
141 | m_legendSettings->setVisible(true); | |
142 | QRectF chartViewRect = m_chartView->rect(); |
|
142 | QRectF chartViewRect = m_chartView->rect(); | |
143 |
|
143 | |||
144 | m_legendPosX->setMinimum(0); |
|
144 | m_legendPosX->setMinimum(0); | |
145 | m_legendPosX->setMaximum(chartViewRect.width()); |
|
145 | m_legendPosX->setMaximum(chartViewRect.width()); | |
146 | m_legendPosX->setValue(150); |
|
146 | m_legendPosX->setValue(150); | |
147 |
|
147 | |||
148 | m_legendPosY->setMinimum(0); |
|
148 | m_legendPosY->setMinimum(0); | |
149 | m_legendPosY->setMaximum(chartViewRect.height()); |
|
149 | m_legendPosY->setMaximum(chartViewRect.height()); | |
150 | m_legendPosY->setValue(150); |
|
150 | m_legendPosY->setValue(150); | |
151 |
|
151 | |||
152 | m_legendWidth->setMinimum(0); |
|
152 | m_legendWidth->setMinimum(0); | |
153 | m_legendWidth->setMaximum(chartViewRect.width()); |
|
153 | m_legendWidth->setMaximum(chartViewRect.width()); | |
154 | m_legendWidth->setValue(150); |
|
154 | m_legendWidth->setValue(150); | |
155 |
|
155 | |||
156 | m_legendHeight->setMinimum(0); |
|
156 | m_legendHeight->setMinimum(0); | |
157 | m_legendHeight->setMaximum(chartViewRect.height()); |
|
157 | m_legendHeight->setMaximum(chartViewRect.height()); | |
158 | m_legendHeight->setValue(75); |
|
158 | m_legendHeight->setValue(75); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void MainWidget::hideLegendSpinbox() |
|
161 | void MainWidget::hideLegendSpinbox() | |
162 | { |
|
162 | { | |
163 | m_legendSettings->setVisible(false); |
|
163 | m_legendSettings->setVisible(false); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 |
|
166 | |||
167 | void MainWidget::detachLegend() |
|
167 | void MainWidget::detachLegend() | |
168 | { |
|
168 | { | |
169 | //![2] |
|
169 | //![2] | |
170 | QLegend *legend = m_chart->legend(); |
|
170 | QLegend *legend = m_chart->legend(); | |
171 | legend->detachFromChart(); |
|
171 | legend->detachFromChart(); | |
172 |
|
172 | |||
173 | m_chart->legend()->setBackgroundVisible(true); |
|
173 | m_chart->legend()->setBackgroundVisible(true); | |
174 | m_chart->legend()->setBrush(QBrush(QColor(128,128,128,128))); |
|
174 | m_chart->legend()->setBrush(QBrush(QColor(128,128,128,128))); | |
175 | m_chart->legend()->setPen(QPen(QColor(192,192,192,192))); |
|
175 | m_chart->legend()->setPen(QPen(QColor(192,192,192,192))); | |
176 | //![2] |
|
176 | //![2] | |
177 |
|
177 | |||
178 | showLegendSpinbox(); |
|
178 | showLegendSpinbox(); | |
179 | updateLegendLayout(); |
|
179 | updateLegendLayout(); | |
180 | update(); |
|
180 | update(); | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 |
|
183 | |||
184 | void MainWidget::attachLegend() |
|
184 | void MainWidget::attachLegend() | |
185 | { |
|
185 | { | |
186 | //![3] |
|
186 | //![3] | |
187 | QLegend *legend = m_chart->legend(); |
|
187 | QLegend *legend = m_chart->legend(); | |
188 | legend->attachToChart(); |
|
188 | legend->attachToChart(); | |
189 | m_chart->legend()->setBackgroundVisible(false); |
|
189 | m_chart->legend()->setBackgroundVisible(false); | |
190 | //![3] |
|
190 | //![3] | |
191 |
|
191 | |||
192 | hideLegendSpinbox(); |
|
192 | hideLegendSpinbox(); | |
193 | update(); |
|
193 | update(); | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | void MainWidget::addBarset() |
|
196 | void MainWidget::addBarset() | |
197 | { |
|
197 | { | |
198 | QBarSet *barSet = new QBarSet(QString("set ") + QString::number(m_series->count())); |
|
198 | QBarSet *barSet = new QBarSet(QString("set ") + QString::number(m_series->count())); | |
199 | qreal delta = m_series->count() * 0.1; |
|
199 | qreal delta = m_series->count() * 0.1; | |
200 | *barSet << 1 + delta << 2 + delta << 3 + delta << 4 + delta; |
|
200 | *barSet << 1 + delta << 2 + delta << 3 + delta << 4 + delta; | |
201 | m_series->append(barSet); |
|
201 | m_series->append(barSet); | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | void MainWidget::removeBarset() |
|
204 | void MainWidget::removeBarset() | |
205 | { |
|
205 | { | |
206 | QList<QBarSet*> sets = m_series->barSets(); |
|
206 | QList<QBarSet*> sets = m_series->barSets(); | |
207 | if (sets.count() > 0) { |
|
207 | if (sets.count() > 0) { | |
208 | m_series->remove(sets.at(sets.count()-1)); |
|
208 | m_series->remove(sets.at(sets.count()-1)); | |
209 | } |
|
209 | } | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | void MainWidget::setLegendLeft() |
|
212 | void MainWidget::setLegendLeft() | |
213 | { |
|
213 | { | |
214 | m_chart->legend()->setAlignment(Qt::AlignLeft); |
|
214 | m_chart->legend()->setAlignment(Qt::AlignLeft); | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | void MainWidget::setLegendRight() |
|
217 | void MainWidget::setLegendRight() | |
218 | { |
|
218 | { | |
219 | m_chart->legend()->setAlignment(Qt::AlignRight); |
|
219 | m_chart->legend()->setAlignment(Qt::AlignRight); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | void MainWidget::setLegendTop() |
|
222 | void MainWidget::setLegendTop() | |
223 | { |
|
223 | { | |
224 | m_chart->legend()->setAlignment(Qt::AlignTop); |
|
224 | m_chart->legend()->setAlignment(Qt::AlignTop); | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | void MainWidget::setLegendBottom() |
|
227 | void MainWidget::setLegendBottom() | |
228 | { |
|
228 | { | |
229 | m_chart->legend()->setAlignment(Qt::AlignBottom); |
|
229 | m_chart->legend()->setAlignment(Qt::AlignBottom); | |
230 | } |
|
230 | } | |
231 |
|
231 | |||
232 | void MainWidget::toggleBold() |
|
232 | void MainWidget::toggleBold() | |
233 | { |
|
233 | { | |
234 | QFont font = m_chart->legend()->font(); |
|
234 | QFont font = m_chart->legend()->font(); | |
235 | font.setBold(!font.bold()); |
|
235 | font.setBold(!font.bold()); | |
236 | m_chart->legend()->setFont(font); |
|
236 | m_chart->legend()->setFont(font); | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | void MainWidget::toggleItalic() |
|
239 | void MainWidget::toggleItalic() | |
240 | { |
|
240 | { | |
241 | QFont font = m_chart->legend()->font(); |
|
241 | QFont font = m_chart->legend()->font(); | |
242 | font.setItalic(!font.italic()); |
|
242 | font.setItalic(!font.italic()); | |
243 | m_chart->legend()->setFont(font); |
|
243 | m_chart->legend()->setFont(font); | |
244 | } |
|
244 | } | |
245 |
|
245 | |||
246 | void MainWidget::fontSizeChanged() |
|
246 | void MainWidget::fontSizeChanged() | |
247 | { |
|
247 | { | |
248 | QFont font = m_chart->legend()->font(); |
|
248 | QFont font = m_chart->legend()->font(); | |
249 | font.setPointSizeF(m_fontSize->value()); |
|
249 | font.setPointSizeF(m_fontSize->value()); | |
250 | m_chart->legend()->setFont(font); |
|
250 | m_chart->legend()->setFont(font); | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | void MainWidget::updateLegendLayout() |
|
253 | void MainWidget::updateLegendLayout() | |
254 | { |
|
254 | { | |
255 | //![4] |
|
255 | //![4] | |
256 | m_chart->legend()->setGeometry(QRectF(m_legendPosX->value() |
|
256 | m_chart->legend()->setGeometry(QRectF(m_legendPosX->value() | |
257 | ,m_legendPosY->value() |
|
257 | ,m_legendPosY->value() | |
258 | ,m_legendWidth->value() |
|
258 | ,m_legendWidth->value() | |
259 | ,m_legendHeight->value())); |
|
259 | ,m_legendHeight->value())); | |
260 | m_chart->legend()->update(); |
|
260 | m_chart->legend()->update(); | |
261 | //![4] |
|
261 | //![4] | |
262 | } |
|
262 | } |
@@ -1,86 +1,86 | |||||
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 MAINWIDGET_H |
|
21 | #ifndef MAINWIDGET_H | |
22 | #define MAINWIDGET_H |
|
22 | #define MAINWIDGET_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "qchart.h" |
|
25 | #include "qchart.h" | |
26 | #include "qchartview.h" |
|
26 | #include "qchartview.h" | |
27 | #include <QWidget> |
|
27 | #include <QWidget> | |
28 | #include <QGraphicsWidget> |
|
28 | #include <QGraphicsWidget> | |
29 | #include <QGridLayout> |
|
29 | #include <QGridLayout> | |
30 | #include <QGraphicsGridLayout> |
|
30 | #include <QGraphicsGridLayout> | |
31 | #include <QDoubleSpinBox> |
|
31 | #include <QDoubleSpinBox> | |
32 | #include <QGroupBox> |
|
32 | #include <QGroupBox> | |
33 |
#include <Q |
|
33 | #include <QBarSeries> | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
35 | QTCOMMERCIALCHART_USE_NAMESPACE | |
36 |
|
36 | |||
37 | class MainWidget : public QWidget |
|
37 | class MainWidget : public QWidget | |
38 | { |
|
38 | { | |
39 | Q_OBJECT |
|
39 | Q_OBJECT | |
40 | public: |
|
40 | public: | |
41 | explicit MainWidget(QWidget *parent = 0); |
|
41 | explicit MainWidget(QWidget *parent = 0); | |
42 | void createSeries(); |
|
42 | void createSeries(); | |
43 | void showLegendSpinbox(); |
|
43 | void showLegendSpinbox(); | |
44 | void hideLegendSpinbox(); |
|
44 | void hideLegendSpinbox(); | |
45 |
|
45 | |||
46 | signals: |
|
46 | signals: | |
47 |
|
47 | |||
48 | public slots: |
|
48 | public slots: | |
49 | void detachLegend(); |
|
49 | void detachLegend(); | |
50 | void attachLegend(); |
|
50 | void attachLegend(); | |
51 | void addBarset(); |
|
51 | void addBarset(); | |
52 | void removeBarset(); |
|
52 | void removeBarset(); | |
53 |
|
53 | |||
54 | void setLegendLeft(); |
|
54 | void setLegendLeft(); | |
55 | void setLegendRight(); |
|
55 | void setLegendRight(); | |
56 | void setLegendTop(); |
|
56 | void setLegendTop(); | |
57 | void setLegendBottom(); |
|
57 | void setLegendBottom(); | |
58 |
|
58 | |||
59 | void toggleBold(); |
|
59 | void toggleBold(); | |
60 | void toggleItalic(); |
|
60 | void toggleItalic(); | |
61 | void fontSizeChanged(); |
|
61 | void fontSizeChanged(); | |
62 |
|
62 | |||
63 | void updateLegendLayout(); |
|
63 | void updateLegendLayout(); | |
64 |
|
64 | |||
65 |
|
65 | |||
66 | private: |
|
66 | private: | |
67 |
|
67 | |||
68 | QChart *m_chart; |
|
68 | QChart *m_chart; | |
69 |
Q |
|
69 | QBarSeries *m_series; | |
70 |
|
70 | |||
71 | QChartView *m_chartView; |
|
71 | QChartView *m_chartView; | |
72 | QGridLayout *m_mainLayout; |
|
72 | QGridLayout *m_mainLayout; | |
73 | QGridLayout *m_buttonLayout; |
|
73 | QGridLayout *m_buttonLayout; | |
74 | QGridLayout *m_fontLayout; |
|
74 | QGridLayout *m_fontLayout; | |
75 |
|
75 | |||
76 | QDoubleSpinBox *m_fontSize; |
|
76 | QDoubleSpinBox *m_fontSize; | |
77 |
|
77 | |||
78 | // For detached layout |
|
78 | // For detached layout | |
79 | QGroupBox* m_legendSettings; |
|
79 | QGroupBox* m_legendSettings; | |
80 | QDoubleSpinBox *m_legendPosX; |
|
80 | QDoubleSpinBox *m_legendPosX; | |
81 | QDoubleSpinBox *m_legendPosY; |
|
81 | QDoubleSpinBox *m_legendPosY; | |
82 | QDoubleSpinBox *m_legendWidth; |
|
82 | QDoubleSpinBox *m_legendWidth; | |
83 | QDoubleSpinBox *m_legendHeight; |
|
83 | QDoubleSpinBox *m_legendHeight; | |
84 | }; |
|
84 | }; | |
85 |
|
85 | |||
86 | #endif // MAINWIDGET_H |
|
86 | #endif // MAINWIDGET_H |
@@ -1,393 +1,393 | |||||
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 "declarativebarseries.h" |
|
21 | #include "declarativebarseries.h" | |
22 | #include "declarativechart.h" |
|
22 | #include "declarativechart.h" | |
23 | #include <QBarSet> |
|
23 | #include <QBarSet> | |
24 | #include <QVBarModelMapper> |
|
24 | #include <QVBarModelMapper> | |
25 | #include <QHBarModelMapper> |
|
25 | #include <QHBarModelMapper> | |
26 | #include <QAbstractAxis> |
|
26 | #include <QAbstractAxis> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | DeclarativeBarSet::DeclarativeBarSet(QObject *parent) : |
|
30 | DeclarativeBarSet::DeclarativeBarSet(QObject *parent) : | |
31 | QBarSet("", parent) |
|
31 | QBarSet("", parent) | |
32 | { |
|
32 | { | |
33 | connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int, int))); |
|
33 | connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int, int))); | |
34 | connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int, int))); |
|
34 | connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int, int))); | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | void DeclarativeBarSet::handleCountChanged(int index, int count) |
|
37 | void DeclarativeBarSet::handleCountChanged(int index, int count) | |
38 | { |
|
38 | { | |
39 | Q_UNUSED(index) |
|
39 | Q_UNUSED(index) | |
40 | Q_UNUSED(count) |
|
40 | Q_UNUSED(count) | |
41 | emit countChanged(QBarSet::count()); |
|
41 | emit countChanged(QBarSet::count()); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | QVariantList DeclarativeBarSet::values() |
|
44 | QVariantList DeclarativeBarSet::values() | |
45 | { |
|
45 | { | |
46 | QVariantList values; |
|
46 | QVariantList values; | |
47 | for (int i(0); i < count(); i++) |
|
47 | for (int i(0); i < count(); i++) | |
48 | values.append(QVariant(QBarSet::at(i))); |
|
48 | values.append(QVariant(QBarSet::at(i))); | |
49 | return values; |
|
49 | return values; | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | void DeclarativeBarSet::setValues(QVariantList values) |
|
52 | void DeclarativeBarSet::setValues(QVariantList values) | |
53 | { |
|
53 | { | |
54 | while (count()) |
|
54 | while (count()) | |
55 | remove(count() - 1); |
|
55 | remove(count() - 1); | |
56 |
|
56 | |||
57 | for (int i(0); i < values.count(); i++) { |
|
57 | for (int i(0); i < values.count(); i++) { | |
58 | if (values.at(i).canConvert(QVariant::Double)) |
|
58 | if (values.at(i).canConvert(QVariant::Double)) | |
59 | QBarSet::append(values[i].toDouble()); |
|
59 | QBarSet::append(values[i].toDouble()); | |
60 | } |
|
60 | } | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | DeclarativeAbstractBarSeries::DeclarativeAbstractBarSeries(QDeclarativeItem *parent) : |
|
63 | DeclarativeAbstractBarSeries::DeclarativeAbstractBarSeries(QDeclarativeItem *parent) : | |
64 | QAbstractBarSeries(parent) |
|
64 | QAbstractBarSeries(parent) | |
65 | { |
|
65 | { | |
66 | connect(this, SIGNAL(barsetsAdded(QList<QBarSet*>)), this, SLOT(handleAdded(QList<QBarSet*>))); |
|
66 | connect(this, SIGNAL(barsetsAdded(QList<QBarSet*>)), this, SLOT(handleAdded(QList<QBarSet*>))); | |
67 | connect(this, SIGNAL(barsetsRemoved(QList<QBarSet*>)), this, SLOT(handleRemoved(QList<QBarSet*>))); |
|
67 | connect(this, SIGNAL(barsetsRemoved(QList<QBarSet*>)), this, SLOT(handleRemoved(QList<QBarSet*>))); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void DeclarativeAbstractBarSeries::handleAdded(QList<QBarSet* > barsets) |
|
70 | void DeclarativeAbstractBarSeries::handleAdded(QList<QBarSet* > barsets) | |
71 | { |
|
71 | { | |
72 | foreach(QBarSet *b, barsets) { |
|
72 | foreach(QBarSet *b, barsets) { | |
73 | DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b); |
|
73 | DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b); | |
74 | emit added(barset); |
|
74 | emit added(barset); | |
75 | } |
|
75 | } | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void DeclarativeAbstractBarSeries::handleRemoved(QList<QBarSet* > barsets) |
|
78 | void DeclarativeAbstractBarSeries::handleRemoved(QList<QBarSet* > barsets) | |
79 | { |
|
79 | { | |
80 | foreach(QBarSet *b, barsets) { |
|
80 | foreach(QBarSet *b, barsets) { | |
81 | DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b); |
|
81 | DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b); | |
82 | emit removed(barset); |
|
82 | emit removed(barset); | |
83 | } |
|
83 | } | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | void DeclarativeAbstractBarSeries::classBegin() |
|
86 | void DeclarativeAbstractBarSeries::classBegin() | |
87 | { |
|
87 | { | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void DeclarativeAbstractBarSeries::componentComplete() |
|
90 | void DeclarativeAbstractBarSeries::componentComplete() | |
91 | { |
|
91 | { | |
92 | foreach(QObject *child, children()) { |
|
92 | foreach(QObject *child, children()) { | |
93 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
93 | if (qobject_cast<DeclarativeBarSet *>(child)) { | |
94 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
94 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | |
95 | } else if (qobject_cast<QVBarModelMapper *>(child)) { |
|
95 | } else if (qobject_cast<QVBarModelMapper *>(child)) { | |
96 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
96 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); | |
97 | mapper->setSeries(this); |
|
97 | mapper->setSeries(this); | |
98 | } else if (qobject_cast<QHBarModelMapper *>(child)) { |
|
98 | } else if (qobject_cast<QHBarModelMapper *>(child)) { | |
99 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
99 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); | |
100 | mapper->setSeries(this); |
|
100 | mapper->setSeries(this); | |
101 | } |
|
101 | } | |
102 | } |
|
102 | } | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | void DeclarativeAbstractBarSeries::setAxisX(QAbstractAxis *axis) |
|
105 | void DeclarativeAbstractBarSeries::setAxisX(QAbstractAxis *axis) | |
106 | { |
|
106 | { | |
107 | chart()->setAxisX(axis, this); |
|
107 | chart()->setAxisX(axis, this); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | QAbstractAxis *DeclarativeAbstractBarSeries::axisX() |
|
110 | QAbstractAxis *DeclarativeAbstractBarSeries::axisX() | |
111 | { |
|
111 | { | |
112 | return chart()->axisX(this); |
|
112 | return chart()->axisX(this); | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | void DeclarativeAbstractBarSeries::setAxisY(QAbstractAxis *axis) |
|
115 | void DeclarativeAbstractBarSeries::setAxisY(QAbstractAxis *axis) | |
116 | { |
|
116 | { | |
117 | chart()->setAxisY(axis, this); |
|
117 | chart()->setAxisY(axis, this); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | QAbstractAxis *DeclarativeAbstractBarSeries::axisY() |
|
120 | QAbstractAxis *DeclarativeAbstractBarSeries::axisY() | |
121 | { |
|
121 | { | |
122 | return chart()->axisY(this); |
|
122 | return chart()->axisY(this); | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | QDeclarativeListProperty<QObject> DeclarativeAbstractBarSeries::seriesChildren() |
|
125 | QDeclarativeListProperty<QObject> DeclarativeAbstractBarSeries::seriesChildren() | |
126 | { |
|
126 | { | |
127 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren); |
|
127 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren); | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | void DeclarativeAbstractBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
130 | void DeclarativeAbstractBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
131 | { |
|
131 | { | |
132 | // Empty implementation; the children are parsed in componentComplete instead |
|
132 | // Empty implementation; the children are parsed in componentComplete instead | |
133 | Q_UNUSED(list); |
|
133 | Q_UNUSED(list); | |
134 | Q_UNUSED(element); |
|
134 | Q_UNUSED(element); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | DeclarativeBarSet *DeclarativeAbstractBarSeries::at(int index) |
|
137 | DeclarativeBarSet *DeclarativeAbstractBarSeries::at(int index) | |
138 | { |
|
138 | { | |
139 | QList<QBarSet*> setList = barSets(); |
|
139 | QList<QBarSet*> setList = barSets(); | |
140 | if (index >= 0 && index < setList.count()) |
|
140 | if (index >= 0 && index < setList.count()) | |
141 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
141 | return qobject_cast<DeclarativeBarSet *>(setList[index]); | |
142 |
|
142 | |||
143 | return 0; |
|
143 | return 0; | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | DeclarativeBarSet *DeclarativeAbstractBarSeries::insert(int index, QString label, QVariantList values) |
|
146 | DeclarativeBarSet *DeclarativeAbstractBarSeries::insert(int index, QString label, QVariantList values) | |
147 | { |
|
147 | { | |
148 | int insertIndex = index; |
|
148 | int insertIndex = index; | |
149 | if (insertIndex < 0) |
|
149 | if (insertIndex < 0) | |
150 | insertIndex = 0; |
|
150 | insertIndex = 0; | |
151 | else if (insertIndex > count()) |
|
151 | else if (insertIndex > count()) | |
152 | insertIndex = count(); |
|
152 | insertIndex = count(); | |
153 |
|
153 | |||
154 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
154 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); | |
155 | barset->setLabel(label); |
|
155 | barset->setLabel(label); | |
156 | barset->setValues(values); |
|
156 | barset->setValues(values); | |
157 | if (QAbstractBarSeries::insert(insertIndex, barset)) |
|
157 | if (QAbstractBarSeries::insert(insertIndex, barset)) | |
158 | return barset; |
|
158 | return barset; | |
159 | delete barset; |
|
159 | delete barset; | |
160 | return 0; |
|
160 | return 0; | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 |
Declarative |
|
163 | DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : | |
164 |
Q |
|
164 | QBarSeries(parent) | |
165 | { |
|
165 | { | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 |
void Declarative |
|
168 | void DeclarativeBarSeries::classBegin() | |
169 | { |
|
169 | { | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 |
void Declarative |
|
172 | void DeclarativeBarSeries::componentComplete() | |
173 | { |
|
173 | { | |
174 | foreach(QObject *child, children()) { |
|
174 | foreach(QObject *child, children()) { | |
175 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
175 | if (qobject_cast<DeclarativeBarSet *>(child)) { | |
176 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
176 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | |
177 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
177 | } else if(qobject_cast<QVBarModelMapper *>(child)) { | |
178 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
178 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); | |
179 | mapper->setSeries(this); |
|
179 | mapper->setSeries(this); | |
180 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
180 | } else if(qobject_cast<QHBarModelMapper *>(child)) { | |
181 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
181 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); | |
182 | mapper->setSeries(this); |
|
182 | mapper->setSeries(this); | |
183 | } |
|
183 | } | |
184 | } |
|
184 | } | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 |
void Declarative |
|
187 | void DeclarativeBarSeries::setAxisX(QAbstractAxis *axis) | |
188 | { |
|
188 | { | |
189 | chart()->setAxisX(axis, this); |
|
189 | chart()->setAxisX(axis, this); | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 |
QAbstractAxis *Declarative |
|
192 | QAbstractAxis *DeclarativeBarSeries::axisX() | |
193 | { |
|
193 | { | |
194 | return chart()->axisX(this); |
|
194 | return chart()->axisX(this); | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 |
void Declarative |
|
197 | void DeclarativeBarSeries::setAxisY(QAbstractAxis *axis) | |
198 | { |
|
198 | { | |
199 | chart()->setAxisY(axis, this); |
|
199 | chart()->setAxisY(axis, this); | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 |
QAbstractAxis *Declarative |
|
202 | QAbstractAxis *DeclarativeBarSeries::axisY() | |
203 | { |
|
203 | { | |
204 | return chart()->axisY(this); |
|
204 | return chart()->axisY(this); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 |
QDeclarativeListProperty<QObject> Declarative |
|
207 | QDeclarativeListProperty<QObject> DeclarativeBarSeries::seriesChildren() | |
208 | { |
|
208 | { | |
209 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren); |
|
209 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 |
void Declarative |
|
212 | void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
213 | { |
|
213 | { | |
214 | // Empty implementation; the children are parsed in componentComplete instead |
|
214 | // Empty implementation; the children are parsed in componentComplete instead | |
215 | Q_UNUSED(list); |
|
215 | Q_UNUSED(list); | |
216 | Q_UNUSED(element); |
|
216 | Q_UNUSED(element); | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 |
DeclarativeBarSet *Declarative |
|
219 | DeclarativeBarSet *DeclarativeBarSeries::at(int index) | |
220 | { |
|
220 | { | |
221 | QList<QBarSet*> setList = barSets(); |
|
221 | QList<QBarSet*> setList = barSets(); | |
222 | if (index >= 0 && index < setList.count()) |
|
222 | if (index >= 0 && index < setList.count()) | |
223 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
223 | return qobject_cast<DeclarativeBarSet *>(setList[index]); | |
224 |
|
224 | |||
225 | return 0; |
|
225 | return 0; | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 |
DeclarativeBarSet *Declarative |
|
228 | DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values) | |
229 | { |
|
229 | { | |
230 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
230 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); | |
231 | barset->setLabel(label); |
|
231 | barset->setLabel(label); | |
232 | barset->setValues(values); |
|
232 | barset->setValues(values); | |
233 |
if (Q |
|
233 | if (QBarSeries::insert(index, barset)) | |
234 | return barset; |
|
234 | return barset; | |
235 | delete barset; |
|
235 | delete barset; | |
236 | return 0; |
|
236 | return 0; | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) : |
|
239 | DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) : | |
240 | QStackedBarSeries(parent) |
|
240 | QStackedBarSeries(parent) | |
241 | { |
|
241 | { | |
242 | } |
|
242 | } | |
243 |
|
243 | |||
244 | void DeclarativeStackedBarSeries::classBegin() |
|
244 | void DeclarativeStackedBarSeries::classBegin() | |
245 | { |
|
245 | { | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | void DeclarativeStackedBarSeries::componentComplete() |
|
248 | void DeclarativeStackedBarSeries::componentComplete() | |
249 | { |
|
249 | { | |
250 | foreach(QObject *child, children()) { |
|
250 | foreach(QObject *child, children()) { | |
251 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
251 | if (qobject_cast<DeclarativeBarSet *>(child)) { | |
252 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
252 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | |
253 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
253 | } else if(qobject_cast<QVBarModelMapper *>(child)) { | |
254 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
254 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); | |
255 | mapper->setSeries(this); |
|
255 | mapper->setSeries(this); | |
256 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
256 | } else if(qobject_cast<QHBarModelMapper *>(child)) { | |
257 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
257 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); | |
258 | mapper->setSeries(this); |
|
258 | mapper->setSeries(this); | |
259 | } |
|
259 | } | |
260 | } |
|
260 | } | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 | void DeclarativeStackedBarSeries::setAxisX(QAbstractAxis *axis) |
|
263 | void DeclarativeStackedBarSeries::setAxisX(QAbstractAxis *axis) | |
264 | { |
|
264 | { | |
265 | chart()->setAxisX(axis, this); |
|
265 | chart()->setAxisX(axis, this); | |
266 | } |
|
266 | } | |
267 |
|
267 | |||
268 | QAbstractAxis *DeclarativeStackedBarSeries::axisX() |
|
268 | QAbstractAxis *DeclarativeStackedBarSeries::axisX() | |
269 | { |
|
269 | { | |
270 | return chart()->axisX(this); |
|
270 | return chart()->axisX(this); | |
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | void DeclarativeStackedBarSeries::setAxisY(QAbstractAxis *axis) |
|
273 | void DeclarativeStackedBarSeries::setAxisY(QAbstractAxis *axis) | |
274 | { |
|
274 | { | |
275 | chart()->setAxisY(axis, this); |
|
275 | chart()->setAxisY(axis, this); | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | QAbstractAxis *DeclarativeStackedBarSeries::axisY() |
|
278 | QAbstractAxis *DeclarativeStackedBarSeries::axisY() | |
279 | { |
|
279 | { | |
280 | return chart()->axisY(this); |
|
280 | return chart()->axisY(this); | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | QDeclarativeListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren() |
|
283 | QDeclarativeListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren() | |
284 | { |
|
284 | { | |
285 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren); |
|
285 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren); | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
288 | void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
289 | { |
|
289 | { | |
290 | // Empty implementation; the children are parsed in componentComplete instead |
|
290 | // Empty implementation; the children are parsed in componentComplete instead | |
291 | Q_UNUSED(list); |
|
291 | Q_UNUSED(list); | |
292 | Q_UNUSED(element); |
|
292 | Q_UNUSED(element); | |
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index) |
|
295 | DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index) | |
296 | { |
|
296 | { | |
297 | QList<QBarSet*> setList = barSets(); |
|
297 | QList<QBarSet*> setList = barSets(); | |
298 | if (index >= 0 && index < setList.count()) |
|
298 | if (index >= 0 && index < setList.count()) | |
299 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
299 | return qobject_cast<DeclarativeBarSet *>(setList[index]); | |
300 |
|
300 | |||
301 | return 0; |
|
301 | return 0; | |
302 | } |
|
302 | } | |
303 |
|
303 | |||
304 | DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, QVariantList values) |
|
304 | DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, QVariantList values) | |
305 | { |
|
305 | { | |
306 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
306 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); | |
307 | barset->setLabel(label); |
|
307 | barset->setLabel(label); | |
308 | barset->setValues(values); |
|
308 | barset->setValues(values); | |
309 | if (QStackedBarSeries::insert(index, barset)) |
|
309 | if (QStackedBarSeries::insert(index, barset)) | |
310 | return barset; |
|
310 | return barset; | |
311 | delete barset; |
|
311 | delete barset; | |
312 | return 0; |
|
312 | return 0; | |
313 | } |
|
313 | } | |
314 |
|
314 | |||
315 | DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) : |
|
315 | DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) : | |
316 | QPercentBarSeries(parent) |
|
316 | QPercentBarSeries(parent) | |
317 | { |
|
317 | { | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | void DeclarativePercentBarSeries::classBegin() |
|
320 | void DeclarativePercentBarSeries::classBegin() | |
321 | { |
|
321 | { | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | void DeclarativePercentBarSeries::componentComplete() |
|
324 | void DeclarativePercentBarSeries::componentComplete() | |
325 | { |
|
325 | { | |
326 | foreach(QObject *child, children()) { |
|
326 | foreach(QObject *child, children()) { | |
327 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
327 | if (qobject_cast<DeclarativeBarSet *>(child)) { | |
328 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
328 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | |
329 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
329 | } else if(qobject_cast<QVBarModelMapper *>(child)) { | |
330 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
330 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); | |
331 | mapper->setSeries(this); |
|
331 | mapper->setSeries(this); | |
332 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
332 | } else if(qobject_cast<QHBarModelMapper *>(child)) { | |
333 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
333 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); | |
334 | mapper->setSeries(this); |
|
334 | mapper->setSeries(this); | |
335 | } |
|
335 | } | |
336 | } |
|
336 | } | |
337 | } |
|
337 | } | |
338 |
|
338 | |||
339 | void DeclarativePercentBarSeries::setAxisX(QAbstractAxis *axis) |
|
339 | void DeclarativePercentBarSeries::setAxisX(QAbstractAxis *axis) | |
340 | { |
|
340 | { | |
341 | chart()->setAxisX(axis, this); |
|
341 | chart()->setAxisX(axis, this); | |
342 | } |
|
342 | } | |
343 |
|
343 | |||
344 | QAbstractAxis *DeclarativePercentBarSeries::axisX() |
|
344 | QAbstractAxis *DeclarativePercentBarSeries::axisX() | |
345 | { |
|
345 | { | |
346 | return chart()->axisX(this); |
|
346 | return chart()->axisX(this); | |
347 | } |
|
347 | } | |
348 |
|
348 | |||
349 | void DeclarativePercentBarSeries::setAxisY(QAbstractAxis *axis) |
|
349 | void DeclarativePercentBarSeries::setAxisY(QAbstractAxis *axis) | |
350 | { |
|
350 | { | |
351 | chart()->setAxisY(axis, this); |
|
351 | chart()->setAxisY(axis, this); | |
352 | } |
|
352 | } | |
353 |
|
353 | |||
354 | QAbstractAxis *DeclarativePercentBarSeries::axisY() |
|
354 | QAbstractAxis *DeclarativePercentBarSeries::axisY() | |
355 | { |
|
355 | { | |
356 | return chart()->axisY(this); |
|
356 | return chart()->axisY(this); | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | QDeclarativeListProperty<QObject> DeclarativePercentBarSeries::seriesChildren() |
|
359 | QDeclarativeListProperty<QObject> DeclarativePercentBarSeries::seriesChildren() | |
360 | { |
|
360 | { | |
361 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren); |
|
361 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren); | |
362 | } |
|
362 | } | |
363 |
|
363 | |||
364 | void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
364 | void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
365 | { |
|
365 | { | |
366 | // Empty implementation; the children are parsed in componentComplete instead |
|
366 | // Empty implementation; the children are parsed in componentComplete instead | |
367 | Q_UNUSED(list); |
|
367 | Q_UNUSED(list); | |
368 | Q_UNUSED(element); |
|
368 | Q_UNUSED(element); | |
369 | } |
|
369 | } | |
370 |
|
370 | |||
371 | DeclarativeBarSet *DeclarativePercentBarSeries::at(int index) |
|
371 | DeclarativeBarSet *DeclarativePercentBarSeries::at(int index) | |
372 | { |
|
372 | { | |
373 | QList<QBarSet*> setList = barSets(); |
|
373 | QList<QBarSet*> setList = barSets(); | |
374 | if (index >= 0 && index < setList.count()) |
|
374 | if (index >= 0 && index < setList.count()) | |
375 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
375 | return qobject_cast<DeclarativeBarSet *>(setList[index]); | |
376 |
|
376 | |||
377 | return 0; |
|
377 | return 0; | |
378 | } |
|
378 | } | |
379 |
|
379 | |||
380 | DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, QVariantList values) |
|
380 | DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, QVariantList values) | |
381 | { |
|
381 | { | |
382 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
382 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); | |
383 | barset->setLabel(label); |
|
383 | barset->setLabel(label); | |
384 | barset->setValues(values); |
|
384 | barset->setValues(values); | |
385 | if (QPercentBarSeries::insert(index, barset)) |
|
385 | if (QPercentBarSeries::insert(index, barset)) | |
386 | return barset; |
|
386 | return barset; | |
387 | delete barset; |
|
387 | delete barset; | |
388 | return 0; |
|
388 | return 0; | |
389 | } |
|
389 | } | |
390 |
|
390 | |||
391 | #include "moc_declarativebarseries.cpp" |
|
391 | #include "moc_declarativebarseries.cpp" | |
392 |
|
392 | |||
393 | QTCOMMERCIALCHART_END_NAMESPACE |
|
393 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,189 +1,190 | |||||
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 DECLARATIVEBARSERIES_H |
|
21 | #ifndef DECLARATIVEBARSERIES_H | |
22 | #define DECLARATIVEBARSERIES_H |
|
22 | #define DECLARATIVEBARSERIES_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 |
#include "q |
|
25 | #include "qabstractbarseries.h" | |
|
26 | #include "qbarseries.h" | |||
26 | #include "qstackedbarseries.h" |
|
27 | #include "qstackedbarseries.h" | |
27 | #include "qpercentbarseries.h" |
|
28 | #include "qpercentbarseries.h" | |
28 | #include "qbarset.h" |
|
29 | #include "qbarset.h" | |
29 | #include "qabstractaxis.h" |
|
30 | #include "qabstractaxis.h" | |
30 | #include <QDeclarativeItem> |
|
31 | #include <QDeclarativeItem> | |
31 | #include <QDeclarativeParserStatus> |
|
32 | #include <QDeclarativeParserStatus> | |
32 |
|
33 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
35 | |||
35 | class QChart; |
|
36 | class QChart; | |
36 |
|
37 | |||
37 | class DeclarativeBarSet : public QBarSet |
|
38 | class DeclarativeBarSet : public QBarSet | |
38 | { |
|
39 | { | |
39 | Q_OBJECT |
|
40 | Q_OBJECT | |
40 | Q_PROPERTY(QVariantList values READ values WRITE setValues) |
|
41 | Q_PROPERTY(QVariantList values READ values WRITE setValues) | |
41 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
|
42 | Q_PROPERTY(int count READ count NOTIFY countChanged) | |
42 |
|
43 | |||
43 | public: |
|
44 | public: | |
44 | explicit DeclarativeBarSet(QObject *parent = 0); |
|
45 | explicit DeclarativeBarSet(QObject *parent = 0); | |
45 | QVariantList values(); |
|
46 | QVariantList values(); | |
46 | void setValues(QVariantList values); |
|
47 | void setValues(QVariantList values); | |
47 |
|
48 | |||
48 | public: // From QBarSet |
|
49 | public: // From QBarSet | |
49 | Q_INVOKABLE void append(qreal value) { QBarSet::append(value); } |
|
50 | Q_INVOKABLE void append(qreal value) { QBarSet::append(value); } | |
50 | Q_INVOKABLE void remove(const int index, const int count = 1) { QBarSet::remove(index, count); } |
|
51 | Q_INVOKABLE void remove(const int index, const int count = 1) { QBarSet::remove(index, count); } | |
51 | Q_INVOKABLE void replace(int index, qreal value) { QBarSet::replace(index, value); } |
|
52 | Q_INVOKABLE void replace(int index, qreal value) { QBarSet::replace(index, value); } | |
52 | Q_INVOKABLE qreal at(int index) { return QBarSet::at(index); } |
|
53 | Q_INVOKABLE qreal at(int index) { return QBarSet::at(index); } | |
53 |
|
54 | |||
54 | Q_SIGNALS: |
|
55 | Q_SIGNALS: | |
55 | void countChanged(int count); |
|
56 | void countChanged(int count); | |
56 |
|
57 | |||
57 | private Q_SLOTS: |
|
58 | private Q_SLOTS: | |
58 | void handleCountChanged(int index, int count); |
|
59 | void handleCountChanged(int index, int count); | |
59 | }; |
|
60 | }; | |
60 |
|
61 | |||
61 | class DeclarativeAbstractBarSeries : public QAbstractBarSeries, public QDeclarativeParserStatus |
|
62 | class DeclarativeAbstractBarSeries : public QAbstractBarSeries, public QDeclarativeParserStatus | |
62 | { |
|
63 | { | |
63 | Q_OBJECT |
|
64 | Q_OBJECT | |
64 | Q_INTERFACES(QDeclarativeParserStatus) |
|
65 | Q_INTERFACES(QDeclarativeParserStatus) | |
65 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) |
|
66 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) | |
66 | Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX) |
|
67 | Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX) | |
67 | Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY) |
|
68 | Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY) | |
68 | Q_CLASSINFO("DefaultProperty", "seriesChildren") |
|
69 | Q_CLASSINFO("DefaultProperty", "seriesChildren") | |
69 |
|
70 | |||
70 | public: |
|
71 | public: | |
71 | explicit DeclarativeAbstractBarSeries(QDeclarativeItem *parent = 0); |
|
72 | explicit DeclarativeAbstractBarSeries(QDeclarativeItem *parent = 0); | |
72 | void setAxisX(QAbstractAxis *axis); |
|
73 | void setAxisX(QAbstractAxis *axis); | |
73 | QAbstractAxis *axisX(); |
|
74 | QAbstractAxis *axisX(); | |
74 | void setAxisY(QAbstractAxis *axis); |
|
75 | void setAxisY(QAbstractAxis *axis); | |
75 | QAbstractAxis *axisY(); |
|
76 | QAbstractAxis *axisY(); | |
76 | QDeclarativeListProperty<QObject> seriesChildren(); |
|
77 | QDeclarativeListProperty<QObject> seriesChildren(); | |
77 | Q_INVOKABLE DeclarativeBarSet *at(int index); |
|
78 | Q_INVOKABLE DeclarativeBarSet *at(int index); | |
78 | Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } |
|
79 | Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } | |
79 | Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); |
|
80 | Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); | |
80 | Q_INVOKABLE bool remove(QBarSet *barset) { return QAbstractBarSeries::remove(barset); } |
|
81 | Q_INVOKABLE bool remove(QBarSet *barset) { return QAbstractBarSeries::remove(barset); } | |
81 | Q_INVOKABLE void clear() { return QAbstractBarSeries::clear(); } |
|
82 | Q_INVOKABLE void clear() { return QAbstractBarSeries::clear(); } | |
82 |
|
83 | |||
83 | public: // from QDeclarativeParserStatus |
|
84 | public: // from QDeclarativeParserStatus | |
84 | void classBegin(); |
|
85 | void classBegin(); | |
85 | void componentComplete(); |
|
86 | void componentComplete(); | |
86 |
|
87 | |||
87 | Q_SIGNALS: |
|
88 | Q_SIGNALS: | |
88 | void added(DeclarativeBarSet *barset); |
|
89 | void added(DeclarativeBarSet *barset); | |
89 | void removed(DeclarativeBarSet *barset); |
|
90 | void removed(DeclarativeBarSet *barset); | |
90 |
|
91 | |||
91 | public Q_SLOTS: |
|
92 | public Q_SLOTS: | |
92 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
93 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); | |
93 | void handleAdded(QList<QBarSet* > barsets); |
|
94 | void handleAdded(QList<QBarSet* > barsets); | |
94 | void handleRemoved(QList<QBarSet* > barsets); |
|
95 | void handleRemoved(QList<QBarSet* > barsets); | |
95 | }; |
|
96 | }; | |
96 |
|
97 | |||
97 |
class Declarative |
|
98 | class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus | |
98 | { |
|
99 | { | |
99 | Q_OBJECT |
|
100 | Q_OBJECT | |
100 | Q_INTERFACES(QDeclarativeParserStatus) |
|
101 | Q_INTERFACES(QDeclarativeParserStatus) | |
101 | Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX) |
|
102 | Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX) | |
102 | Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY) |
|
103 | Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY) | |
103 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) |
|
104 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) | |
104 | Q_CLASSINFO("DefaultProperty", "seriesChildren") |
|
105 | Q_CLASSINFO("DefaultProperty", "seriesChildren") | |
105 |
|
106 | |||
106 | public: |
|
107 | public: | |
107 |
explicit Declarative |
|
108 | explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0); | |
108 | void setAxisX(QAbstractAxis *axis); |
|
109 | void setAxisX(QAbstractAxis *axis); | |
109 | QAbstractAxis *axisX(); |
|
110 | QAbstractAxis *axisX(); | |
110 | void setAxisY(QAbstractAxis *axis); |
|
111 | void setAxisY(QAbstractAxis *axis); | |
111 | QAbstractAxis *axisY(); |
|
112 | QAbstractAxis *axisY(); | |
112 | QDeclarativeListProperty<QObject> seriesChildren(); |
|
113 | QDeclarativeListProperty<QObject> seriesChildren(); | |
113 | Q_INVOKABLE DeclarativeBarSet *at(int index); |
|
114 | Q_INVOKABLE DeclarativeBarSet *at(int index); | |
114 | Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } |
|
115 | Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } | |
115 | Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); |
|
116 | Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); | |
116 |
Q_INVOKABLE bool remove(QBarSet *barset) { return Q |
|
117 | Q_INVOKABLE bool remove(QBarSet *barset) { return QBarSeries::remove(barset); } | |
117 |
Q_INVOKABLE void clear() { return Q |
|
118 | Q_INVOKABLE void clear() { return QBarSeries::clear(); } | |
118 |
|
119 | |||
119 | public: // from QDeclarativeParserStatus |
|
120 | public: // from QDeclarativeParserStatus | |
120 | void classBegin(); |
|
121 | void classBegin(); | |
121 | void componentComplete(); |
|
122 | void componentComplete(); | |
122 |
|
123 | |||
123 | public Q_SLOTS: |
|
124 | public Q_SLOTS: | |
124 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
125 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); | |
125 | }; |
|
126 | }; | |
126 |
|
127 | |||
127 | class DeclarativeStackedBarSeries : public QStackedBarSeries, public QDeclarativeParserStatus |
|
128 | class DeclarativeStackedBarSeries : public QStackedBarSeries, public QDeclarativeParserStatus | |
128 | { |
|
129 | { | |
129 | Q_OBJECT |
|
130 | Q_OBJECT | |
130 | Q_INTERFACES(QDeclarativeParserStatus) |
|
131 | Q_INTERFACES(QDeclarativeParserStatus) | |
131 | Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX) |
|
132 | Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX) | |
132 | Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY) |
|
133 | Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY) | |
133 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) |
|
134 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) | |
134 | Q_CLASSINFO("DefaultProperty", "seriesChildren") |
|
135 | Q_CLASSINFO("DefaultProperty", "seriesChildren") | |
135 |
|
136 | |||
136 | public: |
|
137 | public: | |
137 | explicit DeclarativeStackedBarSeries(QDeclarativeItem *parent = 0); |
|
138 | explicit DeclarativeStackedBarSeries(QDeclarativeItem *parent = 0); | |
138 | void setAxisX(QAbstractAxis *axis); |
|
139 | void setAxisX(QAbstractAxis *axis); | |
139 | QAbstractAxis *axisX(); |
|
140 | QAbstractAxis *axisX(); | |
140 | void setAxisY(QAbstractAxis *axis); |
|
141 | void setAxisY(QAbstractAxis *axis); | |
141 | QAbstractAxis *axisY(); |
|
142 | QAbstractAxis *axisY(); | |
142 | QDeclarativeListProperty<QObject> seriesChildren(); |
|
143 | QDeclarativeListProperty<QObject> seriesChildren(); | |
143 | Q_INVOKABLE DeclarativeBarSet *at(int index); |
|
144 | Q_INVOKABLE DeclarativeBarSet *at(int index); | |
144 | Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } |
|
145 | Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } | |
145 | Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); |
|
146 | Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); | |
146 | Q_INVOKABLE bool remove(QBarSet *barset) { return QStackedBarSeries::remove(barset); } |
|
147 | Q_INVOKABLE bool remove(QBarSet *barset) { return QStackedBarSeries::remove(barset); } | |
147 | Q_INVOKABLE void clear() { return QStackedBarSeries::clear(); } |
|
148 | Q_INVOKABLE void clear() { return QStackedBarSeries::clear(); } | |
148 |
|
149 | |||
149 | public: // from QDeclarativeParserStatus |
|
150 | public: // from QDeclarativeParserStatus | |
150 | void classBegin(); |
|
151 | void classBegin(); | |
151 | void componentComplete(); |
|
152 | void componentComplete(); | |
152 |
|
153 | |||
153 | public Q_SLOTS: |
|
154 | public Q_SLOTS: | |
154 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
155 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); | |
155 | }; |
|
156 | }; | |
156 |
|
157 | |||
157 | class DeclarativePercentBarSeries : public QPercentBarSeries, public QDeclarativeParserStatus |
|
158 | class DeclarativePercentBarSeries : public QPercentBarSeries, public QDeclarativeParserStatus | |
158 | { |
|
159 | { | |
159 | Q_OBJECT |
|
160 | Q_OBJECT | |
160 | Q_INTERFACES(QDeclarativeParserStatus) |
|
161 | Q_INTERFACES(QDeclarativeParserStatus) | |
161 | Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX) |
|
162 | Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX) | |
162 | Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY) |
|
163 | Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY) | |
163 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) |
|
164 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) | |
164 | Q_CLASSINFO("DefaultProperty", "seriesChildren") |
|
165 | Q_CLASSINFO("DefaultProperty", "seriesChildren") | |
165 |
|
166 | |||
166 | public: |
|
167 | public: | |
167 | explicit DeclarativePercentBarSeries(QDeclarativeItem *parent = 0); |
|
168 | explicit DeclarativePercentBarSeries(QDeclarativeItem *parent = 0); | |
168 | void setAxisX(QAbstractAxis *axis); |
|
169 | void setAxisX(QAbstractAxis *axis); | |
169 | QAbstractAxis *axisX(); |
|
170 | QAbstractAxis *axisX(); | |
170 | void setAxisY(QAbstractAxis *axis); |
|
171 | void setAxisY(QAbstractAxis *axis); | |
171 | QAbstractAxis *axisY(); |
|
172 | QAbstractAxis *axisY(); | |
172 | QDeclarativeListProperty<QObject> seriesChildren(); |
|
173 | QDeclarativeListProperty<QObject> seriesChildren(); | |
173 | Q_INVOKABLE DeclarativeBarSet *at(int index); |
|
174 | Q_INVOKABLE DeclarativeBarSet *at(int index); | |
174 | Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } |
|
175 | Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } | |
175 | Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); |
|
176 | Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); | |
176 | Q_INVOKABLE bool remove(QBarSet *barset) { return QPercentBarSeries::remove(barset); } |
|
177 | Q_INVOKABLE bool remove(QBarSet *barset) { return QPercentBarSeries::remove(barset); } | |
177 | Q_INVOKABLE void clear() { return QPercentBarSeries::clear(); } |
|
178 | Q_INVOKABLE void clear() { return QPercentBarSeries::clear(); } | |
178 |
|
179 | |||
179 | public: // from QDeclarativeParserStatus |
|
180 | public: // from QDeclarativeParserStatus | |
180 | void classBegin(); |
|
181 | void classBegin(); | |
181 | void componentComplete(); |
|
182 | void componentComplete(); | |
182 |
|
183 | |||
183 | public Q_SLOTS: |
|
184 | public Q_SLOTS: | |
184 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
185 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); | |
185 | }; |
|
186 | }; | |
186 |
|
187 | |||
187 | QTCOMMERCIALCHART_END_NAMESPACE |
|
188 | QTCOMMERCIALCHART_END_NAMESPACE | |
188 |
|
189 | |||
189 | #endif // DECLARATIVEBARSERIES_H |
|
190 | #endif // DECLARATIVEBARSERIES_H |
@@ -1,498 +1,498 | |||||
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 "declarativechart.h" |
|
21 | #include "declarativechart.h" | |
22 | #include <QPainter> |
|
22 | #include <QPainter> | |
23 | #include "declarativelineseries.h" |
|
23 | #include "declarativelineseries.h" | |
24 | #include "declarativeareaseries.h" |
|
24 | #include "declarativeareaseries.h" | |
25 | #include "declarativebarseries.h" |
|
25 | #include "declarativebarseries.h" | |
26 | #include "declarativepieseries.h" |
|
26 | #include "declarativepieseries.h" | |
27 | #include "declarativesplineseries.h" |
|
27 | #include "declarativesplineseries.h" | |
28 | #include "declarativescatterseries.h" |
|
28 | #include "declarativescatterseries.h" | |
29 | #include "qcategoriesaxis.h" |
|
29 | #include "qcategoriesaxis.h" | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | \qmlclass ChartView DeclarativeChart |
|
34 | \qmlclass ChartView DeclarativeChart | |
35 |
|
35 | |||
36 | ChartView element is the parent that is responsible for showing different chart series types. |
|
36 | ChartView element is the parent that is responsible for showing different chart series types. | |
37 |
|
37 | |||
38 | The following QML shows how to create a simple chart with one pie series: |
|
38 | The following QML shows how to create a simple chart with one pie series: | |
39 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
39 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 | |
40 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
40 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 | |
41 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
41 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 | |
42 |
|
42 | |||
43 | \beginfloatleft |
|
43 | \beginfloatleft | |
44 | \image examples_qmlpiechart.png |
|
44 | \image examples_qmlpiechart.png | |
45 | \endfloat |
|
45 | \endfloat | |
46 | \clearfloat |
|
46 | \clearfloat | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \qmlproperty Theme ChartView::theme |
|
50 | \qmlproperty Theme ChartView::theme | |
51 | Theme defines the visual appearance of the chart, including for example colors, fonts, line |
|
51 | Theme defines the visual appearance of the chart, including for example colors, fonts, line | |
52 | widths and chart background. |
|
52 | widths and chart background. | |
53 | */ |
|
53 | */ | |
54 |
|
54 | |||
55 | /*! |
|
55 | /*! | |
56 | \qmlproperty Animation ChartView::animation |
|
56 | \qmlproperty Animation ChartView::animation | |
57 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, |
|
57 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, | |
58 | ChartView.SeriesAnimations or ChartView.AllAnimations. |
|
58 | ChartView.SeriesAnimations or ChartView.AllAnimations. | |
59 | */ |
|
59 | */ | |
60 |
|
60 | |||
61 | /*! |
|
61 | /*! | |
62 | \qmlproperty Font ChartView::titleFont |
|
62 | \qmlproperty Font ChartView::titleFont | |
63 | The title font of the chart |
|
63 | The title font of the chart | |
64 |
|
64 | |||
65 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
65 | See the \l {Font} {QML Font Element} for detailed documentation. | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | \qmlproperty string ChartView::title |
|
69 | \qmlproperty string ChartView::title | |
70 | The title of the chart, shown on top of the chart. |
|
70 | The title of the chart, shown on top of the chart. | |
71 | \sa ChartView::titleColor |
|
71 | \sa ChartView::titleColor | |
72 | */ |
|
72 | */ | |
73 |
|
73 | |||
74 | /*! |
|
74 | /*! | |
75 | \qmlproperty string ChartView::titleColor |
|
75 | \qmlproperty string ChartView::titleColor | |
76 | The color of the title text. |
|
76 | The color of the title text. | |
77 | */ |
|
77 | */ | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | \qmlproperty Axis ChartView::axisX |
|
80 | \qmlproperty Axis ChartView::axisX | |
81 | The x-axis of the chart. |
|
81 | The x-axis of the chart. | |
82 | */ |
|
82 | */ | |
83 |
|
83 | |||
84 | /*! |
|
84 | /*! | |
85 | \qmlproperty Axis ChartView::axisY |
|
85 | \qmlproperty Axis ChartView::axisY | |
86 | The default y-axis of the chart. |
|
86 | The default y-axis of the chart. | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | \qmlproperty Legend ChartView::legend |
|
90 | \qmlproperty Legend ChartView::legend | |
91 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. |
|
91 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \qmlproperty int ChartView::count |
|
95 | \qmlproperty int ChartView::count | |
96 | The count of series added to the chart. |
|
96 | The count of series added to the chart. | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | \qmlproperty color ChartView::backgroundColor |
|
100 | \qmlproperty color ChartView::backgroundColor | |
101 | The color of the chart's background. By default background color is defined by chart theme. |
|
101 | The color of the chart's background. By default background color is defined by chart theme. | |
102 | \sa ChartView::theme |
|
102 | \sa ChartView::theme | |
103 | */ |
|
103 | */ | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | \qmlproperty bool ChartView::dropShadowEnabled |
|
106 | \qmlproperty bool ChartView::dropShadowEnabled | |
107 | The chart's border drop shadow. Set to true to enable drop shadow. |
|
107 | The chart's border drop shadow. Set to true to enable drop shadow. | |
108 | */ |
|
108 | */ | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | \qmlproperty real ChartView::topMargin |
|
111 | \qmlproperty real ChartView::topMargin | |
112 | The space between the top of chart view and the top of the plot area. The title (if non-empty) is drawn on top margin |
|
112 | The space between the top of chart view and the top of the plot area. The title (if non-empty) is drawn on top margin | |
113 | area of the chart view. Top margin area is also used by legend, if aligned to top. |
|
113 | area of the chart view. Top margin area is also used by legend, if aligned to top. | |
114 | */ |
|
114 | */ | |
115 |
|
115 | |||
116 | /*! |
|
116 | /*! | |
117 | \qmlproperty real ChartView::bottomMargin |
|
117 | \qmlproperty real ChartView::bottomMargin | |
118 | The space between the bottom of chart view and the bottom of the plot area. The bottom margin area may be used by |
|
118 | The space between the bottom of chart view and the bottom of the plot area. The bottom margin area may be used by | |
119 | legend (if aligned to bottom), x-axis, x-axis labels and x-axis tick marks. |
|
119 | legend (if aligned to bottom), x-axis, x-axis labels and x-axis tick marks. | |
120 | */ |
|
120 | */ | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | \qmlproperty real ChartView::leftMargin |
|
123 | \qmlproperty real ChartView::leftMargin | |
124 | The space between the left side of chart view and the left side of the plot area. The left margin area may be used by |
|
124 | The space between the left side of chart view and the left side of the plot area. The left margin area may be used by | |
125 | legend (if aligned to left), y-axis, y-axis labels and y-axis tick marks. |
|
125 | legend (if aligned to left), y-axis, y-axis labels and y-axis tick marks. | |
126 | */ |
|
126 | */ | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | \qmlproperty real ChartView::rightMargin |
|
129 | \qmlproperty real ChartView::rightMargin | |
130 | The space between the right side of chart view and the right side of the plot area. The right margin area may be used |
|
130 | The space between the right side of chart view and the right side of the plot area. The right margin area may be used | |
131 | by legend (if aligned to right). |
|
131 | by legend (if aligned to right). | |
132 | */ |
|
132 | */ | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
135 | \qmlmethod AbstractSeries ChartView::series(int index) | |
136 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
136 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with | |
137 | the count property of the chart. |
|
137 | the count property of the chart. | |
138 | */ |
|
138 | */ | |
139 |
|
139 | |||
140 | /*! |
|
140 | /*! | |
141 | \qmlmethod AbstractSeries ChartView::series(string name) |
|
141 | \qmlmethod AbstractSeries ChartView::series(string name) | |
142 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. |
|
142 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. | |
143 | */ |
|
143 | */ | |
144 |
|
144 | |||
145 | /*! |
|
145 | /*! | |
146 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name) |
|
146 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name) | |
147 | Creates a series object of \a type to the chart. For example: |
|
147 | Creates a series object of \a type to the chart. For example: | |
148 | \code |
|
148 | \code | |
149 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series"); |
|
149 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series"); | |
150 | scatter.markerSize = 22; |
|
150 | scatter.markerSize = 22; | |
151 | scatter.append(1.1, 2.0); |
|
151 | scatter.append(1.1, 2.0); | |
152 | \endcode |
|
152 | \endcode | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \qmlmethod Axis ChartView::axisY(QAbstractSeries *series) |
|
156 | \qmlmethod Axis ChartView::axisY(QAbstractSeries *series) | |
157 | The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported. |
|
157 | The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported. | |
158 | */ |
|
158 | */ | |
159 |
|
159 | |||
160 | /*! |
|
160 | /*! | |
161 | \qmlmethod ChartView::zoomY(real factor) |
|
161 | \qmlmethod ChartView::zoomY(real factor) | |
162 | Zooms in by \a factor on the center of the chart. |
|
162 | Zooms in by \a factor on the center of the chart. | |
163 | */ |
|
163 | */ | |
164 |
|
164 | |||
165 | /*! |
|
165 | /*! | |
166 | \qmlmethod ChartView::scrollLeft(real pixels) |
|
166 | \qmlmethod ChartView::scrollLeft(real pixels) | |
167 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. |
|
167 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. | |
168 | \sa Axis::min, Axis::max |
|
168 | \sa Axis::min, Axis::max | |
169 | */ |
|
169 | */ | |
170 |
|
170 | |||
171 | /*! |
|
171 | /*! | |
172 | \qmlmethod ChartView::scrollRight(real pixels) |
|
172 | \qmlmethod ChartView::scrollRight(real pixels) | |
173 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. |
|
173 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. | |
174 | \sa Axis::min, Axis::max |
|
174 | \sa Axis::min, Axis::max | |
175 | */ |
|
175 | */ | |
176 |
|
176 | |||
177 | /*! |
|
177 | /*! | |
178 | \qmlmethod ChartView::scrollUp(real pixels) |
|
178 | \qmlmethod ChartView::scrollUp(real pixels) | |
179 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. |
|
179 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. | |
180 | \sa Axis::min, Axis::max |
|
180 | \sa Axis::min, Axis::max | |
181 | */ |
|
181 | */ | |
182 |
|
182 | |||
183 | /*! |
|
183 | /*! | |
184 | \qmlmethod ChartView::scrollDown(real pixels) |
|
184 | \qmlmethod ChartView::scrollDown(real pixels) | |
185 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. |
|
185 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. | |
186 | \sa Axis::min, Axis::max |
|
186 | \sa Axis::min, Axis::max | |
187 | */ |
|
187 | */ | |
188 |
|
188 | |||
189 | /*! |
|
189 | /*! | |
190 | \qmlsignal ChartView::onTopMarginChanged(real margin) |
|
190 | \qmlsignal ChartView::onTopMarginChanged(real margin) | |
191 | The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
191 | The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size | |
192 | related properties of the legend or chart title. |
|
192 | related properties of the legend or chart title. | |
193 | */ |
|
193 | */ | |
194 |
|
194 | |||
195 | /*! |
|
195 | /*! | |
196 | \qmlsignal ChartView::onBottomMarginChanged(real margin) |
|
196 | \qmlsignal ChartView::onBottomMarginChanged(real margin) | |
197 | The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
197 | The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size | |
198 | related properties of the legend or chart title. |
|
198 | related properties of the legend or chart title. | |
199 | */ |
|
199 | */ | |
200 |
|
200 | |||
201 | /*! |
|
201 | /*! | |
202 | \qmlsignal ChartView::onLeftMarginChanged(real margin) |
|
202 | \qmlsignal ChartView::onLeftMarginChanged(real margin) | |
203 | The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
203 | The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size | |
204 | related properties of the legend or chart title. |
|
204 | related properties of the legend or chart title. | |
205 | */ |
|
205 | */ | |
206 |
|
206 | |||
207 | /*! |
|
207 | /*! | |
208 | \qmlsignal ChartView::onRightMarginChanged(real margin) |
|
208 | \qmlsignal ChartView::onRightMarginChanged(real margin) | |
209 | The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
209 | The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size | |
210 | related properties of the legend or chart title. |
|
210 | related properties of the legend or chart title. | |
211 | */ |
|
211 | */ | |
212 |
|
212 | |||
213 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
213 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) | |
214 | : QDeclarativeItem(parent), |
|
214 | : QDeclarativeItem(parent), | |
215 | m_chart(new QChart(this)) |
|
215 | m_chart(new QChart(this)) | |
216 | { |
|
216 | { | |
217 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
217 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
218 | // m_chart->axisX()->setNiceNumbersEnabled(false); |
|
218 | // m_chart->axisX()->setNiceNumbersEnabled(false); | |
219 | m_chartMargins = m_chart->margins(); |
|
219 | m_chartMargins = m_chart->margins(); | |
220 | connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF))); |
|
220 | connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF))); | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | void DeclarativeChart::handleMarginsChanged(QRectF newMargins) |
|
223 | void DeclarativeChart::handleMarginsChanged(QRectF newMargins) | |
224 | { |
|
224 | { | |
225 | if (m_chartMargins.top() != newMargins.top()) |
|
225 | if (m_chartMargins.top() != newMargins.top()) | |
226 | topMarginChanged(m_chart->margins().top()); |
|
226 | topMarginChanged(m_chart->margins().top()); | |
227 | if (m_chartMargins.bottom() != newMargins.bottom()) |
|
227 | if (m_chartMargins.bottom() != newMargins.bottom()) | |
228 | bottomMarginChanged(m_chart->margins().bottom()); |
|
228 | bottomMarginChanged(m_chart->margins().bottom()); | |
229 | if (m_chartMargins.left() != newMargins.left()) |
|
229 | if (m_chartMargins.left() != newMargins.left()) | |
230 | leftMarginChanged(m_chart->margins().left()); |
|
230 | leftMarginChanged(m_chart->margins().left()); | |
231 | if (m_chartMargins.right() != newMargins.right()) |
|
231 | if (m_chartMargins.right() != newMargins.right()) | |
232 | rightMarginChanged(m_chart->margins().right()); |
|
232 | rightMarginChanged(m_chart->margins().right()); | |
233 |
|
233 | |||
234 | m_chartMargins = m_chart->margins(); |
|
234 | m_chartMargins = m_chart->margins(); | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | DeclarativeChart::~DeclarativeChart() |
|
237 | DeclarativeChart::~DeclarativeChart() | |
238 | { |
|
238 | { | |
239 | delete m_chart; |
|
239 | delete m_chart; | |
240 | } |
|
240 | } | |
241 |
|
241 | |||
242 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
242 | void DeclarativeChart::childEvent(QChildEvent *event) | |
243 | { |
|
243 | { | |
244 | if (event->type() == QEvent::ChildAdded) { |
|
244 | if (event->type() == QEvent::ChildAdded) { | |
245 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
245 | if (qobject_cast<QAbstractSeries *>(event->child())) { | |
246 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
246 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); | |
247 | } |
|
247 | } | |
248 | } |
|
248 | } | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | void DeclarativeChart::componentComplete() |
|
251 | void DeclarativeChart::componentComplete() | |
252 | { |
|
252 | { | |
253 | foreach(QObject *child, children()) { |
|
253 | foreach(QObject *child, children()) { | |
254 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
254 | if (qobject_cast<QAbstractSeries *>(child)) { | |
255 | // qDebug() << "DeclarativeChart::componentComplete(), add: " << child; |
|
255 | // qDebug() << "DeclarativeChart::componentComplete(), add: " << child; | |
256 | // TODO: how about optional y-axis? |
|
256 | // TODO: how about optional y-axis? | |
257 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(child)); |
|
257 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(child)); | |
258 | } |
|
258 | } | |
259 | } |
|
259 | } | |
260 | QDeclarativeItem::componentComplete(); |
|
260 | QDeclarativeItem::componentComplete(); | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
263 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) | |
264 | { |
|
264 | { | |
265 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); |
|
265 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); | |
266 | if (newGeometry.isValid()) { |
|
266 | if (newGeometry.isValid()) { | |
267 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
267 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { | |
268 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
268 | m_chart->resize(newGeometry.width(), newGeometry.height()); | |
269 | } |
|
269 | } | |
270 | } |
|
270 | } | |
271 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); |
|
271 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); | |
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
274 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
275 | { |
|
275 | { | |
276 | Q_UNUSED(option) |
|
276 | Q_UNUSED(option) | |
277 | Q_UNUSED(widget) |
|
277 | Q_UNUSED(widget) | |
278 |
|
278 | |||
279 | // TODO: optimized? |
|
279 | // TODO: optimized? | |
280 | painter->setRenderHint(QPainter::Antialiasing, true); |
|
280 | painter->setRenderHint(QPainter::Antialiasing, true); | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
283 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) | |
284 | { |
|
284 | { | |
285 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
285 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; | |
286 | if (chartTheme != m_chart->theme()) |
|
286 | if (chartTheme != m_chart->theme()) | |
287 | m_chart->setTheme(chartTheme); |
|
287 | m_chart->setTheme(chartTheme); | |
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
290 | DeclarativeChart::Theme DeclarativeChart::theme() | |
291 | { |
|
291 | { | |
292 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
292 | return (DeclarativeChart::Theme) m_chart->theme(); | |
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
295 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) | |
296 | { |
|
296 | { | |
297 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
297 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; | |
298 | if (animationOptions != m_chart->animationOptions()) |
|
298 | if (animationOptions != m_chart->animationOptions()) | |
299 | m_chart->setAnimationOptions(animationOptions); |
|
299 | m_chart->setAnimationOptions(animationOptions); | |
300 | } |
|
300 | } | |
301 |
|
301 | |||
302 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
302 | DeclarativeChart::Animation DeclarativeChart::animationOptions() | |
303 | { |
|
303 | { | |
304 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
304 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) | |
305 | return DeclarativeChart::AllAnimations; |
|
305 | return DeclarativeChart::AllAnimations; | |
306 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
306 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) | |
307 | return DeclarativeChart::GridAxisAnimations; |
|
307 | return DeclarativeChart::GridAxisAnimations; | |
308 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
308 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) | |
309 | return DeclarativeChart::SeriesAnimations; |
|
309 | return DeclarativeChart::SeriesAnimations; | |
310 | else |
|
310 | else | |
311 | return DeclarativeChart::NoAnimation; |
|
311 | return DeclarativeChart::NoAnimation; | |
312 | } |
|
312 | } | |
313 |
|
313 | |||
314 | void DeclarativeChart::setTitle(QString title) |
|
314 | void DeclarativeChart::setTitle(QString title) | |
315 | { |
|
315 | { | |
316 | if (title != m_chart->title()) |
|
316 | if (title != m_chart->title()) | |
317 | m_chart->setTitle(title); |
|
317 | m_chart->setTitle(title); | |
318 | } |
|
318 | } | |
319 | QString DeclarativeChart::title() |
|
319 | QString DeclarativeChart::title() | |
320 | { |
|
320 | { | |
321 | return m_chart->title(); |
|
321 | return m_chart->title(); | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) |
|
324 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) | |
325 | { |
|
325 | { | |
326 | return m_chart->axisX(series); |
|
326 | return m_chart->axisX(series); | |
327 | } |
|
327 | } | |
328 |
|
328 | |||
329 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
329 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) | |
330 | { |
|
330 | { | |
331 | return m_chart->axisY(series); |
|
331 | return m_chart->axisY(series); | |
332 | } |
|
332 | } | |
333 |
|
333 | |||
334 | QLegend *DeclarativeChart::legend() |
|
334 | QLegend *DeclarativeChart::legend() | |
335 | { |
|
335 | { | |
336 | return m_chart->legend(); |
|
336 | return m_chart->legend(); | |
337 | } |
|
337 | } | |
338 |
|
338 | |||
339 | void DeclarativeChart::setTitleColor(QColor color) |
|
339 | void DeclarativeChart::setTitleColor(QColor color) | |
340 | { |
|
340 | { | |
341 | QBrush b = m_chart->titleBrush(); |
|
341 | QBrush b = m_chart->titleBrush(); | |
342 | if (color != b.color()) { |
|
342 | if (color != b.color()) { | |
343 | b.setColor(color); |
|
343 | b.setColor(color); | |
344 | m_chart->setTitleBrush(b); |
|
344 | m_chart->setTitleBrush(b); | |
345 | emit titleColorChanged(color); |
|
345 | emit titleColorChanged(color); | |
346 | } |
|
346 | } | |
347 | } |
|
347 | } | |
348 |
|
348 | |||
349 | QFont DeclarativeChart::titleFont() const |
|
349 | QFont DeclarativeChart::titleFont() const | |
350 | { |
|
350 | { | |
351 | return m_chart->titleFont(); |
|
351 | return m_chart->titleFont(); | |
352 | } |
|
352 | } | |
353 |
|
353 | |||
354 | void DeclarativeChart::setTitleFont(const QFont& font) |
|
354 | void DeclarativeChart::setTitleFont(const QFont& font) | |
355 | { |
|
355 | { | |
356 | m_chart->setTitleFont(font); |
|
356 | m_chart->setTitleFont(font); | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | QColor DeclarativeChart::titleColor() |
|
359 | QColor DeclarativeChart::titleColor() | |
360 | { |
|
360 | { | |
361 | return m_chart->titleBrush().color(); |
|
361 | return m_chart->titleBrush().color(); | |
362 | } |
|
362 | } | |
363 |
|
363 | |||
364 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
364 | void DeclarativeChart::setBackgroundColor(QColor color) | |
365 | { |
|
365 | { | |
366 | QBrush b = m_chart->backgroundBrush(); |
|
366 | QBrush b = m_chart->backgroundBrush(); | |
367 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
367 | if (b.style() != Qt::SolidPattern || color != b.color()) { | |
368 | b.setStyle(Qt::SolidPattern); |
|
368 | b.setStyle(Qt::SolidPattern); | |
369 | b.setColor(color); |
|
369 | b.setColor(color); | |
370 | m_chart->setBackgroundBrush(b); |
|
370 | m_chart->setBackgroundBrush(b); | |
371 | emit backgroundColorChanged(); |
|
371 | emit backgroundColorChanged(); | |
372 | } |
|
372 | } | |
373 | } |
|
373 | } | |
374 |
|
374 | |||
375 | QColor DeclarativeChart::backgroundColor() |
|
375 | QColor DeclarativeChart::backgroundColor() | |
376 | { |
|
376 | { | |
377 | return m_chart->backgroundBrush().color(); |
|
377 | return m_chart->backgroundBrush().color(); | |
378 | } |
|
378 | } | |
379 |
|
379 | |||
380 | int DeclarativeChart::count() |
|
380 | int DeclarativeChart::count() | |
381 | { |
|
381 | { | |
382 | return m_chart->series().count(); |
|
382 | return m_chart->series().count(); | |
383 | } |
|
383 | } | |
384 |
|
384 | |||
385 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
385 | void DeclarativeChart::setDropShadowEnabled(bool enabled) | |
386 | { |
|
386 | { | |
387 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
387 | if (enabled != m_chart->isDropShadowEnabled()) { | |
388 | m_chart->setDropShadowEnabled(enabled); |
|
388 | m_chart->setDropShadowEnabled(enabled); | |
389 | dropShadowEnabledChanged(enabled); |
|
389 | dropShadowEnabledChanged(enabled); | |
390 | } |
|
390 | } | |
391 | } |
|
391 | } | |
392 |
|
392 | |||
393 | bool DeclarativeChart::dropShadowEnabled() |
|
393 | bool DeclarativeChart::dropShadowEnabled() | |
394 | { |
|
394 | { | |
395 | return m_chart->isDropShadowEnabled(); |
|
395 | return m_chart->isDropShadowEnabled(); | |
396 | } |
|
396 | } | |
397 |
|
397 | |||
398 | qreal DeclarativeChart::topMargin() |
|
398 | qreal DeclarativeChart::topMargin() | |
399 | { |
|
399 | { | |
400 | return m_chart->margins().top(); |
|
400 | return m_chart->margins().top(); | |
401 | } |
|
401 | } | |
402 |
|
402 | |||
403 | qreal DeclarativeChart::bottomMargin() |
|
403 | qreal DeclarativeChart::bottomMargin() | |
404 | { |
|
404 | { | |
405 | return m_chart->margins().bottom(); |
|
405 | return m_chart->margins().bottom(); | |
406 | } |
|
406 | } | |
407 |
|
407 | |||
408 | qreal DeclarativeChart::leftMargin() |
|
408 | qreal DeclarativeChart::leftMargin() | |
409 | { |
|
409 | { | |
410 | return m_chart->margins().left(); |
|
410 | return m_chart->margins().left(); | |
411 | } |
|
411 | } | |
412 |
|
412 | |||
413 | qreal DeclarativeChart::rightMargin() |
|
413 | qreal DeclarativeChart::rightMargin() | |
414 | { |
|
414 | { | |
415 | return m_chart->margins().right(); |
|
415 | return m_chart->margins().right(); | |
416 | } |
|
416 | } | |
417 |
|
417 | |||
418 | void DeclarativeChart::zoom(qreal factor) |
|
418 | void DeclarativeChart::zoom(qreal factor) | |
419 | { |
|
419 | { | |
420 | m_chart->zoom(factor); |
|
420 | m_chart->zoom(factor); | |
421 | } |
|
421 | } | |
422 |
|
422 | |||
423 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
423 | void DeclarativeChart::scrollLeft(qreal pixels) | |
424 | { |
|
424 | { | |
425 | m_chart->scroll(pixels, 0); |
|
425 | m_chart->scroll(pixels, 0); | |
426 | } |
|
426 | } | |
427 |
|
427 | |||
428 | void DeclarativeChart::scrollRight(qreal pixels) |
|
428 | void DeclarativeChart::scrollRight(qreal pixels) | |
429 | { |
|
429 | { | |
430 | m_chart->scroll(-pixels, 0); |
|
430 | m_chart->scroll(-pixels, 0); | |
431 | } |
|
431 | } | |
432 |
|
432 | |||
433 | void DeclarativeChart::scrollUp(qreal pixels) |
|
433 | void DeclarativeChart::scrollUp(qreal pixels) | |
434 | { |
|
434 | { | |
435 | m_chart->scroll(0, pixels); |
|
435 | m_chart->scroll(0, pixels); | |
436 | } |
|
436 | } | |
437 |
|
437 | |||
438 | void DeclarativeChart::scrollDown(qreal pixels) |
|
438 | void DeclarativeChart::scrollDown(qreal pixels) | |
439 | { |
|
439 | { | |
440 | m_chart->scroll(0, -pixels); |
|
440 | m_chart->scroll(0, -pixels); | |
441 | } |
|
441 | } | |
442 |
|
442 | |||
443 | QAbstractSeries *DeclarativeChart::series(int index) |
|
443 | QAbstractSeries *DeclarativeChart::series(int index) | |
444 | { |
|
444 | { | |
445 | if (index < m_chart->series().count()) { |
|
445 | if (index < m_chart->series().count()) { | |
446 | return m_chart->series().at(index); |
|
446 | return m_chart->series().at(index); | |
447 | } |
|
447 | } | |
448 | return 0; |
|
448 | return 0; | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
451 | QAbstractSeries *DeclarativeChart::series(QString seriesName) | |
452 | { |
|
452 | { | |
453 | foreach(QAbstractSeries *series, m_chart->series()) { |
|
453 | foreach(QAbstractSeries *series, m_chart->series()) { | |
454 | if (series->name() == seriesName) |
|
454 | if (series->name() == seriesName) | |
455 | return series; |
|
455 | return series; | |
456 | } |
|
456 | } | |
457 | return 0; |
|
457 | return 0; | |
458 | } |
|
458 | } | |
459 |
|
459 | |||
460 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) |
|
460 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) | |
461 | { |
|
461 | { | |
462 | QAbstractSeries *series = 0; |
|
462 | QAbstractSeries *series = 0; | |
463 | switch (type) { |
|
463 | switch (type) { | |
464 | case DeclarativeChart::SeriesTypeLine: |
|
464 | case DeclarativeChart::SeriesTypeLine: | |
465 | series = new DeclarativeLineSeries(); |
|
465 | series = new DeclarativeLineSeries(); | |
466 | break; |
|
466 | break; | |
467 | case DeclarativeChart::SeriesTypeArea: |
|
467 | case DeclarativeChart::SeriesTypeArea: | |
468 | series = new DeclarativeAreaSeries(); |
|
468 | series = new DeclarativeAreaSeries(); | |
469 | break; |
|
469 | break; | |
470 | case DeclarativeChart::SeriesTypeStackedBar: |
|
470 | case DeclarativeChart::SeriesTypeStackedBar: | |
471 | // TODO |
|
471 | // TODO | |
472 | break; |
|
472 | break; | |
473 | case DeclarativeChart::SeriesTypePercentBar: |
|
473 | case DeclarativeChart::SeriesTypePercentBar: | |
474 | // TODO |
|
474 | // TODO | |
475 | break; |
|
475 | break; | |
476 |
case DeclarativeChart::SeriesType |
|
476 | case DeclarativeChart::SeriesTypeBar: | |
477 |
series = new Declarative |
|
477 | series = new DeclarativeBarSeries(); | |
478 | break; |
|
478 | break; | |
479 | case DeclarativeChart::SeriesTypePie: |
|
479 | case DeclarativeChart::SeriesTypePie: | |
480 | series = new DeclarativePieSeries(); |
|
480 | series = new DeclarativePieSeries(); | |
481 | break; |
|
481 | break; | |
482 | case DeclarativeChart::SeriesTypeScatter: |
|
482 | case DeclarativeChart::SeriesTypeScatter: | |
483 | series = new DeclarativeScatterSeries(); |
|
483 | series = new DeclarativeScatterSeries(); | |
484 | break; |
|
484 | break; | |
485 | case DeclarativeChart::SeriesTypeSpline: |
|
485 | case DeclarativeChart::SeriesTypeSpline: | |
486 | series = new DeclarativeSplineSeries(); |
|
486 | series = new DeclarativeSplineSeries(); | |
487 | break; |
|
487 | break; | |
488 | default: |
|
488 | default: | |
489 | qWarning() << "Illegal series type"; |
|
489 | qWarning() << "Illegal series type"; | |
490 | } |
|
490 | } | |
491 | series->setName(name); |
|
491 | series->setName(name); | |
492 | m_chart->addSeries(series); |
|
492 | m_chart->addSeries(series); | |
493 | return series; |
|
493 | return series; | |
494 | } |
|
494 | } | |
495 |
|
495 | |||
496 | #include "moc_declarativechart.cpp" |
|
496 | #include "moc_declarativechart.cpp" | |
497 |
|
497 | |||
498 | QTCOMMERCIALCHART_END_NAMESPACE |
|
498 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,152 +1,151 | |||||
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 DECLARATIVECHART_H |
|
21 | #ifndef DECLARATIVECHART_H | |
22 | #define DECLARATIVECHART_H |
|
22 | #define DECLARATIVECHART_H | |
23 |
|
23 | |||
24 | #include <QtCore/QtGlobal> |
|
24 | #include <QtCore/QtGlobal> | |
25 | #include <QDeclarativeItem> |
|
25 | #include <QDeclarativeItem> | |
26 | #include <qchart.h> |
|
26 | #include <qchart.h> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | // TODO: Derive from QChart for easier definition of properties? |
|
30 | // TODO: Derive from QChart for easier definition of properties? | |
31 | class DeclarativeChart : public QDeclarativeItem |
|
31 | class DeclarativeChart : public QDeclarativeItem | |
32 | // TODO: for QTQUICK2: extend QQuickPainterItem instead |
|
32 | // TODO: for QTQUICK2: extend QQuickPainterItem instead | |
33 | //class DeclarativeChart : public QQuickPaintedItem, public Chart |
|
33 | //class DeclarativeChart : public QQuickPaintedItem, public Chart | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 | Q_PROPERTY(Theme theme READ theme WRITE setTheme) |
|
36 | Q_PROPERTY(Theme theme READ theme WRITE setTheme) | |
37 | Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions) |
|
37 | Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions) | |
38 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
38 | Q_PROPERTY(QString title READ title WRITE setTitle) | |
39 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) |
|
39 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) | |
40 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) |
|
40 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) | |
41 | Q_PROPERTY(QAbstractAxis *axisX READ axisX) |
|
41 | Q_PROPERTY(QAbstractAxis *axisX READ axisX) | |
42 | Q_PROPERTY(QAbstractAxis *axisY READ axisY) |
|
42 | Q_PROPERTY(QAbstractAxis *axisY READ axisY) | |
43 | Q_PROPERTY(QLegend *legend READ legend) |
|
43 | Q_PROPERTY(QLegend *legend READ legend) | |
44 | Q_PROPERTY(int count READ count) |
|
44 | Q_PROPERTY(int count READ count) | |
45 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) |
|
45 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) | |
46 | Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged) |
|
46 | Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged) | |
47 | Q_PROPERTY(qreal topMargin READ topMargin NOTIFY topMarginChanged) |
|
47 | Q_PROPERTY(qreal topMargin READ topMargin NOTIFY topMarginChanged) | |
48 | Q_PROPERTY(qreal bottomMargin READ bottomMargin NOTIFY bottomMarginChanged) |
|
48 | Q_PROPERTY(qreal bottomMargin READ bottomMargin NOTIFY bottomMarginChanged) | |
49 | Q_PROPERTY(qreal leftMargin READ leftMargin NOTIFY leftMarginChanged) |
|
49 | Q_PROPERTY(qreal leftMargin READ leftMargin NOTIFY leftMarginChanged) | |
50 | Q_PROPERTY(qreal rightMargin READ rightMargin NOTIFY rightMarginChanged) |
|
50 | Q_PROPERTY(qreal rightMargin READ rightMargin NOTIFY rightMarginChanged) | |
51 | Q_ENUMS(Animation) |
|
51 | Q_ENUMS(Animation) | |
52 | Q_ENUMS(Theme) |
|
52 | Q_ENUMS(Theme) | |
53 | Q_ENUMS(SeriesType) |
|
53 | Q_ENUMS(SeriesType) | |
54 |
|
54 | |||
55 | public: |
|
55 | public: | |
56 | // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api |
|
56 | // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api | |
57 | enum Theme { |
|
57 | enum Theme { | |
58 | ChartThemeLight = 0, |
|
58 | ChartThemeLight = 0, | |
59 | ChartThemeBlueCerulean, |
|
59 | ChartThemeBlueCerulean, | |
60 | ChartThemeDark, |
|
60 | ChartThemeDark, | |
61 | ChartThemeBrownSand, |
|
61 | ChartThemeBrownSand, | |
62 | ChartThemeBlueNcs, |
|
62 | ChartThemeBlueNcs, | |
63 | ChartThemeHighContrast, |
|
63 | ChartThemeHighContrast, | |
64 | ChartThemeBlueIcy |
|
64 | ChartThemeBlueIcy | |
65 | }; |
|
65 | }; | |
66 |
|
66 | |||
67 | enum Animation { |
|
67 | enum Animation { | |
68 | NoAnimation = 0x0, |
|
68 | NoAnimation = 0x0, | |
69 | GridAxisAnimations = 0x1, |
|
69 | GridAxisAnimations = 0x1, | |
70 | SeriesAnimations =0x2, |
|
70 | SeriesAnimations =0x2, | |
71 | AllAnimations = 0x3 |
|
71 | AllAnimations = 0x3 | |
72 | }; |
|
72 | }; | |
73 |
|
73 | |||
74 | enum SeriesType { |
|
74 | enum SeriesType { | |
75 | SeriesTypeLine, |
|
75 | SeriesTypeLine, | |
76 | SeriesTypeArea, |
|
76 | SeriesTypeArea, | |
77 | SeriesTypeBar, |
|
77 | SeriesTypeBar, | |
78 | SeriesTypeStackedBar, |
|
78 | SeriesTypeStackedBar, | |
79 | SeriesTypePercentBar, |
|
79 | SeriesTypePercentBar, | |
80 | SeriesTypeGroupedBar, |
|
|||
81 | SeriesTypePie, |
|
80 | SeriesTypePie, | |
82 | SeriesTypeScatter, |
|
81 | SeriesTypeScatter, | |
83 | SeriesTypeSpline |
|
82 | SeriesTypeSpline | |
84 | }; |
|
83 | }; | |
85 |
|
84 | |||
86 | public: |
|
85 | public: | |
87 | DeclarativeChart(QDeclarativeItem *parent = 0); |
|
86 | DeclarativeChart(QDeclarativeItem *parent = 0); | |
88 | ~DeclarativeChart(); |
|
87 | ~DeclarativeChart(); | |
89 |
|
88 | |||
90 | public: // From QDeclarativeItem/QGraphicsItem |
|
89 | public: // From QDeclarativeItem/QGraphicsItem | |
91 | void childEvent(QChildEvent *event); |
|
90 | void childEvent(QChildEvent *event); | |
92 | void componentComplete(); |
|
91 | void componentComplete(); | |
93 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
92 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); | |
94 | void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
93 | void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
95 |
|
94 | |||
96 | public: |
|
95 | public: | |
97 | void setTheme(DeclarativeChart::Theme theme); |
|
96 | void setTheme(DeclarativeChart::Theme theme); | |
98 | DeclarativeChart::Theme theme(); |
|
97 | DeclarativeChart::Theme theme(); | |
99 | void setAnimationOptions(DeclarativeChart::Animation animations); |
|
98 | void setAnimationOptions(DeclarativeChart::Animation animations); | |
100 | DeclarativeChart::Animation animationOptions(); |
|
99 | DeclarativeChart::Animation animationOptions(); | |
101 | void setTitle(QString title); |
|
100 | void setTitle(QString title); | |
102 | QString title(); |
|
101 | QString title(); | |
103 | QLegend *legend(); |
|
102 | QLegend *legend(); | |
104 | QFont titleFont() const; |
|
103 | QFont titleFont() const; | |
105 | void setTitleFont(const QFont& font); |
|
104 | void setTitleFont(const QFont& font); | |
106 | void setTitleColor(QColor color); |
|
105 | void setTitleColor(QColor color); | |
107 | QColor titleColor(); |
|
106 | QColor titleColor(); | |
108 | void setBackgroundColor(QColor color); |
|
107 | void setBackgroundColor(QColor color); | |
109 | QColor backgroundColor(); |
|
108 | QColor backgroundColor(); | |
110 | int count(); |
|
109 | int count(); | |
111 | void setDropShadowEnabled(bool enabled); |
|
110 | void setDropShadowEnabled(bool enabled); | |
112 | bool dropShadowEnabled(); |
|
111 | bool dropShadowEnabled(); | |
113 | qreal topMargin(); |
|
112 | qreal topMargin(); | |
114 | qreal bottomMargin(); |
|
113 | qreal bottomMargin(); | |
115 | qreal leftMargin(); |
|
114 | qreal leftMargin(); | |
116 | qreal rightMargin(); |
|
115 | qreal rightMargin(); | |
117 |
|
116 | |||
118 | public: |
|
117 | public: | |
119 | Q_INVOKABLE QAbstractSeries *series(int index); |
|
118 | Q_INVOKABLE QAbstractSeries *series(int index); | |
120 | Q_INVOKABLE QAbstractSeries *series(QString seriesName); |
|
119 | Q_INVOKABLE QAbstractSeries *series(QString seriesName); | |
121 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = ""); |
|
120 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = ""); | |
122 | Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0); |
|
121 | Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0); | |
123 | Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0); |
|
122 | Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0); | |
124 | Q_INVOKABLE void zoom(qreal factor); |
|
123 | Q_INVOKABLE void zoom(qreal factor); | |
125 | Q_INVOKABLE void scrollLeft(qreal pixels); |
|
124 | Q_INVOKABLE void scrollLeft(qreal pixels); | |
126 | Q_INVOKABLE void scrollRight(qreal pixels); |
|
125 | Q_INVOKABLE void scrollRight(qreal pixels); | |
127 | Q_INVOKABLE void scrollUp(qreal pixels); |
|
126 | Q_INVOKABLE void scrollUp(qreal pixels); | |
128 | Q_INVOKABLE void scrollDown(qreal pixels); |
|
127 | Q_INVOKABLE void scrollDown(qreal pixels); | |
129 |
|
128 | |||
130 | Q_SIGNALS: |
|
129 | Q_SIGNALS: | |
131 | void axisLabelsChanged(); |
|
130 | void axisLabelsChanged(); | |
132 | void titleColorChanged(QColor color); |
|
131 | void titleColorChanged(QColor color); | |
133 | void backgroundColorChanged(); |
|
132 | void backgroundColorChanged(); | |
134 | void dropShadowEnabledChanged(bool enabled); |
|
133 | void dropShadowEnabledChanged(bool enabled); | |
135 | void topMarginChanged(qreal margin); |
|
134 | void topMarginChanged(qreal margin); | |
136 | void bottomMarginChanged(qreal margin); |
|
135 | void bottomMarginChanged(qreal margin); | |
137 | void leftMarginChanged(qreal margin); |
|
136 | void leftMarginChanged(qreal margin); | |
138 | void rightMarginChanged(qreal margin); |
|
137 | void rightMarginChanged(qreal margin); | |
139 |
|
138 | |||
140 | public Q_SLOTS: |
|
139 | public Q_SLOTS: | |
141 | void handleMarginsChanged(QRectF newMargins); |
|
140 | void handleMarginsChanged(QRectF newMargins); | |
142 |
|
141 | |||
143 | private: |
|
142 | private: | |
144 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
143 | // Extending QChart with DeclarativeChart is not possible because QObject does not support | |
145 | // multi inheritance, so we now have a QChart as a member instead |
|
144 | // multi inheritance, so we now have a QChart as a member instead | |
146 | QChart *m_chart; |
|
145 | QChart *m_chart; | |
147 | QRectF m_chartMargins; |
|
146 | QRectF m_chartMargins; | |
148 | }; |
|
147 | }; | |
149 |
|
148 | |||
150 | QTCOMMERCIALCHART_END_NAMESPACE |
|
149 | QTCOMMERCIALCHART_END_NAMESPACE | |
151 |
|
150 | |||
152 | #endif // DECLARATIVECHART_H |
|
151 | #endif // DECLARATIVECHART_H |
@@ -1,108 +1,108 | |||||
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 <QtDeclarative/qdeclarativeextensionplugin.h> |
|
21 | #include <QtDeclarative/qdeclarativeextensionplugin.h> | |
22 | #include <QtDeclarative/qdeclarative.h> |
|
22 | #include <QtDeclarative/qdeclarative.h> | |
23 | #include "qchart.h" |
|
23 | #include "qchart.h" | |
24 | #include "qabstractaxis.h" |
|
24 | #include "qabstractaxis.h" | |
25 | #include "qvaluesaxis.h" |
|
25 | #include "qvaluesaxis.h" | |
26 | #include "qcategoriesaxis.h" |
|
26 | #include "qcategoriesaxis.h" | |
27 | #include "declarativechart.h" |
|
27 | #include "declarativechart.h" | |
28 | #include "declarativexypoint.h" |
|
28 | #include "declarativexypoint.h" | |
29 | #include "declarativelineseries.h" |
|
29 | #include "declarativelineseries.h" | |
30 | #include "declarativesplineseries.h" |
|
30 | #include "declarativesplineseries.h" | |
31 | #include "declarativeareaseries.h" |
|
31 | #include "declarativeareaseries.h" | |
32 | #include "declarativescatterseries.h" |
|
32 | #include "declarativescatterseries.h" | |
33 | #include "declarativebarseries.h" |
|
33 | #include "declarativebarseries.h" | |
34 | #include "declarativepieseries.h" |
|
34 | #include "declarativepieseries.h" | |
35 | #include <QVXYModelMapper> |
|
35 | #include <QVXYModelMapper> | |
36 | #include <QHXYModelMapper> |
|
36 | #include <QHXYModelMapper> | |
37 | #include <QHPieModelMapper> |
|
37 | #include <QHPieModelMapper> | |
38 | #include <QVPieModelMapper> |
|
38 | #include <QVPieModelMapper> | |
39 | #include <QHBarModelMapper> |
|
39 | #include <QHBarModelMapper> | |
40 | #include <QVBarModelMapper> |
|
40 | #include <QVBarModelMapper> | |
41 |
|
41 | |||
42 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
42 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
43 |
|
43 | |||
44 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin |
|
44 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin | |
45 | { |
|
45 | { | |
46 | Q_OBJECT |
|
46 | Q_OBJECT | |
47 | public: |
|
47 | public: | |
48 | virtual void registerTypes(const char *uri) |
|
48 | virtual void registerTypes(const char *uri) | |
49 | { |
|
49 | { | |
50 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); |
|
50 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); | |
51 |
|
51 | |||
52 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); |
|
52 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); | |
53 | qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint"); |
|
53 | qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint"); | |
54 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); |
|
54 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); | |
55 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); |
|
55 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); | |
56 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); |
|
56 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); | |
57 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); |
|
57 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); | |
58 |
qmlRegisterType<Declarative |
|
58 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); | |
59 | qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries"); |
|
59 | qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries"); | |
60 | qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries"); |
|
60 | qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries"); | |
61 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); |
|
61 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); | |
62 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); |
|
62 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); | |
63 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); |
|
63 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); | |
64 | qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper"); |
|
64 | qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper"); | |
65 | qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper"); |
|
65 | qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper"); | |
66 | qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper"); |
|
66 | qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper"); | |
67 | qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper"); |
|
67 | qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper"); | |
68 | qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper"); |
|
68 | qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper"); | |
69 | qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper"); |
|
69 | qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper"); | |
70 | qmlRegisterType<QValuesAxis>(uri, 1, 0, "ValuesAxis"); |
|
70 | qmlRegisterType<QValuesAxis>(uri, 1, 0, "ValuesAxis"); | |
71 | qmlRegisterType<QCategoriesAxis>(uri, 1, 0, "CategoriesAxis"); |
|
71 | qmlRegisterType<QCategoriesAxis>(uri, 1, 0, "CategoriesAxis"); | |
72 |
|
72 | |||
73 | qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend", |
|
73 | qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend", | |
74 | QLatin1String("Trying to create uncreatable: Legend.")); |
|
74 | QLatin1String("Trying to create uncreatable: Legend.")); | |
75 | qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries", |
|
75 | qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries", | |
76 | QLatin1String("Trying to create uncreatable: XYSeries.")); |
|
76 | QLatin1String("Trying to create uncreatable: XYSeries.")); | |
77 | qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries", |
|
77 | qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries", | |
78 | QLatin1String("Trying to create uncreatable: QScatterSeries.")); |
|
78 | QLatin1String("Trying to create uncreatable: QScatterSeries.")); | |
79 | qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries", |
|
79 | qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries", | |
80 | QLatin1String("Trying to create uncreatable: QPieSeries.")); |
|
80 | QLatin1String("Trying to create uncreatable: QPieSeries.")); | |
81 | qmlRegisterUncreatableType<QBarSet>(uri, 1, 0, "QBarSet", |
|
81 | qmlRegisterUncreatableType<QBarSet>(uri, 1, 0, "QBarSet", | |
82 | QLatin1String("Trying to create uncreatable: QBarSet.")); |
|
82 | QLatin1String("Trying to create uncreatable: QBarSet.")); | |
83 | qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", |
|
83 | qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", | |
84 | QLatin1String("Trying to create uncreatable: AbstractItemModel.")); |
|
84 | QLatin1String("Trying to create uncreatable: AbstractItemModel.")); | |
85 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", |
|
85 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", | |
86 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); |
|
86 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); | |
87 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
87 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", | |
88 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
88 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); | |
89 | qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper", |
|
89 | qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper", | |
90 | QLatin1String("Trying to create uncreatable: BarModelMapper.")); |
|
90 | QLatin1String("Trying to create uncreatable: BarModelMapper.")); | |
91 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries", |
|
91 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries", | |
92 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); |
|
92 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); | |
93 | qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis", |
|
93 | qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis", | |
94 | QLatin1String("Trying to create uncreatable: AbstractAxis.")); |
|
94 | QLatin1String("Trying to create uncreatable: AbstractAxis.")); | |
95 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
95 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", | |
96 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
96 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); | |
97 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", |
|
97 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", | |
98 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); |
|
98 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); | |
99 | } |
|
99 | } | |
100 | }; |
|
100 | }; | |
101 |
|
101 | |||
102 | #include "plugin.moc" |
|
102 | #include "plugin.moc" | |
103 |
|
103 | |||
104 | QTCOMMERCIALCHART_END_NAMESPACE |
|
104 | QTCOMMERCIALCHART_END_NAMESPACE | |
105 |
|
105 | |||
106 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
106 | QTCOMMERCIALCHART_USE_NAMESPACE | |
107 |
|
107 | |||
108 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
|
108 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
@@ -1,77 +1,77 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTANIMATOR_P_H |
|
30 | #ifndef CHARTANIMATOR_P_H | |
31 | #define CHARTANIMATOR_P_H |
|
31 | #define CHARTANIMATOR_P_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "chartanimation_p.h" |
|
34 | #include "chartanimation_p.h" | |
35 | #include "piechartitem_p.h" |
|
35 | #include "piechartitem_p.h" | |
36 | #include "barchartitem_p.h" |
|
36 | #include "barchartitem_p.h" | |
37 | #include <QPointF> |
|
37 | #include <QPointF> | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | class ChartItem; |
|
41 | class ChartItem; | |
42 | class ChartAxis; |
|
42 | class ChartAxis; | |
43 | class AreaChartItem; |
|
43 | class AreaChartItem; | |
44 | class SplineChartItem; |
|
44 | class SplineChartItem; | |
45 | class ScatterChartItem; |
|
45 | class ScatterChartItem; | |
46 | class LineChartItem; |
|
46 | class LineChartItem; | |
47 | class XYChartItem; |
|
47 | class XYChartItem; | |
48 | class XYAnimation; |
|
48 | class XYAnimation; | |
49 |
|
49 | |||
50 | class ChartAnimator : public QObject |
|
50 | class ChartAnimator : public QObject | |
51 | { |
|
51 | { | |
52 | Q_OBJECT |
|
52 | Q_OBJECT | |
53 | public: |
|
53 | public: | |
54 | ChartAnimator(QObject *parent = 0); |
|
54 | ChartAnimator(QObject *parent = 0); | |
55 | virtual ~ChartAnimator(); |
|
55 | virtual ~ChartAnimator(); | |
56 |
|
56 | |||
57 | void addAnimation(PieChartItem *item); |
|
57 | void addAnimation(PieChartItem *item); | |
58 |
void addAnimation(BarChartItem *item); |
|
58 | void addAnimation(BarChartItem *item); | |
59 | void addAnimation(StackedBarChartItem *item); |
|
59 | void addAnimation(StackedBarChartItem *item); | |
60 | void addAnimation(PercentBarChartItem *item); |
|
60 | void addAnimation(PercentBarChartItem *item); | |
61 | void removeAnimation(Chart *item); |
|
61 | void removeAnimation(Chart *item); | |
62 |
|
62 | |||
63 | void addAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData, bool isEmpty); |
|
63 | void addAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData, bool isEmpty); | |
64 | void removeAnimation(PieChartItem *item, PieSliceItem *sliceItem); |
|
64 | void removeAnimation(PieChartItem *item, PieSliceItem *sliceItem); | |
65 | void updateAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData); |
|
65 | void updateAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData); | |
66 |
|
66 | |||
67 | void updateLayout(BarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); |
|
67 | void updateLayout(BarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); | |
68 | void updateLayout(StackedBarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); |
|
68 | void updateLayout(StackedBarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); | |
69 | void updateLayout(PercentBarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); |
|
69 | void updateLayout(PercentBarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); | |
70 |
|
70 | |||
71 | private: |
|
71 | private: | |
72 | QMap<Chart *, ChartAnimation *> m_animations; |
|
72 | QMap<Chart *, ChartAnimation *> m_animations; | |
73 | }; |
|
73 | }; | |
74 |
|
74 | |||
75 | QTCOMMERCIALCHART_END_NAMESPACE |
|
75 | QTCOMMERCIALCHART_END_NAMESPACE | |
76 |
|
76 | |||
77 | #endif |
|
77 | #endif |
@@ -1,40 +1,40 | |||||
1 | INCLUDEPATH += $$PWD |
|
1 | INCLUDEPATH += $$PWD | |
2 | DEPENDPATH += $$PWD |
|
2 | DEPENDPATH += $$PWD | |
3 |
|
3 | |||
4 | SOURCES += \ |
|
4 | SOURCES += \ | |
5 | $$PWD/bar.cpp \ |
|
5 | $$PWD/bar.cpp \ | |
6 | $$PWD/barchartitem.cpp \ |
|
6 | $$PWD/barchartitem.cpp \ | |
7 | $$PWD/percentbarchartitem.cpp \ |
|
7 | $$PWD/percentbarchartitem.cpp \ | |
8 | $$PWD/groupedbarchartitem.cpp \ |
|
8 | $$PWD/groupedbarchartitem.cpp \ | |
9 | $$PWD/qabstractbarseries.cpp \ |
|
9 | $$PWD/qabstractbarseries.cpp \ | |
10 | $$PWD/qbarset.cpp \ |
|
10 | $$PWD/qbarset.cpp \ | |
11 | $$PWD/qpercentbarseries.cpp \ |
|
11 | $$PWD/qpercentbarseries.cpp \ | |
12 | $$PWD/qstackedbarseries.cpp \ |
|
12 | $$PWD/qstackedbarseries.cpp \ | |
13 |
$$PWD/q |
|
13 | $$PWD/qbarseries.cpp \ | |
14 | $$PWD/stackedbarchartitem.cpp \ |
|
14 | $$PWD/stackedbarchartitem.cpp \ | |
15 | $$PWD/qbarmodelmapper.cpp \ |
|
15 | $$PWD/qbarmodelmapper.cpp \ | |
16 | $$PWD/qvbarmodelmapper.cpp \ |
|
16 | $$PWD/qvbarmodelmapper.cpp \ | |
17 | $$PWD/qhbarmodelmapper.cpp |
|
17 | $$PWD/qhbarmodelmapper.cpp | |
18 |
|
18 | |||
19 | PRIVATE_HEADERS += \ |
|
19 | PRIVATE_HEADERS += \ | |
20 | $$PWD/bar_p.h \ |
|
20 | $$PWD/bar_p.h \ | |
21 | $$PWD/barchartitem_p.h \ |
|
21 | $$PWD/barchartitem_p.h \ | |
22 | $$PWD/percentbarchartitem_p.h \ |
|
22 | $$PWD/percentbarchartitem_p.h \ | |
23 | $$PWD/stackedbarchartitem_p.h \ |
|
23 | $$PWD/stackedbarchartitem_p.h \ | |
24 | $$PWD/groupedbarchartitem_p.h \ |
|
24 | $$PWD/groupedbarchartitem_p.h \ | |
25 | $$PWD/qbarset_p.h \ |
|
25 | $$PWD/qbarset_p.h \ | |
26 | $$PWD/qabstractbarseries_p.h \ |
|
26 | $$PWD/qabstractbarseries_p.h \ | |
27 | $$PWD/qstackedbarseries_p.h\ |
|
27 | $$PWD/qstackedbarseries_p.h\ | |
28 | $$PWD/qpercentbarseries_p.h \ |
|
28 | $$PWD/qpercentbarseries_p.h \ | |
29 |
$$PWD/q |
|
29 | $$PWD/qbarseries_p.h \ | |
30 | $$PWD/qbarmodelmapper_p.h |
|
30 | $$PWD/qbarmodelmapper_p.h | |
31 |
|
31 | |||
32 | PUBLIC_HEADERS += \ |
|
32 | PUBLIC_HEADERS += \ | |
33 | $$PWD/qabstractbarseries.h \ |
|
33 | $$PWD/qabstractbarseries.h \ | |
34 | $$PWD/qbarset.h \ |
|
34 | $$PWD/qbarset.h \ | |
35 | $$PWD/qpercentbarseries.h \ |
|
35 | $$PWD/qpercentbarseries.h \ | |
36 | $$PWD/qstackedbarseries.h \ |
|
36 | $$PWD/qstackedbarseries.h \ | |
37 |
$$PWD/q |
|
37 | $$PWD/qbarseries.h \ | |
38 | $$PWD/qbarmodelmapper.h \ |
|
38 | $$PWD/qbarmodelmapper.h \ | |
39 | $$PWD/qvbarmodelmapper.h \ |
|
39 | $$PWD/qvbarmodelmapper.h \ | |
40 | $$PWD/qhbarmodelmapper.h |
|
40 | $$PWD/qhbarmodelmapper.h |
@@ -1,735 +1,735 | |||||
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 "qabstractbarseries.h" |
|
21 | #include "qabstractbarseries.h" | |
22 | #include "qabstractbarseries_p.h" |
|
22 | #include "qabstractbarseries_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "legendmarker_p.h" |
|
26 | #include "legendmarker_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
30 | #include "qvaluesaxis.h" |
|
30 | #include "qvaluesaxis.h" | |
31 | #include "qcategoriesaxis.h" |
|
31 | #include "qcategoriesaxis.h" | |
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 | /*! |
|
35 | /*! | |
36 | \class QAbstractBarSeries |
|
36 | \class QAbstractBarSeries | |
37 | \brief Series for creating a bar chart |
|
37 | \brief Series for creating a bar chart | |
38 | \mainclass |
|
38 | \mainclass | |
39 |
|
39 | |||
40 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
40 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to | |
41 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
41 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar | |
42 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
42 | and y-value is the height of the bar. The category names are ignored with this series and x-axis | |
43 | shows the x-values. |
|
43 | shows the x-values. | |
44 |
|
44 | |||
45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
46 | \image examples_barchart.png |
|
46 | \image examples_barchart.png | |
47 |
|
47 | |||
48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
49 | */ |
|
49 | */ | |
50 | /*! |
|
50 | /*! | |
51 | \qmlclass AbstractBarSeries QAbstractBarSeries |
|
51 | \qmlclass AbstractBarSeries QAbstractBarSeries | |
52 | \inherits QAbstractSeries |
|
52 | \inherits QAbstractSeries | |
53 |
|
53 | |||
54 | The following QML shows how to create a simple bar chart: |
|
54 | The following QML shows how to create a simple bar chart: | |
55 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
55 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
56 |
|
56 | |||
57 | \beginfloatleft |
|
57 | \beginfloatleft | |
58 | \image demos_qmlchart6.png |
|
58 | \image demos_qmlchart6.png | |
59 | \endfloat |
|
59 | \endfloat | |
60 | \clearfloat |
|
60 | \clearfloat | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \property QAbstractBarSeries::barWidth |
|
64 | \property QAbstractBarSeries::barWidth | |
65 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
65 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
66 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
66 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
67 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
67 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
68 |
Note that with Q |
|
68 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
69 |
\sa Q |
|
69 | \sa QBarSeries | |
70 | */ |
|
70 | */ | |
71 | /*! |
|
71 | /*! | |
72 | \qmlproperty real AbstractBarSeries::barWidth |
|
72 | \qmlproperty real AbstractBarSeries::barWidth | |
73 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
73 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars | |
74 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
74 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
75 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
75 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
76 |
Note that with Q |
|
76 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
77 | */ |
|
77 | */ | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | \property QAbstractBarSeries::count |
|
80 | \property QAbstractBarSeries::count | |
81 | Holds the number of sets in series. |
|
81 | Holds the number of sets in series. | |
82 | */ |
|
82 | */ | |
83 | /*! |
|
83 | /*! | |
84 | \qmlproperty int AbstractBarSeries::count |
|
84 | \qmlproperty int AbstractBarSeries::count | |
85 | Holds the number of sets in series. |
|
85 | Holds the number of sets in series. | |
86 | */ |
|
86 | */ | |
87 |
|
87 | |||
88 | /*! |
|
88 | /*! | |
89 | \property QAbstractBarSeries::labelsVisible |
|
89 | \property QAbstractBarSeries::labelsVisible | |
90 | Defines the visibility of the labels in series |
|
90 | Defines the visibility of the labels in series | |
91 | */ |
|
91 | */ | |
92 | /*! |
|
92 | /*! | |
93 | \qmlproperty bool AbstractBarSeries::labelsVisible |
|
93 | \qmlproperty bool AbstractBarSeries::labelsVisible | |
94 | Defines the visibility of the labels in series |
|
94 | Defines the visibility of the labels in series | |
95 | */ |
|
95 | */ | |
96 |
|
96 | |||
97 | /*! |
|
97 | /*! | |
98 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) |
|
98 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) | |
99 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
99 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. | |
100 | Clicked bar inside set is indexed by \a index |
|
100 | Clicked bar inside set is indexed by \a index | |
101 | */ |
|
101 | */ | |
102 | /*! |
|
102 | /*! | |
103 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) |
|
103 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) | |
104 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
104 | The signal is emitted if the user clicks with a mouse on top of BarSet. | |
105 | Clicked bar inside set is indexed by \a index |
|
105 | Clicked bar inside set is indexed by \a index | |
106 | */ |
|
106 | */ | |
107 |
|
107 | |||
108 | /*! |
|
108 | /*! | |
109 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) |
|
109 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) | |
110 |
|
110 | |||
111 | The signal is emitted if mouse is hovered on top of series. |
|
111 | The signal is emitted if mouse is hovered on top of series. | |
112 | Parameter \a barset is the pointer of barset, where hover happened. |
|
112 | Parameter \a barset is the pointer of barset, where hover happened. | |
113 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
113 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
114 | */ |
|
114 | */ | |
115 | /*! |
|
115 | /*! | |
116 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) |
|
116 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) | |
117 |
|
117 | |||
118 | The signal is emitted if mouse is hovered on top of series. |
|
118 | The signal is emitted if mouse is hovered on top of series. | |
119 | Parameter \a barset is the pointer of barset, where hover happened. |
|
119 | Parameter \a barset is the pointer of barset, where hover happened. | |
120 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
120 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
121 | */ |
|
121 | */ | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | \fn void QAbstractBarSeries::countChanged() |
|
124 | \fn void QAbstractBarSeries::countChanged() | |
125 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
125 | This signal is emitted when barset count has been changed, for example by append or remove. | |
126 | */ |
|
126 | */ | |
127 | /*! |
|
127 | /*! | |
128 | \qmlsignal AbstractBarSeries::onCountChanged() |
|
128 | \qmlsignal AbstractBarSeries::onCountChanged() | |
129 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
129 | This signal is emitted when barset count has been changed, for example by append or remove. | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \fn void QAbstractBarSeries::labelsVisibleChanged() |
|
133 | \fn void QAbstractBarSeries::labelsVisibleChanged() | |
134 | This signal is emitted when labels visibility have changed. |
|
134 | This signal is emitted when labels visibility have changed. | |
135 | \sa isLabelsVisible(), setLabelsVisible() |
|
135 | \sa isLabelsVisible(), setLabelsVisible() | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
139 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) | |
140 | This signal is emitted when \a sets have been added to the series. |
|
140 | This signal is emitted when \a sets have been added to the series. | |
141 | \sa append(), insert() |
|
141 | \sa append(), insert() | |
142 | */ |
|
142 | */ | |
143 | /*! |
|
143 | /*! | |
144 | \qmlsignal AbstractBarSeries::onAdded(BarSet barset) |
|
144 | \qmlsignal AbstractBarSeries::onAdded(BarSet barset) | |
145 | Emitted when \a barset has been added to the series. |
|
145 | Emitted when \a barset has been added to the series. | |
146 | */ |
|
146 | */ | |
147 |
|
147 | |||
148 | /*! |
|
148 | /*! | |
149 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
149 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) | |
150 | This signal is emitted when \a sets have been removed from the series. |
|
150 | This signal is emitted when \a sets have been removed from the series. | |
151 | \sa remove() |
|
151 | \sa remove() | |
152 | */ |
|
152 | */ | |
153 | /*! |
|
153 | /*! | |
154 | \qmlsignal AbstractBarSeries::onRemoved(BarSet barset) |
|
154 | \qmlsignal AbstractBarSeries::onRemoved(BarSet barset) | |
155 | Emitted when \a barset has been removed from the series. |
|
155 | Emitted when \a barset has been removed from the series. | |
156 | */ |
|
156 | */ | |
157 |
|
157 | |||
158 | /*! |
|
158 | /*! | |
159 | \qmlmethod BarSet AbstractBarSeries::at(int index) |
|
159 | \qmlmethod BarSet AbstractBarSeries::at(int index) | |
160 | Returns bar set at \a index. Returns null if the index is not valid. |
|
160 | Returns bar set at \a index. Returns null if the index is not valid. | |
161 | */ |
|
161 | */ | |
162 |
|
162 | |||
163 | /*! |
|
163 | /*! | |
164 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) |
|
164 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) | |
165 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
165 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. | |
166 | For example: |
|
166 | For example: | |
167 | \code |
|
167 | \code | |
168 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
168 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); | |
169 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); |
|
169 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); | |
170 | \endcode |
|
170 | \endcode | |
171 | */ |
|
171 | */ | |
172 |
|
172 | |||
173 | /*! |
|
173 | /*! | |
174 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) |
|
174 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) | |
175 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
175 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. | |
176 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
176 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is | |
177 | appended. |
|
177 | appended. | |
178 | \sa AbstractBarSeries::append() |
|
178 | \sa AbstractBarSeries::append() | |
179 | */ |
|
179 | */ | |
180 |
|
180 | |||
181 | /*! |
|
181 | /*! | |
182 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) |
|
182 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) | |
183 | Removes the barset from the series. Returns true if successfull, false otherwise. |
|
183 | Removes the barset from the series. Returns true if successfull, false otherwise. | |
184 | */ |
|
184 | */ | |
185 |
|
185 | |||
186 | /*! |
|
186 | /*! | |
187 | \qmlmethod AbstractBarSeries::clear() |
|
187 | \qmlmethod AbstractBarSeries::clear() | |
188 | Removes all barsets from the series. |
|
188 | Removes all barsets from the series. | |
189 | */ |
|
189 | */ | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | Constructs empty QAbstractBarSeries. |
|
192 | Constructs empty QAbstractBarSeries. | |
193 | QAbstractBarSeries is QObject which is a child of a \a parent. |
|
193 | QAbstractBarSeries is QObject which is a child of a \a parent. | |
194 | */ |
|
194 | */ | |
195 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : |
|
195 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : | |
196 | QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent) |
|
196 | QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent) | |
197 | { |
|
197 | { | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | /*! |
|
200 | /*! | |
201 | Destructs abstractbarseries and owned barsets. |
|
201 | Destructs abstractbarseries and owned barsets. | |
202 | */ |
|
202 | */ | |
203 | QAbstractBarSeries::~QAbstractBarSeries() |
|
203 | QAbstractBarSeries::~QAbstractBarSeries() | |
204 | { |
|
204 | { | |
205 | Q_D(QAbstractBarSeries); |
|
205 | Q_D(QAbstractBarSeries); | |
206 | if(d->m_dataset){ |
|
206 | if(d->m_dataset){ | |
207 | d->m_dataset->removeSeries(this); |
|
207 | d->m_dataset->removeSeries(this); | |
208 | } |
|
208 | } | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | /*! |
|
211 | /*! | |
212 | \internal |
|
212 | \internal | |
213 | */ |
|
213 | */ | |
214 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : |
|
214 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : | |
215 | QAbstractSeries(d,parent) |
|
215 | QAbstractSeries(d,parent) | |
216 | { |
|
216 | { | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | /*! |
|
219 | /*! | |
220 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
220 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
221 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
221 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
222 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
222 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
223 |
Note that with \link Q |
|
223 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. | |
224 | */ |
|
224 | */ | |
225 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
225 | void QAbstractBarSeries::setBarWidth(qreal width) | |
226 | { |
|
226 | { | |
227 | Q_D(QAbstractBarSeries); |
|
227 | Q_D(QAbstractBarSeries); | |
228 | d->setBarWidth(width); |
|
228 | d->setBarWidth(width); | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | /*! |
|
231 | /*! | |
232 | Returns the width of the bars of the series. |
|
232 | Returns the width of the bars of the series. | |
233 | \sa setBarWidth() |
|
233 | \sa setBarWidth() | |
234 | */ |
|
234 | */ | |
235 | qreal QAbstractBarSeries::barWidth() const |
|
235 | qreal QAbstractBarSeries::barWidth() const | |
236 | { |
|
236 | { | |
237 | Q_D(const QAbstractBarSeries); |
|
237 | Q_D(const QAbstractBarSeries); | |
238 | return d->barWidth(); |
|
238 | return d->barWidth(); | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | /*! |
|
241 | /*! | |
242 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
242 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
243 | Returns true, if appending succeeded. |
|
243 | Returns true, if appending succeeded. | |
244 | */ |
|
244 | */ | |
245 | bool QAbstractBarSeries::append(QBarSet *set) |
|
245 | bool QAbstractBarSeries::append(QBarSet *set) | |
246 | { |
|
246 | { | |
247 | Q_D(QAbstractBarSeries); |
|
247 | Q_D(QAbstractBarSeries); | |
248 | bool success = d->append(set); |
|
248 | bool success = d->append(set); | |
249 | if (success) { |
|
249 | if (success) { | |
250 | QList<QBarSet*> sets; |
|
250 | QList<QBarSet*> sets; | |
251 | sets.append(set); |
|
251 | sets.append(set); | |
252 | emit barsetsAdded(sets); |
|
252 | emit barsetsAdded(sets); | |
253 | emit countChanged(); |
|
253 | emit countChanged(); | |
254 | } |
|
254 | } | |
255 | return success; |
|
255 | return success; | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | /*! |
|
258 | /*! | |
259 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
259 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
260 | Returns true, if set was removed. |
|
260 | Returns true, if set was removed. | |
261 | */ |
|
261 | */ | |
262 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
262 | bool QAbstractBarSeries::remove(QBarSet *set) | |
263 | { |
|
263 | { | |
264 | Q_D(QAbstractBarSeries); |
|
264 | Q_D(QAbstractBarSeries); | |
265 | bool success = d->remove(set); |
|
265 | bool success = d->remove(set); | |
266 | if (success) { |
|
266 | if (success) { | |
267 | QList<QBarSet*> sets; |
|
267 | QList<QBarSet*> sets; | |
268 | sets.append(set); |
|
268 | sets.append(set); | |
269 | emit barsetsRemoved(sets); |
|
269 | emit barsetsRemoved(sets); | |
270 | emit countChanged(); |
|
270 | emit countChanged(); | |
271 | } |
|
271 | } | |
272 | return success; |
|
272 | return success; | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | /*! |
|
275 | /*! | |
276 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
276 | Adds a list of barsets to series. Takes ownership of \a sets. | |
277 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
277 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |
278 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
278 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
279 | and function returns false. |
|
279 | and function returns false. | |
280 | */ |
|
280 | */ | |
281 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) |
|
281 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) | |
282 | { |
|
282 | { | |
283 | Q_D(QAbstractBarSeries); |
|
283 | Q_D(QAbstractBarSeries); | |
284 | bool success = d->append(sets); |
|
284 | bool success = d->append(sets); | |
285 | if (success) { |
|
285 | if (success) { | |
286 | emit barsetsAdded(sets); |
|
286 | emit barsetsAdded(sets); | |
287 | emit countChanged(); |
|
287 | emit countChanged(); | |
288 | } |
|
288 | } | |
289 | return success; |
|
289 | return success; | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | /*! |
|
292 | /*! | |
293 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
293 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
294 | Returns true, if inserting succeeded. |
|
294 | Returns true, if inserting succeeded. | |
295 |
|
295 | |||
296 | */ |
|
296 | */ | |
297 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
297 | bool QAbstractBarSeries::insert(int index, QBarSet *set) | |
298 | { |
|
298 | { | |
299 | Q_D(QAbstractBarSeries); |
|
299 | Q_D(QAbstractBarSeries); | |
300 | bool success = d->insert(index, set); |
|
300 | bool success = d->insert(index, set); | |
301 | if (success) { |
|
301 | if (success) { | |
302 | QList<QBarSet*> sets; |
|
302 | QList<QBarSet*> sets; | |
303 | sets.append(set); |
|
303 | sets.append(set); | |
304 | emit barsetsAdded(sets); |
|
304 | emit barsetsAdded(sets); | |
305 | emit countChanged(); |
|
305 | emit countChanged(); | |
306 | } |
|
306 | } | |
307 | return success; |
|
307 | return success; | |
308 | } |
|
308 | } | |
309 |
|
309 | |||
310 | /*! |
|
310 | /*! | |
311 | Removes all of the bar sets from the series |
|
311 | Removes all of the bar sets from the series | |
312 | */ |
|
312 | */ | |
313 | void QAbstractBarSeries::clear() |
|
313 | void QAbstractBarSeries::clear() | |
314 | { |
|
314 | { | |
315 | Q_D(QAbstractBarSeries); |
|
315 | Q_D(QAbstractBarSeries); | |
316 | QList<QBarSet *> sets = barSets(); |
|
316 | QList<QBarSet *> sets = barSets(); | |
317 | bool success = d->remove(sets); |
|
317 | bool success = d->remove(sets); | |
318 | if (success) { |
|
318 | if (success) { | |
319 | emit barsetsRemoved(sets); |
|
319 | emit barsetsRemoved(sets); | |
320 | emit countChanged(); |
|
320 | emit countChanged(); | |
321 | } |
|
321 | } | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | /*! |
|
324 | /*! | |
325 | Returns number of sets in series. |
|
325 | Returns number of sets in series. | |
326 | */ |
|
326 | */ | |
327 | int QAbstractBarSeries::count() const |
|
327 | int QAbstractBarSeries::count() const | |
328 | { |
|
328 | { | |
329 | Q_D(const QAbstractBarSeries); |
|
329 | Q_D(const QAbstractBarSeries); | |
330 | return d->m_barSets.count(); |
|
330 | return d->m_barSets.count(); | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 | /*! |
|
333 | /*! | |
334 | Returns a list of sets in series. Keeps ownership of sets. |
|
334 | Returns a list of sets in series. Keeps ownership of sets. | |
335 | */ |
|
335 | */ | |
336 | QList<QBarSet*> QAbstractBarSeries::barSets() const |
|
336 | QList<QBarSet*> QAbstractBarSeries::barSets() const | |
337 | { |
|
337 | { | |
338 | Q_D(const QAbstractBarSeries); |
|
338 | Q_D(const QAbstractBarSeries); | |
339 | return d->m_barSets; |
|
339 | return d->m_barSets; | |
340 | } |
|
340 | } | |
341 |
|
341 | |||
342 | /*! |
|
342 | /*! | |
343 | Sets the visibility of labels in series to \a visible |
|
343 | Sets the visibility of labels in series to \a visible | |
344 | */ |
|
344 | */ | |
345 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
345 | void QAbstractBarSeries::setLabelsVisible(bool visible) | |
346 | { |
|
346 | { | |
347 | Q_D(QAbstractBarSeries); |
|
347 | Q_D(QAbstractBarSeries); | |
348 | if (d->m_labelsVisible != visible) { |
|
348 | if (d->m_labelsVisible != visible) { | |
349 | d->setLabelsVisible(visible); |
|
349 | d->setLabelsVisible(visible); | |
350 | emit labelsVisibleChanged(); |
|
350 | emit labelsVisibleChanged(); | |
351 | } |
|
351 | } | |
352 | } |
|
352 | } | |
353 |
|
353 | |||
354 | /*! |
|
354 | /*! | |
355 | Returns the visibility of labels |
|
355 | Returns the visibility of labels | |
356 | */ |
|
356 | */ | |
357 | bool QAbstractBarSeries::isLabelsVisible() const |
|
357 | bool QAbstractBarSeries::isLabelsVisible() const | |
358 | { |
|
358 | { | |
359 | Q_D(const QAbstractBarSeries); |
|
359 | Q_D(const QAbstractBarSeries); | |
360 | return d->m_labelsVisible; |
|
360 | return d->m_labelsVisible; | |
361 | } |
|
361 | } | |
362 |
|
362 | |||
363 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
363 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
364 |
|
364 | |||
365 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
365 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : | |
366 | QAbstractSeriesPrivate(q), |
|
366 | QAbstractSeriesPrivate(q), | |
367 | m_barWidth(0.5), // Default value is 50% of category width |
|
367 | m_barWidth(0.5), // Default value is 50% of category width | |
368 | m_labelsVisible(false), |
|
368 | m_labelsVisible(false), | |
369 | m_visible(true) |
|
369 | m_visible(true) | |
370 | { |
|
370 | { | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
373 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
373 | int QAbstractBarSeriesPrivate::categoryCount() const | |
374 | { |
|
374 | { | |
375 | // No categories defined. return count of longest set. |
|
375 | // No categories defined. return count of longest set. | |
376 | int count = 0; |
|
376 | int count = 0; | |
377 | for (int i=0; i<m_barSets.count(); i++) { |
|
377 | for (int i=0; i<m_barSets.count(); i++) { | |
378 | if (m_barSets.at(i)->count() > count) { |
|
378 | if (m_barSets.at(i)->count() > count) { | |
379 | count = m_barSets.at(i)->count(); |
|
379 | count = m_barSets.at(i)->count(); | |
380 | } |
|
380 | } | |
381 | } |
|
381 | } | |
382 |
|
382 | |||
383 | return count; |
|
383 | return count; | |
384 | } |
|
384 | } | |
385 |
|
385 | |||
386 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
386 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) | |
387 | { |
|
387 | { | |
388 | if (width < 0.0) { |
|
388 | if (width < 0.0) { | |
389 | width = 0.0; |
|
389 | width = 0.0; | |
390 | } |
|
390 | } | |
391 | m_barWidth = width; |
|
391 | m_barWidth = width; | |
392 | emit updatedBars(); |
|
392 | emit updatedBars(); | |
393 | } |
|
393 | } | |
394 |
|
394 | |||
395 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
395 | qreal QAbstractBarSeriesPrivate::barWidth() const | |
396 | { |
|
396 | { | |
397 | return m_barWidth; |
|
397 | return m_barWidth; | |
398 | } |
|
398 | } | |
399 |
|
399 | |||
400 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) |
|
400 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) | |
401 | { |
|
401 | { | |
402 | return m_barSets.at(index); |
|
402 | return m_barSets.at(index); | |
403 | } |
|
403 | } | |
404 |
|
404 | |||
405 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
405 | void QAbstractBarSeriesPrivate::setVisible(bool visible) | |
406 | { |
|
406 | { | |
407 | m_visible = visible; |
|
407 | m_visible = visible; | |
408 | emit updatedBars(); |
|
408 | emit updatedBars(); | |
409 | } |
|
409 | } | |
410 |
|
410 | |||
411 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
411 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) | |
412 | { |
|
412 | { | |
413 | m_labelsVisible = visible; |
|
413 | m_labelsVisible = visible; | |
414 | emit labelsVisibleChanged(visible); |
|
414 | emit labelsVisibleChanged(visible); | |
415 | } |
|
415 | } | |
416 |
|
416 | |||
417 | qreal QAbstractBarSeriesPrivate::min() |
|
417 | qreal QAbstractBarSeriesPrivate::min() | |
418 | { |
|
418 | { | |
419 | if (m_barSets.count() <= 0) { |
|
419 | if (m_barSets.count() <= 0) { | |
420 | return 0; |
|
420 | return 0; | |
421 | } |
|
421 | } | |
422 | qreal min = INT_MAX; |
|
422 | qreal min = INT_MAX; | |
423 |
|
423 | |||
424 | for (int i = 0; i < m_barSets.count(); i++) { |
|
424 | for (int i = 0; i < m_barSets.count(); i++) { | |
425 | int categoryCount = m_barSets.at(i)->count(); |
|
425 | int categoryCount = m_barSets.at(i)->count(); | |
426 | for (int j = 0; j < categoryCount; j++) { |
|
426 | for (int j = 0; j < categoryCount; j++) { | |
427 | qreal temp = m_barSets.at(i)->at(j); |
|
427 | qreal temp = m_barSets.at(i)->at(j); | |
428 | if (temp < min) |
|
428 | if (temp < min) | |
429 | min = temp; |
|
429 | min = temp; | |
430 | } |
|
430 | } | |
431 | } |
|
431 | } | |
432 | return min; |
|
432 | return min; | |
433 | } |
|
433 | } | |
434 |
|
434 | |||
435 | qreal QAbstractBarSeriesPrivate::max() |
|
435 | qreal QAbstractBarSeriesPrivate::max() | |
436 | { |
|
436 | { | |
437 | if (m_barSets.count() <= 0) { |
|
437 | if (m_barSets.count() <= 0) { | |
438 | return 0; |
|
438 | return 0; | |
439 | } |
|
439 | } | |
440 | qreal max = INT_MIN; |
|
440 | qreal max = INT_MIN; | |
441 |
|
441 | |||
442 | for (int i = 0; i < m_barSets.count(); i++) { |
|
442 | for (int i = 0; i < m_barSets.count(); i++) { | |
443 | int categoryCount = m_barSets.at(i)->count(); |
|
443 | int categoryCount = m_barSets.at(i)->count(); | |
444 | for (int j = 0; j < categoryCount; j++) { |
|
444 | for (int j = 0; j < categoryCount; j++) { | |
445 | qreal temp = m_barSets.at(i)->at(j); |
|
445 | qreal temp = m_barSets.at(i)->at(j); | |
446 | if (temp > max) |
|
446 | if (temp > max) | |
447 | max = temp; |
|
447 | max = temp; | |
448 | } |
|
448 | } | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | return max; |
|
451 | return max; | |
452 | } |
|
452 | } | |
453 |
|
453 | |||
454 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
454 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) | |
455 | { |
|
455 | { | |
456 | if ((set < 0) || (set >= m_barSets.count())) { |
|
456 | if ((set < 0) || (set >= m_barSets.count())) { | |
457 | // No set, no value. |
|
457 | // No set, no value. | |
458 | return 0; |
|
458 | return 0; | |
459 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
459 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
460 | // No category, no value. |
|
460 | // No category, no value. | |
461 | return 0; |
|
461 | return 0; | |
462 | } |
|
462 | } | |
463 |
|
463 | |||
464 | return m_barSets.at(set)->at(category); |
|
464 | return m_barSets.at(set)->at(category); | |
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
467 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) | |
468 | { |
|
468 | { | |
469 | if ((set < 0) || (set >= m_barSets.count())) { |
|
469 | if ((set < 0) || (set >= m_barSets.count())) { | |
470 | // No set, no value. |
|
470 | // No set, no value. | |
471 | return 0; |
|
471 | return 0; | |
472 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
472 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
473 | // No category, no value. |
|
473 | // No category, no value. | |
474 | return 0; |
|
474 | return 0; | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | qreal value = m_barSets.at(set)->at(category); |
|
477 | qreal value = m_barSets.at(set)->at(category); | |
478 | qreal sum = categorySum(category); |
|
478 | qreal sum = categorySum(category); | |
479 | if ( qFuzzyIsNull(sum) ) { |
|
479 | if ( qFuzzyIsNull(sum) ) { | |
480 | return 0; |
|
480 | return 0; | |
481 | } |
|
481 | } | |
482 |
|
482 | |||
483 | return value / sum; |
|
483 | return value / sum; | |
484 | } |
|
484 | } | |
485 |
|
485 | |||
486 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
486 | qreal QAbstractBarSeriesPrivate::categorySum(int category) | |
487 | { |
|
487 | { | |
488 | qreal sum(0); |
|
488 | qreal sum(0); | |
489 | int count = m_barSets.count(); // Count sets |
|
489 | int count = m_barSets.count(); // Count sets | |
490 | for (int set = 0; set < count; set++) { |
|
490 | for (int set = 0; set < count; set++) { | |
491 | if (category < m_barSets.at(set)->count()) |
|
491 | if (category < m_barSets.at(set)->count()) | |
492 | sum += m_barSets.at(set)->at(category); |
|
492 | sum += m_barSets.at(set)->at(category); | |
493 | } |
|
493 | } | |
494 | return sum; |
|
494 | return sum; | |
495 | } |
|
495 | } | |
496 |
|
496 | |||
497 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
497 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) | |
498 | { |
|
498 | { | |
499 | qreal sum(0); |
|
499 | qreal sum(0); | |
500 | int count = m_barSets.count(); // Count sets |
|
500 | int count = m_barSets.count(); // Count sets | |
501 | for (int set = 0; set < count; set++) { |
|
501 | for (int set = 0; set < count; set++) { | |
502 | if (category < m_barSets.at(set)->count()) |
|
502 | if (category < m_barSets.at(set)->count()) | |
503 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
503 | sum += qAbs(m_barSets.at(set)->at(category)); | |
504 | } |
|
504 | } | |
505 | return sum; |
|
505 | return sum; | |
506 | } |
|
506 | } | |
507 |
|
507 | |||
508 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
508 | qreal QAbstractBarSeriesPrivate::maxCategorySum() | |
509 | { |
|
509 | { | |
510 | qreal max = INT_MIN; |
|
510 | qreal max = INT_MIN; | |
511 | int count = categoryCount(); |
|
511 | int count = categoryCount(); | |
512 | for (int i = 0; i < count; i++) { |
|
512 | for (int i = 0; i < count; i++) { | |
513 | qreal sum = categorySum(i); |
|
513 | qreal sum = categorySum(i); | |
514 | if (sum > max) |
|
514 | if (sum > max) | |
515 | max = sum; |
|
515 | max = sum; | |
516 | } |
|
516 | } | |
517 | return max; |
|
517 | return max; | |
518 | } |
|
518 | } | |
519 |
|
519 | |||
520 | qreal QAbstractBarSeriesPrivate::minX() |
|
520 | qreal QAbstractBarSeriesPrivate::minX() | |
521 | { |
|
521 | { | |
522 | if (m_barSets.count() <= 0) { |
|
522 | if (m_barSets.count() <= 0) { | |
523 | return 0; |
|
523 | return 0; | |
524 | } |
|
524 | } | |
525 | qreal min = INT_MAX; |
|
525 | qreal min = INT_MAX; | |
526 |
|
526 | |||
527 | for (int i = 0; i < m_barSets.count(); i++) { |
|
527 | for (int i = 0; i < m_barSets.count(); i++) { | |
528 | int categoryCount = m_barSets.at(i)->count(); |
|
528 | int categoryCount = m_barSets.at(i)->count(); | |
529 | for (int j = 0; j < categoryCount; j++) { |
|
529 | for (int j = 0; j < categoryCount; j++) { | |
530 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
530 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
531 | if (temp < min) |
|
531 | if (temp < min) | |
532 | min = temp; |
|
532 | min = temp; | |
533 | } |
|
533 | } | |
534 | } |
|
534 | } | |
535 | return min; |
|
535 | return min; | |
536 | } |
|
536 | } | |
537 |
|
537 | |||
538 | qreal QAbstractBarSeriesPrivate::maxX() |
|
538 | qreal QAbstractBarSeriesPrivate::maxX() | |
539 | { |
|
539 | { | |
540 | if (m_barSets.count() <= 0) { |
|
540 | if (m_barSets.count() <= 0) { | |
541 | return 0; |
|
541 | return 0; | |
542 | } |
|
542 | } | |
543 | qreal max = INT_MIN; |
|
543 | qreal max = INT_MIN; | |
544 |
|
544 | |||
545 | for (int i = 0; i < m_barSets.count(); i++) { |
|
545 | for (int i = 0; i < m_barSets.count(); i++) { | |
546 | int categoryCount = m_barSets.at(i)->count(); |
|
546 | int categoryCount = m_barSets.at(i)->count(); | |
547 | for (int j = 0; j < categoryCount; j++) { |
|
547 | for (int j = 0; j < categoryCount; j++) { | |
548 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
548 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
549 | if (temp > max) |
|
549 | if (temp > max) | |
550 | max = temp; |
|
550 | max = temp; | |
551 | } |
|
551 | } | |
552 | } |
|
552 | } | |
553 |
|
553 | |||
554 | return max; |
|
554 | return max; | |
555 | } |
|
555 | } | |
556 |
|
556 | |||
557 |
|
557 | |||
558 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) |
|
558 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) | |
559 | { |
|
559 | { | |
560 | qreal minX(domain.minX()); |
|
560 | qreal minX(domain.minX()); | |
561 | qreal minY(domain.minY()); |
|
561 | qreal minY(domain.minY()); | |
562 | qreal maxX(domain.maxX()); |
|
562 | qreal maxX(domain.maxX()); | |
563 | qreal maxY(domain.maxY()); |
|
563 | qreal maxY(domain.maxY()); | |
564 | int tickXCount(domain.tickXCount()); |
|
564 | int tickXCount(domain.tickXCount()); | |
565 | int tickYCount(domain.tickYCount()); |
|
565 | int tickYCount(domain.tickYCount()); | |
566 |
|
566 | |||
567 | qreal seriesMinX = this->minX(); |
|
567 | qreal seriesMinX = this->minX(); | |
568 | qreal seriesMaxX = this->maxX(); |
|
568 | qreal seriesMaxX = this->maxX(); | |
569 | qreal y = max(); |
|
569 | qreal y = max(); | |
570 | minX = qMin(minX, seriesMinX - 0.5); |
|
570 | minX = qMin(minX, seriesMinX - 0.5); | |
571 | minY = qMin(minY, y); |
|
571 | minY = qMin(minY, y); | |
572 | maxX = qMax(maxX, seriesMaxX + 0.5); |
|
572 | maxX = qMax(maxX, seriesMaxX + 0.5); | |
573 | maxY = qMax(maxY, y); |
|
573 | maxY = qMax(maxY, y); | |
574 | tickXCount = categoryCount()+1; |
|
574 | tickXCount = categoryCount()+1; | |
575 |
|
575 | |||
576 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
576 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
577 | } |
|
577 | } | |
578 |
|
578 | |||
579 | Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
579 | Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
580 | { |
|
580 | { | |
581 | Q_Q(QAbstractBarSeries); |
|
581 | Q_Q(QAbstractBarSeries); | |
582 |
|
582 | |||
583 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
583 | BarChartItem* bar = new BarChartItem(q,presenter); | |
584 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
584 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
585 | presenter->animator()->addAnimation(bar); |
|
585 | presenter->animator()->addAnimation(bar); | |
586 | } |
|
586 | } | |
587 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
587 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
588 | return bar; |
|
588 | return bar; | |
589 |
|
589 | |||
590 | } |
|
590 | } | |
591 |
|
591 | |||
592 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
592 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
593 | { |
|
593 | { | |
594 | Q_Q(QAbstractBarSeries); |
|
594 | Q_Q(QAbstractBarSeries); | |
595 | QList<LegendMarker*> markers; |
|
595 | QList<LegendMarker*> markers; | |
596 | foreach(QBarSet* set, q->barSets()) { |
|
596 | foreach(QBarSet* set, q->barSets()) { | |
597 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
597 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
598 | markers << marker; |
|
598 | markers << marker; | |
599 | } |
|
599 | } | |
600 |
|
600 | |||
601 | return markers; |
|
601 | return markers; | |
602 | } |
|
602 | } | |
603 |
|
603 | |||
604 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
604 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) | |
605 | { |
|
605 | { | |
606 | Q_Q(QAbstractBarSeries); |
|
606 | Q_Q(QAbstractBarSeries); | |
607 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
607 | if ((m_barSets.contains(set)) || (set == 0)) { | |
608 | // Fail if set is already in list or set is null. |
|
608 | // Fail if set is already in list or set is null. | |
609 | return false; |
|
609 | return false; | |
610 | } |
|
610 | } | |
611 | m_barSets.append(set); |
|
611 | m_barSets.append(set); | |
612 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
612 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
613 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
613 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
614 | emit restructuredBars(); // this notifies barchartitem |
|
614 | emit restructuredBars(); // this notifies barchartitem | |
615 | if (m_dataset) { |
|
615 | if (m_dataset) { | |
616 | m_dataset->updateSeries(q); // this notifies legend |
|
616 | m_dataset->updateSeries(q); // this notifies legend | |
617 | } |
|
617 | } | |
618 | return true; |
|
618 | return true; | |
619 | } |
|
619 | } | |
620 |
|
620 | |||
621 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
621 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) | |
622 | { |
|
622 | { | |
623 | Q_Q(QAbstractBarSeries); |
|
623 | Q_Q(QAbstractBarSeries); | |
624 | if (!m_barSets.contains(set)) { |
|
624 | if (!m_barSets.contains(set)) { | |
625 | // Fail if set is not in list |
|
625 | // Fail if set is not in list | |
626 | return false; |
|
626 | return false; | |
627 | } |
|
627 | } | |
628 | m_barSets.removeOne(set); |
|
628 | m_barSets.removeOne(set); | |
629 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
629 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
630 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
630 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
631 | emit restructuredBars(); // this notifies barchartitem |
|
631 | emit restructuredBars(); // this notifies barchartitem | |
632 | if (m_dataset) { |
|
632 | if (m_dataset) { | |
633 | m_dataset->updateSeries(q); // this notifies legend |
|
633 | m_dataset->updateSeries(q); // this notifies legend | |
634 | } |
|
634 | } | |
635 | return true; |
|
635 | return true; | |
636 | } |
|
636 | } | |
637 |
|
637 | |||
638 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
638 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) | |
639 | { |
|
639 | { | |
640 | Q_Q(QAbstractBarSeries); |
|
640 | Q_Q(QAbstractBarSeries); | |
641 | foreach (QBarSet* set, sets) { |
|
641 | foreach (QBarSet* set, sets) { | |
642 | if ((set == 0) || (m_barSets.contains(set))) { |
|
642 | if ((set == 0) || (m_barSets.contains(set))) { | |
643 | // Fail if any of the sets is null or is already appended. |
|
643 | // Fail if any of the sets is null or is already appended. | |
644 | return false; |
|
644 | return false; | |
645 | } |
|
645 | } | |
646 | if (sets.count(set) != 1) { |
|
646 | if (sets.count(set) != 1) { | |
647 | // Also fail if same set is more than once in given list. |
|
647 | // Also fail if same set is more than once in given list. | |
648 | return false; |
|
648 | return false; | |
649 | } |
|
649 | } | |
650 | } |
|
650 | } | |
651 |
|
651 | |||
652 | foreach (QBarSet* set, sets) { |
|
652 | foreach (QBarSet* set, sets) { | |
653 | m_barSets.append(set); |
|
653 | m_barSets.append(set); | |
654 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
654 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
655 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
655 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
656 | } |
|
656 | } | |
657 | emit restructuredBars(); // this notifies barchartitem |
|
657 | emit restructuredBars(); // this notifies barchartitem | |
658 | if (m_dataset) { |
|
658 | if (m_dataset) { | |
659 | m_dataset->updateSeries(q); // this notifies legend |
|
659 | m_dataset->updateSeries(q); // this notifies legend | |
660 | } |
|
660 | } | |
661 | return true; |
|
661 | return true; | |
662 | } |
|
662 | } | |
663 |
|
663 | |||
664 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
664 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) | |
665 | { |
|
665 | { | |
666 | Q_Q(QAbstractBarSeries); |
|
666 | Q_Q(QAbstractBarSeries); | |
667 | if (sets.count() == 0) { |
|
667 | if (sets.count() == 0) { | |
668 | return false; |
|
668 | return false; | |
669 | } |
|
669 | } | |
670 | foreach (QBarSet* set, sets) { |
|
670 | foreach (QBarSet* set, sets) { | |
671 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
671 | if ((set == 0) || (!m_barSets.contains(set))) { | |
672 | // Fail if any of the sets is null or is not in series |
|
672 | // Fail if any of the sets is null or is not in series | |
673 | return false; |
|
673 | return false; | |
674 | } |
|
674 | } | |
675 | if (sets.count(set) != 1) { |
|
675 | if (sets.count(set) != 1) { | |
676 | // Also fail if same set is more than once in given list. |
|
676 | // Also fail if same set is more than once in given list. | |
677 | return false; |
|
677 | return false; | |
678 | } |
|
678 | } | |
679 | } |
|
679 | } | |
680 |
|
680 | |||
681 | foreach (QBarSet* set, sets) { |
|
681 | foreach (QBarSet* set, sets) { | |
682 | m_barSets.removeOne(set); |
|
682 | m_barSets.removeOne(set); | |
683 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
683 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
684 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
684 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
685 | } |
|
685 | } | |
686 |
|
686 | |||
687 | emit restructuredBars(); // this notifies barchartitem |
|
687 | emit restructuredBars(); // this notifies barchartitem | |
688 | if (m_dataset) { |
|
688 | if (m_dataset) { | |
689 | m_dataset->updateSeries(q); // this notifies legend |
|
689 | m_dataset->updateSeries(q); // this notifies legend | |
690 | } |
|
690 | } | |
691 | return true; |
|
691 | return true; | |
692 | } |
|
692 | } | |
693 |
|
693 | |||
694 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
694 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) | |
695 | { |
|
695 | { | |
696 | Q_Q(QAbstractBarSeries); |
|
696 | Q_Q(QAbstractBarSeries); | |
697 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
697 | if ((m_barSets.contains(set)) || (set == 0)) { | |
698 | // Fail if set is already in list or set is null. |
|
698 | // Fail if set is already in list or set is null. | |
699 | return false; |
|
699 | return false; | |
700 | } |
|
700 | } | |
701 | m_barSets.insert(index, set); |
|
701 | m_barSets.insert(index, set); | |
702 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
702 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
703 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
703 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
704 | emit restructuredBars(); // this notifies barchartitem |
|
704 | emit restructuredBars(); // this notifies barchartitem | |
705 | if (m_dataset) { |
|
705 | if (m_dataset) { | |
706 | m_dataset->updateSeries(q); // this notifies legend |
|
706 | m_dataset->updateSeries(q); // this notifies legend | |
707 | } |
|
707 | } | |
708 | return true; |
|
708 | return true; | |
709 | } |
|
709 | } | |
710 |
|
710 | |||
711 | void QAbstractBarSeriesPrivate::initializeAxisX(QAbstractAxis* axis) |
|
711 | void QAbstractBarSeriesPrivate::initializeAxisX(QAbstractAxis* axis) | |
712 | { |
|
712 | { | |
713 | Q_UNUSED(axis); |
|
713 | Q_UNUSED(axis); | |
714 | } |
|
714 | } | |
715 |
|
715 | |||
716 | void QAbstractBarSeriesPrivate::initializeAxisY(QAbstractAxis* axis) |
|
716 | void QAbstractBarSeriesPrivate::initializeAxisY(QAbstractAxis* axis) | |
717 | { |
|
717 | { | |
718 | Q_UNUSED(axis) |
|
718 | Q_UNUSED(axis) | |
719 | } |
|
719 | } | |
720 |
|
720 | |||
721 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const |
|
721 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const | |
722 | { |
|
722 | { | |
723 | return QAbstractAxis::AxisTypeCategories; |
|
723 | return QAbstractAxis::AxisTypeCategories; | |
724 | } |
|
724 | } | |
725 |
|
725 | |||
726 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const |
|
726 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const | |
727 | { |
|
727 | { | |
728 | return QAbstractAxis::AxisTypeValues; |
|
728 | return QAbstractAxis::AxisTypeValues; | |
729 | } |
|
729 | } | |
730 |
|
730 | |||
731 | #include "moc_qabstractbarseries.cpp" |
|
731 | #include "moc_qabstractbarseries.cpp" | |
732 | #include "moc_qabstractbarseries_p.cpp" |
|
732 | #include "moc_qabstractbarseries_p.cpp" | |
733 |
|
733 | |||
734 |
|
734 | |||
735 | QTCOMMERCIALCHART_END_NAMESPACE |
|
735 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,119 +1,119 | |||||
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 "q |
|
21 | #include "qbarseries.h" | |
22 |
#include "q |
|
22 | #include "qbarseries_p.h" | |
23 | #include "groupedbarchartitem_p.h" |
|
23 | #include "groupedbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 | #include "qcategoriesaxis.h" |
|
27 | #include "qcategoriesaxis.h" | |
28 | #include "qvaluesaxis.h" |
|
28 | #include "qvaluesaxis.h" | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 |
\class Q |
|
33 | \class QBarSeries | |
34 |
\brief Series for creating |
|
34 | \brief Series for creating bar chart | |
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 |
Q |
|
37 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
38 |
as groups, where bars in same category are grouped next to each other. Q |
|
38 | as groups, where bars in same category are grouped next to each other. QBarSeries groups the data | |
39 | from sets to categories, which are defined by a QStringList. |
|
39 | from sets to categories, which are defined by a QStringList. | |
40 |
|
40 | |||
41 | See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart. |
|
41 | See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart. | |
42 | \image examples_groupedbarchart.png |
|
42 | \image examples_groupedbarchart.png | |
43 |
|
43 | |||
44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries |
|
44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries | |
45 | */ |
|
45 | */ | |
46 | /*! |
|
46 | /*! | |
47 |
\qmlclass |
|
47 | \qmlclass BarSeries QBarSeries | |
48 | \inherits AbstractBarSeries |
|
48 | \inherits AbstractBarSeries | |
49 |
|
49 | |||
50 | The following QML shows how to create a simple grouped bar chart: |
|
50 | The following QML shows how to create a simple grouped bar chart: | |
51 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 |
|
51 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 | |
52 | \beginfloatleft |
|
52 | \beginfloatleft | |
53 | \image demos_qmlchart7.png |
|
53 | \image demos_qmlchart7.png | |
54 | \endfloat |
|
54 | \endfloat | |
55 | \clearfloat |
|
55 | \clearfloat | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 |
Constructs empty Q |
|
59 | Constructs empty QBarSeries. | |
60 |
Q |
|
60 | QBarSeries is QObject which is a child of a \a parent. | |
61 | */ |
|
61 | */ | |
62 |
Q |
|
62 | QBarSeries::QBarSeries(QObject *parent) | |
63 |
: QAbstractBarSeries(*new Q |
|
63 | : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent) | |
64 | { |
|
64 | { | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | /*! |
|
67 | /*! | |
68 | Returns QChartSeries::SeriesTypeGroupedBar. |
|
68 | Returns QChartSeries::SeriesTypeGroupedBar. | |
69 | */ |
|
69 | */ | |
70 |
QAbstractSeries::SeriesType Q |
|
70 | QAbstractSeries::SeriesType QBarSeries::type() const | |
71 | { |
|
71 | { | |
72 |
return QAbstractSeries::SeriesType |
|
72 | return QAbstractSeries::SeriesTypeBar; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
75 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
76 |
|
76 | |||
77 |
Q |
|
77 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
78 | { |
|
78 | { | |
79 |
|
79 | |||
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 |
void Q |
|
82 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
83 | { |
|
83 | { | |
84 | qreal minX(domain.minX()); |
|
84 | qreal minX(domain.minX()); | |
85 | qreal minY(domain.minY()); |
|
85 | qreal minY(domain.minY()); | |
86 | qreal maxX(domain.maxX()); |
|
86 | qreal maxX(domain.maxX()); | |
87 | qreal maxY(domain.maxY()); |
|
87 | qreal maxY(domain.maxY()); | |
88 | int tickXCount(domain.tickXCount()); |
|
88 | int tickXCount(domain.tickXCount()); | |
89 | int tickYCount(domain.tickYCount()); |
|
89 | int tickYCount(domain.tickYCount()); | |
90 |
|
90 | |||
91 | qreal x = categoryCount(); |
|
91 | qreal x = categoryCount(); | |
92 | qreal y = max(); |
|
92 | qreal y = max(); | |
93 | minX = qMin(minX, -0.5); |
|
93 | minX = qMin(minX, -0.5); | |
94 | minY = qMin(minY, y); |
|
94 | minY = qMin(minY, y); | |
95 | maxX = qMax(maxX, x - 0.5); |
|
95 | maxX = qMax(maxX, x - 0.5); | |
96 | maxY = qMax(maxY, y); |
|
96 | maxY = qMax(maxY, y); | |
97 | tickXCount = x+1; |
|
97 | tickXCount = x+1; | |
98 |
|
98 | |||
99 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
99 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 |
|
102 | |||
103 |
Chart* Q |
|
103 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
104 | { |
|
104 | { | |
105 |
Q_Q(Q |
|
105 | Q_Q(QBarSeries); | |
106 |
|
106 | |||
107 | GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter); |
|
107 | GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter); | |
108 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
108 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
109 | presenter->animator()->addAnimation(bar); |
|
109 | presenter->animator()->addAnimation(bar); | |
110 | } |
|
110 | } | |
111 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
111 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
112 | return bar; |
|
112 | return bar; | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 |
|
115 | |||
116 |
#include "moc_q |
|
116 | #include "moc_qbarseries.cpp" | |
117 |
|
117 | |||
118 | QTCOMMERCIALCHART_END_NAMESPACE |
|
118 | QTCOMMERCIALCHART_END_NAMESPACE | |
119 |
|
119 |
@@ -1,45 +1,45 | |||||
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 |
|
21 | #ifndef QBARSERIES_H | |
22 |
#define |
|
22 | #define QBARSERIES_H | |
23 |
|
23 | |||
24 | #include <QStringList> |
|
24 | #include <QStringList> | |
25 | #include <qabstractbarseries.h> |
|
25 | #include <qabstractbarseries.h> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 |
class Q |
|
29 | class QBarSeriesPrivate; | |
30 |
|
30 | |||
31 |
class QTCOMMERCIALCHART_EXPORT Q |
|
31 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractBarSeries | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 | public: |
|
34 | public: | |
35 |
explicit Q |
|
35 | explicit QBarSeries(QObject *parent = 0); | |
36 | QAbstractSeries::SeriesType type() const; |
|
36 | QAbstractSeries::SeriesType type() const; | |
37 |
|
37 | |||
38 | private: |
|
38 | private: | |
39 |
Q_DECLARE_PRIVATE(Q |
|
39 | Q_DECLARE_PRIVATE(QBarSeries) | |
40 |
Q_DISABLE_COPY(Q |
|
40 | Q_DISABLE_COPY(QBarSeries) | |
41 | }; |
|
41 | }; | |
42 |
|
42 | |||
43 | QTCOMMERCIALCHART_END_NAMESPACE |
|
43 | QTCOMMERCIALCHART_END_NAMESPACE | |
44 |
|
44 | |||
45 |
#endif // |
|
45 | #endif // QBARSERIES_H |
@@ -1,52 +1,52 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 |
#ifndef Q |
|
30 | #ifndef QBARSERIES_P_H | |
31 |
#define Q |
|
31 | #define QBARSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qabstractbarseries_p.h" |
|
33 | #include "qabstractbarseries_p.h" | |
34 | #include "domain_p.h" |
|
34 | #include "domain_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 |
|
38 | |||
39 |
class Q |
|
39 | class QBarSeriesPrivate: public QAbstractBarSeriesPrivate | |
40 | { |
|
40 | { | |
41 | public: |
|
41 | public: | |
42 |
Q |
|
42 | QBarSeriesPrivate(QBarSeries* q); | |
43 | Chart* createGraphics(ChartPresenter* presenter); |
|
43 | Chart* createGraphics(ChartPresenter* presenter); | |
44 | void scaleDomain(Domain& domain); |
|
44 | void scaleDomain(Domain& domain); | |
45 |
|
45 | |||
46 | private: |
|
46 | private: | |
47 |
Q_DECLARE_PUBLIC(Q |
|
47 | Q_DECLARE_PUBLIC(QBarSeries) | |
48 | }; |
|
48 | }; | |
49 |
|
49 | |||
50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
50 | QTCOMMERCIALCHART_END_NAMESPACE | |
51 |
|
51 | |||
52 |
#endif // Q |
|
52 | #endif // QBARSERIES_P_H |
@@ -1,616 +1,616 | |||||
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 "qbarset.h" |
|
21 | #include "qbarset.h" | |
22 | #include "qbarset_p.h" |
|
22 | #include "qbarset_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \class QBarSet |
|
27 | \class QBarSet | |
28 | \brief Building block for different bar charts |
|
28 | \brief Building block for different bar charts | |
29 |
|
29 | |||
30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. | |
31 | First value of set is assumed to belong to first category, second to second category and so on. |
|
31 | First value of set is assumed to belong to first category, second to second category and so on. | |
32 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
32 | If set has fewer values than there are categories, then the missing values are assumed to be | |
33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
34 |
|
34 | |||
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 |
\sa QAbstractBarSeries, Q |
|
37 | \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries | |
38 | */ |
|
38 | */ | |
39 | /*! |
|
39 | /*! | |
40 | \qmlclass BarSet QBarSet |
|
40 | \qmlclass BarSet QBarSet | |
41 |
|
41 | |||
42 | BarSet represents one set of bars. Set of bars contains one data value for each category. |
|
42 | BarSet represents one set of bars. Set of bars contains one data value for each category. | |
43 | First value of set is assumed to belong to first category, second to second category and so on. |
|
43 | First value of set is assumed to belong to first category, second to second category and so on. | |
44 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
44 | If set has fewer values than there are categories, then the missing values are assumed to be | |
45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
46 |
\sa AbstractBarSeries, |
|
46 | \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \property QBarSet::label |
|
50 | \property QBarSet::label | |
51 | Defines the label of the barSet. |
|
51 | Defines the label of the barSet. | |
52 | */ |
|
52 | */ | |
53 | /*! |
|
53 | /*! | |
54 | \qmlproperty string BarSet::label |
|
54 | \qmlproperty string BarSet::label | |
55 | Defines the label of the barSet. |
|
55 | Defines the label of the barSet. | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \property QBarSet::pen |
|
59 | \property QBarSet::pen | |
60 | \brief Defines the pen used by the barSet. |
|
60 | \brief Defines the pen used by the barSet. | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \property QBarSet::brush |
|
64 | \property QBarSet::brush | |
65 | \brief Defines the brush used by the barSet. |
|
65 | \brief Defines the brush used by the barSet. | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | \property QBarSet::labelBrush |
|
69 | \property QBarSet::labelBrush | |
70 | \brief Defines the brush used by the barSet's label. |
|
70 | \brief Defines the brush used by the barSet's label. | |
71 | */ |
|
71 | */ | |
72 |
|
72 | |||
73 | /*! |
|
73 | /*! | |
74 | \property QBarSet::labelFont |
|
74 | \property QBarSet::labelFont | |
75 | \brief Defines the font used by the barSet's label. |
|
75 | \brief Defines the font used by the barSet's label. | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \qmlproperty Font BarSet::labelFont |
|
79 | \qmlproperty Font BarSet::labelFont | |
80 | Defines the font used by the barSet's label. |
|
80 | Defines the font used by the barSet's label. | |
81 |
|
81 | |||
82 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
82 | See the \l {Font} {QML Font Element} for detailed documentation. | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \property QBarSet::color |
|
86 | \property QBarSet::color | |
87 | The fill (brush) color of the bar set. |
|
87 | The fill (brush) color of the bar set. | |
88 | */ |
|
88 | */ | |
89 | /*! |
|
89 | /*! | |
90 | \qmlproperty color BarSet::color |
|
90 | \qmlproperty color BarSet::color | |
91 | The fill (brush) color of the bar set. |
|
91 | The fill (brush) color of the bar set. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \property QBarSet::borderColor |
|
95 | \property QBarSet::borderColor | |
96 | The line (pen) color of the bar set. |
|
96 | The line (pen) color of the bar set. | |
97 | */ |
|
97 | */ | |
98 | /*! |
|
98 | /*! | |
99 | \qmlproperty color BarSet::borderColor |
|
99 | \qmlproperty color BarSet::borderColor | |
100 | The line (pen) color of the bar set. |
|
100 | The line (pen) color of the bar set. | |
101 | */ |
|
101 | */ | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | \property QBarSet::labelColor |
|
104 | \property QBarSet::labelColor | |
105 | The text (label) color of the bar set. |
|
105 | The text (label) color of the bar set. | |
106 | */ |
|
106 | */ | |
107 | /*! |
|
107 | /*! | |
108 | \qmlproperty color BarSet::labelColor |
|
108 | \qmlproperty color BarSet::labelColor | |
109 | The text (label) color of the bar set. |
|
109 | The text (label) color of the bar set. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | \fn void QBarSet::clicked(int index) |
|
113 | \fn void QBarSet::clicked(int index) | |
114 |
|
114 | |||
115 | The signal is emitted if the user clicks with a mouse on top of barset. |
|
115 | The signal is emitted if the user clicks with a mouse on top of barset. | |
116 | Clicked bar inside set is indexed by \a index |
|
116 | Clicked bar inside set is indexed by \a index | |
117 | */ |
|
117 | */ | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | \fn void QBarSet::hovered(bool status) |
|
120 | \fn void QBarSet::hovered(bool status) | |
121 |
|
121 | |||
122 | The signal is emitted if mouse is hovered on top of barset. |
|
122 | The signal is emitted if mouse is hovered on top of barset. | |
123 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. |
|
123 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 |
|
126 | |||
127 | /*! |
|
127 | /*! | |
128 | \fn void QBarSet::labelChanged() |
|
128 | \fn void QBarSet::labelChanged() | |
129 | This signal is emitted when the label of the barSet has changed. |
|
129 | This signal is emitted when the label of the barSet has changed. | |
130 | \sa label |
|
130 | \sa label | |
131 | */ |
|
131 | */ | |
132 | /*! |
|
132 | /*! | |
133 | \qmlsignal BarSet::onLabelChanged() |
|
133 | \qmlsignal BarSet::onLabelChanged() | |
134 | This signal is emitted when the label of the barSet has changed. |
|
134 | This signal is emitted when the label of the barSet has changed. | |
135 | */ |
|
135 | */ | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \fn void QBarSet::penChanged() |
|
138 | \fn void QBarSet::penChanged() | |
139 | This signal is emitted when the pen of the barSet has changed. |
|
139 | This signal is emitted when the pen of the barSet has changed. | |
140 | \sa pen |
|
140 | \sa pen | |
141 | */ |
|
141 | */ | |
142 |
|
142 | |||
143 | /*! |
|
143 | /*! | |
144 | \fn void QBarSet::brushChanged() |
|
144 | \fn void QBarSet::brushChanged() | |
145 | This signal is emitted when the brush of the barSet has changed. |
|
145 | This signal is emitted when the brush of the barSet has changed. | |
146 | \sa brush |
|
146 | \sa brush | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | \fn void QBarSet::labelBrushChanged() |
|
150 | \fn void QBarSet::labelBrushChanged() | |
151 | This signal is emitted when the brush of the barSet's label has changed. |
|
151 | This signal is emitted when the brush of the barSet's label has changed. | |
152 | \sa labelBrush |
|
152 | \sa labelBrush | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \fn void QBarSet::labelFontChanged() |
|
156 | \fn void QBarSet::labelFontChanged() | |
157 | This signal is emitted when the font of the barSet's label has changed. |
|
157 | This signal is emitted when the font of the barSet's label has changed. | |
158 | \sa labelBrush |
|
158 | \sa labelBrush | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | \fn void QBarSet::colorChanged(QColor) |
|
162 | \fn void QBarSet::colorChanged(QColor) | |
163 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
163 | This signal is emitted when the fill (brush) color of the set has changed to \a color. | |
164 | */ |
|
164 | */ | |
165 | /*! |
|
165 | /*! | |
166 | \qmlsignal BarSet::onColorChanged(color color) |
|
166 | \qmlsignal BarSet::onColorChanged(color color) | |
167 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
167 | This signal is emitted when the fill (brush) color of the set has changed to \a color. | |
168 | */ |
|
168 | */ | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | \fn void QBarSet::borderColorChanged(QColor) |
|
171 | \fn void QBarSet::borderColorChanged(QColor) | |
172 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
172 | This signal is emitted when the line (pen) color of the set has changed to \a color. | |
173 | */ |
|
173 | */ | |
174 | /*! |
|
174 | /*! | |
175 | \qmlsignal BarSet::onBorderColorChanged(color color) |
|
175 | \qmlsignal BarSet::onBorderColorChanged(color color) | |
176 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
176 | This signal is emitted when the line (pen) color of the set has changed to \a color. | |
177 | */ |
|
177 | */ | |
178 |
|
178 | |||
179 | /*! |
|
179 | /*! | |
180 | \fn void QBarSet::labelColorChanged(QColor) |
|
180 | \fn void QBarSet::labelColorChanged(QColor) | |
181 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
181 | This signal is emitted when the text (label) color of the set has changed to \a color. | |
182 | */ |
|
182 | */ | |
183 | /*! |
|
183 | /*! | |
184 | \qmlsignal BarSet::onLabelColorChanged(color color) |
|
184 | \qmlsignal BarSet::onLabelColorChanged(color color) | |
185 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
185 | This signal is emitted when the text (label) color of the set has changed to \a color. | |
186 | */ |
|
186 | */ | |
187 |
|
187 | |||
188 | /*! |
|
188 | /*! | |
189 | \fn void QBarSet::valuesAdded(int index, int count) |
|
189 | \fn void QBarSet::valuesAdded(int index, int count) | |
190 | This signal is emitted when new values have been added to the set. |
|
190 | This signal is emitted when new values have been added to the set. | |
191 | Parameter \a index indicates the position of the first inserted value. |
|
191 | Parameter \a index indicates the position of the first inserted value. | |
192 | Parameter \a count is the number of iserted values. |
|
192 | Parameter \a count is the number of iserted values. | |
193 | \sa append(), insert() |
|
193 | \sa append(), insert() | |
194 | */ |
|
194 | */ | |
195 | /*! |
|
195 | /*! | |
196 | \qmlsignal BarSet::onValuesAdded(int index, int count) |
|
196 | \qmlsignal BarSet::onValuesAdded(int index, int count) | |
197 | This signal is emitted when new values have been added to the set. |
|
197 | This signal is emitted when new values have been added to the set. | |
198 | Parameter \a index indicates the position of the first inserted value. |
|
198 | Parameter \a index indicates the position of the first inserted value. | |
199 | Parameter \a count is the number of iserted values. |
|
199 | Parameter \a count is the number of iserted values. | |
200 | */ |
|
200 | */ | |
201 |
|
201 | |||
202 | /*! |
|
202 | /*! | |
203 | \fn void QBarSet::valuesRemoved(int index, int count) |
|
203 | \fn void QBarSet::valuesRemoved(int index, int count) | |
204 | This signal is emitted values have been removed from the set. |
|
204 | This signal is emitted values have been removed from the set. | |
205 | Parameter \a index indicates the position of the first removed value. |
|
205 | Parameter \a index indicates the position of the first removed value. | |
206 | Parameter \a count is the number of removed values. |
|
206 | Parameter \a count is the number of removed values. | |
207 | \sa remove() |
|
207 | \sa remove() | |
208 | */ |
|
208 | */ | |
209 | /*! |
|
209 | /*! | |
210 | \qmlsignal BarSet::onValuesRemoved(int index, int count) |
|
210 | \qmlsignal BarSet::onValuesRemoved(int index, int count) | |
211 | This signal is emitted values have been removed from the set. |
|
211 | This signal is emitted values have been removed from the set. | |
212 | Parameter \a index indicates the position of the first removed value. |
|
212 | Parameter \a index indicates the position of the first removed value. | |
213 | Parameter \a count is the number of removed values. |
|
213 | Parameter \a count is the number of removed values. | |
214 | */ |
|
214 | */ | |
215 |
|
215 | |||
216 | /*! |
|
216 | /*! | |
217 | \fn void QBarSet::valueChanged(int index) |
|
217 | \fn void QBarSet::valueChanged(int index) | |
218 | This signal is emitted values the value in the set has been modified. |
|
218 | This signal is emitted values the value in the set has been modified. | |
219 | Parameter \a index indicates the position of the modified value. |
|
219 | Parameter \a index indicates the position of the modified value. | |
220 | \sa at() |
|
220 | \sa at() | |
221 | */ |
|
221 | */ | |
222 | /*! |
|
222 | /*! | |
223 | \qmlsignal BarSet::onValueChanged(int index) |
|
223 | \qmlsignal BarSet::onValueChanged(int index) | |
224 | This signal is emitted values the value in the set has been modified. |
|
224 | This signal is emitted values the value in the set has been modified. | |
225 | Parameter \a index indicates the position of the modified value. |
|
225 | Parameter \a index indicates the position of the modified value. | |
226 | */ |
|
226 | */ | |
227 |
|
227 | |||
228 | /*! |
|
228 | /*! | |
229 | \qmlproperty int BarSet::count |
|
229 | \qmlproperty int BarSet::count | |
230 | The count of values on the barset |
|
230 | The count of values on the barset | |
231 | */ |
|
231 | */ | |
232 |
|
232 | |||
233 | /*! |
|
233 | /*! | |
234 | \qmlproperty QVariantList BarSet::values |
|
234 | \qmlproperty QVariantList BarSet::values | |
235 | The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of |
|
235 | The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of | |
236 | reals as values, the values are automatically completed to points by using the index of a value as it's |
|
236 | reals as values, the values are automatically completed to points by using the index of a value as it's | |
237 | x-coordinate. For example: |
|
237 | x-coordinate. For example: | |
238 | \code |
|
238 | \code | |
239 | myBarSet1.values = [0, 5, 1, 5]; |
|
239 | myBarSet1.values = [0, 5, 1, 5]; | |
240 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; |
|
240 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; | |
241 | \endcode |
|
241 | \endcode | |
242 | */ |
|
242 | */ | |
243 |
|
243 | |||
244 | /*! |
|
244 | /*! | |
245 | Constructs QBarSet with a label of \a label and with parent of \a parent |
|
245 | Constructs QBarSet with a label of \a label and with parent of \a parent | |
246 | */ |
|
246 | */ | |
247 | QBarSet::QBarSet(const QString label, QObject *parent) |
|
247 | QBarSet::QBarSet(const QString label, QObject *parent) | |
248 | : QObject(parent) |
|
248 | : QObject(parent) | |
249 | ,d_ptr(new QBarSetPrivate(label,this)) |
|
249 | ,d_ptr(new QBarSetPrivate(label,this)) | |
250 | { |
|
250 | { | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | /*! |
|
253 | /*! | |
254 | Destroys the barset |
|
254 | Destroys the barset | |
255 | */ |
|
255 | */ | |
256 | QBarSet::~QBarSet() |
|
256 | QBarSet::~QBarSet() | |
257 | { |
|
257 | { | |
258 | // NOTE: d_ptr destroyed by QObject |
|
258 | // NOTE: d_ptr destroyed by QObject | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | /*! |
|
261 | /*! | |
262 | Sets new \a label for set. |
|
262 | Sets new \a label for set. | |
263 | */ |
|
263 | */ | |
264 | void QBarSet::setLabel(const QString label) |
|
264 | void QBarSet::setLabel(const QString label) | |
265 | { |
|
265 | { | |
266 | d_ptr->m_label = label; |
|
266 | d_ptr->m_label = label; | |
267 | emit labelChanged(); |
|
267 | emit labelChanged(); | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | /*! |
|
270 | /*! | |
271 | Returns label of the set. |
|
271 | Returns label of the set. | |
272 | */ |
|
272 | */ | |
273 | QString QBarSet::label() const |
|
273 | QString QBarSet::label() const | |
274 | { |
|
274 | { | |
275 | return d_ptr->m_label; |
|
275 | return d_ptr->m_label; | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | /*! |
|
278 | /*! | |
279 | Appends new value \a value to the end of set. |
|
279 | Appends new value \a value to the end of set. | |
280 | */ |
|
280 | */ | |
281 | void QBarSet::append(const qreal value) |
|
281 | void QBarSet::append(const qreal value) | |
282 | { |
|
282 | { | |
283 | // Convert to QPointF |
|
283 | // Convert to QPointF | |
284 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); |
|
284 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 | /*! |
|
287 | /*! | |
288 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
288 | Appends a list of reals to set. Works like append with single real value. The \a values in list | |
289 | are appended to end of barset |
|
289 | are appended to end of barset | |
290 | \sa append() |
|
290 | \sa append() | |
291 | */ |
|
291 | */ | |
292 | void QBarSet::append(const QList<qreal> &values) |
|
292 | void QBarSet::append(const QList<qreal> &values) | |
293 | { |
|
293 | { | |
294 | int index = d_ptr->m_values.count(); |
|
294 | int index = d_ptr->m_values.count(); | |
295 | d_ptr->append(values); |
|
295 | d_ptr->append(values); | |
296 | emit valuesAdded(index, values.count()); |
|
296 | emit valuesAdded(index, values.count()); | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | /*! |
|
299 | /*! | |
300 | Convinience operator. Same as append, with real \a value. |
|
300 | Convinience operator. Same as append, with real \a value. | |
301 | \sa append() |
|
301 | \sa append() | |
302 | */ |
|
302 | */ | |
303 | QBarSet& QBarSet::operator << (const qreal &value) |
|
303 | QBarSet& QBarSet::operator << (const qreal &value) | |
304 | { |
|
304 | { | |
305 | // append(value); |
|
305 | // append(value); | |
306 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); |
|
306 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); | |
307 | return *this; |
|
307 | return *this; | |
308 | } |
|
308 | } | |
309 |
|
309 | |||
310 | /*! |
|
310 | /*! | |
311 | Inserts new \a value on the \a index position. |
|
311 | Inserts new \a value on the \a index position. | |
312 | The value that is currently at this postion is moved to postion index + 1 |
|
312 | The value that is currently at this postion is moved to postion index + 1 | |
313 | \sa remove() |
|
313 | \sa remove() | |
314 | */ |
|
314 | */ | |
315 | void QBarSet::insert(const int index, const qreal value) |
|
315 | void QBarSet::insert(const int index, const qreal value) | |
316 | { |
|
316 | { | |
317 | d_ptr->insert(index, value); |
|
317 | d_ptr->insert(index, value); | |
318 | emit valuesAdded(index,1); |
|
318 | emit valuesAdded(index,1); | |
319 | } |
|
319 | } | |
320 |
|
320 | |||
321 | /*! |
|
321 | /*! | |
322 | Removes \a count number of values from the set starting at \a index. |
|
322 | Removes \a count number of values from the set starting at \a index. | |
323 | \sa insert() |
|
323 | \sa insert() | |
324 | */ |
|
324 | */ | |
325 | void QBarSet::remove(const int index, const int count) |
|
325 | void QBarSet::remove(const int index, const int count) | |
326 | { |
|
326 | { | |
327 | int removedCount = d_ptr->remove(index,count); |
|
327 | int removedCount = d_ptr->remove(index,count); | |
328 | if (removedCount > 0) { |
|
328 | if (removedCount > 0) { | |
329 | emit valuesRemoved(index,removedCount); |
|
329 | emit valuesRemoved(index,removedCount); | |
330 | } |
|
330 | } | |
331 | return; |
|
331 | return; | |
332 | } |
|
332 | } | |
333 |
|
333 | |||
334 | /*! |
|
334 | /*! | |
335 | Sets a new value \a value to set, indexed by \a index |
|
335 | Sets a new value \a value to set, indexed by \a index | |
336 | */ |
|
336 | */ | |
337 | void QBarSet::replace(const int index, const qreal value) |
|
337 | void QBarSet::replace(const int index, const qreal value) | |
338 | { |
|
338 | { | |
339 | if (index >= 0 && index < d_ptr->m_values.count()) { |
|
339 | if (index >= 0 && index < d_ptr->m_values.count()) { | |
340 | d_ptr->replace(index,value); |
|
340 | d_ptr->replace(index,value); | |
341 | emit valueChanged(index); |
|
341 | emit valueChanged(index); | |
342 | } |
|
342 | } | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 |
|
345 | |||
346 | /*! |
|
346 | /*! | |
347 | Returns value of set indexed by \a index. |
|
347 | Returns value of set indexed by \a index. | |
348 | If the index is out of bounds 0.0 is returned. |
|
348 | If the index is out of bounds 0.0 is returned. | |
349 | */ |
|
349 | */ | |
350 | qreal QBarSet::at(const int index) const |
|
350 | qreal QBarSet::at(const int index) const | |
351 | { |
|
351 | { | |
352 | if (index < 0 || index >= d_ptr->m_values.count()) { |
|
352 | if (index < 0 || index >= d_ptr->m_values.count()) { | |
353 | return 0; |
|
353 | return 0; | |
354 | } |
|
354 | } | |
355 |
|
355 | |||
356 | return d_ptr->m_values.at(index).y(); |
|
356 | return d_ptr->m_values.at(index).y(); | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | /*! |
|
359 | /*! | |
360 | Returns value of set indexed by \a index. |
|
360 | Returns value of set indexed by \a index. | |
361 | If the index is out of bounds 0.0 is returned. |
|
361 | If the index is out of bounds 0.0 is returned. | |
362 | */ |
|
362 | */ | |
363 | qreal QBarSet::operator [](const int index) const |
|
363 | qreal QBarSet::operator [](const int index) const | |
364 | { |
|
364 | { | |
365 | return at(index); |
|
365 | return at(index); | |
366 | } |
|
366 | } | |
367 |
|
367 | |||
368 | /*! |
|
368 | /*! | |
369 | Returns count of values in set. |
|
369 | Returns count of values in set. | |
370 | */ |
|
370 | */ | |
371 | int QBarSet::count() const |
|
371 | int QBarSet::count() const | |
372 | { |
|
372 | { | |
373 | return d_ptr->m_values.count(); |
|
373 | return d_ptr->m_values.count(); | |
374 | } |
|
374 | } | |
375 |
|
375 | |||
376 | /*! |
|
376 | /*! | |
377 | Returns sum of all values in barset. |
|
377 | Returns sum of all values in barset. | |
378 | */ |
|
378 | */ | |
379 | qreal QBarSet::sum() const |
|
379 | qreal QBarSet::sum() const | |
380 | { |
|
380 | { | |
381 | qreal total(0); |
|
381 | qreal total(0); | |
382 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
382 | for (int i=0; i < d_ptr->m_values.count(); i++) { | |
383 | total += d_ptr->m_values.at(i).y(); |
|
383 | total += d_ptr->m_values.at(i).y(); | |
384 | } |
|
384 | } | |
385 | return total; |
|
385 | return total; | |
386 | } |
|
386 | } | |
387 |
|
387 | |||
388 | /*! |
|
388 | /*! | |
389 | Sets pen for set. Bars of this set are drawn using \a pen |
|
389 | Sets pen for set. Bars of this set are drawn using \a pen | |
390 | */ |
|
390 | */ | |
391 | void QBarSet::setPen(const QPen &pen) |
|
391 | void QBarSet::setPen(const QPen &pen) | |
392 | { |
|
392 | { | |
393 | if(d_ptr->m_pen!=pen){ |
|
393 | if(d_ptr->m_pen!=pen){ | |
394 | d_ptr->m_pen = pen; |
|
394 | d_ptr->m_pen = pen; | |
395 | emit d_ptr->updatedBars(); |
|
395 | emit d_ptr->updatedBars(); | |
396 | emit penChanged(); |
|
396 | emit penChanged(); | |
397 | } |
|
397 | } | |
398 | } |
|
398 | } | |
399 |
|
399 | |||
400 | /*! |
|
400 | /*! | |
401 | Returns pen of the set. |
|
401 | Returns pen of the set. | |
402 | */ |
|
402 | */ | |
403 | QPen QBarSet::pen() const |
|
403 | QPen QBarSet::pen() const | |
404 | { |
|
404 | { | |
405 | return d_ptr->m_pen; |
|
405 | return d_ptr->m_pen; | |
406 | } |
|
406 | } | |
407 |
|
407 | |||
408 | /*! |
|
408 | /*! | |
409 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
409 | Sets brush for the set. Bars of this set are drawn using \a brush | |
410 | */ |
|
410 | */ | |
411 | void QBarSet::setBrush(const QBrush &brush) |
|
411 | void QBarSet::setBrush(const QBrush &brush) | |
412 | { |
|
412 | { | |
413 | if(d_ptr->m_brush!=brush){ |
|
413 | if(d_ptr->m_brush!=brush){ | |
414 | d_ptr->m_brush = brush; |
|
414 | d_ptr->m_brush = brush; | |
415 | emit d_ptr->updatedBars(); |
|
415 | emit d_ptr->updatedBars(); | |
416 | emit brushChanged(); |
|
416 | emit brushChanged(); | |
417 | } |
|
417 | } | |
418 | } |
|
418 | } | |
419 |
|
419 | |||
420 | /*! |
|
420 | /*! | |
421 | Returns brush of the set. |
|
421 | Returns brush of the set. | |
422 | */ |
|
422 | */ | |
423 | QBrush QBarSet::brush() const |
|
423 | QBrush QBarSet::brush() const | |
424 | { |
|
424 | { | |
425 | return d_ptr->m_brush; |
|
425 | return d_ptr->m_brush; | |
426 | } |
|
426 | } | |
427 |
|
427 | |||
428 | /*! |
|
428 | /*! | |
429 | Sets \a brush of the values that are drawn on top of this barset |
|
429 | Sets \a brush of the values that are drawn on top of this barset | |
430 | */ |
|
430 | */ | |
431 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
431 | void QBarSet::setLabelBrush(const QBrush &brush) | |
432 | { |
|
432 | { | |
433 | if(d_ptr->m_labelBrush!=brush){ |
|
433 | if(d_ptr->m_labelBrush!=brush){ | |
434 | d_ptr->m_labelBrush = brush; |
|
434 | d_ptr->m_labelBrush = brush; | |
435 | emit d_ptr->updatedBars(); |
|
435 | emit d_ptr->updatedBars(); | |
436 | emit labelBrushChanged(); |
|
436 | emit labelBrushChanged(); | |
437 | } |
|
437 | } | |
438 | } |
|
438 | } | |
439 |
|
439 | |||
440 | /*! |
|
440 | /*! | |
441 | Returns brush of the values that are drawn on top of this barset |
|
441 | Returns brush of the values that are drawn on top of this barset | |
442 | */ |
|
442 | */ | |
443 | QBrush QBarSet::labelBrush() const |
|
443 | QBrush QBarSet::labelBrush() const | |
444 | { |
|
444 | { | |
445 | return d_ptr->m_labelBrush; |
|
445 | return d_ptr->m_labelBrush; | |
446 | } |
|
446 | } | |
447 |
|
447 | |||
448 | /*! |
|
448 | /*! | |
449 | Sets the \a font for values that are drawn on top of this barset |
|
449 | Sets the \a font for values that are drawn on top of this barset | |
450 | */ |
|
450 | */ | |
451 | void QBarSet::setLabelFont(const QFont &font) |
|
451 | void QBarSet::setLabelFont(const QFont &font) | |
452 | { |
|
452 | { | |
453 | if(d_ptr->m_labelFont!=font) { |
|
453 | if(d_ptr->m_labelFont!=font) { | |
454 | d_ptr->m_labelFont = font; |
|
454 | d_ptr->m_labelFont = font; | |
455 | emit d_ptr->updatedBars(); |
|
455 | emit d_ptr->updatedBars(); | |
456 | emit labelFontChanged(); |
|
456 | emit labelFontChanged(); | |
457 | } |
|
457 | } | |
458 |
|
458 | |||
459 | } |
|
459 | } | |
460 |
|
460 | |||
461 | /*! |
|
461 | /*! | |
462 | Returns the pen for values that are drawn on top of this barset |
|
462 | Returns the pen for values that are drawn on top of this barset | |
463 | */ |
|
463 | */ | |
464 | QFont QBarSet::labelFont() const |
|
464 | QFont QBarSet::labelFont() const | |
465 | { |
|
465 | { | |
466 | return d_ptr->m_labelFont; |
|
466 | return d_ptr->m_labelFont; | |
467 | } |
|
467 | } | |
468 |
|
468 | |||
469 | /*! |
|
469 | /*! | |
470 | Returns the color of the brush of barset. |
|
470 | Returns the color of the brush of barset. | |
471 | */ |
|
471 | */ | |
472 | QColor QBarSet::color() |
|
472 | QColor QBarSet::color() | |
473 | { |
|
473 | { | |
474 | return brush().color(); |
|
474 | return brush().color(); | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | /*! |
|
477 | /*! | |
478 | Sets the \a color of brush for this barset |
|
478 | Sets the \a color of brush for this barset | |
479 | */ |
|
479 | */ | |
480 | void QBarSet::setColor(QColor color) |
|
480 | void QBarSet::setColor(QColor color) | |
481 | { |
|
481 | { | |
482 | QBrush b = brush(); |
|
482 | QBrush b = brush(); | |
483 | if (b.color() != color) { |
|
483 | if (b.color() != color) { | |
484 | b.setColor(color); |
|
484 | b.setColor(color); | |
485 | setBrush(b); |
|
485 | setBrush(b); | |
486 | emit colorChanged(color); |
|
486 | emit colorChanged(color); | |
487 | } |
|
487 | } | |
488 | } |
|
488 | } | |
489 |
|
489 | |||
490 | /*! |
|
490 | /*! | |
491 | Returns the color of pen of this barset |
|
491 | Returns the color of pen of this barset | |
492 | */ |
|
492 | */ | |
493 | QColor QBarSet::borderColor() |
|
493 | QColor QBarSet::borderColor() | |
494 | { |
|
494 | { | |
495 | return pen().color(); |
|
495 | return pen().color(); | |
496 | } |
|
496 | } | |
497 |
|
497 | |||
498 | /*! |
|
498 | /*! | |
499 | Sets the color of pen for this barset |
|
499 | Sets the color of pen for this barset | |
500 | */ |
|
500 | */ | |
501 | void QBarSet::setBorderColor(QColor color) |
|
501 | void QBarSet::setBorderColor(QColor color) | |
502 | { |
|
502 | { | |
503 | QPen p = pen(); |
|
503 | QPen p = pen(); | |
504 | if (p.color() != color) { |
|
504 | if (p.color() != color) { | |
505 | p.setColor(color); |
|
505 | p.setColor(color); | |
506 | setPen(p); |
|
506 | setPen(p); | |
507 | emit borderColorChanged(color); |
|
507 | emit borderColorChanged(color); | |
508 | } |
|
508 | } | |
509 | } |
|
509 | } | |
510 |
|
510 | |||
511 | /*! |
|
511 | /*! | |
512 | Returns the color of labels of this barset |
|
512 | Returns the color of labels of this barset | |
513 | */ |
|
513 | */ | |
514 | QColor QBarSet::labelColor() |
|
514 | QColor QBarSet::labelColor() | |
515 | { |
|
515 | { | |
516 | return labelBrush().color(); |
|
516 | return labelBrush().color(); | |
517 | } |
|
517 | } | |
518 |
|
518 | |||
519 | /*! |
|
519 | /*! | |
520 | Sets the color of labels for this barset |
|
520 | Sets the color of labels for this barset | |
521 | */ |
|
521 | */ | |
522 | void QBarSet::setLabelColor(QColor color) |
|
522 | void QBarSet::setLabelColor(QColor color) | |
523 | { |
|
523 | { | |
524 | QBrush b = labelBrush(); |
|
524 | QBrush b = labelBrush(); | |
525 | if (b.color() != color) { |
|
525 | if (b.color() != color) { | |
526 | b.setColor(color); |
|
526 | b.setColor(color); | |
527 | setLabelBrush(b); |
|
527 | setLabelBrush(b); | |
528 | emit labelColorChanged(color); |
|
528 | emit labelColorChanged(color); | |
529 | } |
|
529 | } | |
530 | } |
|
530 | } | |
531 |
|
531 | |||
532 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
532 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
533 |
|
533 | |||
534 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), |
|
534 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), | |
535 | q_ptr(parent), |
|
535 | q_ptr(parent), | |
536 | m_label(label) |
|
536 | m_label(label) | |
537 | { |
|
537 | { | |
538 | } |
|
538 | } | |
539 |
|
539 | |||
540 | QBarSetPrivate::~QBarSetPrivate() |
|
540 | QBarSetPrivate::~QBarSetPrivate() | |
541 | { |
|
541 | { | |
542 | } |
|
542 | } | |
543 |
|
543 | |||
544 | void QBarSetPrivate::append(QPointF value) |
|
544 | void QBarSetPrivate::append(QPointF value) | |
545 | { |
|
545 | { | |
546 | m_values.append(value); |
|
546 | m_values.append(value); | |
547 | emit restructuredBars(); |
|
547 | emit restructuredBars(); | |
548 | } |
|
548 | } | |
549 |
|
549 | |||
550 | void QBarSetPrivate::append(QList<QPointF> values) |
|
550 | void QBarSetPrivate::append(QList<QPointF> values) | |
551 | { |
|
551 | { | |
552 | for (int i=0; i<values.count(); i++) { |
|
552 | for (int i=0; i<values.count(); i++) { | |
553 | m_values.append(values.at(i)); |
|
553 | m_values.append(values.at(i)); | |
554 | } |
|
554 | } | |
555 | emit restructuredBars(); |
|
555 | emit restructuredBars(); | |
556 | } |
|
556 | } | |
557 |
|
557 | |||
558 | void QBarSetPrivate::append(QList<qreal> values) |
|
558 | void QBarSetPrivate::append(QList<qreal> values) | |
559 | { |
|
559 | { | |
560 | int index = m_values.count(); |
|
560 | int index = m_values.count(); | |
561 | for (int i=0; i<values.count(); i++) { |
|
561 | for (int i=0; i<values.count(); i++) { | |
562 | m_values.append(QPointF(index,values.at(i))); |
|
562 | m_values.append(QPointF(index,values.at(i))); | |
563 | index++; |
|
563 | index++; | |
564 | } |
|
564 | } | |
565 | emit restructuredBars(); |
|
565 | emit restructuredBars(); | |
566 | } |
|
566 | } | |
567 |
|
567 | |||
568 | void QBarSetPrivate::insert(const int index, const qreal value) |
|
568 | void QBarSetPrivate::insert(const int index, const qreal value) | |
569 | { |
|
569 | { | |
570 | m_values.insert(index, QPointF(index, value)); |
|
570 | m_values.insert(index, QPointF(index, value)); | |
571 | emit restructuredBars(); |
|
571 | emit restructuredBars(); | |
572 | } |
|
572 | } | |
573 |
|
573 | |||
574 | void QBarSetPrivate::insert(const int index, const QPointF value) |
|
574 | void QBarSetPrivate::insert(const int index, const QPointF value) | |
575 | { |
|
575 | { | |
576 | m_values.insert(index, value); |
|
576 | m_values.insert(index, value); | |
577 | emit restructuredBars(); |
|
577 | emit restructuredBars(); | |
578 | } |
|
578 | } | |
579 |
|
579 | |||
580 | int QBarSetPrivate::remove(const int index, const int count) |
|
580 | int QBarSetPrivate::remove(const int index, const int count) | |
581 | { |
|
581 | { | |
582 | int removeCount = count; |
|
582 | int removeCount = count; | |
583 |
|
583 | |||
584 | if ((index <0) || (m_values.count() == 0)) { |
|
584 | if ((index <0) || (m_values.count() == 0)) { | |
585 | // Invalid index or not values in list, remove nothing. |
|
585 | // Invalid index or not values in list, remove nothing. | |
586 | return 0; |
|
586 | return 0; | |
587 | } else if ((index + count) > m_values.count()) { |
|
587 | } else if ((index + count) > m_values.count()) { | |
588 | // Trying to remove more items than list has. Limit amount to be removed. |
|
588 | // Trying to remove more items than list has. Limit amount to be removed. | |
589 | removeCount = m_values.count() - index; |
|
589 | removeCount = m_values.count() - index; | |
590 | } |
|
590 | } | |
591 |
|
591 | |||
592 | int c = 0; |
|
592 | int c = 0; | |
593 | while (c < removeCount) { |
|
593 | while (c < removeCount) { | |
594 | m_values.removeAt(index); |
|
594 | m_values.removeAt(index); | |
595 | c++; |
|
595 | c++; | |
596 | } |
|
596 | } | |
597 | emit restructuredBars(); |
|
597 | emit restructuredBars(); | |
598 | return removeCount; |
|
598 | return removeCount; | |
599 | } |
|
599 | } | |
600 |
|
600 | |||
601 | void QBarSetPrivate::replace(const int index, const qreal value) |
|
601 | void QBarSetPrivate::replace(const int index, const qreal value) | |
602 | { |
|
602 | { | |
603 | m_values.replace(index,QPointF(index,value)); |
|
603 | m_values.replace(index,QPointF(index,value)); | |
604 | emit updatedBars(); |
|
604 | emit updatedBars(); | |
605 | } |
|
605 | } | |
606 |
|
606 | |||
607 | void QBarSetPrivate::replace(const int index, const QPointF value) |
|
607 | void QBarSetPrivate::replace(const int index, const QPointF value) | |
608 | { |
|
608 | { | |
609 | m_values.replace(index,value); |
|
609 | m_values.replace(index,value); | |
610 | emit updatedBars(); |
|
610 | emit updatedBars(); | |
611 | } |
|
611 | } | |
612 |
|
612 | |||
613 | #include "moc_qbarset.cpp" |
|
613 | #include "moc_qbarset.cpp" | |
614 | #include "moc_qbarset_p.cpp" |
|
614 | #include "moc_qbarset_p.cpp" | |
615 |
|
615 | |||
616 | QTCOMMERCIALCHART_END_NAMESPACE |
|
616 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,248 +1,248 | |||||
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 "qvbarmodelmapper.h" |
|
21 | #include "qvbarmodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QVBarModelMapper |
|
26 | \class QVBarModelMapper | |
27 | \brief Vertical model mapper for bar series |
|
27 | \brief Vertical model mapper for bar series | |
28 | \mainclass |
|
28 | \mainclass | |
29 |
|
29 | |||
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
31 | Vertical model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object. |
|
31 | Vertical model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object. | |
32 | Model mapper maintains equal size of all the BarSets. |
|
32 | Model mapper maintains equal size of all the BarSets. | |
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. | |
34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
35 | */ |
|
35 | */ | |
36 | /*! |
|
36 | /*! | |
37 | \qmlclass VBarModelMapper |
|
37 | \qmlclass VBarModelMapper | |
38 | \mainclass |
|
38 | \mainclass | |
39 |
|
39 | |||
40 | VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source |
|
40 | VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source | |
41 | for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. |
|
41 | for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. | |
42 | VBarModelMapper keeps the series and the model in sync. |
|
42 | VBarModelMapper keeps the series and the model in sync. | |
43 |
|
43 | |||
44 | The following QML example would create a bar series with three bar sets (assuming the |
|
44 | The following QML example would create a bar series with three bar sets (assuming the | |
45 | model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be |
|
45 | model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be | |
46 | defined by the horizontal header (of the column). |
|
46 | defined by the horizontal header (of the column). | |
47 | \code |
|
47 | \code | |
48 |
|
|
48 | BarSeries { | |
49 | VBarModelMapper { |
|
49 | VBarModelMapper { | |
50 | model: myCustomModel // QAbstractItemModel derived implementation |
|
50 | model: myCustomModel // QAbstractItemModel derived implementation | |
51 | firstBarSetColumn: 1 |
|
51 | firstBarSetColumn: 1 | |
52 | lastBarSetColumn: 3 |
|
52 | lastBarSetColumn: 3 | |
53 | firstRow: 1 |
|
53 | firstRow: 1 | |
54 | } |
|
54 | } | |
55 | } |
|
55 | } | |
56 | \endcode |
|
56 | \endcode | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | \property QVBarModelMapper::series |
|
60 | \property QVBarModelMapper::series | |
61 | \brief Defines the QPieSeries object that is used by the mapper. |
|
61 | \brief Defines the QPieSeries object that is used by the mapper. | |
62 |
|
62 | |||
63 | All the data in the series is discarded when it is set to the mapper. |
|
63 | All the data in the series is discarded when it is set to the mapper. | |
64 | When new series is specified the old series is disconnected (it preserves its data) |
|
64 | When new series is specified the old series is disconnected (it preserves its data) | |
65 | */ |
|
65 | */ | |
66 | /*! |
|
66 | /*! | |
67 | \qmlproperty AbstractBarSeries VBarModelMapper::series |
|
67 | \qmlproperty AbstractBarSeries VBarModelMapper::series | |
68 | Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is |
|
68 | Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is | |
69 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
69 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). | |
70 | */ |
|
70 | */ | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | \property QVBarModelMapper::model |
|
73 | \property QVBarModelMapper::model | |
74 | \brief Defines the model that is used by the mapper. |
|
74 | \brief Defines the model that is used by the mapper. | |
75 | */ |
|
75 | */ | |
76 | /*! |
|
76 | /*! | |
77 | \qmlproperty SomeModel VBarModelMapper::model |
|
77 | \qmlproperty SomeModel VBarModelMapper::model | |
78 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to |
|
78 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to | |
79 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns |
|
79 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns | |
80 | and modifying the data of the cells. |
|
80 | and modifying the data of the cells. | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \property QVBarModelMapper::firstBarSetColumn |
|
84 | \property QVBarModelMapper::firstBarSetColumn | |
85 | \brief Defines which column of the model is used as the data source for the first bar set |
|
85 | \brief Defines which column of the model is used as the data source for the first bar set | |
86 | Default value is: -1 (invalid mapping) |
|
86 | Default value is: -1 (invalid mapping) | |
87 | */ |
|
87 | */ | |
88 | /*! |
|
88 | /*! | |
89 | \qmlproperty int VBarModelMapper::firstBarSetColumn |
|
89 | \qmlproperty int VBarModelMapper::firstBarSetColumn | |
90 | Defines which column of the model is used as the data source for the first bar set. Default value |
|
90 | Defines which column of the model is used as the data source for the first bar set. Default value | |
91 | is: -1 (invalid mapping). |
|
91 | is: -1 (invalid mapping). | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \property QVBarModelMapper::lastBarSetColumn |
|
95 | \property QVBarModelMapper::lastBarSetColumn | |
96 | \brief Defines which column of the model is used as the data source for the last bar set |
|
96 | \brief Defines which column of the model is used as the data source for the last bar set | |
97 | Default value is: -1 (invalid mapping) |
|
97 | Default value is: -1 (invalid mapping) | |
98 | */ |
|
98 | */ | |
99 | /*! |
|
99 | /*! | |
100 | \qmlproperty int VBarModelMapper::lastBarSetColumn |
|
100 | \qmlproperty int VBarModelMapper::lastBarSetColumn | |
101 | Defines which column of the model is used as the data source for the last bar set. Default |
|
101 | Defines which column of the model is used as the data source for the last bar set. Default | |
102 | value is: -1 (invalid mapping). |
|
102 | value is: -1 (invalid mapping). | |
103 | */ |
|
103 | */ | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | \property QVBarModelMapper::firstRow |
|
106 | \property QVBarModelMapper::firstRow | |
107 | \brief Defines which row of the model contains the first values of the QBarSets in the series. |
|
107 | \brief Defines which row of the model contains the first values of the QBarSets in the series. | |
108 | Minimal and default value is: 0 |
|
108 | Minimal and default value is: 0 | |
109 | */ |
|
109 | */ | |
110 | /*! |
|
110 | /*! | |
111 | \qmlproperty int VBarModelMapper::firstRow |
|
111 | \qmlproperty int VBarModelMapper::firstRow | |
112 | Defines which row of the model contains the first values of the QBarSets in the series. |
|
112 | Defines which row of the model contains the first values of the QBarSets in the series. | |
113 | The default value is 0. |
|
113 | The default value is 0. | |
114 | */ |
|
114 | */ | |
115 |
|
115 | |||
116 | /*! |
|
116 | /*! | |
117 | \property QVBarModelMapper::rowCount |
|
117 | \property QVBarModelMapper::rowCount | |
118 | \brief Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries |
|
118 | \brief Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries | |
119 | Minimal and default value is: -1 (count limited by the number of rows in the model) |
|
119 | Minimal and default value is: -1 (count limited by the number of rows in the model) | |
120 | */ |
|
120 | */ | |
121 | /*! |
|
121 | /*! | |
122 | \qmlproperty int VBarModelMapper::rowCount |
|
122 | \qmlproperty int VBarModelMapper::rowCount | |
123 | Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries. The default value is |
|
123 | Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries. The default value is | |
124 | -1 (count limited by the number of rows in the model) |
|
124 | -1 (count limited by the number of rows in the model) | |
125 | */ |
|
125 | */ | |
126 |
|
126 | |||
127 | /*! |
|
127 | /*! | |
128 | \fn void QVBarModelMapper::seriesReplaced() |
|
128 | \fn void QVBarModelMapper::seriesReplaced() | |
129 |
|
129 | |||
130 | Emitted when the series to which mapper is connected to has changed. |
|
130 | Emitted when the series to which mapper is connected to has changed. | |
131 | */ |
|
131 | */ | |
132 |
|
132 | |||
133 | /*! |
|
133 | /*! | |
134 | \fn void QVBarModelMapper::modelReplaced() |
|
134 | \fn void QVBarModelMapper::modelReplaced() | |
135 |
|
135 | |||
136 | Emitted when the model to which mapper is connected to has changed. |
|
136 | Emitted when the model to which mapper is connected to has changed. | |
137 | */ |
|
137 | */ | |
138 |
|
138 | |||
139 | /*! |
|
139 | /*! | |
140 | \fn void QVBarModelMapper::firstBarSetColumnChanged() |
|
140 | \fn void QVBarModelMapper::firstBarSetColumnChanged() | |
141 | Emitted when the firstBarSetColumn has changed. |
|
141 | Emitted when the firstBarSetColumn has changed. | |
142 | */ |
|
142 | */ | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \fn void QVBarModelMapper::lastBarSetColumnChanged() |
|
145 | \fn void QVBarModelMapper::lastBarSetColumnChanged() | |
146 | Emitted when the lastBarSetColumn has changed. |
|
146 | Emitted when the lastBarSetColumn has changed. | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | \fn void QVBarModelMapper::firstRowChanged() |
|
150 | \fn void QVBarModelMapper::firstRowChanged() | |
151 | Emitted when the firstRow has changed. |
|
151 | Emitted when the firstRow has changed. | |
152 | */ |
|
152 | */ | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | \fn void QVBarModelMapper::rowCountChanged() |
|
155 | \fn void QVBarModelMapper::rowCountChanged() | |
156 | Emitted when the rowCount has changed. |
|
156 | Emitted when the rowCount has changed. | |
157 | */ |
|
157 | */ | |
158 |
|
158 | |||
159 | /*! |
|
159 | /*! | |
160 | Constructs a mapper object which is a child of \a parent. |
|
160 | Constructs a mapper object which is a child of \a parent. | |
161 | */ |
|
161 | */ | |
162 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : |
|
162 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : | |
163 | QBarModelMapper(parent) |
|
163 | QBarModelMapper(parent) | |
164 | { |
|
164 | { | |
165 | QBarModelMapper::setOrientation(Qt::Vertical); |
|
165 | QBarModelMapper::setOrientation(Qt::Vertical); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | QAbstractItemModel* QVBarModelMapper::model() const |
|
168 | QAbstractItemModel* QVBarModelMapper::model() const | |
169 | { |
|
169 | { | |
170 | return QBarModelMapper::model(); |
|
170 | return QBarModelMapper::model(); | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | void QVBarModelMapper::setModel(QAbstractItemModel *model) |
|
173 | void QVBarModelMapper::setModel(QAbstractItemModel *model) | |
174 | { |
|
174 | { | |
175 | if (model != QBarModelMapper::model()) { |
|
175 | if (model != QBarModelMapper::model()) { | |
176 | QBarModelMapper::setModel(model); |
|
176 | QBarModelMapper::setModel(model); | |
177 | emit modelReplaced(); |
|
177 | emit modelReplaced(); | |
178 | } |
|
178 | } | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | QAbstractBarSeries* QVBarModelMapper::series() const |
|
181 | QAbstractBarSeries* QVBarModelMapper::series() const | |
182 | { |
|
182 | { | |
183 | return QBarModelMapper::series(); |
|
183 | return QBarModelMapper::series(); | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | void QVBarModelMapper::setSeries(QAbstractBarSeries *series) |
|
186 | void QVBarModelMapper::setSeries(QAbstractBarSeries *series) | |
187 | { |
|
187 | { | |
188 | if (series != QBarModelMapper::series()) { |
|
188 | if (series != QBarModelMapper::series()) { | |
189 | QBarModelMapper::setSeries(series); |
|
189 | QBarModelMapper::setSeries(series); | |
190 | emit seriesReplaced(); |
|
190 | emit seriesReplaced(); | |
191 | } |
|
191 | } | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | int QVBarModelMapper::firstBarSetColumn() const |
|
194 | int QVBarModelMapper::firstBarSetColumn() const | |
195 | { |
|
195 | { | |
196 | return QBarModelMapper::firstBarSetSection(); |
|
196 | return QBarModelMapper::firstBarSetSection(); | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) |
|
199 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) | |
200 | { |
|
200 | { | |
201 | if (firstBarSetColumn != firstBarSetSection()) { |
|
201 | if (firstBarSetColumn != firstBarSetSection()) { | |
202 | QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); |
|
202 | QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); | |
203 | emit firstBarSetColumnChanged(); |
|
203 | emit firstBarSetColumnChanged(); | |
204 | } |
|
204 | } | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | int QVBarModelMapper::lastBarSetColumn() const |
|
207 | int QVBarModelMapper::lastBarSetColumn() const | |
208 | { |
|
208 | { | |
209 | return QBarModelMapper::lastBarSetSection(); |
|
209 | return QBarModelMapper::lastBarSetSection(); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) |
|
212 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) | |
213 | { |
|
213 | { | |
214 | if (lastBarSetColumn != lastBarSetSection()) { |
|
214 | if (lastBarSetColumn != lastBarSetSection()) { | |
215 | QBarModelMapper::setLastBarSetSection(lastBarSetColumn); |
|
215 | QBarModelMapper::setLastBarSetSection(lastBarSetColumn); | |
216 | emit lastBarSetColumnChanged(); |
|
216 | emit lastBarSetColumnChanged(); | |
217 | } |
|
217 | } | |
218 | } |
|
218 | } | |
219 |
|
219 | |||
220 | int QVBarModelMapper::firstRow() const |
|
220 | int QVBarModelMapper::firstRow() const | |
221 | { |
|
221 | { | |
222 | return QBarModelMapper::first(); |
|
222 | return QBarModelMapper::first(); | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | void QVBarModelMapper::setFirstRow(int firstRow) |
|
225 | void QVBarModelMapper::setFirstRow(int firstRow) | |
226 | { |
|
226 | { | |
227 | if (firstRow != first()) { |
|
227 | if (firstRow != first()) { | |
228 | QBarModelMapper::setFirst(firstRow); |
|
228 | QBarModelMapper::setFirst(firstRow); | |
229 | emit firstRowChanged(); |
|
229 | emit firstRowChanged(); | |
230 | } |
|
230 | } | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | int QVBarModelMapper::rowCount() const |
|
233 | int QVBarModelMapper::rowCount() const | |
234 | { |
|
234 | { | |
235 | return QBarModelMapper::count(); |
|
235 | return QBarModelMapper::count(); | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | void QVBarModelMapper::setRowCount(int rowCount) |
|
238 | void QVBarModelMapper::setRowCount(int rowCount) | |
239 | { |
|
239 | { | |
240 | if (rowCount != count()) { |
|
240 | if (rowCount != count()) { | |
241 | QBarModelMapper::setCount(rowCount); |
|
241 | QBarModelMapper::setCount(rowCount); | |
242 | emit firstRowChanged(); |
|
242 | emit firstRowChanged(); | |
243 | } |
|
243 | } | |
244 | } |
|
244 | } | |
245 |
|
245 | |||
246 | #include "moc_qvbarmodelmapper.cpp" |
|
246 | #include "moc_qvbarmodelmapper.cpp" | |
247 |
|
247 | |||
248 | QTCOMMERCIALCHART_END_NAMESPACE |
|
248 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,190 +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 "qabstractseries.h" |
|
21 | #include "qabstractseries.h" | |
22 | #include "qabstractseries_p.h" |
|
22 | #include "qabstractseries_p.h" | |
23 | #include "chartdataset_p.h" |
|
23 | #include "chartdataset_p.h" | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \class QAbstractSeries |
|
28 | \class QAbstractSeries | |
29 | \brief Base class for all QtCommercial Chart series. |
|
29 | \brief Base class for all QtCommercial Chart series. | |
30 | \mainclass |
|
30 | \mainclass | |
31 |
|
31 | |||
32 | Usually you use the series type specific inherited classes instead of the base class. |
|
32 | Usually you use the series type specific inherited classes instead of the base class. | |
33 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries, |
|
33 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries, | |
34 | QPercentBarSeries, QPieSeries |
|
34 | QPercentBarSeries, QPieSeries | |
35 | */ |
|
35 | */ | |
36 | /*! |
|
36 | /*! | |
37 | \qmlclass AbstractSeries |
|
37 | \qmlclass AbstractSeries | |
38 | AbstractSeries is the base class for all series. |
|
38 | AbstractSeries is the base class for all series. | |
39 | The class cannot be instantiated by the user. |
|
39 | The class cannot be instantiated by the user. | |
40 | */ |
|
40 | */ | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 | \enum QAbstractSeries::SeriesType |
|
43 | \enum QAbstractSeries::SeriesType | |
44 |
|
44 | |||
45 | The type of the series object. |
|
45 | The type of the series object. | |
46 |
|
46 | |||
47 | \value SeriesTypeLine |
|
47 | \value SeriesTypeLine | |
48 | \value SeriesTypeArea |
|
48 | \value SeriesTypeArea | |
49 | \value SeriesTypeBar |
|
49 | \value SeriesTypeBar | |
50 | \value SeriesTypeStackedBar |
|
50 | \value SeriesTypeStackedBar | |
51 | \value SeriesTypePercentBar |
|
51 | \value SeriesTypePercentBar | |
52 | \value SeriesTypeGroupedBar |
|
|||
53 | \value SeriesTypePie |
|
52 | \value SeriesTypePie | |
54 | \value SeriesTypeScatter |
|
53 | \value SeriesTypeScatter | |
55 | \value SeriesTypeSpline |
|
54 | \value SeriesTypeSpline | |
56 | */ |
|
55 | */ | |
57 |
|
56 | |||
58 | /*! |
|
57 | /*! | |
59 | \property QAbstractSeries::type |
|
58 | \property QAbstractSeries::type | |
60 | The type of the series. |
|
59 | The type of the series. | |
61 | */ |
|
60 | */ | |
62 | /*! |
|
61 | /*! | |
63 | \qmlproperty ChartView.SeriesType AbstractSeries::type |
|
62 | \qmlproperty ChartView.SeriesType AbstractSeries::type | |
64 | The type of the series. |
|
63 | The type of the series. | |
65 | */ |
|
64 | */ | |
66 |
|
65 | |||
67 | /*! |
|
66 | /*! | |
68 | \property QAbstractSeries::name |
|
67 | \property QAbstractSeries::name | |
69 | \brief name of the series property. The name is shown in legend for QXYSeries. |
|
68 | \brief name of the series property. The name is shown in legend for QXYSeries. | |
70 | */ |
|
69 | */ | |
71 | /*! |
|
70 | /*! | |
72 | \qmlproperty string AbstractSeries::name |
|
71 | \qmlproperty string AbstractSeries::name | |
73 | Name of the series. The name is shown in legend for QXYSeries. |
|
72 | Name of the series. The name is shown in legend for QXYSeries. | |
74 | */ |
|
73 | */ | |
75 |
|
74 | |||
76 | /*! |
|
75 | /*! | |
77 | \fn void QAbstractSeries::nameChanged() |
|
76 | \fn void QAbstractSeries::nameChanged() | |
78 | This signal is emitted when the series name changes. |
|
77 | This signal is emitted when the series name changes. | |
79 | */ |
|
78 | */ | |
80 | /*! |
|
79 | /*! | |
81 | \qmlsignal AbstractSeries::nameChanged() |
|
80 | \qmlsignal AbstractSeries::nameChanged() | |
82 | This signal is emitted when the series name changes. |
|
81 | This signal is emitted when the series name changes. | |
83 | */ |
|
82 | */ | |
84 |
|
83 | |||
85 | /*! |
|
84 | /*! | |
86 | \property QAbstractSeries::visible |
|
85 | \property QAbstractSeries::visible | |
87 | \brief whether the series is visible or not; true by default. |
|
86 | \brief whether the series is visible or not; true by default. | |
88 | */ |
|
87 | */ | |
89 |
|
88 | |||
90 | /*! |
|
89 | /*! | |
91 | \fn void QAbstractSeries::visibleChanged() |
|
90 | \fn void QAbstractSeries::visibleChanged() | |
92 | Emitted when the series visibility changes. |
|
91 | Emitted when the series visibility changes. | |
93 | */ |
|
92 | */ | |
94 |
|
93 | |||
95 | /*! |
|
94 | /*! | |
96 | \internal |
|
95 | \internal | |
97 | \brief Constructs ChartSeries object with \a parent. |
|
96 | \brief Constructs ChartSeries object with \a parent. | |
98 | */ |
|
97 | */ | |
99 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : |
|
98 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : | |
100 | QObject(parent), |
|
99 | QObject(parent), | |
101 | d_ptr(&d) |
|
100 | d_ptr(&d) | |
102 | { |
|
101 | { | |
103 | } |
|
102 | } | |
104 |
|
103 | |||
105 | /*! |
|
104 | /*! | |
106 | \brief Virtual destructor for the chart series. |
|
105 | \brief Virtual destructor for the chart series. | |
107 | */ |
|
106 | */ | |
108 | QAbstractSeries::~QAbstractSeries() |
|
107 | QAbstractSeries::~QAbstractSeries() | |
109 | { |
|
108 | { | |
110 | if(d_ptr->m_dataset) qFatal("Still binded series detected !"); |
|
109 | if(d_ptr->m_dataset) qFatal("Still binded series detected !"); | |
111 | } |
|
110 | } | |
112 |
|
111 | |||
113 | void QAbstractSeries::setName(const QString& name) |
|
112 | void QAbstractSeries::setName(const QString& name) | |
114 | { |
|
113 | { | |
115 | if (name != d_ptr->m_name) { |
|
114 | if (name != d_ptr->m_name) { | |
116 | d_ptr->m_name = name; |
|
115 | d_ptr->m_name = name; | |
117 | emit nameChanged(); |
|
116 | emit nameChanged(); | |
118 | } |
|
117 | } | |
119 | } |
|
118 | } | |
120 |
|
119 | |||
121 | QString QAbstractSeries::name() const |
|
120 | QString QAbstractSeries::name() const | |
122 | { |
|
121 | { | |
123 | return d_ptr->m_name; |
|
122 | return d_ptr->m_name; | |
124 | } |
|
123 | } | |
125 |
|
124 | |||
126 | /*! |
|
125 | /*! | |
127 | Sets the visibility of series to \a visible |
|
126 | Sets the visibility of series to \a visible | |
128 | */ |
|
127 | */ | |
129 | void QAbstractSeries::setVisible(bool visible) |
|
128 | void QAbstractSeries::setVisible(bool visible) | |
130 | { |
|
129 | { | |
131 | if (visible != d_ptr->m_visible) { |
|
130 | if (visible != d_ptr->m_visible) { | |
132 | d_ptr->m_visible = visible; |
|
131 | d_ptr->m_visible = visible; | |
133 | emit visibleChanged(); |
|
132 | emit visibleChanged(); | |
134 | } |
|
133 | } | |
135 | } |
|
134 | } | |
136 |
|
135 | |||
137 | /*! |
|
136 | /*! | |
138 | Returns the visibility of series |
|
137 | Returns the visibility of series | |
139 | */ |
|
138 | */ | |
140 | bool QAbstractSeries::isVisible() const |
|
139 | bool QAbstractSeries::isVisible() const | |
141 | { |
|
140 | { | |
142 | return d_ptr->m_visible; |
|
141 | return d_ptr->m_visible; | |
143 | } |
|
142 | } | |
144 |
|
143 | |||
145 | /*! |
|
144 | /*! | |
146 | \brief Returns the chart where series belongs to. |
|
145 | \brief Returns the chart where series belongs to. | |
147 |
|
146 | |||
148 | Set automatically when the series is added to the chart |
|
147 | Set automatically when the series is added to the chart | |
149 | and unset when the series is removed from the chart. |
|
148 | and unset when the series is removed from the chart. | |
150 | */ |
|
149 | */ | |
151 | QChart* QAbstractSeries::chart() const |
|
150 | QChart* QAbstractSeries::chart() const | |
152 | { |
|
151 | { | |
153 | return d_ptr->m_chart; |
|
152 | return d_ptr->m_chart; | |
154 | } |
|
153 | } | |
155 |
|
154 | |||
156 | void QAbstractSeries::adjustView() |
|
155 | void QAbstractSeries::adjustView() | |
157 | { |
|
156 | { | |
158 | //TODO: |
|
157 | //TODO: | |
159 | } |
|
158 | } | |
160 |
|
159 | |||
161 | void QAbstractSeries::show() |
|
160 | void QAbstractSeries::show() | |
162 | { |
|
161 | { | |
163 | setVisible(true); |
|
162 | setVisible(true); | |
164 | } |
|
163 | } | |
165 |
|
164 | |||
166 | void QAbstractSeries::hide() |
|
165 | void QAbstractSeries::hide() | |
167 | { |
|
166 | { | |
168 | setVisible(false); |
|
167 | setVisible(false); | |
169 | } |
|
168 | } | |
170 |
|
169 | |||
171 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
170 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
172 |
|
171 | |||
173 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q): |
|
172 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q): | |
174 | q_ptr(q), |
|
173 | q_ptr(q), | |
175 | m_chart(0), |
|
174 | m_chart(0), | |
176 | m_dataset(0), |
|
175 | m_dataset(0), | |
177 | m_visible(true) |
|
176 | m_visible(true) | |
178 | { |
|
177 | { | |
179 | } |
|
178 | } | |
180 |
|
179 | |||
181 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() |
|
180 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() | |
182 | { |
|
181 | { | |
183 | } |
|
182 | } | |
184 |
|
183 | |||
185 | #include "moc_qabstractseries.cpp" |
|
184 | #include "moc_qabstractseries.cpp" | |
186 | #include "moc_qabstractseries_p.cpp" |
|
185 | #include "moc_qabstractseries_p.cpp" | |
187 |
|
186 | |||
188 | QTCOMMERCIALCHART_END_NAMESPACE |
|
187 | QTCOMMERCIALCHART_END_NAMESPACE | |
189 |
|
188 | |||
190 |
|
189 |
@@ -1,85 +1,84 | |||||
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 QABSTRACTSERIES_H |
|
21 | #ifndef QABSTRACTSERIES_H | |
22 | #define QABSTRACTSERIES_H |
|
22 | #define QABSTRACTSERIES_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <qabstractaxis.h> |
|
25 | #include <qabstractaxis.h> | |
26 | #include <QObject> |
|
26 | #include <QObject> | |
27 | #include <QPen> |
|
27 | #include <QPen> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QAbstractSeriesPrivate; |
|
31 | class QAbstractSeriesPrivate; | |
32 | class QChart; |
|
32 | class QChart; | |
33 |
|
33 | |||
34 | class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject |
|
34 | class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) |
|
37 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) | |
38 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) |
|
38 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) | |
39 | Q_PROPERTY(SeriesType type READ type) |
|
39 | Q_PROPERTY(SeriesType type READ type) | |
40 | Q_ENUMS(SeriesType) |
|
40 | Q_ENUMS(SeriesType) | |
41 |
|
41 | |||
42 | public: |
|
42 | public: | |
43 | enum SeriesType { |
|
43 | enum SeriesType { | |
44 | SeriesTypeLine, |
|
44 | SeriesTypeLine, | |
45 | SeriesTypeArea, |
|
45 | SeriesTypeArea, | |
46 | SeriesTypeBar, |
|
46 | SeriesTypeBar, | |
47 | SeriesTypeStackedBar, |
|
47 | SeriesTypeStackedBar, | |
48 | SeriesTypePercentBar, |
|
48 | SeriesTypePercentBar, | |
49 | SeriesTypeGroupedBar, |
|
|||
50 | SeriesTypePie, |
|
49 | SeriesTypePie, | |
51 | SeriesTypeScatter, |
|
50 | SeriesTypeScatter, | |
52 | SeriesTypeSpline |
|
51 | SeriesTypeSpline | |
53 | }; |
|
52 | }; | |
54 |
|
53 | |||
55 | protected: |
|
54 | protected: | |
56 | QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent = 0); |
|
55 | QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent = 0); | |
57 |
|
56 | |||
58 | public: |
|
57 | public: | |
59 | ~QAbstractSeries(); |
|
58 | ~QAbstractSeries(); | |
60 | virtual SeriesType type() const = 0; |
|
59 | virtual SeriesType type() const = 0; | |
61 |
|
60 | |||
62 | void setName(const QString& name); |
|
61 | void setName(const QString& name); | |
63 | QString name() const; |
|
62 | QString name() const; | |
64 | void setVisible(bool visible = true); |
|
63 | void setVisible(bool visible = true); | |
65 | bool isVisible() const; |
|
64 | bool isVisible() const; | |
66 | QChart* chart() const; |
|
65 | QChart* chart() const; | |
67 |
|
66 | |||
68 | void adjustView(); |
|
67 | void adjustView(); | |
69 | void show(); |
|
68 | void show(); | |
70 | void hide(); |
|
69 | void hide(); | |
71 |
|
70 | |||
72 | Q_SIGNALS: |
|
71 | Q_SIGNALS: | |
73 | void nameChanged(); |
|
72 | void nameChanged(); | |
74 | void visibleChanged(); |
|
73 | void visibleChanged(); | |
75 |
|
74 | |||
76 | protected: |
|
75 | protected: | |
77 | QScopedPointer<QAbstractSeriesPrivate> d_ptr; |
|
76 | QScopedPointer<QAbstractSeriesPrivate> d_ptr; | |
78 | friend class ChartDataSet; |
|
77 | friend class ChartDataSet; | |
79 | friend class ChartPresenter; |
|
78 | friend class ChartPresenter; | |
80 | friend class QLegendPrivate; |
|
79 | friend class QLegendPrivate; | |
81 | }; |
|
80 | }; | |
82 |
|
81 | |||
83 | QTCOMMERCIALCHART_END_NAMESPACE |
|
82 | QTCOMMERCIALCHART_END_NAMESPACE | |
84 |
|
83 | |||
85 | #endif |
|
84 | #endif |
@@ -1,624 +1,624 | |||||
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 <qabstractaxis.h> |
|
22 | #include <qabstractaxis.h> | |
23 | #include <qvaluesaxis.h> |
|
23 | #include <qvaluesaxis.h> | |
24 | #include <qcategoriesaxis.h> |
|
24 | #include <qcategoriesaxis.h> | |
25 | #include <qlineseries.h> |
|
25 | #include <qlineseries.h> | |
26 | #include <qareaseries.h> |
|
26 | #include <qareaseries.h> | |
27 | #include <qscatterseries.h> |
|
27 | #include <qscatterseries.h> | |
28 | #include <qsplineseries.h> |
|
28 | #include <qsplineseries.h> | |
29 | #include <qpieseries.h> |
|
29 | #include <qpieseries.h> | |
30 |
#include <q |
|
30 | #include <qbarseries.h> | |
31 | #include <qpercentbarseries.h> |
|
31 | #include <qpercentbarseries.h> | |
32 | #include <qstackedbarseries.h> |
|
32 | #include <qstackedbarseries.h> | |
33 | #include <private/chartdataset_p.h> |
|
33 | #include <private/chartdataset_p.h> | |
34 | #include <private/domain_p.h> |
|
34 | #include <private/domain_p.h> | |
35 | #include <tst_definitions.h> |
|
35 | #include <tst_definitions.h> | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
37 | QTCOMMERCIALCHART_USE_NAMESPACE | |
38 |
|
38 | |||
39 | Q_DECLARE_METATYPE(Domain *) |
|
39 | Q_DECLARE_METATYPE(Domain *) | |
40 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
40 | Q_DECLARE_METATYPE(QAbstractAxis *) | |
41 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
41 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
42 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) |
|
42 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) | |
43 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) |
|
43 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) | |
44 | Q_DECLARE_METATYPE(QLineSeries *) |
|
44 | Q_DECLARE_METATYPE(QLineSeries *) | |
45 |
|
45 | |||
46 | class tst_ChartDataSet: public QObject { |
|
46 | class tst_ChartDataSet: public QObject { | |
47 |
|
47 | |||
48 | Q_OBJECT |
|
48 | Q_OBJECT | |
49 |
|
49 | |||
50 | public Q_SLOTS: |
|
50 | public Q_SLOTS: | |
51 | void initTestCase(); |
|
51 | void initTestCase(); | |
52 | void cleanupTestCase(); |
|
52 | void cleanupTestCase(); | |
53 | void init(); |
|
53 | void init(); | |
54 | void cleanup(); |
|
54 | void cleanup(); | |
55 |
|
55 | |||
56 | private Q_SLOTS: |
|
56 | private Q_SLOTS: | |
57 | void chartdataset_data(); |
|
57 | void chartdataset_data(); | |
58 | void chartdataset(); |
|
58 | void chartdataset(); | |
59 | void addSeries_data(); |
|
59 | void addSeries_data(); | |
60 | void addSeries(); |
|
60 | void addSeries(); | |
61 | void setAxisX_data(); |
|
61 | void setAxisX_data(); | |
62 | void setAxisX(); |
|
62 | void setAxisX(); | |
63 | void setAxisY_data(); |
|
63 | void setAxisY_data(); | |
64 | void setAxisY(); |
|
64 | void setAxisY(); | |
65 | void removeSeries_data(); |
|
65 | void removeSeries_data(); | |
66 | void removeSeries(); |
|
66 | void removeSeries(); | |
67 | void removeAllSeries_data(); |
|
67 | void removeAllSeries_data(); | |
68 | void removeAllSeries(); |
|
68 | void removeAllSeries(); | |
69 | void seriesCount_data(); |
|
69 | void seriesCount_data(); | |
70 | void seriesCount(); |
|
70 | void seriesCount(); | |
71 | void seriesIndex_data(); |
|
71 | void seriesIndex_data(); | |
72 | void seriesIndex(); |
|
72 | void seriesIndex(); | |
73 | void domain_data(); |
|
73 | void domain_data(); | |
74 | void domain(); |
|
74 | void domain(); | |
75 | void zoomInDomain_data(); |
|
75 | void zoomInDomain_data(); | |
76 | void zoomInDomain(); |
|
76 | void zoomInDomain(); | |
77 | void zoomOutDomain_data(); |
|
77 | void zoomOutDomain_data(); | |
78 | void zoomOutDomain(); |
|
78 | void zoomOutDomain(); | |
79 | void scrollDomain_data(); |
|
79 | void scrollDomain_data(); | |
80 | void scrollDomain(); |
|
80 | void scrollDomain(); | |
81 |
|
81 | |||
82 | private: |
|
82 | private: | |
83 | ChartDataSet* m_dataset; |
|
83 | ChartDataSet* m_dataset; | |
84 | }; |
|
84 | }; | |
85 |
|
85 | |||
86 | void tst_ChartDataSet::initTestCase() |
|
86 | void tst_ChartDataSet::initTestCase() | |
87 | { |
|
87 | { | |
88 | qRegisterMetaType<Domain*>(); |
|
88 | qRegisterMetaType<Domain*>(); | |
89 | qRegisterMetaType<QAbstractAxis*>(); |
|
89 | qRegisterMetaType<QAbstractAxis*>(); | |
90 | qRegisterMetaType<QAbstractSeries*>(); |
|
90 | qRegisterMetaType<QAbstractSeries*>(); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | void tst_ChartDataSet::cleanupTestCase() |
|
93 | void tst_ChartDataSet::cleanupTestCase() | |
94 | { |
|
94 | { | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | void tst_ChartDataSet::init() |
|
97 | void tst_ChartDataSet::init() | |
98 | { |
|
98 | { | |
99 | m_dataset = new ChartDataSet(); |
|
99 | m_dataset = new ChartDataSet(); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 |
|
102 | |||
103 | void tst_ChartDataSet::cleanup() |
|
103 | void tst_ChartDataSet::cleanup() | |
104 | { |
|
104 | { | |
105 | QList<QAbstractSeries*> series = m_dataset->series(); |
|
105 | QList<QAbstractSeries*> series = m_dataset->series(); | |
106 | foreach(QAbstractSeries* serie, series) |
|
106 | foreach(QAbstractSeries* serie, series) | |
107 | { |
|
107 | { | |
108 | m_dataset->removeSeries(serie); |
|
108 | m_dataset->removeSeries(serie); | |
109 | } |
|
109 | } | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | void tst_ChartDataSet::chartdataset_data() |
|
112 | void tst_ChartDataSet::chartdataset_data() | |
113 | { |
|
113 | { | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | void tst_ChartDataSet::chartdataset() |
|
116 | void tst_ChartDataSet::chartdataset() | |
117 | { |
|
117 | { | |
118 | QVERIFY(m_dataset->axisX(0) == 0); |
|
118 | QVERIFY(m_dataset->axisX(0) == 0); | |
119 | QVERIFY(m_dataset->axisY(0) == 0); |
|
119 | QVERIFY(m_dataset->axisY(0) == 0); | |
120 | QLineSeries* series = new QLineSeries(this); |
|
120 | QLineSeries* series = new QLineSeries(this); | |
121 | QCOMPARE(m_dataset->seriesIndex(series),-1); |
|
121 | QCOMPARE(m_dataset->seriesIndex(series),-1); | |
122 | QVERIFY(m_dataset->domain(series) == 0); |
|
122 | QVERIFY(m_dataset->domain(series) == 0); | |
123 | QVERIFY(m_dataset->axisX(series) == 0); |
|
123 | QVERIFY(m_dataset->axisX(series) == 0); | |
124 | QVERIFY(m_dataset->axisY(series) == 0); |
|
124 | QVERIFY(m_dataset->axisY(series) == 0); | |
125 | m_dataset->createDefaultAxes(); |
|
125 | m_dataset->createDefaultAxes(); | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 |
|
128 | |||
129 | void tst_ChartDataSet::addSeries_data() |
|
129 | void tst_ChartDataSet::addSeries_data() | |
130 | { |
|
130 | { | |
131 | QTest::addColumn<QAbstractSeries*>("series"); |
|
131 | QTest::addColumn<QAbstractSeries*>("series"); | |
132 |
|
132 | |||
133 | QAbstractSeries* line = new QLineSeries(this); |
|
133 | QAbstractSeries* line = new QLineSeries(this); | |
134 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
134 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
135 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
135 | QAbstractSeries* scatter = new QScatterSeries(this); | |
136 | QAbstractSeries* spline = new QSplineSeries(this); |
|
136 | QAbstractSeries* spline = new QSplineSeries(this); | |
137 | QAbstractSeries* pie = new QPieSeries(this); |
|
137 | QAbstractSeries* pie = new QPieSeries(this); | |
138 |
QAbstractSeries* bar = new Q |
|
138 | QAbstractSeries* bar = new QBarSeries(this); | |
139 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
139 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
140 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
140 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
141 |
|
141 | |||
142 | QTest::newRow("line") << line; |
|
142 | QTest::newRow("line") << line; | |
143 | QTest::newRow("area") << area; |
|
143 | QTest::newRow("area") << area; | |
144 | QTest::newRow("scatter") << scatter; |
|
144 | QTest::newRow("scatter") << scatter; | |
145 | QTest::newRow("spline") << spline; |
|
145 | QTest::newRow("spline") << spline; | |
146 | QTest::newRow("pie") << pie; |
|
146 | QTest::newRow("pie") << pie; | |
147 | QTest::newRow("bar") << bar; |
|
147 | QTest::newRow("bar") << bar; | |
148 | QTest::newRow("percent") << percent; |
|
148 | QTest::newRow("percent") << percent; | |
149 | QTest::newRow("stacked") << stacked; |
|
149 | QTest::newRow("stacked") << stacked; | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | void tst_ChartDataSet::addSeries() |
|
152 | void tst_ChartDataSet::addSeries() | |
153 | { |
|
153 | { | |
154 |
|
154 | |||
155 | QFETCH(QAbstractSeries*, series); |
|
155 | QFETCH(QAbstractSeries*, series); | |
156 |
|
156 | |||
157 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); |
|
157 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); | |
158 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
158 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
159 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
159 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
160 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
160 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
161 |
|
161 | |||
162 | m_dataset->addSeries(series); |
|
162 | m_dataset->addSeries(series); | |
163 | m_dataset->createDefaultAxes(); |
|
163 | m_dataset->createDefaultAxes(); | |
164 | if(series->type()==QAbstractSeries::SeriesTypePie){ |
|
164 | if(series->type()==QAbstractSeries::SeriesTypePie){ | |
165 | TRY_COMPARE(spy0.count(), 0); |
|
165 | TRY_COMPARE(spy0.count(), 0); | |
166 | }else{ |
|
166 | }else{ | |
167 | TRY_COMPARE(spy0.count(), 2); |
|
167 | TRY_COMPARE(spy0.count(), 2); | |
168 | } |
|
168 | } | |
169 | TRY_COMPARE(spy1.count(), 0); |
|
169 | TRY_COMPARE(spy1.count(), 0); | |
170 | TRY_COMPARE(spy2.count(), 1); |
|
170 | TRY_COMPARE(spy2.count(), 1); | |
171 | TRY_COMPARE(spy3.count(), 0); |
|
171 | TRY_COMPARE(spy3.count(), 0); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 |
|
174 | |||
175 | void tst_ChartDataSet::setAxisX_data() |
|
175 | void tst_ChartDataSet::setAxisX_data() | |
176 | { |
|
176 | { | |
177 |
|
177 | |||
178 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
178 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
179 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
179 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); | |
180 | QTest::addColumn<int>("axisCount"); |
|
180 | QTest::addColumn<int>("axisCount"); | |
181 |
|
181 | |||
182 | QAbstractSeries* line = new QLineSeries(this); |
|
182 | QAbstractSeries* line = new QLineSeries(this); | |
183 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
183 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
184 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
184 | QAbstractSeries* scatter = new QScatterSeries(this); | |
185 | QAbstractSeries* spline = new QSplineSeries(this); |
|
185 | QAbstractSeries* spline = new QSplineSeries(this); | |
186 | QAbstractSeries* pie = new QPieSeries(this); |
|
186 | QAbstractSeries* pie = new QPieSeries(this); | |
187 |
QAbstractSeries* bar = new Q |
|
187 | QAbstractSeries* bar = new QBarSeries(this); | |
188 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
188 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
189 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
189 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
190 |
|
190 | |||
191 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") |
|
191 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") | |
192 | << (QList<QAbstractSeries*>() << line << spline << scatter) |
|
192 | << (QList<QAbstractSeries*>() << line << spline << scatter) | |
193 | << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) << new QValuesAxis(this)) << 3; |
|
193 | << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) << new QValuesAxis(this)) << 3; | |
194 |
|
194 | |||
195 | QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area) |
|
195 | QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area) | |
196 | << (QList<QAbstractAxis*>() << new QValuesAxis(this)) << 1; |
|
196 | << (QList<QAbstractAxis*>() << new QValuesAxis(this)) << 1; | |
197 |
|
197 | |||
198 | QList<QAbstractAxis*> axes0; |
|
198 | QList<QAbstractAxis*> axes0; | |
199 | axes0 << new QValuesAxis(this) << new QValuesAxis(this); |
|
199 | axes0 << new QValuesAxis(this) << new QValuesAxis(this); | |
200 | axes0 << axes0.last(); |
|
200 | axes0 << axes0.last(); | |
201 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1") |
|
201 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1") | |
202 | << (QList<QAbstractSeries*>() << line << spline << scatter) |
|
202 | << (QList<QAbstractSeries*>() << line << spline << scatter) | |
203 | << axes0 << 2; |
|
203 | << axes0 << 2; | |
204 | //TODO: add more test cases |
|
204 | //TODO: add more test cases | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | void tst_ChartDataSet::setAxisX() |
|
207 | void tst_ChartDataSet::setAxisX() | |
208 | { |
|
208 | { | |
209 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
209 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
210 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
210 | QFETCH(QList<QAbstractAxis*>, axisList); | |
211 | QFETCH(int, axisCount); |
|
211 | QFETCH(int, axisCount); | |
212 |
|
212 | |||
213 | Q_ASSERT(seriesList.count() == axisList.count()); |
|
213 | Q_ASSERT(seriesList.count() == axisList.count()); | |
214 |
|
214 | |||
215 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); |
|
215 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); | |
216 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
216 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
217 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
217 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); | |
218 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
218 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
219 |
|
219 | |||
220 | foreach(QAbstractSeries* series, seriesList){ |
|
220 | foreach(QAbstractSeries* series, seriesList){ | |
221 | m_dataset->addSeries(series); |
|
221 | m_dataset->addSeries(series); | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | TRY_COMPARE(spy0.count(), 0); |
|
224 | TRY_COMPARE(spy0.count(), 0); | |
225 | TRY_COMPARE(spy1.count(), 0); |
|
225 | TRY_COMPARE(spy1.count(), 0); | |
226 | TRY_COMPARE(spy2.count(), seriesList.count()); |
|
226 | TRY_COMPARE(spy2.count(), seriesList.count()); | |
227 | TRY_COMPARE(spy3.count(), 0); |
|
227 | TRY_COMPARE(spy3.count(), 0); | |
228 |
|
228 | |||
229 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
229 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); | |
230 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
230 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
231 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
231 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); | |
232 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
232 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
233 |
|
233 | |||
234 | for(int i=0 ; i < seriesList.count(); i++){ |
|
234 | for(int i=0 ; i < seriesList.count(); i++){ | |
235 | m_dataset->setAxisX(seriesList.at(i),axisList.at(i)); |
|
235 | m_dataset->setAxisX(seriesList.at(i),axisList.at(i)); | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | TRY_COMPARE(spy4.count(), axisCount); |
|
238 | TRY_COMPARE(spy4.count(), axisCount); | |
239 | TRY_COMPARE(spy5.count(), 0); |
|
239 | TRY_COMPARE(spy5.count(), 0); | |
240 | TRY_COMPARE(spy6.count(), 0); |
|
240 | TRY_COMPARE(spy6.count(), 0); | |
241 | TRY_COMPARE(spy7.count(), 0); |
|
241 | TRY_COMPARE(spy7.count(), 0); | |
242 |
|
242 | |||
243 | for(int i=0 ; i < seriesList.count(); i++){ |
|
243 | for(int i=0 ; i < seriesList.count(); i++){ | |
244 | QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i)); |
|
244 | QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i)); | |
245 | } |
|
245 | } | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | void tst_ChartDataSet::setAxisY_data() |
|
248 | void tst_ChartDataSet::setAxisY_data() | |
249 | { |
|
249 | { | |
250 | setAxisX_data(); |
|
250 | setAxisX_data(); | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | void tst_ChartDataSet::setAxisY() |
|
253 | void tst_ChartDataSet::setAxisY() | |
254 | { |
|
254 | { | |
255 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
255 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
256 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
256 | QFETCH(QList<QAbstractAxis*>, axisList); | |
257 | QFETCH(int, axisCount); |
|
257 | QFETCH(int, axisCount); | |
258 |
|
258 | |||
259 | Q_ASSERT(seriesList.count() == axisList.count()); |
|
259 | Q_ASSERT(seriesList.count() == axisList.count()); | |
260 |
|
260 | |||
261 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
261 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); | |
262 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
262 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
263 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
263 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); | |
264 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
264 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
265 |
|
265 | |||
266 | foreach(QAbstractSeries* series, seriesList){ |
|
266 | foreach(QAbstractSeries* series, seriesList){ | |
267 | m_dataset->addSeries(series); |
|
267 | m_dataset->addSeries(series); | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | TRY_COMPARE(spy0.count(), 0); |
|
270 | TRY_COMPARE(spy0.count(), 0); | |
271 | TRY_COMPARE(spy1.count(), 0); |
|
271 | TRY_COMPARE(spy1.count(), 0); | |
272 | TRY_COMPARE(spy2.count(), seriesList.count()); |
|
272 | TRY_COMPARE(spy2.count(), seriesList.count()); | |
273 | TRY_COMPARE(spy3.count(), 0); |
|
273 | TRY_COMPARE(spy3.count(), 0); | |
274 |
|
274 | |||
275 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
275 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); | |
276 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
276 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
277 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
277 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); | |
278 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
278 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
279 |
|
279 | |||
280 | for(int i=0 ; i < seriesList.count(); i++){ |
|
280 | for(int i=0 ; i < seriesList.count(); i++){ | |
281 | m_dataset->setAxisY(seriesList.at(i),axisList.at(i)); |
|
281 | m_dataset->setAxisY(seriesList.at(i),axisList.at(i)); | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | TRY_COMPARE(spy4.count(), axisCount); |
|
284 | TRY_COMPARE(spy4.count(), axisCount); | |
285 | TRY_COMPARE(spy5.count(), 0); |
|
285 | TRY_COMPARE(spy5.count(), 0); | |
286 | TRY_COMPARE(spy6.count(), 0); |
|
286 | TRY_COMPARE(spy6.count(), 0); | |
287 | TRY_COMPARE(spy7.count(), 0); |
|
287 | TRY_COMPARE(spy7.count(), 0); | |
288 |
|
288 | |||
289 | for(int i=0 ; i < seriesList.count(); i++){ |
|
289 | for(int i=0 ; i < seriesList.count(); i++){ | |
290 | QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i)); |
|
290 | QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i)); | |
291 | } |
|
291 | } | |
292 | } |
|
292 | } | |
293 |
|
293 | |||
294 | void tst_ChartDataSet::removeSeries_data() |
|
294 | void tst_ChartDataSet::removeSeries_data() | |
295 | { |
|
295 | { | |
296 | addSeries_data(); |
|
296 | addSeries_data(); | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | void tst_ChartDataSet::removeSeries() |
|
299 | void tst_ChartDataSet::removeSeries() | |
300 | { |
|
300 | { | |
301 | QFETCH(QAbstractSeries*, series); |
|
301 | QFETCH(QAbstractSeries*, series); | |
302 |
|
302 | |||
303 | m_dataset->addSeries(series); |
|
303 | m_dataset->addSeries(series); | |
304 | m_dataset->createDefaultAxes(); |
|
304 | m_dataset->createDefaultAxes(); | |
305 |
|
305 | |||
306 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); |
|
306 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); | |
307 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
307 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
308 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
308 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
309 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
309 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
310 |
|
310 | |||
311 | m_dataset->removeSeries(series); |
|
311 | m_dataset->removeSeries(series); | |
312 |
|
312 | |||
313 | TRY_COMPARE(spy0.count(), 0); |
|
313 | TRY_COMPARE(spy0.count(), 0); | |
314 | if (series->type() == QAbstractSeries::SeriesTypePie) { |
|
314 | if (series->type() == QAbstractSeries::SeriesTypePie) { | |
315 | TRY_COMPARE(spy1.count(), 0); |
|
315 | TRY_COMPARE(spy1.count(), 0); | |
316 | } |
|
316 | } | |
317 | else { |
|
317 | else { | |
318 | TRY_COMPARE(spy1.count(), 2); |
|
318 | TRY_COMPARE(spy1.count(), 2); | |
319 | } |
|
319 | } | |
320 | TRY_COMPARE(spy2.count(), 0); |
|
320 | TRY_COMPARE(spy2.count(), 0); | |
321 | TRY_COMPARE(spy3.count(), 1); |
|
321 | TRY_COMPARE(spy3.count(), 1); | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | void tst_ChartDataSet::removeAllSeries_data() |
|
324 | void tst_ChartDataSet::removeAllSeries_data() | |
325 | { |
|
325 | { | |
326 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
326 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
327 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
327 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); | |
328 | QTest::addColumn<int>("axisCount"); |
|
328 | QTest::addColumn<int>("axisCount"); | |
329 |
|
329 | |||
330 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") |
|
330 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") | |
331 | << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this) |
|
331 | << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this) | |
332 | << new QScatterSeries(this)) |
|
332 | << new QScatterSeries(this)) | |
333 | << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) |
|
333 | << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) | |
334 | << new QValuesAxis(this)) << 3; |
|
334 | << new QValuesAxis(this)) << 3; | |
335 | //TODO: |
|
335 | //TODO: | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 | void tst_ChartDataSet::removeAllSeries() |
|
338 | void tst_ChartDataSet::removeAllSeries() | |
339 | { |
|
339 | { | |
340 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
340 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
341 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
341 | QFETCH(QList<QAbstractAxis*>, axisList); | |
342 | QFETCH(int, axisCount); |
|
342 | QFETCH(int, axisCount); | |
343 |
|
343 | |||
344 | foreach(QAbstractSeries* series, seriesList) { |
|
344 | foreach(QAbstractSeries* series, seriesList) { | |
345 | m_dataset->addSeries(series); |
|
345 | m_dataset->addSeries(series); | |
346 | } |
|
346 | } | |
347 |
|
347 | |||
348 | for (int i = 0; i < seriesList.count(); i++) { |
|
348 | for (int i = 0; i < seriesList.count(); i++) { | |
349 | m_dataset->setAxisX(seriesList.at(i), axisList.at(i)); |
|
349 | m_dataset->setAxisX(seriesList.at(i), axisList.at(i)); | |
350 | } |
|
350 | } | |
351 |
|
351 | |||
352 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
352 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); | |
353 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
353 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
354 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
354 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
355 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
355 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
356 |
|
356 | |||
357 | m_dataset->removeAllSeries(); |
|
357 | m_dataset->removeAllSeries(); | |
358 |
|
358 | |||
359 | TRY_COMPARE(spy0.count(), 0); |
|
359 | TRY_COMPARE(spy0.count(), 0); | |
360 | TRY_COMPARE(spy1.count(), axisCount); |
|
360 | TRY_COMPARE(spy1.count(), axisCount); | |
361 | TRY_COMPARE(spy2.count(), 0); |
|
361 | TRY_COMPARE(spy2.count(), 0); | |
362 | TRY_COMPARE(spy3.count(), seriesList.count()); |
|
362 | TRY_COMPARE(spy3.count(), seriesList.count()); | |
363 | } |
|
363 | } | |
364 |
|
364 | |||
365 |
|
365 | |||
366 | void tst_ChartDataSet::seriesCount_data() |
|
366 | void tst_ChartDataSet::seriesCount_data() | |
367 | { |
|
367 | { | |
368 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
368 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
369 | QTest::addColumn<int>("seriesCount"); |
|
369 | QTest::addColumn<int>("seriesCount"); | |
370 |
|
370 | |||
371 | QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3; |
|
371 | QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3; | |
372 | QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2; |
|
372 | QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2; | |
373 | } |
|
373 | } | |
374 |
|
374 | |||
375 | void tst_ChartDataSet::seriesCount() |
|
375 | void tst_ChartDataSet::seriesCount() | |
376 | { |
|
376 | { | |
377 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
377 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
378 | QFETCH(int, seriesCount); |
|
378 | QFETCH(int, seriesCount); | |
379 |
|
379 | |||
380 | foreach(QAbstractSeries* series, seriesList){ |
|
380 | foreach(QAbstractSeries* series, seriesList){ | |
381 | m_dataset->addSeries(series); |
|
381 | m_dataset->addSeries(series); | |
382 | } |
|
382 | } | |
383 |
|
383 | |||
384 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
384 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); | |
385 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
385 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
386 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
386 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
387 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
387 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
388 |
|
388 | |||
389 | QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount); |
|
389 | QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount); | |
390 | TRY_COMPARE(spy0.count(), 0); |
|
390 | TRY_COMPARE(spy0.count(), 0); | |
391 | TRY_COMPARE(spy1.count(), 0); |
|
391 | TRY_COMPARE(spy1.count(), 0); | |
392 | TRY_COMPARE(spy2.count(), 0); |
|
392 | TRY_COMPARE(spy2.count(), 0); | |
393 | TRY_COMPARE(spy3.count(), 0); |
|
393 | TRY_COMPARE(spy3.count(), 0); | |
394 | } |
|
394 | } | |
395 |
|
395 | |||
396 | void tst_ChartDataSet::seriesIndex_data() |
|
396 | void tst_ChartDataSet::seriesIndex_data() | |
397 | { |
|
397 | { | |
398 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
398 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
399 |
|
399 | |||
400 | QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
400 | QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); | |
401 | QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ); |
|
401 | QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ); | |
402 | } |
|
402 | } | |
403 |
|
403 | |||
404 | void tst_ChartDataSet::seriesIndex() |
|
404 | void tst_ChartDataSet::seriesIndex() | |
405 | { |
|
405 | { | |
406 |
|
406 | |||
407 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
407 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
408 |
|
408 | |||
409 | foreach(QAbstractSeries* series, seriesList) { |
|
409 | foreach(QAbstractSeries* series, seriesList) { | |
410 | m_dataset->addSeries(series); |
|
410 | m_dataset->addSeries(series); | |
411 | } |
|
411 | } | |
412 |
|
412 | |||
413 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); |
|
413 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); | |
414 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
414 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
415 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); |
|
415 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); | |
416 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
416 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
417 |
|
417 | |||
418 | for (int i = 0; i < seriesList.count(); i++) { |
|
418 | for (int i = 0; i < seriesList.count(); i++) { | |
419 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
419 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
420 | } |
|
420 | } | |
421 |
|
421 | |||
422 | TRY_COMPARE(spy0.count(), 0); |
|
422 | TRY_COMPARE(spy0.count(), 0); | |
423 | TRY_COMPARE(spy1.count(), 0); |
|
423 | TRY_COMPARE(spy1.count(), 0); | |
424 | TRY_COMPARE(spy2.count(), 0); |
|
424 | TRY_COMPARE(spy2.count(), 0); | |
425 | TRY_COMPARE(spy3.count(), 0); |
|
425 | TRY_COMPARE(spy3.count(), 0); | |
426 |
|
426 | |||
427 | foreach(QAbstractSeries* series, seriesList) { |
|
427 | foreach(QAbstractSeries* series, seriesList) { | |
428 | m_dataset->removeSeries(series); |
|
428 | m_dataset->removeSeries(series); | |
429 | } |
|
429 | } | |
430 |
|
430 | |||
431 | for (int i = 0; i < seriesList.count(); i++) { |
|
431 | for (int i = 0; i < seriesList.count(); i++) { | |
432 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
432 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); | |
433 | } |
|
433 | } | |
434 |
|
434 | |||
435 | foreach(QAbstractSeries* series, seriesList) { |
|
435 | foreach(QAbstractSeries* series, seriesList) { | |
436 | m_dataset->addSeries(series); |
|
436 | m_dataset->addSeries(series); | |
437 | } |
|
437 | } | |
438 |
|
438 | |||
439 | for (int i = 0; i < seriesList.count(); i++) { |
|
439 | for (int i = 0; i < seriesList.count(); i++) { | |
440 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
440 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
441 | } |
|
441 | } | |
442 |
|
442 | |||
443 | m_dataset->removeSeries(seriesList.at(1)); |
|
443 | m_dataset->removeSeries(seriesList.at(1)); | |
444 |
|
444 | |||
445 | for (int i = 0; i < seriesList.count(); i++) { |
|
445 | for (int i = 0; i < seriesList.count(); i++) { | |
446 | if (i != 1) |
|
446 | if (i != 1) | |
447 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
447 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
448 | else |
|
448 | else | |
449 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
449 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); | |
450 | } |
|
450 | } | |
451 |
|
451 | |||
452 | m_dataset->addSeries(seriesList.at(1)); |
|
452 | m_dataset->addSeries(seriesList.at(1)); | |
453 |
|
453 | |||
454 | for (int i = 0; i < seriesList.count(); i++) { |
|
454 | for (int i = 0; i < seriesList.count(); i++) { | |
455 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
455 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
456 | } |
|
456 | } | |
457 |
|
457 | |||
458 | m_dataset->removeSeries(seriesList.at(2)); |
|
458 | m_dataset->removeSeries(seriesList.at(2)); | |
459 |
|
459 | |||
460 | for (int i = 0; i < seriesList.count(); i++) { |
|
460 | for (int i = 0; i < seriesList.count(); i++) { | |
461 | if (i != 2) |
|
461 | if (i != 2) | |
462 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
462 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
463 | else |
|
463 | else | |
464 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
464 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); | |
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | m_dataset->removeSeries(seriesList.at(0)); |
|
467 | m_dataset->removeSeries(seriesList.at(0)); | |
468 |
|
468 | |||
469 | for (int i = 0; i < seriesList.count(); i++) { |
|
469 | for (int i = 0; i < seriesList.count(); i++) { | |
470 | if (i != 2 && i != 0) |
|
470 | if (i != 2 && i != 0) | |
471 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
471 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
472 | else |
|
472 | else | |
473 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
473 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); | |
474 | } |
|
474 | } | |
475 |
|
475 | |||
476 | m_dataset->addSeries(seriesList.at(2)); |
|
476 | m_dataset->addSeries(seriesList.at(2)); | |
477 | m_dataset->addSeries(seriesList.at(0)); |
|
477 | m_dataset->addSeries(seriesList.at(0)); | |
478 |
|
478 | |||
479 | for (int i = 0; i < seriesList.count(); i++) { |
|
479 | for (int i = 0; i < seriesList.count(); i++) { | |
480 | if (i == 2) |
|
480 | if (i == 2) | |
481 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0); |
|
481 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0); | |
482 | else if (i == 0) |
|
482 | else if (i == 0) | |
483 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2); |
|
483 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2); | |
484 | else |
|
484 | else | |
485 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
485 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
486 | } |
|
486 | } | |
487 |
|
487 | |||
488 | } |
|
488 | } | |
489 |
|
489 | |||
490 | void tst_ChartDataSet::domain_data() |
|
490 | void tst_ChartDataSet::domain_data() | |
491 | { |
|
491 | { | |
492 | addSeries_data(); |
|
492 | addSeries_data(); | |
493 | } |
|
493 | } | |
494 |
|
494 | |||
495 | void tst_ChartDataSet::domain() |
|
495 | void tst_ChartDataSet::domain() | |
496 | { |
|
496 | { | |
497 | QFETCH(QAbstractSeries*, series); |
|
497 | QFETCH(QAbstractSeries*, series); | |
498 |
|
498 | |||
499 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
499 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); | |
500 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
500 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
501 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
501 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
502 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
502 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
503 |
|
503 | |||
504 | m_dataset->addSeries(series); |
|
504 | m_dataset->addSeries(series); | |
505 | QVERIFY(m_dataset->domain(series)); |
|
505 | QVERIFY(m_dataset->domain(series)); | |
506 |
|
506 | |||
507 |
|
507 | |||
508 | TRY_COMPARE(spy0.count(), 0); |
|
508 | TRY_COMPARE(spy0.count(), 0); | |
509 | TRY_COMPARE(spy1.count(), 0); |
|
509 | TRY_COMPARE(spy1.count(), 0); | |
510 | TRY_COMPARE(spy2.count(), 1); |
|
510 | TRY_COMPARE(spy2.count(), 1); | |
511 |
|
511 | |||
512 | QList<QVariant> arguments = spy2.takeFirst(); |
|
512 | QList<QVariant> arguments = spy2.takeFirst(); | |
513 | Domain *domain = (Domain *) arguments.at(1).value<Domain *>(); |
|
513 | Domain *domain = (Domain *) arguments.at(1).value<Domain *>(); | |
514 | QVERIFY(m_dataset->domain(series) == domain); |
|
514 | QVERIFY(m_dataset->domain(series) == domain); | |
515 |
|
515 | |||
516 | TRY_COMPARE(spy3.count(), 0); |
|
516 | TRY_COMPARE(spy3.count(), 0); | |
517 |
|
517 | |||
518 | } |
|
518 | } | |
519 |
|
519 | |||
520 | void tst_ChartDataSet::zoomInDomain_data() |
|
520 | void tst_ChartDataSet::zoomInDomain_data() | |
521 | { |
|
521 | { | |
522 | QTest::addColumn<bool >("sameAxis"); |
|
522 | QTest::addColumn<bool >("sameAxis"); | |
523 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
523 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
524 | QTest::newRow("sameAxis: line,line, line, spline") << true << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
524 | QTest::newRow("sameAxis: line,line, line, spline") << true << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); | |
525 | QTest::newRow("separeateAxis: line,line, line, spline") << false << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
525 | QTest::newRow("separeateAxis: line,line, line, spline") << false << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); | |
526 | } |
|
526 | } | |
527 |
|
527 | |||
528 | void tst_ChartDataSet::zoomInDomain() |
|
528 | void tst_ChartDataSet::zoomInDomain() | |
529 | { |
|
529 | { | |
530 | QFETCH(bool, sameAxis); |
|
530 | QFETCH(bool, sameAxis); | |
531 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
531 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
532 |
|
532 | |||
533 | foreach(QAbstractSeries* series, seriesList) { |
|
533 | foreach(QAbstractSeries* series, seriesList) { | |
534 | m_dataset->addSeries(series); |
|
534 | m_dataset->addSeries(series); | |
535 | } |
|
535 | } | |
536 |
|
536 | |||
537 | if(sameAxis) m_dataset->createDefaultAxes(); |
|
537 | if(sameAxis) m_dataset->createDefaultAxes(); | |
538 |
|
538 | |||
539 | QList<QSignalSpy*> spyList; |
|
539 | QList<QSignalSpy*> spyList; | |
540 |
|
540 | |||
541 | foreach(QAbstractSeries* series, seriesList) { |
|
541 | foreach(QAbstractSeries* series, seriesList) { | |
542 | spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
542 | spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
543 | } |
|
543 | } | |
544 |
|
544 | |||
545 | m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); |
|
545 | m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); | |
546 |
|
546 | |||
547 | foreach(QSignalSpy* spy, spyList) { |
|
547 | foreach(QSignalSpy* spy, spyList) { | |
548 | TRY_COMPARE(spy->count(), 1); |
|
548 | TRY_COMPARE(spy->count(), 1); | |
549 | } |
|
549 | } | |
550 |
|
550 | |||
551 | qDeleteAll(spyList); |
|
551 | qDeleteAll(spyList); | |
552 | } |
|
552 | } | |
553 |
|
553 | |||
554 |
|
554 | |||
555 |
|
555 | |||
556 | void tst_ChartDataSet::zoomOutDomain_data() |
|
556 | void tst_ChartDataSet::zoomOutDomain_data() | |
557 | { |
|
557 | { | |
558 | zoomInDomain_data(); |
|
558 | zoomInDomain_data(); | |
559 | } |
|
559 | } | |
560 |
|
560 | |||
561 | void tst_ChartDataSet::zoomOutDomain() |
|
561 | void tst_ChartDataSet::zoomOutDomain() | |
562 | { |
|
562 | { | |
563 | QFETCH(bool, sameAxis); |
|
563 | QFETCH(bool, sameAxis); | |
564 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
564 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
565 |
|
565 | |||
566 | foreach(QAbstractSeries* series, seriesList) { |
|
566 | foreach(QAbstractSeries* series, seriesList) { | |
567 | m_dataset->addSeries(series); |
|
567 | m_dataset->addSeries(series); | |
568 | } |
|
568 | } | |
569 |
|
569 | |||
570 | if (sameAxis) |
|
570 | if (sameAxis) | |
571 | m_dataset->createDefaultAxes(); |
|
571 | m_dataset->createDefaultAxes(); | |
572 |
|
572 | |||
573 | QList<QSignalSpy*> spyList; |
|
573 | QList<QSignalSpy*> spyList; | |
574 |
|
574 | |||
575 | foreach(QAbstractSeries* series, seriesList) { |
|
575 | foreach(QAbstractSeries* series, seriesList) { | |
576 | spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
576 | spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
577 | } |
|
577 | } | |
578 |
|
578 | |||
579 | m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); |
|
579 | m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); | |
580 |
|
580 | |||
581 | foreach(QSignalSpy* spy, spyList) { |
|
581 | foreach(QSignalSpy* spy, spyList) { | |
582 | TRY_COMPARE(spy->count(), 1); |
|
582 | TRY_COMPARE(spy->count(), 1); | |
583 | } |
|
583 | } | |
584 |
|
584 | |||
585 | qDeleteAll (spyList); |
|
585 | qDeleteAll (spyList); | |
586 | } |
|
586 | } | |
587 |
|
587 | |||
588 | void tst_ChartDataSet::scrollDomain_data() |
|
588 | void tst_ChartDataSet::scrollDomain_data() | |
589 | { |
|
589 | { | |
590 | zoomInDomain_data(); |
|
590 | zoomInDomain_data(); | |
591 | } |
|
591 | } | |
592 |
|
592 | |||
593 | void tst_ChartDataSet::scrollDomain() |
|
593 | void tst_ChartDataSet::scrollDomain() | |
594 | { |
|
594 | { | |
595 | QFETCH(bool, sameAxis); |
|
595 | QFETCH(bool, sameAxis); | |
596 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
596 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
597 |
|
597 | |||
598 | foreach(QAbstractSeries* series, seriesList) { |
|
598 | foreach(QAbstractSeries* series, seriesList) { | |
599 | m_dataset->addSeries(series); |
|
599 | m_dataset->addSeries(series); | |
600 | } |
|
600 | } | |
601 |
|
601 | |||
602 | if (sameAxis) |
|
602 | if (sameAxis) | |
603 | m_dataset->createDefaultAxes(); |
|
603 | m_dataset->createDefaultAxes(); | |
604 |
|
604 | |||
605 | QList<QSignalSpy*> spyList; |
|
605 | QList<QSignalSpy*> spyList; | |
606 |
|
606 | |||
607 | foreach(QAbstractSeries* series, seriesList) { |
|
607 | foreach(QAbstractSeries* series, seriesList) { | |
608 | spyList |
|
608 | spyList | |
609 | << new QSignalSpy(m_dataset->domain(series), |
|
609 | << new QSignalSpy(m_dataset->domain(series), | |
610 | SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
610 | SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
611 | } |
|
611 | } | |
612 |
|
612 | |||
613 | m_dataset->scrollDomain(10, 10, QSize(1000, 1000)); |
|
613 | m_dataset->scrollDomain(10, 10, QSize(1000, 1000)); | |
614 |
|
614 | |||
615 | foreach(QSignalSpy* spy, spyList) { |
|
615 | foreach(QSignalSpy* spy, spyList) { | |
616 | TRY_COMPARE(spy->count(), 1); |
|
616 | TRY_COMPARE(spy->count(), 1); | |
617 | } |
|
617 | } | |
618 |
|
618 | |||
619 | qDeleteAll(spyList); |
|
619 | qDeleteAll(spyList); | |
620 | } |
|
620 | } | |
621 |
|
621 | |||
622 | QTEST_MAIN(tst_ChartDataSet) |
|
622 | QTEST_MAIN(tst_ChartDataSet) | |
623 | #include "tst_chartdataset.moc" |
|
623 | #include "tst_chartdataset.moc" | |
624 |
|
624 |
@@ -1,614 +1,614 | |||||
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 <QtCore/QString> |
|
21 | #include <QtCore/QString> | |
22 | #include <QtTest/QtTest> |
|
22 | #include <QtTest/QtTest> | |
23 |
|
23 | |||
24 | #include <qchart.h> |
|
24 | #include <qchart.h> | |
25 | #include <qchartview.h> |
|
25 | #include <qchartview.h> | |
26 |
#include <q |
|
26 | #include <qbarseries.h> | |
27 | #include <qbarset.h> |
|
27 | #include <qbarset.h> | |
28 | #include <qvbarmodelmapper.h> |
|
28 | #include <qvbarmodelmapper.h> | |
29 | #include <qhbarmodelmapper.h> |
|
29 | #include <qhbarmodelmapper.h> | |
30 | #include <QStandardItemModel> |
|
30 | #include <QStandardItemModel> | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
32 | QTCOMMERCIALCHART_USE_NAMESPACE | |
33 |
|
33 | |||
34 | class tst_qbarmodelmapper : public QObject |
|
34 | class tst_qbarmodelmapper : public QObject | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 |
|
37 | |||
38 | public: |
|
38 | public: | |
39 | tst_qbarmodelmapper(); |
|
39 | tst_qbarmodelmapper(); | |
40 | void createVerticalMapper(); |
|
40 | void createVerticalMapper(); | |
41 | void createHorizontalMapper(); |
|
41 | void createHorizontalMapper(); | |
42 |
|
42 | |||
43 | private Q_SLOTS: |
|
43 | private Q_SLOTS: | |
44 | void initTestCase(); |
|
44 | void initTestCase(); | |
45 | void cleanupTestCase(); |
|
45 | void cleanupTestCase(); | |
46 | void init(); |
|
46 | void init(); | |
47 | void cleanup(); |
|
47 | void cleanup(); | |
48 | void verticalMapper_data(); |
|
48 | void verticalMapper_data(); | |
49 | void verticalMapper(); |
|
49 | void verticalMapper(); | |
50 | void verticalMapperCustomMapping_data(); |
|
50 | void verticalMapperCustomMapping_data(); | |
51 | void verticalMapperCustomMapping(); |
|
51 | void verticalMapperCustomMapping(); | |
52 | void horizontalMapper_data(); |
|
52 | void horizontalMapper_data(); | |
53 | void horizontalMapper(); |
|
53 | void horizontalMapper(); | |
54 | void horizontalMapperCustomMapping_data(); |
|
54 | void horizontalMapperCustomMapping_data(); | |
55 | void horizontalMapperCustomMapping(); |
|
55 | void horizontalMapperCustomMapping(); | |
56 | void seriesUpdated(); |
|
56 | void seriesUpdated(); | |
57 | void verticalModelInsertRows(); |
|
57 | void verticalModelInsertRows(); | |
58 | void verticalModelRemoveRows(); |
|
58 | void verticalModelRemoveRows(); | |
59 | void verticalModelInsertColumns(); |
|
59 | void verticalModelInsertColumns(); | |
60 | void verticalModelRemoveColumns(); |
|
60 | void verticalModelRemoveColumns(); | |
61 | void horizontalModelInsertRows(); |
|
61 | void horizontalModelInsertRows(); | |
62 | void horizontalModelRemoveRows(); |
|
62 | void horizontalModelRemoveRows(); | |
63 | void horizontalModelInsertColumns(); |
|
63 | void horizontalModelInsertColumns(); | |
64 | void horizontalModelRemoveColumns(); |
|
64 | void horizontalModelRemoveColumns(); | |
65 | void modelUpdateCell(); |
|
65 | void modelUpdateCell(); | |
66 |
|
66 | |||
67 | private: |
|
67 | private: | |
68 | QStandardItemModel *m_model; |
|
68 | QStandardItemModel *m_model; | |
69 | int m_modelRowCount; |
|
69 | int m_modelRowCount; | |
70 | int m_modelColumnCount; |
|
70 | int m_modelColumnCount; | |
71 |
|
71 | |||
72 | QVBarModelMapper *m_vMapper; |
|
72 | QVBarModelMapper *m_vMapper; | |
73 | QHBarModelMapper *m_hMapper; |
|
73 | QHBarModelMapper *m_hMapper; | |
74 |
|
74 | |||
75 |
Q |
|
75 | QBarSeries *m_series; | |
76 | QChart *m_chart; |
|
76 | QChart *m_chart; | |
77 | }; |
|
77 | }; | |
78 |
|
78 | |||
79 | tst_qbarmodelmapper::tst_qbarmodelmapper(): |
|
79 | tst_qbarmodelmapper::tst_qbarmodelmapper(): | |
80 | m_model(0), |
|
80 | m_model(0), | |
81 | m_modelRowCount(10), |
|
81 | m_modelRowCount(10), | |
82 | m_modelColumnCount(8), |
|
82 | m_modelColumnCount(8), | |
83 | m_vMapper(0), |
|
83 | m_vMapper(0), | |
84 | m_hMapper(0), |
|
84 | m_hMapper(0), | |
85 | m_series(0), |
|
85 | m_series(0), | |
86 | m_chart(0) |
|
86 | m_chart(0) | |
87 | { |
|
87 | { | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void tst_qbarmodelmapper::createVerticalMapper() |
|
90 | void tst_qbarmodelmapper::createVerticalMapper() | |
91 | { |
|
91 | { | |
92 | m_vMapper = new QVBarModelMapper; |
|
92 | m_vMapper = new QVBarModelMapper; | |
93 | QVERIFY(m_vMapper->model() == 0); |
|
93 | QVERIFY(m_vMapper->model() == 0); | |
94 | m_vMapper->setFirstBarSetColumn(0); |
|
94 | m_vMapper->setFirstBarSetColumn(0); | |
95 | m_vMapper->setLastBarSetColumn(4); |
|
95 | m_vMapper->setLastBarSetColumn(4); | |
96 | m_vMapper->setModel(m_model); |
|
96 | m_vMapper->setModel(m_model); | |
97 | m_vMapper->setSeries(m_series); |
|
97 | m_vMapper->setSeries(m_series); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | void tst_qbarmodelmapper::createHorizontalMapper() |
|
100 | void tst_qbarmodelmapper::createHorizontalMapper() | |
101 | { |
|
101 | { | |
102 | m_hMapper = new QHBarModelMapper; |
|
102 | m_hMapper = new QHBarModelMapper; | |
103 | QVERIFY(m_hMapper->model() == 0); |
|
103 | QVERIFY(m_hMapper->model() == 0); | |
104 | m_hMapper->setFirstBarSetRow(0); |
|
104 | m_hMapper->setFirstBarSetRow(0); | |
105 | m_hMapper->setLastBarSetRow(4); |
|
105 | m_hMapper->setLastBarSetRow(4); | |
106 | m_hMapper->setModel(m_model); |
|
106 | m_hMapper->setModel(m_model); | |
107 | m_hMapper->setSeries(m_series); |
|
107 | m_hMapper->setSeries(m_series); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | void tst_qbarmodelmapper::init() |
|
110 | void tst_qbarmodelmapper::init() | |
111 | { |
|
111 | { | |
112 |
m_series = new Q |
|
112 | m_series = new QBarSeries; | |
113 | m_chart->addSeries(m_series); |
|
113 | m_chart->addSeries(m_series); | |
114 |
|
114 | |||
115 | m_model = new QStandardItemModel(m_modelRowCount, m_modelColumnCount, this); |
|
115 | m_model = new QStandardItemModel(m_modelRowCount, m_modelColumnCount, this); | |
116 | for (int row = 0; row < m_modelRowCount; ++row) { |
|
116 | for (int row = 0; row < m_modelRowCount; ++row) { | |
117 | for (int column = 0; column < m_modelColumnCount; column++) { |
|
117 | for (int column = 0; column < m_modelColumnCount; column++) { | |
118 | m_model->setData(m_model->index(row, column), row * column); |
|
118 | m_model->setData(m_model->index(row, column), row * column); | |
119 | } |
|
119 | } | |
120 | } |
|
120 | } | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | void tst_qbarmodelmapper::cleanup() |
|
123 | void tst_qbarmodelmapper::cleanup() | |
124 | { |
|
124 | { | |
125 | m_chart->removeSeries(m_series); |
|
125 | m_chart->removeSeries(m_series); | |
126 | delete m_series; |
|
126 | delete m_series; | |
127 | m_series = 0; |
|
127 | m_series = 0; | |
128 |
|
128 | |||
129 | m_model->clear(); |
|
129 | m_model->clear(); | |
130 | m_model->deleteLater(); |
|
130 | m_model->deleteLater(); | |
131 | m_model = 0; |
|
131 | m_model = 0; | |
132 |
|
132 | |||
133 | if (m_vMapper) { |
|
133 | if (m_vMapper) { | |
134 | m_vMapper->deleteLater(); |
|
134 | m_vMapper->deleteLater(); | |
135 | m_vMapper = 0; |
|
135 | m_vMapper = 0; | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | if (m_hMapper) { |
|
138 | if (m_hMapper) { | |
139 | m_hMapper->deleteLater(); |
|
139 | m_hMapper->deleteLater(); | |
140 | m_hMapper = 0; |
|
140 | m_hMapper = 0; | |
141 | } |
|
141 | } | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | void tst_qbarmodelmapper::initTestCase() |
|
144 | void tst_qbarmodelmapper::initTestCase() | |
145 | { |
|
145 | { | |
146 | m_chart = new QChart; |
|
146 | m_chart = new QChart; | |
147 | QChartView *chartView = new QChartView(m_chart); |
|
147 | QChartView *chartView = new QChartView(m_chart); | |
148 | chartView->show(); |
|
148 | chartView->show(); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void tst_qbarmodelmapper::cleanupTestCase() |
|
151 | void tst_qbarmodelmapper::cleanupTestCase() | |
152 | { |
|
152 | { | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | void tst_qbarmodelmapper::verticalMapper_data() |
|
155 | void tst_qbarmodelmapper::verticalMapper_data() | |
156 | { |
|
156 | { | |
157 | QTest::addColumn<int>("firstBarSetColumn"); |
|
157 | QTest::addColumn<int>("firstBarSetColumn"); | |
158 | QTest::addColumn<int>("lastBarSetColumn"); |
|
158 | QTest::addColumn<int>("lastBarSetColumn"); | |
159 | QTest::addColumn<int>("expectedBarSetCount"); |
|
159 | QTest::addColumn<int>("expectedBarSetCount"); | |
160 | QTest::newRow("lastBarSetColumn greater than firstBarSetColumn") << 0 << 1 << 2; |
|
160 | QTest::newRow("lastBarSetColumn greater than firstBarSetColumn") << 0 << 1 << 2; | |
161 | QTest::newRow("lastBarSetColumn equal to firstBarSetColumn") << 1 << 1 << 1; |
|
161 | QTest::newRow("lastBarSetColumn equal to firstBarSetColumn") << 1 << 1 << 1; | |
162 | QTest::newRow("lastBarSetColumn lesser than firstBarSetColumn") << 1 << 0 << 0; |
|
162 | QTest::newRow("lastBarSetColumn lesser than firstBarSetColumn") << 1 << 0 << 0; | |
163 | QTest::newRow("invalid firstBarSetColumn and correct lastBarSetColumn") << -3 << 1 << 0; |
|
163 | QTest::newRow("invalid firstBarSetColumn and correct lastBarSetColumn") << -3 << 1 << 0; | |
164 | QTest::newRow("firstBarSetColumn beyond the size of model and correct lastBarSetColumn") << m_modelColumnCount << 1 << 0; |
|
164 | QTest::newRow("firstBarSetColumn beyond the size of model and correct lastBarSetColumn") << m_modelColumnCount << 1 << 0; | |
165 | QTest::newRow("firstBarSetColumn beyond the size of model and invalid lastBarSetColumn") << m_modelColumnCount << -1 << 0; |
|
165 | QTest::newRow("firstBarSetColumn beyond the size of model and invalid lastBarSetColumn") << m_modelColumnCount << -1 << 0; | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void tst_qbarmodelmapper::verticalMapper() |
|
168 | void tst_qbarmodelmapper::verticalMapper() | |
169 | { |
|
169 | { | |
170 | QFETCH(int, firstBarSetColumn); |
|
170 | QFETCH(int, firstBarSetColumn); | |
171 | QFETCH(int, lastBarSetColumn); |
|
171 | QFETCH(int, lastBarSetColumn); | |
172 | QFETCH(int, expectedBarSetCount); |
|
172 | QFETCH(int, expectedBarSetCount); | |
173 |
|
173 | |||
174 |
m_series = new Q |
|
174 | m_series = new QBarSeries; | |
175 |
|
175 | |||
176 | QVBarModelMapper *mapper = new QVBarModelMapper; |
|
176 | QVBarModelMapper *mapper = new QVBarModelMapper; | |
177 | mapper->setFirstBarSetColumn(firstBarSetColumn); |
|
177 | mapper->setFirstBarSetColumn(firstBarSetColumn); | |
178 | mapper->setLastBarSetColumn(lastBarSetColumn); |
|
178 | mapper->setLastBarSetColumn(lastBarSetColumn); | |
179 | mapper->setModel(m_model); |
|
179 | mapper->setModel(m_model); | |
180 | mapper->setSeries(m_series); |
|
180 | mapper->setSeries(m_series); | |
181 |
|
181 | |||
182 | m_chart->addSeries(m_series); |
|
182 | m_chart->addSeries(m_series); | |
183 |
|
183 | |||
184 | QCOMPARE(m_series->count(), expectedBarSetCount); |
|
184 | QCOMPARE(m_series->count(), expectedBarSetCount); | |
185 | QCOMPARE(mapper->firstBarSetColumn(), qMax(-1, firstBarSetColumn)); |
|
185 | QCOMPARE(mapper->firstBarSetColumn(), qMax(-1, firstBarSetColumn)); | |
186 | QCOMPARE(mapper->lastBarSetColumn(), qMax(-1, lastBarSetColumn)); |
|
186 | QCOMPARE(mapper->lastBarSetColumn(), qMax(-1, lastBarSetColumn)); | |
187 |
|
187 | |||
188 | delete mapper; |
|
188 | delete mapper; | |
189 | mapper = 0; |
|
189 | mapper = 0; | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | void tst_qbarmodelmapper::verticalMapperCustomMapping_data() |
|
192 | void tst_qbarmodelmapper::verticalMapperCustomMapping_data() | |
193 | { |
|
193 | { | |
194 | QTest::addColumn<int>("first"); |
|
194 | QTest::addColumn<int>("first"); | |
195 | QTest::addColumn<int>("countLimit"); |
|
195 | QTest::addColumn<int>("countLimit"); | |
196 | QTest::addColumn<int>("expectedBarSetCount"); |
|
196 | QTest::addColumn<int>("expectedBarSetCount"); | |
197 | QTest::addColumn<int>("expectedCount"); |
|
197 | QTest::addColumn<int>("expectedCount"); | |
198 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelRowCount; |
|
198 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelRowCount; | |
199 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelRowCount - 3; |
|
199 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelRowCount - 3; | |
200 | QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelRowCount); |
|
200 | QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelRowCount); | |
201 | QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelRowCount - 3); |
|
201 | QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelRowCount - 3); | |
202 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0 << 0; |
|
202 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0 << 0; | |
203 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0 << 0; |
|
203 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0 << 0; | |
204 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << 2 << m_modelRowCount; |
|
204 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << 2 << m_modelRowCount; | |
205 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelRowCount; |
|
205 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelRowCount; | |
206 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelRowCount; |
|
206 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelRowCount; | |
207 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelRowCount; |
|
207 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelRowCount; | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | void tst_qbarmodelmapper::verticalMapperCustomMapping() |
|
210 | void tst_qbarmodelmapper::verticalMapperCustomMapping() | |
211 | { |
|
211 | { | |
212 | QFETCH(int, first); |
|
212 | QFETCH(int, first); | |
213 | QFETCH(int, countLimit); |
|
213 | QFETCH(int, countLimit); | |
214 | QFETCH(int, expectedBarSetCount); |
|
214 | QFETCH(int, expectedBarSetCount); | |
215 | QFETCH(int, expectedCount); |
|
215 | QFETCH(int, expectedCount); | |
216 |
|
216 | |||
217 |
m_series = new Q |
|
217 | m_series = new QBarSeries; | |
218 |
|
218 | |||
219 | QCOMPARE(m_series->count(), 0); |
|
219 | QCOMPARE(m_series->count(), 0); | |
220 |
|
220 | |||
221 | QVBarModelMapper *mapper = new QVBarModelMapper; |
|
221 | QVBarModelMapper *mapper = new QVBarModelMapper; | |
222 | mapper->setFirstBarSetColumn(0); |
|
222 | mapper->setFirstBarSetColumn(0); | |
223 | mapper->setLastBarSetColumn(1); |
|
223 | mapper->setLastBarSetColumn(1); | |
224 | mapper->setModel(m_model); |
|
224 | mapper->setModel(m_model); | |
225 | mapper->setSeries(m_series); |
|
225 | mapper->setSeries(m_series); | |
226 | mapper->setFirstRow(first); |
|
226 | mapper->setFirstRow(first); | |
227 | mapper->setRowCount(countLimit); |
|
227 | mapper->setRowCount(countLimit); | |
228 | m_chart->addSeries(m_series); |
|
228 | m_chart->addSeries(m_series); | |
229 |
|
229 | |||
230 | QCOMPARE(m_series->count(), expectedBarSetCount); |
|
230 | QCOMPARE(m_series->count(), expectedBarSetCount); | |
231 |
|
231 | |||
232 | if (expectedBarSetCount > 0) |
|
232 | if (expectedBarSetCount > 0) | |
233 | QCOMPARE(m_series->barSets().first()->count(), expectedCount); |
|
233 | QCOMPARE(m_series->barSets().first()->count(), expectedCount); | |
234 |
|
234 | |||
235 | // change values column mapping to invalid |
|
235 | // change values column mapping to invalid | |
236 | mapper->setFirstBarSetColumn(-1); |
|
236 | mapper->setFirstBarSetColumn(-1); | |
237 | mapper->setLastBarSetColumn(1); |
|
237 | mapper->setLastBarSetColumn(1); | |
238 |
|
238 | |||
239 | QCOMPARE(m_series->count(), 0); |
|
239 | QCOMPARE(m_series->count(), 0); | |
240 |
|
240 | |||
241 | delete mapper; |
|
241 | delete mapper; | |
242 | mapper = 0; |
|
242 | mapper = 0; | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | void tst_qbarmodelmapper::horizontalMapper_data() |
|
245 | void tst_qbarmodelmapper::horizontalMapper_data() | |
246 | { |
|
246 | { | |
247 | QTest::addColumn<int>("firstBarSetRow"); |
|
247 | QTest::addColumn<int>("firstBarSetRow"); | |
248 | QTest::addColumn<int>("lastBarSetRow"); |
|
248 | QTest::addColumn<int>("lastBarSetRow"); | |
249 | QTest::addColumn<int>("expectedBarSetCount"); |
|
249 | QTest::addColumn<int>("expectedBarSetCount"); | |
250 | QTest::newRow("lastBarSetRow greater than firstBarSetRow") << 0 << 1 << 2; |
|
250 | QTest::newRow("lastBarSetRow greater than firstBarSetRow") << 0 << 1 << 2; | |
251 | QTest::newRow("lastBarSetRow equal to firstBarSetRow") << 1 << 1 << 1; |
|
251 | QTest::newRow("lastBarSetRow equal to firstBarSetRow") << 1 << 1 << 1; | |
252 | QTest::newRow("lastBarSetRow lesser than firstBarSetRow") << 1 << 0 << 0; |
|
252 | QTest::newRow("lastBarSetRow lesser than firstBarSetRow") << 1 << 0 << 0; | |
253 | QTest::newRow("invalid firstBarSetRow and correct lastBarSetRow") << -3 << 1 << 0; |
|
253 | QTest::newRow("invalid firstBarSetRow and correct lastBarSetRow") << -3 << 1 << 0; | |
254 | QTest::newRow("firstBarSetRow beyond the size of model and correct lastBarSetRow") << m_modelRowCount << 1 << 0; |
|
254 | QTest::newRow("firstBarSetRow beyond the size of model and correct lastBarSetRow") << m_modelRowCount << 1 << 0; | |
255 | QTest::newRow("firstBarSetRow beyond the size of model and invalid lastBarSetRow") << m_modelRowCount << -1 << 0; |
|
255 | QTest::newRow("firstBarSetRow beyond the size of model and invalid lastBarSetRow") << m_modelRowCount << -1 << 0; | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | void tst_qbarmodelmapper::horizontalMapper() |
|
258 | void tst_qbarmodelmapper::horizontalMapper() | |
259 | { |
|
259 | { | |
260 | QFETCH(int, firstBarSetRow); |
|
260 | QFETCH(int, firstBarSetRow); | |
261 | QFETCH(int, lastBarSetRow); |
|
261 | QFETCH(int, lastBarSetRow); | |
262 | QFETCH(int, expectedBarSetCount); |
|
262 | QFETCH(int, expectedBarSetCount); | |
263 |
|
263 | |||
264 |
m_series = new Q |
|
264 | m_series = new QBarSeries; | |
265 |
|
265 | |||
266 | QHBarModelMapper *mapper = new QHBarModelMapper; |
|
266 | QHBarModelMapper *mapper = new QHBarModelMapper; | |
267 | mapper->setFirstBarSetRow(firstBarSetRow); |
|
267 | mapper->setFirstBarSetRow(firstBarSetRow); | |
268 | mapper->setLastBarSetRow(lastBarSetRow); |
|
268 | mapper->setLastBarSetRow(lastBarSetRow); | |
269 | mapper->setModel(m_model); |
|
269 | mapper->setModel(m_model); | |
270 | mapper->setSeries(m_series); |
|
270 | mapper->setSeries(m_series); | |
271 |
|
271 | |||
272 | m_chart->addSeries(m_series); |
|
272 | m_chart->addSeries(m_series); | |
273 |
|
273 | |||
274 | QCOMPARE(m_series->count(), expectedBarSetCount); |
|
274 | QCOMPARE(m_series->count(), expectedBarSetCount); | |
275 | QCOMPARE(mapper->firstBarSetRow(), qMax(-1, firstBarSetRow)); |
|
275 | QCOMPARE(mapper->firstBarSetRow(), qMax(-1, firstBarSetRow)); | |
276 | QCOMPARE(mapper->lastBarSetRow(), qMax(-1, lastBarSetRow)); |
|
276 | QCOMPARE(mapper->lastBarSetRow(), qMax(-1, lastBarSetRow)); | |
277 |
|
277 | |||
278 | delete mapper; |
|
278 | delete mapper; | |
279 | mapper = 0; |
|
279 | mapper = 0; | |
280 | } |
|
280 | } | |
281 |
|
281 | |||
282 | void tst_qbarmodelmapper::horizontalMapperCustomMapping_data() |
|
282 | void tst_qbarmodelmapper::horizontalMapperCustomMapping_data() | |
283 | { |
|
283 | { | |
284 | QTest::addColumn<int>("first"); |
|
284 | QTest::addColumn<int>("first"); | |
285 | QTest::addColumn<int>("countLimit"); |
|
285 | QTest::addColumn<int>("countLimit"); | |
286 | QTest::addColumn<int>("expectedBarSetCount"); |
|
286 | QTest::addColumn<int>("expectedBarSetCount"); | |
287 | QTest::addColumn<int>("expectedCount"); |
|
287 | QTest::addColumn<int>("expectedCount"); | |
288 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelColumnCount; |
|
288 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelColumnCount; | |
289 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelColumnCount - 3; |
|
289 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelColumnCount - 3; | |
290 | QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelColumnCount); |
|
290 | QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelColumnCount); | |
291 | QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelColumnCount - 3); |
|
291 | QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelColumnCount - 3); | |
292 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0 << 0; |
|
292 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0 << 0; | |
293 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0 << 0; |
|
293 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0 << 0; | |
294 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << 2 << m_modelColumnCount; |
|
294 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << 2 << m_modelColumnCount; | |
295 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelColumnCount; |
|
295 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelColumnCount; | |
296 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelColumnCount; |
|
296 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelColumnCount; | |
297 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelColumnCount; |
|
297 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelColumnCount; | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | void tst_qbarmodelmapper::horizontalMapperCustomMapping() |
|
300 | void tst_qbarmodelmapper::horizontalMapperCustomMapping() | |
301 | { |
|
301 | { | |
302 | QFETCH(int, first); |
|
302 | QFETCH(int, first); | |
303 | QFETCH(int, countLimit); |
|
303 | QFETCH(int, countLimit); | |
304 | QFETCH(int, expectedBarSetCount); |
|
304 | QFETCH(int, expectedBarSetCount); | |
305 | QFETCH(int, expectedCount); |
|
305 | QFETCH(int, expectedCount); | |
306 |
|
306 | |||
307 |
m_series = new Q |
|
307 | m_series = new QBarSeries; | |
308 |
|
308 | |||
309 | QCOMPARE(m_series->count(), 0); |
|
309 | QCOMPARE(m_series->count(), 0); | |
310 |
|
310 | |||
311 | QHBarModelMapper *mapper = new QHBarModelMapper; |
|
311 | QHBarModelMapper *mapper = new QHBarModelMapper; | |
312 | mapper->setFirstBarSetRow(0); |
|
312 | mapper->setFirstBarSetRow(0); | |
313 | mapper->setLastBarSetRow(1); |
|
313 | mapper->setLastBarSetRow(1); | |
314 | mapper->setModel(m_model); |
|
314 | mapper->setModel(m_model); | |
315 | mapper->setSeries(m_series); |
|
315 | mapper->setSeries(m_series); | |
316 | mapper->setFirstColumn(first); |
|
316 | mapper->setFirstColumn(first); | |
317 | mapper->setColumnCount(countLimit); |
|
317 | mapper->setColumnCount(countLimit); | |
318 | m_chart->addSeries(m_series); |
|
318 | m_chart->addSeries(m_series); | |
319 |
|
319 | |||
320 | QCOMPARE(m_series->count(), expectedBarSetCount); |
|
320 | QCOMPARE(m_series->count(), expectedBarSetCount); | |
321 |
|
321 | |||
322 | if (expectedBarSetCount > 0) |
|
322 | if (expectedBarSetCount > 0) | |
323 | QCOMPARE(m_series->barSets().first()->count(), expectedCount); |
|
323 | QCOMPARE(m_series->barSets().first()->count(), expectedCount); | |
324 |
|
324 | |||
325 | // change values column mapping to invalid |
|
325 | // change values column mapping to invalid | |
326 | mapper->setFirstBarSetRow(-1); |
|
326 | mapper->setFirstBarSetRow(-1); | |
327 | mapper->setLastBarSetRow(1); |
|
327 | mapper->setLastBarSetRow(1); | |
328 |
|
328 | |||
329 | QCOMPARE(m_series->count(), 0); |
|
329 | QCOMPARE(m_series->count(), 0); | |
330 |
|
330 | |||
331 | delete mapper; |
|
331 | delete mapper; | |
332 | mapper = 0; |
|
332 | mapper = 0; | |
333 | } |
|
333 | } | |
334 |
|
334 | |||
335 | void tst_qbarmodelmapper::seriesUpdated() |
|
335 | void tst_qbarmodelmapper::seriesUpdated() | |
336 | { |
|
336 | { | |
337 | // setup the mapper |
|
337 | // setup the mapper | |
338 | createVerticalMapper(); |
|
338 | createVerticalMapper(); | |
339 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
339 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
340 | QCOMPARE(m_vMapper->rowCount(), -1); |
|
340 | QCOMPARE(m_vMapper->rowCount(), -1); | |
341 |
|
341 | |||
342 | m_series->barSets().first()->append(123); |
|
342 | m_series->barSets().first()->append(123); | |
343 | QCOMPARE(m_model->rowCount(), m_modelRowCount + 1); |
|
343 | QCOMPARE(m_model->rowCount(), m_modelRowCount + 1); | |
344 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model |
|
344 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model | |
345 |
|
345 | |||
346 | m_series->barSets().last()->remove(0, m_modelRowCount); |
|
346 | m_series->barSets().last()->remove(0, m_modelRowCount); | |
347 | QCOMPARE(m_model->rowCount(), 1); |
|
347 | QCOMPARE(m_model->rowCount(), 1); | |
348 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model |
|
348 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model | |
349 |
|
349 | |||
350 | m_series->barSets().first()->replace(0, 444.0); |
|
350 | m_series->barSets().first()->replace(0, 444.0); | |
351 | QCOMPARE(m_model->data(m_model->index(0, 0)).toReal(), 444.0); |
|
351 | QCOMPARE(m_model->data(m_model->index(0, 0)).toReal(), 444.0); | |
352 |
|
352 | |||
353 | m_series->barSets().first()->setLabel("Hello"); |
|
353 | m_series->barSets().first()->setLabel("Hello"); | |
354 | QCOMPARE(m_model->headerData(0, Qt::Horizontal).toString(), QString("Hello")); |
|
354 | QCOMPARE(m_model->headerData(0, Qt::Horizontal).toString(), QString("Hello")); | |
355 |
|
355 | |||
356 | QList<qreal> newValues; |
|
356 | QList<qreal> newValues; | |
357 | newValues << 15 << 27 << 35 << 49; |
|
357 | newValues << 15 << 27 << 35 << 49; | |
358 | m_series->barSets().first()->append(newValues); |
|
358 | m_series->barSets().first()->append(newValues); | |
359 | QCOMPARE(m_model->rowCount(), 1 + newValues.count()); |
|
359 | QCOMPARE(m_model->rowCount(), 1 + newValues.count()); | |
360 |
|
360 | |||
361 | QList<QBarSet* > newBarSets; |
|
361 | QList<QBarSet* > newBarSets; | |
362 | QBarSet* newBarSet_1 = new QBarSet("New_1"); |
|
362 | QBarSet* newBarSet_1 = new QBarSet("New_1"); | |
363 | newBarSet_1->append(101); |
|
363 | newBarSet_1->append(101); | |
364 | newBarSet_1->append(102); |
|
364 | newBarSet_1->append(102); | |
365 | newBarSet_1->append(103); |
|
365 | newBarSet_1->append(103); | |
366 | newBarSets.append(newBarSet_1); |
|
366 | newBarSets.append(newBarSet_1); | |
367 |
|
367 | |||
368 | QBarSet* newBarSet_2 = new QBarSet("New_1"); |
|
368 | QBarSet* newBarSet_2 = new QBarSet("New_1"); | |
369 | newBarSet_2->append(201); |
|
369 | newBarSet_2->append(201); | |
370 | newBarSet_2->append(202); |
|
370 | newBarSet_2->append(202); | |
371 | newBarSet_2->append(203); |
|
371 | newBarSet_2->append(203); | |
372 | newBarSets.append(newBarSet_2); |
|
372 | newBarSets.append(newBarSet_2); | |
373 |
|
373 | |||
374 | m_series->append(newBarSets); |
|
374 | m_series->append(newBarSets); | |
375 | QCOMPARE(m_model->columnCount(), m_modelColumnCount + newBarSets.count()); |
|
375 | QCOMPARE(m_model->columnCount(), m_modelColumnCount + newBarSets.count()); | |
376 | } |
|
376 | } | |
377 |
|
377 | |||
378 | void tst_qbarmodelmapper::verticalModelInsertRows() |
|
378 | void tst_qbarmodelmapper::verticalModelInsertRows() | |
379 | { |
|
379 | { | |
380 | // setup the mapper |
|
380 | // setup the mapper | |
381 | createVerticalMapper(); |
|
381 | createVerticalMapper(); | |
382 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
382 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
383 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
383 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
384 | QVERIFY(m_vMapper->model() != 0); |
|
384 | QVERIFY(m_vMapper->model() != 0); | |
385 |
|
385 | |||
386 | int insertCount = 4; |
|
386 | int insertCount = 4; | |
387 | m_model->insertRows(3, insertCount); |
|
387 | m_model->insertRows(3, insertCount); | |
388 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
388 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
389 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + insertCount); |
|
389 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + insertCount); | |
390 |
|
390 | |||
391 | int first = 3; |
|
391 | int first = 3; | |
392 | m_vMapper->setFirstRow(3); |
|
392 | m_vMapper->setFirstRow(3); | |
393 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
393 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
394 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + insertCount - first); |
|
394 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + insertCount - first); | |
395 |
|
395 | |||
396 | m_model->insertRows(3, insertCount); |
|
396 | m_model->insertRows(3, insertCount); | |
397 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
397 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
398 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + 2 * insertCount - first); |
|
398 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + 2 * insertCount - first); | |
399 |
|
399 | |||
400 | int countLimit = 6; |
|
400 | int countLimit = 6; | |
401 | m_vMapper->setRowCount(countLimit); |
|
401 | m_vMapper->setRowCount(countLimit); | |
402 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
402 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
403 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 2 * insertCount - first)); |
|
403 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 2 * insertCount - first)); | |
404 |
|
404 | |||
405 | m_model->insertRows(3, insertCount); |
|
405 | m_model->insertRows(3, insertCount); | |
406 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
406 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
407 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount - first)); |
|
407 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount - first)); | |
408 |
|
408 | |||
409 | m_vMapper->setFirstRow(0); |
|
409 | m_vMapper->setFirstRow(0); | |
410 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
410 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
411 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount)); |
|
411 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount)); | |
412 |
|
412 | |||
413 | m_vMapper->setRowCount(-1); |
|
413 | m_vMapper->setRowCount(-1); | |
414 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
414 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
415 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + 3 * insertCount); |
|
415 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + 3 * insertCount); | |
416 | } |
|
416 | } | |
417 |
|
417 | |||
418 | void tst_qbarmodelmapper::verticalModelRemoveRows() |
|
418 | void tst_qbarmodelmapper::verticalModelRemoveRows() | |
419 | { |
|
419 | { | |
420 | // setup the mapper |
|
420 | // setup the mapper | |
421 | createVerticalMapper(); |
|
421 | createVerticalMapper(); | |
422 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
422 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
423 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
423 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
424 | QVERIFY(m_vMapper->model() != 0); |
|
424 | QVERIFY(m_vMapper->model() != 0); | |
425 |
|
425 | |||
426 | int removeCount = 2; |
|
426 | int removeCount = 2; | |
427 | m_model->removeRows(1, removeCount); |
|
427 | m_model->removeRows(1, removeCount); | |
428 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
428 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
429 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - removeCount); |
|
429 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - removeCount); | |
430 |
|
430 | |||
431 | int first = 1; |
|
431 | int first = 1; | |
432 | m_vMapper->setFirstRow(first); |
|
432 | m_vMapper->setFirstRow(first); | |
433 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
433 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
434 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - removeCount - first); |
|
434 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - removeCount - first); | |
435 |
|
435 | |||
436 | m_model->removeRows(1, removeCount); |
|
436 | m_model->removeRows(1, removeCount); | |
437 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
437 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
438 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - 2 * removeCount - first); |
|
438 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - 2 * removeCount - first); | |
439 |
|
439 | |||
440 | int countLimit = 3; |
|
440 | int countLimit = 3; | |
441 | m_vMapper->setRowCount(countLimit); |
|
441 | m_vMapper->setRowCount(countLimit); | |
442 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
442 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
443 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 2 * removeCount - first)); |
|
443 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 2 * removeCount - first)); | |
444 |
|
444 | |||
445 | m_model->removeRows(1, removeCount); |
|
445 | m_model->removeRows(1, removeCount); | |
446 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
446 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
447 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount - first)); |
|
447 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount - first)); | |
448 |
|
448 | |||
449 | m_vMapper->setFirstRow(0); |
|
449 | m_vMapper->setFirstRow(0); | |
450 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
450 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
451 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount)); |
|
451 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount)); | |
452 |
|
452 | |||
453 | m_vMapper->setRowCount(-1); |
|
453 | m_vMapper->setRowCount(-1); | |
454 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
454 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
455 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - 3 * removeCount); |
|
455 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - 3 * removeCount); | |
456 | } |
|
456 | } | |
457 |
|
457 | |||
458 | void tst_qbarmodelmapper::verticalModelInsertColumns() |
|
458 | void tst_qbarmodelmapper::verticalModelInsertColumns() | |
459 | { |
|
459 | { | |
460 | // setup the mapper |
|
460 | // setup the mapper | |
461 | createVerticalMapper(); |
|
461 | createVerticalMapper(); | |
462 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
462 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
463 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
463 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
464 | QVERIFY(m_vMapper->model() != 0); |
|
464 | QVERIFY(m_vMapper->model() != 0); | |
465 |
|
465 | |||
466 | int insertCount = 4; |
|
466 | int insertCount = 4; | |
467 | m_model->insertColumns(3, insertCount); |
|
467 | m_model->insertColumns(3, insertCount); | |
468 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
468 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
469 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
469 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
470 | } |
|
470 | } | |
471 |
|
471 | |||
472 | void tst_qbarmodelmapper::verticalModelRemoveColumns() |
|
472 | void tst_qbarmodelmapper::verticalModelRemoveColumns() | |
473 | { |
|
473 | { | |
474 | // setup the mapper |
|
474 | // setup the mapper | |
475 | createVerticalMapper(); |
|
475 | createVerticalMapper(); | |
476 | QCOMPARE(m_series->count(), qMin(m_model->columnCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1)); |
|
476 | QCOMPARE(m_series->count(), qMin(m_model->columnCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1)); | |
477 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
477 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
478 | QVERIFY(m_vMapper->model() != 0); |
|
478 | QVERIFY(m_vMapper->model() != 0); | |
479 |
|
479 | |||
480 | int removeCount = m_modelColumnCount - 2; |
|
480 | int removeCount = m_modelColumnCount - 2; | |
481 | m_model->removeColumns(0, removeCount); |
|
481 | m_model->removeColumns(0, removeCount); | |
482 | QCOMPARE(m_series->count(), qMin(m_model->columnCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1)); |
|
482 | QCOMPARE(m_series->count(), qMin(m_model->columnCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1)); | |
483 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
483 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
484 |
|
484 | |||
485 | // leave all the columns |
|
485 | // leave all the columns | |
486 | m_model->removeColumns(0, m_modelColumnCount - removeCount); |
|
486 | m_model->removeColumns(0, m_modelColumnCount - removeCount); | |
487 | QCOMPARE(m_series->count(), 0); |
|
487 | QCOMPARE(m_series->count(), 0); | |
488 | } |
|
488 | } | |
489 |
|
489 | |||
490 | void tst_qbarmodelmapper::horizontalModelInsertRows() |
|
490 | void tst_qbarmodelmapper::horizontalModelInsertRows() | |
491 | { |
|
491 | { | |
492 | // setup the mapper |
|
492 | // setup the mapper | |
493 | createHorizontalMapper(); |
|
493 | createHorizontalMapper(); | |
494 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
494 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
495 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
495 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); | |
496 | QVERIFY(m_hMapper->model() != 0); |
|
496 | QVERIFY(m_hMapper->model() != 0); | |
497 |
|
497 | |||
498 | int insertCount = 4; |
|
498 | int insertCount = 4; | |
499 | m_model->insertRows(3, insertCount); |
|
499 | m_model->insertRows(3, insertCount); | |
500 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
500 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
501 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
501 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); | |
502 | } |
|
502 | } | |
503 |
|
503 | |||
504 | void tst_qbarmodelmapper::horizontalModelRemoveRows() |
|
504 | void tst_qbarmodelmapper::horizontalModelRemoveRows() | |
505 | { |
|
505 | { | |
506 | // setup the mapper |
|
506 | // setup the mapper | |
507 | createHorizontalMapper(); |
|
507 | createHorizontalMapper(); | |
508 | QCOMPARE(m_series->count(), qMin(m_model->rowCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1)); |
|
508 | QCOMPARE(m_series->count(), qMin(m_model->rowCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1)); | |
509 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
509 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); | |
510 | QVERIFY(m_hMapper->model() != 0); |
|
510 | QVERIFY(m_hMapper->model() != 0); | |
511 |
|
511 | |||
512 | int removeCount = m_modelRowCount - 2; |
|
512 | int removeCount = m_modelRowCount - 2; | |
513 | m_model->removeRows(0, removeCount); |
|
513 | m_model->removeRows(0, removeCount); | |
514 | QCOMPARE(m_series->count(), qMin(m_model->rowCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1)); |
|
514 | QCOMPARE(m_series->count(), qMin(m_model->rowCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1)); | |
515 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
515 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); | |
516 |
|
516 | |||
517 | // leave all the columns |
|
517 | // leave all the columns | |
518 | m_model->removeRows(0, m_modelRowCount - removeCount); |
|
518 | m_model->removeRows(0, m_modelRowCount - removeCount); | |
519 | QCOMPARE(m_series->count(), 0); |
|
519 | QCOMPARE(m_series->count(), 0); | |
520 | } |
|
520 | } | |
521 |
|
521 | |||
522 | void tst_qbarmodelmapper::horizontalModelInsertColumns() |
|
522 | void tst_qbarmodelmapper::horizontalModelInsertColumns() | |
523 | { |
|
523 | { | |
524 | // setup the mapper |
|
524 | // setup the mapper | |
525 | createHorizontalMapper(); |
|
525 | createHorizontalMapper(); | |
526 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
526 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
527 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
527 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); | |
528 | QVERIFY(m_hMapper->model() != 0); |
|
528 | QVERIFY(m_hMapper->model() != 0); | |
529 |
|
529 | |||
530 | int insertCount = 4; |
|
530 | int insertCount = 4; | |
531 | m_model->insertColumns(3, insertCount); |
|
531 | m_model->insertColumns(3, insertCount); | |
532 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
532 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
533 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + insertCount); |
|
533 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + insertCount); | |
534 |
|
534 | |||
535 | int first = 3; |
|
535 | int first = 3; | |
536 | m_hMapper->setFirstColumn(3); |
|
536 | m_hMapper->setFirstColumn(3); | |
537 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
537 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
538 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + insertCount - first); |
|
538 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + insertCount - first); | |
539 |
|
539 | |||
540 | m_model->insertColumns(3, insertCount); |
|
540 | m_model->insertColumns(3, insertCount); | |
541 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
541 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
542 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + 2 * insertCount - first); |
|
542 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + 2 * insertCount - first); | |
543 |
|
543 | |||
544 | int countLimit = 6; |
|
544 | int countLimit = 6; | |
545 | m_hMapper->setColumnCount(countLimit); |
|
545 | m_hMapper->setColumnCount(countLimit); | |
546 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
546 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
547 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 2 * insertCount - first)); |
|
547 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 2 * insertCount - first)); | |
548 |
|
548 | |||
549 | m_model->insertColumns(3, insertCount); |
|
549 | m_model->insertColumns(3, insertCount); | |
550 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
550 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
551 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount - first)); |
|
551 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount - first)); | |
552 |
|
552 | |||
553 | m_hMapper->setFirstColumn(0); |
|
553 | m_hMapper->setFirstColumn(0); | |
554 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
554 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
555 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount)); |
|
555 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount)); | |
556 |
|
556 | |||
557 | m_hMapper->setColumnCount(-1); |
|
557 | m_hMapper->setColumnCount(-1); | |
558 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
558 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
559 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + 3 * insertCount); |
|
559 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + 3 * insertCount); | |
560 | } |
|
560 | } | |
561 |
|
561 | |||
562 | void tst_qbarmodelmapper::horizontalModelRemoveColumns() |
|
562 | void tst_qbarmodelmapper::horizontalModelRemoveColumns() | |
563 | { |
|
563 | { | |
564 | // setup the mapper |
|
564 | // setup the mapper | |
565 | createHorizontalMapper(); |
|
565 | createHorizontalMapper(); | |
566 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
566 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
567 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
567 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); | |
568 | QVERIFY(m_hMapper->model() != 0); |
|
568 | QVERIFY(m_hMapper->model() != 0); | |
569 |
|
569 | |||
570 | int removeCount = 2; |
|
570 | int removeCount = 2; | |
571 | m_model->removeColumns(1, removeCount); |
|
571 | m_model->removeColumns(1, removeCount); | |
572 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
572 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
573 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - removeCount); |
|
573 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - removeCount); | |
574 |
|
574 | |||
575 | int first = 1; |
|
575 | int first = 1; | |
576 | m_hMapper->setFirstColumn(first); |
|
576 | m_hMapper->setFirstColumn(first); | |
577 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
577 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
578 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - removeCount - first); |
|
578 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - removeCount - first); | |
579 |
|
579 | |||
580 | m_model->removeColumns(1, removeCount); |
|
580 | m_model->removeColumns(1, removeCount); | |
581 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
581 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
582 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - 2 * removeCount - first); |
|
582 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - 2 * removeCount - first); | |
583 |
|
583 | |||
584 | int countLimit = 3; |
|
584 | int countLimit = 3; | |
585 | m_hMapper->setColumnCount(countLimit); |
|
585 | m_hMapper->setColumnCount(countLimit); | |
586 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
586 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
587 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 2 * removeCount - first)); |
|
587 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 2 * removeCount - first)); | |
588 |
|
588 | |||
589 | m_model->removeColumns(1, removeCount); |
|
589 | m_model->removeColumns(1, removeCount); | |
590 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
590 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
591 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount - first)); |
|
591 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount - first)); | |
592 |
|
592 | |||
593 | m_hMapper->setFirstColumn(0); |
|
593 | m_hMapper->setFirstColumn(0); | |
594 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
594 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
595 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount)); |
|
595 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount)); | |
596 |
|
596 | |||
597 | m_hMapper->setColumnCount(-1); |
|
597 | m_hMapper->setColumnCount(-1); | |
598 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
598 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
599 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - 3 * removeCount); |
|
599 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - 3 * removeCount); | |
600 | } |
|
600 | } | |
601 |
|
601 | |||
602 | void tst_qbarmodelmapper::modelUpdateCell() |
|
602 | void tst_qbarmodelmapper::modelUpdateCell() | |
603 | { |
|
603 | { | |
604 | // setup the mapper |
|
604 | // setup the mapper | |
605 | createVerticalMapper(); |
|
605 | createVerticalMapper(); | |
606 |
|
606 | |||
607 | QVERIFY(m_model->setData(m_model->index(1, 0), 44)); |
|
607 | QVERIFY(m_model->setData(m_model->index(1, 0), 44)); | |
608 | QCOMPARE(m_series->barSets().at(0)->at(1), 44.0); |
|
608 | QCOMPARE(m_series->barSets().at(0)->at(1), 44.0); | |
609 | QCOMPARE(m_model->data(m_model->index(1, 0)).toReal(), 44.0); |
|
609 | QCOMPARE(m_model->data(m_model->index(1, 0)).toReal(), 44.0); | |
610 | } |
|
610 | } | |
611 |
|
611 | |||
612 | QTEST_MAIN(tst_qbarmodelmapper) |
|
612 | QTEST_MAIN(tst_qbarmodelmapper) | |
613 |
|
613 | |||
614 | #include "tst_qbarmodelmapper.moc" |
|
614 | #include "tst_qbarmodelmapper.moc" |
@@ -1,571 +1,571 | |||||
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 <q |
|
22 | #include <qbarseries.h> | |
23 | #include <qbarset.h> |
|
23 | #include <qbarset.h> | |
24 | #include <qchartview.h> |
|
24 | #include <qchartview.h> | |
25 | #include <qchart.h> |
|
25 | #include <qchart.h> | |
26 | #include "tst_definitions.h" |
|
26 | #include "tst_definitions.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | Q_DECLARE_METATYPE(QBarSet*) |
|
30 | Q_DECLARE_METATYPE(QBarSet*) | |
31 |
|
31 | |||
32 | class tst_QBarSeries : public QObject |
|
32 | class tst_QBarSeries : public QObject | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 |
|
35 | |||
36 | public slots: |
|
36 | public slots: | |
37 | void initTestCase(); |
|
37 | void initTestCase(); | |
38 | void cleanupTestCase(); |
|
38 | void cleanupTestCase(); | |
39 | void init(); |
|
39 | void init(); | |
40 | void cleanup(); |
|
40 | void cleanup(); | |
41 |
|
41 | |||
42 | private slots: |
|
42 | private slots: | |
43 | void qbarseries_data(); |
|
43 | void qbarseries_data(); | |
44 | void qbarseries(); |
|
44 | void qbarseries(); | |
45 | void type_data(); |
|
45 | void type_data(); | |
46 | void type(); |
|
46 | void type(); | |
47 | void append_data(); |
|
47 | void append_data(); | |
48 | void append(); |
|
48 | void append(); | |
49 | void remove_data(); |
|
49 | void remove_data(); | |
50 | void remove(); |
|
50 | void remove(); | |
51 | void appendList_data(); |
|
51 | void appendList_data(); | |
52 | void appendList(); |
|
52 | void appendList(); | |
53 | void count_data(); |
|
53 | void count_data(); | |
54 | void count(); |
|
54 | void count(); | |
55 | void barSets_data(); |
|
55 | void barSets_data(); | |
56 | void barSets(); |
|
56 | void barSets(); | |
57 | void setLabelsVisible_data(); |
|
57 | void setLabelsVisible_data(); | |
58 | void setLabelsVisible(); |
|
58 | void setLabelsVisible(); | |
59 | void mouseclicked_data(); |
|
59 | void mouseclicked_data(); | |
60 | void mouseclicked(); |
|
60 | void mouseclicked(); | |
61 | void mousehovered_data(); |
|
61 | void mousehovered_data(); | |
62 | void mousehovered(); |
|
62 | void mousehovered(); | |
63 | void clearWithAnimations(); |
|
63 | void clearWithAnimations(); | |
64 |
|
64 | |||
65 | private: |
|
65 | private: | |
66 |
Q |
|
66 | QBarSeries* m_barseries; | |
67 |
Q |
|
67 | QBarSeries* m_barseries_with_sets; | |
68 |
|
68 | |||
69 | QList<QBarSet*> m_testSets; |
|
69 | QList<QBarSet*> m_testSets; | |
70 |
|
70 | |||
71 | }; |
|
71 | }; | |
72 |
|
72 | |||
73 | void tst_QBarSeries::initTestCase() |
|
73 | void tst_QBarSeries::initTestCase() | |
74 | { |
|
74 | { | |
75 | qRegisterMetaType<QBarSet*>("QBarSet*"); |
|
75 | qRegisterMetaType<QBarSet*>("QBarSet*"); | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void tst_QBarSeries::cleanupTestCase() |
|
78 | void tst_QBarSeries::cleanupTestCase() | |
79 | { |
|
79 | { | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | void tst_QBarSeries::init() |
|
82 | void tst_QBarSeries::init() | |
83 | { |
|
83 | { | |
84 |
m_barseries = new Q |
|
84 | m_barseries = new QBarSeries(); | |
85 |
m_barseries_with_sets = new Q |
|
85 | m_barseries_with_sets = new QBarSeries(); | |
86 |
|
86 | |||
87 | for (int i=0; i<5; i++) { |
|
87 | for (int i=0; i<5; i++) { | |
88 | m_testSets.append(new QBarSet("testset")); |
|
88 | m_testSets.append(new QBarSet("testset")); | |
89 | m_barseries_with_sets->append(m_testSets.at(i)); |
|
89 | m_barseries_with_sets->append(m_testSets.at(i)); | |
90 | } |
|
90 | } | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | void tst_QBarSeries::cleanup() |
|
93 | void tst_QBarSeries::cleanup() | |
94 | { |
|
94 | { | |
95 | foreach(QBarSet* s, m_testSets) { |
|
95 | foreach(QBarSet* s, m_testSets) { | |
96 | m_barseries_with_sets->remove(s); |
|
96 | m_barseries_with_sets->remove(s); | |
97 | delete s; |
|
97 | delete s; | |
98 | } |
|
98 | } | |
99 | m_testSets.clear(); |
|
99 | m_testSets.clear(); | |
100 |
|
100 | |||
101 | delete m_barseries; |
|
101 | delete m_barseries; | |
102 | m_barseries = 0; |
|
102 | m_barseries = 0; | |
103 | delete m_barseries_with_sets; |
|
103 | delete m_barseries_with_sets; | |
104 | m_barseries_with_sets = 0; |
|
104 | m_barseries_with_sets = 0; | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | void tst_QBarSeries::qbarseries_data() |
|
107 | void tst_QBarSeries::qbarseries_data() | |
108 | { |
|
108 | { | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | void tst_QBarSeries::qbarseries() |
|
111 | void tst_QBarSeries::qbarseries() | |
112 | { |
|
112 | { | |
113 |
Q |
|
113 | QBarSeries *barseries = new QBarSeries(); | |
114 | QVERIFY(barseries != 0); |
|
114 | QVERIFY(barseries != 0); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void tst_QBarSeries::type_data() |
|
117 | void tst_QBarSeries::type_data() | |
118 | { |
|
118 | { | |
119 |
|
119 | |||
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | void tst_QBarSeries::type() |
|
122 | void tst_QBarSeries::type() | |
123 | { |
|
123 | { | |
124 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); |
|
124 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | void tst_QBarSeries::append_data() |
|
127 | void tst_QBarSeries::append_data() | |
128 | { |
|
128 | { | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | void tst_QBarSeries::append() |
|
131 | void tst_QBarSeries::append() | |
132 | { |
|
132 | { | |
133 | QVERIFY(m_barseries->count() == 0); |
|
133 | QVERIFY(m_barseries->count() == 0); | |
134 |
|
134 | |||
135 | bool ret = false; |
|
135 | bool ret = false; | |
136 |
|
136 | |||
137 | // Try adding barset |
|
137 | // Try adding barset | |
138 | QBarSet *barset = new QBarSet("testset"); |
|
138 | QBarSet *barset = new QBarSet("testset"); | |
139 | ret = m_barseries->append(barset); |
|
139 | ret = m_barseries->append(barset); | |
140 |
|
140 | |||
141 | QVERIFY(ret == true); |
|
141 | QVERIFY(ret == true); | |
142 | QVERIFY(m_barseries->count() == 1); |
|
142 | QVERIFY(m_barseries->count() == 1); | |
143 |
|
143 | |||
144 | // Try adding another set |
|
144 | // Try adding another set | |
145 | QBarSet *barset2 = new QBarSet("testset2"); |
|
145 | QBarSet *barset2 = new QBarSet("testset2"); | |
146 | ret = m_barseries->append(barset2); |
|
146 | ret = m_barseries->append(barset2); | |
147 |
|
147 | |||
148 | QVERIFY(ret == true); |
|
148 | QVERIFY(ret == true); | |
149 | QVERIFY(m_barseries->count() == 2); |
|
149 | QVERIFY(m_barseries->count() == 2); | |
150 |
|
150 | |||
151 | // Try adding same set again |
|
151 | // Try adding same set again | |
152 | ret = m_barseries->append(barset2); |
|
152 | ret = m_barseries->append(barset2); | |
153 | QVERIFY(ret == false); |
|
153 | QVERIFY(ret == false); | |
154 | QVERIFY(m_barseries->count() == 2); |
|
154 | QVERIFY(m_barseries->count() == 2); | |
155 |
|
155 | |||
156 | // Try adding null set |
|
156 | // Try adding null set | |
157 | ret = m_barseries->append(0); |
|
157 | ret = m_barseries->append(0); | |
158 | QVERIFY(ret == false); |
|
158 | QVERIFY(ret == false); | |
159 | QVERIFY(m_barseries->count() == 2); |
|
159 | QVERIFY(m_barseries->count() == 2); | |
160 |
|
160 | |||
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | void tst_QBarSeries::remove_data() |
|
163 | void tst_QBarSeries::remove_data() | |
164 | { |
|
164 | { | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | void tst_QBarSeries::remove() |
|
167 | void tst_QBarSeries::remove() | |
168 | { |
|
168 | { | |
169 | int count = m_testSets.count(); |
|
169 | int count = m_testSets.count(); | |
170 | QVERIFY(m_barseries_with_sets->count() == count); |
|
170 | QVERIFY(m_barseries_with_sets->count() == count); | |
171 |
|
171 | |||
172 | // Try to remove null pointer (should not remove, should not crash) |
|
172 | // Try to remove null pointer (should not remove, should not crash) | |
173 | bool ret = false; |
|
173 | bool ret = false; | |
174 | ret = m_barseries_with_sets->remove(0); |
|
174 | ret = m_barseries_with_sets->remove(0); | |
175 | QVERIFY(ret == false); |
|
175 | QVERIFY(ret == false); | |
176 | QVERIFY(m_barseries_with_sets->count() == count); |
|
176 | QVERIFY(m_barseries_with_sets->count() == count); | |
177 |
|
177 | |||
178 | // Try to remove invalid pointer (should not remove, should not crash) |
|
178 | // Try to remove invalid pointer (should not remove, should not crash) | |
179 | ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) ); |
|
179 | ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) ); | |
180 | QVERIFY(ret == false); |
|
180 | QVERIFY(ret == false); | |
181 | QVERIFY(m_barseries_with_sets->count() == count); |
|
181 | QVERIFY(m_barseries_with_sets->count() == count); | |
182 |
|
182 | |||
183 | // remove some sets |
|
183 | // remove some sets | |
184 | ret = m_barseries_with_sets->remove(m_testSets.at(2)); |
|
184 | ret = m_barseries_with_sets->remove(m_testSets.at(2)); | |
185 | QVERIFY(ret == true); |
|
185 | QVERIFY(ret == true); | |
186 | ret = m_barseries_with_sets->remove(m_testSets.at(3)); |
|
186 | ret = m_barseries_with_sets->remove(m_testSets.at(3)); | |
187 | QVERIFY(ret == true); |
|
187 | QVERIFY(ret == true); | |
188 | ret = m_barseries_with_sets->remove(m_testSets.at(4)); |
|
188 | ret = m_barseries_with_sets->remove(m_testSets.at(4)); | |
189 | QVERIFY(ret == true); |
|
189 | QVERIFY(ret == true); | |
190 |
|
190 | |||
191 | QVERIFY(m_barseries_with_sets->count() == 2); |
|
191 | QVERIFY(m_barseries_with_sets->count() == 2); | |
192 |
|
192 | |||
193 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); |
|
193 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); | |
194 |
|
194 | |||
195 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); |
|
195 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); | |
196 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); |
|
196 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); | |
197 |
|
197 | |||
198 | // Try removing all sets again (should be ok, even if some sets have already been removed) |
|
198 | // Try removing all sets again (should be ok, even if some sets have already been removed) | |
199 | ret = false; |
|
199 | ret = false; | |
200 | for (int i=0; i<count; i++) { |
|
200 | for (int i=0; i<count; i++) { | |
201 | ret |= m_barseries_with_sets->remove(m_testSets.at(i)); |
|
201 | ret |= m_barseries_with_sets->remove(m_testSets.at(i)); | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | QVERIFY(ret == true); |
|
204 | QVERIFY(ret == true); | |
205 | QVERIFY(m_barseries_with_sets->count() == 0); |
|
205 | QVERIFY(m_barseries_with_sets->count() == 0); | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | void tst_QBarSeries::appendList_data() |
|
208 | void tst_QBarSeries::appendList_data() | |
209 | { |
|
209 | { | |
210 |
|
210 | |||
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 | void tst_QBarSeries::appendList() |
|
213 | void tst_QBarSeries::appendList() | |
214 | { |
|
214 | { | |
215 | int count = 5; |
|
215 | int count = 5; | |
216 | QVERIFY(m_barseries->count() == 0); |
|
216 | QVERIFY(m_barseries->count() == 0); | |
217 |
|
217 | |||
218 | QList<QBarSet*> sets; |
|
218 | QList<QBarSet*> sets; | |
219 | for (int i=0; i<count; i++) { |
|
219 | for (int i=0; i<count; i++) { | |
220 | sets.append(new QBarSet("testset")); |
|
220 | sets.append(new QBarSet("testset")); | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | // Append new sets (should succeed, count should match the count of sets) |
|
223 | // Append new sets (should succeed, count should match the count of sets) | |
224 | bool ret = false; |
|
224 | bool ret = false; | |
225 | ret = m_barseries->append(sets); |
|
225 | ret = m_barseries->append(sets); | |
226 | QVERIFY(ret == true); |
|
226 | QVERIFY(ret == true); | |
227 | QVERIFY(m_barseries->count() == count); |
|
227 | QVERIFY(m_barseries->count() == count); | |
228 |
|
228 | |||
229 | // Append same sets again (should fail, count should remain same) |
|
229 | // Append same sets again (should fail, count should remain same) | |
230 | ret = m_barseries->append(sets); |
|
230 | ret = m_barseries->append(sets); | |
231 | QVERIFY(ret == false); |
|
231 | QVERIFY(ret == false); | |
232 | QVERIFY(m_barseries->count() == count); |
|
232 | QVERIFY(m_barseries->count() == count); | |
233 |
|
233 | |||
234 | // Try append empty list (should succeed, but count should remain same) |
|
234 | // Try append empty list (should succeed, but count should remain same) | |
235 | QList<QBarSet*> invalidList; |
|
235 | QList<QBarSet*> invalidList; | |
236 | ret = m_barseries->append(invalidList); |
|
236 | ret = m_barseries->append(invalidList); | |
237 | QVERIFY(ret == true); |
|
237 | QVERIFY(ret == true); | |
238 | QVERIFY(m_barseries->count() == count); |
|
238 | QVERIFY(m_barseries->count() == count); | |
239 |
|
239 | |||
240 | // Try append list with one new and one existing set (should fail, count remains same) |
|
240 | // Try append list with one new and one existing set (should fail, count remains same) | |
241 | invalidList.append(new QBarSet("ok set")); |
|
241 | invalidList.append(new QBarSet("ok set")); | |
242 | invalidList.append(sets.at(0)); |
|
242 | invalidList.append(sets.at(0)); | |
243 | ret = m_barseries->append(invalidList); |
|
243 | ret = m_barseries->append(invalidList); | |
244 | QVERIFY(ret == false); |
|
244 | QVERIFY(ret == false); | |
245 | QVERIFY(m_barseries->count() == count); |
|
245 | QVERIFY(m_barseries->count() == count); | |
246 |
|
246 | |||
247 | // Try append list with null pointers (should fail, count remains same) |
|
247 | // Try append list with null pointers (should fail, count remains same) | |
248 | QList<QBarSet*> invalidList2; |
|
248 | QList<QBarSet*> invalidList2; | |
249 | invalidList2.append(0); |
|
249 | invalidList2.append(0); | |
250 | invalidList2.append(0); |
|
250 | invalidList2.append(0); | |
251 | invalidList2.append(0); |
|
251 | invalidList2.append(0); | |
252 | ret = m_barseries->append(invalidList2); |
|
252 | ret = m_barseries->append(invalidList2); | |
253 | QVERIFY(ret == false); |
|
253 | QVERIFY(ret == false); | |
254 | QVERIFY(m_barseries->count() == count); |
|
254 | QVERIFY(m_barseries->count() == count); | |
255 | } |
|
255 | } | |
256 |
|
256 | |||
257 | void tst_QBarSeries::count_data() |
|
257 | void tst_QBarSeries::count_data() | |
258 | { |
|
258 | { | |
259 |
|
259 | |||
260 | } |
|
260 | } | |
261 |
|
261 | |||
262 | void tst_QBarSeries::count() |
|
262 | void tst_QBarSeries::count() | |
263 | { |
|
263 | { | |
264 | QVERIFY(m_barseries->count() == 0); |
|
264 | QVERIFY(m_barseries->count() == 0); | |
265 | QVERIFY(m_barseries_with_sets->count() == m_testSets.count()); |
|
265 | QVERIFY(m_barseries_with_sets->count() == m_testSets.count()); | |
266 | } |
|
266 | } | |
267 |
|
267 | |||
268 | void tst_QBarSeries::barSets_data() |
|
268 | void tst_QBarSeries::barSets_data() | |
269 | { |
|
269 | { | |
270 |
|
270 | |||
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | void tst_QBarSeries::barSets() |
|
273 | void tst_QBarSeries::barSets() | |
274 | { |
|
274 | { | |
275 | QVERIFY(m_barseries->barSets().count() == 0); |
|
275 | QVERIFY(m_barseries->barSets().count() == 0); | |
276 |
|
276 | |||
277 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); |
|
277 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); | |
278 | QVERIFY(sets.count() == m_testSets.count()); |
|
278 | QVERIFY(sets.count() == m_testSets.count()); | |
279 |
|
279 | |||
280 | for (int i=0; i<m_testSets.count(); i++) { |
|
280 | for (int i=0; i<m_testSets.count(); i++) { | |
281 | QVERIFY(sets.at(i) == m_testSets.at(i)); |
|
281 | QVERIFY(sets.at(i) == m_testSets.at(i)); | |
282 | } |
|
282 | } | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | void tst_QBarSeries::setLabelsVisible_data() |
|
285 | void tst_QBarSeries::setLabelsVisible_data() | |
286 | { |
|
286 | { | |
287 |
|
287 | |||
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | void tst_QBarSeries::setLabelsVisible() |
|
290 | void tst_QBarSeries::setLabelsVisible() | |
291 | { |
|
291 | { | |
292 | // labels should be invisible by default |
|
292 | // labels should be invisible by default | |
293 | QVERIFY(m_barseries->isLabelsVisible() == false); |
|
293 | QVERIFY(m_barseries->isLabelsVisible() == false); | |
294 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); |
|
294 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); | |
295 |
|
295 | |||
296 | // turn labels to visible |
|
296 | // turn labels to visible | |
297 | m_barseries_with_sets->setLabelsVisible(true); |
|
297 | m_barseries_with_sets->setLabelsVisible(true); | |
298 | // TODO: test the signal |
|
298 | // TODO: test the signal | |
299 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); |
|
299 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); | |
300 |
|
300 | |||
301 | // turn labels to invisible |
|
301 | // turn labels to invisible | |
302 | m_barseries_with_sets->setLabelsVisible(false); |
|
302 | m_barseries_with_sets->setLabelsVisible(false); | |
303 | // TODO: test the signal |
|
303 | // TODO: test the signal | |
304 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); |
|
304 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); | |
305 |
|
305 | |||
306 | // without parameter, should turn labels to visible |
|
306 | // without parameter, should turn labels to visible | |
307 | m_barseries_with_sets->setLabelsVisible(); |
|
307 | m_barseries_with_sets->setLabelsVisible(); | |
308 | // TODO: test the signal |
|
308 | // TODO: test the signal | |
309 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); |
|
309 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); | |
310 | } |
|
310 | } | |
311 |
|
311 | |||
312 | void tst_QBarSeries::mouseclicked_data() |
|
312 | void tst_QBarSeries::mouseclicked_data() | |
313 | { |
|
313 | { | |
314 |
|
314 | |||
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | void tst_QBarSeries::mouseclicked() |
|
317 | void tst_QBarSeries::mouseclicked() | |
318 | { |
|
318 | { | |
319 |
Q |
|
319 | QBarSeries* series = new QBarSeries(); | |
320 |
|
320 | |||
321 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
321 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
322 | *set1 << 10 << 10 << 10; |
|
322 | *set1 << 10 << 10 << 10; | |
323 | series->append(set1); |
|
323 | series->append(set1); | |
324 |
|
324 | |||
325 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
325 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
326 | *set2 << 10 << 10 << 10; |
|
326 | *set2 << 10 << 10 << 10; | |
327 | series->append(set2); |
|
327 | series->append(set2); | |
328 |
|
328 | |||
329 | QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*))); |
|
329 | QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*))); | |
330 | QSignalSpy setSpy1(set1, SIGNAL(clicked(int))); |
|
330 | QSignalSpy setSpy1(set1, SIGNAL(clicked(int))); | |
331 | QSignalSpy setSpy2(set2, SIGNAL(clicked(int))); |
|
331 | QSignalSpy setSpy2(set2, SIGNAL(clicked(int))); | |
332 |
|
332 | |||
333 | QChartView view(new QChart()); |
|
333 | QChartView view(new QChart()); | |
334 | view.resize(400,300); |
|
334 | view.resize(400,300); | |
335 | view.chart()->addSeries(series); |
|
335 | view.chart()->addSeries(series); | |
336 | view.show(); |
|
336 | view.show(); | |
337 | QTest::qWaitForWindowShown(&view); |
|
337 | QTest::qWaitForWindowShown(&view); | |
338 |
|
338 | |||
339 | //==================================================================================== |
|
339 | //==================================================================================== | |
340 | // barset 1, bar 0 |
|
340 | // barset 1, bar 0 | |
341 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(102,142)); |
|
341 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(102,142)); | |
342 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
342 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
343 |
|
343 | |||
344 | QCOMPARE(seriesSpy.count(), 1); |
|
344 | QCOMPARE(seriesSpy.count(), 1); | |
345 | QCOMPARE(setSpy1.count(), 1); |
|
345 | QCOMPARE(setSpy1.count(), 1); | |
346 | QCOMPARE(setSpy2.count(), 0); |
|
346 | QCOMPARE(setSpy2.count(), 0); | |
347 |
|
347 | |||
348 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
348 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
349 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
349 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
350 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
350 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
351 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); |
|
351 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); | |
352 |
|
352 | |||
353 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); |
|
353 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); | |
354 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
354 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); | |
355 | QVERIFY(setSpyArg.at(0).toInt() == 0); |
|
355 | QVERIFY(setSpyArg.at(0).toInt() == 0); | |
356 |
|
356 | |||
357 | //==================================================================================== |
|
357 | //==================================================================================== | |
358 | // barset 1, bar 1 |
|
358 | // barset 1, bar 1 | |
359 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,142)); |
|
359 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,142)); | |
360 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
360 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
361 |
|
361 | |||
362 | QCOMPARE(seriesSpy.count(), 1); |
|
362 | QCOMPARE(seriesSpy.count(), 1); | |
363 | QCOMPARE(setSpy1.count(), 1); |
|
363 | QCOMPARE(setSpy1.count(), 1); | |
364 | QCOMPARE(setSpy2.count(), 0); |
|
364 | QCOMPARE(setSpy2.count(), 0); | |
365 |
|
365 | |||
366 | seriesSpyArg = seriesSpy.takeFirst(); |
|
366 | seriesSpyArg = seriesSpy.takeFirst(); | |
367 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
367 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
368 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
368 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
369 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); |
|
369 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); | |
370 |
|
370 | |||
371 | setSpyArg = setSpy1.takeFirst(); |
|
371 | setSpyArg = setSpy1.takeFirst(); | |
372 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
372 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); | |
373 | QVERIFY(setSpyArg.at(0).toInt() == 1); |
|
373 | QVERIFY(setSpyArg.at(0).toInt() == 1); | |
374 |
|
374 | |||
375 | //==================================================================================== |
|
375 | //==================================================================================== | |
376 | // barset 1, bar 2 |
|
376 | // barset 1, bar 2 | |
377 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(271,142)); |
|
377 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(271,142)); | |
378 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
378 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
379 |
|
379 | |||
380 | QCOMPARE(seriesSpy.count(), 1); |
|
380 | QCOMPARE(seriesSpy.count(), 1); | |
381 | QCOMPARE(setSpy1.count(), 1); |
|
381 | QCOMPARE(setSpy1.count(), 1); | |
382 | QCOMPARE(setSpy2.count(), 0); |
|
382 | QCOMPARE(setSpy2.count(), 0); | |
383 |
|
383 | |||
384 | seriesSpyArg = seriesSpy.takeFirst(); |
|
384 | seriesSpyArg = seriesSpy.takeFirst(); | |
385 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
385 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
386 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
386 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
387 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); |
|
387 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); | |
388 |
|
388 | |||
389 | setSpyArg = setSpy1.takeFirst(); |
|
389 | setSpyArg = setSpy1.takeFirst(); | |
390 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
390 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); | |
391 | QVERIFY(setSpyArg.at(0).toInt() == 2); |
|
391 | QVERIFY(setSpyArg.at(0).toInt() == 2); | |
392 |
|
392 | |||
393 | //==================================================================================== |
|
393 | //==================================================================================== | |
394 | // barset 2, bar 0 |
|
394 | // barset 2, bar 0 | |
395 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(127,142)); |
|
395 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(127,142)); | |
396 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
396 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
397 |
|
397 | |||
398 | QCOMPARE(seriesSpy.count(), 1); |
|
398 | QCOMPARE(seriesSpy.count(), 1); | |
399 | QCOMPARE(setSpy1.count(), 0); |
|
399 | QCOMPARE(setSpy1.count(), 0); | |
400 | QCOMPARE(setSpy2.count(), 1); |
|
400 | QCOMPARE(setSpy2.count(), 1); | |
401 |
|
401 | |||
402 | seriesSpyArg = seriesSpy.takeFirst(); |
|
402 | seriesSpyArg = seriesSpy.takeFirst(); | |
403 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
403 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
404 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
404 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
405 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); |
|
405 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); | |
406 |
|
406 | |||
407 | setSpyArg = setSpy2.takeFirst(); |
|
407 | setSpyArg = setSpy2.takeFirst(); | |
408 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
408 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); | |
409 | QVERIFY(setSpyArg.at(0).toInt() == 0); |
|
409 | QVERIFY(setSpyArg.at(0).toInt() == 0); | |
410 |
|
410 | |||
411 | //==================================================================================== |
|
411 | //==================================================================================== | |
412 | // barset 2, bar 1 |
|
412 | // barset 2, bar 1 | |
413 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(212,142)); |
|
413 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(212,142)); | |
414 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
414 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
415 |
|
415 | |||
416 | QCOMPARE(seriesSpy.count(), 1); |
|
416 | QCOMPARE(seriesSpy.count(), 1); | |
417 | QCOMPARE(setSpy1.count(), 0); |
|
417 | QCOMPARE(setSpy1.count(), 0); | |
418 | QCOMPARE(setSpy2.count(), 1); |
|
418 | QCOMPARE(setSpy2.count(), 1); | |
419 |
|
419 | |||
420 | seriesSpyArg = seriesSpy.takeFirst(); |
|
420 | seriesSpyArg = seriesSpy.takeFirst(); | |
421 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
421 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
422 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
422 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
423 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); |
|
423 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); | |
424 |
|
424 | |||
425 | setSpyArg = setSpy2.takeFirst(); |
|
425 | setSpyArg = setSpy2.takeFirst(); | |
426 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
426 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); | |
427 | QVERIFY(setSpyArg.at(0).toInt() == 1); |
|
427 | QVERIFY(setSpyArg.at(0).toInt() == 1); | |
428 |
|
428 | |||
429 | //==================================================================================== |
|
429 | //==================================================================================== | |
430 | // barset 2, bar 2 |
|
430 | // barset 2, bar 2 | |
431 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(296,142)); |
|
431 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(296,142)); | |
432 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
432 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
433 |
|
433 | |||
434 | QCOMPARE(seriesSpy.count(), 1); |
|
434 | QCOMPARE(seriesSpy.count(), 1); | |
435 | QCOMPARE(setSpy1.count(), 0); |
|
435 | QCOMPARE(setSpy1.count(), 0); | |
436 | QCOMPARE(setSpy2.count(), 1); |
|
436 | QCOMPARE(setSpy2.count(), 1); | |
437 |
|
437 | |||
438 | seriesSpyArg = seriesSpy.takeFirst(); |
|
438 | seriesSpyArg = seriesSpy.takeFirst(); | |
439 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
439 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
440 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
440 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
441 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); |
|
441 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); | |
442 |
|
442 | |||
443 | setSpyArg = setSpy2.takeFirst(); |
|
443 | setSpyArg = setSpy2.takeFirst(); | |
444 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
444 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); | |
445 | QVERIFY(setSpyArg.at(0).toInt() == 2); |
|
445 | QVERIFY(setSpyArg.at(0).toInt() == 2); | |
446 | } |
|
446 | } | |
447 |
|
447 | |||
448 | void tst_QBarSeries::mousehovered_data() |
|
448 | void tst_QBarSeries::mousehovered_data() | |
449 | { |
|
449 | { | |
450 |
|
450 | |||
451 | } |
|
451 | } | |
452 |
|
452 | |||
453 | void tst_QBarSeries::mousehovered() |
|
453 | void tst_QBarSeries::mousehovered() | |
454 | { |
|
454 | { | |
455 |
Q |
|
455 | QBarSeries* series = new QBarSeries(); | |
456 |
|
456 | |||
457 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
457 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
458 | *set1 << 10 << 10 << 10; |
|
458 | *set1 << 10 << 10 << 10; | |
459 | series->append(set1); |
|
459 | series->append(set1); | |
460 |
|
460 | |||
461 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
461 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
462 | *set2 << 10 << 10 << 10; |
|
462 | *set2 << 10 << 10 << 10; | |
463 | series->append(set2); |
|
463 | series->append(set2); | |
464 |
|
464 | |||
465 | QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*))); |
|
465 | QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*))); | |
466 | QSignalSpy setSpy1(set1, SIGNAL(hovered(bool))); |
|
466 | QSignalSpy setSpy1(set1, SIGNAL(hovered(bool))); | |
467 | QSignalSpy setSpy2(set2, SIGNAL(hovered(bool))); |
|
467 | QSignalSpy setSpy2(set2, SIGNAL(hovered(bool))); | |
468 |
|
468 | |||
469 | QChartView view(new QChart()); |
|
469 | QChartView view(new QChart()); | |
470 | view.resize(400,300); |
|
470 | view.resize(400,300); | |
471 | view.chart()->addSeries(series); |
|
471 | view.chart()->addSeries(series); | |
472 | view.show(); |
|
472 | view.show(); | |
473 | QTest::qWaitForWindowShown(&view); |
|
473 | QTest::qWaitForWindowShown(&view); | |
474 |
|
474 | |||
475 | //this is hack since view does not get events otherwise |
|
475 | //this is hack since view does not get events otherwise | |
476 | view.setMouseTracking(true); |
|
476 | view.setMouseTracking(true); | |
477 |
|
477 | |||
478 | //======================================================================= |
|
478 | //======================================================================= | |
479 | // move mouse to left border |
|
479 | // move mouse to left border | |
480 | QTest::mouseMove(view.viewport(), QPoint(0, 142)); |
|
480 | QTest::mouseMove(view.viewport(), QPoint(0, 142)); | |
481 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); |
|
481 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); | |
482 | TRY_COMPARE(seriesSpy.count(), 0); |
|
482 | TRY_COMPARE(seriesSpy.count(), 0); | |
483 | TRY_COMPARE(setSpy1.count(), 0); |
|
483 | TRY_COMPARE(setSpy1.count(), 0); | |
484 | TRY_COMPARE(setSpy2.count(), 0); |
|
484 | TRY_COMPARE(setSpy2.count(), 0); | |
485 |
|
485 | |||
486 | //======================================================================= |
|
486 | //======================================================================= | |
487 | // move mouse on top of set1 |
|
487 | // move mouse on top of set1 | |
488 | QTest::mouseMove(view.viewport(), QPoint(102,142)); |
|
488 | QTest::mouseMove(view.viewport(), QPoint(102,142)); | |
489 | TRY_COMPARE(seriesSpy.count(), 1); |
|
489 | TRY_COMPARE(seriesSpy.count(), 1); | |
490 | TRY_COMPARE(setSpy1.count(), 1); |
|
490 | TRY_COMPARE(setSpy1.count(), 1); | |
491 | TRY_COMPARE(setSpy2.count(), 0); |
|
491 | TRY_COMPARE(setSpy2.count(), 0); | |
492 |
|
492 | |||
493 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
493 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
494 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
494 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
495 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
495 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | |
496 | QVERIFY(seriesSpyArg.at(0).toBool() == true); |
|
496 | QVERIFY(seriesSpyArg.at(0).toBool() == true); | |
497 |
|
497 | |||
498 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); |
|
498 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); | |
499 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
499 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); | |
500 | QVERIFY(setSpyArg.at(0).toBool() == true); |
|
500 | QVERIFY(setSpyArg.at(0).toBool() == true); | |
501 |
|
501 | |||
502 | //======================================================================= |
|
502 | //======================================================================= | |
503 | // move mouse from top of set1 to top of set2 |
|
503 | // move mouse from top of set1 to top of set2 | |
504 | QTest::mouseMove(view.viewport(), QPoint(127,142)); |
|
504 | QTest::mouseMove(view.viewport(), QPoint(127,142)); | |
505 | TRY_COMPARE(seriesSpy.count(), 2); |
|
505 | TRY_COMPARE(seriesSpy.count(), 2); | |
506 | TRY_COMPARE(setSpy1.count(), 1); |
|
506 | TRY_COMPARE(setSpy1.count(), 1); | |
507 | TRY_COMPARE(setSpy2.count(), 1); |
|
507 | TRY_COMPARE(setSpy2.count(), 1); | |
508 |
|
508 | |||
509 | // should leave set1 |
|
509 | // should leave set1 | |
510 | seriesSpyArg = seriesSpy.takeFirst(); |
|
510 | seriesSpyArg = seriesSpy.takeFirst(); | |
511 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
511 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
512 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
512 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | |
513 | QVERIFY(seriesSpyArg.at(0).toBool() == false); |
|
513 | QVERIFY(seriesSpyArg.at(0).toBool() == false); | |
514 |
|
514 | |||
515 | setSpyArg = setSpy1.takeFirst(); |
|
515 | setSpyArg = setSpy1.takeFirst(); | |
516 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
516 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); | |
517 | QVERIFY(setSpyArg.at(0).toBool() == false); |
|
517 | QVERIFY(setSpyArg.at(0).toBool() == false); | |
518 |
|
518 | |||
519 | // should enter set2 |
|
519 | // should enter set2 | |
520 | seriesSpyArg = seriesSpy.takeFirst(); |
|
520 | seriesSpyArg = seriesSpy.takeFirst(); | |
521 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
521 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
522 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
522 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | |
523 | QVERIFY(seriesSpyArg.at(0).toBool() == true); |
|
523 | QVERIFY(seriesSpyArg.at(0).toBool() == true); | |
524 |
|
524 | |||
525 | setSpyArg = setSpy2.takeFirst(); |
|
525 | setSpyArg = setSpy2.takeFirst(); | |
526 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
526 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); | |
527 | QVERIFY(setSpyArg.at(0).toBool() == true); |
|
527 | QVERIFY(setSpyArg.at(0).toBool() == true); | |
528 |
|
528 | |||
529 | //======================================================================= |
|
529 | //======================================================================= | |
530 | // move mouse from top of set2 to background |
|
530 | // move mouse from top of set2 to background | |
531 | QTest::mouseMove(view.viewport(), QPoint(127,0)); |
|
531 | QTest::mouseMove(view.viewport(), QPoint(127,0)); | |
532 | TRY_COMPARE(seriesSpy.count(), 1); |
|
532 | TRY_COMPARE(seriesSpy.count(), 1); | |
533 | TRY_COMPARE(setSpy1.count(), 0); |
|
533 | TRY_COMPARE(setSpy1.count(), 0); | |
534 | TRY_COMPARE(setSpy2.count(), 1); |
|
534 | TRY_COMPARE(setSpy2.count(), 1); | |
535 |
|
535 | |||
536 | // should leave set2 |
|
536 | // should leave set2 | |
537 | seriesSpyArg = seriesSpy.takeFirst(); |
|
537 | seriesSpyArg = seriesSpy.takeFirst(); | |
538 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
538 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
539 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
539 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | |
540 | QVERIFY(seriesSpyArg.at(0).toBool() == false); |
|
540 | QVERIFY(seriesSpyArg.at(0).toBool() == false); | |
541 |
|
541 | |||
542 | setSpyArg = setSpy2.takeFirst(); |
|
542 | setSpyArg = setSpy2.takeFirst(); | |
543 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
543 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); | |
544 | QVERIFY(setSpyArg.at(0).toBool() == false); |
|
544 | QVERIFY(setSpyArg.at(0).toBool() == false); | |
545 | } |
|
545 | } | |
546 |
|
546 | |||
547 | void tst_QBarSeries::clearWithAnimations() |
|
547 | void tst_QBarSeries::clearWithAnimations() | |
548 | { |
|
548 | { | |
549 |
Q |
|
549 | QBarSeries* series = new QBarSeries(); | |
550 |
|
550 | |||
551 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
551 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
552 | *set1 << 10 << 10 << 10; |
|
552 | *set1 << 10 << 10 << 10; | |
553 | series->append(set1); |
|
553 | series->append(set1); | |
554 |
|
554 | |||
555 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
555 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
556 | *set2 << 10 << 10 << 10; |
|
556 | *set2 << 10 << 10 << 10; | |
557 | series->append(set2); |
|
557 | series->append(set2); | |
558 |
|
558 | |||
559 | QChartView view(new QChart()); |
|
559 | QChartView view(new QChart()); | |
560 | view.resize(400,300); |
|
560 | view.resize(400,300); | |
561 | view.chart()->setAnimationOptions(QChart::SeriesAnimations); |
|
561 | view.chart()->setAnimationOptions(QChart::SeriesAnimations); | |
562 | view.chart()->addSeries(series); |
|
562 | view.chart()->addSeries(series); | |
563 | view.show(); |
|
563 | view.show(); | |
564 |
|
564 | |||
565 | series->clear(); |
|
565 | series->clear(); | |
566 | } |
|
566 | } | |
567 |
|
567 | |||
568 | QTEST_MAIN(tst_QBarSeries) |
|
568 | QTEST_MAIN(tst_QBarSeries) | |
569 |
|
569 | |||
570 | #include "tst_qbarseries.moc" |
|
570 | #include "tst_qbarseries.moc" | |
571 |
|
571 |
@@ -1,488 +1,488 | |||||
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 <q |
|
23 | #include <qbarseries.h> | |
24 | #include <qchartview.h> |
|
24 | #include <qchartview.h> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
26 | QTCOMMERCIALCHART_USE_NAMESPACE | |
27 |
|
27 | |||
28 | class tst_QBarSet : public QObject |
|
28 | class tst_QBarSet : public QObject | |
29 | { |
|
29 | { | |
30 | Q_OBJECT |
|
30 | Q_OBJECT | |
31 |
|
31 | |||
32 | public slots: |
|
32 | public slots: | |
33 | void initTestCase(); |
|
33 | void initTestCase(); | |
34 | void cleanupTestCase(); |
|
34 | void cleanupTestCase(); | |
35 | void init(); |
|
35 | void init(); | |
36 | void cleanup(); |
|
36 | void cleanup(); | |
37 |
|
37 | |||
38 | private slots: |
|
38 | private slots: | |
39 | void qbarset_data(); |
|
39 | void qbarset_data(); | |
40 | void qbarset(); |
|
40 | void qbarset(); | |
41 | void label_data(); |
|
41 | void label_data(); | |
42 | void label(); |
|
42 | void label(); | |
43 | void append_data(); |
|
43 | void append_data(); | |
44 | void append(); |
|
44 | void append(); | |
45 | void appendOperator_data(); |
|
45 | void appendOperator_data(); | |
46 | void appendOperator(); |
|
46 | void appendOperator(); | |
47 | void insert_data(); |
|
47 | void insert_data(); | |
48 | void insert(); |
|
48 | void insert(); | |
49 | void remove_data(); |
|
49 | void remove_data(); | |
50 | void remove(); |
|
50 | void remove(); | |
51 | void replace_data(); |
|
51 | void replace_data(); | |
52 | void replace(); |
|
52 | void replace(); | |
53 | void at_data(); |
|
53 | void at_data(); | |
54 | void at(); |
|
54 | void at(); | |
55 | void atOperator_data(); |
|
55 | void atOperator_data(); | |
56 | void atOperator(); |
|
56 | void atOperator(); | |
57 | void count_data(); |
|
57 | void count_data(); | |
58 | void count(); |
|
58 | void count(); | |
59 | void sum_data(); |
|
59 | void sum_data(); | |
60 | void sum(); |
|
60 | void sum(); | |
61 | void customize(); |
|
61 | void customize(); | |
62 |
|
62 | |||
63 | private: |
|
63 | private: | |
64 | QBarSet* m_barset; |
|
64 | QBarSet* m_barset; | |
65 | }; |
|
65 | }; | |
66 |
|
66 | |||
67 | void tst_QBarSet::initTestCase() |
|
67 | void tst_QBarSet::initTestCase() | |
68 | { |
|
68 | { | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void tst_QBarSet::cleanupTestCase() |
|
71 | void tst_QBarSet::cleanupTestCase() | |
72 | { |
|
72 | { | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void tst_QBarSet::init() |
|
75 | void tst_QBarSet::init() | |
76 | { |
|
76 | { | |
77 | m_barset = new QBarSet(QString("label")); |
|
77 | m_barset = new QBarSet(QString("label")); | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void tst_QBarSet::cleanup() |
|
80 | void tst_QBarSet::cleanup() | |
81 | { |
|
81 | { | |
82 | delete m_barset; |
|
82 | delete m_barset; | |
83 | m_barset = 0; |
|
83 | m_barset = 0; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | void tst_QBarSet::qbarset_data() |
|
86 | void tst_QBarSet::qbarset_data() | |
87 | { |
|
87 | { | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void tst_QBarSet::qbarset() |
|
90 | void tst_QBarSet::qbarset() | |
91 | { |
|
91 | { | |
92 | QBarSet barset(QString("label")); |
|
92 | QBarSet barset(QString("label")); | |
93 | QCOMPARE(barset.label(), QString("label")); |
|
93 | QCOMPARE(barset.label(), QString("label")); | |
94 | QCOMPARE(barset.count(), 0); |
|
94 | QCOMPARE(barset.count(), 0); | |
95 | QVERIFY(qFuzzyIsNull(barset.sum())); |
|
95 | QVERIFY(qFuzzyIsNull(barset.sum())); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void tst_QBarSet::label_data() |
|
98 | void tst_QBarSet::label_data() | |
99 | { |
|
99 | { | |
100 | QTest::addColumn<QString> ("label"); |
|
100 | QTest::addColumn<QString> ("label"); | |
101 | QTest::addColumn<QString> ("result"); |
|
101 | QTest::addColumn<QString> ("result"); | |
102 | QTest::newRow("label0") << QString("label0") << QString("label0"); |
|
102 | QTest::newRow("label0") << QString("label0") << QString("label0"); | |
103 | QTest::newRow("label1") << QString("label1") << QString("label1"); |
|
103 | QTest::newRow("label1") << QString("label1") << QString("label1"); | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | void tst_QBarSet::label() |
|
106 | void tst_QBarSet::label() | |
107 | { |
|
107 | { | |
108 | QFETCH(QString, label); |
|
108 | QFETCH(QString, label); | |
109 | QFETCH(QString, result); |
|
109 | QFETCH(QString, result); | |
110 |
|
110 | |||
111 | QSignalSpy labelSpy(m_barset,SIGNAL(labelChanged())); |
|
111 | QSignalSpy labelSpy(m_barset,SIGNAL(labelChanged())); | |
112 | m_barset->setLabel(label); |
|
112 | m_barset->setLabel(label); | |
113 | QCOMPARE(m_barset->label(), result); |
|
113 | QCOMPARE(m_barset->label(), result); | |
114 | QVERIFY(labelSpy.count() == 1); |
|
114 | QVERIFY(labelSpy.count() == 1); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void tst_QBarSet::append_data() |
|
117 | void tst_QBarSet::append_data() | |
118 | { |
|
118 | { | |
119 | QTest::addColumn<int> ("count"); |
|
119 | QTest::addColumn<int> ("count"); | |
120 | QTest::newRow("0") << 0; |
|
120 | QTest::newRow("0") << 0; | |
121 | QTest::newRow("5") << 5; |
|
121 | QTest::newRow("5") << 5; | |
122 | QTest::newRow("100") << 100; |
|
122 | QTest::newRow("100") << 100; | |
123 | QTest::newRow("1000") << 1000; |
|
123 | QTest::newRow("1000") << 1000; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | void tst_QBarSet::append() |
|
126 | void tst_QBarSet::append() | |
127 | { |
|
127 | { | |
128 | QFETCH(int, count); |
|
128 | QFETCH(int, count); | |
129 |
|
129 | |||
130 | QCOMPARE(m_barset->count(), 0); |
|
130 | QCOMPARE(m_barset->count(), 0); | |
131 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
131 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
132 |
|
132 | |||
133 | QSignalSpy valueSpy(m_barset, SIGNAL(valuesAdded(int,int))); |
|
133 | QSignalSpy valueSpy(m_barset, SIGNAL(valuesAdded(int,int))); | |
134 |
|
134 | |||
135 | qreal sum(0.0); |
|
135 | qreal sum(0.0); | |
136 | qreal value(0.0); |
|
136 | qreal value(0.0); | |
137 |
|
137 | |||
138 | for (int i=0; i<count; i++) { |
|
138 | for (int i=0; i<count; i++) { | |
139 | m_barset->append(value); |
|
139 | m_barset->append(value); | |
140 | QCOMPARE(m_barset->at(i), value); |
|
140 | QCOMPARE(m_barset->at(i), value); | |
141 | sum += value; |
|
141 | sum += value; | |
142 | value += 1.0; |
|
142 | value += 1.0; | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | QCOMPARE(m_barset->count(), count); |
|
145 | QCOMPARE(m_barset->count(), count); | |
146 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); |
|
146 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); | |
147 |
|
147 | |||
148 | QCOMPARE(valueSpy.count(), count); |
|
148 | QCOMPARE(valueSpy.count(), count); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void tst_QBarSet::appendOperator_data() |
|
151 | void tst_QBarSet::appendOperator_data() | |
152 | { |
|
152 | { | |
153 | append_data(); |
|
153 | append_data(); | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void tst_QBarSet::appendOperator() |
|
156 | void tst_QBarSet::appendOperator() | |
157 | { |
|
157 | { | |
158 | QFETCH(int, count); |
|
158 | QFETCH(int, count); | |
159 |
|
159 | |||
160 | QCOMPARE(m_barset->count(), 0); |
|
160 | QCOMPARE(m_barset->count(), 0); | |
161 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
161 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
162 |
|
162 | |||
163 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int))); |
|
163 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int))); | |
164 |
|
164 | |||
165 | qreal sum(0.0); |
|
165 | qreal sum(0.0); | |
166 | qreal value(0.0); |
|
166 | qreal value(0.0); | |
167 |
|
167 | |||
168 | for (int i=0; i<count; i++) { |
|
168 | for (int i=0; i<count; i++) { | |
169 | *m_barset << value; |
|
169 | *m_barset << value; | |
170 | QCOMPARE(m_barset->at(i), value); |
|
170 | QCOMPARE(m_barset->at(i), value); | |
171 | sum += value; |
|
171 | sum += value; | |
172 | value += 1.0; |
|
172 | value += 1.0; | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | QCOMPARE(m_barset->count(), count); |
|
175 | QCOMPARE(m_barset->count(), count); | |
176 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); |
|
176 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); | |
177 | QCOMPARE(valueSpy.count(), count); |
|
177 | QCOMPARE(valueSpy.count(), count); | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | void tst_QBarSet::insert_data() |
|
180 | void tst_QBarSet::insert_data() | |
181 | { |
|
181 | { | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | void tst_QBarSet::insert() |
|
184 | void tst_QBarSet::insert() | |
185 | { |
|
185 | { | |
186 | QCOMPARE(m_barset->count(), 0); |
|
186 | QCOMPARE(m_barset->count(), 0); | |
187 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
187 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
188 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int))); |
|
188 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int))); | |
189 |
|
189 | |||
190 | m_barset->insert(0, 1.0); // 1.0 |
|
190 | m_barset->insert(0, 1.0); // 1.0 | |
191 | QCOMPARE(m_barset->at(0), 1.0); |
|
191 | QCOMPARE(m_barset->at(0), 1.0); | |
192 | QCOMPARE(m_barset->count(), 1); |
|
192 | QCOMPARE(m_barset->count(), 1); | |
193 | QVERIFY(qFuzzyCompare(m_barset->sum(), 1.0)); |
|
193 | QVERIFY(qFuzzyCompare(m_barset->sum(), 1.0)); | |
194 |
|
194 | |||
195 | m_barset->insert(0, 2.0); // 2.0 1.0 |
|
195 | m_barset->insert(0, 2.0); // 2.0 1.0 | |
196 | QCOMPARE(m_barset->at(0), 2.0); |
|
196 | QCOMPARE(m_barset->at(0), 2.0); | |
197 | QCOMPARE(m_barset->at(1), 1.0); |
|
197 | QCOMPARE(m_barset->at(1), 1.0); | |
198 | QCOMPARE(m_barset->count(), 2); |
|
198 | QCOMPARE(m_barset->count(), 2); | |
199 | QVERIFY(qFuzzyCompare(m_barset->sum(), 3.0)); |
|
199 | QVERIFY(qFuzzyCompare(m_barset->sum(), 3.0)); | |
200 |
|
200 | |||
201 | m_barset->insert(1, 3.0); // 2.0 3.0 1.0 |
|
201 | m_barset->insert(1, 3.0); // 2.0 3.0 1.0 | |
202 | QCOMPARE(m_barset->at(1), 3.0); |
|
202 | QCOMPARE(m_barset->at(1), 3.0); | |
203 | QCOMPARE(m_barset->at(0), 2.0); |
|
203 | QCOMPARE(m_barset->at(0), 2.0); | |
204 | QCOMPARE(m_barset->at(2), 1.0); |
|
204 | QCOMPARE(m_barset->at(2), 1.0); | |
205 | QCOMPARE(m_barset->count(), 3); |
|
205 | QCOMPARE(m_barset->count(), 3); | |
206 | QVERIFY(qFuzzyCompare(m_barset->sum(), 6.0)); |
|
206 | QVERIFY(qFuzzyCompare(m_barset->sum(), 6.0)); | |
207 | QCOMPARE(valueSpy.count(), 3); |
|
207 | QCOMPARE(valueSpy.count(), 3); | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | void tst_QBarSet::remove_data() |
|
210 | void tst_QBarSet::remove_data() | |
211 | { |
|
211 | { | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | void tst_QBarSet::remove() |
|
214 | void tst_QBarSet::remove() | |
215 | { |
|
215 | { | |
216 | QCOMPARE(m_barset->count(), 0); |
|
216 | QCOMPARE(m_barset->count(), 0); | |
217 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
217 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
218 |
|
218 | |||
219 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesRemoved(int,int))); |
|
219 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesRemoved(int,int))); | |
220 |
|
220 | |||
221 | m_barset->append(1.0); |
|
221 | m_barset->append(1.0); | |
222 | m_barset->append(2.0); |
|
222 | m_barset->append(2.0); | |
223 | m_barset->append(3.0); |
|
223 | m_barset->append(3.0); | |
224 | m_barset->append(4.0); |
|
224 | m_barset->append(4.0); | |
225 |
|
225 | |||
226 | QCOMPARE(m_barset->count(), 4); |
|
226 | QCOMPARE(m_barset->count(), 4); | |
227 | QCOMPARE(m_barset->sum(), 10.0); |
|
227 | QCOMPARE(m_barset->sum(), 10.0); | |
228 |
|
228 | |||
229 | // Remove middle |
|
229 | // Remove middle | |
230 | m_barset->remove(2); // 1.0 2.0 4.0 |
|
230 | m_barset->remove(2); // 1.0 2.0 4.0 | |
231 | QCOMPARE(m_barset->at(0), 1.0); |
|
231 | QCOMPARE(m_barset->at(0), 1.0); | |
232 | QCOMPARE(m_barset->at(1), 2.0); |
|
232 | QCOMPARE(m_barset->at(1), 2.0); | |
233 | QCOMPARE(m_barset->at(2), 4.0); |
|
233 | QCOMPARE(m_barset->at(2), 4.0); | |
234 | QCOMPARE(m_barset->count(), 3); |
|
234 | QCOMPARE(m_barset->count(), 3); | |
235 | QCOMPARE(m_barset->sum(), 7.0); |
|
235 | QCOMPARE(m_barset->sum(), 7.0); | |
236 | QCOMPARE(valueSpy.count(), 1); |
|
236 | QCOMPARE(valueSpy.count(), 1); | |
237 |
|
237 | |||
238 | QList<QVariant> valueSpyArg = valueSpy.takeFirst(); |
|
238 | QList<QVariant> valueSpyArg = valueSpy.takeFirst(); | |
239 | // Verify index of removed signal |
|
239 | // Verify index of removed signal | |
240 | QVERIFY(valueSpyArg.at(0).type() == QVariant::Int); |
|
240 | QVERIFY(valueSpyArg.at(0).type() == QVariant::Int); | |
241 | QVERIFY(valueSpyArg.at(0).toInt() == 2); |
|
241 | QVERIFY(valueSpyArg.at(0).toInt() == 2); | |
242 | // Verify count of removed signal |
|
242 | // Verify count of removed signal | |
243 | QVERIFY(valueSpyArg.at(1).type() == QVariant::Int); |
|
243 | QVERIFY(valueSpyArg.at(1).type() == QVariant::Int); | |
244 | QVERIFY(valueSpyArg.at(1).toInt() == 1); |
|
244 | QVERIFY(valueSpyArg.at(1).toInt() == 1); | |
245 |
|
245 | |||
246 | // Remove first |
|
246 | // Remove first | |
247 | m_barset->remove(0); // 2.0 4.0 |
|
247 | m_barset->remove(0); // 2.0 4.0 | |
248 | QCOMPARE(m_barset->at(0), 2.0); |
|
248 | QCOMPARE(m_barset->at(0), 2.0); | |
249 | QCOMPARE(m_barset->at(1), 4.0); |
|
249 | QCOMPARE(m_barset->at(1), 4.0); | |
250 | QCOMPARE(m_barset->count(), 2); |
|
250 | QCOMPARE(m_barset->count(), 2); | |
251 | QCOMPARE(m_barset->sum(), 6.0); |
|
251 | QCOMPARE(m_barset->sum(), 6.0); | |
252 |
|
252 | |||
253 | QCOMPARE(valueSpy.count(), 1); |
|
253 | QCOMPARE(valueSpy.count(), 1); | |
254 | valueSpyArg = valueSpy.takeFirst(); |
|
254 | valueSpyArg = valueSpy.takeFirst(); | |
255 | // Verify index of removed signal |
|
255 | // Verify index of removed signal | |
256 | QVERIFY(valueSpyArg.at(0).type() == QVariant::Int); |
|
256 | QVERIFY(valueSpyArg.at(0).type() == QVariant::Int); | |
257 | QVERIFY(valueSpyArg.at(0).toInt() == 0); |
|
257 | QVERIFY(valueSpyArg.at(0).toInt() == 0); | |
258 | // Verify count of removed signal |
|
258 | // Verify count of removed signal | |
259 | QVERIFY(valueSpyArg.at(1).type() == QVariant::Int); |
|
259 | QVERIFY(valueSpyArg.at(1).type() == QVariant::Int); | |
260 | QVERIFY(valueSpyArg.at(1).toInt() == 1); |
|
260 | QVERIFY(valueSpyArg.at(1).toInt() == 1); | |
261 |
|
261 | |||
262 |
|
262 | |||
263 | // Illegal indexes |
|
263 | // Illegal indexes | |
264 | m_barset->remove(4); |
|
264 | m_barset->remove(4); | |
265 | QCOMPARE(m_barset->count(), 2); |
|
265 | QCOMPARE(m_barset->count(), 2); | |
266 | QCOMPARE(m_barset->sum(), 6.0); |
|
266 | QCOMPARE(m_barset->sum(), 6.0); | |
267 | m_barset->remove(-1); |
|
267 | m_barset->remove(-1); | |
268 | QCOMPARE(m_barset->count(), 2); |
|
268 | QCOMPARE(m_barset->count(), 2); | |
269 | QCOMPARE(m_barset->sum(), 6.0); |
|
269 | QCOMPARE(m_barset->sum(), 6.0); | |
270 |
|
270 | |||
271 | // nothing removed, no signals should be emitted |
|
271 | // nothing removed, no signals should be emitted | |
272 | QCOMPARE(valueSpy.count(), 0); |
|
272 | QCOMPARE(valueSpy.count(), 0); | |
273 |
|
273 | |||
274 | // Remove more items than list has |
|
274 | // Remove more items than list has | |
275 | m_barset->remove(0,312); |
|
275 | m_barset->remove(0,312); | |
276 | QCOMPARE(m_barset->count(), 0); |
|
276 | QCOMPARE(m_barset->count(), 0); | |
277 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
277 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
278 |
|
278 | |||
279 | QCOMPARE(valueSpy.count(), 1); |
|
279 | QCOMPARE(valueSpy.count(), 1); | |
280 | valueSpyArg = valueSpy.takeFirst(); |
|
280 | valueSpyArg = valueSpy.takeFirst(); | |
281 |
|
281 | |||
282 | // Verify index of removed signal |
|
282 | // Verify index of removed signal | |
283 | QVERIFY(valueSpyArg.at(0).type() == QVariant::Int); |
|
283 | QVERIFY(valueSpyArg.at(0).type() == QVariant::Int); | |
284 | QVERIFY(valueSpyArg.at(0).toInt() == 0); |
|
284 | QVERIFY(valueSpyArg.at(0).toInt() == 0); | |
285 | // Verify count of removed signal (expect 2 values removed, because list had only 2 items) |
|
285 | // Verify count of removed signal (expect 2 values removed, because list had only 2 items) | |
286 | QVERIFY(valueSpyArg.at(1).type() == QVariant::Int); |
|
286 | QVERIFY(valueSpyArg.at(1).type() == QVariant::Int); | |
287 | QVERIFY(valueSpyArg.at(1).toInt() == 2); |
|
287 | QVERIFY(valueSpyArg.at(1).toInt() == 2); | |
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | void tst_QBarSet::replace_data() |
|
290 | void tst_QBarSet::replace_data() | |
291 | { |
|
291 | { | |
292 |
|
292 | |||
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | void tst_QBarSet::replace() |
|
295 | void tst_QBarSet::replace() | |
296 | { |
|
296 | { | |
297 | QCOMPARE(m_barset->count(), 0); |
|
297 | QCOMPARE(m_barset->count(), 0); | |
298 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
298 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
299 | QSignalSpy valueSpy(m_barset,SIGNAL(valueChanged(int))); |
|
299 | QSignalSpy valueSpy(m_barset,SIGNAL(valueChanged(int))); | |
300 |
|
300 | |||
301 | m_barset->append(1.0); |
|
301 | m_barset->append(1.0); | |
302 | m_barset->append(2.0); |
|
302 | m_barset->append(2.0); | |
303 | m_barset->append(3.0); |
|
303 | m_barset->append(3.0); | |
304 | m_barset->append(4.0); |
|
304 | m_barset->append(4.0); | |
305 |
|
305 | |||
306 | QCOMPARE(m_barset->count(), 4); |
|
306 | QCOMPARE(m_barset->count(), 4); | |
307 | QCOMPARE(m_barset->sum(), 10.0); |
|
307 | QCOMPARE(m_barset->sum(), 10.0); | |
308 |
|
308 | |||
309 | // Replace first |
|
309 | // Replace first | |
310 | m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0 |
|
310 | m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0 | |
311 | QCOMPARE(m_barset->count(), 4); |
|
311 | QCOMPARE(m_barset->count(), 4); | |
312 | QCOMPARE(m_barset->sum(), 14.0); |
|
312 | QCOMPARE(m_barset->sum(), 14.0); | |
313 | QCOMPARE(m_barset->at(0), 5.0); |
|
313 | QCOMPARE(m_barset->at(0), 5.0); | |
314 |
|
314 | |||
315 | // Replace last |
|
315 | // Replace last | |
316 | m_barset->replace(3, 6.0); |
|
316 | m_barset->replace(3, 6.0); | |
317 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
317 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |
318 | QCOMPARE(m_barset->sum(), 16.0); |
|
318 | QCOMPARE(m_barset->sum(), 16.0); | |
319 | QCOMPARE(m_barset->at(0), 5.0); |
|
319 | QCOMPARE(m_barset->at(0), 5.0); | |
320 | QCOMPARE(m_barset->at(1), 2.0); |
|
320 | QCOMPARE(m_barset->at(1), 2.0); | |
321 | QCOMPARE(m_barset->at(2), 3.0); |
|
321 | QCOMPARE(m_barset->at(2), 3.0); | |
322 | QCOMPARE(m_barset->at(3), 6.0); |
|
322 | QCOMPARE(m_barset->at(3), 6.0); | |
323 |
|
323 | |||
324 | // Illegal indexes |
|
324 | // Illegal indexes | |
325 | m_barset->replace(4, 6.0); |
|
325 | m_barset->replace(4, 6.0); | |
326 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
326 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |
327 | QCOMPARE(m_barset->sum(), 16.0); |
|
327 | QCOMPARE(m_barset->sum(), 16.0); | |
328 | m_barset->replace(-1, 6.0); |
|
328 | m_barset->replace(-1, 6.0); | |
329 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
329 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |
330 | QCOMPARE(m_barset->sum(), 16.0); |
|
330 | QCOMPARE(m_barset->sum(), 16.0); | |
331 | m_barset->replace(4, 1.0); |
|
331 | m_barset->replace(4, 1.0); | |
332 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
332 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |
333 | QCOMPARE(m_barset->sum(), 16.0); |
|
333 | QCOMPARE(m_barset->sum(), 16.0); | |
334 | m_barset->replace(-1, 1.0); |
|
334 | m_barset->replace(-1, 1.0); | |
335 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
335 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |
336 | QCOMPARE(m_barset->sum(), 16.0); |
|
336 | QCOMPARE(m_barset->sum(), 16.0); | |
337 |
|
337 | |||
338 | QVERIFY(valueSpy.count() == 2); |
|
338 | QVERIFY(valueSpy.count() == 2); | |
339 | } |
|
339 | } | |
340 |
|
340 | |||
341 | void tst_QBarSet::at_data() |
|
341 | void tst_QBarSet::at_data() | |
342 | { |
|
342 | { | |
343 |
|
343 | |||
344 | } |
|
344 | } | |
345 |
|
345 | |||
346 | void tst_QBarSet::at() |
|
346 | void tst_QBarSet::at() | |
347 | { |
|
347 | { | |
348 | QCOMPARE(m_barset->count(), 0); |
|
348 | QCOMPARE(m_barset->count(), 0); | |
349 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
349 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
350 |
|
350 | |||
351 | m_barset->append(1.0); |
|
351 | m_barset->append(1.0); | |
352 | m_barset->append(2.0); |
|
352 | m_barset->append(2.0); | |
353 | m_barset->append(3.0); |
|
353 | m_barset->append(3.0); | |
354 | m_barset->append(4.0); |
|
354 | m_barset->append(4.0); | |
355 |
|
355 | |||
356 | QCOMPARE(m_barset->at(0), 1.0); |
|
356 | QCOMPARE(m_barset->at(0), 1.0); | |
357 | QCOMPARE(m_barset->at(1), 2.0); |
|
357 | QCOMPARE(m_barset->at(1), 2.0); | |
358 | QCOMPARE(m_barset->at(2), 3.0); |
|
358 | QCOMPARE(m_barset->at(2), 3.0); | |
359 | QCOMPARE(m_barset->at(3), 4.0); |
|
359 | QCOMPARE(m_barset->at(3), 4.0); | |
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | void tst_QBarSet::atOperator_data() |
|
362 | void tst_QBarSet::atOperator_data() | |
363 | { |
|
363 | { | |
364 |
|
364 | |||
365 | } |
|
365 | } | |
366 |
|
366 | |||
367 | void tst_QBarSet::atOperator() |
|
367 | void tst_QBarSet::atOperator() | |
368 | { |
|
368 | { | |
369 | QCOMPARE(m_barset->count(), 0); |
|
369 | QCOMPARE(m_barset->count(), 0); | |
370 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
370 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
371 |
|
371 | |||
372 | m_barset->append(1.0); |
|
372 | m_barset->append(1.0); | |
373 | m_barset->append(2.0); |
|
373 | m_barset->append(2.0); | |
374 | m_barset->append(3.0); |
|
374 | m_barset->append(3.0); | |
375 | m_barset->append(4.0); |
|
375 | m_barset->append(4.0); | |
376 |
|
376 | |||
377 | QCOMPARE(m_barset->operator [](0), 1.0); |
|
377 | QCOMPARE(m_barset->operator [](0), 1.0); | |
378 | QCOMPARE(m_barset->operator [](1), 2.0); |
|
378 | QCOMPARE(m_barset->operator [](1), 2.0); | |
379 | QCOMPARE(m_barset->operator [](2), 3.0); |
|
379 | QCOMPARE(m_barset->operator [](2), 3.0); | |
380 | QCOMPARE(m_barset->operator [](3), 4.0); |
|
380 | QCOMPARE(m_barset->operator [](3), 4.0); | |
381 | } |
|
381 | } | |
382 |
|
382 | |||
383 | void tst_QBarSet::count_data() |
|
383 | void tst_QBarSet::count_data() | |
384 | { |
|
384 | { | |
385 |
|
385 | |||
386 | } |
|
386 | } | |
387 |
|
387 | |||
388 | void tst_QBarSet::count() |
|
388 | void tst_QBarSet::count() | |
389 | { |
|
389 | { | |
390 | QCOMPARE(m_barset->count(), 0); |
|
390 | QCOMPARE(m_barset->count(), 0); | |
391 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
391 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
392 |
|
392 | |||
393 | m_barset->append(1.0); |
|
393 | m_barset->append(1.0); | |
394 | QCOMPARE(m_barset->count(),1); |
|
394 | QCOMPARE(m_barset->count(),1); | |
395 | m_barset->append(2.0); |
|
395 | m_barset->append(2.0); | |
396 | QCOMPARE(m_barset->count(),2); |
|
396 | QCOMPARE(m_barset->count(),2); | |
397 | m_barset->append(3.0); |
|
397 | m_barset->append(3.0); | |
398 | QCOMPARE(m_barset->count(),3); |
|
398 | QCOMPARE(m_barset->count(),3); | |
399 | m_barset->append(4.0); |
|
399 | m_barset->append(4.0); | |
400 | QCOMPARE(m_barset->count(),4); |
|
400 | QCOMPARE(m_barset->count(),4); | |
401 | } |
|
401 | } | |
402 |
|
402 | |||
403 | void tst_QBarSet::sum_data() |
|
403 | void tst_QBarSet::sum_data() | |
404 | { |
|
404 | { | |
405 |
|
405 | |||
406 | } |
|
406 | } | |
407 |
|
407 | |||
408 | void tst_QBarSet::sum() |
|
408 | void tst_QBarSet::sum() | |
409 | { |
|
409 | { | |
410 | QCOMPARE(m_barset->count(), 0); |
|
410 | QCOMPARE(m_barset->count(), 0); | |
411 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
411 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
412 |
|
412 | |||
413 | m_barset->append(1.0); |
|
413 | m_barset->append(1.0); | |
414 | QVERIFY(qFuzzyCompare(m_barset->sum(),1.0)); |
|
414 | QVERIFY(qFuzzyCompare(m_barset->sum(),1.0)); | |
415 | m_barset->append(2.0); |
|
415 | m_barset->append(2.0); | |
416 | QVERIFY(qFuzzyCompare(m_barset->sum(),3.0)); |
|
416 | QVERIFY(qFuzzyCompare(m_barset->sum(),3.0)); | |
417 | m_barset->append(3.0); |
|
417 | m_barset->append(3.0); | |
418 | QVERIFY(qFuzzyCompare(m_barset->sum(),6.0)); |
|
418 | QVERIFY(qFuzzyCompare(m_barset->sum(),6.0)); | |
419 | m_barset->append(4.0); |
|
419 | m_barset->append(4.0); | |
420 | QVERIFY(qFuzzyCompare(m_barset->sum(),10.0)); |
|
420 | QVERIFY(qFuzzyCompare(m_barset->sum(),10.0)); | |
421 | } |
|
421 | } | |
422 |
|
422 | |||
423 | void tst_QBarSet::customize() |
|
423 | void tst_QBarSet::customize() | |
424 | { |
|
424 | { | |
425 | // Create sets |
|
425 | // Create sets | |
426 | QBarSet *set1 = new QBarSet("set1"); |
|
426 | QBarSet *set1 = new QBarSet("set1"); | |
427 | QBarSet *set2 = new QBarSet("set2"); |
|
427 | QBarSet *set2 = new QBarSet("set2"); | |
428 |
|
428 | |||
429 | // Append set1 to series |
|
429 | // Append set1 to series | |
430 |
Q |
|
430 | QBarSeries *series = new QBarSeries(); | |
431 | bool success = series->append(set1); |
|
431 | bool success = series->append(set1); | |
432 | QVERIFY(success); |
|
432 | QVERIFY(success); | |
433 |
|
433 | |||
434 | // Add series to the chart |
|
434 | // Add series to the chart | |
435 | QChartView view(new QChart()); |
|
435 | QChartView view(new QChart()); | |
436 | view.resize(200, 200); |
|
436 | view.resize(200, 200); | |
437 | view.chart()->addSeries(series); |
|
437 | view.chart()->addSeries(series); | |
438 | view.show(); |
|
438 | view.show(); | |
439 | QTest::qWaitForWindowShown(&view); |
|
439 | QTest::qWaitForWindowShown(&view); | |
440 |
|
440 | |||
441 | // Test adding data to the sets |
|
441 | // Test adding data to the sets | |
442 | *set1 << 1 << 2 << 1 << 3; |
|
442 | *set1 << 1 << 2 << 1 << 3; | |
443 | *set2 << 2 << 1 << 3 << 1; |
|
443 | *set2 << 2 << 1 << 3 << 1; | |
444 |
|
444 | |||
445 | // Test pen |
|
445 | // Test pen | |
446 | QVERIFY(set1->pen() != QPen()); |
|
446 | QVERIFY(set1->pen() != QPen()); | |
447 | QVERIFY(set2->pen() == QPen()); |
|
447 | QVERIFY(set2->pen() == QPen()); | |
448 | QPen pen(QColor(128,128,128,128)); |
|
448 | QPen pen(QColor(128,128,128,128)); | |
449 | set1->setPen(pen); |
|
449 | set1->setPen(pen); | |
450 | QVERIFY(set1->pen() == pen); |
|
450 | QVERIFY(set1->pen() == pen); | |
451 | QVERIFY(set2->pen() == QPen()); |
|
451 | QVERIFY(set2->pen() == QPen()); | |
452 |
|
452 | |||
453 | // Test brush |
|
453 | // Test brush | |
454 | QVERIFY(set1->brush() != QBrush()); |
|
454 | QVERIFY(set1->brush() != QBrush()); | |
455 | QVERIFY(set2->brush() == QBrush()); |
|
455 | QVERIFY(set2->brush() == QBrush()); | |
456 | QBrush brush(QColor(128,128,128,128)); |
|
456 | QBrush brush(QColor(128,128,128,128)); | |
457 | set1->setBrush(brush); |
|
457 | set1->setBrush(brush); | |
458 | QVERIFY(set1->brush() == brush); |
|
458 | QVERIFY(set1->brush() == brush); | |
459 | QVERIFY(set2->brush() == QBrush()); |
|
459 | QVERIFY(set2->brush() == QBrush()); | |
460 |
|
460 | |||
461 | // Test label brush |
|
461 | // Test label brush | |
462 | QVERIFY(set1->labelBrush() != QBrush()); |
|
462 | QVERIFY(set1->labelBrush() != QBrush()); | |
463 | QVERIFY(set2->labelBrush() == QBrush()); |
|
463 | QVERIFY(set2->labelBrush() == QBrush()); | |
464 | set1->setLabelBrush(brush); |
|
464 | set1->setLabelBrush(brush); | |
465 | QVERIFY(set1->labelBrush() == brush); |
|
465 | QVERIFY(set1->labelBrush() == brush); | |
466 | QVERIFY(set2->labelBrush() == QBrush()); |
|
466 | QVERIFY(set2->labelBrush() == QBrush()); | |
467 |
|
467 | |||
468 | // Test label font |
|
468 | // Test label font | |
469 | // Note: QFont empty constructor creates font with application's default font, so the font may or may not be the |
|
469 | // Note: QFont empty constructor creates font with application's default font, so the font may or may not be the | |
470 | // same for the set added to the series (depending on the QChart's theme configuration) |
|
470 | // same for the set added to the series (depending on the QChart's theme configuration) | |
471 | QVERIFY(set1->labelFont() != QFont() || set1->labelFont() == QFont()); |
|
471 | QVERIFY(set1->labelFont() != QFont() || set1->labelFont() == QFont()); | |
472 | QVERIFY(set2->labelFont() == QFont()); |
|
472 | QVERIFY(set2->labelFont() == QFont()); | |
473 | QFont font; |
|
473 | QFont font; | |
474 | font.setBold(true); |
|
474 | font.setBold(true); | |
475 | font.setItalic(true); |
|
475 | font.setItalic(true); | |
476 | set1->setLabelFont(font); |
|
476 | set1->setLabelFont(font); | |
477 | QVERIFY(set1->labelFont() == font); |
|
477 | QVERIFY(set1->labelFont() == font); | |
478 | QVERIFY(set2->labelFont() == QFont()); |
|
478 | QVERIFY(set2->labelFont() == QFont()); | |
479 |
|
479 | |||
480 | // Test adding data to the sets |
|
480 | // Test adding data to the sets | |
481 | *set1 << 1 << 2 << 1 << 3; |
|
481 | *set1 << 1 << 2 << 1 << 3; | |
482 | *set2 << 2 << 1 << 3 << 1; |
|
482 | *set2 << 2 << 1 << 3 << 1; | |
483 | } |
|
483 | } | |
484 |
|
484 | |||
485 | QTEST_MAIN(tst_QBarSet) |
|
485 | QTEST_MAIN(tst_QBarSet) | |
486 |
|
486 | |||
487 | #include "tst_qbarset.moc" |
|
487 | #include "tst_qbarset.moc" | |
488 |
|
488 |
@@ -1,615 +1,615 | |||||
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 <q |
|
29 | #include <qbarseries.h> | |
30 | #include <qpercentbarseries.h> |
|
30 | #include <qpercentbarseries.h> | |
31 | #include <qstackedbarseries.h> |
|
31 | #include <qstackedbarseries.h> | |
32 | #include <qvaluesaxis.h> |
|
32 | #include <qvaluesaxis.h> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
34 | QTCOMMERCIALCHART_USE_NAMESPACE | |
35 |
|
35 | |||
36 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
36 | Q_DECLARE_METATYPE(QAbstractAxis *) | |
37 | Q_DECLARE_METATYPE(QValuesAxis *) |
|
37 | Q_DECLARE_METATYPE(QValuesAxis *) | |
38 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
38 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
39 | Q_DECLARE_METATYPE(QChart::AnimationOption) |
|
39 | Q_DECLARE_METATYPE(QChart::AnimationOption) | |
40 | Q_DECLARE_METATYPE(QBrush) |
|
40 | Q_DECLARE_METATYPE(QBrush) | |
41 | Q_DECLARE_METATYPE(QPen) |
|
41 | Q_DECLARE_METATYPE(QPen) | |
42 | Q_DECLARE_METATYPE(QChart::ChartTheme) |
|
42 | Q_DECLARE_METATYPE(QChart::ChartTheme) | |
43 |
|
43 | |||
44 | class tst_QChart : public QObject |
|
44 | class tst_QChart : public QObject | |
45 | { |
|
45 | { | |
46 | Q_OBJECT |
|
46 | Q_OBJECT | |
47 |
|
47 | |||
48 | public slots: |
|
48 | public slots: | |
49 | void initTestCase(); |
|
49 | void initTestCase(); | |
50 | void cleanupTestCase(); |
|
50 | void cleanupTestCase(); | |
51 | void init(); |
|
51 | void init(); | |
52 | void cleanup(); |
|
52 | void cleanup(); | |
53 |
|
53 | |||
54 | private slots: |
|
54 | private slots: | |
55 | void qchart_data(); |
|
55 | void qchart_data(); | |
56 | void qchart(); |
|
56 | void qchart(); | |
57 |
|
57 | |||
58 | void addSeries_data(); |
|
58 | void addSeries_data(); | |
59 | void addSeries(); |
|
59 | void addSeries(); | |
60 | void animationOptions_data(); |
|
60 | void animationOptions_data(); | |
61 | void animationOptions(); |
|
61 | void animationOptions(); | |
62 | void axisX_data(); |
|
62 | void axisX_data(); | |
63 | void axisX(); |
|
63 | void axisX(); | |
64 | void axisY_data(); |
|
64 | void axisY_data(); | |
65 | void axisY(); |
|
65 | void axisY(); | |
66 | void backgroundBrush_data(); |
|
66 | void backgroundBrush_data(); | |
67 | void backgroundBrush(); |
|
67 | void backgroundBrush(); | |
68 | void backgroundPen_data(); |
|
68 | void backgroundPen_data(); | |
69 | void backgroundPen(); |
|
69 | void backgroundPen(); | |
70 | void isBackgroundVisible_data(); |
|
70 | void isBackgroundVisible_data(); | |
71 | void isBackgroundVisible(); |
|
71 | void isBackgroundVisible(); | |
72 | void legend_data(); |
|
72 | void legend_data(); | |
73 | void legend(); |
|
73 | void legend(); | |
74 | void margins_data(); |
|
74 | void margins_data(); | |
75 | void margins(); |
|
75 | void margins(); | |
76 | void removeAllSeries_data(); |
|
76 | void removeAllSeries_data(); | |
77 | void removeAllSeries(); |
|
77 | void removeAllSeries(); | |
78 | void removeSeries_data(); |
|
78 | void removeSeries_data(); | |
79 | void removeSeries(); |
|
79 | void removeSeries(); | |
80 | void scroll_data(); |
|
80 | void scroll_data(); | |
81 | void scroll(); |
|
81 | void scroll(); | |
82 | void theme_data(); |
|
82 | void theme_data(); | |
83 | void theme(); |
|
83 | void theme(); | |
84 | void title_data(); |
|
84 | void title_data(); | |
85 | void title(); |
|
85 | void title(); | |
86 | void titleBrush_data(); |
|
86 | void titleBrush_data(); | |
87 | void titleBrush(); |
|
87 | void titleBrush(); | |
88 | void titleFont_data(); |
|
88 | void titleFont_data(); | |
89 | void titleFont(); |
|
89 | void titleFont(); | |
90 | void zoomIn_data(); |
|
90 | void zoomIn_data(); | |
91 | void zoomIn(); |
|
91 | void zoomIn(); | |
92 | void zoomOut_data(); |
|
92 | void zoomOut_data(); | |
93 | void zoomOut(); |
|
93 | void zoomOut(); | |
94 |
|
94 | |||
95 | private: |
|
95 | private: | |
96 | void createTestData(); |
|
96 | void createTestData(); | |
97 |
|
97 | |||
98 | private: |
|
98 | private: | |
99 | QChartView* m_view; |
|
99 | QChartView* m_view; | |
100 | QChart* m_chart; |
|
100 | QChart* m_chart; | |
101 | }; |
|
101 | }; | |
102 |
|
102 | |||
103 | void tst_QChart::initTestCase() |
|
103 | void tst_QChart::initTestCase() | |
104 | { |
|
104 | { | |
105 |
|
105 | |||
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | void tst_QChart::cleanupTestCase() |
|
108 | void tst_QChart::cleanupTestCase() | |
109 | { |
|
109 | { | |
110 |
|
110 | |||
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | void tst_QChart::init() |
|
113 | void tst_QChart::init() | |
114 | { |
|
114 | { | |
115 | m_view = new QChartView(new QChart()); |
|
115 | m_view = new QChartView(new QChart()); | |
116 | m_chart = m_view->chart(); |
|
116 | m_chart = m_view->chart(); | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | void tst_QChart::createTestData() |
|
119 | void tst_QChart::createTestData() | |
120 | { |
|
120 | { | |
121 | QLineSeries* series0 = new QLineSeries(this); |
|
121 | QLineSeries* series0 = new QLineSeries(this); | |
122 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
122 | *series0 << QPointF(0, 0) << QPointF(100, 100); | |
123 | m_chart->addSeries(series0); |
|
123 | m_chart->addSeries(series0); | |
124 | m_view->show(); |
|
124 | m_view->show(); | |
125 | QTest::qWaitForWindowShown(m_view); |
|
125 | QTest::qWaitForWindowShown(m_view); | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | void tst_QChart::cleanup() |
|
128 | void tst_QChart::cleanup() | |
129 | { |
|
129 | { | |
130 | delete m_view; |
|
130 | delete m_view; | |
131 | m_view = 0; |
|
131 | m_view = 0; | |
132 | m_chart = 0; |
|
132 | m_chart = 0; | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | void tst_QChart::qchart_data() |
|
135 | void tst_QChart::qchart_data() | |
136 | { |
|
136 | { | |
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | void tst_QChart::qchart() |
|
139 | void tst_QChart::qchart() | |
140 | { |
|
140 | { | |
141 | QVERIFY(m_chart); |
|
141 | QVERIFY(m_chart); | |
142 | QVERIFY(m_chart->legend()); |
|
142 | QVERIFY(m_chart->legend()); | |
143 | QVERIFY(m_chart->legend()->isVisible()); |
|
143 | QVERIFY(m_chart->legend()->isVisible()); | |
144 |
|
144 | |||
145 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); |
|
145 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); | |
146 | QVERIFY(m_chart->axisX()); |
|
146 | QVERIFY(m_chart->axisX()); | |
147 | QVERIFY(m_chart->axisY()); |
|
147 | QVERIFY(m_chart->axisY()); | |
148 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); |
|
148 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); | |
149 | QVERIFY(m_chart->backgroundPen()!=QPen()); |
|
149 | QVERIFY(m_chart->backgroundPen()!=QPen()); | |
150 | QCOMPARE(m_chart->isBackgroundVisible(), true); |
|
150 | QCOMPARE(m_chart->isBackgroundVisible(), true); | |
151 |
|
151 | |||
152 | QVERIFY(m_chart->margins().top()>0); |
|
152 | QVERIFY(m_chart->margins().top()>0); | |
153 | QVERIFY(m_chart->margins().left()>0); |
|
153 | QVERIFY(m_chart->margins().left()>0); | |
154 | QVERIFY(m_chart->margins().right()>0); |
|
154 | QVERIFY(m_chart->margins().right()>0); | |
155 | QVERIFY(m_chart->margins().bottom()>0); |
|
155 | QVERIFY(m_chart->margins().bottom()>0); | |
156 |
|
156 | |||
157 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); |
|
157 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); | |
158 | QCOMPARE(m_chart->title(), QString()); |
|
158 | QCOMPARE(m_chart->title(), QString()); | |
159 |
|
159 | |||
160 | //QCOMPARE(m_chart->titleBrush(),QBrush()); |
|
160 | //QCOMPARE(m_chart->titleBrush(),QBrush()); | |
161 | //QCOMPARE(m_chart->titleFont(),QFont()); |
|
161 | //QCOMPARE(m_chart->titleFont(),QFont()); | |
162 |
|
162 | |||
163 | m_chart->removeAllSeries(); |
|
163 | m_chart->removeAllSeries(); | |
164 | m_chart->scroll(0,0); |
|
164 | m_chart->scroll(0,0); | |
165 |
|
165 | |||
166 | m_chart->zoomIn(); |
|
166 | m_chart->zoomIn(); | |
167 | m_chart->zoomIn(QRectF()); |
|
167 | m_chart->zoomIn(QRectF()); | |
168 | m_chart->zoomOut(); |
|
168 | m_chart->zoomOut(); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | void tst_QChart::addSeries_data() |
|
171 | void tst_QChart::addSeries_data() | |
172 | { |
|
172 | { | |
173 | QTest::addColumn<QAbstractSeries *>("series"); |
|
173 | QTest::addColumn<QAbstractSeries *>("series"); | |
174 | QTest::addColumn<QAbstractAxis *>("axis"); |
|
174 | QTest::addColumn<QAbstractAxis *>("axis"); | |
175 |
|
175 | |||
176 | QAbstractSeries* series0 = new QLineSeries(this); |
|
176 | QAbstractSeries* series0 = new QLineSeries(this); | |
177 | QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0)); |
|
177 | QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0)); | |
178 | QAbstractSeries* series2 = new QScatterSeries(this); |
|
178 | QAbstractSeries* series2 = new QScatterSeries(this); | |
179 | QAbstractSeries* series3 = new QSplineSeries(this); |
|
179 | QAbstractSeries* series3 = new QSplineSeries(this); | |
180 | QAbstractSeries* series4 = new QPieSeries(this); |
|
180 | QAbstractSeries* series4 = new QPieSeries(this); | |
181 |
QAbstractSeries* series5 = new Q |
|
181 | QAbstractSeries* series5 = new QBarSeries(this); | |
182 | QAbstractSeries* series6 = new QPercentBarSeries(this); |
|
182 | QAbstractSeries* series6 = new QPercentBarSeries(this); | |
183 | QAbstractSeries* series7 = new QStackedBarSeries(this); |
|
183 | QAbstractSeries* series7 = new QStackedBarSeries(this); | |
184 |
|
184 | |||
185 | QValuesAxis* axis = new QValuesAxis(this); |
|
185 | QValuesAxis* axis = new QValuesAxis(this); | |
186 |
|
186 | |||
187 | QTest::newRow("default axis: lineSeries") << series0 << (QAbstractAxis*) 0; |
|
187 | QTest::newRow("default axis: lineSeries") << series0 << (QAbstractAxis*) 0; | |
188 | QTest::newRow("axis0: lineSeries") << series0 << axis; |
|
188 | QTest::newRow("axis0: lineSeries") << series0 << axis; | |
189 | QTest::newRow("default axis: areaSeries") << series1 << (QAbstractAxis*) 0; |
|
189 | QTest::newRow("default axis: areaSeries") << series1 << (QAbstractAxis*) 0; | |
190 | QTest::newRow("axis: areaSeries") << series1 << axis; |
|
190 | QTest::newRow("axis: areaSeries") << series1 << axis; | |
191 | QTest::newRow("default axis: scatterSeries") << series2 << (QAbstractAxis*) 0; |
|
191 | QTest::newRow("default axis: scatterSeries") << series2 << (QAbstractAxis*) 0; | |
192 | QTest::newRow("axis1: scatterSeries") << series2 << axis; |
|
192 | QTest::newRow("axis1: scatterSeries") << series2 << axis; | |
193 | QTest::newRow("default axis: splineSeries") << series3 << (QAbstractAxis*) 0; |
|
193 | QTest::newRow("default axis: splineSeries") << series3 << (QAbstractAxis*) 0; | |
194 | QTest::newRow("axis: splineSeries") << series3 << axis; |
|
194 | QTest::newRow("axis: splineSeries") << series3 << axis; | |
195 | QTest::newRow("default axis: pieSeries") << series4 << (QAbstractAxis*) 0; |
|
195 | QTest::newRow("default axis: pieSeries") << series4 << (QAbstractAxis*) 0; | |
196 | QTest::newRow("axis: pieSeries") << series4 << axis; |
|
196 | QTest::newRow("axis: pieSeries") << series4 << axis; | |
197 | QTest::newRow("default axis: barSeries") << series5 << (QAbstractAxis*) 0; |
|
197 | QTest::newRow("default axis: barSeries") << series5 << (QAbstractAxis*) 0; | |
198 | QTest::newRow("axis: barSeries") << series5 << axis; |
|
198 | QTest::newRow("axis: barSeries") << series5 << axis; | |
199 | QTest::newRow("default axis: percentBarSeries") << series6 << (QAbstractAxis*) 0; |
|
199 | QTest::newRow("default axis: percentBarSeries") << series6 << (QAbstractAxis*) 0; | |
200 | QTest::newRow("axis: barSeries") << series6 << axis; |
|
200 | QTest::newRow("axis: barSeries") << series6 << axis; | |
201 | QTest::newRow("default axis: stackedBarSeries") << series7 << (QAbstractAxis*) 0; |
|
201 | QTest::newRow("default axis: stackedBarSeries") << series7 << (QAbstractAxis*) 0; | |
202 | QTest::newRow("axis: barSeries") << series7 << axis; |
|
202 | QTest::newRow("axis: barSeries") << series7 << axis; | |
203 |
|
203 | |||
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | void tst_QChart::addSeries() |
|
206 | void tst_QChart::addSeries() | |
207 | { |
|
207 | { | |
208 | QFETCH(QAbstractSeries *, series); |
|
208 | QFETCH(QAbstractSeries *, series); | |
209 | QFETCH(QAbstractAxis *, axis); |
|
209 | QFETCH(QAbstractAxis *, axis); | |
210 | m_view->show(); |
|
210 | m_view->show(); | |
211 | QTest::qWaitForWindowShown(m_view); |
|
211 | QTest::qWaitForWindowShown(m_view); | |
212 | if(!axis) axis = m_chart->axisY(); |
|
212 | if(!axis) axis = m_chart->axisY(); | |
213 | QVERIFY(!series->chart()); |
|
213 | QVERIFY(!series->chart()); | |
214 | QCOMPARE(m_chart->series().count(), 0); |
|
214 | QCOMPARE(m_chart->series().count(), 0); | |
215 | m_chart->addSeries(series); |
|
215 | m_chart->addSeries(series); | |
216 | m_chart->setAxisY(axis,series); |
|
216 | m_chart->setAxisY(axis,series); | |
217 | QCOMPARE(m_chart->series().count(), 1); |
|
217 | QCOMPARE(m_chart->series().count(), 1); | |
218 | QCOMPARE(m_chart->series().first(), series); |
|
218 | QCOMPARE(m_chart->series().first(), series); | |
219 | QVERIFY(series->chart() == m_chart); |
|
219 | QVERIFY(series->chart() == m_chart); | |
220 | QCOMPARE(m_chart->axisY(series),axis); |
|
220 | QCOMPARE(m_chart->axisY(series),axis); | |
221 | m_chart->removeSeries(series); |
|
221 | m_chart->removeSeries(series); | |
222 | QVERIFY(!series->chart()); |
|
222 | QVERIFY(!series->chart()); | |
223 | QCOMPARE(m_chart->series().count(), 0); |
|
223 | QCOMPARE(m_chart->series().count(), 0); | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 | void tst_QChart::animationOptions_data() |
|
226 | void tst_QChart::animationOptions_data() | |
227 | { |
|
227 | { | |
228 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); |
|
228 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); | |
229 | QTest::newRow("AllAnimations") << QChart::AllAnimations; |
|
229 | QTest::newRow("AllAnimations") << QChart::AllAnimations; | |
230 | QTest::newRow("NoAnimation") << QChart::NoAnimation; |
|
230 | QTest::newRow("NoAnimation") << QChart::NoAnimation; | |
231 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; |
|
231 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; | |
232 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; |
|
232 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | void tst_QChart::animationOptions() |
|
235 | void tst_QChart::animationOptions() | |
236 | { |
|
236 | { | |
237 | createTestData(); |
|
237 | createTestData(); | |
238 | QFETCH(QChart::AnimationOption, animationOptions); |
|
238 | QFETCH(QChart::AnimationOption, animationOptions); | |
239 | m_chart->setAnimationOptions(animationOptions); |
|
239 | m_chart->setAnimationOptions(animationOptions); | |
240 | QCOMPARE(m_chart->animationOptions(), animationOptions); |
|
240 | QCOMPARE(m_chart->animationOptions(), animationOptions); | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | void tst_QChart::axisX_data() |
|
243 | void tst_QChart::axisX_data() | |
244 | { |
|
244 | { | |
245 |
|
245 | |||
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | void tst_QChart::axisX() |
|
248 | void tst_QChart::axisX() | |
249 | { |
|
249 | { | |
250 | QVERIFY(m_chart->axisX()); |
|
250 | QVERIFY(m_chart->axisX()); | |
251 | QAbstractAxis* axis = m_chart->axisX(); |
|
251 | QAbstractAxis* axis = m_chart->axisX(); | |
252 | createTestData(); |
|
252 | createTestData(); | |
253 | //it should be the same axis |
|
253 | //it should be the same axis | |
254 | QCOMPARE(axis,m_chart->axisX()); |
|
254 | QCOMPARE(axis,m_chart->axisX()); | |
255 | } |
|
255 | } | |
256 |
|
256 | |||
257 | void tst_QChart::axisY_data() |
|
257 | void tst_QChart::axisY_data() | |
258 | { |
|
258 | { | |
259 | QTest::addColumn<QAbstractAxis*>("axis0"); |
|
259 | QTest::addColumn<QAbstractAxis*>("axis0"); | |
260 | QTest::addColumn<QAbstractAxis*>("axis1"); |
|
260 | QTest::addColumn<QAbstractAxis*>("axis1"); | |
261 | QTest::addColumn<QAbstractAxis*>("axis2"); |
|
261 | QTest::addColumn<QAbstractAxis*>("axis2"); | |
262 | QTest::newRow("1 defualt, 2 optional") << (QAbstractAxis*)0 << new QValuesAxis() << new QValuesAxis(); |
|
262 | QTest::newRow("1 defualt, 2 optional") << (QAbstractAxis*)0 << new QValuesAxis() << new QValuesAxis(); | |
263 | QTest::newRow("3 optional") << new QValuesAxis() << new QValuesAxis() << new QValuesAxis(); |
|
263 | QTest::newRow("3 optional") << new QValuesAxis() << new QValuesAxis() << new QValuesAxis(); | |
264 | } |
|
264 | } | |
265 |
|
265 | |||
266 |
|
266 | |||
267 | void tst_QChart::axisY() |
|
267 | void tst_QChart::axisY() | |
268 | { |
|
268 | { | |
269 | QFETCH(QAbstractAxis*, axis0); |
|
269 | QFETCH(QAbstractAxis*, axis0); | |
270 | QFETCH(QAbstractAxis*, axis1); |
|
270 | QFETCH(QAbstractAxis*, axis1); | |
271 | QFETCH(QAbstractAxis*, axis2); |
|
271 | QFETCH(QAbstractAxis*, axis2); | |
272 |
|
272 | |||
273 | QAbstractAxis* defaultAxisY = m_chart->axisY(); |
|
273 | QAbstractAxis* defaultAxisY = m_chart->axisY(); | |
274 |
|
274 | |||
275 | QVERIFY2(defaultAxisY, "Missing axisY."); |
|
275 | QVERIFY2(defaultAxisY, "Missing axisY."); | |
276 |
|
276 | |||
277 | QLineSeries* series0 = new QLineSeries(); |
|
277 | QLineSeries* series0 = new QLineSeries(); | |
278 | m_chart->addSeries(series0); |
|
278 | m_chart->addSeries(series0); | |
279 | m_chart->setAxisY(axis0,series0); |
|
279 | m_chart->setAxisY(axis0,series0); | |
280 |
|
280 | |||
281 | QLineSeries* series1 = new QLineSeries(); |
|
281 | QLineSeries* series1 = new QLineSeries(); | |
282 | m_chart->addSeries(series1); |
|
282 | m_chart->addSeries(series1); | |
283 | m_chart->setAxisY(axis1,series1); |
|
283 | m_chart->setAxisY(axis1,series1); | |
284 |
|
284 | |||
285 | QLineSeries* series2 = new QLineSeries(); |
|
285 | QLineSeries* series2 = new QLineSeries(); | |
286 | m_chart->addSeries(series2); |
|
286 | m_chart->addSeries(series2); | |
287 | m_chart->setAxisY(axis2,series2); |
|
287 | m_chart->setAxisY(axis2,series2); | |
288 |
|
288 | |||
289 | if (!axis0) |
|
289 | if (!axis0) | |
290 | axis0 = defaultAxisY; |
|
290 | axis0 = defaultAxisY; | |
291 | if (!axis1) |
|
291 | if (!axis1) | |
292 | axis1 = defaultAxisY; |
|
292 | axis1 = defaultAxisY; | |
293 | if (!axis2) |
|
293 | if (!axis2) | |
294 | axis2 = defaultAxisY; |
|
294 | axis2 = defaultAxisY; | |
295 |
|
295 | |||
296 | QVERIFY(m_chart->axisY(series0) == axis0); |
|
296 | QVERIFY(m_chart->axisY(series0) == axis0); | |
297 | QVERIFY(m_chart->axisY(series1) == axis1); |
|
297 | QVERIFY(m_chart->axisY(series1) == axis1); | |
298 | QVERIFY(m_chart->axisY(series2) == axis2); |
|
298 | QVERIFY(m_chart->axisY(series2) == axis2); | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | void tst_QChart::backgroundBrush_data() |
|
301 | void tst_QChart::backgroundBrush_data() | |
302 | { |
|
302 | { | |
303 | QTest::addColumn<QBrush>("backgroundBrush"); |
|
303 | QTest::addColumn<QBrush>("backgroundBrush"); | |
304 | QTest::newRow("null") << QBrush(); |
|
304 | QTest::newRow("null") << QBrush(); | |
305 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
305 | QTest::newRow("blue") << QBrush(Qt::blue); | |
306 | QTest::newRow("white") << QBrush(Qt::white); |
|
306 | QTest::newRow("white") << QBrush(Qt::white); | |
307 | QTest::newRow("black") << QBrush(Qt::black); |
|
307 | QTest::newRow("black") << QBrush(Qt::black); | |
308 | } |
|
308 | } | |
309 |
|
309 | |||
310 | void tst_QChart::backgroundBrush() |
|
310 | void tst_QChart::backgroundBrush() | |
311 | { |
|
311 | { | |
312 | QFETCH(QBrush, backgroundBrush); |
|
312 | QFETCH(QBrush, backgroundBrush); | |
313 | m_chart->setBackgroundBrush(backgroundBrush); |
|
313 | m_chart->setBackgroundBrush(backgroundBrush); | |
314 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); |
|
314 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | void tst_QChart::backgroundPen_data() |
|
317 | void tst_QChart::backgroundPen_data() | |
318 | { |
|
318 | { | |
319 | QTest::addColumn<QPen>("backgroundPen"); |
|
319 | QTest::addColumn<QPen>("backgroundPen"); | |
320 | QTest::newRow("null") << QPen(); |
|
320 | QTest::newRow("null") << QPen(); | |
321 | QTest::newRow("blue") << QPen(Qt::blue); |
|
321 | QTest::newRow("blue") << QPen(Qt::blue); | |
322 | QTest::newRow("white") << QPen(Qt::white); |
|
322 | QTest::newRow("white") << QPen(Qt::white); | |
323 | QTest::newRow("black") << QPen(Qt::black); |
|
323 | QTest::newRow("black") << QPen(Qt::black); | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 |
|
326 | |||
327 | void tst_QChart::backgroundPen() |
|
327 | void tst_QChart::backgroundPen() | |
328 | { |
|
328 | { | |
329 | QFETCH(QPen, backgroundPen); |
|
329 | QFETCH(QPen, backgroundPen); | |
330 | m_chart->setBackgroundPen(backgroundPen); |
|
330 | m_chart->setBackgroundPen(backgroundPen); | |
331 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); |
|
331 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); | |
332 | } |
|
332 | } | |
333 |
|
333 | |||
334 | void tst_QChart::isBackgroundVisible_data() |
|
334 | void tst_QChart::isBackgroundVisible_data() | |
335 | { |
|
335 | { | |
336 | QTest::addColumn<bool>("isBackgroundVisible"); |
|
336 | QTest::addColumn<bool>("isBackgroundVisible"); | |
337 | QTest::newRow("true") << true; |
|
337 | QTest::newRow("true") << true; | |
338 | QTest::newRow("false") << false; |
|
338 | QTest::newRow("false") << false; | |
339 | } |
|
339 | } | |
340 |
|
340 | |||
341 | void tst_QChart::isBackgroundVisible() |
|
341 | void tst_QChart::isBackgroundVisible() | |
342 | { |
|
342 | { | |
343 | QFETCH(bool, isBackgroundVisible); |
|
343 | QFETCH(bool, isBackgroundVisible); | |
344 | m_chart->setBackgroundVisible(isBackgroundVisible); |
|
344 | m_chart->setBackgroundVisible(isBackgroundVisible); | |
345 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); |
|
345 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); | |
346 | } |
|
346 | } | |
347 |
|
347 | |||
348 | void tst_QChart::legend_data() |
|
348 | void tst_QChart::legend_data() | |
349 | { |
|
349 | { | |
350 |
|
350 | |||
351 | } |
|
351 | } | |
352 |
|
352 | |||
353 | void tst_QChart::legend() |
|
353 | void tst_QChart::legend() | |
354 | { |
|
354 | { | |
355 | QLegend *legend = m_chart->legend(); |
|
355 | QLegend *legend = m_chart->legend(); | |
356 | QVERIFY(legend); |
|
356 | QVERIFY(legend); | |
357 |
|
357 | |||
358 | // Colors related signals |
|
358 | // Colors related signals | |
359 | QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor))); |
|
359 | QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor))); | |
360 | QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor))); |
|
360 | QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor))); | |
361 | QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor))); |
|
361 | QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor))); | |
362 |
|
362 | |||
363 | // colorChanged |
|
363 | // colorChanged | |
364 | legend->setColor(QColor("aliceblue")); |
|
364 | legend->setColor(QColor("aliceblue")); | |
365 | QCOMPARE(colorSpy.count(), 1); |
|
365 | QCOMPARE(colorSpy.count(), 1); | |
366 | QBrush b = legend->brush(); |
|
366 | QBrush b = legend->brush(); | |
367 | b.setColor(QColor("aqua")); |
|
367 | b.setColor(QColor("aqua")); | |
368 | legend->setBrush(b); |
|
368 | legend->setBrush(b); | |
369 | QCOMPARE(colorSpy.count(), 2); |
|
369 | QCOMPARE(colorSpy.count(), 2); | |
370 |
|
370 | |||
371 | // borderColorChanged |
|
371 | // borderColorChanged | |
372 | legend->setBorderColor(QColor("aliceblue")); |
|
372 | legend->setBorderColor(QColor("aliceblue")); | |
373 | QCOMPARE(borderColorSpy.count(), 1); |
|
373 | QCOMPARE(borderColorSpy.count(), 1); | |
374 | QPen p = legend->pen(); |
|
374 | QPen p = legend->pen(); | |
375 | p.setColor(QColor("aqua")); |
|
375 | p.setColor(QColor("aqua")); | |
376 | legend->setPen(p); |
|
376 | legend->setPen(p); | |
377 | QCOMPARE(borderColorSpy.count(), 2); |
|
377 | QCOMPARE(borderColorSpy.count(), 2); | |
378 |
|
378 | |||
379 | // labelColorChanged |
|
379 | // labelColorChanged | |
380 | legend->setLabelColor(QColor("lightsalmon")); |
|
380 | legend->setLabelColor(QColor("lightsalmon")); | |
381 | QCOMPARE(labelColorSpy.count(), 1); |
|
381 | QCOMPARE(labelColorSpy.count(), 1); | |
382 | b = legend->labelBrush(); |
|
382 | b = legend->labelBrush(); | |
383 | b.setColor(QColor("lightseagreen")); |
|
383 | b.setColor(QColor("lightseagreen")); | |
384 | legend->setLabelBrush(b); |
|
384 | legend->setLabelBrush(b); | |
385 | QCOMPARE(labelColorSpy.count(), 2); |
|
385 | QCOMPARE(labelColorSpy.count(), 2); | |
386 |
|
386 | |||
387 | // fontChanged |
|
387 | // fontChanged | |
388 | QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont))); |
|
388 | QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont))); | |
389 | QFont f = legend->font(); |
|
389 | QFont f = legend->font(); | |
390 | f.setBold(!f.bold()); |
|
390 | f.setBold(!f.bold()); | |
391 | legend->setFont(f); |
|
391 | legend->setFont(f); | |
392 | QCOMPARE(fontSpy.count(), 1); |
|
392 | QCOMPARE(fontSpy.count(), 1); | |
393 | } |
|
393 | } | |
394 |
|
394 | |||
395 | void tst_QChart::margins_data() |
|
395 | void tst_QChart::margins_data() | |
396 | { |
|
396 | { | |
397 |
|
397 | |||
398 | } |
|
398 | } | |
399 |
|
399 | |||
400 | void tst_QChart::margins() |
|
400 | void tst_QChart::margins() | |
401 | { |
|
401 | { | |
402 | createTestData(); |
|
402 | createTestData(); | |
403 | QRectF rect = m_chart->geometry(); |
|
403 | QRectF rect = m_chart->geometry(); | |
404 |
|
404 | |||
405 | QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); |
|
405 | QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); | |
406 | QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); |
|
406 | QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); | |
407 | } |
|
407 | } | |
408 |
|
408 | |||
409 | void tst_QChart::removeAllSeries_data() |
|
409 | void tst_QChart::removeAllSeries_data() | |
410 | { |
|
410 | { | |
411 |
|
411 | |||
412 | } |
|
412 | } | |
413 |
|
413 | |||
414 | void tst_QChart::removeAllSeries() |
|
414 | void tst_QChart::removeAllSeries() | |
415 | { |
|
415 | { | |
416 | QLineSeries* series0 = new QLineSeries(this); |
|
416 | QLineSeries* series0 = new QLineSeries(this); | |
417 | QLineSeries* series1 = new QLineSeries(this); |
|
417 | QLineSeries* series1 = new QLineSeries(this); | |
418 | QLineSeries* series2 = new QLineSeries(this); |
|
418 | QLineSeries* series2 = new QLineSeries(this); | |
419 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); |
|
419 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); | |
420 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); |
|
420 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); | |
421 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); |
|
421 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); | |
422 |
|
422 | |||
423 | m_chart->addSeries(series0); |
|
423 | m_chart->addSeries(series0); | |
424 | m_chart->addSeries(series1); |
|
424 | m_chart->addSeries(series1); | |
425 | m_chart->addSeries(series2); |
|
425 | m_chart->addSeries(series2); | |
426 | m_view->show(); |
|
426 | m_view->show(); | |
427 | QTest::qWaitForWindowShown(m_view); |
|
427 | QTest::qWaitForWindowShown(m_view); | |
428 |
|
428 | |||
429 | QVERIFY(m_chart->axisY(series0)!=0); |
|
429 | QVERIFY(m_chart->axisY(series0)!=0); | |
430 | QVERIFY(m_chart->axisY(series1)!=0); |
|
430 | QVERIFY(m_chart->axisY(series1)!=0); | |
431 | QVERIFY(m_chart->axisY(series2)!=0); |
|
431 | QVERIFY(m_chart->axisY(series2)!=0); | |
432 |
|
432 | |||
433 | m_chart->removeAllSeries(); |
|
433 | m_chart->removeAllSeries(); | |
434 | QVERIFY(m_chart->axisY(series0)==0); |
|
434 | QVERIFY(m_chart->axisY(series0)==0); | |
435 | QVERIFY(m_chart->axisY(series1)==0); |
|
435 | QVERIFY(m_chart->axisY(series1)==0); | |
436 | QVERIFY(m_chart->axisY(series2)==0); |
|
436 | QVERIFY(m_chart->axisY(series2)==0); | |
437 | QCOMPARE(deleteSpy1.count(), 1); |
|
437 | QCOMPARE(deleteSpy1.count(), 1); | |
438 | QCOMPARE(deleteSpy2.count(), 1); |
|
438 | QCOMPARE(deleteSpy2.count(), 1); | |
439 | QCOMPARE(deleteSpy3.count(), 1); |
|
439 | QCOMPARE(deleteSpy3.count(), 1); | |
440 | } |
|
440 | } | |
441 |
|
441 | |||
442 | void tst_QChart::removeSeries_data() |
|
442 | void tst_QChart::removeSeries_data() | |
443 | { |
|
443 | { | |
444 | addSeries_data(); |
|
444 | addSeries_data(); | |
445 | } |
|
445 | } | |
446 |
|
446 | |||
447 | void tst_QChart::removeSeries() |
|
447 | void tst_QChart::removeSeries() | |
448 | { |
|
448 | { | |
449 | QFETCH(QAbstractSeries *, series); |
|
449 | QFETCH(QAbstractSeries *, series); | |
450 | QFETCH(QAbstractAxis *, axis); |
|
450 | QFETCH(QAbstractAxis *, axis); | |
451 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); |
|
451 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); | |
452 | m_view->show(); |
|
452 | m_view->show(); | |
453 | QTest::qWaitForWindowShown(m_view); |
|
453 | QTest::qWaitForWindowShown(m_view); | |
454 | if(!axis) axis = m_chart->axisY(); |
|
454 | if(!axis) axis = m_chart->axisY(); | |
455 | m_chart->addSeries(series); |
|
455 | m_chart->addSeries(series); | |
456 | m_chart->setAxisY(axis,series); |
|
456 | m_chart->setAxisY(axis,series); | |
457 | QCOMPARE(m_chart->axisY(series),axis); |
|
457 | QCOMPARE(m_chart->axisY(series),axis); | |
458 | m_chart->removeSeries(series); |
|
458 | m_chart->removeSeries(series); | |
459 | QVERIFY(m_chart->axisY(series)==0); |
|
459 | QVERIFY(m_chart->axisY(series)==0); | |
460 | QCOMPARE(deleteSpy.count(), 0); |
|
460 | QCOMPARE(deleteSpy.count(), 0); | |
461 | } |
|
461 | } | |
462 |
|
462 | |||
463 | void tst_QChart::scroll_data() |
|
463 | void tst_QChart::scroll_data() | |
464 | { |
|
464 | { | |
465 |
|
465 | |||
466 | } |
|
466 | } | |
467 |
|
467 | |||
468 | void tst_QChart::scroll() |
|
468 | void tst_QChart::scroll() | |
469 | { |
|
469 | { | |
470 | qFatal("implement me"); |
|
470 | qFatal("implement me"); | |
471 | createTestData(); |
|
471 | createTestData(); | |
472 | //TODO qreal min = m_chart->axisY()->min(); |
|
472 | //TODO qreal min = m_chart->axisY()->min(); | |
473 | m_chart->scroll(0,0); |
|
473 | m_chart->scroll(0,0); | |
474 | //TODO QVERIFY(m_chart->axisY()->min()<min); |
|
474 | //TODO QVERIFY(m_chart->axisY()->min()<min); | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | void tst_QChart::theme_data() |
|
477 | void tst_QChart::theme_data() | |
478 | { |
|
478 | { | |
479 | QTest::addColumn<QChart::ChartTheme>("theme"); |
|
479 | QTest::addColumn<QChart::ChartTheme>("theme"); | |
480 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; |
|
480 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; | |
481 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; |
|
481 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; | |
482 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; |
|
482 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; | |
483 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; |
|
483 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; | |
484 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; |
|
484 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; | |
485 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; |
|
485 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; | |
486 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; |
|
486 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; | |
487 | } |
|
487 | } | |
488 |
|
488 | |||
489 | void tst_QChart::theme() |
|
489 | void tst_QChart::theme() | |
490 | { |
|
490 | { | |
491 | QFETCH(QChart::ChartTheme, theme); |
|
491 | QFETCH(QChart::ChartTheme, theme); | |
492 | createTestData(); |
|
492 | createTestData(); | |
493 | m_chart->setTheme(theme); |
|
493 | m_chart->setTheme(theme); | |
494 | QVERIFY(m_chart->theme()==theme); |
|
494 | QVERIFY(m_chart->theme()==theme); | |
495 | } |
|
495 | } | |
496 |
|
496 | |||
497 | void tst_QChart::title_data() |
|
497 | void tst_QChart::title_data() | |
498 | { |
|
498 | { | |
499 | QTest::addColumn<QString>("title"); |
|
499 | QTest::addColumn<QString>("title"); | |
500 | QTest::newRow("null") << QString(); |
|
500 | QTest::newRow("null") << QString(); | |
501 | QTest::newRow("foo") << QString("foo"); |
|
501 | QTest::newRow("foo") << QString("foo"); | |
502 | } |
|
502 | } | |
503 |
|
503 | |||
504 | void tst_QChart::title() |
|
504 | void tst_QChart::title() | |
505 | { |
|
505 | { | |
506 | QFETCH(QString, title); |
|
506 | QFETCH(QString, title); | |
507 | m_chart->setTitle(title); |
|
507 | m_chart->setTitle(title); | |
508 | QCOMPARE(m_chart->title(), title); |
|
508 | QCOMPARE(m_chart->title(), title); | |
509 | } |
|
509 | } | |
510 |
|
510 | |||
511 | void tst_QChart::titleBrush_data() |
|
511 | void tst_QChart::titleBrush_data() | |
512 | { |
|
512 | { | |
513 | QTest::addColumn<QBrush>("titleBrush"); |
|
513 | QTest::addColumn<QBrush>("titleBrush"); | |
514 | QTest::newRow("null") << QBrush(); |
|
514 | QTest::newRow("null") << QBrush(); | |
515 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
515 | QTest::newRow("blue") << QBrush(Qt::blue); | |
516 | QTest::newRow("white") << QBrush(Qt::white); |
|
516 | QTest::newRow("white") << QBrush(Qt::white); | |
517 | QTest::newRow("black") << QBrush(Qt::black); |
|
517 | QTest::newRow("black") << QBrush(Qt::black); | |
518 | } |
|
518 | } | |
519 |
|
519 | |||
520 | void tst_QChart::titleBrush() |
|
520 | void tst_QChart::titleBrush() | |
521 | { |
|
521 | { | |
522 | QFETCH(QBrush, titleBrush); |
|
522 | QFETCH(QBrush, titleBrush); | |
523 | m_chart->setTitleBrush(titleBrush); |
|
523 | m_chart->setTitleBrush(titleBrush); | |
524 | QCOMPARE(m_chart->titleBrush(), titleBrush); |
|
524 | QCOMPARE(m_chart->titleBrush(), titleBrush); | |
525 | } |
|
525 | } | |
526 |
|
526 | |||
527 | void tst_QChart::titleFont_data() |
|
527 | void tst_QChart::titleFont_data() | |
528 | { |
|
528 | { | |
529 | QTest::addColumn<QFont>("titleFont"); |
|
529 | QTest::addColumn<QFont>("titleFont"); | |
530 | QTest::newRow("null") << QFont(); |
|
530 | QTest::newRow("null") << QFont(); | |
531 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); |
|
531 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); | |
532 | } |
|
532 | } | |
533 |
|
533 | |||
534 | void tst_QChart::titleFont() |
|
534 | void tst_QChart::titleFont() | |
535 | { |
|
535 | { | |
536 | QFETCH(QFont, titleFont); |
|
536 | QFETCH(QFont, titleFont); | |
537 | m_chart->setTitleFont(titleFont); |
|
537 | m_chart->setTitleFont(titleFont); | |
538 | QCOMPARE(m_chart->titleFont(), titleFont); |
|
538 | QCOMPARE(m_chart->titleFont(), titleFont); | |
539 | } |
|
539 | } | |
540 |
|
540 | |||
541 | void tst_QChart::zoomIn_data() |
|
541 | void tst_QChart::zoomIn_data() | |
542 | { |
|
542 | { | |
543 | QTest::addColumn<QRectF>("rect"); |
|
543 | QTest::addColumn<QRectF>("rect"); | |
544 | QTest::newRow("null") << QRectF(); |
|
544 | QTest::newRow("null") << QRectF(); | |
545 | QTest::newRow("100x100") << QRectF(10,10,100,100); |
|
545 | QTest::newRow("100x100") << QRectF(10,10,100,100); | |
546 | QTest::newRow("200x200") << QRectF(10,10,200,200); |
|
546 | QTest::newRow("200x200") << QRectF(10,10,200,200); | |
547 | } |
|
547 | } | |
548 |
|
548 | |||
549 |
|
549 | |||
550 | void tst_QChart::zoomIn() |
|
550 | void tst_QChart::zoomIn() | |
551 | { |
|
551 | { | |
552 | qFatal("implement me"); |
|
552 | qFatal("implement me"); | |
553 | /* |
|
553 | /* | |
554 | QFETCH(QRectF, rect); |
|
554 | QFETCH(QRectF, rect); | |
555 | createTestData(); |
|
555 | createTestData(); | |
556 | QRectF marigns = m_chart->margins(); |
|
556 | QRectF marigns = m_chart->margins(); | |
557 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); |
|
557 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); | |
558 | qreal minX = m_chart->axisX()->min(); |
|
558 | qreal minX = m_chart->axisX()->min(); | |
559 | qreal minY = m_chart->axisY()->min(); |
|
559 | qreal minY = m_chart->axisY()->min(); | |
560 | qreal maxX = m_chart->axisX()->max(); |
|
560 | qreal maxX = m_chart->axisX()->max(); | |
561 | qreal maxY = m_chart->axisY()->max(); |
|
561 | qreal maxY = m_chart->axisY()->max(); | |
562 | m_chart->zoomIn(rect); |
|
562 | m_chart->zoomIn(rect); | |
563 | if(rect.isValid()){ |
|
563 | if(rect.isValid()){ | |
564 | QVERIFY(minX<m_chart->axisX()->min()); |
|
564 | QVERIFY(minX<m_chart->axisX()->min()); | |
565 | QVERIFY(maxX>m_chart->axisX()->max()); |
|
565 | QVERIFY(maxX>m_chart->axisX()->max()); | |
566 | QVERIFY(minY<m_chart->axisY()->min()); |
|
566 | QVERIFY(minY<m_chart->axisY()->min()); | |
567 | QVERIFY(maxY>m_chart->axisY()->max()); |
|
567 | QVERIFY(maxY>m_chart->axisY()->max()); | |
568 | } |
|
568 | } | |
569 | */ |
|
569 | */ | |
570 | } |
|
570 | } | |
571 |
|
571 | |||
572 | void tst_QChart::zoomOut_data() |
|
572 | void tst_QChart::zoomOut_data() | |
573 | { |
|
573 | { | |
574 |
|
574 | |||
575 | } |
|
575 | } | |
576 |
|
576 | |||
577 | void tst_QChart::zoomOut() |
|
577 | void tst_QChart::zoomOut() | |
578 | { |
|
578 | { | |
579 | qFatal("implement me"); |
|
579 | qFatal("implement me"); | |
580 | createTestData(); |
|
580 | createTestData(); | |
581 | /* |
|
581 | /* | |
582 | qreal minX = m_chart->axisX()->min(); |
|
582 | qreal minX = m_chart->axisX()->min(); | |
583 | qreal minY = m_chart->axisY()->min(); |
|
583 | qreal minY = m_chart->axisY()->min(); | |
584 | qreal maxX = m_chart->axisX()->max(); |
|
584 | qreal maxX = m_chart->axisX()->max(); | |
585 | qreal maxY = m_chart->axisY()->max(); |
|
585 | qreal maxY = m_chart->axisY()->max(); | |
586 |
|
586 | |||
587 | m_chart->zoomIn(); |
|
587 | m_chart->zoomIn(); | |
588 |
|
588 | |||
589 | QVERIFY(minX < m_chart->axisX()->min()); |
|
589 | QVERIFY(minX < m_chart->axisX()->min()); | |
590 | QVERIFY(maxX > m_chart->axisX()->max()); |
|
590 | QVERIFY(maxX > m_chart->axisX()->max()); | |
591 | QVERIFY(minY < m_chart->axisY()->min()); |
|
591 | QVERIFY(minY < m_chart->axisY()->min()); | |
592 | QVERIFY(maxY > m_chart->axisY()->max()); |
|
592 | QVERIFY(maxY > m_chart->axisY()->max()); | |
593 |
|
593 | |||
594 | m_chart->zoomOut(); |
|
594 | m_chart->zoomOut(); | |
595 |
|
595 | |||
596 | // min x may be a zero value |
|
596 | // min x may be a zero value | |
597 | if (qFuzzyIsNull(minX)) |
|
597 | if (qFuzzyIsNull(minX)) | |
598 | QVERIFY(qFuzzyIsNull(m_chart->axisX()->min())); |
|
598 | QVERIFY(qFuzzyIsNull(m_chart->axisX()->min())); | |
599 | else |
|
599 | else | |
600 | QCOMPARE(minX, m_chart->axisX()->min()); |
|
600 | QCOMPARE(minX, m_chart->axisX()->min()); | |
601 |
|
601 | |||
602 | // min y may be a zero value |
|
602 | // min y may be a zero value | |
603 | if (qFuzzyIsNull(minY)) |
|
603 | if (qFuzzyIsNull(minY)) | |
604 | QVERIFY(qFuzzyIsNull(m_chart->axisY()->min())); |
|
604 | QVERIFY(qFuzzyIsNull(m_chart->axisY()->min())); | |
605 | else |
|
605 | else | |
606 | QCOMPARE(minY, m_chart->axisY()->min()); |
|
606 | QCOMPARE(minY, m_chart->axisY()->min()); | |
607 |
|
607 | |||
608 | QVERIFY(maxX == m_chart->axisX()->max()); |
|
608 | QVERIFY(maxX == m_chart->axisX()->max()); | |
609 | QVERIFY(maxY == m_chart->axisY()->max()); |
|
609 | QVERIFY(maxY == m_chart->axisY()->max()); | |
610 | */ |
|
610 | */ | |
611 | } |
|
611 | } | |
612 |
|
612 | |||
613 | QTEST_MAIN(tst_QChart) |
|
613 | QTEST_MAIN(tst_QChart) | |
614 | #include "tst_qchart.moc" |
|
614 | #include "tst_qchart.moc" | |
615 |
|
615 |
@@ -1,277 +1,277 | |||||
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 <q |
|
22 | #include <qbarseries.h> | |
23 | #include <qbarset.h> |
|
23 | #include <qbarset.h> | |
24 | #include <qchartview.h> |
|
24 | #include <qchartview.h> | |
25 | #include <qchart.h> |
|
25 | #include <qchart.h> | |
26 | #include <QBarModelMapper> |
|
26 | #include <QBarModelMapper> | |
27 | #include <QStandardItemModel> |
|
27 | #include <QStandardItemModel> | |
28 | #include "tst_definitions.h" |
|
28 | #include "tst_definitions.h" | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
30 | QTCOMMERCIALCHART_USE_NAMESPACE | |
31 |
|
31 | |||
32 | Q_DECLARE_METATYPE(QBarSet*) |
|
32 | Q_DECLARE_METATYPE(QBarSet*) | |
33 |
|
33 | |||
34 | class tst_QGroupedBarSeries : public QObject |
|
34 | class tst_QGroupedBarSeries : public QObject | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 |
|
37 | |||
38 | public slots: |
|
38 | public slots: | |
39 | void initTestCase(); |
|
39 | void initTestCase(); | |
40 | void cleanupTestCase(); |
|
40 | void cleanupTestCase(); | |
41 | void init(); |
|
41 | void init(); | |
42 | void cleanup(); |
|
42 | void cleanup(); | |
43 |
|
43 | |||
44 | private slots: |
|
44 | private slots: | |
45 | void qgroupedbarseries_data(); |
|
45 | void qgroupedbarseries_data(); | |
46 | void qgroupedbarseries(); |
|
46 | void qgroupedbarseries(); | |
47 | void type_data(); |
|
47 | void type_data(); | |
48 | void type(); |
|
48 | void type(); | |
49 | void mouseclicked_data(); |
|
49 | void mouseclicked_data(); | |
50 | void mouseclicked(); |
|
50 | void mouseclicked(); | |
51 | void mousehovered_data(); |
|
51 | void mousehovered_data(); | |
52 | void mousehovered(); |
|
52 | void mousehovered(); | |
53 |
|
53 | |||
54 | private: |
|
54 | private: | |
55 |
Q |
|
55 | QBarSeries* m_barseries; | |
56 | }; |
|
56 | }; | |
57 |
|
57 | |||
58 | void tst_QGroupedBarSeries::initTestCase() |
|
58 | void tst_QGroupedBarSeries::initTestCase() | |
59 | { |
|
59 | { | |
60 | qRegisterMetaType<QBarSet*>("QBarSet*"); |
|
60 | qRegisterMetaType<QBarSet*>("QBarSet*"); | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | void tst_QGroupedBarSeries::cleanupTestCase() |
|
63 | void tst_QGroupedBarSeries::cleanupTestCase() | |
64 | { |
|
64 | { | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | void tst_QGroupedBarSeries::init() |
|
67 | void tst_QGroupedBarSeries::init() | |
68 | { |
|
68 | { | |
69 |
m_barseries = new Q |
|
69 | m_barseries = new QBarSeries(); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void tst_QGroupedBarSeries::cleanup() |
|
72 | void tst_QGroupedBarSeries::cleanup() | |
73 | { |
|
73 | { | |
74 | delete m_barseries; |
|
74 | delete m_barseries; | |
75 | m_barseries = 0; |
|
75 | m_barseries = 0; | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void tst_QGroupedBarSeries::qgroupedbarseries_data() |
|
78 | void tst_QGroupedBarSeries::qgroupedbarseries_data() | |
79 | { |
|
79 | { | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | void tst_QGroupedBarSeries::qgroupedbarseries() |
|
82 | void tst_QGroupedBarSeries::qgroupedbarseries() | |
83 | { |
|
83 | { | |
84 |
Q |
|
84 | QBarSeries *barseries = new QBarSeries(); | |
85 | QVERIFY(barseries != 0); |
|
85 | QVERIFY(barseries != 0); | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | void tst_QGroupedBarSeries::type_data() |
|
88 | void tst_QGroupedBarSeries::type_data() | |
89 | { |
|
89 | { | |
90 |
|
90 | |||
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | void tst_QGroupedBarSeries::type() |
|
93 | void tst_QGroupedBarSeries::type() | |
94 | { |
|
94 | { | |
95 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeGroupedBar); |
|
95 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeGroupedBar); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void tst_QGroupedBarSeries::mouseclicked_data() |
|
98 | void tst_QGroupedBarSeries::mouseclicked_data() | |
99 | { |
|
99 | { | |
100 |
|
100 | |||
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | void tst_QGroupedBarSeries::mouseclicked() |
|
103 | void tst_QGroupedBarSeries::mouseclicked() | |
104 | { |
|
104 | { | |
105 |
Q |
|
105 | QBarSeries* series = new QBarSeries(); | |
106 |
|
106 | |||
107 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
107 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
108 | *set1 << 10 << 10 << 10; |
|
108 | *set1 << 10 << 10 << 10; | |
109 | series->append(set1); |
|
109 | series->append(set1); | |
110 |
|
110 | |||
111 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
111 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
112 | *set2 << 10 << 10 << 10; |
|
112 | *set2 << 10 << 10 << 10; | |
113 | series->append(set2); |
|
113 | series->append(set2); | |
114 |
|
114 | |||
115 | QSignalSpy seriesSpy(series,SIGNAL(clicked(int, QBarSet*))); |
|
115 | QSignalSpy seriesSpy(series,SIGNAL(clicked(int, QBarSet*))); | |
116 |
|
116 | |||
117 | QChartView view(new QChart()); |
|
117 | QChartView view(new QChart()); | |
118 | view.resize(400,300); |
|
118 | view.resize(400,300); | |
119 | view.chart()->addSeries(series); |
|
119 | view.chart()->addSeries(series); | |
120 | view.show(); |
|
120 | view.show(); | |
121 | QTest::qWaitForWindowShown(&view); |
|
121 | QTest::qWaitForWindowShown(&view); | |
122 |
|
122 | |||
123 | //==================================================================================== |
|
123 | //==================================================================================== | |
124 | // barset 1, category test1 |
|
124 | // barset 1, category test1 | |
125 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(95,143)); |
|
125 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(95,143)); | |
126 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
126 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
127 |
|
127 | |||
128 | QCOMPARE(seriesSpy.count(), 1); |
|
128 | QCOMPARE(seriesSpy.count(), 1); | |
129 |
|
129 | |||
130 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
130 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
131 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
131 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
132 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
132 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
133 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); |
|
133 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); | |
134 |
|
134 | |||
135 | //==================================================================================== |
|
135 | //==================================================================================== | |
136 | // barset 1, category test2 |
|
136 | // barset 1, category test2 | |
137 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(187,143)); |
|
137 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(187,143)); | |
138 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
138 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
139 |
|
139 | |||
140 | QCOMPARE(seriesSpy.count(), 1); |
|
140 | QCOMPARE(seriesSpy.count(), 1); | |
141 |
|
141 | |||
142 | seriesSpyArg = seriesSpy.takeFirst(); |
|
142 | seriesSpyArg = seriesSpy.takeFirst(); | |
143 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
143 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
144 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
144 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
145 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); |
|
145 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); | |
146 |
|
146 | |||
147 | //==================================================================================== |
|
147 | //==================================================================================== | |
148 | // barset 1, category test3 |
|
148 | // barset 1, category test3 | |
149 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(280,143)); |
|
149 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(280,143)); | |
150 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
150 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
151 |
|
151 | |||
152 | QCOMPARE(seriesSpy.count(), 1); |
|
152 | QCOMPARE(seriesSpy.count(), 1); | |
153 |
|
153 | |||
154 | seriesSpyArg = seriesSpy.takeFirst(); |
|
154 | seriesSpyArg = seriesSpy.takeFirst(); | |
155 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
155 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
156 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
156 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
157 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); |
|
157 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); | |
158 |
|
158 | |||
159 | //==================================================================================== |
|
159 | //==================================================================================== | |
160 | // barset 2, category test1 |
|
160 | // barset 2, category test1 | |
161 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(118,143)); |
|
161 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(118,143)); | |
162 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
162 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
163 |
|
163 | |||
164 | QCOMPARE(seriesSpy.count(), 1); |
|
164 | QCOMPARE(seriesSpy.count(), 1); | |
165 |
|
165 | |||
166 | seriesSpyArg = seriesSpy.takeFirst(); |
|
166 | seriesSpyArg = seriesSpy.takeFirst(); | |
167 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
167 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
168 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
168 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
169 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); |
|
169 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); | |
170 |
|
170 | |||
171 | //==================================================================================== |
|
171 | //==================================================================================== | |
172 | // barset 2, category test2 |
|
172 | // barset 2, category test2 | |
173 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(210,143)); |
|
173 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(210,143)); | |
174 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
174 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
175 |
|
175 | |||
176 | QCOMPARE(seriesSpy.count(), 1); |
|
176 | QCOMPARE(seriesSpy.count(), 1); | |
177 |
|
177 | |||
178 | seriesSpyArg = seriesSpy.takeFirst(); |
|
178 | seriesSpyArg = seriesSpy.takeFirst(); | |
179 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
179 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
180 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
180 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
181 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); |
|
181 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); | |
182 |
|
182 | |||
183 | //==================================================================================== |
|
183 | //==================================================================================== | |
184 | // barset 2, category test3 |
|
184 | // barset 2, category test3 | |
185 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(303,143)); |
|
185 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(303,143)); | |
186 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
186 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
187 |
|
187 | |||
188 | QCOMPARE(seriesSpy.count(), 1); |
|
188 | QCOMPARE(seriesSpy.count(), 1); | |
189 |
|
189 | |||
190 | seriesSpyArg = seriesSpy.takeFirst(); |
|
190 | seriesSpyArg = seriesSpy.takeFirst(); | |
191 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
191 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
192 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
192 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
193 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); |
|
193 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | void tst_QGroupedBarSeries::mousehovered_data() |
|
196 | void tst_QGroupedBarSeries::mousehovered_data() | |
197 | { |
|
197 | { | |
198 |
|
198 | |||
199 | } |
|
199 | } | |
200 |
|
200 | |||
201 | void tst_QGroupedBarSeries::mousehovered() |
|
201 | void tst_QGroupedBarSeries::mousehovered() | |
202 | { |
|
202 | { | |
203 |
Q |
|
203 | QBarSeries* series = new QBarSeries(); | |
204 |
|
204 | |||
205 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
205 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
206 | *set1 << 10 << 10 << 10; |
|
206 | *set1 << 10 << 10 << 10; | |
207 | series->append(set1); |
|
207 | series->append(set1); | |
208 |
|
208 | |||
209 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
209 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
210 | *set2 << 10 << 10 << 10; |
|
210 | *set2 << 10 << 10 << 10; | |
211 | series->append(set2); |
|
211 | series->append(set2); | |
212 |
|
212 | |||
213 | QSignalSpy seriesSpy(series,SIGNAL(hovered(bool, QBarSet*))); |
|
213 | QSignalSpy seriesSpy(series,SIGNAL(hovered(bool, QBarSet*))); | |
214 |
|
214 | |||
215 | QChartView view(new QChart()); |
|
215 | QChartView view(new QChart()); | |
216 | view.resize(400,300); |
|
216 | view.resize(400,300); | |
217 | view.chart()->addSeries(series); |
|
217 | view.chart()->addSeries(series); | |
218 | view.show(); |
|
218 | view.show(); | |
219 | QTest::qWaitForWindowShown(&view); |
|
219 | QTest::qWaitForWindowShown(&view); | |
220 |
|
220 | |||
221 | //this is hack since view does not get events otherwise |
|
221 | //this is hack since view does not get events otherwise | |
222 | view.setMouseTracking(true); |
|
222 | view.setMouseTracking(true); | |
223 |
|
223 | |||
224 | //======================================================================= |
|
224 | //======================================================================= | |
225 | // move mouse to left border |
|
225 | // move mouse to left border | |
226 | qDebug() << "move mouse to left border"; |
|
226 | qDebug() << "move mouse to left border"; | |
227 | QTest::mouseMove(view.viewport(), QPoint(0, 143)); |
|
227 | QTest::mouseMove(view.viewport(), QPoint(0, 143)); | |
228 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); |
|
228 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); | |
229 | TRY_COMPARE(seriesSpy.count(), 0); |
|
229 | TRY_COMPARE(seriesSpy.count(), 0); | |
230 |
|
230 | |||
231 | //======================================================================= |
|
231 | //======================================================================= | |
232 | // move mouse on top of set1 |
|
232 | // move mouse on top of set1 | |
233 | qDebug() << "move mouse on top of set1"; |
|
233 | qDebug() << "move mouse on top of set1"; | |
234 | QTest::mouseMove(view.viewport(), QPoint(95,143)); |
|
234 | QTest::mouseMove(view.viewport(), QPoint(95,143)); | |
235 | TRY_COMPARE(seriesSpy.count(), 1); |
|
235 | TRY_COMPARE(seriesSpy.count(), 1); | |
236 |
|
236 | |||
237 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
237 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
238 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
238 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
239 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
239 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | |
240 | QVERIFY(seriesSpyArg.at(0).toBool() == true); |
|
240 | QVERIFY(seriesSpyArg.at(0).toBool() == true); | |
241 |
|
241 | |||
242 | //======================================================================= |
|
242 | //======================================================================= | |
243 | // move mouse from top of set1 to top of set2 |
|
243 | // move mouse from top of set1 to top of set2 | |
244 | qDebug() << "move mouse from top of set1 to top of set2"; |
|
244 | qDebug() << "move mouse from top of set1 to top of set2"; | |
245 | QTest::mouseMove(view.viewport(), QPoint(118,143)); |
|
245 | QTest::mouseMove(view.viewport(), QPoint(118,143)); | |
246 | TRY_COMPARE(seriesSpy.count(), 2); |
|
246 | TRY_COMPARE(seriesSpy.count(), 2); | |
247 |
|
247 | |||
248 | // should leave set1 |
|
248 | // should leave set1 | |
249 | seriesSpyArg = seriesSpy.takeFirst(); |
|
249 | seriesSpyArg = seriesSpy.takeFirst(); | |
250 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
250 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
251 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
251 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | |
252 | QVERIFY(seriesSpyArg.at(0).toBool() == false); |
|
252 | QVERIFY(seriesSpyArg.at(0).toBool() == false); | |
253 |
|
253 | |||
254 | // should enter set2 |
|
254 | // should enter set2 | |
255 | seriesSpyArg = seriesSpy.takeFirst(); |
|
255 | seriesSpyArg = seriesSpy.takeFirst(); | |
256 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
256 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
257 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
257 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | |
258 | QVERIFY(seriesSpyArg.at(0).toBool() == true); |
|
258 | QVERIFY(seriesSpyArg.at(0).toBool() == true); | |
259 |
|
259 | |||
260 | //======================================================================= |
|
260 | //======================================================================= | |
261 | // move mouse from top of set2 to background |
|
261 | // move mouse from top of set2 to background | |
262 | qDebug() << "move mouse from top of set2 to background"; |
|
262 | qDebug() << "move mouse from top of set2 to background"; | |
263 |
|
263 | |||
264 | QTest::mouseMove(view.viewport(), QPoint(118,0)); |
|
264 | QTest::mouseMove(view.viewport(), QPoint(118,0)); | |
265 | TRY_COMPARE(seriesSpy.count(), 1); |
|
265 | TRY_COMPARE(seriesSpy.count(), 1); | |
266 |
|
266 | |||
267 | // should leave set2 |
|
267 | // should leave set2 | |
268 | seriesSpyArg = seriesSpy.takeFirst(); |
|
268 | seriesSpyArg = seriesSpy.takeFirst(); | |
269 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
269 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
270 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
270 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | |
271 | QVERIFY(seriesSpyArg.at(0).toBool() == false); |
|
271 | QVERIFY(seriesSpyArg.at(0).toBool() == false); | |
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 | QTEST_MAIN(tst_QGroupedBarSeries) |
|
274 | QTEST_MAIN(tst_QGroupedBarSeries) | |
275 |
|
275 | |||
276 | #include "tst_qgroupedbarseries.moc" |
|
276 | #include "tst_qgroupedbarseries.moc" | |
277 |
|
277 |
@@ -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 "dataseriedialog.h" |
|
21 | #include "dataseriedialog.h" | |
22 | #include <QDialogButtonBox> |
|
22 | #include <QDialogButtonBox> | |
23 | #include <QGridLayout> |
|
23 | #include <QGridLayout> | |
24 | #include <QCheckBox> |
|
24 | #include <QCheckBox> | |
25 | #include <QPushButton> |
|
25 | #include <QPushButton> | |
26 | #include <QGroupBox> |
|
26 | #include <QGroupBox> | |
27 | #include <QRadioButton> |
|
27 | #include <QRadioButton> | |
28 | #include <QLabel> |
|
28 | #include <QLabel> | |
29 | #include <QDebug> |
|
29 | #include <QDebug> | |
30 |
|
30 | |||
31 | DataSerieDialog::DataSerieDialog(QWidget *parent) : |
|
31 | DataSerieDialog::DataSerieDialog(QWidget *parent) : | |
32 | QDialog(parent) |
|
32 | QDialog(parent) | |
33 | { |
|
33 | { | |
34 | QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal); |
|
34 | QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal); | |
35 | QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok); |
|
35 | QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok); | |
36 | connect(b, SIGNAL(clicked()), this, SLOT(accept())); |
|
36 | connect(b, SIGNAL(clicked()), this, SLOT(accept())); | |
37 | b = addSeriesBox->addButton(QDialogButtonBox::Cancel); |
|
37 | b = addSeriesBox->addButton(QDialogButtonBox::Cancel); | |
38 | connect(b, SIGNAL(clicked()), this, SLOT(reject())); |
|
38 | connect(b, SIGNAL(clicked()), this, SLOT(reject())); | |
39 |
|
39 | |||
40 | QGridLayout *grid = new QGridLayout(); |
|
40 | QGridLayout *grid = new QGridLayout(); | |
41 |
|
41 | |||
42 | m_seriesTypeSelector = seriesTypeSelector(); |
|
42 | m_seriesTypeSelector = seriesTypeSelector(); | |
43 | m_columnCountSelector = columnCountSelector(); |
|
43 | m_columnCountSelector = columnCountSelector(); | |
44 | m_rowCountSelector = rowCountSelector(); |
|
44 | m_rowCountSelector = rowCountSelector(); | |
45 | m_dataCharacteristicsSelector = dataCharacteristicsSelector(); |
|
45 | m_dataCharacteristicsSelector = dataCharacteristicsSelector(); | |
46 |
|
46 | |||
47 | grid->addWidget(m_seriesTypeSelector, 0, 0); |
|
47 | grid->addWidget(m_seriesTypeSelector, 0, 0); | |
48 | grid->addWidget(m_columnCountSelector, 0, 1); |
|
48 | grid->addWidget(m_columnCountSelector, 0, 1); | |
49 | grid->addWidget(m_rowCountSelector, 1, 1); |
|
49 | grid->addWidget(m_rowCountSelector, 1, 1); | |
50 | grid->addWidget(m_dataCharacteristicsSelector, 1, 0); |
|
50 | grid->addWidget(m_dataCharacteristicsSelector, 1, 0); | |
51 | m_labelsSelector = new QCheckBox("Labels defined"); |
|
51 | m_labelsSelector = new QCheckBox("Labels defined"); | |
52 | m_labelsSelector->setChecked(true); |
|
52 | m_labelsSelector->setChecked(true); | |
53 | grid->addWidget(m_labelsSelector, 2, 0); |
|
53 | grid->addWidget(m_labelsSelector, 2, 0); | |
54 | grid->addWidget(addSeriesBox, 3, 1); |
|
54 | grid->addWidget(addSeriesBox, 3, 1); | |
55 |
|
55 | |||
56 | setLayout(grid); |
|
56 | setLayout(grid); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | QGroupBox *DataSerieDialog::seriesTypeSelector() |
|
59 | QGroupBox *DataSerieDialog::seriesTypeSelector() | |
60 | { |
|
60 | { | |
61 | QVBoxLayout *layout = new QVBoxLayout(); |
|
61 | QVBoxLayout *layout = new QVBoxLayout(); | |
62 |
|
62 | |||
63 | QRadioButton *line = new QRadioButton("Line"); |
|
63 | QRadioButton *line = new QRadioButton("Line"); | |
64 | line->setChecked(true); |
|
64 | line->setChecked(true); | |
65 | layout->addWidget(line); |
|
65 | layout->addWidget(line); | |
66 | layout->addWidget(new QRadioButton("Area")); |
|
66 | layout->addWidget(new QRadioButton("Area")); | |
67 | layout->addWidget(new QRadioButton("Pie")); |
|
67 | layout->addWidget(new QRadioButton("Pie")); | |
68 |
layout->addWidget(new QRadioButton(" |
|
68 | layout->addWidget(new QRadioButton("Bar")); | |
69 | layout->addWidget(new QRadioButton("Stacked bar")); |
|
69 | layout->addWidget(new QRadioButton("Stacked bar")); | |
70 | layout->addWidget(new QRadioButton("Percent bar")); |
|
70 | layout->addWidget(new QRadioButton("Percent bar")); | |
71 | layout->addWidget(new QRadioButton("Scatter")); |
|
71 | layout->addWidget(new QRadioButton("Scatter")); | |
72 | layout->addWidget(new QRadioButton("Spline")); |
|
72 | layout->addWidget(new QRadioButton("Spline")); | |
73 |
|
73 | |||
74 | QGroupBox *groupBox = new QGroupBox("Series type"); |
|
74 | QGroupBox *groupBox = new QGroupBox("Series type"); | |
75 | groupBox->setLayout(layout); |
|
75 | groupBox->setLayout(layout); | |
76 | selectRadio(groupBox, 0); |
|
76 | selectRadio(groupBox, 0); | |
77 |
|
77 | |||
78 | return groupBox; |
|
78 | return groupBox; | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | QGroupBox *DataSerieDialog::columnCountSelector() |
|
81 | QGroupBox *DataSerieDialog::columnCountSelector() | |
82 | { |
|
82 | { | |
83 | QVBoxLayout *layout = new QVBoxLayout(); |
|
83 | QVBoxLayout *layout = new QVBoxLayout(); | |
84 |
|
84 | |||
85 | QRadioButton *radio = new QRadioButton("1"); |
|
85 | QRadioButton *radio = new QRadioButton("1"); | |
86 | radio->setChecked(true); |
|
86 | radio->setChecked(true); | |
87 | layout->addWidget(radio); |
|
87 | layout->addWidget(radio); | |
88 | layout->addWidget(new QRadioButton("2")); |
|
88 | layout->addWidget(new QRadioButton("2")); | |
89 | layout->addWidget(new QRadioButton("3")); |
|
89 | layout->addWidget(new QRadioButton("3")); | |
90 | layout->addWidget(new QRadioButton("4")); |
|
90 | layout->addWidget(new QRadioButton("4")); | |
91 | layout->addWidget(new QRadioButton("5")); |
|
91 | layout->addWidget(new QRadioButton("5")); | |
92 | layout->addWidget(new QRadioButton("8")); |
|
92 | layout->addWidget(new QRadioButton("8")); | |
93 | layout->addWidget(new QRadioButton("10")); |
|
93 | layout->addWidget(new QRadioButton("10")); | |
94 | layout->addWidget(new QRadioButton("100")); |
|
94 | layout->addWidget(new QRadioButton("100")); | |
95 |
|
95 | |||
96 | QGroupBox *groupBox = new QGroupBox("Column count"); |
|
96 | QGroupBox *groupBox = new QGroupBox("Column count"); | |
97 | groupBox->setLayout(layout); |
|
97 | groupBox->setLayout(layout); | |
98 | selectRadio(groupBox, 0); |
|
98 | selectRadio(groupBox, 0); | |
99 |
|
99 | |||
100 | return groupBox; |
|
100 | return groupBox; | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | QGroupBox *DataSerieDialog::rowCountSelector() |
|
103 | QGroupBox *DataSerieDialog::rowCountSelector() | |
104 | { |
|
104 | { | |
105 | QVBoxLayout *layout = new QVBoxLayout(); |
|
105 | QVBoxLayout *layout = new QVBoxLayout(); | |
106 |
|
106 | |||
107 | layout->addWidget(new QRadioButton("1")); |
|
107 | layout->addWidget(new QRadioButton("1")); | |
108 | QRadioButton *radio = new QRadioButton("10"); |
|
108 | QRadioButton *radio = new QRadioButton("10"); | |
109 | radio->setChecked(true); |
|
109 | radio->setChecked(true); | |
110 | layout->addWidget(radio); |
|
110 | layout->addWidget(radio); | |
111 | layout->addWidget(new QRadioButton("50")); |
|
111 | layout->addWidget(new QRadioButton("50")); | |
112 | layout->addWidget(new QRadioButton("100")); |
|
112 | layout->addWidget(new QRadioButton("100")); | |
113 | layout->addWidget(new QRadioButton("1000")); |
|
113 | layout->addWidget(new QRadioButton("1000")); | |
114 | layout->addWidget(new QRadioButton("10000")); |
|
114 | layout->addWidget(new QRadioButton("10000")); | |
115 | layout->addWidget(new QRadioButton("100000")); |
|
115 | layout->addWidget(new QRadioButton("100000")); | |
116 | layout->addWidget(new QRadioButton("1000000")); |
|
116 | layout->addWidget(new QRadioButton("1000000")); | |
117 |
|
117 | |||
118 | QGroupBox *groupBox = new QGroupBox("Row count"); |
|
118 | QGroupBox *groupBox = new QGroupBox("Row count"); | |
119 | groupBox->setLayout(layout); |
|
119 | groupBox->setLayout(layout); | |
120 | selectRadio(groupBox, 0); |
|
120 | selectRadio(groupBox, 0); | |
121 |
|
121 | |||
122 | return groupBox; |
|
122 | return groupBox; | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | QGroupBox *DataSerieDialog::dataCharacteristicsSelector() |
|
125 | QGroupBox *DataSerieDialog::dataCharacteristicsSelector() | |
126 | { |
|
126 | { | |
127 | QVBoxLayout *layout = new QVBoxLayout(); |
|
127 | QVBoxLayout *layout = new QVBoxLayout(); | |
128 |
|
128 | |||
129 | layout->addWidget(new QRadioButton("Linear")); |
|
129 | layout->addWidget(new QRadioButton("Linear")); | |
130 | layout->addWidget(new QRadioButton("Constant")); |
|
130 | layout->addWidget(new QRadioButton("Constant")); | |
131 | layout->addWidget(new QRadioButton("Random")); |
|
131 | layout->addWidget(new QRadioButton("Random")); | |
132 | layout->addWidget(new QRadioButton("Sin")); |
|
132 | layout->addWidget(new QRadioButton("Sin")); | |
133 | layout->addWidget(new QRadioButton("Sin + random")); |
|
133 | layout->addWidget(new QRadioButton("Sin + random")); | |
134 |
|
134 | |||
135 | QGroupBox *groupBox = new QGroupBox("Data Characteristics"); |
|
135 | QGroupBox *groupBox = new QGroupBox("Data Characteristics"); | |
136 | groupBox->setLayout(layout); |
|
136 | groupBox->setLayout(layout); | |
137 | selectRadio(groupBox, 0); |
|
137 | selectRadio(groupBox, 0); | |
138 |
|
138 | |||
139 | return groupBox; |
|
139 | return groupBox; | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | void DataSerieDialog::accept() |
|
142 | void DataSerieDialog::accept() | |
143 | { |
|
143 | { | |
144 | accepted(radioSelection(m_seriesTypeSelector), |
|
144 | accepted(radioSelection(m_seriesTypeSelector), | |
145 | radioSelection(m_columnCountSelector).toInt(), |
|
145 | radioSelection(m_columnCountSelector).toInt(), | |
146 | radioSelection(m_rowCountSelector).toInt(), |
|
146 | radioSelection(m_rowCountSelector).toInt(), | |
147 | radioSelection(m_dataCharacteristicsSelector), |
|
147 | radioSelection(m_dataCharacteristicsSelector), | |
148 | m_labelsSelector->isChecked()); |
|
148 | m_labelsSelector->isChecked()); | |
149 | QDialog::accept(); |
|
149 | QDialog::accept(); | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | void DataSerieDialog::selectRadio(QGroupBox *groupBox, int defaultSelection) |
|
152 | void DataSerieDialog::selectRadio(QGroupBox *groupBox, int defaultSelection) | |
153 | { |
|
153 | { | |
154 | QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout()); |
|
154 | QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout()); | |
155 | Q_ASSERT(layout); |
|
155 | Q_ASSERT(layout); | |
156 | Q_ASSERT(layout->count()); |
|
156 | Q_ASSERT(layout->count()); | |
157 |
|
157 | |||
158 | QLayoutItem *item = 0; |
|
158 | QLayoutItem *item = 0; | |
159 | if (defaultSelection == -1) { |
|
159 | if (defaultSelection == -1) { | |
160 | item = layout->itemAt(0); |
|
160 | item = layout->itemAt(0); | |
161 | } else if (layout->count() > defaultSelection) { |
|
161 | } else if (layout->count() > defaultSelection) { | |
162 | item = layout->itemAt(defaultSelection); |
|
162 | item = layout->itemAt(defaultSelection); | |
163 | } |
|
163 | } | |
164 | Q_ASSERT(item); |
|
164 | Q_ASSERT(item); | |
165 | QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget()); |
|
165 | QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget()); | |
166 | Q_ASSERT(radio); |
|
166 | Q_ASSERT(radio); | |
167 | radio->setChecked(true); |
|
167 | radio->setChecked(true); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | QString DataSerieDialog::radioSelection(QGroupBox *groupBox) |
|
170 | QString DataSerieDialog::radioSelection(QGroupBox *groupBox) | |
171 | { |
|
171 | { | |
172 | QString selection; |
|
172 | QString selection; | |
173 | QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout()); |
|
173 | QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout()); | |
174 | Q_ASSERT(layout); |
|
174 | Q_ASSERT(layout); | |
175 |
|
175 | |||
176 | for (int i(0); i < layout->count(); i++) { |
|
176 | for (int i(0); i < layout->count(); i++) { | |
177 | QLayoutItem *item = layout->itemAt(i); |
|
177 | QLayoutItem *item = layout->itemAt(i); | |
178 | Q_ASSERT(item); |
|
178 | Q_ASSERT(item); | |
179 | QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget()); |
|
179 | QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget()); | |
180 | Q_ASSERT(radio); |
|
180 | Q_ASSERT(radio); | |
181 | if (radio->isChecked()) { |
|
181 | if (radio->isChecked()) { | |
182 | selection = radio->text(); |
|
182 | selection = radio->text(); | |
183 | break; |
|
183 | break; | |
184 | } |
|
184 | } | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | qDebug() << "radioSelection: " << selection; |
|
187 | qDebug() << "radioSelection: " << selection; | |
188 | return selection; |
|
188 | return selection; | |
189 | } |
|
189 | } |
@@ -1,357 +1,357 | |||||
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 "mainwidget.h" |
|
21 | #include "mainwidget.h" | |
22 | #include "dataseriedialog.h" |
|
22 | #include "dataseriedialog.h" | |
23 | #include "qchartview.h" |
|
23 | #include "qchartview.h" | |
24 | #include "qpieseries.h" |
|
24 | #include "qpieseries.h" | |
25 | #include "qscatterseries.h" |
|
25 | #include "qscatterseries.h" | |
26 | #include "qlineseries.h" |
|
26 | #include "qlineseries.h" | |
27 | #include <qareaseries.h> |
|
27 | #include <qareaseries.h> | |
28 | #include <qsplineseries.h> |
|
28 | #include <qsplineseries.h> | |
29 | #include <qbarset.h> |
|
29 | #include <qbarset.h> | |
30 |
#include <q |
|
30 | #include <qbarseries.h> | |
31 | #include <qstackedbarseries.h> |
|
31 | #include <qstackedbarseries.h> | |
32 | #include <qpercentbarseries.h> |
|
32 | #include <qpercentbarseries.h> | |
33 | #include <QPushButton> |
|
33 | #include <QPushButton> | |
34 | #include <QComboBox> |
|
34 | #include <QComboBox> | |
35 | #include <QSpinBox> |
|
35 | #include <QSpinBox> | |
36 | #include <QCheckBox> |
|
36 | #include <QCheckBox> | |
37 | #include <QGridLayout> |
|
37 | #include <QGridLayout> | |
38 | #include <QHBoxLayout> |
|
38 | #include <QHBoxLayout> | |
39 | #include <QLabel> |
|
39 | #include <QLabel> | |
40 | #include <QSpacerItem> |
|
40 | #include <QSpacerItem> | |
41 | #include <QMessageBox> |
|
41 | #include <QMessageBox> | |
42 | #include <cmath> |
|
42 | #include <cmath> | |
43 | #include <QDebug> |
|
43 | #include <QDebug> | |
44 | #include <QStandardItemModel> |
|
44 | #include <QStandardItemModel> | |
45 | #include <QCategoriesAxis> |
|
45 | #include <QCategoriesAxis> | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
48 | QTCOMMERCIALCHART_USE_NAMESPACE | |
49 |
|
49 | |||
50 | MainWidget::MainWidget(QWidget *parent) : |
|
50 | MainWidget::MainWidget(QWidget *parent) : | |
51 | QWidget(parent), |
|
51 | QWidget(parent), | |
52 | m_addSerieDialog(0), |
|
52 | m_addSerieDialog(0), | |
53 | m_chart(0) |
|
53 | m_chart(0) | |
54 | { |
|
54 | { | |
55 | m_chart = new QChart(); |
|
55 | m_chart = new QChart(); | |
56 |
|
56 | |||
57 | // Grid layout for the controls for configuring the chart widget |
|
57 | // Grid layout for the controls for configuring the chart widget | |
58 | QGridLayout *grid = new QGridLayout(); |
|
58 | QGridLayout *grid = new QGridLayout(); | |
59 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
59 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
60 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
60 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
61 | grid->addWidget(addSeriesButton, 0, 1); |
|
61 | grid->addWidget(addSeriesButton, 0, 1); | |
62 | initBackroundCombo(grid); |
|
62 | initBackroundCombo(grid); | |
63 | initScaleControls(grid); |
|
63 | initScaleControls(grid); | |
64 | initThemeCombo(grid); |
|
64 | initThemeCombo(grid); | |
65 | initCheckboxes(grid); |
|
65 | initCheckboxes(grid); | |
66 |
|
66 | |||
67 | // add row with empty label to make all the other rows static |
|
67 | // add row with empty label to make all the other rows static | |
68 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
68 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
69 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
69 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
70 |
|
70 | |||
71 | // Create chart view with the chart |
|
71 | // Create chart view with the chart | |
72 | m_chartView = new QChartView(m_chart, this); |
|
72 | m_chartView = new QChartView(m_chart, this); | |
73 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); |
|
73 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); | |
74 |
|
74 | |||
75 | // Another grid layout as a main layout |
|
75 | // Another grid layout as a main layout | |
76 | QGridLayout *mainLayout = new QGridLayout(); |
|
76 | QGridLayout *mainLayout = new QGridLayout(); | |
77 | mainLayout->addLayout(grid, 0, 0); |
|
77 | mainLayout->addLayout(grid, 0, 0); | |
78 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
78 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |
79 | setLayout(mainLayout); |
|
79 | setLayout(mainLayout); | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | // Combo box for selecting the chart's background |
|
82 | // Combo box for selecting the chart's background | |
83 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
83 | void MainWidget::initBackroundCombo(QGridLayout *grid) | |
84 | { |
|
84 | { | |
85 | QComboBox *backgroundCombo = new QComboBox(this); |
|
85 | QComboBox *backgroundCombo = new QComboBox(this); | |
86 | backgroundCombo->addItem("Color"); |
|
86 | backgroundCombo->addItem("Color"); | |
87 | backgroundCombo->addItem("Gradient"); |
|
87 | backgroundCombo->addItem("Gradient"); | |
88 | backgroundCombo->addItem("Image"); |
|
88 | backgroundCombo->addItem("Image"); | |
89 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
89 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
90 | this, SLOT(backgroundChanged(int))); |
|
90 | this, SLOT(backgroundChanged(int))); | |
91 |
|
91 | |||
92 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
92 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); | |
93 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
93 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | // Scale related controls (auto-scale vs. manual min-max values) |
|
96 | // Scale related controls (auto-scale vs. manual min-max values) | |
97 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
97 | void MainWidget::initScaleControls(QGridLayout *grid) | |
98 | { |
|
98 | { | |
99 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
99 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
100 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
100 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
101 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
101 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
102 | m_xMinSpin = new QSpinBox(); |
|
102 | m_xMinSpin = new QSpinBox(); | |
103 | m_xMinSpin->setMinimum(INT_MIN); |
|
103 | m_xMinSpin->setMinimum(INT_MIN); | |
104 | m_xMinSpin->setMaximum(INT_MAX); |
|
104 | m_xMinSpin->setMaximum(INT_MAX); | |
105 | m_xMinSpin->setValue(0); |
|
105 | m_xMinSpin->setValue(0); | |
106 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
106 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
107 | m_xMaxSpin = new QSpinBox(); |
|
107 | m_xMaxSpin = new QSpinBox(); | |
108 | m_xMaxSpin->setMinimum(INT_MIN); |
|
108 | m_xMaxSpin->setMinimum(INT_MIN); | |
109 | m_xMaxSpin->setMaximum(INT_MAX); |
|
109 | m_xMaxSpin->setMaximum(INT_MAX); | |
110 | m_xMaxSpin->setValue(10); |
|
110 | m_xMaxSpin->setValue(10); | |
111 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
111 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
112 | m_yMinSpin = new QSpinBox(); |
|
112 | m_yMinSpin = new QSpinBox(); | |
113 | m_yMinSpin->setMinimum(INT_MIN); |
|
113 | m_yMinSpin->setMinimum(INT_MIN); | |
114 | m_yMinSpin->setMaximum(INT_MAX); |
|
114 | m_yMinSpin->setMaximum(INT_MAX); | |
115 | m_yMinSpin->setValue(0); |
|
115 | m_yMinSpin->setValue(0); | |
116 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
116 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
117 | m_yMaxSpin = new QSpinBox(); |
|
117 | m_yMaxSpin = new QSpinBox(); | |
118 | m_yMaxSpin->setMinimum(INT_MIN); |
|
118 | m_yMaxSpin->setMinimum(INT_MIN); | |
119 | m_yMaxSpin->setMaximum(INT_MAX); |
|
119 | m_yMaxSpin->setMaximum(INT_MAX); | |
120 | m_yMaxSpin->setValue(10); |
|
120 | m_yMaxSpin->setValue(10); | |
121 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
121 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
122 |
|
122 | |||
123 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
123 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); | |
124 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
124 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); | |
125 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
125 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); | |
126 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
126 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); | |
127 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
127 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); | |
128 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
128 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); | |
129 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
129 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); | |
130 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
130 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); | |
131 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
131 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); | |
132 |
|
132 | |||
133 | m_autoScaleCheck->setChecked(true); |
|
133 | m_autoScaleCheck->setChecked(true); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | // Combo box for selecting theme |
|
136 | // Combo box for selecting theme | |
137 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
137 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
138 | { |
|
138 | { | |
139 | QComboBox *chartTheme = new QComboBox(); |
|
139 | QComboBox *chartTheme = new QComboBox(); | |
140 | chartTheme->addItem("Default"); |
|
140 | chartTheme->addItem("Default"); | |
141 | chartTheme->addItem("Light"); |
|
141 | chartTheme->addItem("Light"); | |
142 | chartTheme->addItem("Blue Cerulean"); |
|
142 | chartTheme->addItem("Blue Cerulean"); | |
143 | chartTheme->addItem("Dark"); |
|
143 | chartTheme->addItem("Dark"); | |
144 | chartTheme->addItem("Brown Sand"); |
|
144 | chartTheme->addItem("Brown Sand"); | |
145 | chartTheme->addItem("Blue NCS"); |
|
145 | chartTheme->addItem("Blue NCS"); | |
146 | chartTheme->addItem("High Contrast"); |
|
146 | chartTheme->addItem("High Contrast"); | |
147 | chartTheme->addItem("Blue Icy"); |
|
147 | chartTheme->addItem("Blue Icy"); | |
148 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
148 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
149 | this, SLOT(changeChartTheme(int))); |
|
149 | this, SLOT(changeChartTheme(int))); | |
150 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
150 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); | |
151 | grid->addWidget(chartTheme, 8, 1); |
|
151 | grid->addWidget(chartTheme, 8, 1); | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | // Different check boxes for customizing chart |
|
154 | // Different check boxes for customizing chart | |
155 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
155 | void MainWidget::initCheckboxes(QGridLayout *grid) | |
156 | { |
|
156 | { | |
157 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off |
|
157 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off | |
158 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
158 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); | |
159 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); |
|
159 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); | |
160 | zoomCheckBox->setChecked(true); |
|
160 | zoomCheckBox->setChecked(true); | |
161 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
161 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); | |
162 |
|
162 | |||
163 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); |
|
163 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); | |
164 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); |
|
164 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); | |
165 | aliasCheckBox->setChecked(false); |
|
165 | aliasCheckBox->setChecked(false); | |
166 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); |
|
166 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | void MainWidget::antiAliasToggled(bool enabled) |
|
169 | void MainWidget::antiAliasToggled(bool enabled) | |
170 | { |
|
170 | { | |
171 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); |
|
171 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | void MainWidget::addSeries() |
|
174 | void MainWidget::addSeries() | |
175 | { |
|
175 | { | |
176 | if (!m_addSerieDialog) { |
|
176 | if (!m_addSerieDialog) { | |
177 | m_addSerieDialog = new DataSerieDialog(this); |
|
177 | m_addSerieDialog = new DataSerieDialog(this); | |
178 | connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), |
|
178 | connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), | |
179 | this, SLOT(addSeries(QString,int,int,QString,bool))); |
|
179 | this, SLOT(addSeries(QString,int,int,QString,bool))); | |
180 | } |
|
180 | } | |
181 | m_addSerieDialog->exec(); |
|
181 | m_addSerieDialog->exec(); | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) |
|
184 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) | |
185 | { |
|
185 | { | |
186 | // TODO: dataCharacteristics |
|
186 | // TODO: dataCharacteristics | |
187 | QList<RealList> testData; |
|
187 | QList<RealList> testData; | |
188 | for (int j(0); j < columnCount; j++) { |
|
188 | for (int j(0); j < columnCount; j++) { | |
189 | QList <qreal> newColumn; |
|
189 | QList <qreal> newColumn; | |
190 | for (int i(0); i < rowCount; i++) { |
|
190 | for (int i(0); i < rowCount; i++) { | |
191 | if (dataCharacteristics == "Sin") { |
|
191 | if (dataCharacteristics == "Sin") { | |
192 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
192 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
193 | } else if (dataCharacteristics == "Sin + random") { |
|
193 | } else if (dataCharacteristics == "Sin + random") { | |
194 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
194 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
195 | } else if (dataCharacteristics == "Random") { |
|
195 | } else if (dataCharacteristics == "Random") { | |
196 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); |
|
196 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); | |
197 | } else if (dataCharacteristics == "Linear") { |
|
197 | } else if (dataCharacteristics == "Linear") { | |
198 | //newColumn.append(i * (j + 1.0)); |
|
198 | //newColumn.append(i * (j + 1.0)); | |
199 | // TODO: temporary hack to make pie work; prevent zero values: |
|
199 | // TODO: temporary hack to make pie work; prevent zero values: | |
200 | newColumn.append(i * (j + 1.0) + 0.1); |
|
200 | newColumn.append(i * (j + 1.0) + 0.1); | |
201 | } else { // "constant" |
|
201 | } else { // "constant" | |
202 | newColumn.append((j + 1.0)); |
|
202 | newColumn.append((j + 1.0)); | |
203 | } |
|
203 | } | |
204 | } |
|
204 | } | |
205 | testData.append(newColumn); |
|
205 | testData.append(newColumn); | |
206 | } |
|
206 | } | |
207 | return testData; |
|
207 | return testData; | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | QStringList MainWidget::generateLabels(int count) |
|
210 | QStringList MainWidget::generateLabels(int count) | |
211 | { |
|
211 | { | |
212 | QStringList result; |
|
212 | QStringList result; | |
213 | for (int i(0); i < count; i++) |
|
213 | for (int i(0); i < count; i++) | |
214 | result.append("label" + QString::number(i)); |
|
214 | result.append("label" + QString::number(i)); | |
215 | return result; |
|
215 | return result; | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) |
|
218 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) | |
219 | { |
|
219 | { | |
220 | qDebug() << "addSeries: " << seriesName |
|
220 | qDebug() << "addSeries: " << seriesName | |
221 | << " columnCount: " << columnCount |
|
221 | << " columnCount: " << columnCount | |
222 | << " rowCount: " << rowCount |
|
222 | << " rowCount: " << rowCount | |
223 | << " dataCharacteristics: " << dataCharacteristics |
|
223 | << " dataCharacteristics: " << dataCharacteristics | |
224 | << " labels enabled: " << labelsEnabled; |
|
224 | << " labels enabled: " << labelsEnabled; | |
225 | m_defaultSeriesName = seriesName; |
|
225 | m_defaultSeriesName = seriesName; | |
226 |
|
226 | |||
227 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); |
|
227 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); | |
228 |
|
228 | |||
229 | // Line series and scatter series use similar data |
|
229 | // Line series and scatter series use similar data | |
230 | if (seriesName == "Line") { |
|
230 | if (seriesName == "Line") { | |
231 | for (int j(0); j < data.count(); j ++) { |
|
231 | for (int j(0); j < data.count(); j ++) { | |
232 | QList<qreal> column = data.at(j); |
|
232 | QList<qreal> column = data.at(j); | |
233 | QLineSeries *series = new QLineSeries(); |
|
233 | QLineSeries *series = new QLineSeries(); | |
234 | series->setName("line" + QString::number(j)); |
|
234 | series->setName("line" + QString::number(j)); | |
235 | for (int i(0); i < column.count(); i++) |
|
235 | for (int i(0); i < column.count(); i++) | |
236 | series->append(i, column.at(i)); |
|
236 | series->append(i, column.at(i)); | |
237 | m_chart->addSeries(series); |
|
237 | m_chart->addSeries(series); | |
238 | } |
|
238 | } | |
239 | } else if (seriesName == "Area") { |
|
239 | } else if (seriesName == "Area") { | |
240 | // TODO: lower series for the area? |
|
240 | // TODO: lower series for the area? | |
241 | for (int j(0); j < data.count(); j ++) { |
|
241 | for (int j(0); j < data.count(); j ++) { | |
242 | QList<qreal> column = data.at(j); |
|
242 | QList<qreal> column = data.at(j); | |
243 | QLineSeries *lineSeries = new QLineSeries(); |
|
243 | QLineSeries *lineSeries = new QLineSeries(); | |
244 | for (int i(0); i < column.count(); i++) |
|
244 | for (int i(0); i < column.count(); i++) | |
245 | lineSeries->append(i, column.at(i)); |
|
245 | lineSeries->append(i, column.at(i)); | |
246 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); |
|
246 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); | |
247 | areaSeries->setName("area" + QString::number(j)); |
|
247 | areaSeries->setName("area" + QString::number(j)); | |
248 | m_chart->addSeries(areaSeries); |
|
248 | m_chart->addSeries(areaSeries); | |
249 | } |
|
249 | } | |
250 | } else if (seriesName == "Scatter") { |
|
250 | } else if (seriesName == "Scatter") { | |
251 | for (int j(0); j < data.count(); j++) { |
|
251 | for (int j(0); j < data.count(); j++) { | |
252 | QList<qreal> column = data.at(j); |
|
252 | QList<qreal> column = data.at(j); | |
253 | QScatterSeries *series = new QScatterSeries(); |
|
253 | QScatterSeries *series = new QScatterSeries(); | |
254 | series->setName("scatter" + QString::number(j)); |
|
254 | series->setName("scatter" + QString::number(j)); | |
255 | for (int i(0); i < column.count(); i++) |
|
255 | for (int i(0); i < column.count(); i++) | |
256 | series->append(i, column.at(i)); |
|
256 | series->append(i, column.at(i)); | |
257 | m_chart->addSeries(series); |
|
257 | m_chart->addSeries(series); | |
258 | } |
|
258 | } | |
259 | } else if (seriesName == "Pie") { |
|
259 | } else if (seriesName == "Pie") { | |
260 | QStringList labels = generateLabels(rowCount); |
|
260 | QStringList labels = generateLabels(rowCount); | |
261 | for (int j(0); j < data.count(); j++) { |
|
261 | for (int j(0); j < data.count(); j++) { | |
262 | QPieSeries *series = new QPieSeries(); |
|
262 | QPieSeries *series = new QPieSeries(); | |
263 | QList<qreal> column = data.at(j); |
|
263 | QList<qreal> column = data.at(j); | |
264 | for (int i(0); i < column.count(); i++) |
|
264 | for (int i(0); i < column.count(); i++) | |
265 | series->append(labels.at(i), column.at(i)); |
|
265 | series->append(labels.at(i), column.at(i)); | |
266 | m_chart->addSeries(series); |
|
266 | m_chart->addSeries(series); | |
267 | } |
|
267 | } | |
268 |
} else if (seriesName == " |
|
268 | } else if (seriesName == "Bar" | |
269 | || seriesName == "Stacked bar" |
|
269 | || seriesName == "Stacked bar" | |
270 | || seriesName == "Percent bar") { |
|
270 | || seriesName == "Percent bar") { | |
271 | QStringList category; |
|
271 | QStringList category; | |
272 | QStringList labels = generateLabels(rowCount); |
|
272 | QStringList labels = generateLabels(rowCount); | |
273 | foreach(QString label, labels) |
|
273 | foreach(QString label, labels) | |
274 | category << label; |
|
274 | category << label; | |
275 | QAbstractBarSeries* series = 0; |
|
275 | QAbstractBarSeries* series = 0; | |
276 |
if (seriesName == " |
|
276 | if (seriesName == "Bar") { | |
277 |
series = new Q |
|
277 | series = new QBarSeries(this); | |
278 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
278 | QCategoriesAxis* axis = new QCategoriesAxis(); | |
279 | axis->append(category); |
|
279 | axis->append(category); | |
280 | m_chart->setAxisX(axis,series); |
|
280 | m_chart->setAxisX(axis,series); | |
281 | } else if (seriesName == "Stacked bar") { |
|
281 | } else if (seriesName == "Stacked bar") { | |
282 | series = new QStackedBarSeries(this); |
|
282 | series = new QStackedBarSeries(this); | |
283 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
283 | QCategoriesAxis* axis = new QCategoriesAxis(); | |
284 | axis->append(category); |
|
284 | axis->append(category); | |
285 | m_chart->setAxisX(axis,series); |
|
285 | m_chart->setAxisX(axis,series); | |
286 | } else { |
|
286 | } else { | |
287 | series = new QPercentBarSeries(this); |
|
287 | series = new QPercentBarSeries(this); | |
288 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
288 | QCategoriesAxis* axis = new QCategoriesAxis(); | |
289 | axis->append(category); |
|
289 | axis->append(category); | |
290 | m_chart->setAxisX(axis,series); |
|
290 | m_chart->setAxisX(axis,series); | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | for (int j(0); j < data.count(); j++) { |
|
293 | for (int j(0); j < data.count(); j++) { | |
294 | QList<qreal> column = data.at(j); |
|
294 | QList<qreal> column = data.at(j); | |
295 | QBarSet *set = new QBarSet("set" + QString::number(j)); |
|
295 | QBarSet *set = new QBarSet("set" + QString::number(j)); | |
296 | for (int i(0); i < column.count(); i++) |
|
296 | for (int i(0); i < column.count(); i++) | |
297 | *set << column.at(i); |
|
297 | *set << column.at(i); | |
298 | series->append(set); |
|
298 | series->append(set); | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | m_chart->addSeries(series); |
|
301 | m_chart->addSeries(series); | |
302 | } else if (seriesName == "Spline") { |
|
302 | } else if (seriesName == "Spline") { | |
303 | for (int j(0); j < data.count(); j ++) { |
|
303 | for (int j(0); j < data.count(); j ++) { | |
304 | QList<qreal> column = data.at(j); |
|
304 | QList<qreal> column = data.at(j); | |
305 | QSplineSeries *series = new QSplineSeries(); |
|
305 | QSplineSeries *series = new QSplineSeries(); | |
306 | for (int i(0); i < column.count(); i++) |
|
306 | for (int i(0); i < column.count(); i++) | |
307 | series->append(i, column.at(i)); |
|
307 | series->append(i, column.at(i)); | |
308 | m_chart->addSeries(series); |
|
308 | m_chart->addSeries(series); | |
309 | } |
|
309 | } | |
310 | } |
|
310 | } | |
311 | m_chart->createDefaultAxes(); |
|
311 | m_chart->createDefaultAxes(); | |
312 | } |
|
312 | } | |
313 |
|
313 | |||
314 | void MainWidget::backgroundChanged(int itemIndex) |
|
314 | void MainWidget::backgroundChanged(int itemIndex) | |
315 | { |
|
315 | { | |
316 | qDebug() << "backgroundChanged: " << itemIndex; |
|
316 | qDebug() << "backgroundChanged: " << itemIndex; | |
317 | } |
|
317 | } | |
318 |
|
318 | |||
319 | void MainWidget::autoScaleChanged(int value) |
|
319 | void MainWidget::autoScaleChanged(int value) | |
320 | { |
|
320 | { | |
321 | if (value) { |
|
321 | if (value) { | |
322 | // TODO: enable auto scaling |
|
322 | // TODO: enable auto scaling | |
323 | } else { |
|
323 | } else { | |
324 | // TODO: set scaling manually (and disable auto scaling) |
|
324 | // TODO: set scaling manually (and disable auto scaling) | |
325 | } |
|
325 | } | |
326 |
|
326 | |||
327 | m_xMinSpin->setEnabled(!value); |
|
327 | m_xMinSpin->setEnabled(!value); | |
328 | m_xMaxSpin->setEnabled(!value); |
|
328 | m_xMaxSpin->setEnabled(!value); | |
329 | m_yMinSpin->setEnabled(!value); |
|
329 | m_yMinSpin->setEnabled(!value); | |
330 | m_yMaxSpin->setEnabled(!value); |
|
330 | m_yMaxSpin->setEnabled(!value); | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 | void MainWidget::xMinChanged(int value) |
|
333 | void MainWidget::xMinChanged(int value) | |
334 | { |
|
334 | { | |
335 | qDebug() << "xMinChanged: " << value; |
|
335 | qDebug() << "xMinChanged: " << value; | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 | void MainWidget::xMaxChanged(int value) |
|
338 | void MainWidget::xMaxChanged(int value) | |
339 | { |
|
339 | { | |
340 | qDebug() << "xMaxChanged: " << value; |
|
340 | qDebug() << "xMaxChanged: " << value; | |
341 | } |
|
341 | } | |
342 |
|
342 | |||
343 | void MainWidget::yMinChanged(int value) |
|
343 | void MainWidget::yMinChanged(int value) | |
344 | { |
|
344 | { | |
345 | qDebug() << "yMinChanged: " << value; |
|
345 | qDebug() << "yMinChanged: " << value; | |
346 | } |
|
346 | } | |
347 |
|
347 | |||
348 | void MainWidget::yMaxChanged(int value) |
|
348 | void MainWidget::yMaxChanged(int value) | |
349 | { |
|
349 | { | |
350 | qDebug() << "yMaxChanged: " << value; |
|
350 | qDebug() << "yMaxChanged: " << value; | |
351 | } |
|
351 | } | |
352 |
|
352 | |||
353 | void MainWidget::changeChartTheme(int themeIndex) |
|
353 | void MainWidget::changeChartTheme(int themeIndex) | |
354 | { |
|
354 | { | |
355 | qDebug() << "changeChartTheme: " << themeIndex; |
|
355 | qDebug() << "changeChartTheme: " << themeIndex; | |
356 | m_chart->setTheme((QChart::ChartTheme) themeIndex); |
|
356 | m_chart->setTheme((QChart::ChartTheme) themeIndex); | |
357 | } |
|
357 | } |
General Comments 0
You need to be logged in to leave comments.
Login now