##// END OF EJS Templates
removed double signal emitting from barseries/set
sauimone -
r1563:d73e56958c7d
parent child
Show More
@@ -1,58 +1,58
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 "drilldownchart.h"
21 #include "drilldownchart.h"
22 #include <QCategoriesAxis>
22 #include <QCategoriesAxis>
23
23
24 QTCOMMERCIALCHART_USE_NAMESPACE
24 QTCOMMERCIALCHART_USE_NAMESPACE
25
25
26 DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
26 DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
27 : QChart(parent, wFlags)
27 : QChart(parent, wFlags)
28 ,m_currentSeries(0)
28 ,m_currentSeries(0)
29 {
29 {
30 }
30 }
31
31
32 void DrilldownChart::changeSeries(DrilldownBarSeries *series)
32 void DrilldownChart::changeSeries(DrilldownBarSeries *series)
33 {
33 {
34 if (m_currentSeries) {
34 if (m_currentSeries) {
35 removeSeries(m_currentSeries);
35 removeSeries(m_currentSeries);
36 }
36 }
37
37
38 m_currentSeries = series;
38 m_currentSeries = series;
39
39
40 // Reset axis
40 // Reset axis
41 QCategoriesAxis* axis = new QCategoriesAxis();
41 QCategoriesAxis* axis = new QCategoriesAxis();
42 axis->append(m_currentSeries->categories());
42 axis->append(m_currentSeries->categories());
43
43
44 addSeries(series);
44 addSeries(series);
45
45
46 setAxisX(series,axis);
46 setAxisX(series,axis);
47
47
48 setTitle(series->name());
48 setTitle(series->name());
49 }
49 }
50
50
51 void DrilldownChart::handleClicked(QBarSet *barset, int index)
51 void DrilldownChart::handleClicked(int index, QBarSet *barset)
52 {
52 {
53 Q_UNUSED(barset)
53 Q_UNUSED(barset)
54 DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender());
54 DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender());
55 changeSeries(series->drilldownSeries(index));
55 changeSeries(series->drilldownSeries(index));
56 }
56 }
57
57
58 #include "moc_drilldownchart.cpp"
58 #include "moc_drilldownchart.cpp"
@@ -1,46 +1,46
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 DRILLDOWNCHART_H
21 #ifndef DRILLDOWNCHART_H
22 #define DRILLDOWNCHART_H
22 #define DRILLDOWNCHART_H
23
23
24 #include <QChart>
24 #include <QChart>
25 #include "drilldownseries.h"
25 #include "drilldownseries.h"
26
26
27 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
28
28
29 //! [1]
29 //! [1]
30 class DrilldownChart : public QChart
30 class DrilldownChart : public QChart
31 {
31 {
32 Q_OBJECT
32 Q_OBJECT
33 public:
33 public:
34 explicit DrilldownChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
34 explicit DrilldownChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
35
35
36 void changeSeries(DrilldownBarSeries *series);
36 void changeSeries(DrilldownBarSeries *series);
37
37
38 public Q_SLOTS:
38 public Q_SLOTS:
39 void handleClicked(QBarSet *barset, int index);
39 void handleClicked(int index, QBarSet *barset);
40
40
41 private:
41 private:
42 DrilldownBarSeries* m_currentSeries;
42 DrilldownBarSeries* m_currentSeries;
43 };
43 };
44 //! [1]
44 //! [1]
45
45
46 #endif // DRILLDOWNCHART_H
46 #endif // DRILLDOWNCHART_H
@@ -1,115 +1,115
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 <QtGui/QApplication>
21 #include <QtGui/QApplication>
22 #include <QMainWindow>
22 #include <QMainWindow>
23 #include <QChartView>
23 #include <QChartView>
24 #include <QBarSet>
24 #include <QBarSet>
25 #include <QLegend>
25 #include <QLegend>
26 #include "drilldownseries.h"
26 #include "drilldownseries.h"
27 #include "drilldownchart.h"
27 #include "drilldownchart.h"
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 QMainWindow window;
34 QMainWindow window;
35
35
36 //! [1]
36 //! [1]
37 DrilldownChart* drilldownChart = new DrilldownChart();
37 DrilldownChart* drilldownChart = new DrilldownChart();
38 drilldownChart->setTheme(QChart::ChartThemeBlueIcy);
38 drilldownChart->setTheme(QChart::ChartThemeBlueIcy);
39 drilldownChart->setAnimationOptions(QChart::SeriesAnimations);
39 drilldownChart->setAnimationOptions(QChart::SeriesAnimations);
40 //! [1]
40 //! [1]
41
41
42 //! [2]
42 //! [2]
43 // Define categories
43 // Define categories
44 QStringList months;
44 QStringList months;
45 months << "May" << "Jun" << "Jul" << "Aug" << "Sep";
45 months << "May" << "Jun" << "Jul" << "Aug" << "Sep";
46 QStringList weeks;
46 QStringList weeks;
47 weeks << "week 1" << "week 2" << "week 3" << "week 4";
47 weeks << "week 1" << "week 2" << "week 3" << "week 4";
48 QStringList plants;
48 QStringList plants;
49 plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo";
49 plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo";
50 //! [2]
50 //! [2]
51
51
52 //! [3]
52 //! [3]
53 // Create drilldown structure
53 // Create drilldown structure
54 DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart);
54 DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart);
55 seasonSeries->setName("Crop by month - Season");
55 seasonSeries->setName("Crop by month - Season");
56
56
57 // Each month in season series has drilldown series for weekly data
57 // Each month in season series has drilldown series for weekly data
58 for (int month=0; month < months.count(); month++) {
58 for (int month=0; month < months.count(); month++) {
59
59
60 // Create drilldown series for every week
60 // Create drilldown series for every week
61 DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart);
61 DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart);
62 seasonSeries->mapDrilldownSeries(month, weeklySeries);
62 seasonSeries->mapDrilldownSeries(month, weeklySeries);
63
63
64 // Drilling down from weekly data brings us back to season data.
64 // Drilling down from weekly data brings us back to season data.
65 for (int week=0; week < weeks.count(); week++) {
65 for (int week=0; week < weeks.count(); week++) {
66 weeklySeries->mapDrilldownSeries(week, seasonSeries);
66 weeklySeries->mapDrilldownSeries(week, seasonSeries);
67 weeklySeries->setName(QString("Crop by week - " + months.at(month)));
67 weeklySeries->setName(QString("Crop by week - " + months.at(month)));
68 }
68 }
69
69
70 // Use right click signal to implement drilldown
70 // Use clicked signal to implement drilldown
71 QObject::connect(weeklySeries, SIGNAL(clicked(QBarSet*,int)), drilldownChart, SLOT(handleClicked(QBarSet*,int)));
71 QObject::connect(weeklySeries, SIGNAL(clicked(int, QBarSet*)), drilldownChart, SLOT(handleClicked(int, QBarSet*)));
72 }
72 }
73
73
74 // Enable drilldown from season series using right click.
74 // Enable drilldown from season series using clicked signal
75 QObject::connect(seasonSeries, SIGNAL(clicked(QBarSet*,int)), drilldownChart, SLOT(handleClicked(QBarSet*,int)));
75 QObject::connect(seasonSeries, SIGNAL(clicked(int, QBarSet*)), drilldownChart, SLOT(handleClicked(int, QBarSet*)));
76 //! [3]
76 //! [3]
77
77
78 //! [4]
78 //! [4]
79 // Fill monthly and weekly series with data
79 // Fill monthly and weekly series with data
80 foreach (QString plant, plants) {
80 foreach (QString plant, plants) {
81 QBarSet* monthlyCrop = new QBarSet(plant);
81 QBarSet* monthlyCrop = new QBarSet(plant);
82 for (int month=0; month<months.count(); month++) {
82 for (int month=0; month<months.count(); month++) {
83 QBarSet* weeklyCrop = new QBarSet(plant);
83 QBarSet* weeklyCrop = new QBarSet(plant);
84 for (int week=0; week<weeks.count(); week++) {
84 for (int week=0; week<weeks.count(); week++) {
85 *weeklyCrop << (qrand() % 20);
85 *weeklyCrop << (qrand() % 20);
86 }
86 }
87 // Get the drilldown series from season series and add crop to it.
87 // Get the drilldown series from season series and add crop to it.
88 seasonSeries->drilldownSeries(month)->append(weeklyCrop);
88 seasonSeries->drilldownSeries(month)->append(weeklyCrop);
89 *monthlyCrop << weeklyCrop->sum();
89 *monthlyCrop << weeklyCrop->sum();
90 }
90 }
91 seasonSeries->append(monthlyCrop);
91 seasonSeries->append(monthlyCrop);
92 }
92 }
93 //! [4]
93 //! [4]
94
94
95 //! [5]
95 //! [5]
96 // Show season series in initial view
96 // Show season series in initial view
97 drilldownChart->changeSeries(seasonSeries);
97 drilldownChart->changeSeries(seasonSeries);
98 drilldownChart->setTitle(seasonSeries->name());
98 drilldownChart->setTitle(seasonSeries->name());
99 //! [5]
99 //! [5]
100
100
101 //! [6]
101 //! [6]
102 drilldownChart->axisX()->setGridLineVisible(false);
102 drilldownChart->axisX()->setGridLineVisible(false);
103 //TODO: drilldownChart->axisY()->setNiceNumbersEnabled(true);
103 //TODO: drilldownChart->axisY()->setNiceNumbersEnabled(true);
104 drilldownChart->legend()->setVisible(true);
104 drilldownChart->legend()->setVisible(true);
105 drilldownChart->legend()->setAlignment(Qt::AlignBottom);
105 drilldownChart->legend()->setAlignment(Qt::AlignBottom);
106 //! [6]
106 //! [6]
107
107
108 QChartView *chartView = new QChartView(drilldownChart);
108 QChartView *chartView = new QChartView(drilldownChart);
109 window.setCentralWidget(chartView);
109 window.setCentralWidget(chartView);
110 window.resize(400, 300);
110 window.resize(400, 300);
111 window.show();
111 window.show();
112
112
113 return a.exec();
113 return a.exec();
114 }
114 }
115
115
@@ -1,58 +1,66
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 "bar_p.h"
21 #include "bar_p.h"
22 #include <QPainter>
22 #include <QPainter>
23 #include <QGraphicsSceneEvent>
23 #include <QGraphicsSceneEvent>
24
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
26
27 Bar::Bar(QBarSet *barset, int index, QGraphicsItem *parent) : QGraphicsRectItem(parent),
27 Bar::Bar(QBarSet *barset, int index, QGraphicsItem *parent) : QGraphicsRectItem(parent),
28 m_index(index),
28 m_index(index),
29 m_barset(barset)
29 m_barset(barset),
30 m_hovering(false)
30 {
31 {
31 setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
32 setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
32 setAcceptHoverEvents(true);
33 setAcceptHoverEvents(true);
33 }
34 }
34
35
36 Bar::~Bar()
37 {
38 // End hover event, if bar is deleted during it
39 if (m_hovering) {
40 emit hovered(false, m_barset);
41 }
42 }
43
35 void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event)
44 void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event)
36 {
45 {
37 Q_UNUSED(event)
46 Q_UNUSED(event)
38 emit clicked(m_barset, m_index);
47 emit clicked(m_index, m_barset);
39 emit clicked(m_index);
40 }
48 }
41
49
42 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
50 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
43 {
51 {
44 Q_UNUSED(event)
52 Q_UNUSED(event)
45 emit hovered(m_barset, true);
53 m_hovering = true;
46 emit hovered(true);
54 emit hovered(true, m_barset);
47 }
55 }
48
56
49 void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
57 void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
50 {
58 {
51 Q_UNUSED(event)
59 Q_UNUSED(event)
52 emit hovered(m_barset, false);
60 m_hovering = false;
53 emit hovered(false);
61 emit hovered(false, m_barset);
54 }
62 }
55
63
56 #include "moc_bar_p.cpp"
64 #include "moc_bar_p.cpp"
57
65
58 QTCOMMERCIALCHART_END_NAMESPACE
66 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,65 +1,65
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 BAR_H
30 #ifndef BAR_H
31 #define BAR_H
31 #define BAR_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include <QGraphicsRectItem>
34 #include <QGraphicsRectItem>
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class QBarSet;
38 class QBarSet;
39
39
40 // Single visual bar item of chart
40 // Single visual bar item of chart
41 class Bar : public QObject, public QGraphicsRectItem
41 class Bar : public QObject, public QGraphicsRectItem
42 {
42 {
43 Q_OBJECT
43 Q_OBJECT
44 public:
44 public:
45 Bar(QBarSet *barset, int index, QGraphicsItem *parent = 0);
45 Bar(QBarSet *barset, int index, QGraphicsItem *parent = 0);
46 ~Bar();
46
47
47 public:
48 public:
48 void mousePressEvent(QGraphicsSceneMouseEvent *event);
49 void mousePressEvent(QGraphicsSceneMouseEvent *event);
49 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
50 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
50 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
51 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
51
52
52 Q_SIGNALS:
53 Q_SIGNALS:
53 void clicked(QBarSet *barset, int index);
54 void clicked(int index, QBarSet *barset);
54 void hovered(QBarSet *barset, bool status);
55 void hovered(bool status, QBarSet *barset);
55 void clicked(int index);
56 void hovered(bool status);
57
56
58 private:
57 private:
59 int m_index;
58 int m_index;
59 bool m_hovering;
60 QBarSet *m_barset;
60 QBarSet *m_barset;
61 };
61 };
62
62
63 QTCOMMERCIALCHART_END_NAMESPACE
63 QTCOMMERCIALCHART_END_NAMESPACE
64
64
65 #endif // BAR_H
65 #endif // BAR_H
@@ -1,226 +1,226
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 "barchartitem_p.h"
21 #include "barchartitem_p.h"
22 #include "bar_p.h"
22 #include "bar_p.h"
23 #include "qbarset.h"
23 #include "qbarset.h"
24 #include "qbarset_p.h"
24 #include "qbarset_p.h"
25 #include "qbarseries.h"
25 #include "qbarseries.h"
26 #include "qbarseries_p.h"
26 #include "qbarseries_p.h"
27 #include "qchart.h"
27 #include "qchart.h"
28 #include "chartpresenter_p.h"
28 #include "chartpresenter_p.h"
29 #include "chartanimator_p.h"
29 #include "chartanimator_p.h"
30 #include "chartdataset_p.h"
30 #include "chartdataset_p.h"
31 #include <QPainter>
31 #include <QPainter>
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) :
35 BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) :
36 ChartItem(presenter),
36 ChartItem(presenter),
37 m_series(series)
37 m_series(series)
38 {
38 {
39 setFlag(ItemClipsChildrenToShape);
39 setFlag(ItemClipsChildrenToShape);
40 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged()));
40 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged()));
41 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
41 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
42 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
42 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
43 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged()));
43 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged()));
44 setZValue(ChartPresenter::BarSeriesZValue);
44 setZValue(ChartPresenter::BarSeriesZValue);
45 handleDataStructureChanged();
45 handleDataStructureChanged();
46 }
46 }
47
47
48 BarChartItem::~BarChartItem()
48 BarChartItem::~BarChartItem()
49 {
49 {
50 }
50 }
51
51
52 void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
52 void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
53 {
53 {
54 Q_UNUSED(painter);
54 Q_UNUSED(painter);
55 Q_UNUSED(option);
55 Q_UNUSED(option);
56 Q_UNUSED(widget);
56 Q_UNUSED(widget);
57 }
57 }
58
58
59 QRectF BarChartItem::boundingRect() const
59 QRectF BarChartItem::boundingRect() const
60 {
60 {
61 return m_rect;
61 return m_rect;
62 }
62 }
63
63
64 QVector<QRectF> BarChartItem::calculateLayout()
64 QVector<QRectF> BarChartItem::calculateLayout()
65 {
65 {
66 QVector<QRectF> layout;
66 QVector<QRectF> layout;
67
67
68 // Use temporary qreals for accuracy
68 // Use temporary qreals for accuracy
69 qreal categoryCount = m_series->d_func()->categoryCount();
69 qreal categoryCount = m_series->d_func()->categoryCount();
70 qreal setCount = m_series->count();
70 qreal setCount = m_series->count();
71 bool barsVisible = m_series->isVisible();
71 bool barsVisible = m_series->isVisible();
72
72
73 // Domain:
73 // Domain:
74 qreal width = geometry().width();
74 qreal width = geometry().width();
75 qreal height = geometry().height();
75 qreal height = geometry().height();
76 qreal rangeY = m_domainMaxY - m_domainMinY;
76 qreal rangeY = m_domainMaxY - m_domainMinY;
77 qreal rangeX = m_domainMaxX - m_domainMinX;
77 qreal rangeX = m_domainMaxX - m_domainMinX;
78 qreal scaleY = (height / rangeY);
78 qreal scaleY = (height / rangeY);
79 qreal scaleX = (width / rangeX);
79 qreal scaleX = (width / rangeX);
80 qreal barWidth = scaleX * m_series->d_func()->barWidth();
80 qreal barWidth = scaleX * m_series->d_func()->barWidth();
81
81
82 int itemIndex(0);
82 int itemIndex(0);
83 for (int category = 0; category < categoryCount; category++) {
83 for (int category = 0; category < categoryCount; category++) {
84 qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y();
84 qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y();
85 for (int set = 0; set < setCount; set++) {
85 for (int set = 0; set < setCount; set++) {
86 QBarSet* barSet = m_series->d_func()->barsetAt(set);
86 QBarSet* barSet = m_series->d_func()->barsetAt(set);
87 qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2;
87 qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2;
88 qreal barHeight = barSet->at(category).y() * scaleY;
88 qreal barHeight = barSet->at(category).y() * scaleY;
89
89
90 Bar* bar = m_bars.at(itemIndex);
90 Bar* bar = m_bars.at(itemIndex);
91 QRectF rect(xPos, yPos - barHeight, barWidth, barHeight);
91 QRectF rect(xPos, yPos - barHeight, barWidth, barHeight);
92
92
93 layout.append(rect);
93 layout.append(rect);
94 bar->setPen(barSet->pen());
94 bar->setPen(barSet->pen());
95 bar->setBrush(barSet->brush());
95 bar->setBrush(barSet->brush());
96 bar->setVisible(barsVisible);
96 bar->setVisible(barsVisible);
97
97
98 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
98 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
99
99
100 if (!qFuzzyIsNull(barSet->at(category).y())) {
100 if (!qFuzzyIsNull(barSet->at(category).y())) {
101 label->setText(QString::number(barSet->at(category).y()));
101 label->setText(QString::number(barSet->at(category).y()));
102 } else {
102 } else {
103 label->setText(QString(""));
103 label->setText(QString(""));
104 }
104 }
105
105
106 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
106 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
107 ,yPos - barHeight/2 - label->boundingRect().height()/2);
107 ,yPos - barHeight/2 - label->boundingRect().height()/2);
108 label->setFont(barSet->labelFont());
108 label->setFont(barSet->labelFont());
109 label->setBrush(barSet->labelBrush());
109 label->setBrush(barSet->labelBrush());
110
110
111 itemIndex++;
111 itemIndex++;
112 }
112 }
113 }
113 }
114
114
115 return layout;
115 return layout;
116 }
116 }
117
117
118 void BarChartItem::applyLayout(const QVector<QRectF> &layout)
118 void BarChartItem::applyLayout(const QVector<QRectF> &layout)
119 {
119 {
120 if (animator()) {
120 if (animator()) {
121 animator()->updateLayout(this, m_layout, layout);
121 animator()->updateLayout(this, m_layout, layout);
122 } else {
122 } else {
123 setLayout(layout);
123 setLayout(layout);
124 update();
124 update();
125 }
125 }
126 }
126 }
127
127
128 void BarChartItem::setLayout(const QVector<QRectF> &layout)
128 void BarChartItem::setLayout(const QVector<QRectF> &layout)
129 {
129 {
130 if (layout.count() != m_bars.count())
130 if (layout.count() != m_bars.count())
131 return;
131 return;
132
132
133 m_layout = layout;
133 m_layout = layout;
134
134
135 for (int i=0; i < m_bars.count(); i++) {
135 for (int i=0; i < m_bars.count(); i++) {
136 m_bars.at(i)->setRect(layout.at(i));
136 m_bars.at(i)->setRect(layout.at(i));
137 }
137 }
138 }
138 }
139 //handlers
139 //handlers
140
140
141 void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
141 void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
142 {
142 {
143 m_domainMinX = minX;
143 m_domainMinX = minX;
144 m_domainMaxX = maxX;
144 m_domainMaxX = maxX;
145 m_domainMinY = minY;
145 m_domainMinY = minY;
146 m_domainMaxY = maxY;
146 m_domainMaxY = maxY;
147 handleLayoutChanged();
147 handleLayoutChanged();
148 }
148 }
149
149
150 void BarChartItem::handleGeometryChanged(const QRectF &rect)
150 void BarChartItem::handleGeometryChanged(const QRectF &rect)
151 {
151 {
152 prepareGeometryChange();
152 prepareGeometryChange();
153 m_rect = rect;
153 m_rect = rect;
154 handleLayoutChanged();
154 handleLayoutChanged();
155 }
155 }
156
156
157 void BarChartItem::handleLayoutChanged()
157 void BarChartItem::handleLayoutChanged()
158 {
158 {
159 if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) {
159 if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) {
160 // rect size zero.
160 // rect size zero.
161 return;
161 return;
162 }
162 }
163 QVector<QRectF> layout = calculateLayout();
163 QVector<QRectF> layout = calculateLayout();
164 applyLayout(layout);
164 applyLayout(layout);
165 }
165 }
166
166
167
167
168
168
169 void BarChartItem::handleLabelsVisibleChanged(bool visible)
169 void BarChartItem::handleLabelsVisibleChanged(bool visible)
170 {
170 {
171 foreach (QGraphicsSimpleTextItem* label, m_labels) {
171 foreach (QGraphicsSimpleTextItem* label, m_labels) {
172 label->setVisible(visible);
172 label->setVisible(visible);
173 }
173 }
174 update();
174 update();
175 }
175 }
176
176
177 void BarChartItem::handleDataStructureChanged()
177 void BarChartItem::handleDataStructureChanged()
178 {
178 {
179 foreach(QGraphicsItem *item, childItems()) {
179 foreach(QGraphicsItem *item, childItems()) {
180 delete item;
180 delete item;
181 }
181 }
182
182
183 m_bars.clear();
183 m_bars.clear();
184 m_labels.clear();
184 m_labels.clear();
185 m_layout.clear();
185 m_layout.clear();
186
186
187 bool labelsVisible = m_series->isLabelsVisible();
187 bool labelsVisible = m_series->isLabelsVisible();
188
188
189 // Create new graphic items for bars
189 // Create new graphic items for bars
190 for (int c = 0; c < m_series->d_func()->categoryCount(); c++) {
190 for (int c = 0; c < m_series->d_func()->categoryCount(); c++) {
191 for (int s = 0; s < m_series->count(); s++) {
191 for (int s = 0; s < m_series->count(); s++) {
192 QBarSet *set = m_series->d_func()->barsetAt(s);
192 QBarSet *set = m_series->d_func()->barsetAt(s);
193
193
194 // Bars
194 // Bars
195 Bar *bar = new Bar(set,c,this);
195 Bar *bar = new Bar(set,c,this);
196 m_bars.append(bar);
196 m_bars.append(bar);
197 connect(bar, SIGNAL(clicked(QBarSet*,int)), m_series, SIGNAL(clicked(QBarSet*,int)));
197 connect(bar, SIGNAL(clicked(int, QBarSet*)), m_series, SIGNAL(clicked(int, QBarSet*)));
198 connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool)));
198 connect(bar, SIGNAL(hovered(bool, QBarSet*)), m_series, SIGNAL(hovered(bool, QBarSet*)));
199 connect(bar, SIGNAL(clicked(int)), set, SIGNAL(clicked(int)));
199 connect(bar, SIGNAL(clicked(int, QBarSet*)), set, SIGNAL(clicked(int)));
200 connect(bar, SIGNAL(hovered(bool)), set, SIGNAL(hovered(bool)));
200 connect(bar, SIGNAL(hovered(bool, QBarSet*)), set, SIGNAL(hovered(bool)));
201 m_layout.append(QRectF(0, 0, 0, 0));
201 m_layout.append(QRectF(0, 0, 0, 0));
202
202
203 // Labels
203 // Labels
204 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this);
204 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this);
205 label->setVisible(labelsVisible);
205 label->setVisible(labelsVisible);
206 m_labels.append(label);
206 m_labels.append(label);
207 }
207 }
208 }
208 }
209
209
210 // TODO: Is this the right place to call it?
210 // TODO: Is this the right place to call it?
211 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
211 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
212 handleLayoutChanged();
212 handleLayoutChanged();
213 }
213 }
214
214
215 void BarChartItem::handleVisibleChanged()
215 void BarChartItem::handleVisibleChanged()
216 {
216 {
217 bool visible = m_series->isVisible();
217 bool visible = m_series->isVisible();
218 handleLabelsVisibleChanged(visible);
218 handleLabelsVisibleChanged(visible);
219 foreach(QGraphicsItem *item, childItems()) {
219 foreach(QGraphicsItem *item, childItems()) {
220 item->setVisible(visible);
220 item->setVisible(visible);
221 }
221 }
222 }
222 }
223
223
224 #include "moc_barchartitem_p.cpp"
224 #include "moc_barchartitem_p.cpp"
225
225
226 QTCOMMERCIALCHART_END_NAMESPACE
226 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,731 +1,731
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 "qbarseries.h"
21 #include "qbarseries.h"
22 #include "qbarseries_p.h"
22 #include "qbarseries_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
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 /*!
34 /*!
35 \class QBarSeries
35 \class QBarSeries
36 \brief Series for creating a bar chart
36 \brief Series for creating a bar chart
37 \mainclass
37 \mainclass
38
38
39 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
39 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
40 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
40 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
41 and y-value is the height of the bar. The category names are ignored with this series and x-axis
41 and y-value is the height of the bar. The category names are ignored with this series and x-axis
42 shows the x-values.
42 shows the x-values.
43
43
44 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
44 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
45 \image examples_barchart.png
45 \image examples_barchart.png
46
46
47 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
47 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
48 */
48 */
49 /*!
49 /*!
50 \qmlclass BarSeries QBarSeries
50 \qmlclass BarSeries QBarSeries
51 \inherits AbstractSeries
51 \inherits AbstractSeries
52
52
53 The following QML shows how to create a simple bar chart:
53 The following QML shows how to create a simple bar chart:
54 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
54 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
55
55
56 \beginfloatleft
56 \beginfloatleft
57 \image demos_qmlchart6.png
57 \image demos_qmlchart6.png
58 \endfloat
58 \endfloat
59 \clearfloat
59 \clearfloat
60 */
60 */
61
61
62 /*!
62 /*!
63 \property QBarSeries::barWidth
63 \property QBarSeries::barWidth
64 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
64 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 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
65 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
66 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
66 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
67 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
67 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
68 \sa QGroupedBarSeries
68 \sa QGroupedBarSeries
69 */
69 */
70 /*!
70 /*!
71 \qmlproperty real BarSeries::barWidth
71 \qmlproperty real BarSeries::barWidth
72 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
72 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
73 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
73 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
74 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
74 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
75 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
75 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
76 */
76 */
77
77
78 /*!
78 /*!
79 \property QBarSeries::count
79 \property QBarSeries::count
80 Holds the number of sets in series.
80 Holds the number of sets in series.
81 */
81 */
82 /*!
82 /*!
83 \qmlproperty int BarSeries::count
83 \qmlproperty int BarSeries::count
84 Holds the number of sets in series.
84 Holds the number of sets in series.
85 */
85 */
86
86
87 /*!
87 /*!
88 \property QBarSeries::labelsVisible
88 \property QBarSeries::labelsVisible
89 Defines the visibility of the labels in series
89 Defines the visibility of the labels in series
90 */
90 */
91 /*!
91 /*!
92 \qmlproperty bool BarSeries::labelsVisible
92 \qmlproperty bool BarSeries::labelsVisible
93 Defines the visibility of the labels in series
93 Defines the visibility of the labels in series
94 */
94 */
95
95
96 /*!
96 /*!
97 \fn void QBarSeries::clicked(QBarSet *barset, int index)
97 \fn void QBarSeries::clicked(int index, QBarSet *barset)
98 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
98 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
99 Clicked bar inside set is indexed by \a index
99 Clicked bar inside set is indexed by \a index
100 */
100 */
101 /*!
101 /*!
102 \qmlsignal BarSeries::onClicked(BarSet barset, int index)
102 \qmlsignal BarSeries::onClicked(int index, BarSet barset)
103 The signal is emitted if the user clicks with a mouse on top of BarSet.
103 The signal is emitted if the user clicks with a mouse on top of BarSet.
104 Clicked bar inside set is indexed by \a index
104 Clicked bar inside set is indexed by \a index
105 */
105 */
106
106
107 /*!
107 /*!
108 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
108 \fn void QBarSeries::hovered(bool status, QBarSet* barset)
109
109
110 The signal is emitted if mouse is hovered on top of series.
110 The signal is emitted if mouse is hovered on top of series.
111 Parameter \a barset is the pointer of barset, where hover happened.
111 Parameter \a barset is the pointer of barset, where hover happened.
112 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
112 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
113 */
113 */
114 /*!
114 /*!
115 \qmlsignal BarSeries::onHovered(BarSet barset, bool status)
115 \qmlsignal BarSeries::onHovered(bool status, BarSet barset)
116
116
117 The signal is emitted if mouse is hovered on top of series.
117 The signal is emitted if mouse is hovered on top of series.
118 Parameter \a barset is the pointer of barset, where hover happened.
118 Parameter \a barset is the pointer of barset, where hover happened.
119 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
119 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
120 */
120 */
121
121
122 /*!
122 /*!
123 \fn void QBarSeries::countChanged()
123 \fn void QBarSeries::countChanged()
124 This signal is emitted when barset count has been changed, for example by append or remove.
124 This signal is emitted when barset count has been changed, for example by append or remove.
125 */
125 */
126 /*!
126 /*!
127 \qmlsignal BarSeries::onCountChanged()
127 \qmlsignal BarSeries::onCountChanged()
128 This signal is emitted when barset count has been changed, for example by append or remove.
128 This signal is emitted when barset count has been changed, for example by append or remove.
129 */
129 */
130
130
131 /*!
131 /*!
132 \fn void QBarSeries::labelsVisibleChanged()
132 \fn void QBarSeries::labelsVisibleChanged()
133 This signal is emitted when labels visibility have changed.
133 This signal is emitted when labels visibility have changed.
134 \sa isLabelsVisible(), setLabelsVisible()
134 \sa isLabelsVisible(), setLabelsVisible()
135 */
135 */
136
136
137 /*!
137 /*!
138 \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets)
138 \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets)
139 This signal is emitted when \a sets have been added to the series.
139 This signal is emitted when \a sets have been added to the series.
140 \sa append(), insert()
140 \sa append(), insert()
141 */
141 */
142 /*!
142 /*!
143 \qmlsignal BarSeries::onAdded(BarSet barset)
143 \qmlsignal BarSeries::onAdded(BarSet barset)
144 Emitted when \a barset has been added to the series.
144 Emitted when \a barset has been added to the series.
145 */
145 */
146
146
147 /*!
147 /*!
148 \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets)
148 \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets)
149 This signal is emitted when \a sets have been removed from the series.
149 This signal is emitted when \a sets have been removed from the series.
150 \sa remove()
150 \sa remove()
151 */
151 */
152 /*!
152 /*!
153 \qmlsignal BarSeries::onRemoved(BarSet barset)
153 \qmlsignal BarSeries::onRemoved(BarSet barset)
154 Emitted when \a barset has been removed from the series.
154 Emitted when \a barset has been removed from the series.
155 */
155 */
156
156
157 /*!
157 /*!
158 \qmlmethod BarSet BarSeries::at(int index)
158 \qmlmethod BarSet BarSeries::at(int index)
159 Returns bar set at \a index. Returns null if the index is not valid.
159 Returns bar set at \a index. Returns null if the index is not valid.
160 */
160 */
161
161
162 /*!
162 /*!
163 \qmlmethod BarSet BarSeries::append(string label, VariantList values)
163 \qmlmethod BarSet BarSeries::append(string label, VariantList values)
164 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.
164 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 For example:
165 For example:
166 \code
166 \code
167 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
167 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
168 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
168 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
169 \endcode
169 \endcode
170 */
170 */
171
171
172 /*!
172 /*!
173 \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values)
173 \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values)
174 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.
174 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 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
175 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
176 appended.
176 appended.
177 \sa BarSeries::append()
177 \sa BarSeries::append()
178 */
178 */
179
179
180 /*!
180 /*!
181 \qmlmethod bool BarSeries::remove(BarSet barset)
181 \qmlmethod bool BarSeries::remove(BarSet barset)
182 Removes the barset from the series. Returns true if successfull, false otherwise.
182 Removes the barset from the series. Returns true if successfull, false otherwise.
183 */
183 */
184
184
185 /*!
185 /*!
186 \qmlmethod BarSeries::clear()
186 \qmlmethod BarSeries::clear()
187 Removes all barsets from the series.
187 Removes all barsets from the series.
188 */
188 */
189
189
190 /*!
190 /*!
191 Constructs empty QBarSeries.
191 Constructs empty QBarSeries.
192 QBarSeries is QObject which is a child of a \a parent.
192 QBarSeries is QObject which is a child of a \a parent.
193 */
193 */
194 QBarSeries::QBarSeries(QObject *parent) :
194 QBarSeries::QBarSeries(QObject *parent) :
195 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
195 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
196 {
196 {
197 }
197 }
198
198
199 /*!
199 /*!
200 Destructs barseries and owned barsets.
200 Destructs barseries and owned barsets.
201 */
201 */
202 QBarSeries::~QBarSeries()
202 QBarSeries::~QBarSeries()
203 {
203 {
204 Q_D(QBarSeries);
204 Q_D(QBarSeries);
205 if(d->m_dataset){
205 if(d->m_dataset){
206 d->m_dataset->removeSeries(this);
206 d->m_dataset->removeSeries(this);
207 }
207 }
208 }
208 }
209
209
210 /*!
210 /*!
211 \internal
211 \internal
212 */
212 */
213 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
213 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
214 QAbstractSeries(d,parent)
214 QAbstractSeries(d,parent)
215 {
215 {
216 }
216 }
217
217
218 /*!
218 /*!
219 Returns the type of series. Derived classes override this.
219 Returns the type of series. Derived classes override this.
220 */
220 */
221 QAbstractSeries::SeriesType QBarSeries::type() const
221 QAbstractSeries::SeriesType QBarSeries::type() const
222 {
222 {
223 return QAbstractSeries::SeriesTypeBar;
223 return QAbstractSeries::SeriesTypeBar;
224 }
224 }
225
225
226 /*!
226 /*!
227 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
227 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
228 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
228 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
229 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
229 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
230 Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar.
230 Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar.
231 */
231 */
232 void QBarSeries::setBarWidth(qreal width)
232 void QBarSeries::setBarWidth(qreal width)
233 {
233 {
234 Q_D(QBarSeries);
234 Q_D(QBarSeries);
235 d->setBarWidth(width);
235 d->setBarWidth(width);
236 }
236 }
237
237
238 /*!
238 /*!
239 Returns the width of the bars of the series.
239 Returns the width of the bars of the series.
240 \sa setBarWidth()
240 \sa setBarWidth()
241 */
241 */
242 qreal QBarSeries::barWidth() const
242 qreal QBarSeries::barWidth() const
243 {
243 {
244 Q_D(const QBarSeries);
244 Q_D(const QBarSeries);
245 return d->barWidth();
245 return d->barWidth();
246 }
246 }
247
247
248 /*!
248 /*!
249 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.
249 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.
250 Returns true, if appending succeeded.
250 Returns true, if appending succeeded.
251 */
251 */
252 bool QBarSeries::append(QBarSet *set)
252 bool QBarSeries::append(QBarSet *set)
253 {
253 {
254 Q_D(QBarSeries);
254 Q_D(QBarSeries);
255 bool success = d->append(set);
255 bool success = d->append(set);
256 if (success) {
256 if (success) {
257 QList<QBarSet*> sets;
257 QList<QBarSet*> sets;
258 sets.append(set);
258 sets.append(set);
259 emit barsetsAdded(sets);
259 emit barsetsAdded(sets);
260 emit countChanged();
260 emit countChanged();
261 }
261 }
262 return success;
262 return success;
263 }
263 }
264
264
265 /*!
265 /*!
266 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
266 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
267 Returns true, if set was removed.
267 Returns true, if set was removed.
268 */
268 */
269 bool QBarSeries::remove(QBarSet *set)
269 bool QBarSeries::remove(QBarSet *set)
270 {
270 {
271 Q_D(QBarSeries);
271 Q_D(QBarSeries);
272 bool success = d->remove(set);
272 bool success = d->remove(set);
273 if (success) {
273 if (success) {
274 QList<QBarSet*> sets;
274 QList<QBarSet*> sets;
275 sets.append(set);
275 sets.append(set);
276 emit barsetsRemoved(sets);
276 emit barsetsRemoved(sets);
277 emit countChanged();
277 emit countChanged();
278 }
278 }
279 return success;
279 return success;
280 }
280 }
281
281
282 /*!
282 /*!
283 Adds a list of barsets to series. Takes ownership of \a sets.
283 Adds a list of barsets to series. Takes ownership of \a sets.
284 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
284 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
285 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
285 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
286 and function returns false.
286 and function returns false.
287 */
287 */
288 bool QBarSeries::append(QList<QBarSet* > sets)
288 bool QBarSeries::append(QList<QBarSet* > sets)
289 {
289 {
290 Q_D(QBarSeries);
290 Q_D(QBarSeries);
291 bool success = d->append(sets);
291 bool success = d->append(sets);
292 if (success) {
292 if (success) {
293 emit barsetsAdded(sets);
293 emit barsetsAdded(sets);
294 emit countChanged();
294 emit countChanged();
295 }
295 }
296 return success;
296 return success;
297 }
297 }
298
298
299 /*!
299 /*!
300 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.
300 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.
301 Returns true, if inserting succeeded.
301 Returns true, if inserting succeeded.
302
302
303 */
303 */
304 bool QBarSeries::insert(int index, QBarSet *set)
304 bool QBarSeries::insert(int index, QBarSet *set)
305 {
305 {
306 Q_D(QBarSeries);
306 Q_D(QBarSeries);
307 bool success = d->insert(index, set);
307 bool success = d->insert(index, set);
308 if (success) {
308 if (success) {
309 QList<QBarSet*> sets;
309 QList<QBarSet*> sets;
310 sets.append(set);
310 sets.append(set);
311 emit barsetsAdded(sets);
311 emit barsetsAdded(sets);
312 emit countChanged();
312 emit countChanged();
313 }
313 }
314 return success;
314 return success;
315 }
315 }
316
316
317 /*!
317 /*!
318 Removes all of the bar sets from the series
318 Removes all of the bar sets from the series
319 */
319 */
320 void QBarSeries::clear()
320 void QBarSeries::clear()
321 {
321 {
322 Q_D(QBarSeries);
322 Q_D(QBarSeries);
323 QList<QBarSet *> sets = barSets();
323 QList<QBarSet *> sets = barSets();
324 bool success = d->remove(sets);
324 bool success = d->remove(sets);
325 if (success) {
325 if (success) {
326 emit barsetsRemoved(sets);
326 emit barsetsRemoved(sets);
327 emit countChanged();
327 emit countChanged();
328 }
328 }
329 }
329 }
330
330
331 /*!
331 /*!
332 Returns number of sets in series.
332 Returns number of sets in series.
333 */
333 */
334 int QBarSeries::count() const
334 int QBarSeries::count() const
335 {
335 {
336 Q_D(const QBarSeries);
336 Q_D(const QBarSeries);
337 return d->m_barSets.count();
337 return d->m_barSets.count();
338 }
338 }
339
339
340 /*!
340 /*!
341 Returns a list of sets in series. Keeps ownership of sets.
341 Returns a list of sets in series. Keeps ownership of sets.
342 */
342 */
343 QList<QBarSet*> QBarSeries::barSets() const
343 QList<QBarSet*> QBarSeries::barSets() const
344 {
344 {
345 Q_D(const QBarSeries);
345 Q_D(const QBarSeries);
346 return d->m_barSets;
346 return d->m_barSets;
347 }
347 }
348
348
349 /*!
349 /*!
350 Sets the visibility of labels in series to \a visible
350 Sets the visibility of labels in series to \a visible
351 */
351 */
352 void QBarSeries::setLabelsVisible(bool visible)
352 void QBarSeries::setLabelsVisible(bool visible)
353 {
353 {
354 Q_D(QBarSeries);
354 Q_D(QBarSeries);
355 if (d->m_labelsVisible != visible) {
355 if (d->m_labelsVisible != visible) {
356 d->setLabelsVisible(visible);
356 d->setLabelsVisible(visible);
357 emit labelsVisibleChanged();
357 emit labelsVisibleChanged();
358 }
358 }
359 }
359 }
360
360
361 /*!
361 /*!
362 Returns the visibility of labels
362 Returns the visibility of labels
363 */
363 */
364 bool QBarSeries::isLabelsVisible() const
364 bool QBarSeries::isLabelsVisible() const
365 {
365 {
366 Q_D(const QBarSeries);
366 Q_D(const QBarSeries);
367 return d->m_labelsVisible;
367 return d->m_labelsVisible;
368 }
368 }
369
369
370 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
370 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
371
371
372 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
372 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
373 QAbstractSeriesPrivate(q),
373 QAbstractSeriesPrivate(q),
374 m_barWidth(0.5), // Default value is 50% of category width
374 m_barWidth(0.5), // Default value is 50% of category width
375 m_labelsVisible(false),
375 m_labelsVisible(false),
376 m_visible(true)
376 m_visible(true)
377 {
377 {
378 }
378 }
379
379
380 int QBarSeriesPrivate::categoryCount() const
380 int QBarSeriesPrivate::categoryCount() const
381 {
381 {
382 // No categories defined. return count of longest set.
382 // No categories defined. return count of longest set.
383 int count = 0;
383 int count = 0;
384 for (int i=0; i<m_barSets.count(); i++) {
384 for (int i=0; i<m_barSets.count(); i++) {
385 if (m_barSets.at(i)->count() > count) {
385 if (m_barSets.at(i)->count() > count) {
386 count = m_barSets.at(i)->count();
386 count = m_barSets.at(i)->count();
387 }
387 }
388 }
388 }
389
389
390 return count;
390 return count;
391 }
391 }
392
392
393 void QBarSeriesPrivate::setBarWidth(qreal width)
393 void QBarSeriesPrivate::setBarWidth(qreal width)
394 {
394 {
395 if (width < 0.0) {
395 if (width < 0.0) {
396 width = 0.0;
396 width = 0.0;
397 }
397 }
398 m_barWidth = width;
398 m_barWidth = width;
399 emit updatedBars();
399 emit updatedBars();
400 }
400 }
401
401
402 qreal QBarSeriesPrivate::barWidth() const
402 qreal QBarSeriesPrivate::barWidth() const
403 {
403 {
404 return m_barWidth;
404 return m_barWidth;
405 }
405 }
406
406
407 QBarSet* QBarSeriesPrivate::barsetAt(int index)
407 QBarSet* QBarSeriesPrivate::barsetAt(int index)
408 {
408 {
409 return m_barSets.at(index);
409 return m_barSets.at(index);
410 }
410 }
411
411
412 void QBarSeriesPrivate::setVisible(bool visible)
412 void QBarSeriesPrivate::setVisible(bool visible)
413 {
413 {
414 m_visible = visible;
414 m_visible = visible;
415 emit updatedBars();
415 emit updatedBars();
416 }
416 }
417
417
418 void QBarSeriesPrivate::setLabelsVisible(bool visible)
418 void QBarSeriesPrivate::setLabelsVisible(bool visible)
419 {
419 {
420 m_labelsVisible = visible;
420 m_labelsVisible = visible;
421 emit labelsVisibleChanged(visible);
421 emit labelsVisibleChanged(visible);
422 }
422 }
423
423
424 qreal QBarSeriesPrivate::min()
424 qreal QBarSeriesPrivate::min()
425 {
425 {
426 if (m_barSets.count() <= 0) {
426 if (m_barSets.count() <= 0) {
427 return 0;
427 return 0;
428 }
428 }
429 qreal min = INT_MAX;
429 qreal min = INT_MAX;
430
430
431 for (int i = 0; i < m_barSets.count(); i++) {
431 for (int i = 0; i < m_barSets.count(); i++) {
432 int categoryCount = m_barSets.at(i)->count();
432 int categoryCount = m_barSets.at(i)->count();
433 for (int j = 0; j < categoryCount; j++) {
433 for (int j = 0; j < categoryCount; j++) {
434 qreal temp = m_barSets.at(i)->at(j).y();
434 qreal temp = m_barSets.at(i)->at(j).y();
435 if (temp < min)
435 if (temp < min)
436 min = temp;
436 min = temp;
437 }
437 }
438 }
438 }
439 return min;
439 return min;
440 }
440 }
441
441
442 qreal QBarSeriesPrivate::max()
442 qreal QBarSeriesPrivate::max()
443 {
443 {
444 if (m_barSets.count() <= 0) {
444 if (m_barSets.count() <= 0) {
445 return 0;
445 return 0;
446 }
446 }
447 qreal max = INT_MIN;
447 qreal max = INT_MIN;
448
448
449 for (int i = 0; i < m_barSets.count(); i++) {
449 for (int i = 0; i < m_barSets.count(); i++) {
450 int categoryCount = m_barSets.at(i)->count();
450 int categoryCount = m_barSets.at(i)->count();
451 for (int j = 0; j < categoryCount; j++) {
451 for (int j = 0; j < categoryCount; j++) {
452 qreal temp = m_barSets.at(i)->at(j).y();
452 qreal temp = m_barSets.at(i)->at(j).y();
453 if (temp > max)
453 if (temp > max)
454 max = temp;
454 max = temp;
455 }
455 }
456 }
456 }
457
457
458 return max;
458 return max;
459 }
459 }
460
460
461 qreal QBarSeriesPrivate::valueAt(int set, int category)
461 qreal QBarSeriesPrivate::valueAt(int set, int category)
462 {
462 {
463 if ((set < 0) || (set >= m_barSets.count())) {
463 if ((set < 0) || (set >= m_barSets.count())) {
464 // No set, no value.
464 // No set, no value.
465 return 0;
465 return 0;
466 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
466 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
467 // No category, no value.
467 // No category, no value.
468 return 0;
468 return 0;
469 }
469 }
470
470
471 return m_barSets.at(set)->at(category).y();
471 return m_barSets.at(set)->at(category).y();
472 }
472 }
473
473
474 qreal QBarSeriesPrivate::percentageAt(int set, int category)
474 qreal QBarSeriesPrivate::percentageAt(int set, int category)
475 {
475 {
476 if ((set < 0) || (set >= m_barSets.count())) {
476 if ((set < 0) || (set >= m_barSets.count())) {
477 // No set, no value.
477 // No set, no value.
478 return 0;
478 return 0;
479 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
479 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
480 // No category, no value.
480 // No category, no value.
481 return 0;
481 return 0;
482 }
482 }
483
483
484 qreal value = m_barSets.at(set)->at(category).y();
484 qreal value = m_barSets.at(set)->at(category).y();
485 qreal sum = categorySum(category);
485 qreal sum = categorySum(category);
486 if ( qFuzzyIsNull(sum) ) {
486 if ( qFuzzyIsNull(sum) ) {
487 return 0;
487 return 0;
488 }
488 }
489
489
490 return value / sum;
490 return value / sum;
491 }
491 }
492
492
493 qreal QBarSeriesPrivate::categorySum(int category)
493 qreal QBarSeriesPrivate::categorySum(int category)
494 {
494 {
495 qreal sum(0);
495 qreal sum(0);
496 int count = m_barSets.count(); // Count sets
496 int count = m_barSets.count(); // Count sets
497 for (int set = 0; set < count; set++) {
497 for (int set = 0; set < count; set++) {
498 if (category < m_barSets.at(set)->count())
498 if (category < m_barSets.at(set)->count())
499 sum += m_barSets.at(set)->at(category).y();
499 sum += m_barSets.at(set)->at(category).y();
500 }
500 }
501 return sum;
501 return sum;
502 }
502 }
503
503
504 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
504 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
505 {
505 {
506 qreal sum(0);
506 qreal sum(0);
507 int count = m_barSets.count(); // Count sets
507 int count = m_barSets.count(); // Count sets
508 for (int set = 0; set < count; set++) {
508 for (int set = 0; set < count; set++) {
509 if (category < m_barSets.at(set)->count())
509 if (category < m_barSets.at(set)->count())
510 sum += qAbs(m_barSets.at(set)->at(category).y());
510 sum += qAbs(m_barSets.at(set)->at(category).y());
511 }
511 }
512 return sum;
512 return sum;
513 }
513 }
514
514
515 qreal QBarSeriesPrivate::maxCategorySum()
515 qreal QBarSeriesPrivate::maxCategorySum()
516 {
516 {
517 qreal max = INT_MIN;
517 qreal max = INT_MIN;
518 int count = categoryCount();
518 int count = categoryCount();
519 for (int i = 0; i < count; i++) {
519 for (int i = 0; i < count; i++) {
520 qreal sum = categorySum(i);
520 qreal sum = categorySum(i);
521 if (sum > max)
521 if (sum > max)
522 max = sum;
522 max = sum;
523 }
523 }
524 return max;
524 return max;
525 }
525 }
526
526
527 qreal QBarSeriesPrivate::minX()
527 qreal QBarSeriesPrivate::minX()
528 {
528 {
529 if (m_barSets.count() <= 0) {
529 if (m_barSets.count() <= 0) {
530 return 0;
530 return 0;
531 }
531 }
532 qreal min = INT_MAX;
532 qreal min = INT_MAX;
533
533
534 for (int i = 0; i < m_barSets.count(); i++) {
534 for (int i = 0; i < m_barSets.count(); i++) {
535 int categoryCount = m_barSets.at(i)->count();
535 int categoryCount = m_barSets.at(i)->count();
536 for (int j = 0; j < categoryCount; j++) {
536 for (int j = 0; j < categoryCount; j++) {
537 qreal temp = m_barSets.at(i)->at(j).x();
537 qreal temp = m_barSets.at(i)->at(j).x();
538 if (temp < min)
538 if (temp < min)
539 min = temp;
539 min = temp;
540 }
540 }
541 }
541 }
542 return min;
542 return min;
543 }
543 }
544
544
545 qreal QBarSeriesPrivate::maxX()
545 qreal QBarSeriesPrivate::maxX()
546 {
546 {
547 if (m_barSets.count() <= 0) {
547 if (m_barSets.count() <= 0) {
548 return 0;
548 return 0;
549 }
549 }
550 qreal max = INT_MIN;
550 qreal max = INT_MIN;
551
551
552 for (int i = 0; i < m_barSets.count(); i++) {
552 for (int i = 0; i < m_barSets.count(); i++) {
553 int categoryCount = m_barSets.at(i)->count();
553 int categoryCount = m_barSets.at(i)->count();
554 for (int j = 0; j < categoryCount; j++) {
554 for (int j = 0; j < categoryCount; j++) {
555 qreal temp = m_barSets.at(i)->at(j).x();
555 qreal temp = m_barSets.at(i)->at(j).x();
556 if (temp > max)
556 if (temp > max)
557 max = temp;
557 max = temp;
558 }
558 }
559 }
559 }
560
560
561 return max;
561 return max;
562 }
562 }
563
563
564
564
565 void QBarSeriesPrivate::scaleDomain(Domain& domain)
565 void QBarSeriesPrivate::scaleDomain(Domain& domain)
566 {
566 {
567 qreal minX(domain.minX());
567 qreal minX(domain.minX());
568 qreal minY(domain.minY());
568 qreal minY(domain.minY());
569 qreal maxX(domain.maxX());
569 qreal maxX(domain.maxX());
570 qreal maxY(domain.maxY());
570 qreal maxY(domain.maxY());
571 int tickXCount(domain.tickXCount());
571 int tickXCount(domain.tickXCount());
572 int tickYCount(domain.tickYCount());
572 int tickYCount(domain.tickYCount());
573
573
574 qreal seriesMinX = this->minX();
574 qreal seriesMinX = this->minX();
575 qreal seriesMaxX = this->maxX();
575 qreal seriesMaxX = this->maxX();
576 qreal y = max();
576 qreal y = max();
577 minX = qMin(minX, seriesMinX - 0.5);
577 minX = qMin(minX, seriesMinX - 0.5);
578 minY = qMin(minY, y);
578 minY = qMin(minY, y);
579 maxX = qMax(maxX, seriesMaxX + 0.5);
579 maxX = qMax(maxX, seriesMaxX + 0.5);
580 maxY = qMax(maxY, y);
580 maxY = qMax(maxY, y);
581 tickXCount = categoryCount()+1;
581 tickXCount = categoryCount()+1;
582
582
583 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
583 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
584 }
584 }
585
585
586 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
586 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
587 {
587 {
588 Q_Q(QBarSeries);
588 Q_Q(QBarSeries);
589
589
590 BarChartItem* bar = new BarChartItem(q,presenter);
590 BarChartItem* bar = new BarChartItem(q,presenter);
591 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
591 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
592 presenter->animator()->addAnimation(bar);
592 presenter->animator()->addAnimation(bar);
593 }
593 }
594 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
594 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
595 return bar;
595 return bar;
596
596
597 }
597 }
598
598
599 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
599 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
600 {
600 {
601 Q_Q(QBarSeries);
601 Q_Q(QBarSeries);
602 QList<LegendMarker*> markers;
602 QList<LegendMarker*> markers;
603 foreach(QBarSet* set, q->barSets()) {
603 foreach(QBarSet* set, q->barSets()) {
604 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
604 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
605 markers << marker;
605 markers << marker;
606 }
606 }
607
607
608 return markers;
608 return markers;
609 }
609 }
610
610
611 QAbstractAxis* QBarSeriesPrivate::createAxisX(QObject* parent)
611 QAbstractAxis* QBarSeriesPrivate::createAxisX(QObject* parent)
612 {
612 {
613 return new QValuesAxis(parent);
613 return new QValuesAxis(parent);
614 }
614 }
615
615
616 QAbstractAxis* QBarSeriesPrivate::createAxisY(QObject* parent)
616 QAbstractAxis* QBarSeriesPrivate::createAxisY(QObject* parent)
617 {
617 {
618 return new QValuesAxis(parent);
618 return new QValuesAxis(parent);
619 }
619 }
620
620
621 bool QBarSeriesPrivate::append(QBarSet *set)
621 bool QBarSeriesPrivate::append(QBarSet *set)
622 {
622 {
623 Q_Q(QBarSeries);
623 Q_Q(QBarSeries);
624 if ((m_barSets.contains(set)) || (set == 0)) {
624 if ((m_barSets.contains(set)) || (set == 0)) {
625 // Fail if set is already in list or set is null.
625 // Fail if set is already in list or set is null.
626 return false;
626 return false;
627 }
627 }
628 m_barSets.append(set);
628 m_barSets.append(set);
629 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
629 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
630 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
630 QObject::connect(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 QBarSeriesPrivate::remove(QBarSet *set)
638 bool QBarSeriesPrivate::remove(QBarSet *set)
639 {
639 {
640 Q_Q(QBarSeries);
640 Q_Q(QBarSeries);
641 if (!m_barSets.contains(set)) {
641 if (!m_barSets.contains(set)) {
642 // Fail if set is not in list
642 // Fail if set is not in list
643 return false;
643 return false;
644 }
644 }
645 m_barSets.removeOne(set);
645 m_barSets.removeOne(set);
646 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
646 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
647 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
647 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
648 emit restructuredBars(); // this notifies barchartitem
648 emit restructuredBars(); // this notifies barchartitem
649 if (m_dataset) {
649 if (m_dataset) {
650 m_dataset->updateSeries(q); // this notifies legend
650 m_dataset->updateSeries(q); // this notifies legend
651 }
651 }
652 return true;
652 return true;
653 }
653 }
654
654
655 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
655 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
656 {
656 {
657 Q_Q(QBarSeries);
657 Q_Q(QBarSeries);
658 foreach (QBarSet* set, sets) {
658 foreach (QBarSet* set, sets) {
659 if ((set == 0) || (m_barSets.contains(set))) {
659 if ((set == 0) || (m_barSets.contains(set))) {
660 // Fail if any of the sets is null or is already appended.
660 // Fail if any of the sets is null or is already appended.
661 return false;
661 return false;
662 }
662 }
663 if (sets.count(set) != 1) {
663 if (sets.count(set) != 1) {
664 // Also fail if same set is more than once in given list.
664 // Also fail if same set is more than once in given list.
665 return false;
665 return false;
666 }
666 }
667 }
667 }
668
668
669 foreach (QBarSet* set, sets) {
669 foreach (QBarSet* set, sets) {
670 m_barSets.append(set);
670 m_barSets.append(set);
671 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
671 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
672 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
672 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
673 }
673 }
674 emit restructuredBars(); // this notifies barchartitem
674 emit restructuredBars(); // this notifies barchartitem
675 if (m_dataset) {
675 if (m_dataset) {
676 m_dataset->updateSeries(q); // this notifies legend
676 m_dataset->updateSeries(q); // this notifies legend
677 }
677 }
678 return true;
678 return true;
679 }
679 }
680
680
681 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
681 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
682 {
682 {
683 Q_Q(QBarSeries);
683 Q_Q(QBarSeries);
684 if (sets.count() == 0) {
684 if (sets.count() == 0) {
685 return false;
685 return false;
686 }
686 }
687 foreach (QBarSet* set, sets) {
687 foreach (QBarSet* set, sets) {
688 if ((set == 0) || (!m_barSets.contains(set))) {
688 if ((set == 0) || (!m_barSets.contains(set))) {
689 // Fail if any of the sets is null or is not in series
689 // Fail if any of the sets is null or is not in series
690 return false;
690 return false;
691 }
691 }
692 if (sets.count(set) != 1) {
692 if (sets.count(set) != 1) {
693 // Also fail if same set is more than once in given list.
693 // Also fail if same set is more than once in given list.
694 return false;
694 return false;
695 }
695 }
696 }
696 }
697
697
698 foreach (QBarSet* set, sets) {
698 foreach (QBarSet* set, sets) {
699 m_barSets.removeOne(set);
699 m_barSets.removeOne(set);
700 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
700 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
701 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
701 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
702 }
702 }
703
703
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 bool QBarSeriesPrivate::insert(int index, QBarSet *set)
711 bool QBarSeriesPrivate::insert(int index, QBarSet *set)
712 {
712 {
713 Q_Q(QBarSeries);
713 Q_Q(QBarSeries);
714 if ((m_barSets.contains(set)) || (set == 0)) {
714 if ((m_barSets.contains(set)) || (set == 0)) {
715 // Fail if set is already in list or set is null.
715 // Fail if set is already in list or set is null.
716 return false;
716 return false;
717 }
717 }
718 m_barSets.insert(index, set);
718 m_barSets.insert(index, set);
719 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
719 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
720 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
720 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
721 emit restructuredBars(); // this notifies barchartitem
721 emit restructuredBars(); // this notifies barchartitem
722 if (m_dataset) {
722 if (m_dataset) {
723 m_dataset->updateSeries(q); // this notifies legend
723 m_dataset->updateSeries(q); // this notifies legend
724 }
724 }
725 return true;
725 return true;
726 }
726 }
727
727
728 #include "moc_qbarseries.cpp"
728 #include "moc_qbarseries.cpp"
729 #include "moc_qbarseries_p.cpp"
729 #include "moc_qbarseries_p.cpp"
730
730
731 QTCOMMERCIALCHART_END_NAMESPACE
731 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,82 +1,82
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 BARSERIES_H
21 #ifndef BARSERIES_H
22 #define BARSERIES_H
22 #define BARSERIES_H
23
23
24 #include <qabstractseries.h>
24 #include <qabstractseries.h>
25 #include <QStringList>
25 #include <QStringList>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 class QBarSet;
29 class QBarSet;
30 class QBarSeriesPrivate;
30 class QBarSeriesPrivate;
31
31
32 // Container for series
32 // Container for series
33 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries
33 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth)
36 Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth)
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
38 Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
38 Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
39
39
40 public:
40 public:
41 explicit QBarSeries(QObject *parent = 0);
41 explicit QBarSeries(QObject *parent = 0);
42 virtual ~QBarSeries();
42 virtual ~QBarSeries();
43
43
44 QAbstractSeries::SeriesType type() const;
44 QAbstractSeries::SeriesType type() const;
45
45
46 void setBarWidth(qreal width);
46 void setBarWidth(qreal width);
47 qreal barWidth() const;
47 qreal barWidth() const;
48
48
49 bool append(QBarSet *set);
49 bool append(QBarSet *set);
50 bool remove(QBarSet *set);
50 bool remove(QBarSet *set);
51 bool append(QList<QBarSet* > sets);
51 bool append(QList<QBarSet* > sets);
52 bool insert(int index, QBarSet *set);
52 bool insert(int index, QBarSet *set);
53 int count() const;
53 int count() const;
54 QList<QBarSet*> barSets() const;
54 QList<QBarSet*> barSets() const;
55 void clear();
55 void clear();
56
56
57 void setLabelsVisible(bool visible = true);
57 void setLabelsVisible(bool visible = true);
58 bool isLabelsVisible() const;
58 bool isLabelsVisible() const;
59
59
60 protected:
60 protected:
61 explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0);
61 explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0);
62
62
63 Q_SIGNALS:
63 Q_SIGNALS:
64 void clicked(QBarSet *barset, int index);
64 void clicked(int index, QBarSet *barset);
65 void hovered(QBarSet* barset, bool status);
65 void hovered(bool status, QBarSet *barset);
66 void countChanged();
66 void countChanged();
67 void labelsVisibleChanged();
67 void labelsVisibleChanged();
68
68
69 void barsetsAdded(QList<QBarSet*> sets);
69 void barsetsAdded(QList<QBarSet*> sets);
70 void barsetsRemoved(QList<QBarSet*> sets);
70 void barsetsRemoved(QList<QBarSet*> sets);
71
71
72 protected:
72 protected:
73 Q_DECLARE_PRIVATE(QBarSeries)
73 Q_DECLARE_PRIVATE(QBarSeries)
74 friend class BarChartItem;
74 friend class BarChartItem;
75 friend class PercentBarChartItem;
75 friend class PercentBarChartItem;
76 friend class StackedBarChartItem;
76 friend class StackedBarChartItem;
77 friend class GroupedBarChartItem;
77 friend class GroupedBarChartItem;
78 };
78 };
79
79
80 QTCOMMERCIALCHART_END_NAMESPACE
80 QTCOMMERCIALCHART_END_NAMESPACE
81
81
82 #endif // BARSERIES_H
82 #endif // BARSERIES_H
@@ -1,97 +1,97
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 QBARSERIES_P_H
30 #ifndef QBARSERIES_P_H
31 #define QBARSERIES_P_H
31 #define QBARSERIES_P_H
32
32
33 #include "qbarseries.h"
33 #include "qbarseries.h"
34 #include "qabstractseries_p.h"
34 #include "qabstractseries_p.h"
35 #include <QStringList>
35 #include <QStringList>
36 #include <QAbstractSeries>
36 #include <QAbstractSeries>
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class QBarModelMapper;
40 class QBarModelMapper;
41
41
42 class QBarSeriesPrivate : public QAbstractSeriesPrivate
42 class QBarSeriesPrivate : public QAbstractSeriesPrivate
43 {
43 {
44 Q_OBJECT
44 Q_OBJECT
45 public:
45 public:
46 QBarSeriesPrivate(QBarSeries *parent);
46 QBarSeriesPrivate(QBarSeries *parent);
47 int categoryCount() const;
47 int categoryCount() const;
48
48
49 void setBarWidth(qreal width);
49 void setBarWidth(qreal width);
50 qreal barWidth() const;
50 qreal barWidth() const;
51
51
52 void setVisible(bool visible);
52 void setVisible(bool visible);
53 void setLabelsVisible(bool visible);
53 void setLabelsVisible(bool visible);
54
54
55 void scaleDomain(Domain& domain);
55 void scaleDomain(Domain& domain);
56 Chart* createGraphics(ChartPresenter* presenter);
56 Chart* createGraphics(ChartPresenter* presenter);
57 QList<LegendMarker*> createLegendMarker(QLegend* legend);
57 QList<LegendMarker*> createLegendMarker(QLegend* legend);
58
58
59 QAbstractAxis* createAxisX(QObject* parent = 0);
59 QAbstractAxis* createAxisX(QObject* parent = 0);
60 QAbstractAxis* createAxisY(QObject* parent = 0);
60 QAbstractAxis* createAxisY(QObject* parent = 0);
61
61
62 bool append(QBarSet *set);
62 bool append(QBarSet *set);
63 bool remove(QBarSet *set);
63 bool remove(QBarSet *set);
64 bool append(QList<QBarSet* > sets);
64 bool append(QList<QBarSet* > sets);
65 bool remove(QList<QBarSet* > sets);
65 bool remove(QList<QBarSet* > sets);
66 bool insert(int index, QBarSet *set);
66 bool insert(int index, QBarSet *set);
67
67
68 QBarSet* barsetAt(int index);
68 QBarSet* barsetAt(int index);
69 qreal min();
69 qreal min();
70 qreal max();
70 qreal max();
71 qreal valueAt(int set, int category);
71 qreal valueAt(int set, int category);
72 qreal percentageAt(int set, int category);
72 qreal percentageAt(int set, int category);
73 qreal categorySum(int category);
73 qreal categorySum(int category);
74 qreal absoluteCategorySum(int category);
74 qreal absoluteCategorySum(int category);
75 qreal maxCategorySum();
75 qreal maxCategorySum();
76 qreal minX();
76 qreal minX();
77 qreal maxX();
77 qreal maxX();
78
78
79 Q_SIGNALS:
79 Q_SIGNALS:
80 void clicked(QBarSet *barset, int index);
80 void clicked(int index, QBarSet *barset);
81 void updatedBars();
81 void updatedBars();
82 void restructuredBars();
82 void restructuredBars();
83 void labelsVisibleChanged(bool visible);
83 void labelsVisibleChanged(bool visible);
84
84
85 protected:
85 protected:
86 QList<QBarSet *> m_barSets;
86 QList<QBarSet *> m_barSets;
87 qreal m_barWidth;
87 qreal m_barWidth;
88 bool m_labelsVisible;
88 bool m_labelsVisible;
89 bool m_visible;
89 bool m_visible;
90
90
91 private:
91 private:
92 Q_DECLARE_PUBLIC(QBarSeries)
92 Q_DECLARE_PUBLIC(QBarSeries)
93 };
93 };
94
94
95 QTCOMMERCIALCHART_END_NAMESPACE
95 QTCOMMERCIALCHART_END_NAMESPACE
96
96
97 #endif // QBARSERIESPRIVATE_P_H
97 #endif // QBARSERIESPRIVATE_P_H
@@ -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 <qbarseries.h>
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 QBarSeries* m_barseries;
66 QBarSeries* m_barseries;
67 QBarSeries* m_barseries_with_sets;
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 QBarSeries();
84 m_barseries = new QBarSeries();
85 m_barseries_with_sets = new QBarSeries();
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 QBarSeries *barseries = new QBarSeries();
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 QBarSeries* series = new QBarSeries();
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 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10);
322 *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,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 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
326 *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
327 series->append(set2);
327 series->append(set2);
328
328
329 QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,int)));
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(0)), set1);
349 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
350 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
350 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
351 QVERIFY(seriesSpyArg.at(1).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(0)), set1);
367 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
368 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
368 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
369 QVERIFY(seriesSpyArg.at(1).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(0)), set1);
385 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
386 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
386 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
387 QVERIFY(seriesSpyArg.at(1).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(0)), set2);
403 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
404 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
404 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
405 QVERIFY(seriesSpyArg.at(1).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(0)), set2);
421 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
422 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
422 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
423 QVERIFY(seriesSpyArg.at(1).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(0)), set2);
439 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
440 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
440 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
441 QVERIFY(seriesSpyArg.at(1).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 QBarSeries* series = new QBarSeries();
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 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10);
458 *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,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 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
462 *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
463 series->append(set2);
463 series->append(set2);
464
464
465 QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool)));
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(0)), set1);
494 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
495 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
495 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
496 QVERIFY(seriesSpyArg.at(1).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(0)), set1);
511 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
512 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
512 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
513 QVERIFY(seriesSpyArg.at(1).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(0)), set2);
521 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
522 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
522 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
523 QVERIFY(seriesSpyArg.at(1).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(0)), set2);
538 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
539 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
539 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
540 QVERIFY(seriesSpyArg.at(1).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 QBarSeries* series = new QBarSeries();
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 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10);
552 *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,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 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
556 *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,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,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 <qgroupedbarseries.h>
22 #include <qgroupedbarseries.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 QGroupedBarSeries* m_barseries;
55 QGroupedBarSeries* 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 QGroupedBarSeries();
69 m_barseries = new QGroupedBarSeries();
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 QGroupedBarSeries *barseries = new QGroupedBarSeries();
84 QGroupedBarSeries *barseries = new QGroupedBarSeries();
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 QGroupedBarSeries* series = new QGroupedBarSeries();
105 QGroupedBarSeries* series = new QGroupedBarSeries();
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(QBarSet*,int)));
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(0)), set1);
131 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
132 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
132 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
133 QVERIFY(seriesSpyArg.at(1).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(0)), set1);
143 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
144 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
144 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
145 QVERIFY(seriesSpyArg.at(1).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(0)), set1);
155 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
156 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
156 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
157 QVERIFY(seriesSpyArg.at(1).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(0)), set2);
167 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
168 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
168 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
169 QVERIFY(seriesSpyArg.at(1).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(0)), set2);
179 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
180 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
180 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
181 QVERIFY(seriesSpyArg.at(1).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(0)), set2);
191 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
192 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
192 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
193 QVERIFY(seriesSpyArg.at(1).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 QGroupedBarSeries* series = new QGroupedBarSeries();
203 QGroupedBarSeries* series = new QGroupedBarSeries();
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(QBarSet*,bool)));
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(0)), set1);
238 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
239 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
239 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
240 QVERIFY(seriesSpyArg.at(1).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(0)), set1);
250 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
251 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
251 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
252 QVERIFY(seriesSpyArg.at(1).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(0)), set2);
256 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
257 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
257 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
258 QVERIFY(seriesSpyArg.at(1).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(0)), set2);
269 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
270 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
270 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
271 QVERIFY(seriesSpyArg.at(1).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,270 +1,270
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 <qpercentbarseries.h>
22 #include <qpercentbarseries.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_QPercentBarSeries : public QObject
32 class tst_QPercentBarSeries : 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 qpercentbarseries_data();
43 void qpercentbarseries_data();
44 void qpercentbarseries();
44 void qpercentbarseries();
45 void type_data();
45 void type_data();
46 void type();
46 void type();
47 void mouseclicked_data();
47 void mouseclicked_data();
48 void mouseclicked();
48 void mouseclicked();
49 void mousehovered_data();
49 void mousehovered_data();
50 void mousehovered();
50 void mousehovered();
51
51
52 private:
52 private:
53 QPercentBarSeries* m_barseries;
53 QPercentBarSeries* m_barseries;
54 };
54 };
55
55
56 void tst_QPercentBarSeries::initTestCase()
56 void tst_QPercentBarSeries::initTestCase()
57 {
57 {
58 qRegisterMetaType<QBarSet*>("QBarSet*");
58 qRegisterMetaType<QBarSet*>("QBarSet*");
59 }
59 }
60
60
61 void tst_QPercentBarSeries::cleanupTestCase()
61 void tst_QPercentBarSeries::cleanupTestCase()
62 {
62 {
63 }
63 }
64
64
65 void tst_QPercentBarSeries::init()
65 void tst_QPercentBarSeries::init()
66 {
66 {
67 m_barseries = new QPercentBarSeries();
67 m_barseries = new QPercentBarSeries();
68 }
68 }
69
69
70 void tst_QPercentBarSeries::cleanup()
70 void tst_QPercentBarSeries::cleanup()
71 {
71 {
72 delete m_barseries;
72 delete m_barseries;
73 m_barseries = 0;
73 m_barseries = 0;
74 }
74 }
75
75
76 void tst_QPercentBarSeries::qpercentbarseries_data()
76 void tst_QPercentBarSeries::qpercentbarseries_data()
77 {
77 {
78 }
78 }
79
79
80 void tst_QPercentBarSeries::qpercentbarseries()
80 void tst_QPercentBarSeries::qpercentbarseries()
81 {
81 {
82 QPercentBarSeries *barseries = new QPercentBarSeries();
82 QPercentBarSeries *barseries = new QPercentBarSeries();
83 QVERIFY(barseries != 0);
83 QVERIFY(barseries != 0);
84 }
84 }
85
85
86 void tst_QPercentBarSeries::type_data()
86 void tst_QPercentBarSeries::type_data()
87 {
87 {
88
88
89 }
89 }
90
90
91 void tst_QPercentBarSeries::type()
91 void tst_QPercentBarSeries::type()
92 {
92 {
93 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypePercentBar);
93 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypePercentBar);
94 }
94 }
95
95
96 void tst_QPercentBarSeries::mouseclicked_data()
96 void tst_QPercentBarSeries::mouseclicked_data()
97 {
97 {
98
98
99 }
99 }
100
100
101 void tst_QPercentBarSeries::mouseclicked()
101 void tst_QPercentBarSeries::mouseclicked()
102 {
102 {
103 QPercentBarSeries* series = new QPercentBarSeries();
103 QPercentBarSeries* series = new QPercentBarSeries();
104
104
105 QBarSet* set1 = new QBarSet(QString("set 1"));
105 QBarSet* set1 = new QBarSet(QString("set 1"));
106 *set1 << 10 << 10 << 10;
106 *set1 << 10 << 10 << 10;
107 series->append(set1);
107 series->append(set1);
108
108
109 QBarSet* set2 = new QBarSet(QString("set 2"));
109 QBarSet* set2 = new QBarSet(QString("set 2"));
110 *set2 << 10 << 10 << 10;
110 *set2 << 10 << 10 << 10;
111 series->append(set2);
111 series->append(set2);
112
112
113 QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,int)));
113 QSignalSpy seriesSpy(series,SIGNAL(clicked(int, QBarSet*)));
114
114
115 QChartView view(new QChart());
115 QChartView view(new QChart());
116 view.resize(400,300);
116 view.resize(400,300);
117 view.chart()->addSeries(series);
117 view.chart()->addSeries(series);
118 view.show();
118 view.show();
119 QTest::qWaitForWindowShown(&view);
119 QTest::qWaitForWindowShown(&view);
120
120
121 //====================================================================================
121 //====================================================================================
122 // barset 1, category test1
122 // barset 1, category test1
123 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,190));
123 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,190));
124 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
124 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
125
125
126 QCOMPARE(seriesSpy.count(), 1);
126 QCOMPARE(seriesSpy.count(), 1);
127
127
128 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
128 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
129 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
129 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
130 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
130 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
131 QVERIFY(seriesSpyArg.at(1).toInt() == 0);
131 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
132
132
133 //====================================================================================
133 //====================================================================================
134 // barset 1, category test2
134 // barset 1, category test2
135 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,190));
135 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,190));
136 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
136 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
137
137
138 QCOMPARE(seriesSpy.count(), 1);
138 QCOMPARE(seriesSpy.count(), 1);
139
139
140 seriesSpyArg = seriesSpy.takeFirst();
140 seriesSpyArg = seriesSpy.takeFirst();
141 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
141 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
142 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
142 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
143 QVERIFY(seriesSpyArg.at(1).toInt() == 1);
143 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
144
144
145 //====================================================================================
145 //====================================================================================
146 // barset 1, category test3
146 // barset 1, category test3
147 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(292,190));
147 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(292,190));
148 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
148 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
149
149
150 QCOMPARE(seriesSpy.count(), 1);
150 QCOMPARE(seriesSpy.count(), 1);
151
151
152 seriesSpyArg = seriesSpy.takeFirst();
152 seriesSpyArg = seriesSpy.takeFirst();
153 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
153 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
154 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
154 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
155 QVERIFY(seriesSpyArg.at(1).toInt() == 2);
155 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
156
156
157 //====================================================================================
157 //====================================================================================
158 // barset 2, category test1
158 // barset 2, category test1
159 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,95));
159 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,95));
160 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
160 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
161
161
162 QCOMPARE(seriesSpy.count(), 1);
162 QCOMPARE(seriesSpy.count(), 1);
163
163
164 seriesSpyArg = seriesSpy.takeFirst();
164 seriesSpyArg = seriesSpy.takeFirst();
165 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
165 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
166 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
166 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
167 QVERIFY(seriesSpyArg.at(1).toInt() == 0);
167 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
168
168
169 //====================================================================================
169 //====================================================================================
170 // barset 2, category test2
170 // barset 2, category test2
171 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,95));
171 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,95));
172 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
172 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
173
173
174 QCOMPARE(seriesSpy.count(), 1);
174 QCOMPARE(seriesSpy.count(), 1);
175
175
176 seriesSpyArg = seriesSpy.takeFirst();
176 seriesSpyArg = seriesSpy.takeFirst();
177 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
177 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
178 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
178 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
179 QVERIFY(seriesSpyArg.at(1).toInt() == 1);
179 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
180
180
181 //====================================================================================
181 //====================================================================================
182 // barset 2, category test3
182 // barset 2, category test3
183 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(292,95));
183 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(292,95));
184 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
184 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
185
185
186 QCOMPARE(seriesSpy.count(), 1);
186 QCOMPARE(seriesSpy.count(), 1);
187
187
188 seriesSpyArg = seriesSpy.takeFirst();
188 seriesSpyArg = seriesSpy.takeFirst();
189 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
189 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
190 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
190 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
191 QVERIFY(seriesSpyArg.at(1).toInt() == 2);
191 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
192 }
192 }
193
193
194 void tst_QPercentBarSeries::mousehovered_data()
194 void tst_QPercentBarSeries::mousehovered_data()
195 {
195 {
196
196
197 }
197 }
198
198
199 void tst_QPercentBarSeries::mousehovered()
199 void tst_QPercentBarSeries::mousehovered()
200 {
200 {
201 QPercentBarSeries* series = new QPercentBarSeries();
201 QPercentBarSeries* series = new QPercentBarSeries();
202
202
203 QBarSet* set1 = new QBarSet(QString("set 1"));
203 QBarSet* set1 = new QBarSet(QString("set 1"));
204 *set1 << 10 << 10 << 10;
204 *set1 << 10 << 10 << 10;
205 series->append(set1);
205 series->append(set1);
206
206
207 QBarSet* set2 = new QBarSet(QString("set 2"));
207 QBarSet* set2 = new QBarSet(QString("set 2"));
208 *set2 << 10 << 10 << 10;
208 *set2 << 10 << 10 << 10;
209 series->append(set2);
209 series->append(set2);
210
210
211 QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool)));
211 QSignalSpy seriesSpy(series,SIGNAL(hovered(bool, QBarSet*)));
212
212
213 QChartView view(new QChart());
213 QChartView view(new QChart());
214 view.resize(400,300);
214 view.resize(400,300);
215 view.chart()->addSeries(series);
215 view.chart()->addSeries(series);
216 view.show();
216 view.show();
217 QTest::qWaitForWindowShown(&view);
217 QTest::qWaitForWindowShown(&view);
218
218
219 //this is hack since view does not get events otherwise
219 //this is hack since view does not get events otherwise
220 view.setMouseTracking(true);
220 view.setMouseTracking(true);
221
221
222 //=======================================================================
222 //=======================================================================
223 // move mouse to left border
223 // move mouse to left border
224 QTest::mouseMove(view.viewport(), QPoint(0, 190));
224 QTest::mouseMove(view.viewport(), QPoint(0, 190));
225 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
225 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
226 TRY_COMPARE(seriesSpy.count(), 0);
226 TRY_COMPARE(seriesSpy.count(), 0);
227
227
228 //=======================================================================
228 //=======================================================================
229 // move mouse on top of set1
229 // move mouse on top of set1
230 QTest::mouseMove(view.viewport(), QPoint(106,190));
230 QTest::mouseMove(view.viewport(), QPoint(106,190));
231 TRY_COMPARE(seriesSpy.count(), 1);
231 TRY_COMPARE(seriesSpy.count(), 1);
232
232
233 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
233 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
234 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
234 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
235 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
235 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
236 QVERIFY(seriesSpyArg.at(1).toBool() == true);
236 QVERIFY(seriesSpyArg.at(0).toBool() == true);
237
237
238 //=======================================================================
238 //=======================================================================
239 // move mouse from top of set1 to top of set2
239 // move mouse from top of set1 to top of set2
240 QTest::mouseMove(view.viewport(), QPoint(106,95));
240 QTest::mouseMove(view.viewport(), QPoint(106,95));
241 TRY_COMPARE(seriesSpy.count(), 2);
241 TRY_COMPARE(seriesSpy.count(), 2);
242
242
243 // should leave set1
243 // should leave set1
244 seriesSpyArg = seriesSpy.takeFirst();
244 seriesSpyArg = seriesSpy.takeFirst();
245 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
245 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
246 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
246 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
247 QVERIFY(seriesSpyArg.at(1).toBool() == false);
247 QVERIFY(seriesSpyArg.at(0).toBool() == false);
248
248
249 // should enter set2
249 // should enter set2
250 seriesSpyArg = seriesSpy.takeFirst();
250 seriesSpyArg = seriesSpy.takeFirst();
251 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
251 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
252 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
252 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
253 QVERIFY(seriesSpyArg.at(1).toBool() == true);
253 QVERIFY(seriesSpyArg.at(0).toBool() == true);
254
254
255 //=======================================================================
255 //=======================================================================
256 // move mouse from top of set2 to background
256 // move mouse from top of set2 to background
257 QTest::mouseMove(view.viewport(), QPoint(106,0));
257 QTest::mouseMove(view.viewport(), QPoint(106,0));
258 TRY_COMPARE(seriesSpy.count(), 1);
258 TRY_COMPARE(seriesSpy.count(), 1);
259
259
260 // should leave set2
260 // should leave set2
261 seriesSpyArg = seriesSpy.takeFirst();
261 seriesSpyArg = seriesSpy.takeFirst();
262 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
262 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
263 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
263 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
264 QVERIFY(seriesSpyArg.at(1).toBool() == false);
264 QVERIFY(seriesSpyArg.at(0).toBool() == false);
265 }
265 }
266
266
267 QTEST_MAIN(tst_QPercentBarSeries)
267 QTEST_MAIN(tst_QPercentBarSeries)
268
268
269 #include "tst_qpercentbarseries.moc"
269 #include "tst_qpercentbarseries.moc"
270
270
@@ -1,270 +1,270
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 <qstackedbarseries.h>
22 #include <qstackedbarseries.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_QStackedBarSeries : public QObject
32 class tst_QStackedBarSeries : 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 qstackedbarseries_data();
43 void qstackedbarseries_data();
44 void qstackedbarseries();
44 void qstackedbarseries();
45 void type_data();
45 void type_data();
46 void type();
46 void type();
47 void mouseclicked_data();
47 void mouseclicked_data();
48 void mouseclicked();
48 void mouseclicked();
49 void mousehovered_data();
49 void mousehovered_data();
50 void mousehovered();
50 void mousehovered();
51
51
52 private:
52 private:
53 QStackedBarSeries* m_barseries;
53 QStackedBarSeries* m_barseries;
54 };
54 };
55
55
56 void tst_QStackedBarSeries::initTestCase()
56 void tst_QStackedBarSeries::initTestCase()
57 {
57 {
58 qRegisterMetaType<QBarSet*>("QBarSet*");
58 qRegisterMetaType<QBarSet*>("QBarSet*");
59 }
59 }
60
60
61 void tst_QStackedBarSeries::cleanupTestCase()
61 void tst_QStackedBarSeries::cleanupTestCase()
62 {
62 {
63 }
63 }
64
64
65 void tst_QStackedBarSeries::init()
65 void tst_QStackedBarSeries::init()
66 {
66 {
67 m_barseries = new QStackedBarSeries();
67 m_barseries = new QStackedBarSeries();
68 }
68 }
69
69
70 void tst_QStackedBarSeries::cleanup()
70 void tst_QStackedBarSeries::cleanup()
71 {
71 {
72 delete m_barseries;
72 delete m_barseries;
73 m_barseries = 0;
73 m_barseries = 0;
74 }
74 }
75
75
76 void tst_QStackedBarSeries::qstackedbarseries_data()
76 void tst_QStackedBarSeries::qstackedbarseries_data()
77 {
77 {
78 }
78 }
79
79
80 void tst_QStackedBarSeries::qstackedbarseries()
80 void tst_QStackedBarSeries::qstackedbarseries()
81 {
81 {
82 QStackedBarSeries *barseries = new QStackedBarSeries();
82 QStackedBarSeries *barseries = new QStackedBarSeries();
83 QVERIFY(barseries != 0);
83 QVERIFY(barseries != 0);
84 }
84 }
85
85
86 void tst_QStackedBarSeries::type_data()
86 void tst_QStackedBarSeries::type_data()
87 {
87 {
88
88
89 }
89 }
90
90
91 void tst_QStackedBarSeries::type()
91 void tst_QStackedBarSeries::type()
92 {
92 {
93 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeStackedBar);
93 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeStackedBar);
94 }
94 }
95
95
96 void tst_QStackedBarSeries::mouseclicked_data()
96 void tst_QStackedBarSeries::mouseclicked_data()
97 {
97 {
98
98
99 }
99 }
100
100
101 void tst_QStackedBarSeries::mouseclicked()
101 void tst_QStackedBarSeries::mouseclicked()
102 {
102 {
103 QStackedBarSeries* series = new QStackedBarSeries();
103 QStackedBarSeries* series = new QStackedBarSeries();
104
104
105 QBarSet* set1 = new QBarSet(QString("set 1"));
105 QBarSet* set1 = new QBarSet(QString("set 1"));
106 *set1 << 10 << 10 << 10;
106 *set1 << 10 << 10 << 10;
107 series->append(set1);
107 series->append(set1);
108
108
109 QBarSet* set2 = new QBarSet(QString("set 2"));
109 QBarSet* set2 = new QBarSet(QString("set 2"));
110 *set2 << 10 << 10 << 10;
110 *set2 << 10 << 10 << 10;
111 series->append(set2);
111 series->append(set2);
112
112
113 QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,int)));
113 QSignalSpy seriesSpy(series,SIGNAL(clicked(int, QBarSet*)));
114
114
115 QChartView view(new QChart());
115 QChartView view(new QChart());
116 view.resize(400,300);
116 view.resize(400,300);
117 view.chart()->addSeries(series);
117 view.chart()->addSeries(series);
118 view.show();
118 view.show();
119 QTest::qWaitForWindowShown(&view);
119 QTest::qWaitForWindowShown(&view);
120
120
121 //====================================================================================
121 //====================================================================================
122 // barset 1, category test1
122 // barset 1, category test1
123 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,190));
123 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,190));
124 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
124 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
125
125
126 QCOMPARE(seriesSpy.count(), 1);
126 QCOMPARE(seriesSpy.count(), 1);
127
127
128 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
128 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
129 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
129 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
130 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
130 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
131 QVERIFY(seriesSpyArg.at(1).toInt() == 0);
131 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
132
132
133 //====================================================================================
133 //====================================================================================
134 // barset 1, category test2
134 // barset 1, category test2
135 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,190));
135 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,190));
136 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
136 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
137
137
138 QCOMPARE(seriesSpy.count(), 1);
138 QCOMPARE(seriesSpy.count(), 1);
139
139
140 seriesSpyArg = seriesSpy.takeFirst();
140 seriesSpyArg = seriesSpy.takeFirst();
141 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
141 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
142 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
142 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
143 QVERIFY(seriesSpyArg.at(1).toInt() == 1);
143 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
144
144
145 //====================================================================================
145 //====================================================================================
146 // barset 1, category test3
146 // barset 1, category test3
147 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(292,190));
147 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(292,190));
148 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
148 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
149
149
150 QCOMPARE(seriesSpy.count(), 1);
150 QCOMPARE(seriesSpy.count(), 1);
151
151
152 seriesSpyArg = seriesSpy.takeFirst();
152 seriesSpyArg = seriesSpy.takeFirst();
153 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
153 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
154 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
154 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
155 QVERIFY(seriesSpyArg.at(1).toInt() == 2);
155 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
156
156
157 //====================================================================================
157 //====================================================================================
158 // barset 2, category test1
158 // barset 2, category test1
159 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,95));
159 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,95));
160 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
160 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
161
161
162 QCOMPARE(seriesSpy.count(), 1);
162 QCOMPARE(seriesSpy.count(), 1);
163
163
164 seriesSpyArg = seriesSpy.takeFirst();
164 seriesSpyArg = seriesSpy.takeFirst();
165 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
165 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
166 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
166 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
167 QVERIFY(seriesSpyArg.at(1).toInt() == 0);
167 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
168
168
169 //====================================================================================
169 //====================================================================================
170 // barset 2, category test2
170 // barset 2, category test2
171 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,95));
171 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,95));
172 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
172 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
173
173
174 QCOMPARE(seriesSpy.count(), 1);
174 QCOMPARE(seriesSpy.count(), 1);
175
175
176 seriesSpyArg = seriesSpy.takeFirst();
176 seriesSpyArg = seriesSpy.takeFirst();
177 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
177 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
178 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
178 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
179 QVERIFY(seriesSpyArg.at(1).toInt() == 1);
179 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
180
180
181 //====================================================================================
181 //====================================================================================
182 // barset 2, category test3
182 // barset 2, category test3
183 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(292,95));
183 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(292,95));
184 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
184 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
185
185
186 QCOMPARE(seriesSpy.count(), 1);
186 QCOMPARE(seriesSpy.count(), 1);
187
187
188 seriesSpyArg = seriesSpy.takeFirst();
188 seriesSpyArg = seriesSpy.takeFirst();
189 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
189 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
190 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
190 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
191 QVERIFY(seriesSpyArg.at(1).toInt() == 2);
191 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
192 }
192 }
193
193
194 void tst_QStackedBarSeries::mousehovered_data()
194 void tst_QStackedBarSeries::mousehovered_data()
195 {
195 {
196
196
197 }
197 }
198
198
199 void tst_QStackedBarSeries::mousehovered()
199 void tst_QStackedBarSeries::mousehovered()
200 {
200 {
201 QStackedBarSeries* series = new QStackedBarSeries();
201 QStackedBarSeries* series = new QStackedBarSeries();
202
202
203 QBarSet* set1 = new QBarSet(QString("set 1"));
203 QBarSet* set1 = new QBarSet(QString("set 1"));
204 *set1 << 10 << 10 << 10;
204 *set1 << 10 << 10 << 10;
205 series->append(set1);
205 series->append(set1);
206
206
207 QBarSet* set2 = new QBarSet(QString("set 2"));
207 QBarSet* set2 = new QBarSet(QString("set 2"));
208 *set2 << 10 << 10 << 10;
208 *set2 << 10 << 10 << 10;
209 series->append(set2);
209 series->append(set2);
210
210
211 QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool)));
211 QSignalSpy seriesSpy(series,SIGNAL(hovered(bool, QBarSet*)));
212
212
213 QChartView view(new QChart());
213 QChartView view(new QChart());
214 view.resize(400,300);
214 view.resize(400,300);
215 view.chart()->addSeries(series);
215 view.chart()->addSeries(series);
216 view.show();
216 view.show();
217 QTest::qWaitForWindowShown(&view);
217 QTest::qWaitForWindowShown(&view);
218
218
219 //this is hack since view does not get events otherwise
219 //this is hack since view does not get events otherwise
220 view.setMouseTracking(true);
220 view.setMouseTracking(true);
221
221
222 //=======================================================================
222 //=======================================================================
223 // move mouse to left border
223 // move mouse to left border
224 QTest::mouseMove(view.viewport(), QPoint(0, 190));
224 QTest::mouseMove(view.viewport(), QPoint(0, 190));
225 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
225 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
226 TRY_COMPARE(seriesSpy.count(), 0);
226 TRY_COMPARE(seriesSpy.count(), 0);
227
227
228 //=======================================================================
228 //=======================================================================
229 // move mouse on top of set1
229 // move mouse on top of set1
230 QTest::mouseMove(view.viewport(), QPoint(106,190));
230 QTest::mouseMove(view.viewport(), QPoint(106,190));
231 TRY_COMPARE(seriesSpy.count(), 1);
231 TRY_COMPARE(seriesSpy.count(), 1);
232
232
233 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
233 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
234 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
234 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
235 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
235 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
236 QVERIFY(seriesSpyArg.at(1).toBool() == true);
236 QVERIFY(seriesSpyArg.at(0).toBool() == true);
237
237
238 //=======================================================================
238 //=======================================================================
239 // move mouse from top of set1 to top of set2
239 // move mouse from top of set1 to top of set2
240 QTest::mouseMove(view.viewport(), QPoint(106,95));
240 QTest::mouseMove(view.viewport(), QPoint(106,95));
241 TRY_COMPARE(seriesSpy.count(), 2);
241 TRY_COMPARE(seriesSpy.count(), 2);
242
242
243 // should leave set1
243 // should leave set1
244 seriesSpyArg = seriesSpy.takeFirst();
244 seriesSpyArg = seriesSpy.takeFirst();
245 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
245 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
246 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
246 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
247 QVERIFY(seriesSpyArg.at(1).toBool() == false);
247 QVERIFY(seriesSpyArg.at(0).toBool() == false);
248
248
249 // should enter set2
249 // should enter set2
250 seriesSpyArg = seriesSpy.takeFirst();
250 seriesSpyArg = seriesSpy.takeFirst();
251 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
251 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
252 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
252 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
253 QVERIFY(seriesSpyArg.at(1).toBool() == true);
253 QVERIFY(seriesSpyArg.at(0).toBool() == true);
254
254
255 //=======================================================================
255 //=======================================================================
256 // move mouse from top of set2 to background
256 // move mouse from top of set2 to background
257 QTest::mouseMove(view.viewport(), QPoint(106,0));
257 QTest::mouseMove(view.viewport(), QPoint(106,0));
258 TRY_COMPARE(seriesSpy.count(), 1);
258 TRY_COMPARE(seriesSpy.count(), 1);
259
259
260 // should leave set2
260 // should leave set2
261 seriesSpyArg = seriesSpy.takeFirst();
261 seriesSpyArg = seriesSpy.takeFirst();
262 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
262 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
263 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
263 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
264 QVERIFY(seriesSpyArg.at(1).toBool() == false);
264 QVERIFY(seriesSpyArg.at(0).toBool() == false);
265 }
265 }
266
266
267 QTEST_MAIN(tst_QStackedBarSeries)
267 QTEST_MAIN(tst_QStackedBarSeries)
268
268
269 #include "tst_qstackedbarseries.moc"
269 #include "tst_qstackedbarseries.moc"
270
270
General Comments 0
You need to be logged in to leave comments. Login now