##// END OF EJS Templates
enable axis layout changes again
sauimone -
r1386:47613a850965
parent child
Show More
@@ -1,112 +1,112
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartaxisx_p.h"
21 #include "chartaxisx_p.h"
22 #include "qaxis.h"
22 #include "qaxis.h"
23 #include "qaxis_p.h"
23 #include "qaxis_p.h"
24 #include "qaxiscategories_p.h"
24 #include "qaxiscategories_p.h"
25 #include "chartpresenter_p.h"
25 #include "chartpresenter_p.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27
27
28 static int label_padding = 5;
28 static int label_padding = 5;
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 ChartAxisX::ChartAxisX(QAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
32 ChartAxisX::ChartAxisX(QAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
33 {
33 {
34 }
34 }
35
35
36 ChartAxisX::~ChartAxisX()
36 ChartAxisX::~ChartAxisX()
37 {
37 {
38 }
38 }
39
39
40 QVector<qreal> ChartAxisX::calculateLayout() const
40 QVector<qreal> ChartAxisX::calculateLayout() const
41 {
41 {
42 Q_ASSERT(m_ticksCount>=2);
42 Q_ASSERT(m_ticksCount>=2);
43
43
44 QVector<qreal> points;
44 QVector<qreal> points;
45 points.resize(m_ticksCount);
45 points.resize(m_ticksCount);
46
46
47 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
47 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
48 for (int i = 0; i < m_ticksCount; ++i) {
48 for (int i = 0; i < m_ticksCount; ++i) {
49 int x = i * deltaX + m_rect.left();
49 int x = i * deltaX + m_rect.left();
50 points[i] = x;
50 points[i] = x;
51 }
51 }
52 return points;
52 return points;
53 }
53 }
54
54
55 void ChartAxisX::updateGeometry()
55 void ChartAxisX::updateGeometry()
56 {
56 {
57 const QVector<qreal>& layout = ChartAxis::layout();
57 const QVector<qreal>& layout = ChartAxis::layout();
58
58
59 QStringList ticksList;
59 QStringList ticksList;
60
60
61 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
61 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
62
62
63 QList<QGraphicsItem *> lines = m_grid->childItems();
63 QList<QGraphicsItem *> lines = m_grid->childItems();
64 QList<QGraphicsItem *> labels = m_labels->childItems();
64 QList<QGraphicsItem *> labels = m_labels->childItems();
65 QList<QGraphicsItem *> shades = m_shades->childItems();
65 QList<QGraphicsItem *> shades = m_shades->childItems();
66 QList<QGraphicsItem *> axis = m_axis->childItems();
66 QList<QGraphicsItem *> axis = m_axis->childItems();
67
67
68 Q_ASSERT(labels.size() == ticksList.size());
68 Q_ASSERT(labels.size() == ticksList.size());
69 Q_ASSERT(layout.size() == ticksList.size());
69 Q_ASSERT(layout.size() == ticksList.size());
70
70
71 qreal minWidth = 0;
71 qreal minWidth = 0;
72 qreal minHeight = 0;
72 qreal minHeight = 0;
73
73
74 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
74 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
75 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
75 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
76
76
77 for (int i = 0; i < layout.size(); ++i) {
77 for (int i = 0; i < layout.size(); ++i) {
78 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
78 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
79 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
79 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
80 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
80 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
81 if (!categories || i<1) {
81 if (!categories || i<1) {
82 labelItem->setText(ticksList.at(i));
82 labelItem->setText(ticksList.at(i));
83 const QRectF& rect = labelItem->boundingRect();
83 const QRectF& rect = labelItem->boundingRect();
84 minWidth+=rect.width();
84 minWidth+=rect.width();
85 minHeight=qMax(rect.height(),minHeight);
85 minHeight=qMax(rect.height(),minHeight);
86 QPointF center = rect.center();
86 QPointF center = rect.center();
87 labelItem->setTransformOriginPoint(center.x(), center.y());
87 labelItem->setTransformOriginPoint(center.x(), center.y());
88 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
88 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
89 }
89 }
90 else {
90 else {
91 labelItem->setText(ticksList.at(i));
91 labelItem->setText(ticksList.at(i));
92 const QRectF& rect = labelItem->boundingRect();
92 const QRectF& rect = labelItem->boundingRect();
93 minWidth+=rect.width();
93 minWidth+=rect.width();
94 minHeight=qMax(rect.height()+label_padding,minHeight);
94 minHeight=qMax(rect.height()+label_padding,minHeight);
95 QPointF center = rect.center();
95 QPointF center = rect.center();
96 labelItem->setTransformOriginPoint(center.x(), center.y());
96 labelItem->setTransformOriginPoint(center.x(), center.y());
97 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
97 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
98 }
98 }
99
99
100 if ((i+1)%2 && i>1) {
100 if ((i+1)%2 && i>1) {
101 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
101 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
102 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
102 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
103 }
103 }
104 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
104 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
105 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
105 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
106 }
106 }
107
107
108 //presenter()->setMinimumMarginWidth(this,minWidth);
108 presenter()->setMinimumMarginWidth(this,minWidth);
109 //presenter()->setMinimumMarginHeight(this,minHeight);
109 presenter()->setMinimumMarginHeight(this,minHeight);
110 }
110 }
111
111
112 QTCOMMERCIALCHART_END_NAMESPACE
112 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,116 +1,116
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 "chartaxisy_p.h"
21 #include "chartaxisy_p.h"
22 #include "qaxis.h"
22 #include "qaxis.h"
23 #include "qaxis_p.h"
23 #include "qaxis_p.h"
24 #include "qaxiscategories_p.h"
24 #include "qaxiscategories_p.h"
25 #include "chartpresenter_p.h"
25 #include "chartpresenter_p.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27
27
28
28
29 static int label_padding = 5;
29 static int label_padding = 5;
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 ChartAxisY::ChartAxisY(QAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
33 ChartAxisY::ChartAxisY(QAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
34 {
34 {
35 }
35 }
36
36
37 ChartAxisY::~ChartAxisY()
37 ChartAxisY::~ChartAxisY()
38 {
38 {
39 }
39 }
40
40
41 QVector<qreal> ChartAxisY::calculateLayout() const
41 QVector<qreal> ChartAxisY::calculateLayout() const
42 {
42 {
43 Q_ASSERT(m_ticksCount>=2);
43 Q_ASSERT(m_ticksCount>=2);
44
44
45 QVector<qreal> points;
45 QVector<qreal> points;
46 points.resize(m_ticksCount);
46 points.resize(m_ticksCount);
47
47
48 const qreal deltaY = m_rect.height()/(m_ticksCount-1);
48 const qreal deltaY = m_rect.height()/(m_ticksCount-1);
49 for (int i = 0; i < m_ticksCount; ++i) {
49 for (int i = 0; i < m_ticksCount; ++i) {
50 int y = i * -deltaY + m_rect.bottom();
50 int y = i * -deltaY + m_rect.bottom();
51 points[i] = y;
51 points[i] = y;
52 }
52 }
53
53
54 return points;
54 return points;
55 }
55 }
56
56
57 void ChartAxisY::updateGeometry()
57 void ChartAxisY::updateGeometry()
58 {
58 {
59 const QVector<qreal> &layout = ChartAxis::layout();
59 const QVector<qreal> &layout = ChartAxis::layout();
60
60
61 QStringList ticksList;
61 QStringList ticksList;
62
62
63 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
63 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
64
64
65 QList<QGraphicsItem *> lines = m_grid->childItems();
65 QList<QGraphicsItem *> lines = m_grid->childItems();
66 QList<QGraphicsItem *> labels = m_labels->childItems();
66 QList<QGraphicsItem *> labels = m_labels->childItems();
67 QList<QGraphicsItem *> shades = m_shades->childItems();
67 QList<QGraphicsItem *> shades = m_shades->childItems();
68 QList<QGraphicsItem *> axis = m_axis->childItems();
68 QList<QGraphicsItem *> axis = m_axis->childItems();
69
69
70 Q_ASSERT(labels.size() == ticksList.size());
70 Q_ASSERT(labels.size() == ticksList.size());
71 Q_ASSERT(layout.size() == ticksList.size());
71 Q_ASSERT(layout.size() == ticksList.size());
72
72
73 qreal minWidth = 0;
73 qreal minWidth = 0;
74 qreal minHeight = 0;
74 qreal minHeight = 0;
75
75
76 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
76 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
77 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
77 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
78
78
79 for (int i = 0; i < layout.size(); ++i) {
79 for (int i = 0; i < layout.size(); ++i) {
80 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
80 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
81 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
81 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
82 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
82 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
83
83
84 if (!categories || i<1) {
84 if (!categories || i<1) {
85 labelItem->setText(ticksList.at(i));
85 labelItem->setText(ticksList.at(i));
86 const QRectF& rect = labelItem->boundingRect();
86 const QRectF& rect = labelItem->boundingRect();
87 minWidth=qMax(rect.width()+label_padding,minWidth);
87 minWidth=qMax(rect.width()+label_padding,minWidth);
88 minHeight+=rect.height();
88 minHeight+=rect.height();
89 QPointF center = rect.center();
89 QPointF center = rect.center();
90 labelItem->setTransformOriginPoint(center.x(), center.y());
90 labelItem->setTransformOriginPoint(center.x(), center.y());
91 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y());
91 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y());
92 }
92 }
93 else {
93 else {
94 labelItem->setText(ticksList.at(i));
94 labelItem->setText(ticksList.at(i));
95 const QRectF& rect = labelItem->boundingRect();
95 const QRectF& rect = labelItem->boundingRect();
96 minWidth=qMax(rect.width(),minWidth);
96 minWidth=qMax(rect.width(),minWidth);
97 minHeight+=rect.height();
97 minHeight+=rect.height();
98 QPointF center = rect.center();
98 QPointF center = rect.center();
99 labelItem->setTransformOriginPoint(center.x(), center.y());
99 labelItem->setTransformOriginPoint(center.x(), center.y());
100 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y());
100 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y());
101 }
101 }
102
102
103 if ((i+1)%2 && i>1) {
103 if ((i+1)%2 && i>1) {
104 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
104 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
105 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
105 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
106 }
106 }
107 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
107 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
108 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
108 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
109 }
109 }
110
110
111 //presenter()->setMinimumMarginWidth(this,minWidth);
111 presenter()->setMinimumMarginWidth(this,minWidth);
112 //presenter()->setMinimumMarginHeight(this,minHeight);
112 presenter()->setMinimumMarginHeight(this,minHeight);
113
113
114 }
114 }
115
115
116 QTCOMMERCIALCHART_END_NAMESPACE
116 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,514 +1,514
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
26
27 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
28
28
29 Q_DECLARE_METATYPE(QBarSet*)
29 Q_DECLARE_METATYPE(QBarSet*)
30
30
31 class tst_QBarSeries : public QObject
31 class tst_QBarSeries : public QObject
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34
34
35 public slots:
35 public slots:
36 void initTestCase();
36 void initTestCase();
37 void cleanupTestCase();
37 void cleanupTestCase();
38 void init();
38 void init();
39 void cleanup();
39 void cleanup();
40
40
41 private slots:
41 private slots:
42 void qbarseries_data();
42 void qbarseries_data();
43 void qbarseries();
43 void qbarseries();
44 void type_data();
44 void type_data();
45 void type();
45 void type();
46 void append_data();
46 void append_data();
47 void append();
47 void append();
48 void remove_data();
48 void remove_data();
49 void remove();
49 void remove();
50 void appendList_data();
50 void appendList_data();
51 void appendList();
51 void appendList();
52 void barsetCount_data();
52 void barsetCount_data();
53 void barsetCount();
53 void barsetCount();
54 void barSets_data();
54 void barSets_data();
55 void barSets();
55 void barSets();
56 void setLabelsVisible_data();
56 void setLabelsVisible_data();
57 void setLabelsVisible();
57 void setLabelsVisible();
58 void mouseclicked_data();
58 void mouseclicked_data();
59 void mouseclicked();
59 void mouseclicked();
60 void mousehovered_data();
60 void mousehovered_data();
61 void mousehovered();
61 void mousehovered();
62 void clearWithAnimations();
62 void clearWithAnimations();
63
63
64 private:
64 private:
65 QBarSeries* m_barseries;
65 QBarSeries* m_barseries;
66 QBarSeries* m_barseries_with_sets;
66 QBarSeries* m_barseries_with_sets;
67
67
68 QList<QBarSet*> m_testSets;
68 QList<QBarSet*> m_testSets;
69
69
70 };
70 };
71
71
72 void tst_QBarSeries::initTestCase()
72 void tst_QBarSeries::initTestCase()
73 {
73 {
74 qRegisterMetaType<QBarSet*>("QBarSet*");
74 qRegisterMetaType<QBarSet*>("QBarSet*");
75 }
75 }
76
76
77 void tst_QBarSeries::cleanupTestCase()
77 void tst_QBarSeries::cleanupTestCase()
78 {
78 {
79 }
79 }
80
80
81 void tst_QBarSeries::init()
81 void tst_QBarSeries::init()
82 {
82 {
83 m_barseries = new QBarSeries();
83 m_barseries = new QBarSeries();
84 m_barseries_with_sets = new QBarSeries();
84 m_barseries_with_sets = new QBarSeries();
85
85
86 for (int i=0; i<5; i++) {
86 for (int i=0; i<5; i++) {
87 m_testSets.append(new QBarSet("testset"));
87 m_testSets.append(new QBarSet("testset"));
88 m_barseries_with_sets->append(m_testSets.at(i));
88 m_barseries_with_sets->append(m_testSets.at(i));
89 }
89 }
90 }
90 }
91
91
92 void tst_QBarSeries::cleanup()
92 void tst_QBarSeries::cleanup()
93 {
93 {
94 foreach(QBarSet* s, m_testSets) {
94 foreach(QBarSet* s, m_testSets) {
95 m_barseries_with_sets->remove(s);
95 m_barseries_with_sets->remove(s);
96 delete s;
96 delete s;
97 }
97 }
98 m_testSets.clear();
98 m_testSets.clear();
99
99
100 delete m_barseries;
100 delete m_barseries;
101 m_barseries = 0;
101 m_barseries = 0;
102 delete m_barseries_with_sets;
102 delete m_barseries_with_sets;
103 m_barseries_with_sets = 0;
103 m_barseries_with_sets = 0;
104 }
104 }
105
105
106 void tst_QBarSeries::qbarseries_data()
106 void tst_QBarSeries::qbarseries_data()
107 {
107 {
108 }
108 }
109
109
110 void tst_QBarSeries::qbarseries()
110 void tst_QBarSeries::qbarseries()
111 {
111 {
112 QBarSeries *barseries = new QBarSeries();
112 QBarSeries *barseries = new QBarSeries();
113 QVERIFY(barseries != 0);
113 QVERIFY(barseries != 0);
114 }
114 }
115
115
116 void tst_QBarSeries::type_data()
116 void tst_QBarSeries::type_data()
117 {
117 {
118
118
119 }
119 }
120
120
121 void tst_QBarSeries::type()
121 void tst_QBarSeries::type()
122 {
122 {
123 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar);
123 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar);
124 }
124 }
125
125
126 void tst_QBarSeries::append_data()
126 void tst_QBarSeries::append_data()
127 {
127 {
128 }
128 }
129
129
130 void tst_QBarSeries::append()
130 void tst_QBarSeries::append()
131 {
131 {
132 QVERIFY(m_barseries->barsetCount() == 0);
132 QVERIFY(m_barseries->barsetCount() == 0);
133
133
134 bool ret = false;
134 bool ret = false;
135
135
136 // Try adding barset
136 // Try adding barset
137 QBarSet *barset = new QBarSet("testset");
137 QBarSet *barset = new QBarSet("testset");
138 ret = m_barseries->append(barset);
138 ret = m_barseries->append(barset);
139
139
140 QVERIFY(ret == true);
140 QVERIFY(ret == true);
141 QVERIFY(m_barseries->barsetCount() == 1);
141 QVERIFY(m_barseries->barsetCount() == 1);
142
142
143 // Try adding another set
143 // Try adding another set
144 QBarSet *barset2 = new QBarSet("testset2");
144 QBarSet *barset2 = new QBarSet("testset2");
145 ret = m_barseries->append(barset2);
145 ret = m_barseries->append(barset2);
146
146
147 QVERIFY(ret == true);
147 QVERIFY(ret == true);
148 QVERIFY(m_barseries->barsetCount() == 2);
148 QVERIFY(m_barseries->barsetCount() == 2);
149
149
150 // Try adding same set again
150 // Try adding same set again
151 ret = m_barseries->append(barset2);
151 ret = m_barseries->append(barset2);
152 QVERIFY(ret == false);
152 QVERIFY(ret == false);
153 QVERIFY(m_barseries->barsetCount() == 2);
153 QVERIFY(m_barseries->barsetCount() == 2);
154
154
155 // Try adding null set
155 // Try adding null set
156 ret = m_barseries->append(0);
156 ret = m_barseries->append(0);
157 QVERIFY(ret == false);
157 QVERIFY(ret == false);
158 QVERIFY(m_barseries->barsetCount() == 2);
158 QVERIFY(m_barseries->barsetCount() == 2);
159
159
160 }
160 }
161
161
162 void tst_QBarSeries::remove_data()
162 void tst_QBarSeries::remove_data()
163 {
163 {
164 }
164 }
165
165
166 void tst_QBarSeries::remove()
166 void tst_QBarSeries::remove()
167 {
167 {
168 int count = m_testSets.count();
168 int count = m_testSets.count();
169 QVERIFY(m_barseries_with_sets->barsetCount() == count);
169 QVERIFY(m_barseries_with_sets->barsetCount() == count);
170
170
171 // Try to remove null pointer (should not remove, should not crash)
171 // Try to remove null pointer (should not remove, should not crash)
172 bool ret = false;
172 bool ret = false;
173 ret = m_barseries_with_sets->remove(0);
173 ret = m_barseries_with_sets->remove(0);
174 QVERIFY(ret == false);
174 QVERIFY(ret == false);
175 QVERIFY(m_barseries_with_sets->barsetCount() == count);
175 QVERIFY(m_barseries_with_sets->barsetCount() == count);
176
176
177 // Try to remove invalid pointer (should not remove, should not crash)
177 // Try to remove invalid pointer (should not remove, should not crash)
178 ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) );
178 ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) );
179 QVERIFY(ret == false);
179 QVERIFY(ret == false);
180 QVERIFY(m_barseries_with_sets->barsetCount() == count);
180 QVERIFY(m_barseries_with_sets->barsetCount() == count);
181
181
182 // remove some sets
182 // remove some sets
183 ret = m_barseries_with_sets->remove(m_testSets.at(2));
183 ret = m_barseries_with_sets->remove(m_testSets.at(2));
184 QVERIFY(ret == true);
184 QVERIFY(ret == true);
185 ret = m_barseries_with_sets->remove(m_testSets.at(3));
185 ret = m_barseries_with_sets->remove(m_testSets.at(3));
186 QVERIFY(ret == true);
186 QVERIFY(ret == true);
187 ret = m_barseries_with_sets->remove(m_testSets.at(4));
187 ret = m_barseries_with_sets->remove(m_testSets.at(4));
188 QVERIFY(ret == true);
188 QVERIFY(ret == true);
189
189
190 QVERIFY(m_barseries_with_sets->barsetCount() == 2);
190 QVERIFY(m_barseries_with_sets->barsetCount() == 2);
191
191
192 QList<QBarSet*> verifysets = m_barseries_with_sets->barSets();
192 QList<QBarSet*> verifysets = m_barseries_with_sets->barSets();
193
193
194 QVERIFY(verifysets.at(0) == m_testSets.at(0));
194 QVERIFY(verifysets.at(0) == m_testSets.at(0));
195 QVERIFY(verifysets.at(1) == m_testSets.at(1));
195 QVERIFY(verifysets.at(1) == m_testSets.at(1));
196
196
197 // Try removing all sets again (should be ok, even if some sets have already been removed)
197 // Try removing all sets again (should be ok, even if some sets have already been removed)
198 ret = false;
198 ret = false;
199 for (int i=0; i<count; i++) {
199 for (int i=0; i<count; i++) {
200 ret |= m_barseries_with_sets->remove(m_testSets.at(i));
200 ret |= m_barseries_with_sets->remove(m_testSets.at(i));
201 }
201 }
202
202
203 QVERIFY(ret == true);
203 QVERIFY(ret == true);
204 QVERIFY(m_barseries_with_sets->barsetCount() == 0);
204 QVERIFY(m_barseries_with_sets->barsetCount() == 0);
205 }
205 }
206
206
207 void tst_QBarSeries::appendList_data()
207 void tst_QBarSeries::appendList_data()
208 {
208 {
209
209
210 }
210 }
211
211
212 void tst_QBarSeries::appendList()
212 void tst_QBarSeries::appendList()
213 {
213 {
214 int count = 5;
214 int count = 5;
215 QVERIFY(m_barseries->barsetCount() == 0);
215 QVERIFY(m_barseries->barsetCount() == 0);
216
216
217 QList<QBarSet*> sets;
217 QList<QBarSet*> sets;
218 for (int i=0; i<count; i++) {
218 for (int i=0; i<count; i++) {
219 sets.append(new QBarSet("testset"));
219 sets.append(new QBarSet("testset"));
220 }
220 }
221
221
222 // Append new sets (should succeed, count should match the count of sets)
222 // Append new sets (should succeed, count should match the count of sets)
223 bool ret = false;
223 bool ret = false;
224 ret = m_barseries->append(sets);
224 ret = m_barseries->append(sets);
225 QVERIFY(ret == true);
225 QVERIFY(ret == true);
226 QVERIFY(m_barseries->barsetCount() == count);
226 QVERIFY(m_barseries->barsetCount() == count);
227
227
228 // Append same sets again (should fail, count should remain same)
228 // Append same sets again (should fail, count should remain same)
229 ret = m_barseries->append(sets);
229 ret = m_barseries->append(sets);
230 QVERIFY(ret == false);
230 QVERIFY(ret == false);
231 QVERIFY(m_barseries->barsetCount() == count);
231 QVERIFY(m_barseries->barsetCount() == count);
232
232
233 // Try append empty list (should succeed, but count should remain same)
233 // Try append empty list (should succeed, but count should remain same)
234 QList<QBarSet*> invalidList;
234 QList<QBarSet*> invalidList;
235 ret = m_barseries->append(invalidList);
235 ret = m_barseries->append(invalidList);
236 QVERIFY(ret == true);
236 QVERIFY(ret == true);
237 QVERIFY(m_barseries->barsetCount() == count);
237 QVERIFY(m_barseries->barsetCount() == count);
238
238
239 // Try append list with one new and one existing set (should fail, count remains same)
239 // Try append list with one new and one existing set (should fail, count remains same)
240 invalidList.append(new QBarSet("ok set"));
240 invalidList.append(new QBarSet("ok set"));
241 invalidList.append(sets.at(0));
241 invalidList.append(sets.at(0));
242 ret = m_barseries->append(invalidList);
242 ret = m_barseries->append(invalidList);
243 QVERIFY(ret == false);
243 QVERIFY(ret == false);
244 QVERIFY(m_barseries->barsetCount() == count);
244 QVERIFY(m_barseries->barsetCount() == count);
245
245
246 // Try append list with null pointers (should fail, count remains same)
246 // Try append list with null pointers (should fail, count remains same)
247 QList<QBarSet*> invalidList2;
247 QList<QBarSet*> invalidList2;
248 invalidList2.append(0);
248 invalidList2.append(0);
249 invalidList2.append(0);
249 invalidList2.append(0);
250 invalidList2.append(0);
250 invalidList2.append(0);
251 ret = m_barseries->append(invalidList2);
251 ret = m_barseries->append(invalidList2);
252 QVERIFY(ret == false);
252 QVERIFY(ret == false);
253 QVERIFY(m_barseries->barsetCount() == count);
253 QVERIFY(m_barseries->barsetCount() == count);
254 }
254 }
255
255
256 void tst_QBarSeries::barsetCount_data()
256 void tst_QBarSeries::barsetCount_data()
257 {
257 {
258
258
259 }
259 }
260
260
261 void tst_QBarSeries::barsetCount()
261 void tst_QBarSeries::barsetCount()
262 {
262 {
263 QVERIFY(m_barseries->barsetCount() == 0);
263 QVERIFY(m_barseries->barsetCount() == 0);
264 QVERIFY(m_barseries_with_sets->barsetCount() == m_testSets.count());
264 QVERIFY(m_barseries_with_sets->barsetCount() == m_testSets.count());
265 }
265 }
266
266
267 void tst_QBarSeries::barSets_data()
267 void tst_QBarSeries::barSets_data()
268 {
268 {
269
269
270 }
270 }
271
271
272 void tst_QBarSeries::barSets()
272 void tst_QBarSeries::barSets()
273 {
273 {
274 QVERIFY(m_barseries->barSets().count() == 0);
274 QVERIFY(m_barseries->barSets().count() == 0);
275
275
276 QList<QBarSet*> sets = m_barseries_with_sets->barSets();
276 QList<QBarSet*> sets = m_barseries_with_sets->barSets();
277 QVERIFY(sets.count() == m_testSets.count());
277 QVERIFY(sets.count() == m_testSets.count());
278
278
279 for (int i=0; i<m_testSets.count(); i++) {
279 for (int i=0; i<m_testSets.count(); i++) {
280 QVERIFY(sets.at(i) == m_testSets.at(i));
280 QVERIFY(sets.at(i) == m_testSets.at(i));
281 }
281 }
282 }
282 }
283
283
284 void tst_QBarSeries::setLabelsVisible_data()
284 void tst_QBarSeries::setLabelsVisible_data()
285 {
285 {
286
286
287 }
287 }
288
288
289 void tst_QBarSeries::setLabelsVisible()
289 void tst_QBarSeries::setLabelsVisible()
290 {
290 {
291 // labels should be invisible by default
291 // labels should be invisible by default
292 QVERIFY(m_barseries->isLabelsVisible() == false);
292 QVERIFY(m_barseries->isLabelsVisible() == false);
293 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
293 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
294
294
295 // turn labels to visible
295 // turn labels to visible
296 m_barseries_with_sets->setLabelsVisible(true);
296 m_barseries_with_sets->setLabelsVisible(true);
297 // TODO: test the signal
297 // TODO: test the signal
298 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
298 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
299
299
300 // turn labels to invisible
300 // turn labels to invisible
301 m_barseries_with_sets->setLabelsVisible(false);
301 m_barseries_with_sets->setLabelsVisible(false);
302 // TODO: test the signal
302 // TODO: test the signal
303 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
303 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
304
304
305 // without parameter, should turn labels to visible
305 // without parameter, should turn labels to visible
306 m_barseries_with_sets->setLabelsVisible();
306 m_barseries_with_sets->setLabelsVisible();
307 // TODO: test the signal
307 // TODO: test the signal
308 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
308 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
309 }
309 }
310
310
311 void tst_QBarSeries::mouseclicked_data()
311 void tst_QBarSeries::mouseclicked_data()
312 {
312 {
313
313
314 }
314 }
315
315
316 void tst_QBarSeries::mouseclicked()
316 void tst_QBarSeries::mouseclicked()
317 {
317 {
318 QBarSeries* series = new QBarSeries();
318 QBarSeries* series = new QBarSeries();
319
319
320 QBarSet* set1 = new QBarSet(QString("set 1"));
320 QBarSet* set1 = new QBarSet(QString("set 1"));
321 *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10);
321 *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10);
322 series->append(set1);
322 series->append(set1);
323
323
324 QBarSet* set2 = new QBarSet(QString("set 2"));
324 QBarSet* set2 = new QBarSet(QString("set 2"));
325 *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
325 *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
326 series->append(set2);
326 series->append(set2);
327
327
328 QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,int)));
328 QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,int)));
329
329
330 QChartView view(new QChart());
330 QChartView view(new QChart());
331 view.resize(400,300);
331 view.resize(400,300);
332 view.chart()->addSeries(series);
332 view.chart()->addSeries(series);
333 view.show();
333 view.show();
334 QTest::qWaitForWindowShown(&view);
334 QTest::qWaitForWindowShown(&view);
335
335
336 //====================================================================================
336 //====================================================================================
337 // barset 1, category test1
337 // barset 1, bar 0
338 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,142));
338 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(95,142));
339 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
339 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
340
340
341 QCOMPARE(seriesSpy.count(), 1);
341 QCOMPARE(seriesSpy.count(), 1);
342
342
343 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
343 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
344 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
344 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
345 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
345 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
346 QVERIFY(seriesSpyArg.at(1).toInt() == 0);
346 QVERIFY(seriesSpyArg.at(1).toInt() == 0);
347
347
348 //====================================================================================
348 //====================================================================================
349 // barset 1, category test2
349 // barset 1, bar 1
350 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,142));
350 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(164,142));
351 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
351 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
352
352
353 QCOMPARE(seriesSpy.count(), 1);
353 QCOMPARE(seriesSpy.count(), 1);
354
354
355 seriesSpyArg = seriesSpy.takeFirst();
355 seriesSpyArg = seriesSpy.takeFirst();
356 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
356 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
357 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
357 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
358 QVERIFY(seriesSpyArg.at(1).toInt() == 1);
358 QVERIFY(seriesSpyArg.at(1).toInt() == 1);
359
359
360 //====================================================================================
360 //====================================================================================
361 // barset 1, category test3
361 // barset 1, bar 2
362 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(291,142));
362 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(234,142));
363 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
363 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
364
364
365 QCOMPARE(seriesSpy.count(), 1);
365 QCOMPARE(seriesSpy.count(), 1);
366
366
367 seriesSpyArg = seriesSpy.takeFirst();
367 seriesSpyArg = seriesSpy.takeFirst();
368 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
368 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
369 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
369 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
370 QVERIFY(seriesSpyArg.at(1).toInt() == 2);
370 QVERIFY(seriesSpyArg.at(1).toInt() == 2);
371
371
372 //====================================================================================
372 //====================================================================================
373 // barset 2, category test1
373 // barset 2, bar 0
374 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(134,142));
374 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(115,142));
375 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
375 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
376
376
377 QCOMPARE(seriesSpy.count(), 1);
377 QCOMPARE(seriesSpy.count(), 1);
378
378
379 seriesSpyArg = seriesSpy.takeFirst();
379 seriesSpyArg = seriesSpy.takeFirst();
380 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
380 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
381 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
381 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
382 QVERIFY(seriesSpyArg.at(1).toInt() == 0);
382 QVERIFY(seriesSpyArg.at(1).toInt() == 0);
383
383
384 //====================================================================================
384 //====================================================================================
385 // barset 2, category test2
385 // barset 2, bar 1
386 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(227,142));
386 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(185,142));
387 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
387 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
388
388
389 QCOMPARE(seriesSpy.count(), 1);
389 QCOMPARE(seriesSpy.count(), 1);
390
390
391 seriesSpyArg = seriesSpy.takeFirst();
391 seriesSpyArg = seriesSpy.takeFirst();
392 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
392 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
393 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
393 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
394 QVERIFY(seriesSpyArg.at(1).toInt() == 1);
394 QVERIFY(seriesSpyArg.at(1).toInt() == 1);
395
395
396 //====================================================================================
396 //====================================================================================
397 // barset 2, category test3
397 // barset 2, bar 2
398 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(319,142));
398 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(254,142));
399 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
399 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
400
400
401 QCOMPARE(seriesSpy.count(), 1);
401 QCOMPARE(seriesSpy.count(), 1);
402
402
403 seriesSpyArg = seriesSpy.takeFirst();
403 seriesSpyArg = seriesSpy.takeFirst();
404 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
404 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
405 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
405 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
406 QVERIFY(seriesSpyArg.at(1).toInt() == 2);
406 QVERIFY(seriesSpyArg.at(1).toInt() == 2);
407 }
407 }
408
408
409 void tst_QBarSeries::mousehovered_data()
409 void tst_QBarSeries::mousehovered_data()
410 {
410 {
411
411
412 }
412 }
413
413
414 void tst_QBarSeries::mousehovered()
414 void tst_QBarSeries::mousehovered()
415 {
415 {
416 QBarSeries* series = new QBarSeries();
416 QBarSeries* series = new QBarSeries();
417 QStringList categories;
417 QStringList categories;
418 categories << "test1" << "test2" << "test3";
418 categories << "test1" << "test2" << "test3";
419 // series->setCategories(categories);
419 // series->setCategories(categories);
420
420
421 QBarSet* set1 = new QBarSet(QString("set 1"));
421 QBarSet* set1 = new QBarSet(QString("set 1"));
422 *set1 << QPointF(0.1,10) << QPointF(1.1,10) << QPointF(2.1,10);
422 *set1 << QPointF(0.1,10) << QPointF(1.1,10) << QPointF(2.1,10);
423 series->append(set1);
423 series->append(set1);
424
424
425 QBarSet* set2 = new QBarSet(QString("set 2"));
425 QBarSet* set2 = new QBarSet(QString("set 2"));
426 *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
426 *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
427 series->append(set2);
427 series->append(set2);
428
428
429 QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool)));
429 QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool)));
430
430
431 QChartView view(new QChart());
431 QChartView view(new QChart());
432 view.resize(400,300);
432 view.resize(400,300);
433 view.chart()->addSeries(series);
433 view.chart()->addSeries(series);
434 view.show();
434 view.show();
435 QTest::qWaitForWindowShown(&view);
435 QTest::qWaitForWindowShown(&view);
436
436
437 //this is hack since view does not get events otherwise
437 //this is hack since view does not get events otherwise
438 view.setMouseTracking(true);
438 view.setMouseTracking(true);
439
439
440 //=======================================================================
440 //=======================================================================
441 // move mouse to left border
441 // move mouse to left border
442 QTest::mouseMove(view.viewport(), QPoint(0, 142));
442 QTest::mouseMove(view.viewport(), QPoint(0, 142));
443
443
444 QVERIFY(seriesSpy.count() == 0);
444 QVERIFY(seriesSpy.count() == 0);
445
445
446 //=======================================================================
446 //=======================================================================
447 // move mouse on top of set1
447 // move mouse on top of set1
448 QTest::mouseMove(view.viewport(), QPoint(106,142));
448 QTest::mouseMove(view.viewport(), QPoint(95,142));
449
449
450 QVERIFY(seriesSpy.count() == 1);
450 QVERIFY(seriesSpy.count() == 1);
451
451
452 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
452 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
453 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
453 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
454 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
454 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
455 QVERIFY(seriesSpyArg.at(1).toBool() == true);
455 QVERIFY(seriesSpyArg.at(1).toBool() == true);
456
456
457 //=======================================================================
457 //=======================================================================
458 // move mouse from top of set1 to top of set2
458 // move mouse from top of set1 to top of set2
459 QTest::mouseMove(view.viewport(), QPoint(134,142));
459 QTest::mouseMove(view.viewport(), QPoint(116,142));
460
460
461 QVERIFY(seriesSpy.count() == 2);
461 QVERIFY(seriesSpy.count() == 2);
462
462
463 // should leave set1
463 // should leave set1
464 seriesSpyArg = seriesSpy.takeFirst();
464 seriesSpyArg = seriesSpy.takeFirst();
465 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
465 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
466 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
466 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
467 QVERIFY(seriesSpyArg.at(1).toBool() == false);
467 QVERIFY(seriesSpyArg.at(1).toBool() == false);
468
468
469 // should enter set2
469 // should enter set2
470 seriesSpyArg = seriesSpy.takeFirst();
470 seriesSpyArg = seriesSpy.takeFirst();
471 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
471 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
472 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
472 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
473 QVERIFY(seriesSpyArg.at(1).toBool() == true);
473 QVERIFY(seriesSpyArg.at(1).toBool() == true);
474
474
475 //=======================================================================
475 //=======================================================================
476 // move mouse from top of set2 to background
476 // move mouse from top of set2 to background
477 QTest::mouseMove(view.viewport(), QPoint(134,0));
477 QTest::mouseMove(view.viewport(), QPoint(116,0));
478 QVERIFY(seriesSpy.count() == 1);
478 QVERIFY(seriesSpy.count() == 1);
479
479
480 // should leave set2
480 // should leave set2
481 seriesSpyArg = seriesSpy.takeFirst();
481 seriesSpyArg = seriesSpy.takeFirst();
482 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
482 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
483 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
483 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
484 QVERIFY(seriesSpyArg.at(1).toBool() == false);
484 QVERIFY(seriesSpyArg.at(1).toBool() == false);
485 }
485 }
486
486
487 void tst_QBarSeries::clearWithAnimations()
487 void tst_QBarSeries::clearWithAnimations()
488 {
488 {
489 QBarSeries* series = new QBarSeries();
489 QBarSeries* series = new QBarSeries();
490 QStringList categories;
490 QStringList categories;
491 categories << "test1" << "test2" << "test3";
491 categories << "test1" << "test2" << "test3";
492 // series->setCategories(categories);
492 // series->setCategories(categories);
493
493
494 QBarSet* set1 = new QBarSet(QString("set 1"));
494 QBarSet* set1 = new QBarSet(QString("set 1"));
495 *set1 << QPointF(0.1,10) << QPointF(1.1,10) << QPointF(2.1,10);
495 *set1 << QPointF(0.1,10) << QPointF(1.1,10) << QPointF(2.1,10);
496 series->append(set1);
496 series->append(set1);
497
497
498 QBarSet* set2 = new QBarSet(QString("set 2"));
498 QBarSet* set2 = new QBarSet(QString("set 2"));
499 *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
499 *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
500 series->append(set2);
500 series->append(set2);
501
501
502 QChartView view(new QChart());
502 QChartView view(new QChart());
503 view.resize(400,300);
503 view.resize(400,300);
504 view.chart()->setAnimationOptions(QChart::SeriesAnimations);
504 view.chart()->setAnimationOptions(QChart::SeriesAnimations);
505 view.chart()->addSeries(series);
505 view.chart()->addSeries(series);
506 view.show();
506 view.show();
507
507
508 series->clear();
508 series->clear();
509 }
509 }
510
510
511 QTEST_MAIN(tst_QBarSeries)
511 QTEST_MAIN(tst_QBarSeries)
512
512
513 #include "tst_qbarseries.moc"
513 #include "tst_qbarseries.moc"
514
514
General Comments 0
You need to be logged in to leave comments. Login now