##// END OF EJS Templates
Removed the old hovered signal from bar chart...
Titta Heikkala -
r2726:17ddbeb77815
parent child
Show More
@@ -1,269 +1,267
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 <private/abstractbarchartitem_p.h>
21 #include <private/abstractbarchartitem_p.h>
22 #include <private/bar_p.h>
22 #include <private/bar_p.h>
23 #include <QtCharts/QBarSet>
23 #include <QtCharts/QBarSet>
24 #include <private/qbarset_p.h>
24 #include <private/qbarset_p.h>
25 #include <QtCharts/QAbstractBarSeries>
25 #include <QtCharts/QAbstractBarSeries>
26 #include <private/qabstractbarseries_p.h>
26 #include <private/qabstractbarseries_p.h>
27 #include <QtCharts/QChart>
27 #include <QtCharts/QChart>
28 #include <private/chartpresenter_p.h>
28 #include <private/chartpresenter_p.h>
29 #include <private/charttheme_p.h>
29 #include <private/charttheme_p.h>
30 #include <private/baranimation_p.h>
30 #include <private/baranimation_p.h>
31
31
32 #include <private/chartdataset_p.h>
32 #include <private/chartdataset_p.h>
33 #include <QtGui/QPainter>
33 #include <QtGui/QPainter>
34 #include <QtGui/QTextDocument>
34 #include <QtGui/QTextDocument>
35
35
36 QT_CHARTS_BEGIN_NAMESPACE
36 QT_CHARTS_BEGIN_NAMESPACE
37
37
38 AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) :
38 AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) :
39 ChartItem(series->d_func(),item),
39 ChartItem(series->d_func(),item),
40 m_animation(0),
40 m_animation(0),
41 m_series(series)
41 m_series(series)
42 {
42 {
43
43
44 setFlag(ItemClipsChildrenToShape);
44 setFlag(ItemClipsChildrenToShape);
45 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
45 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
46 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars()));
46 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars()));
47 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
47 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
48 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
48 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
49 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged()));
49 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged()));
50 connect(series, SIGNAL(opacityChanged()), this, SLOT(handleOpacityChanged()));
50 connect(series, SIGNAL(opacityChanged()), this, SLOT(handleOpacityChanged()));
51 connect(series, SIGNAL(labelsFormatChanged(QString)), this, SLOT(handleUpdatedBars()));
51 connect(series, SIGNAL(labelsFormatChanged(QString)), this, SLOT(handleUpdatedBars()));
52 connect(series, SIGNAL(labelsFormatChanged(QString)), this, SLOT(positionLabels()));
52 connect(series, SIGNAL(labelsFormatChanged(QString)), this, SLOT(positionLabels()));
53 connect(series, SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)),
53 connect(series, SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)),
54 this, SLOT(handleLabelsPositionChanged()));
54 this, SLOT(handleLabelsPositionChanged()));
55 setZValue(ChartPresenter::BarSeriesZValue);
55 setZValue(ChartPresenter::BarSeriesZValue);
56 handleDataStructureChanged();
56 handleDataStructureChanged();
57 handleVisibleChanged();
57 handleVisibleChanged();
58 handleUpdatedBars();
58 handleUpdatedBars();
59 }
59 }
60
60
61 AbstractBarChartItem::~AbstractBarChartItem()
61 AbstractBarChartItem::~AbstractBarChartItem()
62 {
62 {
63 }
63 }
64
64
65 void AbstractBarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
65 void AbstractBarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
66 {
66 {
67 Q_UNUSED(painter);
67 Q_UNUSED(painter);
68 Q_UNUSED(option);
68 Q_UNUSED(option);
69 Q_UNUSED(widget);
69 Q_UNUSED(widget);
70 }
70 }
71
71
72 QRectF AbstractBarChartItem::boundingRect() const
72 QRectF AbstractBarChartItem::boundingRect() const
73 {
73 {
74 return m_rect;
74 return m_rect;
75 }
75 }
76
76
77 void AbstractBarChartItem::applyLayout(const QVector<QRectF> &layout)
77 void AbstractBarChartItem::applyLayout(const QVector<QRectF> &layout)
78 {
78 {
79 QSizeF size = geometry().size();
79 QSizeF size = geometry().size();
80 if (geometry().size().isValid()) {
80 if (geometry().size().isValid()) {
81 if (m_animation) {
81 if (m_animation) {
82 if (m_layout.count() == 0 || m_oldSize != size) {
82 if (m_layout.count() == 0 || m_oldSize != size) {
83 initializeLayout();
83 initializeLayout();
84 m_oldSize = size;
84 m_oldSize = size;
85 }
85 }
86 m_animation->setup(m_layout, layout);
86 m_animation->setup(m_layout, layout);
87 presenter()->startAnimation(m_animation);
87 presenter()->startAnimation(m_animation);
88 } else {
88 } else {
89 setLayout(layout);
89 setLayout(layout);
90 update();
90 update();
91 }
91 }
92 }
92 }
93 }
93 }
94
94
95 void AbstractBarChartItem::setAnimation(BarAnimation *animation)
95 void AbstractBarChartItem::setAnimation(BarAnimation *animation)
96 {
96 {
97 m_animation = animation;
97 m_animation = animation;
98 }
98 }
99
99
100 void AbstractBarChartItem::setLayout(const QVector<QRectF> &layout)
100 void AbstractBarChartItem::setLayout(const QVector<QRectF> &layout)
101 {
101 {
102 if (layout.count() != m_bars.count())
102 if (layout.count() != m_bars.count())
103 return;
103 return;
104
104
105 m_layout = layout;
105 m_layout = layout;
106
106
107 for (int i = 0; i < m_bars.count(); i++)
107 for (int i = 0; i < m_bars.count(); i++)
108 m_bars.at(i)->setRect(layout.at(i));
108 m_bars.at(i)->setRect(layout.at(i));
109
109
110 positionLabels();
110 positionLabels();
111 }
111 }
112 //handlers
112 //handlers
113
113
114 void AbstractBarChartItem::handleDomainUpdated()
114 void AbstractBarChartItem::handleDomainUpdated()
115 {
115 {
116 m_domainMinX = domain()->minX();
116 m_domainMinX = domain()->minX();
117 m_domainMaxX = domain()->maxX();
117 m_domainMaxX = domain()->maxX();
118 m_domainMinY = domain()->minY();
118 m_domainMinY = domain()->minY();
119 m_domainMaxY = domain()->maxY();
119 m_domainMaxY = domain()->maxY();
120
120
121 QRectF rect(QPointF(0,0),domain()->size());
121 QRectF rect(QPointF(0,0),domain()->size());
122
122
123 if(m_rect != rect){
123 if(m_rect != rect){
124 prepareGeometryChange();
124 prepareGeometryChange();
125 m_rect = rect;
125 m_rect = rect;
126 }
126 }
127
127
128 handleLayoutChanged();
128 handleLayoutChanged();
129 }
129 }
130
130
131 void AbstractBarChartItem::handleLayoutChanged()
131 void AbstractBarChartItem::handleLayoutChanged()
132 {
132 {
133 if ((m_rect.width() <= 0) || (m_rect.height() <= 0))
133 if ((m_rect.width() <= 0) || (m_rect.height() <= 0))
134 return; // rect size zero.
134 return; // rect size zero.
135 QVector<QRectF> layout = calculateLayout();
135 QVector<QRectF> layout = calculateLayout();
136 applyLayout(layout);
136 applyLayout(layout);
137 handleUpdatedBars();
137 handleUpdatedBars();
138 }
138 }
139
139
140 void AbstractBarChartItem::handleLabelsVisibleChanged(bool visible)
140 void AbstractBarChartItem::handleLabelsVisibleChanged(bool visible)
141 {
141 {
142 foreach (QGraphicsTextItem *label, m_labels)
142 foreach (QGraphicsTextItem *label, m_labels)
143 label->setVisible(visible);
143 label->setVisible(visible);
144 update();
144 update();
145 }
145 }
146
146
147 void AbstractBarChartItem::handleDataStructureChanged()
147 void AbstractBarChartItem::handleDataStructureChanged()
148 {
148 {
149 foreach (QGraphicsItem *item, childItems())
149 foreach (QGraphicsItem *item, childItems())
150 delete item;
150 delete item;
151
151
152 m_bars.clear();
152 m_bars.clear();
153 m_labels.clear();
153 m_labels.clear();
154 m_layout.clear();
154 m_layout.clear();
155
155
156 // Create new graphic items for bars
156 // Create new graphic items for bars
157 for (int c = 0; c < m_series->d_func()->categoryCount(); c++) {
157 for (int c = 0; c < m_series->d_func()->categoryCount(); c++) {
158 for (int s = 0; s < m_series->count(); s++) {
158 for (int s = 0; s < m_series->count(); s++) {
159 QBarSet *set = m_series->d_func()->barsetAt(s);
159 QBarSet *set = m_series->d_func()->barsetAt(s);
160
160
161 // Bars
161 // Bars
162 Bar *bar = new Bar(set, c, this);
162 Bar *bar = new Bar(set, c, this);
163 m_bars.append(bar);
163 m_bars.append(bar);
164 connect(bar, SIGNAL(clicked(int,QBarSet*)), m_series, SIGNAL(clicked(int,QBarSet*)));
164 connect(bar, SIGNAL(clicked(int,QBarSet*)), m_series, SIGNAL(clicked(int,QBarSet*)));
165 connect(bar, SIGNAL(hovered(bool,QBarSet*)), m_series, SIGNAL(hovered(bool,QBarSet*)));
166 connect(bar, SIGNAL(hovered(bool, int, QBarSet*)), m_series, SIGNAL(hovered(bool, int, QBarSet*)));
165 connect(bar, SIGNAL(hovered(bool, int, QBarSet*)), m_series, SIGNAL(hovered(bool, int, QBarSet*)));
167 connect(bar, SIGNAL(clicked(int,QBarSet*)), set, SIGNAL(clicked(int)));
166 connect(bar, SIGNAL(clicked(int,QBarSet*)), set, SIGNAL(clicked(int)));
168 connect(bar, SIGNAL(hovered(bool,QBarSet*)), set, SIGNAL(hovered(bool)));
169 connect(bar, SIGNAL(hovered(bool, int, QBarSet*)), set, SIGNAL(hovered(bool, int)));
167 connect(bar, SIGNAL(hovered(bool, int, QBarSet*)), set, SIGNAL(hovered(bool, int)));
170 // m_layout.append(QRectF(0, 0, 1, 1));
168 // m_layout.append(QRectF(0, 0, 1, 1));
171
169
172 // Labels
170 // Labels
173 QGraphicsTextItem *newLabel = new QGraphicsTextItem(this);
171 QGraphicsTextItem *newLabel = new QGraphicsTextItem(this);
174 newLabel->document()->setDocumentMargin(ChartPresenter::textMargin());
172 newLabel->document()->setDocumentMargin(ChartPresenter::textMargin());
175 m_labels.append(newLabel);
173 m_labels.append(newLabel);
176 }
174 }
177 }
175 }
178
176
179 if(themeManager()) themeManager()->updateSeries(m_series);
177 if(themeManager()) themeManager()->updateSeries(m_series);
180 handleLayoutChanged();
178 handleLayoutChanged();
181 handleVisibleChanged();
179 handleVisibleChanged();
182 }
180 }
183
181
184 void AbstractBarChartItem::handleVisibleChanged()
182 void AbstractBarChartItem::handleVisibleChanged()
185 {
183 {
186 bool visible = m_series->isVisible();
184 bool visible = m_series->isVisible();
187 if (visible)
185 if (visible)
188 handleLabelsVisibleChanged(m_series->isLabelsVisible());
186 handleLabelsVisibleChanged(m_series->isLabelsVisible());
189 else
187 else
190 handleLabelsVisibleChanged(visible);
188 handleLabelsVisibleChanged(visible);
191
189
192 foreach (QGraphicsItem *bar, m_bars)
190 foreach (QGraphicsItem *bar, m_bars)
193 bar->setVisible(visible);
191 bar->setVisible(visible);
194 }
192 }
195
193
196 void AbstractBarChartItem::handleOpacityChanged()
194 void AbstractBarChartItem::handleOpacityChanged()
197 {
195 {
198 foreach (QGraphicsItem *item, childItems())
196 foreach (QGraphicsItem *item, childItems())
199 item->setOpacity(m_series->opacity());
197 item->setOpacity(m_series->opacity());
200 }
198 }
201
199
202 void AbstractBarChartItem::handleUpdatedBars()
200 void AbstractBarChartItem::handleUpdatedBars()
203 {
201 {
204 if (!m_series->d_func()->blockBarUpdate()) {
202 if (!m_series->d_func()->blockBarUpdate()) {
205 // Handle changes in pen, brush, labels etc.
203 // Handle changes in pen, brush, labels etc.
206 int categoryCount = m_series->d_func()->categoryCount();
204 int categoryCount = m_series->d_func()->categoryCount();
207 int setCount = m_series->count();
205 int setCount = m_series->count();
208 int itemIndex(0);
206 int itemIndex(0);
209 static const QString valueTag(QLatin1String("@value"));
207 static const QString valueTag(QLatin1String("@value"));
210
208
211 for (int category = 0; category < categoryCount; category++) {
209 for (int category = 0; category < categoryCount; category++) {
212 for (int set = 0; set < setCount; set++) {
210 for (int set = 0; set < setCount; set++) {
213 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
211 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
214 Bar *bar = m_bars.at(itemIndex);
212 Bar *bar = m_bars.at(itemIndex);
215 bar->setPen(barSet->m_pen);
213 bar->setPen(barSet->m_pen);
216 bar->setBrush(barSet->m_brush);
214 bar->setBrush(barSet->m_brush);
217 bar->update();
215 bar->update();
218
216
219 QGraphicsTextItem *label = m_labels.at(itemIndex);
217 QGraphicsTextItem *label = m_labels.at(itemIndex);
220 QString valueLabel;
218 QString valueLabel;
221 if (presenter()) { // At startup presenter is not yet set, yet somehow update comes
219 if (presenter()) { // At startup presenter is not yet set, yet somehow update comes
222 if (m_series->labelsFormat().isEmpty()) {
220 if (m_series->labelsFormat().isEmpty()) {
223 valueLabel = presenter()->numberToString(barSet->value(category));
221 valueLabel = presenter()->numberToString(barSet->value(category));
224 } else {
222 } else {
225 valueLabel = m_series->labelsFormat();
223 valueLabel = m_series->labelsFormat();
226 valueLabel.replace(valueTag,
224 valueLabel.replace(valueTag,
227 presenter()->numberToString(barSet->value(category)));
225 presenter()->numberToString(barSet->value(category)));
228 }
226 }
229 }
227 }
230 label->setHtml(valueLabel);
228 label->setHtml(valueLabel);
231 label->setFont(barSet->m_labelFont);
229 label->setFont(barSet->m_labelFont);
232 label->setDefaultTextColor(barSet->m_labelBrush.color());
230 label->setDefaultTextColor(barSet->m_labelBrush.color());
233 label->update();
231 label->update();
234 itemIndex++;
232 itemIndex++;
235 }
233 }
236 }
234 }
237 }
235 }
238 }
236 }
239
237
240 void AbstractBarChartItem::handleLabelsPositionChanged()
238 void AbstractBarChartItem::handleLabelsPositionChanged()
241 {
239 {
242 positionLabels();
240 positionLabels();
243 }
241 }
244
242
245 void AbstractBarChartItem::positionLabels()
243 void AbstractBarChartItem::positionLabels()
246 {
244 {
247 for (int i = 0; i < m_layout.count(); i++) {
245 for (int i = 0; i < m_layout.count(); i++) {
248 QGraphicsTextItem *label = m_labels.at(i);
246 QGraphicsTextItem *label = m_labels.at(i);
249 qreal xPos = 0;
247 qreal xPos = 0;
250 qreal yPos = m_layout.at(i).center().y() - label->boundingRect().center().y();
248 qreal yPos = m_layout.at(i).center().y() - label->boundingRect().center().y();
251
249
252 int offset = m_bars.at(i)->pen().width() / 2 + 2;
250 int offset = m_bars.at(i)->pen().width() / 2 + 2;
253 if (m_series->labelsPosition() == QAbstractBarSeries::LabelsCenter)
251 if (m_series->labelsPosition() == QAbstractBarSeries::LabelsCenter)
254 xPos = m_layout.at(i).center().x() - label->boundingRect().center().x();
252 xPos = m_layout.at(i).center().x() - label->boundingRect().center().x();
255 else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideEnd)
253 else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideEnd)
256 xPos = m_layout.at(i).right() - label->boundingRect().width() - offset;
254 xPos = m_layout.at(i).right() - label->boundingRect().width() - offset;
257 else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideBase)
255 else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideBase)
258 xPos = m_layout.at(i).left() + offset;
256 xPos = m_layout.at(i).left() + offset;
259 else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsOutsideEnd)
257 else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsOutsideEnd)
260 xPos = m_layout.at(i).right() + offset;
258 xPos = m_layout.at(i).right() + offset;
261
259
262 label->setPos(xPos, yPos);
260 label->setPos(xPos, yPos);
263 label->setZValue(zValue() + 1);
261 label->setZValue(zValue() + 1);
264 }
262 }
265 }
263 }
266
264
267 #include "moc_abstractbarchartitem_p.cpp"
265 #include "moc_abstractbarchartitem_p.cpp"
268
266
269 QT_CHARTS_END_NAMESPACE
267 QT_CHARTS_END_NAMESPACE
@@ -1,71 +1,67
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 <private/bar_p.h>
21 #include <private/bar_p.h>
22 #include <QtGui/QPainter>
22 #include <QtGui/QPainter>
23 #include <QtWidgets/QGraphicsSceneEvent>
23 #include <QtWidgets/QGraphicsSceneEvent>
24
24
25 QT_CHARTS_BEGIN_NAMESPACE
25 QT_CHARTS_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 m_hovering(false)
31 {
31 {
32 setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
32 setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
33 setAcceptHoverEvents(true);
33 setAcceptHoverEvents(true);
34 }
34 }
35
35
36 Bar::~Bar()
36 Bar::~Bar()
37 {
37 {
38 // End hover event, if bar is deleted during it
38 // End hover event, if bar is deleted during it
39 if (m_hovering) {
39 if (m_hovering)
40 emit hovered(false, m_barset);
41 emit hovered(false, m_index, m_barset);
40 emit hovered(false, m_index, m_barset);
42 }
43 }
41 }
44
42
45 void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event)
43 void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event)
46 {
44 {
47 Q_UNUSED(event)
45 Q_UNUSED(event)
48 emit clicked(m_index, m_barset);
46 emit clicked(m_index, m_barset);
49 QGraphicsItem::mousePressEvent(event);
47 QGraphicsItem::mousePressEvent(event);
50 }
48 }
51
49
52 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
50 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
53 {
51 {
54 Q_UNUSED(event)
52 Q_UNUSED(event)
55 m_hovering = true;
53 m_hovering = true;
56 emit hovered(true, m_barset);
57 emit hovered(true, m_index, m_barset);
54 emit hovered(true, m_index, m_barset);
58
55
59 }
56 }
60
57
61 void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
58 void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
62 {
59 {
63 Q_UNUSED(event)
60 Q_UNUSED(event)
64 m_hovering = false;
61 m_hovering = false;
65 emit hovered(false, m_barset);
66 emit hovered(false, m_index, m_barset);
62 emit hovered(false, m_index, m_barset);
67 }
63 }
68
64
69 #include "moc_bar_p.cpp"
65 #include "moc_bar_p.cpp"
70
66
71 QT_CHARTS_END_NAMESPACE
67 QT_CHARTS_END_NAMESPACE
@@ -1,66 +1,65
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 Qt Enterprise Chart API. It exists purely as an
24 // This file is not part of the Qt Enterprise 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 <QtCharts/QChartGlobal>
33 #include <QtCharts/QChartGlobal>
34 #include <QtWidgets/QGraphicsRectItem>
34 #include <QtWidgets/QGraphicsRectItem>
35
35
36 QT_CHARTS_BEGIN_NAMESPACE
36 QT_CHARTS_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 ~Bar();
47
47
48 public:
48 public:
49 void mousePressEvent(QGraphicsSceneMouseEvent *event);
49 void mousePressEvent(QGraphicsSceneMouseEvent *event);
50 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
50 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
51 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
51 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
52
52
53 Q_SIGNALS:
53 Q_SIGNALS:
54 void clicked(int index, QBarSet *barset);
54 void clicked(int index, QBarSet *barset);
55 void hovered(bool status, QBarSet *barset);
56 void hovered(bool status, int index, QBarSet *barset);
55 void hovered(bool status, int index, QBarSet *barset);
57
56
58 private:
57 private:
59 int m_index;
58 int m_index;
60 QBarSet *m_barset;
59 QBarSet *m_barset;
61 bool m_hovering;
60 bool m_hovering;
62 };
61 };
63
62
64 QT_CHARTS_END_NAMESPACE
63 QT_CHARTS_END_NAMESPACE
65
64
66 #endif // BAR_H
65 #endif // BAR_H
@@ -1,1030 +1,1022
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 <QtCharts/QAbstractBarSeries>
21 #include <QtCharts/QAbstractBarSeries>
22 #include <private/qabstractbarseries_p.h>
22 #include <private/qabstractbarseries_p.h>
23 #include <QtCharts/QBarSet>
23 #include <QtCharts/QBarSet>
24 #include <private/qbarset_p.h>
24 #include <private/qbarset_p.h>
25 #include <private/abstractdomain_p.h>
25 #include <private/abstractdomain_p.h>
26 #include <private/chartdataset_p.h>
26 #include <private/chartdataset_p.h>
27 #include <private/charttheme_p.h>
27 #include <private/charttheme_p.h>
28 #include <QtCharts/QValueAxis>
28 #include <QtCharts/QValueAxis>
29 #include <QtCharts/QBarCategoryAxis>
29 #include <QtCharts/QBarCategoryAxis>
30 #include <QtCharts/QBarLegendMarker>
30 #include <QtCharts/QBarLegendMarker>
31 #include <private/baranimation_p.h>
31 #include <private/baranimation_p.h>
32 #include <private/abstractbarchartitem_p.h>
32 #include <private/abstractbarchartitem_p.h>
33 #include <private/qchart_p.h>
33 #include <private/qchart_p.h>
34
34
35 QT_CHARTS_BEGIN_NAMESPACE
35 QT_CHARTS_BEGIN_NAMESPACE
36
36
37 /*!
37 /*!
38 \class QAbstractBarSeries
38 \class QAbstractBarSeries
39 \inmodule Qt Charts
39 \inmodule Qt Charts
40 \brief Series for creating a bar chart.
40 \brief Series for creating a bar chart.
41 \mainclass
41 \mainclass
42
42
43 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
43 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
44 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
44 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
45 and y-value is the height of the bar. The category names are ignored with this series and x-axis
45 and y-value is the height of the bar. The category names are ignored with this series and x-axis
46 shows the x-values.
46 shows the x-values.
47
47
48 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
48 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
49 \image examples_barchart.png
49 \image examples_barchart.png
50
50
51 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
51 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
52 */
52 */
53 /*!
53 /*!
54 \qmltype AbstractBarSeries
54 \qmltype AbstractBarSeries
55 \instantiates QAbstractBarSeries
55 \instantiates QAbstractBarSeries
56 \inqmlmodule QtCharts
56 \inqmlmodule QtCharts
57
57
58 \inherits AbstractSeries
58 \inherits AbstractSeries
59
59
60 \brief Series type for creating a bar chart.
60 \brief Series type for creating a bar chart.
61
61
62 The following QML shows how to create a simple bar chart:
62 The following QML shows how to create a simple bar chart:
63 \snippet qmlchart/qml/qmlchart/View6.qml 1
63 \snippet qmlchart/qml/qmlchart/View6.qml 1
64
64
65 \beginfloatleft
65 \beginfloatleft
66 \image examples_qmlchart6.png
66 \image examples_qmlchart6.png
67 \endfloat
67 \endfloat
68 \clearfloat
68 \clearfloat
69 */
69 */
70
70
71 /*!
71 /*!
72 \qmlproperty AbstractAxis AbstractBarSeries::axisX
72 \qmlproperty AbstractAxis AbstractBarSeries::axisX
73 The x axis used for the series. If you leave both axisX and axisXTop undefined, a BarCategoriesAxis is created for
73 The x axis used for the series. If you leave both axisX and axisXTop undefined, a BarCategoriesAxis is created for
74 the series.
74 the series.
75 \sa axisXTop
75 \sa axisXTop
76 */
76 */
77
77
78 /*!
78 /*!
79 \qmlproperty AbstractAxis AbstractBarSeries::axisY
79 \qmlproperty AbstractAxis AbstractBarSeries::axisY
80 The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for
80 The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for
81 the series.
81 the series.
82 \sa axisYRight
82 \sa axisYRight
83 */
83 */
84
84
85 /*!
85 /*!
86 \qmlproperty AbstractAxis AbstractBarSeries::axisXTop
86 \qmlproperty AbstractAxis AbstractBarSeries::axisXTop
87 The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or
87 The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or
88 axisXTop, but not both.
88 axisXTop, but not both.
89 \sa axisX
89 \sa axisX
90 */
90 */
91
91
92 /*!
92 /*!
93 \qmlproperty AbstractAxis AbstractBarSeries::axisYRight
93 \qmlproperty AbstractAxis AbstractBarSeries::axisYRight
94 The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY
94 The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY
95 or axisYRight, but not both.
95 or axisYRight, but not both.
96 \sa axisY
96 \sa axisY
97 */
97 */
98
98
99 /*!
99 /*!
100 \property QAbstractBarSeries::barWidth
100 \property QAbstractBarSeries::barWidth
101 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
101 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
102 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
102 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
103 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
103 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
104 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
104 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
105 \sa QBarSeries
105 \sa QBarSeries
106 */
106 */
107 /*!
107 /*!
108 \qmlproperty real AbstractBarSeries::barWidth
108 \qmlproperty real AbstractBarSeries::barWidth
109 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
109 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
110 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
110 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
111 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
111 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
112 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
112 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
113 */
113 */
114
114
115 /*!
115 /*!
116 \property QAbstractBarSeries::count
116 \property QAbstractBarSeries::count
117 Holds the number of sets in series.
117 Holds the number of sets in series.
118 */
118 */
119 /*!
119 /*!
120 \qmlproperty int AbstractBarSeries::count
120 \qmlproperty int AbstractBarSeries::count
121 Holds the number of sets in series.
121 Holds the number of sets in series.
122 */
122 */
123
123
124 /*!
124 /*!
125 \property QAbstractBarSeries::labelsVisible
125 \property QAbstractBarSeries::labelsVisible
126 Defines the visibility of the labels in series
126 Defines the visibility of the labels in series
127 */
127 */
128 /*!
128 /*!
129 \qmlproperty bool AbstractBarSeries::labelsVisible
129 \qmlproperty bool AbstractBarSeries::labelsVisible
130 Defines the visibility of the labels in series
130 Defines the visibility of the labels in series
131 */
131 */
132
132
133 /*!
133 /*!
134 \property QAbstractBarSeries::labelsFormat
134 \property QAbstractBarSeries::labelsFormat
135 The \a format used for showing labels in series.
135 The \a format used for showing labels in series.
136
136
137 QAbstractBarSeries supports the following format tag:
137 QAbstractBarSeries supports the following format tag:
138 \table
138 \table
139 \row
139 \row
140 \li @value \li The value of the bar
140 \li @value \li The value of the bar
141 \endtable
141 \endtable
142
142
143 For example, the following usage of the format tags would produce labels that show the value
143 For example, the following usage of the format tags would produce labels that show the value
144 followed by unit ('u'):
144 followed by unit ('u'):
145 \code
145 \code
146 series->setLabelsFormat("@value u");
146 series->setLabelsFormat("@value u");
147 \endcode
147 \endcode
148
148
149 By default, the labels shows the value of the bar. For percent bar series '%' is added after
149 By default, the labels shows the value of the bar. For percent bar series '%' is added after
150 the value. The labels are shown on the plot area, labels on the edge of the plot area are cut.
150 the value. The labels are shown on the plot area, labels on the edge of the plot area are cut.
151 If the bars are close to each other the labels may overlap.
151 If the bars are close to each other the labels may overlap.
152
152
153 \sa QAbstractBarSeries::labelsVisible, QAbstractBarSeries::labelsPosition
153 \sa QAbstractBarSeries::labelsVisible, QAbstractBarSeries::labelsPosition
154 */
154 */
155 /*!
155 /*!
156 \qmlproperty string AbstractBarSeries::labelsFormat
156 \qmlproperty string AbstractBarSeries::labelsFormat
157 The format used for showing labels in series.
157 The format used for showing labels in series.
158
158
159 \sa QAbstractBarSeries::labelsFormat, labelsVisible, labelsPosition
159 \sa QAbstractBarSeries::labelsFormat, labelsVisible, labelsPosition
160 */
160 */
161 /*!
161 /*!
162 \fn void QAbstractBarSeries::labelsFormatChanged(const QString &format)
162 \fn void QAbstractBarSeries::labelsFormatChanged(const QString &format)
163 Signal is emitted when the \a format of data value labels is changed.
163 Signal is emitted when the \a format of data value labels is changed.
164 */
164 */
165 /*!
165 /*!
166 \qmlsignal XYSeries::onLabelsFormatChanged(string format)
166 \qmlsignal XYSeries::onLabelsFormatChanged(string format)
167 Signal is emitted when the \a format of data value labels is changed.
167 Signal is emitted when the \a format of data value labels is changed.
168 */
168 */
169
169
170 /*!
170 /*!
171 \enum QAbstractBarSeries::LabelsPosition
171 \enum QAbstractBarSeries::LabelsPosition
172
172
173 This enum describes the position of the data value labels.
173 This enum describes the position of the data value labels.
174
174
175 \value LabelsCenter Label is in the center of the bar.
175 \value LabelsCenter Label is in the center of the bar.
176 \value LabelsInsideEnd Label is inside the bar at the high end of it.
176 \value LabelsInsideEnd Label is inside the bar at the high end of it.
177 \value LabelsInsideBase Label is inside the bar at the low end of it.
177 \value LabelsInsideBase Label is inside the bar at the low end of it.
178 \value LabelsOutsideEnd Label is outside the bar at the high end of it.
178 \value LabelsOutsideEnd Label is outside the bar at the high end of it.
179 */
179 */
180
180
181 /*!
181 /*!
182 \property QAbstractBarSeries::labelsPosition
182 \property QAbstractBarSeries::labelsPosition
183 Defines the \a position of value labels.
183 Defines the \a position of value labels.
184
184
185 \sa QAbstractBarSeries::labelsVisible, QAbstractBarSeries::labelsFormat
185 \sa QAbstractBarSeries::labelsVisible, QAbstractBarSeries::labelsFormat
186 */
186 */
187 /*!
187 /*!
188 \qmlproperty string AbstractBarSeries::labelsPosition
188 \qmlproperty string AbstractBarSeries::labelsPosition
189 Defines the \a position of value labels.
189 Defines the \a position of value labels.
190
190
191 \sa labelsVisible, labelsFormat
191 \sa labelsVisible, labelsFormat
192 */
192 */
193 /*!
193 /*!
194 \fn void QAbstractBarSeries::labelsPositionChanged(QAbstractBarSeries::LabelsPosition position)
194 \fn void QAbstractBarSeries::labelsPositionChanged(QAbstractBarSeries::LabelsPosition position)
195 Signal is emitted when the \a position of value labels is changed.
195 Signal is emitted when the \a position of value labels is changed.
196 */
196 */
197 /*!
197 /*!
198 \qmlsignal AbstractBarSeries::onLabelsPositionChanged(LabelsPosition position)
198 \qmlsignal AbstractBarSeries::onLabelsPositionChanged(LabelsPosition position)
199 Signal is emitted when the \a position of value labels is changed.
199 Signal is emitted when the \a position of value labels is changed.
200 */
200 */
201
201
202 /*!
202 /*!
203 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
203 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
204 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
204 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
205 Clicked bar inside set is indexed by \a index
205 Clicked bar inside set is indexed by \a index
206 */
206 */
207 /*!
207 /*!
208 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
208 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
209 The signal is emitted if the user clicks with a mouse on top of BarSet.
209 The signal is emitted if the user clicks with a mouse on top of BarSet.
210 Clicked bar inside set is indexed by \a index
210 Clicked bar inside set is indexed by \a index
211 */
211 */
212
212
213 /*!
213 /*!
214 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
215
216 The signal is emitted if mouse is hovered on top of series.
217 Parameter \a barset is the pointer of barset, where hover happened.
218 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
219 */
220
221 /*!
222 \fn void QAbstractBarSeries::hovered(bool status, int index, QBarSet* barset)
214 \fn void QAbstractBarSeries::hovered(bool status, int index, QBarSet* barset)
223
215
224 The signal is emitted if mouse is hovered on top of series.
216 The signal is emitted if mouse is hovered on top of series.
225 Parameter \a barset is the pointer of barset, where hover happened.
217 Parameter \a barset is the pointer of barset, where hover happened.
226 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
218 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
227 Hovered bar inside the set is indexed by \a index.
219 Hovered bar inside the set is indexed by \a index.
228 */
220 */
229 /*!
221 /*!
230 \qmlsignal AbstractBarSeries::onHovered(bool status, int index, BarSet barset)
222 \qmlsignal AbstractBarSeries::onHovered(bool status, int index, BarSet barset)
231
223
232 The signal is emitted if mouse is hovered on top of series.
224 The signal is emitted if mouse is hovered on top of series.
233 Parameter \a barset is the pointer of barset, where hover happened.
225 Parameter \a barset is the pointer of barset, where hover happened.
234 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
226 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
235 Hovered bar inside the set is indexed by \a index.
227 Hovered bar inside the set is indexed by \a index.
236 */
228 */
237
229
238 /*!
230 /*!
239 \fn void QAbstractBarSeries::countChanged()
231 \fn void QAbstractBarSeries::countChanged()
240 This signal is emitted when barset count has been changed, for example by append or remove.
232 This signal is emitted when barset count has been changed, for example by append or remove.
241 */
233 */
242 /*!
234 /*!
243 \qmlsignal AbstractBarSeries::onCountChanged()
235 \qmlsignal AbstractBarSeries::onCountChanged()
244 This signal is emitted when barset count has been changed, for example by append or remove.
236 This signal is emitted when barset count has been changed, for example by append or remove.
245 */
237 */
246
238
247 /*!
239 /*!
248 \fn void QAbstractBarSeries::labelsVisibleChanged()
240 \fn void QAbstractBarSeries::labelsVisibleChanged()
249 This signal is emitted when labels visibility have changed.
241 This signal is emitted when labels visibility have changed.
250 \sa isLabelsVisible(), setLabelsVisible()
242 \sa isLabelsVisible(), setLabelsVisible()
251 */
243 */
252
244
253 /*!
245 /*!
254 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
246 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
255 This signal is emitted when \a sets have been added to the series.
247 This signal is emitted when \a sets have been added to the series.
256 \sa append(), insert()
248 \sa append(), insert()
257 */
249 */
258 /*!
250 /*!
259 \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset)
251 \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset)
260 Emitted when \a barset has been added to the series.
252 Emitted when \a barset has been added to the series.
261 */
253 */
262
254
263 /*!
255 /*!
264 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
256 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
265 This signal is emitted when \a sets have been removed from the series.
257 This signal is emitted when \a sets have been removed from the series.
266 \sa remove()
258 \sa remove()
267 */
259 */
268 /*!
260 /*!
269 \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset)
261 \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset)
270 Emitted when \a barset has been removed from the series.
262 Emitted when \a barset has been removed from the series.
271 */
263 */
272
264
273 /*!
265 /*!
274 \qmlmethod BarSet AbstractBarSeries::at(int index)
266 \qmlmethod BarSet AbstractBarSeries::at(int index)
275 Returns bar set at \a index. Returns null if the index is not valid.
267 Returns bar set at \a index. Returns null if the index is not valid.
276 */
268 */
277
269
278 /*!
270 /*!
279 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
271 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
280 Adds a new bar set with \a label and \a values to \a index. Values is a list of reals.
272 Adds a new bar set with \a label and \a values to \a index. Values is a list of reals.
281 For example:
273 For example:
282 \code
274 \code
283 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
275 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
284 \endcode
276 \endcode
285 */
277 */
286
278
287 /*!
279 /*!
288 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
280 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
289 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.
281 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.
290 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
282 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
291 appended.
283 appended.
292 \sa AbstractBarSeries::append()
284 \sa AbstractBarSeries::append()
293 */
285 */
294
286
295 /*!
287 /*!
296 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
288 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
297 Removes the barset from the series. Returns true if successful, false otherwise.
289 Removes the barset from the series. Returns true if successful, false otherwise.
298 */
290 */
299
291
300 /*!
292 /*!
301 \qmlmethod AbstractBarSeries::clear()
293 \qmlmethod AbstractBarSeries::clear()
302 Removes all barsets from the series.
294 Removes all barsets from the series.
303 */
295 */
304
296
305 /*!
297 /*!
306 Destructs abstractbarseries and owned barsets.
298 Destructs abstractbarseries and owned barsets.
307 */
299 */
308 QAbstractBarSeries::~QAbstractBarSeries()
300 QAbstractBarSeries::~QAbstractBarSeries()
309 {
301 {
310
302
311 }
303 }
312
304
313 /*!
305 /*!
314 \internal
306 \internal
315 */
307 */
316 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent)
308 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent)
317 : QAbstractSeries(o, parent)
309 : QAbstractSeries(o, parent)
318 {
310 {
319 Q_D(QAbstractSeries);
311 Q_D(QAbstractSeries);
320 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
312 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
321 }
313 }
322
314
323 /*!
315 /*!
324 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
316 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
325 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
317 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
326 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
318 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
327 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
319 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
328 */
320 */
329 void QAbstractBarSeries::setBarWidth(qreal width)
321 void QAbstractBarSeries::setBarWidth(qreal width)
330 {
322 {
331 Q_D(QAbstractBarSeries);
323 Q_D(QAbstractBarSeries);
332 d->setBarWidth(width);
324 d->setBarWidth(width);
333 }
325 }
334
326
335 /*!
327 /*!
336 Returns the width of the bars of the series.
328 Returns the width of the bars of the series.
337 \sa setBarWidth()
329 \sa setBarWidth()
338 */
330 */
339 qreal QAbstractBarSeries::barWidth() const
331 qreal QAbstractBarSeries::barWidth() const
340 {
332 {
341 Q_D(const QAbstractBarSeries);
333 Q_D(const QAbstractBarSeries);
342 return d->barWidth();
334 return d->barWidth();
343 }
335 }
344
336
345 /*!
337 /*!
346 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.
338 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.
347 Returns true, if appending succeeded.
339 Returns true, if appending succeeded.
348 */
340 */
349 bool QAbstractBarSeries::append(QBarSet *set)
341 bool QAbstractBarSeries::append(QBarSet *set)
350 {
342 {
351 Q_D(QAbstractBarSeries);
343 Q_D(QAbstractBarSeries);
352 bool success = d->append(set);
344 bool success = d->append(set);
353 if (success) {
345 if (success) {
354 QList<QBarSet *> sets;
346 QList<QBarSet *> sets;
355 sets.append(set);
347 sets.append(set);
356 set->setParent(this);
348 set->setParent(this);
357 emit barsetsAdded(sets);
349 emit barsetsAdded(sets);
358 emit countChanged();
350 emit countChanged();
359 }
351 }
360 return success;
352 return success;
361 }
353 }
362
354
363 /*!
355 /*!
364 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
356 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
365 was successful.
357 was successful.
366 Returns true, if set was removed.
358 Returns true, if set was removed.
367 */
359 */
368 bool QAbstractBarSeries::remove(QBarSet *set)
360 bool QAbstractBarSeries::remove(QBarSet *set)
369 {
361 {
370 Q_D(QAbstractBarSeries);
362 Q_D(QAbstractBarSeries);
371 bool success = d->remove(set);
363 bool success = d->remove(set);
372 if (success) {
364 if (success) {
373 QList<QBarSet *> sets;
365 QList<QBarSet *> sets;
374 sets.append(set);
366 sets.append(set);
375 set->setParent(0);
367 set->setParent(0);
376 emit barsetsRemoved(sets);
368 emit barsetsRemoved(sets);
377 emit countChanged();
369 emit countChanged();
378 delete set;
370 delete set;
379 set = 0;
371 set = 0;
380 }
372 }
381 return success;
373 return success;
382 }
374 }
383
375
384 /*!
376 /*!
385 Takes a single \a set from the series. Does not delete the barset object.
377 Takes a single \a set from the series. Does not delete the barset object.
386
378
387 NOTE: The series remains as the barset's parent object. You must set the
379 NOTE: The series remains as the barset's parent object. You must set the
388 parent object to take full ownership.
380 parent object to take full ownership.
389
381
390 Returns true if take was successful.
382 Returns true if take was successful.
391 */
383 */
392 bool QAbstractBarSeries::take(QBarSet *set)
384 bool QAbstractBarSeries::take(QBarSet *set)
393 {
385 {
394 Q_D(QAbstractBarSeries);
386 Q_D(QAbstractBarSeries);
395 bool success = d->remove(set);
387 bool success = d->remove(set);
396 if (success) {
388 if (success) {
397 QList<QBarSet *> sets;
389 QList<QBarSet *> sets;
398 sets.append(set);
390 sets.append(set);
399 emit barsetsRemoved(sets);
391 emit barsetsRemoved(sets);
400 emit countChanged();
392 emit countChanged();
401 }
393 }
402 return success;
394 return success;
403 }
395 }
404
396
405 /*!
397 /*!
406 Adds a list of barsets to series. Takes ownership of \a sets.
398 Adds a list of barsets to series. Takes ownership of \a sets.
407 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
399 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
408 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
400 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
409 and function returns false.
401 and function returns false.
410 */
402 */
411 bool QAbstractBarSeries::append(QList<QBarSet *> sets)
403 bool QAbstractBarSeries::append(QList<QBarSet *> sets)
412 {
404 {
413 Q_D(QAbstractBarSeries);
405 Q_D(QAbstractBarSeries);
414 bool success = d->append(sets);
406 bool success = d->append(sets);
415 if (success) {
407 if (success) {
416 emit barsetsAdded(sets);
408 emit barsetsAdded(sets);
417 emit countChanged();
409 emit countChanged();
418 }
410 }
419 return success;
411 return success;
420 }
412 }
421
413
422 /*!
414 /*!
423 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.
415 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.
424 Returns true, if inserting succeeded.
416 Returns true, if inserting succeeded.
425
417
426 */
418 */
427 bool QAbstractBarSeries::insert(int index, QBarSet *set)
419 bool QAbstractBarSeries::insert(int index, QBarSet *set)
428 {
420 {
429 Q_D(QAbstractBarSeries);
421 Q_D(QAbstractBarSeries);
430 bool success = d->insert(index, set);
422 bool success = d->insert(index, set);
431 if (success) {
423 if (success) {
432 QList<QBarSet *> sets;
424 QList<QBarSet *> sets;
433 sets.append(set);
425 sets.append(set);
434 emit barsetsAdded(sets);
426 emit barsetsAdded(sets);
435 emit countChanged();
427 emit countChanged();
436 }
428 }
437 return success;
429 return success;
438 }
430 }
439
431
440 /*!
432 /*!
441 Removes all barsets from the series. Deletes removed sets.
433 Removes all barsets from the series. Deletes removed sets.
442 */
434 */
443 void QAbstractBarSeries::clear()
435 void QAbstractBarSeries::clear()
444 {
436 {
445 Q_D(QAbstractBarSeries);
437 Q_D(QAbstractBarSeries);
446 QList<QBarSet *> sets = barSets();
438 QList<QBarSet *> sets = barSets();
447 bool success = d->remove(sets);
439 bool success = d->remove(sets);
448 if (success) {
440 if (success) {
449 emit barsetsRemoved(sets);
441 emit barsetsRemoved(sets);
450 emit countChanged();
442 emit countChanged();
451 foreach (QBarSet *set, sets)
443 foreach (QBarSet *set, sets)
452 delete set;
444 delete set;
453 }
445 }
454 }
446 }
455
447
456 /*!
448 /*!
457 Returns number of sets in series.
449 Returns number of sets in series.
458 */
450 */
459 int QAbstractBarSeries::count() const
451 int QAbstractBarSeries::count() const
460 {
452 {
461 Q_D(const QAbstractBarSeries);
453 Q_D(const QAbstractBarSeries);
462 return d->m_barSets.count();
454 return d->m_barSets.count();
463 }
455 }
464
456
465 /*!
457 /*!
466 Returns a list of sets in series. Keeps ownership of sets.
458 Returns a list of sets in series. Keeps ownership of sets.
467 */
459 */
468 QList<QBarSet *> QAbstractBarSeries::barSets() const
460 QList<QBarSet *> QAbstractBarSeries::barSets() const
469 {
461 {
470 Q_D(const QAbstractBarSeries);
462 Q_D(const QAbstractBarSeries);
471 return d->m_barSets;
463 return d->m_barSets;
472 }
464 }
473
465
474 /*!
466 /*!
475 Sets the visibility of labels in series to \a visible
467 Sets the visibility of labels in series to \a visible
476 */
468 */
477 void QAbstractBarSeries::setLabelsVisible(bool visible)
469 void QAbstractBarSeries::setLabelsVisible(bool visible)
478 {
470 {
479 Q_D(QAbstractBarSeries);
471 Q_D(QAbstractBarSeries);
480 if (d->m_labelsVisible != visible) {
472 if (d->m_labelsVisible != visible) {
481 d->setLabelsVisible(visible);
473 d->setLabelsVisible(visible);
482 emit labelsVisibleChanged();
474 emit labelsVisibleChanged();
483 }
475 }
484 }
476 }
485
477
486 /*!
478 /*!
487 Returns the visibility of labels
479 Returns the visibility of labels
488 */
480 */
489 bool QAbstractBarSeries::isLabelsVisible() const
481 bool QAbstractBarSeries::isLabelsVisible() const
490 {
482 {
491 Q_D(const QAbstractBarSeries);
483 Q_D(const QAbstractBarSeries);
492 return d->m_labelsVisible;
484 return d->m_labelsVisible;
493 }
485 }
494
486
495 void QAbstractBarSeries::setLabelsFormat(const QString &format)
487 void QAbstractBarSeries::setLabelsFormat(const QString &format)
496 {
488 {
497 Q_D(QAbstractBarSeries);
489 Q_D(QAbstractBarSeries);
498 if (d->m_labelsFormat != format) {
490 if (d->m_labelsFormat != format) {
499 d->m_labelsFormat = format;
491 d->m_labelsFormat = format;
500 emit labelsFormatChanged(format);
492 emit labelsFormatChanged(format);
501 }
493 }
502 }
494 }
503
495
504 QString QAbstractBarSeries::labelsFormat() const
496 QString QAbstractBarSeries::labelsFormat() const
505 {
497 {
506 Q_D(const QAbstractBarSeries);
498 Q_D(const QAbstractBarSeries);
507 return d->m_labelsFormat;
499 return d->m_labelsFormat;
508 }
500 }
509
501
510 void QAbstractBarSeries::setLabelsPosition(QAbstractBarSeries::LabelsPosition position)
502 void QAbstractBarSeries::setLabelsPosition(QAbstractBarSeries::LabelsPosition position)
511 {
503 {
512 Q_D(QAbstractBarSeries);
504 Q_D(QAbstractBarSeries);
513 if (d->m_labelsPosition != position) {
505 if (d->m_labelsPosition != position) {
514 d->m_labelsPosition = position;
506 d->m_labelsPosition = position;
515 emit labelsPositionChanged(position);
507 emit labelsPositionChanged(position);
516 }
508 }
517 }
509 }
518
510
519 QAbstractBarSeries::LabelsPosition QAbstractBarSeries::labelsPosition() const
511 QAbstractBarSeries::LabelsPosition QAbstractBarSeries::labelsPosition() const
520 {
512 {
521 Q_D(const QAbstractBarSeries);
513 Q_D(const QAbstractBarSeries);
522 return d->m_labelsPosition;
514 return d->m_labelsPosition;
523 }
515 }
524
516
525 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
517 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
526
518
527 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
519 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
528 QAbstractSeriesPrivate(q),
520 QAbstractSeriesPrivate(q),
529 m_barWidth(0.5), // Default value is 50% of category width
521 m_barWidth(0.5), // Default value is 50% of category width
530 m_labelsVisible(false),
522 m_labelsVisible(false),
531 m_visible(true),
523 m_visible(true),
532 m_blockBarUpdate(false),
524 m_blockBarUpdate(false),
533 m_labelsFormat(),
525 m_labelsFormat(),
534 m_labelsPosition(QAbstractBarSeries::LabelsCenter)
526 m_labelsPosition(QAbstractBarSeries::LabelsCenter)
535 {
527 {
536 }
528 }
537
529
538 int QAbstractBarSeriesPrivate::categoryCount() const
530 int QAbstractBarSeriesPrivate::categoryCount() const
539 {
531 {
540 // No categories defined. return count of longest set.
532 // No categories defined. return count of longest set.
541 int count = 0;
533 int count = 0;
542 for (int i = 0; i < m_barSets.count(); i++) {
534 for (int i = 0; i < m_barSets.count(); i++) {
543 if (m_barSets.at(i)->count() > count)
535 if (m_barSets.at(i)->count() > count)
544 count = m_barSets.at(i)->count();
536 count = m_barSets.at(i)->count();
545 }
537 }
546
538
547 return count;
539 return count;
548 }
540 }
549
541
550 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
542 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
551 {
543 {
552 if (width < 0.0)
544 if (width < 0.0)
553 width = 0.0;
545 width = 0.0;
554 m_barWidth = width;
546 m_barWidth = width;
555 emit updatedLayout();
547 emit updatedLayout();
556 }
548 }
557
549
558 qreal QAbstractBarSeriesPrivate::barWidth() const
550 qreal QAbstractBarSeriesPrivate::barWidth() const
559 {
551 {
560 return m_barWidth;
552 return m_barWidth;
561 }
553 }
562
554
563 QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index)
555 QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index)
564 {
556 {
565 return m_barSets.at(index);
557 return m_barSets.at(index);
566 }
558 }
567
559
568 void QAbstractBarSeriesPrivate::setVisible(bool visible)
560 void QAbstractBarSeriesPrivate::setVisible(bool visible)
569 {
561 {
570 m_visible = visible;
562 m_visible = visible;
571 emit visibleChanged();
563 emit visibleChanged();
572 }
564 }
573
565
574 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
566 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
575 {
567 {
576 m_labelsVisible = visible;
568 m_labelsVisible = visible;
577 emit labelsVisibleChanged(visible);
569 emit labelsVisibleChanged(visible);
578 }
570 }
579
571
580 qreal QAbstractBarSeriesPrivate::min()
572 qreal QAbstractBarSeriesPrivate::min()
581 {
573 {
582 if (m_barSets.count() <= 0)
574 if (m_barSets.count() <= 0)
583 return 0;
575 return 0;
584
576
585 qreal min = INT_MAX;
577 qreal min = INT_MAX;
586
578
587 for (int i = 0; i < m_barSets.count(); i++) {
579 for (int i = 0; i < m_barSets.count(); i++) {
588 int categoryCount = m_barSets.at(i)->count();
580 int categoryCount = m_barSets.at(i)->count();
589 for (int j = 0; j < categoryCount; j++) {
581 for (int j = 0; j < categoryCount; j++) {
590 qreal temp = m_barSets.at(i)->at(j);
582 qreal temp = m_barSets.at(i)->at(j);
591 if (temp < min)
583 if (temp < min)
592 min = temp;
584 min = temp;
593 }
585 }
594 }
586 }
595 return min;
587 return min;
596 }
588 }
597
589
598 qreal QAbstractBarSeriesPrivate::max()
590 qreal QAbstractBarSeriesPrivate::max()
599 {
591 {
600 if (m_barSets.count() <= 0)
592 if (m_barSets.count() <= 0)
601 return 0;
593 return 0;
602
594
603 qreal max = INT_MIN;
595 qreal max = INT_MIN;
604
596
605 for (int i = 0; i < m_barSets.count(); i++) {
597 for (int i = 0; i < m_barSets.count(); i++) {
606 int categoryCount = m_barSets.at(i)->count();
598 int categoryCount = m_barSets.at(i)->count();
607 for (int j = 0; j < categoryCount; j++) {
599 for (int j = 0; j < categoryCount; j++) {
608 qreal temp = m_barSets.at(i)->at(j);
600 qreal temp = m_barSets.at(i)->at(j);
609 if (temp > max)
601 if (temp > max)
610 max = temp;
602 max = temp;
611 }
603 }
612 }
604 }
613
605
614 return max;
606 return max;
615 }
607 }
616
608
617 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
609 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
618 {
610 {
619 if ((set < 0) || (set >= m_barSets.count()))
611 if ((set < 0) || (set >= m_barSets.count()))
620 return 0; // No set, no value.
612 return 0; // No set, no value.
621 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
613 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
622 return 0; // No category, no value.
614 return 0; // No category, no value.
623
615
624 return m_barSets.at(set)->at(category);
616 return m_barSets.at(set)->at(category);
625 }
617 }
626
618
627 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
619 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
628 {
620 {
629 if ((set < 0) || (set >= m_barSets.count()))
621 if ((set < 0) || (set >= m_barSets.count()))
630 return 0; // No set, no value.
622 return 0; // No set, no value.
631 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
623 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
632 return 0; // No category, no value.
624 return 0; // No category, no value.
633
625
634 qreal value = m_barSets.at(set)->at(category);
626 qreal value = m_barSets.at(set)->at(category);
635 qreal sum = categorySum(category);
627 qreal sum = categorySum(category);
636 if (qFuzzyCompare(sum, 0))
628 if (qFuzzyCompare(sum, 0))
637 return 0;
629 return 0;
638
630
639 return value / sum;
631 return value / sum;
640 }
632 }
641
633
642 qreal QAbstractBarSeriesPrivate::categorySum(int category)
634 qreal QAbstractBarSeriesPrivate::categorySum(int category)
643 {
635 {
644 qreal sum(0);
636 qreal sum(0);
645 int count = m_barSets.count(); // Count sets
637 int count = m_barSets.count(); // Count sets
646 for (int set = 0; set < count; set++) {
638 for (int set = 0; set < count; set++) {
647 if (category < m_barSets.at(set)->count())
639 if (category < m_barSets.at(set)->count())
648 sum += m_barSets.at(set)->at(category);
640 sum += m_barSets.at(set)->at(category);
649 }
641 }
650 return sum;
642 return sum;
651 }
643 }
652
644
653 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
645 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
654 {
646 {
655 qreal sum(0);
647 qreal sum(0);
656 int count = m_barSets.count(); // Count sets
648 int count = m_barSets.count(); // Count sets
657 for (int set = 0; set < count; set++) {
649 for (int set = 0; set < count; set++) {
658 if (category < m_barSets.at(set)->count())
650 if (category < m_barSets.at(set)->count())
659 sum += qAbs(m_barSets.at(set)->at(category));
651 sum += qAbs(m_barSets.at(set)->at(category));
660 }
652 }
661 return sum;
653 return sum;
662 }
654 }
663
655
664 qreal QAbstractBarSeriesPrivate::maxCategorySum()
656 qreal QAbstractBarSeriesPrivate::maxCategorySum()
665 {
657 {
666 qreal max = INT_MIN;
658 qreal max = INT_MIN;
667 int count = categoryCount();
659 int count = categoryCount();
668 for (int i = 0; i < count; i++) {
660 for (int i = 0; i < count; i++) {
669 qreal sum = categorySum(i);
661 qreal sum = categorySum(i);
670 if (sum > max)
662 if (sum > max)
671 max = sum;
663 max = sum;
672 }
664 }
673 return max;
665 return max;
674 }
666 }
675
667
676 qreal QAbstractBarSeriesPrivate::minX()
668 qreal QAbstractBarSeriesPrivate::minX()
677 {
669 {
678 if (m_barSets.count() <= 0)
670 if (m_barSets.count() <= 0)
679 return 0;
671 return 0;
680
672
681 qreal min = INT_MAX;
673 qreal min = INT_MAX;
682
674
683 for (int i = 0; i < m_barSets.count(); i++) {
675 for (int i = 0; i < m_barSets.count(); i++) {
684 int categoryCount = m_barSets.at(i)->count();
676 int categoryCount = m_barSets.at(i)->count();
685 for (int j = 0; j < categoryCount; j++) {
677 for (int j = 0; j < categoryCount; j++) {
686 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
678 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
687 if (temp < min)
679 if (temp < min)
688 min = temp;
680 min = temp;
689 }
681 }
690 }
682 }
691 return min;
683 return min;
692 }
684 }
693
685
694 qreal QAbstractBarSeriesPrivate::maxX()
686 qreal QAbstractBarSeriesPrivate::maxX()
695 {
687 {
696 if (m_barSets.count() <= 0)
688 if (m_barSets.count() <= 0)
697 return 0;
689 return 0;
698
690
699 qreal max = INT_MIN;
691 qreal max = INT_MIN;
700
692
701 for (int i = 0; i < m_barSets.count(); i++) {
693 for (int i = 0; i < m_barSets.count(); i++) {
702 int categoryCount = m_barSets.at(i)->count();
694 int categoryCount = m_barSets.at(i)->count();
703 for (int j = 0; j < categoryCount; j++) {
695 for (int j = 0; j < categoryCount; j++) {
704 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
696 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
705 if (temp > max)
697 if (temp > max)
706 max = temp;
698 max = temp;
707 }
699 }
708 }
700 }
709
701
710 return max;
702 return max;
711 }
703 }
712
704
713 qreal QAbstractBarSeriesPrivate::categoryTop(int category)
705 qreal QAbstractBarSeriesPrivate::categoryTop(int category)
714 {
706 {
715 // Returns top (sum of all positive values) of category.
707 // Returns top (sum of all positive values) of category.
716 // Returns 0, if all values are negative
708 // Returns 0, if all values are negative
717 qreal top(0);
709 qreal top(0);
718 int count = m_barSets.count();
710 int count = m_barSets.count();
719 for (int set = 0; set < count; set++) {
711 for (int set = 0; set < count; set++) {
720 if (category < m_barSets.at(set)->count()) {
712 if (category < m_barSets.at(set)->count()) {
721 qreal temp = m_barSets.at(set)->at(category);
713 qreal temp = m_barSets.at(set)->at(category);
722 if (temp > 0) {
714 if (temp > 0) {
723 top += temp;
715 top += temp;
724 }
716 }
725 }
717 }
726 }
718 }
727 return top;
719 return top;
728 }
720 }
729
721
730 qreal QAbstractBarSeriesPrivate::categoryBottom(int category)
722 qreal QAbstractBarSeriesPrivate::categoryBottom(int category)
731 {
723 {
732 // Returns bottom (sum of all negative values) of category
724 // Returns bottom (sum of all negative values) of category
733 // Returns 0, if all values are positive
725 // Returns 0, if all values are positive
734 qreal bottom(0);
726 qreal bottom(0);
735 int count = m_barSets.count();
727 int count = m_barSets.count();
736 for (int set = 0; set < count; set++) {
728 for (int set = 0; set < count; set++) {
737 if (category < m_barSets.at(set)->count()) {
729 if (category < m_barSets.at(set)->count()) {
738 qreal temp = m_barSets.at(set)->at(category);
730 qreal temp = m_barSets.at(set)->at(category);
739 if (temp < 0) {
731 if (temp < 0) {
740 bottom += temp;
732 bottom += temp;
741 }
733 }
742 }
734 }
743 }
735 }
744 return bottom;
736 return bottom;
745 }
737 }
746
738
747 qreal QAbstractBarSeriesPrivate::top()
739 qreal QAbstractBarSeriesPrivate::top()
748 {
740 {
749 // Returns top of all categories
741 // Returns top of all categories
750 qreal top(0);
742 qreal top(0);
751 int count = categoryCount();
743 int count = categoryCount();
752 for (int i = 0; i < count; i++) {
744 for (int i = 0; i < count; i++) {
753 qreal temp = categoryTop(i);
745 qreal temp = categoryTop(i);
754 if (temp > top)
746 if (temp > top)
755 top = temp;
747 top = temp;
756 }
748 }
757 return top;
749 return top;
758 }
750 }
759
751
760 qreal QAbstractBarSeriesPrivate::bottom()
752 qreal QAbstractBarSeriesPrivate::bottom()
761 {
753 {
762 // Returns bottom of all categories
754 // Returns bottom of all categories
763 qreal bottom(0);
755 qreal bottom(0);
764 int count = categoryCount();
756 int count = categoryCount();
765 for (int i = 0; i < count; i++) {
757 for (int i = 0; i < count; i++) {
766 qreal temp = categoryBottom(i);
758 qreal temp = categoryBottom(i);
767 if (temp < bottom)
759 if (temp < bottom)
768 bottom = temp;
760 bottom = temp;
769 }
761 }
770 return bottom;
762 return bottom;
771 }
763 }
772
764
773 bool QAbstractBarSeriesPrivate::blockBarUpdate()
765 bool QAbstractBarSeriesPrivate::blockBarUpdate()
774 {
766 {
775 return m_blockBarUpdate;
767 return m_blockBarUpdate;
776 }
768 }
777
769
778 void QAbstractBarSeriesPrivate::initializeDomain()
770 void QAbstractBarSeriesPrivate::initializeDomain()
779 {
771 {
780 qreal minX(domain()->minX());
772 qreal minX(domain()->minX());
781 qreal minY(domain()->minY());
773 qreal minY(domain()->minY());
782 qreal maxX(domain()->maxX());
774 qreal maxX(domain()->maxX());
783 qreal maxY(domain()->maxY());
775 qreal maxY(domain()->maxY());
784
776
785 qreal seriesMinX = this->minX();
777 qreal seriesMinX = this->minX();
786 qreal seriesMaxX = this->maxX();
778 qreal seriesMaxX = this->maxX();
787 qreal y = max();
779 qreal y = max();
788 minX = qMin(minX, seriesMinX - (qreal)0.5);
780 minX = qMin(minX, seriesMinX - (qreal)0.5);
789 minY = qMin(minY, y);
781 minY = qMin(minY, y);
790 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
782 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
791 maxY = qMax(maxY, y);
783 maxY = qMax(maxY, y);
792
784
793 domain()->setRange(minX, maxX, minY, maxY);
785 domain()->setRange(minX, maxX, minY, maxY);
794 }
786 }
795
787
796 QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend)
788 QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend)
797 {
789 {
798 Q_Q(QAbstractBarSeries);
790 Q_Q(QAbstractBarSeries);
799 QList<QLegendMarker*> markers;
791 QList<QLegendMarker*> markers;
800
792
801 foreach(QBarSet* set, q->barSets()) {
793 foreach(QBarSet* set, q->barSets()) {
802 QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend);
794 QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend);
803 markers << marker;
795 markers << marker;
804 }
796 }
805 return markers;
797 return markers;
806 }
798 }
807
799
808
800
809 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
801 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
810 {
802 {
811 if ((m_barSets.contains(set)) || (set == 0))
803 if ((m_barSets.contains(set)) || (set == 0))
812 return false; // Fail if set is already in list or set is null.
804 return false; // Fail if set is already in list or set is null.
813
805
814 m_barSets.append(set);
806 m_barSets.append(set);
815 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
807 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
816 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
808 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
817 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
809 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
818
810
819 emit restructuredBars(); // this notifies barchartitem
811 emit restructuredBars(); // this notifies barchartitem
820 return true;
812 return true;
821 }
813 }
822
814
823 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
815 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
824 {
816 {
825 if (!m_barSets.contains(set))
817 if (!m_barSets.contains(set))
826 return false; // Fail if set is not in list
818 return false; // Fail if set is not in list
827
819
828 m_barSets.removeOne(set);
820 m_barSets.removeOne(set);
829 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
821 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
830 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
822 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
831 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
823 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
832
824
833 emit restructuredBars(); // this notifies barchartitem
825 emit restructuredBars(); // this notifies barchartitem
834 return true;
826 return true;
835 }
827 }
836
828
837 bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets)
829 bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets)
838 {
830 {
839 foreach (QBarSet *set, sets) {
831 foreach (QBarSet *set, sets) {
840 if ((set == 0) || (m_barSets.contains(set)))
832 if ((set == 0) || (m_barSets.contains(set)))
841 return false; // Fail if any of the sets is null or is already appended.
833 return false; // Fail if any of the sets is null or is already appended.
842 if (sets.count(set) != 1)
834 if (sets.count(set) != 1)
843 return false; // Also fail if same set is more than once in given list.
835 return false; // Also fail if same set is more than once in given list.
844 }
836 }
845
837
846 foreach (QBarSet *set, sets) {
838 foreach (QBarSet *set, sets) {
847 m_barSets.append(set);
839 m_barSets.append(set);
848 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
840 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
849 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
841 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
850 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
842 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
851 }
843 }
852
844
853 emit restructuredBars(); // this notifies barchartitem
845 emit restructuredBars(); // this notifies barchartitem
854 return true;
846 return true;
855 }
847 }
856
848
857 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets)
849 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets)
858 {
850 {
859 if (sets.count() == 0)
851 if (sets.count() == 0)
860 return false;
852 return false;
861
853
862 foreach (QBarSet *set, sets) {
854 foreach (QBarSet *set, sets) {
863 if ((set == 0) || (!m_barSets.contains(set)))
855 if ((set == 0) || (!m_barSets.contains(set)))
864 return false; // Fail if any of the sets is null or is not in series
856 return false; // Fail if any of the sets is null or is not in series
865 if (sets.count(set) != 1)
857 if (sets.count(set) != 1)
866 return false; // Also fail if same set is more than once in given list.
858 return false; // Also fail if same set is more than once in given list.
867 }
859 }
868
860
869 foreach (QBarSet *set, sets) {
861 foreach (QBarSet *set, sets) {
870 m_barSets.removeOne(set);
862 m_barSets.removeOne(set);
871 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
863 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
872 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
864 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
873 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
865 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
874 }
866 }
875
867
876 emit restructuredBars(); // this notifies barchartitem
868 emit restructuredBars(); // this notifies barchartitem
877
869
878 return true;
870 return true;
879 }
871 }
880
872
881 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
873 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
882 {
874 {
883 if ((m_barSets.contains(set)) || (set == 0))
875 if ((m_barSets.contains(set)) || (set == 0))
884 return false; // Fail if set is already in list or set is null.
876 return false; // Fail if set is already in list or set is null.
885
877
886 m_barSets.insert(index, set);
878 m_barSets.insert(index, set);
887 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
879 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
888 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
880 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
889 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
881 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
890
882
891 emit restructuredBars(); // this notifies barchartitem
883 emit restructuredBars(); // this notifies barchartitem
892 return true;
884 return true;
893 }
885 }
894
886
895 void QAbstractBarSeriesPrivate::initializeAxes()
887 void QAbstractBarSeriesPrivate::initializeAxes()
896 {
888 {
897 Q_Q(QAbstractBarSeries);
889 Q_Q(QAbstractBarSeries);
898
890
899 foreach(QAbstractAxis* axis, m_axes) {
891 foreach(QAbstractAxis* axis, m_axes) {
900
892
901 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
893 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
902 switch (q->type()) {
894 switch (q->type()) {
903 case QAbstractSeries::SeriesTypeHorizontalBar:
895 case QAbstractSeries::SeriesTypeHorizontalBar:
904 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
896 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
905 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
897 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
906 if (axis->orientation() == Qt::Vertical)
898 if (axis->orientation() == Qt::Vertical)
907 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
899 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
908 break;
900 break;
909 case QAbstractSeries::SeriesTypeBar:
901 case QAbstractSeries::SeriesTypeBar:
910 case QAbstractSeries::SeriesTypePercentBar:
902 case QAbstractSeries::SeriesTypePercentBar:
911 case QAbstractSeries::SeriesTypeStackedBar:
903 case QAbstractSeries::SeriesTypeStackedBar:
912 case QAbstractSeries::SeriesTypeBoxPlot:
904 case QAbstractSeries::SeriesTypeBoxPlot:
913 if (axis->orientation() == Qt::Horizontal)
905 if (axis->orientation() == Qt::Horizontal)
914 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
906 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
915 break;
907 break;
916 default:
908 default:
917 qWarning() << "Unexpected series type";
909 qWarning() << "Unexpected series type";
918 break;
910 break;
919 }
911 }
920 }
912 }
921 }
913 }
922 }
914 }
923
915
924 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
916 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
925 {
917 {
926 Q_Q(const QAbstractBarSeries);
918 Q_Q(const QAbstractBarSeries);
927
919
928 switch (q->type()) {
920 switch (q->type()) {
929 case QAbstractSeries::SeriesTypeHorizontalBar:
921 case QAbstractSeries::SeriesTypeHorizontalBar:
930 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
922 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
931 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
923 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
932 if (orientation == Qt::Vertical)
924 if (orientation == Qt::Vertical)
933 return QAbstractAxis::AxisTypeBarCategory;
925 return QAbstractAxis::AxisTypeBarCategory;
934 break;
926 break;
935 case QAbstractSeries::SeriesTypeBar:
927 case QAbstractSeries::SeriesTypeBar:
936 case QAbstractSeries::SeriesTypePercentBar:
928 case QAbstractSeries::SeriesTypePercentBar:
937 case QAbstractSeries::SeriesTypeStackedBar:
929 case QAbstractSeries::SeriesTypeStackedBar:
938 case QAbstractSeries::SeriesTypeBoxPlot:
930 case QAbstractSeries::SeriesTypeBoxPlot:
939 if (orientation == Qt::Horizontal)
931 if (orientation == Qt::Horizontal)
940 return QAbstractAxis::AxisTypeBarCategory;
932 return QAbstractAxis::AxisTypeBarCategory;
941 break;
933 break;
942 default:
934 default:
943 qWarning() << "Unexpected series type";
935 qWarning() << "Unexpected series type";
944 break;
936 break;
945 }
937 }
946 return QAbstractAxis::AxisTypeValue;
938 return QAbstractAxis::AxisTypeValue;
947
939
948 }
940 }
949
941
950 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
942 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
951 {
943 {
952 QStringList categories;
944 QStringList categories;
953 if (axis->categories().isEmpty()) {
945 if (axis->categories().isEmpty()) {
954 for (int i(1); i < categoryCount() + 1; i++)
946 for (int i(1); i < categoryCount() + 1; i++)
955 categories << presenter()->numberToString(i);
947 categories << presenter()->numberToString(i);
956 axis->append(categories);
948 axis->append(categories);
957 }
949 }
958 }
950 }
959
951
960 QAbstractAxis* QAbstractBarSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
952 QAbstractAxis* QAbstractBarSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
961 {
953 {
962 if (defaultAxisType(orientation) == QAbstractAxis::AxisTypeBarCategory)
954 if (defaultAxisType(orientation) == QAbstractAxis::AxisTypeBarCategory)
963 return new QBarCategoryAxis;
955 return new QBarCategoryAxis;
964 else
956 else
965 return new QValueAxis;
957 return new QValueAxis;
966 }
958 }
967
959
968 void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
960 void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
969 {
961 {
970 m_blockBarUpdate = true; // Ensures that the bars are not updated before the theme is ready
962 m_blockBarUpdate = true; // Ensures that the bars are not updated before the theme is ready
971
963
972 const QList<QGradient> gradients = theme->seriesGradients();
964 const QList<QGradient> gradients = theme->seriesGradients();
973
965
974 qreal takeAtPos = 0.5;
966 qreal takeAtPos = 0.5;
975 qreal step = 0.2;
967 qreal step = 0.2;
976 if (m_barSets.count() > 1) {
968 if (m_barSets.count() > 1) {
977 step = 1.0 / (qreal) m_barSets.count();
969 step = 1.0 / (qreal) m_barSets.count();
978 if (m_barSets.count() % gradients.count())
970 if (m_barSets.count() % gradients.count())
979 step *= gradients.count();
971 step *= gradients.count();
980 else
972 else
981 step *= (gradients.count() - 1);
973 step *= (gradients.count() - 1);
982 }
974 }
983
975
984 for (int i(0); i < m_barSets.count(); i++) {
976 for (int i(0); i < m_barSets.count(); i++) {
985 int colorIndex = (index + i) % gradients.count();
977 int colorIndex = (index + i) % gradients.count();
986 if (i > 0 && i %gradients.count() == 0) {
978 if (i > 0 && i %gradients.count() == 0) {
987 // There is no dedicated base color for each sets, generate more colors
979 // There is no dedicated base color for each sets, generate more colors
988 takeAtPos += step;
980 takeAtPos += step;
989 if (takeAtPos == 1.0)
981 if (takeAtPos == 1.0)
990 takeAtPos += step;
982 takeAtPos += step;
991 takeAtPos -= (int) takeAtPos;
983 takeAtPos -= (int) takeAtPos;
992 }
984 }
993 if (forced || QChartPrivate::defaultBrush() == m_barSets.at(i)->d_ptr->m_brush)
985 if (forced || QChartPrivate::defaultBrush() == m_barSets.at(i)->d_ptr->m_brush)
994 m_barSets.at(i)->setBrush(ChartThemeManager::colorAt(gradients.at(colorIndex), takeAtPos));
986 m_barSets.at(i)->setBrush(ChartThemeManager::colorAt(gradients.at(colorIndex), takeAtPos));
995
987
996 // Pick label color from the opposite end of the gradient.
988 // Pick label color from the opposite end of the gradient.
997 // 0.3 as a boundary seems to work well.
989 // 0.3 as a boundary seems to work well.
998 if (forced || QChartPrivate::defaultBrush() == m_barSets.at(i)->d_ptr->m_labelBrush) {
990 if (forced || QChartPrivate::defaultBrush() == m_barSets.at(i)->d_ptr->m_labelBrush) {
999 if (takeAtPos < 0.3)
991 if (takeAtPos < 0.3)
1000 m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 1));
992 m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 1));
1001 else
993 else
1002 m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0));
994 m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0));
1003 }
995 }
1004 if (forced || QChartPrivate::defaultPen() == m_barSets.at(i)->d_ptr->m_pen) {
996 if (forced || QChartPrivate::defaultPen() == m_barSets.at(i)->d_ptr->m_pen) {
1005 QColor c = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0);
997 QColor c = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0);
1006 m_barSets.at(i)->setPen(c);
998 m_barSets.at(i)->setPen(c);
1007 }
999 }
1008 }
1000 }
1009 m_blockBarUpdate = false;
1001 m_blockBarUpdate = false;
1010 emit updatedBars();
1002 emit updatedBars();
1011 }
1003 }
1012
1004
1013 void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
1005 void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
1014 {
1006 {
1015 AbstractBarChartItem *bar = static_cast<AbstractBarChartItem *>(m_item.data());
1007 AbstractBarChartItem *bar = static_cast<AbstractBarChartItem *>(m_item.data());
1016 Q_ASSERT(bar);
1008 Q_ASSERT(bar);
1017 if (bar->animation())
1009 if (bar->animation())
1018 bar->animation()->stopAndDestroyLater();
1010 bar->animation()->stopAndDestroyLater();
1019
1011
1020 if (options.testFlag(QChart::SeriesAnimations))
1012 if (options.testFlag(QChart::SeriesAnimations))
1021 bar->setAnimation(new BarAnimation(bar));
1013 bar->setAnimation(new BarAnimation(bar));
1022 else
1014 else
1023 bar->setAnimation(0);
1015 bar->setAnimation(0);
1024 QAbstractSeriesPrivate::initializeAnimations(options);
1016 QAbstractSeriesPrivate::initializeAnimations(options);
1025 }
1017 }
1026
1018
1027 #include "moc_qabstractbarseries.cpp"
1019 #include "moc_qabstractbarseries.cpp"
1028 #include "moc_qabstractbarseries_p.cpp"
1020 #include "moc_qabstractbarseries_p.cpp"
1029
1021
1030 QT_CHARTS_END_NAMESPACE
1022 QT_CHARTS_END_NAMESPACE
@@ -1,105 +1,104
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 QABSTRACTBARSERIES_H
21 #ifndef QABSTRACTBARSERIES_H
22 #define QABSTRACTBARSERIES_H
22 #define QABSTRACTBARSERIES_H
23
23
24 #include <QtCharts/QAbstractSeries>
24 #include <QtCharts/QAbstractSeries>
25 #include <QtCore/QStringList>
25 #include <QtCore/QStringList>
26
26
27 QT_CHARTS_BEGIN_NAMESPACE
27 QT_CHARTS_BEGIN_NAMESPACE
28
28
29 class QBarSet;
29 class QBarSet;
30 class QAbstractBarSeriesPrivate;
30 class QAbstractBarSeriesPrivate;
31
31
32 // Container for series
32 // Container for series
33 class QT_CHARTS_EXPORT QAbstractBarSeries : public QAbstractSeries
33 class QT_CHARTS_EXPORT QAbstractBarSeries : 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 Q_PROPERTY(QString labelsFormat READ labelsFormat WRITE setLabelsFormat NOTIFY labelsFormatChanged)
39 Q_PROPERTY(QString labelsFormat READ labelsFormat WRITE setLabelsFormat NOTIFY labelsFormatChanged)
40 Q_PROPERTY(LabelsPosition labelsPosition READ labelsPosition WRITE setLabelsPosition NOTIFY labelsPositionChanged)
40 Q_PROPERTY(LabelsPosition labelsPosition READ labelsPosition WRITE setLabelsPosition NOTIFY labelsPositionChanged)
41 Q_ENUMS(LabelsPosition)
41 Q_ENUMS(LabelsPosition)
42
42
43 public:
43 public:
44 enum LabelsPosition {
44 enum LabelsPosition {
45 LabelsCenter = 0,
45 LabelsCenter = 0,
46 LabelsInsideEnd,
46 LabelsInsideEnd,
47 LabelsInsideBase,
47 LabelsInsideBase,
48 LabelsOutsideEnd
48 LabelsOutsideEnd
49 };
49 };
50
50
51 public:
51 public:
52 virtual ~QAbstractBarSeries();
52 virtual ~QAbstractBarSeries();
53
53
54 void setBarWidth(qreal width);
54 void setBarWidth(qreal width);
55 qreal barWidth() const;
55 qreal barWidth() const;
56
56
57 bool append(QBarSet *set);
57 bool append(QBarSet *set);
58 bool remove(QBarSet *set);
58 bool remove(QBarSet *set);
59 bool take(QBarSet *set);
59 bool take(QBarSet *set);
60 bool append(QList<QBarSet *> sets);
60 bool append(QList<QBarSet *> sets);
61 bool insert(int index, QBarSet *set);
61 bool insert(int index, QBarSet *set);
62 int count() const;
62 int count() const;
63 QList<QBarSet *> barSets() const;
63 QList<QBarSet *> barSets() const;
64 void clear();
64 void clear();
65
65
66 void setLabelsVisible(bool visible = true);
66 void setLabelsVisible(bool visible = true);
67 bool isLabelsVisible() const;
67 bool isLabelsVisible() const;
68
68
69 void setLabelsFormat(const QString &format);
69 void setLabelsFormat(const QString &format);
70 QString labelsFormat() const;
70 QString labelsFormat() const;
71
71
72 void setLabelsPosition(QAbstractBarSeries::LabelsPosition position);
72 void setLabelsPosition(QAbstractBarSeries::LabelsPosition position);
73 QAbstractBarSeries::LabelsPosition labelsPosition() const;
73 QAbstractBarSeries::LabelsPosition labelsPosition() const;
74
74
75 protected:
75 protected:
76 explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent = 0);
76 explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent = 0);
77
77
78 Q_SIGNALS:
78 Q_SIGNALS:
79 void clicked(int index, QBarSet *barset);
79 void clicked(int index, QBarSet *barset);
80 void hovered(bool status, QBarSet *barset);
81 void hovered(bool status, int index, QBarSet *barset);
80 void hovered(bool status, int index, QBarSet *barset);
82 void countChanged();
81 void countChanged();
83 void labelsVisibleChanged();
82 void labelsVisibleChanged();
84 void labelsFormatChanged(const QString &format);
83 void labelsFormatChanged(const QString &format);
85 void labelsPositionChanged(QAbstractBarSeries::LabelsPosition position);
84 void labelsPositionChanged(QAbstractBarSeries::LabelsPosition position);
86
85
87 void barsetsAdded(QList<QBarSet *> sets);
86 void barsetsAdded(QList<QBarSet *> sets);
88 void barsetsRemoved(QList<QBarSet *> sets);
87 void barsetsRemoved(QList<QBarSet *> sets);
89
88
90 protected:
89 protected:
91 Q_DECLARE_PRIVATE(QAbstractBarSeries)
90 Q_DECLARE_PRIVATE(QAbstractBarSeries)
92 friend class AbstractBarChartItem;
91 friend class AbstractBarChartItem;
93 friend class PercentBarChartItem;
92 friend class PercentBarChartItem;
94 friend class StackedBarChartItem;
93 friend class StackedBarChartItem;
95 friend class BoxPlotChartItem;
94 friend class BoxPlotChartItem;
96 friend class BarChartItem;
95 friend class BarChartItem;
97 friend class HorizontalBarChartItem;
96 friend class HorizontalBarChartItem;
98 friend class HorizontalStackedBarChartItem;
97 friend class HorizontalStackedBarChartItem;
99 friend class HorizontalPercentBarChartItem;
98 friend class HorizontalPercentBarChartItem;
100 friend class BarSet;
99 friend class BarSet;
101 };
100 };
102
101
103 QT_CHARTS_END_NAMESPACE
102 QT_CHARTS_END_NAMESPACE
104
103
105 #endif // QABSTRACTBARSERIES_H
104 #endif // QABSTRACTBARSERIES_H
@@ -1,676 +1,669
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 <QtCharts/QBarSet>
21 #include <QtCharts/QBarSet>
22 #include <private/qbarset_p.h>
22 #include <private/qbarset_p.h>
23 #include <private/charthelpers_p.h>
23 #include <private/charthelpers_p.h>
24 #include <private/qchart_p.h>
24 #include <private/qchart_p.h>
25
25
26 QT_CHARTS_BEGIN_NAMESPACE
26 QT_CHARTS_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QBarSet
29 \class QBarSet
30 \inmodule Qt Charts
30 \inmodule Qt Charts
31 \brief Building block for different bar charts.
31 \brief Building block for different bar charts.
32
32
33 QBarSet represents one set of bars. Set of bars contains one data value for each category.
33 QBarSet represents one set of bars. Set of bars contains one data value for each category.
34 First value of set is assumed to belong to first category, second to second category and so on.
34 First value of set is assumed to belong to first category, second to second category and so on.
35 If set has fewer values than there are categories, then the missing values are assumed to be
35 If set has fewer values than there are categories, then the missing values are assumed to be
36 at the end of set. For missing values in middle of a set, numerical value of zero is used.
36 at the end of set. For missing values in middle of a set, numerical value of zero is used.
37
37
38 \mainclass
38 \mainclass
39
39
40 \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries
40 \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries
41 */
41 */
42 /*!
42 /*!
43 \qmltype BarSet
43 \qmltype BarSet
44 \instantiates QBarSet
44 \instantiates QBarSet
45 \inqmlmodule QtCharts
45 \inqmlmodule QtCharts
46
46
47 \brief Building block for different bar charts.
47 \brief Building block for different bar charts.
48
48
49 BarSet represents one set of bars. Set of bars contains one data value for each category.
49 BarSet represents one set of bars. Set of bars contains one data value for each category.
50 First value of set is assumed to belong to first category, second to second category and so on.
50 First value of set is assumed to belong to first category, second to second category and so on.
51 If set has fewer values than there are categories, then the missing values are assumed to be
51 If set has fewer values than there are categories, then the missing values are assumed to be
52 at the end of set. For missing values in middle of a set, numerical value of zero is used.
52 at the end of set. For missing values in middle of a set, numerical value of zero is used.
53 \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries
53 \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries
54 */
54 */
55
55
56 /*!
56 /*!
57 \property QBarSet::label
57 \property QBarSet::label
58 Defines the label of the bar set.
58 Defines the label of the bar set.
59 */
59 */
60 /*!
60 /*!
61 \qmlproperty string BarSet::label
61 \qmlproperty string BarSet::label
62 Defines the label of the bar set.
62 Defines the label of the bar set.
63 */
63 */
64
64
65 /*!
65 /*!
66 \property QBarSet::pen
66 \property QBarSet::pen
67 \brief Defines the pen used by the bar set.
67 \brief Defines the pen used by the bar set.
68 */
68 */
69
69
70 /*!
70 /*!
71 \property QBarSet::brush
71 \property QBarSet::brush
72 \brief Defines the brush used by the bar set.
72 \brief Defines the brush used by the bar set.
73 */
73 */
74
74
75 /*!
75 /*!
76 \qmlproperty QString BarSet::brushFilename
76 \qmlproperty QString BarSet::brushFilename
77 The name of the file used as a brush for the set.
77 The name of the file used as a brush for the set.
78 */
78 */
79
79
80 /*!
80 /*!
81 \property QBarSet::labelBrush
81 \property QBarSet::labelBrush
82 \brief Defines the brush used by the bar set's label.
82 \brief Defines the brush used by the bar set's label.
83 */
83 */
84
84
85 /*!
85 /*!
86 \property QBarSet::labelFont
86 \property QBarSet::labelFont
87 \brief Defines the font used by the bar set's label.
87 \brief Defines the font used by the bar set's label.
88 */
88 */
89
89
90 /*!
90 /*!
91 \qmlproperty Font BarSet::labelFont
91 \qmlproperty Font BarSet::labelFont
92 Defines the font used by the bar set's label.
92 Defines the font used by the bar set's label.
93
93
94 See the Qt documentation for more details of Font.
94 See the Qt documentation for more details of Font.
95 */
95 */
96
96
97 /*!
97 /*!
98 \property QBarSet::color
98 \property QBarSet::color
99 The fill (brush) color of the bar set.
99 The fill (brush) color of the bar set.
100 */
100 */
101 /*!
101 /*!
102 \qmlproperty color BarSet::color
102 \qmlproperty color BarSet::color
103 The fill (brush) color of the bar set.
103 The fill (brush) color of the bar set.
104 */
104 */
105
105
106 /*!
106 /*!
107 \property QBarSet::borderColor
107 \property QBarSet::borderColor
108 The line (pen) color of the bar set.
108 The line (pen) color of the bar set.
109 */
109 */
110 /*!
110 /*!
111 \qmlproperty color BarSet::borderColor
111 \qmlproperty color BarSet::borderColor
112 The line (pen) color of the bar set.
112 The line (pen) color of the bar set.
113 */
113 */
114
114
115 /*!
115 /*!
116 \qmlproperty real BarSet::borderWidth
116 \qmlproperty real BarSet::borderWidth
117 The width of the border line. By default the width is 2.0.
117 The width of the border line. By default the width is 2.0.
118 */
118 */
119
119
120 /*!
120 /*!
121 \property QBarSet::labelColor
121 \property QBarSet::labelColor
122 The text (label) color of the bar set.
122 The text (label) color of the bar set.
123 */
123 */
124 /*!
124 /*!
125 \qmlproperty color BarSet::labelColor
125 \qmlproperty color BarSet::labelColor
126 The text (label) color of the bar set.
126 The text (label) color of the bar set.
127 */
127 */
128
128
129 /*!
129 /*!
130 \fn void QBarSet::clicked(int index)
130 \fn void QBarSet::clicked(int index)
131
131
132 The signal is emitted if the user clicks with a mouse on top of bar set.
132 The signal is emitted if the user clicks with a mouse on top of bar set.
133 Clicked bar inside set is indexed by \a index
133 Clicked bar inside set is indexed by \a index
134 */
134 */
135
135
136 /*!
136 /*!
137 \fn void QBarSet::hovered(bool status)
138
139 The signal is emitted if mouse is hovered on top of bar set.
140 Parameter \a status is true, if mouse entered on top of bar set, false if mouse left from top of bar set.
141 */
142
143 /*!
144 \fn void QBarSet::hovered(bool status, int index)
137 \fn void QBarSet::hovered(bool status, int index)
145
138
146 The signal is emitted if mouse is hovered on top of bar set.
139 The signal is emitted if mouse is hovered on top of bar set.
147 Parameter \a status is true, if mouse entered on top of bar set, false if mouse left from top of bar set.
140 Parameter \a status is true, if mouse entered on top of bar set, false if mouse left from top of bar set.
148 Hovered bar inside the set is indexed by \a index.
141 Hovered bar inside the set is indexed by \a index.
149 */
142 */
150
143
151
144
152 /*!
145 /*!
153 \fn void QBarSet::labelChanged()
146 \fn void QBarSet::labelChanged()
154 This signal is emitted when the label of the bar set has changed.
147 This signal is emitted when the label of the bar set has changed.
155 \sa label
148 \sa label
156 */
149 */
157 /*!
150 /*!
158 \qmlsignal BarSet::onLabelChanged()
151 \qmlsignal BarSet::onLabelChanged()
159 This signal is emitted when the label of the bar set has changed.
152 This signal is emitted when the label of the bar set has changed.
160 */
153 */
161
154
162 /*!
155 /*!
163 \fn void QBarSet::penChanged()
156 \fn void QBarSet::penChanged()
164 This signal is emitted when the pen of the bar set has changed.
157 This signal is emitted when the pen of the bar set has changed.
165 \sa pen
158 \sa pen
166 */
159 */
167
160
168 /*!
161 /*!
169 \fn void QBarSet::brushChanged()
162 \fn void QBarSet::brushChanged()
170 This signal is emitted when the brush of the bar set has changed.
163 This signal is emitted when the brush of the bar set has changed.
171 \sa brush
164 \sa brush
172 */
165 */
173
166
174 /*!
167 /*!
175 \fn void QBarSet::labelBrushChanged()
168 \fn void QBarSet::labelBrushChanged()
176 This signal is emitted when the brush of the bar set's label has changed.
169 This signal is emitted when the brush of the bar set's label has changed.
177 \sa labelBrush
170 \sa labelBrush
178 */
171 */
179
172
180 /*!
173 /*!
181 \fn void QBarSet::labelFontChanged()
174 \fn void QBarSet::labelFontChanged()
182 This signal is emitted when the font of the bar set's label has changed.
175 This signal is emitted when the font of the bar set's label has changed.
183 \sa labelBrush
176 \sa labelBrush
184 */
177 */
185
178
186 /*!
179 /*!
187 \fn void QBarSet::colorChanged(QColor)
180 \fn void QBarSet::colorChanged(QColor)
188 This signal is emitted when the fill (brush) color of the set has changed to \a color.
181 This signal is emitted when the fill (brush) color of the set has changed to \a color.
189 */
182 */
190 /*!
183 /*!
191 \qmlsignal BarSet::onColorChanged(color color)
184 \qmlsignal BarSet::onColorChanged(color color)
192 This signal is emitted when the fill (brush) color of the set has changed to \a color.
185 This signal is emitted when the fill (brush) color of the set has changed to \a color.
193 */
186 */
194
187
195 /*!
188 /*!
196 \fn void QBarSet::borderColorChanged(QColor)
189 \fn void QBarSet::borderColorChanged(QColor)
197 This signal is emitted when the line (pen) color of the set has changed to \a color.
190 This signal is emitted when the line (pen) color of the set has changed to \a color.
198 */
191 */
199 /*!
192 /*!
200 \qmlsignal BarSet::onBorderColorChanged(color color)
193 \qmlsignal BarSet::onBorderColorChanged(color color)
201 This signal is emitted when the line (pen) color of the set has changed to \a color.
194 This signal is emitted when the line (pen) color of the set has changed to \a color.
202 */
195 */
203
196
204 /*!
197 /*!
205 \fn void QBarSet::labelColorChanged(QColor)
198 \fn void QBarSet::labelColorChanged(QColor)
206 This signal is emitted when the text (label) color of the set has changed to \a color.
199 This signal is emitted when the text (label) color of the set has changed to \a color.
207 */
200 */
208 /*!
201 /*!
209 \qmlsignal BarSet::onLabelColorChanged(color color)
202 \qmlsignal BarSet::onLabelColorChanged(color color)
210 This signal is emitted when the text (label) color of the set has changed to \a color.
203 This signal is emitted when the text (label) color of the set has changed to \a color.
211 */
204 */
212
205
213 /*!
206 /*!
214 \fn void QBarSet::valuesAdded(int index, int count)
207 \fn void QBarSet::valuesAdded(int index, int count)
215 This signal is emitted when new values have been added to the set.
208 This signal is emitted when new values have been added to the set.
216 Parameter \a index indicates the position of the first inserted value.
209 Parameter \a index indicates the position of the first inserted value.
217 Parameter \a count is the number of inserted values.
210 Parameter \a count is the number of inserted values.
218 \sa append(), insert()
211 \sa append(), insert()
219 */
212 */
220 /*!
213 /*!
221 \qmlsignal BarSet::onValuesAdded(int index, int count)
214 \qmlsignal BarSet::onValuesAdded(int index, int count)
222 This signal is emitted when new values have been added to the set.
215 This signal is emitted when new values have been added to the set.
223 Parameter \a index indicates the position of the first inserted value.
216 Parameter \a index indicates the position of the first inserted value.
224 Parameter \a count is the number of inserted values.
217 Parameter \a count is the number of inserted values.
225 */
218 */
226
219
227 /*!
220 /*!
228 \fn void QBarSet::valuesRemoved(int index, int count)
221 \fn void QBarSet::valuesRemoved(int index, int count)
229 This signal is emitted values have been removed from the set.
222 This signal is emitted values have been removed from the set.
230 Parameter \a index indicates the position of the first removed value.
223 Parameter \a index indicates the position of the first removed value.
231 Parameter \a count is the number of removed values.
224 Parameter \a count is the number of removed values.
232 \sa remove()
225 \sa remove()
233 */
226 */
234 /*!
227 /*!
235 \qmlsignal BarSet::onValuesRemoved(int index, int count)
228 \qmlsignal BarSet::onValuesRemoved(int index, int count)
236 This signal is emitted values have been removed from the set.
229 This signal is emitted values have been removed from the set.
237 Parameter \a index indicates the position of the first removed value.
230 Parameter \a index indicates the position of the first removed value.
238 Parameter \a count is the number of removed values.
231 Parameter \a count is the number of removed values.
239 */
232 */
240
233
241 /*!
234 /*!
242 \fn void QBarSet::valueChanged(int index)
235 \fn void QBarSet::valueChanged(int index)
243 This signal is emitted values the value in the set has been modified.
236 This signal is emitted values the value in the set has been modified.
244 Parameter \a index indicates the position of the modified value.
237 Parameter \a index indicates the position of the modified value.
245 \sa at()
238 \sa at()
246 */
239 */
247 /*!
240 /*!
248 \qmlsignal BarSet::onValueChanged(int index)
241 \qmlsignal BarSet::onValueChanged(int index)
249 This signal is emitted values the value in the set has been modified.
242 This signal is emitted values the value in the set has been modified.
250 Parameter \a index indicates the position of the modified value.
243 Parameter \a index indicates the position of the modified value.
251 */
244 */
252
245
253 /*!
246 /*!
254 \qmlproperty int BarSet::count
247 \qmlproperty int BarSet::count
255 The count of values on the bar set
248 The count of values on the bar set
256 */
249 */
257
250
258 /*!
251 /*!
259 \qmlproperty QVariantList BarSet::values
252 \qmlproperty QVariantList BarSet::values
260 The values of the bar set. You can set either a list of reals or a list of points as values. If you set a list of
253 The values of the bar set. You can set either a list of reals or a list of points as values. If you set a list of
261 reals as values, the values are automatically completed to points by using the index of a value as it's
254 reals as values, the values are automatically completed to points by using the index of a value as it's
262 x-coordinate. For example the following sets have equal values:
255 x-coordinate. For example the following sets have equal values:
263 \code
256 \code
264 myBarSet1.values = [0, 5, 1, 5];
257 myBarSet1.values = [0, 5, 1, 5];
265 myBarSet2.values = [Qt.point(0, 0), Qt.point(1, 5), Qt.point(2, 1), Qt.point(3, 5)];
258 myBarSet2.values = [Qt.point(0, 0), Qt.point(1, 5), Qt.point(2, 1), Qt.point(3, 5)];
266 \endcode
259 \endcode
267 */
260 */
268
261
269 /*!
262 /*!
270 Constructs QBarSet with a label of \a label and with parent of \a parent.
263 Constructs QBarSet with a label of \a label and with parent of \a parent.
271 */
264 */
272 QBarSet::QBarSet(const QString label, QObject *parent)
265 QBarSet::QBarSet(const QString label, QObject *parent)
273 : QObject(parent),
266 : QObject(parent),
274 d_ptr(new QBarSetPrivate(label, this))
267 d_ptr(new QBarSetPrivate(label, this))
275 {
268 {
276 }
269 }
277
270
278 /*!
271 /*!
279 Destroys the bar set.
272 Destroys the bar set.
280 */
273 */
281 QBarSet::~QBarSet()
274 QBarSet::~QBarSet()
282 {
275 {
283 // NOTE: d_ptr destroyed by QObject
276 // NOTE: d_ptr destroyed by QObject
284 }
277 }
285
278
286 /*!
279 /*!
287 Sets new \a label for set.
280 Sets new \a label for set.
288 */
281 */
289 void QBarSet::setLabel(const QString label)
282 void QBarSet::setLabel(const QString label)
290 {
283 {
291 d_ptr->m_label = label;
284 d_ptr->m_label = label;
292 emit labelChanged();
285 emit labelChanged();
293 }
286 }
294
287
295 /*!
288 /*!
296 Returns label of the set.
289 Returns label of the set.
297 */
290 */
298 QString QBarSet::label() const
291 QString QBarSet::label() const
299 {
292 {
300 return d_ptr->m_label;
293 return d_ptr->m_label;
301 }
294 }
302
295
303 /*!
296 /*!
304 Appends new value \a value to the end of set.
297 Appends new value \a value to the end of set.
305 */
298 */
306 void QBarSet::append(const qreal value)
299 void QBarSet::append(const qreal value)
307 {
300 {
308 // Convert to QPointF
301 // Convert to QPointF
309 int index = d_ptr->m_values.count();
302 int index = d_ptr->m_values.count();
310 d_ptr->append(QPointF(d_ptr->m_values.count(), value));
303 d_ptr->append(QPointF(d_ptr->m_values.count(), value));
311 emit valuesAdded(index, 1);
304 emit valuesAdded(index, 1);
312 }
305 }
313
306
314 /*!
307 /*!
315 Appends a list of reals to set. Works like append with single real value. The \a values in list
308 Appends a list of reals to set. Works like append with single real value. The \a values in list
316 are appended to end of bar set.
309 are appended to end of bar set.
317 \sa append()
310 \sa append()
318 */
311 */
319 void QBarSet::append(const QList<qreal> &values)
312 void QBarSet::append(const QList<qreal> &values)
320 {
313 {
321 int index = d_ptr->m_values.count();
314 int index = d_ptr->m_values.count();
322 d_ptr->append(values);
315 d_ptr->append(values);
323 emit valuesAdded(index, values.count());
316 emit valuesAdded(index, values.count());
324 }
317 }
325
318
326 /*!
319 /*!
327 Convenience operator. Same as append, with real \a value.
320 Convenience operator. Same as append, with real \a value.
328 \sa append()
321 \sa append()
329 */
322 */
330 QBarSet &QBarSet::operator << (const qreal &value)
323 QBarSet &QBarSet::operator << (const qreal &value)
331 {
324 {
332 append(value);
325 append(value);
333 return *this;
326 return *this;
334 }
327 }
335
328
336 /*!
329 /*!
337 Inserts new \a value on the \a index position.
330 Inserts new \a value on the \a index position.
338 The value that is currently at this postion is moved to position index + 1
331 The value that is currently at this postion is moved to position index + 1
339 \sa remove()
332 \sa remove()
340 */
333 */
341 void QBarSet::insert(const int index, const qreal value)
334 void QBarSet::insert(const int index, const qreal value)
342 {
335 {
343 d_ptr->insert(index, value);
336 d_ptr->insert(index, value);
344 emit valuesAdded(index, 1);
337 emit valuesAdded(index, 1);
345 }
338 }
346
339
347 /*!
340 /*!
348 Removes \a count number of values from the set starting at \a index.
341 Removes \a count number of values from the set starting at \a index.
349 \sa insert()
342 \sa insert()
350 */
343 */
351 void QBarSet::remove(const int index, const int count)
344 void QBarSet::remove(const int index, const int count)
352 {
345 {
353 int removedCount = d_ptr->remove(index, count);
346 int removedCount = d_ptr->remove(index, count);
354 if (removedCount > 0)
347 if (removedCount > 0)
355 emit valuesRemoved(index, removedCount);
348 emit valuesRemoved(index, removedCount);
356 return;
349 return;
357 }
350 }
358
351
359 /*!
352 /*!
360 Sets a new value \a value to set, indexed by \a index.
353 Sets a new value \a value to set, indexed by \a index.
361 */
354 */
362 void QBarSet::replace(const int index, const qreal value)
355 void QBarSet::replace(const int index, const qreal value)
363 {
356 {
364 if (index >= 0 && index < d_ptr->m_values.count()) {
357 if (index >= 0 && index < d_ptr->m_values.count()) {
365 d_ptr->replace(index, value);
358 d_ptr->replace(index, value);
366 emit valueChanged(index);
359 emit valueChanged(index);
367 }
360 }
368 }
361 }
369
362
370
363
371 /*!
364 /*!
372 Returns value of set indexed by \a index.
365 Returns value of set indexed by \a index.
373 If the index is out of bounds 0.0 is returned.
366 If the index is out of bounds 0.0 is returned.
374 */
367 */
375 qreal QBarSet::at(const int index) const
368 qreal QBarSet::at(const int index) const
376 {
369 {
377 if (index < 0 || index >= d_ptr->m_values.count())
370 if (index < 0 || index >= d_ptr->m_values.count())
378 return 0;
371 return 0;
379 return d_ptr->m_values.at(index).y();
372 return d_ptr->m_values.at(index).y();
380 }
373 }
381
374
382 /*!
375 /*!
383 Returns value of set indexed by \a index.
376 Returns value of set indexed by \a index.
384 If the index is out of bounds 0.0 is returned.
377 If the index is out of bounds 0.0 is returned.
385 */
378 */
386 qreal QBarSet::operator [](const int index) const
379 qreal QBarSet::operator [](const int index) const
387 {
380 {
388 return at(index);
381 return at(index);
389 }
382 }
390
383
391 /*!
384 /*!
392 Returns count of values in set.
385 Returns count of values in set.
393 */
386 */
394 int QBarSet::count() const
387 int QBarSet::count() const
395 {
388 {
396 return d_ptr->m_values.count();
389 return d_ptr->m_values.count();
397 }
390 }
398
391
399 /*!
392 /*!
400 Returns sum of all values in the bar set.
393 Returns sum of all values in the bar set.
401 */
394 */
402 qreal QBarSet::sum() const
395 qreal QBarSet::sum() const
403 {
396 {
404 qreal total(0);
397 qreal total(0);
405 for (int i = 0; i < d_ptr->m_values.count(); i++)
398 for (int i = 0; i < d_ptr->m_values.count(); i++)
406 total += d_ptr->m_values.at(i).y();
399 total += d_ptr->m_values.at(i).y();
407 return total;
400 return total;
408 }
401 }
409
402
410 /*!
403 /*!
411 Sets pen for set. Bars of this set are drawn using \a pen
404 Sets pen for set. Bars of this set are drawn using \a pen
412 */
405 */
413 void QBarSet::setPen(const QPen &pen)
406 void QBarSet::setPen(const QPen &pen)
414 {
407 {
415 if (d_ptr->m_pen != pen) {
408 if (d_ptr->m_pen != pen) {
416 d_ptr->m_pen = pen;
409 d_ptr->m_pen = pen;
417 emit d_ptr->updatedBars();
410 emit d_ptr->updatedBars();
418 emit penChanged();
411 emit penChanged();
419 }
412 }
420 }
413 }
421
414
422 /*!
415 /*!
423 Returns pen of the set.
416 Returns pen of the set.
424 */
417 */
425 QPen QBarSet::pen() const
418 QPen QBarSet::pen() const
426 {
419 {
427 if (d_ptr->m_pen == QChartPrivate::defaultPen())
420 if (d_ptr->m_pen == QChartPrivate::defaultPen())
428 return QPen();
421 return QPen();
429 else
422 else
430 return d_ptr->m_pen;
423 return d_ptr->m_pen;
431 }
424 }
432
425
433 /*!
426 /*!
434 Sets brush for the set. Bars of this set are drawn using \a brush.
427 Sets brush for the set. Bars of this set are drawn using \a brush.
435 */
428 */
436 void QBarSet::setBrush(const QBrush &brush)
429 void QBarSet::setBrush(const QBrush &brush)
437 {
430 {
438 if (d_ptr->m_brush != brush) {
431 if (d_ptr->m_brush != brush) {
439 d_ptr->m_brush = brush;
432 d_ptr->m_brush = brush;
440 emit d_ptr->updatedBars();
433 emit d_ptr->updatedBars();
441 emit brushChanged();
434 emit brushChanged();
442 }
435 }
443 }
436 }
444
437
445 /*!
438 /*!
446 Returns brush of the set.
439 Returns brush of the set.
447 */
440 */
448 QBrush QBarSet::brush() const
441 QBrush QBarSet::brush() const
449 {
442 {
450 if (d_ptr->m_brush == QChartPrivate::defaultBrush())
443 if (d_ptr->m_brush == QChartPrivate::defaultBrush())
451 return QBrush();
444 return QBrush();
452 else
445 else
453 return d_ptr->m_brush;
446 return d_ptr->m_brush;
454 }
447 }
455
448
456 /*!
449 /*!
457 Sets \a brush of the values that are drawn on top of this bar set.
450 Sets \a brush of the values that are drawn on top of this bar set.
458 */
451 */
459 void QBarSet::setLabelBrush(const QBrush &brush)
452 void QBarSet::setLabelBrush(const QBrush &brush)
460 {
453 {
461 if (d_ptr->m_labelBrush != brush) {
454 if (d_ptr->m_labelBrush != brush) {
462 d_ptr->m_labelBrush = brush;
455 d_ptr->m_labelBrush = brush;
463 emit d_ptr->updatedBars();
456 emit d_ptr->updatedBars();
464 emit labelBrushChanged();
457 emit labelBrushChanged();
465 }
458 }
466 }
459 }
467
460
468 /*!
461 /*!
469 Returns brush of the values that are drawn on top of this bar set.
462 Returns brush of the values that are drawn on top of this bar set.
470 */
463 */
471 QBrush QBarSet::labelBrush() const
464 QBrush QBarSet::labelBrush() const
472 {
465 {
473 if (d_ptr->m_labelBrush == QChartPrivate::defaultBrush())
466 if (d_ptr->m_labelBrush == QChartPrivate::defaultBrush())
474 return QBrush();
467 return QBrush();
475 else
468 else
476 return d_ptr->m_labelBrush;
469 return d_ptr->m_labelBrush;
477 }
470 }
478
471
479 /*!
472 /*!
480 Sets the \a font for values that are drawn on top of this bar set.
473 Sets the \a font for values that are drawn on top of this bar set.
481 */
474 */
482 void QBarSet::setLabelFont(const QFont &font)
475 void QBarSet::setLabelFont(const QFont &font)
483 {
476 {
484 if (d_ptr->m_labelFont != font) {
477 if (d_ptr->m_labelFont != font) {
485 d_ptr->m_labelFont = font;
478 d_ptr->m_labelFont = font;
486 emit d_ptr->updatedBars();
479 emit d_ptr->updatedBars();
487 emit labelFontChanged();
480 emit labelFontChanged();
488 }
481 }
489
482
490 }
483 }
491
484
492 /*!
485 /*!
493 Returns the pen for values that are drawn on top of this bar set.
486 Returns the pen for values that are drawn on top of this bar set.
494 */
487 */
495 QFont QBarSet::labelFont() const
488 QFont QBarSet::labelFont() const
496 {
489 {
497 return d_ptr->m_labelFont;
490 return d_ptr->m_labelFont;
498 }
491 }
499
492
500 /*!
493 /*!
501 Returns the color of the brush of bar set.
494 Returns the color of the brush of bar set.
502 */
495 */
503 QColor QBarSet::color()
496 QColor QBarSet::color()
504 {
497 {
505 return brush().color();
498 return brush().color();
506 }
499 }
507
500
508 /*!
501 /*!
509 Sets the \a color of brush for this bar set.
502 Sets the \a color of brush for this bar set.
510 */
503 */
511 void QBarSet::setColor(QColor color)
504 void QBarSet::setColor(QColor color)
512 {
505 {
513 QBrush b = brush();
506 QBrush b = brush();
514 if ((b.color() != color) || (b.style() == Qt::NoBrush)) {
507 if ((b.color() != color) || (b.style() == Qt::NoBrush)) {
515 b.setColor(color);
508 b.setColor(color);
516 if (b.style() == Qt::NoBrush) {
509 if (b.style() == Qt::NoBrush) {
517 // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush)
510 // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush)
518 // This prevents theme to override color defined in QML side:
511 // This prevents theme to override color defined in QML side:
519 // BarSet { label: "Bob"; color:"red"; values: [1,2,3] }
512 // BarSet { label: "Bob"; color:"red"; values: [1,2,3] }
520 // The color must be obeyed, since user wanted it.
513 // The color must be obeyed, since user wanted it.
521 b.setStyle(Qt::SolidPattern);
514 b.setStyle(Qt::SolidPattern);
522 }
515 }
523 setBrush(b);
516 setBrush(b);
524 emit colorChanged(color);
517 emit colorChanged(color);
525 }
518 }
526 }
519 }
527
520
528 /*!
521 /*!
529 Returns the color of pen of this bar set.
522 Returns the color of pen of this bar set.
530 */
523 */
531 QColor QBarSet::borderColor()
524 QColor QBarSet::borderColor()
532 {
525 {
533 return pen().color();
526 return pen().color();
534 }
527 }
535
528
536 /*!
529 /*!
537 Sets the color of pen for this bar set.
530 Sets the color of pen for this bar set.
538 */
531 */
539 void QBarSet::setBorderColor(QColor color)
532 void QBarSet::setBorderColor(QColor color)
540 {
533 {
541 QPen p = pen();
534 QPen p = pen();
542 if (p.color() != color) {
535 if (p.color() != color) {
543 p.setColor(color);
536 p.setColor(color);
544 setPen(p);
537 setPen(p);
545 emit borderColorChanged(color);
538 emit borderColorChanged(color);
546 }
539 }
547 }
540 }
548
541
549 /*!
542 /*!
550 Returns the color of labels of this bar set.
543 Returns the color of labels of this bar set.
551 */
544 */
552 QColor QBarSet::labelColor()
545 QColor QBarSet::labelColor()
553 {
546 {
554 return labelBrush().color();
547 return labelBrush().color();
555 }
548 }
556
549
557 /*!
550 /*!
558 Sets the color of labels for this bar set.
551 Sets the color of labels for this bar set.
559 */
552 */
560 void QBarSet::setLabelColor(QColor color)
553 void QBarSet::setLabelColor(QColor color)
561 {
554 {
562 QBrush b = labelBrush();
555 QBrush b = labelBrush();
563 if (b == QBrush())
556 if (b == QBrush())
564 b.setStyle(Qt::SolidPattern);
557 b.setStyle(Qt::SolidPattern);
565
558
566 if (b.color() != color) {
559 if (b.color() != color) {
567 b.setColor(color);
560 b.setColor(color);
568 setLabelBrush(b);
561 setLabelBrush(b);
569 emit labelColorChanged(color);
562 emit labelColorChanged(color);
570 }
563 }
571 }
564 }
572
565
573 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
566 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
574
567
575 QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent),
568 QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent),
576 q_ptr(parent),
569 q_ptr(parent),
577 m_label(label),
570 m_label(label),
578 m_pen(QChartPrivate::defaultPen()),
571 m_pen(QChartPrivate::defaultPen()),
579 m_brush(QChartPrivate::defaultBrush()),
572 m_brush(QChartPrivate::defaultBrush()),
580 m_labelBrush(QChartPrivate::defaultBrush())
573 m_labelBrush(QChartPrivate::defaultBrush())
581 {
574 {
582 }
575 }
583
576
584 QBarSetPrivate::~QBarSetPrivate()
577 QBarSetPrivate::~QBarSetPrivate()
585 {
578 {
586 }
579 }
587
580
588 void QBarSetPrivate::append(QPointF value)
581 void QBarSetPrivate::append(QPointF value)
589 {
582 {
590 if (isValidValue(value)) {
583 if (isValidValue(value)) {
591 m_values.append(value);
584 m_values.append(value);
592 emit restructuredBars();
585 emit restructuredBars();
593 }
586 }
594 }
587 }
595
588
596 void QBarSetPrivate::append(QList<QPointF> values)
589 void QBarSetPrivate::append(QList<QPointF> values)
597 {
590 {
598 for (int i = 0; i < values.count(); i++) {
591 for (int i = 0; i < values.count(); i++) {
599 if (isValidValue(values.at(i)))
592 if (isValidValue(values.at(i)))
600 m_values.append(values.at(i));
593 m_values.append(values.at(i));
601 }
594 }
602 emit restructuredBars();
595 emit restructuredBars();
603 }
596 }
604
597
605 void QBarSetPrivate::append(QList<qreal> values)
598 void QBarSetPrivate::append(QList<qreal> values)
606 {
599 {
607 int index = m_values.count();
600 int index = m_values.count();
608 for (int i = 0; i < values.count(); i++) {
601 for (int i = 0; i < values.count(); i++) {
609 if (isValidValue(values.at(i))) {
602 if (isValidValue(values.at(i))) {
610 m_values.append(QPointF(index, values.at(i)));
603 m_values.append(QPointF(index, values.at(i)));
611 index++;
604 index++;
612 }
605 }
613 }
606 }
614 emit restructuredBars();
607 emit restructuredBars();
615 }
608 }
616
609
617 void QBarSetPrivate::insert(const int index, const qreal value)
610 void QBarSetPrivate::insert(const int index, const qreal value)
618 {
611 {
619 m_values.insert(index, QPointF(index, value));
612 m_values.insert(index, QPointF(index, value));
620 emit restructuredBars();
613 emit restructuredBars();
621 }
614 }
622
615
623 void QBarSetPrivate::insert(const int index, const QPointF value)
616 void QBarSetPrivate::insert(const int index, const QPointF value)
624 {
617 {
625 m_values.insert(index, value);
618 m_values.insert(index, value);
626 emit restructuredBars();
619 emit restructuredBars();
627 }
620 }
628
621
629 int QBarSetPrivate::remove(const int index, const int count)
622 int QBarSetPrivate::remove(const int index, const int count)
630 {
623 {
631 int removeCount = count;
624 int removeCount = count;
632
625
633 if ((index < 0) || (m_values.count() == 0))
626 if ((index < 0) || (m_values.count() == 0))
634 return 0; // Invalid index or not values in list, remove nothing.
627 return 0; // Invalid index or not values in list, remove nothing.
635 else if ((index + count) > m_values.count())
628 else if ((index + count) > m_values.count())
636 removeCount = m_values.count() - index; // Trying to remove more items than list has. Limit amount to be removed.
629 removeCount = m_values.count() - index; // Trying to remove more items than list has. Limit amount to be removed.
637
630
638 int c = 0;
631 int c = 0;
639 while (c < removeCount) {
632 while (c < removeCount) {
640 m_values.removeAt(index);
633 m_values.removeAt(index);
641 c++;
634 c++;
642 }
635 }
643 emit restructuredBars();
636 emit restructuredBars();
644 return removeCount;
637 return removeCount;
645 }
638 }
646
639
647 void QBarSetPrivate::replace(const int index, const qreal value)
640 void QBarSetPrivate::replace(const int index, const qreal value)
648 {
641 {
649 m_values.replace(index, QPointF(index, value));
642 m_values.replace(index, QPointF(index, value));
650 emit updatedLayout();
643 emit updatedLayout();
651 }
644 }
652
645
653 void QBarSetPrivate::replace(const int index, const QPointF value)
646 void QBarSetPrivate::replace(const int index, const QPointF value)
654 {
647 {
655 m_values.replace(index, value);
648 m_values.replace(index, value);
656 emit updatedLayout();
649 emit updatedLayout();
657 }
650 }
658
651
659 qreal QBarSetPrivate::pos(const int index)
652 qreal QBarSetPrivate::pos(const int index)
660 {
653 {
661 if (index < 0 || index >= m_values.count())
654 if (index < 0 || index >= m_values.count())
662 return 0;
655 return 0;
663 return m_values.at(index).x();
656 return m_values.at(index).x();
664 }
657 }
665
658
666 qreal QBarSetPrivate::value(const int index)
659 qreal QBarSetPrivate::value(const int index)
667 {
660 {
668 if (index < 0 || index >= m_values.count())
661 if (index < 0 || index >= m_values.count())
669 return 0;
662 return 0;
670 return m_values.at(index).y();
663 return m_values.at(index).y();
671 }
664 }
672
665
673 #include "moc_qbarset.cpp"
666 #include "moc_qbarset.cpp"
674 #include "moc_qbarset_p.cpp"
667 #include "moc_qbarset_p.cpp"
675
668
676 QT_CHARTS_END_NAMESPACE
669 QT_CHARTS_END_NAMESPACE
@@ -1,120 +1,119
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 QBARSET_H
21 #ifndef QBARSET_H
22 #define QBARSET_H
22 #define QBARSET_H
23
23
24 #include <QtCharts/QChartGlobal>
24 #include <QtCharts/QChartGlobal>
25 #include <QtGui/QPen>
25 #include <QtGui/QPen>
26 #include <QtGui/QBrush>
26 #include <QtGui/QBrush>
27 #include <QtGui/QFont>
27 #include <QtGui/QFont>
28
28
29 QT_CHARTS_BEGIN_NAMESPACE
29 QT_CHARTS_BEGIN_NAMESPACE
30 class QBarSetPrivate;
30 class QBarSetPrivate;
31
31
32 class QT_CHARTS_EXPORT QBarSet : public QObject
32 class QT_CHARTS_EXPORT QBarSet : public QObject
33 {
33 {
34 Q_OBJECT
34 Q_OBJECT
35 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
35 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
36 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
36 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
37 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
37 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
38 Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged)
38 Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged)
39 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged)
39 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged)
40 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
40 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
41 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
41 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
42 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
42 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
43
43
44 public:
44 public:
45 explicit QBarSet(const QString label, QObject *parent = 0);
45 explicit QBarSet(const QString label, QObject *parent = 0);
46 virtual ~QBarSet();
46 virtual ~QBarSet();
47
47
48 void setLabel(const QString label);
48 void setLabel(const QString label);
49 QString label() const;
49 QString label() const;
50
50
51 void append(const qreal value);
51 void append(const qreal value);
52 void append(const QList<qreal> &values);
52 void append(const QList<qreal> &values);
53
53
54 QBarSet &operator << (const qreal &value);
54 QBarSet &operator << (const qreal &value);
55
55
56 void insert(const int index, const qreal value);
56 void insert(const int index, const qreal value);
57 void remove(const int index, const int count = 1);
57 void remove(const int index, const int count = 1);
58 void replace(const int index, const qreal value);
58 void replace(const int index, const qreal value);
59 qreal at(const int index) const;
59 qreal at(const int index) const;
60 qreal operator [](const int index) const;
60 qreal operator [](const int index) const;
61 int count() const;
61 int count() const;
62 qreal sum() const;
62 qreal sum() const;
63
63
64 void setPen(const QPen &pen);
64 void setPen(const QPen &pen);
65 QPen pen() const;
65 QPen pen() const;
66
66
67 void setBrush(const QBrush &brush);
67 void setBrush(const QBrush &brush);
68 QBrush brush() const;
68 QBrush brush() const;
69
69
70 void setLabelBrush(const QBrush &brush);
70 void setLabelBrush(const QBrush &brush);
71 QBrush labelBrush() const;
71 QBrush labelBrush() const;
72
72
73 void setLabelFont(const QFont &font);
73 void setLabelFont(const QFont &font);
74 QFont labelFont() const;
74 QFont labelFont() const;
75
75
76 QColor color();
76 QColor color();
77 void setColor(QColor color);
77 void setColor(QColor color);
78
78
79 QColor borderColor();
79 QColor borderColor();
80 void setBorderColor(QColor color);
80 void setBorderColor(QColor color);
81
81
82 QColor labelColor();
82 QColor labelColor();
83 void setLabelColor(QColor color);
83 void setLabelColor(QColor color);
84
84
85 Q_SIGNALS:
85 Q_SIGNALS:
86 void clicked(int index);
86 void clicked(int index);
87 void hovered(bool status);
88 void hovered(bool status, int index);
87 void hovered(bool status, int index);
89 void penChanged();
88 void penChanged();
90 void brushChanged();
89 void brushChanged();
91 void labelChanged();
90 void labelChanged();
92 void labelBrushChanged();
91 void labelBrushChanged();
93 void labelFontChanged();
92 void labelFontChanged();
94 void colorChanged(QColor color);
93 void colorChanged(QColor color);
95 void borderColorChanged(QColor color);
94 void borderColorChanged(QColor color);
96 void labelColorChanged(QColor color);
95 void labelColorChanged(QColor color);
97
96
98 void valuesAdded(int index, int count);
97 void valuesAdded(int index, int count);
99 void valuesRemoved(int index, int count);
98 void valuesRemoved(int index, int count);
100 void valueChanged(int index);
99 void valueChanged(int index);
101
100
102 private:
101 private:
103 QScopedPointer<QBarSetPrivate> d_ptr;
102 QScopedPointer<QBarSetPrivate> d_ptr;
104 Q_DISABLE_COPY(QBarSet)
103 Q_DISABLE_COPY(QBarSet)
105 friend class QAbstractBarSeries;
104 friend class QAbstractBarSeries;
106 friend class BarLegendMarker;
105 friend class BarLegendMarker;
107 friend class AbstractBarChartItem;
106 friend class AbstractBarChartItem;
108 friend class QAbstractBarSeriesPrivate;
107 friend class QAbstractBarSeriesPrivate;
109 friend class StackedBarChartItem;
108 friend class StackedBarChartItem;
110 friend class PercentBarChartItem;
109 friend class PercentBarChartItem;
111 friend class BarChartItem;
110 friend class BarChartItem;
112 friend class HorizontalBarChartItem;
111 friend class HorizontalBarChartItem;
113 friend class HorizontalStackedBarChartItem;
112 friend class HorizontalStackedBarChartItem;
114 friend class HorizontalPercentBarChartItem;
113 friend class HorizontalPercentBarChartItem;
115 friend class BoxPlotChartItem;
114 friend class BoxPlotChartItem;
116 };
115 };
117
116
118 QT_CHARTS_END_NAMESPACE
117 QT_CHARTS_END_NAMESPACE
119
118
120 #endif // QBARSET_H
119 #endif // QBARSET_H
@@ -1,1070 +1,929
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 <QtCharts/QBarSeries>
22 #include <QtCharts/QBarSeries>
23 #include <QtCharts/QBarSet>
23 #include <QtCharts/QBarSet>
24 #include <QtCharts/QChartView>
24 #include <QtCharts/QChartView>
25 #include <QtCharts/QChart>
25 #include <QtCharts/QChart>
26 #include "tst_definitions.h"
26 #include "tst_definitions.h"
27
27
28 QT_CHARTS_USE_NAMESPACE
28 QT_CHARTS_USE_NAMESPACE
29
29
30 Q_DECLARE_METATYPE(QBarSet*)
30 Q_DECLARE_METATYPE(QBarSet*)
31 Q_DECLARE_METATYPE(QList<QBarSet*>)
31 Q_DECLARE_METATYPE(QList<QBarSet*>)
32 Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition)
32 Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition)
33
33
34 class tst_QBarSeries : public QObject
34 class tst_QBarSeries : 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 qbarseries_data();
45 void qbarseries_data();
46 void qbarseries();
46 void qbarseries();
47 void type_data();
47 void type_data();
48 void type();
48 void type();
49 void append_data();
49 void append_data();
50 void append();
50 void append();
51 void remove_data();
51 void remove_data();
52 void remove();
52 void remove();
53 void take_data();
53 void take_data();
54 void take();
54 void take();
55 void appendList_data();
55 void appendList_data();
56 void appendList();
56 void appendList();
57 void count_data();
57 void count_data();
58 void count();
58 void count();
59 void barSets_data();
59 void barSets_data();
60 void barSets();
60 void barSets();
61 void setLabelsVisible_data();
61 void setLabelsVisible_data();
62 void setLabelsVisible();
62 void setLabelsVisible();
63 void setLabelsFormat();
63 void setLabelsFormat();
64 void setLabelsPosition();
64 void setLabelsPosition();
65 void opacity();
65 void opacity();
66 void mouseclicked_data();
66 void mouseclicked_data();
67 void mouseclicked();
67 void mouseclicked();
68 void mousehovered_data();
68 void mousehovered_data();
69 void mousehovered();
69 void mousehovered();
70 void clearWithAnimations();
70 void clearWithAnimations();
71 void destruction();
71 void destruction();
72
72
73 private:
73 private:
74 QBarSeries* m_barseries;
74 QBarSeries* m_barseries;
75 QBarSeries* m_barseries_with_sets;
75 QBarSeries* m_barseries_with_sets;
76
76
77 QList<QBarSet*> m_testSets;
77 QList<QBarSet*> m_testSets;
78
78
79 };
79 };
80
80
81 void tst_QBarSeries::initTestCase()
81 void tst_QBarSeries::initTestCase()
82 {
82 {
83 qRegisterMetaType<QBarSet*>("QBarSet*");
83 qRegisterMetaType<QBarSet*>("QBarSet*");
84 qRegisterMetaType<QList<QBarSet*> >("QList<QBarSet*>");
84 qRegisterMetaType<QList<QBarSet*> >("QList<QBarSet*>");
85 qRegisterMetaType<QAbstractBarSeries::LabelsPosition>("QAbstractBarSeries::LabelsPosition");
85 qRegisterMetaType<QAbstractBarSeries::LabelsPosition>("QAbstractBarSeries::LabelsPosition");
86 }
86 }
87
87
88 void tst_QBarSeries::cleanupTestCase()
88 void tst_QBarSeries::cleanupTestCase()
89 {
89 {
90 }
90 }
91
91
92 void tst_QBarSeries::init()
92 void tst_QBarSeries::init()
93 {
93 {
94 m_barseries = new QBarSeries();
94 m_barseries = new QBarSeries();
95 m_barseries_with_sets = new QBarSeries();
95 m_barseries_with_sets = new QBarSeries();
96
96
97 for (int i=0; i<5; i++) {
97 for (int i=0; i<5; i++) {
98 m_testSets.append(new QBarSet("testset"));
98 m_testSets.append(new QBarSet("testset"));
99 m_barseries_with_sets->append(m_testSets.at(i));
99 m_barseries_with_sets->append(m_testSets.at(i));
100 }
100 }
101 }
101 }
102
102
103 void tst_QBarSeries::cleanup()
103 void tst_QBarSeries::cleanup()
104 {
104 {
105 foreach (QBarSet* s, m_testSets) {
105 foreach (QBarSet* s, m_testSets) {
106 m_barseries_with_sets->remove(s);
106 m_barseries_with_sets->remove(s);
107 }
107 }
108 m_testSets.clear();
108 m_testSets.clear();
109
109
110 delete m_barseries;
110 delete m_barseries;
111 m_barseries = 0;
111 m_barseries = 0;
112 delete m_barseries_with_sets;
112 delete m_barseries_with_sets;
113 m_barseries_with_sets = 0;
113 m_barseries_with_sets = 0;
114 }
114 }
115
115
116 void tst_QBarSeries::qbarseries_data()
116 void tst_QBarSeries::qbarseries_data()
117 {
117 {
118 }
118 }
119
119
120 void tst_QBarSeries::qbarseries()
120 void tst_QBarSeries::qbarseries()
121 {
121 {
122 QBarSeries *barseries = new QBarSeries();
122 QBarSeries *barseries = new QBarSeries();
123 QVERIFY(barseries != 0);
123 QVERIFY(barseries != 0);
124 }
124 }
125
125
126 void tst_QBarSeries::type_data()
126 void tst_QBarSeries::type_data()
127 {
127 {
128
128
129 }
129 }
130
130
131 void tst_QBarSeries::type()
131 void tst_QBarSeries::type()
132 {
132 {
133 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar);
133 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar);
134 }
134 }
135
135
136 void tst_QBarSeries::append_data()
136 void tst_QBarSeries::append_data()
137 {
137 {
138 }
138 }
139
139
140 void tst_QBarSeries::append()
140 void tst_QBarSeries::append()
141 {
141 {
142 QVERIFY(m_barseries->count() == 0);
142 QVERIFY(m_barseries->count() == 0);
143
143
144 bool ret = false;
144 bool ret = false;
145
145
146 // Try adding barset
146 // Try adding barset
147 QBarSet *barset = new QBarSet("testset");
147 QBarSet *barset = new QBarSet("testset");
148 ret = m_barseries->append(barset);
148 ret = m_barseries->append(barset);
149
149
150 QVERIFY(ret == true);
150 QVERIFY(ret == true);
151 QVERIFY(m_barseries->count() == 1);
151 QVERIFY(m_barseries->count() == 1);
152
152
153 // Try adding another set
153 // Try adding another set
154 QBarSet *barset2 = new QBarSet("testset2");
154 QBarSet *barset2 = new QBarSet("testset2");
155 ret = m_barseries->append(barset2);
155 ret = m_barseries->append(barset2);
156
156
157 QVERIFY(ret == true);
157 QVERIFY(ret == true);
158 QVERIFY(m_barseries->count() == 2);
158 QVERIFY(m_barseries->count() == 2);
159
159
160 // Try adding same set again
160 // Try adding same set again
161 ret = m_barseries->append(barset2);
161 ret = m_barseries->append(barset2);
162 QVERIFY(ret == false);
162 QVERIFY(ret == false);
163 QVERIFY(m_barseries->count() == 2);
163 QVERIFY(m_barseries->count() == 2);
164
164
165 // Try adding null set
165 // Try adding null set
166 ret = m_barseries->append(0);
166 ret = m_barseries->append(0);
167 QVERIFY(ret == false);
167 QVERIFY(ret == false);
168 QVERIFY(m_barseries->count() == 2);
168 QVERIFY(m_barseries->count() == 2);
169
169
170 }
170 }
171
171
172 void tst_QBarSeries::remove_data()
172 void tst_QBarSeries::remove_data()
173 {
173 {
174 }
174 }
175
175
176 void tst_QBarSeries::remove()
176 void tst_QBarSeries::remove()
177 {
177 {
178 int count = m_testSets.count();
178 int count = m_testSets.count();
179 QVERIFY(m_barseries_with_sets->count() == count);
179 QVERIFY(m_barseries_with_sets->count() == count);
180
180
181 // Try to remove null pointer (should not remove, should not crash)
181 // Try to remove null pointer (should not remove, should not crash)
182 bool ret = false;
182 bool ret = false;
183 ret = m_barseries_with_sets->remove(0);
183 ret = m_barseries_with_sets->remove(0);
184 QVERIFY(ret == false);
184 QVERIFY(ret == false);
185 QVERIFY(m_barseries_with_sets->count() == count);
185 QVERIFY(m_barseries_with_sets->count() == count);
186
186
187 // Try to remove invalid pointer (should not remove, should not crash)
187 // Try to remove invalid pointer (should not remove, should not crash)
188 ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) );
188 ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) );
189 QVERIFY(ret == false);
189 QVERIFY(ret == false);
190 QVERIFY(m_barseries_with_sets->count() == count);
190 QVERIFY(m_barseries_with_sets->count() == count);
191
191
192 // remove some sets
192 // remove some sets
193 ret = m_barseries_with_sets->remove(m_testSets.at(2));
193 ret = m_barseries_with_sets->remove(m_testSets.at(2));
194 QVERIFY(ret == true);
194 QVERIFY(ret == true);
195 ret = m_barseries_with_sets->remove(m_testSets.at(3));
195 ret = m_barseries_with_sets->remove(m_testSets.at(3));
196 QVERIFY(ret == true);
196 QVERIFY(ret == true);
197 ret = m_barseries_with_sets->remove(m_testSets.at(4));
197 ret = m_barseries_with_sets->remove(m_testSets.at(4));
198 QVERIFY(ret == true);
198 QVERIFY(ret == true);
199
199
200 QVERIFY(m_barseries_with_sets->count() == 2);
200 QVERIFY(m_barseries_with_sets->count() == 2);
201
201
202 QList<QBarSet*> verifysets = m_barseries_with_sets->barSets();
202 QList<QBarSet*> verifysets = m_barseries_with_sets->barSets();
203
203
204 QVERIFY(verifysets.at(0) == m_testSets.at(0));
204 QVERIFY(verifysets.at(0) == m_testSets.at(0));
205 QVERIFY(verifysets.at(1) == m_testSets.at(1));
205 QVERIFY(verifysets.at(1) == m_testSets.at(1));
206
206
207 // Try removing all sets again (should be ok, even if some sets have already been removed)
207 // Try removing all sets again (should be ok, even if some sets have already been removed)
208 ret = false;
208 ret = false;
209 for (int i=0; i<count; i++) {
209 for (int i=0; i<count; i++) {
210 ret |= m_barseries_with_sets->remove(m_testSets.at(i));
210 ret |= m_barseries_with_sets->remove(m_testSets.at(i));
211 }
211 }
212
212
213 QVERIFY(ret == true);
213 QVERIFY(ret == true);
214 QVERIFY(m_barseries_with_sets->count() == 0);
214 QVERIFY(m_barseries_with_sets->count() == 0);
215 }
215 }
216
216
217 void tst_QBarSeries::take_data()
217 void tst_QBarSeries::take_data()
218 {
218 {
219
219
220 }
220 }
221
221
222 void tst_QBarSeries::take()
222 void tst_QBarSeries::take()
223 {
223 {
224 int count = m_testSets.count();
224 int count = m_testSets.count();
225 QVERIFY(m_barseries_with_sets->count() == count);
225 QVERIFY(m_barseries_with_sets->count() == count);
226
226
227 QSignalSpy countSpy(m_barseries_with_sets,SIGNAL(countChanged()));
227 QSignalSpy countSpy(m_barseries_with_sets,SIGNAL(countChanged()));
228 QSignalSpy removedSpy(m_barseries_with_sets,SIGNAL(barsetsRemoved(QList<QBarSet*>)));
228 QSignalSpy removedSpy(m_barseries_with_sets,SIGNAL(barsetsRemoved(QList<QBarSet*>)));
229
229
230 for (int i=0; i<m_testSets.count(); i++) {
230 for (int i=0; i<m_testSets.count(); i++) {
231 QBarSet* set = m_testSets.at(i);
231 QBarSet* set = m_testSets.at(i);
232 bool success = m_barseries_with_sets->take(set);
232 bool success = m_barseries_with_sets->take(set);
233 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
233 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
234 QVERIFY(success);
234 QVERIFY(success);
235 TRY_COMPARE(countSpy.count(),1);
235 TRY_COMPARE(countSpy.count(),1);
236 TRY_COMPARE(removedSpy.count(),1);
236 TRY_COMPARE(removedSpy.count(),1);
237
237
238 QList<QVariant> removedSpyArg = removedSpy.takeFirst();
238 QList<QVariant> removedSpyArg = removedSpy.takeFirst();
239 QList<QBarSet*> removedSets = qvariant_cast<QList<QBarSet*> > (removedSpyArg.at(0));
239 QList<QBarSet*> removedSets = qvariant_cast<QList<QBarSet*> > (removedSpyArg.at(0));
240 QCOMPARE(removedSets.at(0), m_testSets.at(i));
240 QCOMPARE(removedSets.at(0), m_testSets.at(i));
241 countSpy.takeFirst();
241 countSpy.takeFirst();
242 }
242 }
243 }
243 }
244
244
245
245
246 void tst_QBarSeries::appendList_data()
246 void tst_QBarSeries::appendList_data()
247 {
247 {
248
248
249 }
249 }
250
250
251 void tst_QBarSeries::appendList()
251 void tst_QBarSeries::appendList()
252 {
252 {
253 int count = 5;
253 int count = 5;
254 QVERIFY(m_barseries->count() == 0);
254 QVERIFY(m_barseries->count() == 0);
255
255
256 QList<QBarSet*> sets;
256 QList<QBarSet*> sets;
257 for (int i=0; i<count; i++) {
257 for (int i=0; i<count; i++) {
258 sets.append(new QBarSet("testset"));
258 sets.append(new QBarSet("testset"));
259 }
259 }
260
260
261 // Append new sets (should succeed, count should match the count of sets)
261 // Append new sets (should succeed, count should match the count of sets)
262 bool ret = false;
262 bool ret = false;
263 ret = m_barseries->append(sets);
263 ret = m_barseries->append(sets);
264 QVERIFY(ret == true);
264 QVERIFY(ret == true);
265 QVERIFY(m_barseries->count() == count);
265 QVERIFY(m_barseries->count() == count);
266
266
267 // Append same sets again (should fail, count should remain same)
267 // Append same sets again (should fail, count should remain same)
268 ret = m_barseries->append(sets);
268 ret = m_barseries->append(sets);
269 QVERIFY(ret == false);
269 QVERIFY(ret == false);
270 QVERIFY(m_barseries->count() == count);
270 QVERIFY(m_barseries->count() == count);
271
271
272 // Try append empty list (should succeed, but count should remain same)
272 // Try append empty list (should succeed, but count should remain same)
273 QList<QBarSet*> invalidList;
273 QList<QBarSet*> invalidList;
274 ret = m_barseries->append(invalidList);
274 ret = m_barseries->append(invalidList);
275 QVERIFY(ret == true);
275 QVERIFY(ret == true);
276 QVERIFY(m_barseries->count() == count);
276 QVERIFY(m_barseries->count() == count);
277
277
278 // Try append list with one new and one existing set (should fail, count remains same)
278 // Try append list with one new and one existing set (should fail, count remains same)
279 invalidList.append(new QBarSet("ok set"));
279 invalidList.append(new QBarSet("ok set"));
280 invalidList.append(sets.at(0));
280 invalidList.append(sets.at(0));
281 ret = m_barseries->append(invalidList);
281 ret = m_barseries->append(invalidList);
282 QVERIFY(ret == false);
282 QVERIFY(ret == false);
283 QVERIFY(m_barseries->count() == count);
283 QVERIFY(m_barseries->count() == count);
284
284
285 // Try append list with null pointers (should fail, count remains same)
285 // Try append list with null pointers (should fail, count remains same)
286 QList<QBarSet*> invalidList2;
286 QList<QBarSet*> invalidList2;
287 invalidList2.append(0);
287 invalidList2.append(0);
288 invalidList2.append(0);
288 invalidList2.append(0);
289 invalidList2.append(0);
289 invalidList2.append(0);
290 ret = m_barseries->append(invalidList2);
290 ret = m_barseries->append(invalidList2);
291 QVERIFY(ret == false);
291 QVERIFY(ret == false);
292 QVERIFY(m_barseries->count() == count);
292 QVERIFY(m_barseries->count() == count);
293 }
293 }
294
294
295 void tst_QBarSeries::count_data()
295 void tst_QBarSeries::count_data()
296 {
296 {
297
297
298 }
298 }
299
299
300 void tst_QBarSeries::count()
300 void tst_QBarSeries::count()
301 {
301 {
302 QVERIFY(m_barseries->count() == 0);
302 QVERIFY(m_barseries->count() == 0);
303 QVERIFY(m_barseries_with_sets->count() == m_testSets.count());
303 QVERIFY(m_barseries_with_sets->count() == m_testSets.count());
304 }
304 }
305
305
306 void tst_QBarSeries::barSets_data()
306 void tst_QBarSeries::barSets_data()
307 {
307 {
308
308
309 }
309 }
310
310
311 void tst_QBarSeries::barSets()
311 void tst_QBarSeries::barSets()
312 {
312 {
313 QVERIFY(m_barseries->barSets().count() == 0);
313 QVERIFY(m_barseries->barSets().count() == 0);
314
314
315 QList<QBarSet*> sets = m_barseries_with_sets->barSets();
315 QList<QBarSet*> sets = m_barseries_with_sets->barSets();
316 QVERIFY(sets.count() == m_testSets.count());
316 QVERIFY(sets.count() == m_testSets.count());
317
317
318 for (int i=0; i<m_testSets.count(); i++) {
318 for (int i=0; i<m_testSets.count(); i++) {
319 QVERIFY(sets.at(i) == m_testSets.at(i));
319 QVERIFY(sets.at(i) == m_testSets.at(i));
320 }
320 }
321 }
321 }
322
322
323 void tst_QBarSeries::setLabelsVisible_data()
323 void tst_QBarSeries::setLabelsVisible_data()
324 {
324 {
325
325
326 }
326 }
327
327
328 void tst_QBarSeries::setLabelsVisible()
328 void tst_QBarSeries::setLabelsVisible()
329 {
329 {
330 // labels should be invisible by default
330 // labels should be invisible by default
331 QVERIFY(m_barseries->isLabelsVisible() == false);
331 QVERIFY(m_barseries->isLabelsVisible() == false);
332 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
332 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
333
333
334 // turn labels to visible
334 // turn labels to visible
335 m_barseries_with_sets->setLabelsVisible(true);
335 m_barseries_with_sets->setLabelsVisible(true);
336 // TODO: test the signal
336 // TODO: test the signal
337 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
337 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
338
338
339 // turn labels to invisible
339 // turn labels to invisible
340 m_barseries_with_sets->setLabelsVisible(false);
340 m_barseries_with_sets->setLabelsVisible(false);
341 // TODO: test the signal
341 // TODO: test the signal
342 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
342 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
343
343
344 // without parameter, should turn labels to visible
344 // without parameter, should turn labels to visible
345 m_barseries_with_sets->setLabelsVisible();
345 m_barseries_with_sets->setLabelsVisible();
346 // TODO: test the signal
346 // TODO: test the signal
347 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
347 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
348 }
348 }
349
349
350 void tst_QBarSeries::setLabelsFormat()
350 void tst_QBarSeries::setLabelsFormat()
351 {
351 {
352 QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString)));
352 QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString)));
353 QCOMPARE(m_barseries->labelsFormat(), QString());
353 QCOMPARE(m_barseries->labelsFormat(), QString());
354
354
355 QString format("(@value)");
355 QString format("(@value)");
356 m_barseries->setLabelsFormat(format);
356 m_barseries->setLabelsFormat(format);
357 TRY_COMPARE(labelsFormatSpy.count(), 1);
357 TRY_COMPARE(labelsFormatSpy.count(), 1);
358 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
358 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
359 QVERIFY(arguments.at(0).toString() == format);
359 QVERIFY(arguments.at(0).toString() == format);
360 QCOMPARE(m_barseries->labelsFormat(), format);
360 QCOMPARE(m_barseries->labelsFormat(), format);
361
361
362 m_barseries->setLabelsFormat(QString());
362 m_barseries->setLabelsFormat(QString());
363 TRY_COMPARE(labelsFormatSpy.count(), 1);
363 TRY_COMPARE(labelsFormatSpy.count(), 1);
364 arguments = labelsFormatSpy.takeFirst();
364 arguments = labelsFormatSpy.takeFirst();
365 QVERIFY(arguments.at(0).toString() == QString());
365 QVERIFY(arguments.at(0).toString() == QString());
366 QCOMPARE(m_barseries->labelsFormat(), QString());
366 QCOMPARE(m_barseries->labelsFormat(), QString());
367 }
367 }
368
368
369 void tst_QBarSeries::setLabelsPosition()
369 void tst_QBarSeries::setLabelsPosition()
370 {
370 {
371 QSignalSpy labelsPositionSpy(m_barseries,
371 QSignalSpy labelsPositionSpy(m_barseries,
372 SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)));
372 SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)));
373 QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsCenter);
373 QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsCenter);
374
374
375 m_barseries->setLabelsPosition(QBarSeries::LabelsInsideEnd);
375 m_barseries->setLabelsPosition(QBarSeries::LabelsInsideEnd);
376 TRY_COMPARE(labelsPositionSpy.count(), 1);
376 TRY_COMPARE(labelsPositionSpy.count(), 1);
377 QList<QVariant> arguments = labelsPositionSpy.takeFirst();
377 QList<QVariant> arguments = labelsPositionSpy.takeFirst();
378 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
378 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
379 == QBarSeries::LabelsInsideEnd);
379 == QBarSeries::LabelsInsideEnd);
380 QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsInsideEnd);
380 QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsInsideEnd);
381
381
382 m_barseries->setLabelsPosition(QBarSeries::LabelsInsideBase);
382 m_barseries->setLabelsPosition(QBarSeries::LabelsInsideBase);
383 TRY_COMPARE(labelsPositionSpy.count(), 1);
383 TRY_COMPARE(labelsPositionSpy.count(), 1);
384 arguments = labelsPositionSpy.takeFirst();
384 arguments = labelsPositionSpy.takeFirst();
385 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
385 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
386 == QBarSeries::LabelsInsideBase);
386 == QBarSeries::LabelsInsideBase);
387 QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsInsideBase);
387 QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsInsideBase);
388
388
389 m_barseries->setLabelsPosition(QBarSeries::LabelsOutsideEnd);
389 m_barseries->setLabelsPosition(QBarSeries::LabelsOutsideEnd);
390 TRY_COMPARE(labelsPositionSpy.count(), 1);
390 TRY_COMPARE(labelsPositionSpy.count(), 1);
391 arguments = labelsPositionSpy.takeFirst();
391 arguments = labelsPositionSpy.takeFirst();
392 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
392 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
393 == QBarSeries::LabelsOutsideEnd);
393 == QBarSeries::LabelsOutsideEnd);
394 QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsOutsideEnd);
394 QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsOutsideEnd);
395
395
396 m_barseries->setLabelsPosition(QBarSeries::LabelsCenter);
396 m_barseries->setLabelsPosition(QBarSeries::LabelsCenter);
397 TRY_COMPARE(labelsPositionSpy.count(), 1);
397 TRY_COMPARE(labelsPositionSpy.count(), 1);
398 arguments = labelsPositionSpy.takeFirst();
398 arguments = labelsPositionSpy.takeFirst();
399 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
399 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
400 == QBarSeries::LabelsCenter);
400 == QBarSeries::LabelsCenter);
401 QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsCenter);
401 QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsCenter);
402 }
402 }
403
403
404 void tst_QBarSeries::opacity()
404 void tst_QBarSeries::opacity()
405 {
405 {
406 QSignalSpy opacitySpy(m_barseries, SIGNAL(opacityChanged()));
406 QSignalSpy opacitySpy(m_barseries, SIGNAL(opacityChanged()));
407
407
408 QCOMPARE(m_barseries->opacity(), 1.0);
408 QCOMPARE(m_barseries->opacity(), 1.0);
409
409
410 m_barseries->setOpacity(0.5);
410 m_barseries->setOpacity(0.5);
411 QCOMPARE(m_barseries->opacity(), 0.5);
411 QCOMPARE(m_barseries->opacity(), 0.5);
412 QCOMPARE(opacitySpy.count(), 1);
412 QCOMPARE(opacitySpy.count(), 1);
413
413
414 m_barseries->setOpacity(0.0);
414 m_barseries->setOpacity(0.0);
415 QCOMPARE(m_barseries->opacity(), 0.0);
415 QCOMPARE(m_barseries->opacity(), 0.0);
416 QCOMPARE(opacitySpy.count(), 2);
416 QCOMPARE(opacitySpy.count(), 2);
417
417
418 m_barseries->setOpacity(1.0);
418 m_barseries->setOpacity(1.0);
419 QCOMPARE(m_barseries->opacity(), 1.0);
419 QCOMPARE(m_barseries->opacity(), 1.0);
420 QCOMPARE(opacitySpy.count(), 3);
420 QCOMPARE(opacitySpy.count(), 3);
421 }
421 }
422
422
423 void tst_QBarSeries::mouseclicked_data()
423 void tst_QBarSeries::mouseclicked_data()
424 {
424 {
425
425
426 }
426 }
427
427
428 void tst_QBarSeries::mouseclicked()
428 void tst_QBarSeries::mouseclicked()
429 {
429 {
430 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
430 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
431
431
432 QBarSeries* series = new QBarSeries();
432 QBarSeries* series = new QBarSeries();
433
433
434 QBarSet* set1 = new QBarSet(QString("set 1"));
434 QBarSet* set1 = new QBarSet(QString("set 1"));
435 *set1 << 10 << 10 << 10;
435 *set1 << 10 << 10 << 10;
436 series->append(set1);
436 series->append(set1);
437
437
438 QBarSet* set2 = new QBarSet(QString("set 2"));
438 QBarSet* set2 = new QBarSet(QString("set 2"));
439 *set2 << 10 << 10 << 10;
439 *set2 << 10 << 10 << 10;
440 series->append(set2);
440 series->append(set2);
441 QList<QBarSet*> barSets = series->barSets();
441 QList<QBarSet*> barSets = series->barSets();
442
442
443 QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*)));
443 QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*)));
444 QSignalSpy setSpy1(set1, SIGNAL(clicked(int)));
444 QSignalSpy setSpy1(set1, SIGNAL(clicked(int)));
445 QSignalSpy setSpy2(set2, SIGNAL(clicked(int)));
445 QSignalSpy setSpy2(set2, SIGNAL(clicked(int)));
446
446
447 QChartView view(new QChart());
447 QChartView view(new QChart());
448 view.resize(400,300);
448 view.resize(400,300);
449 view.chart()->addSeries(series);
449 view.chart()->addSeries(series);
450 view.show();
450 view.show();
451 QTest::qWaitForWindowShown(&view);
451 QTest::qWaitForWindowShown(&view);
452
452
453 // Calculate expected layout for bars
453 // Calculate expected layout for bars
454 QRectF plotArea = view.chart()->plotArea();
454 QRectF plotArea = view.chart()->plotArea();
455 qreal width = plotArea.width();
455 qreal width = plotArea.width();
456 qreal height = plotArea.height();
456 qreal height = plotArea.height();
457 qreal rangeY = 10; // From 0 to 10 because of maximum value in set is 10
457 qreal rangeY = 10; // From 0 to 10 because of maximum value in set is 10
458 qreal rangeX = 3; // 3 values per set
458 qreal rangeX = 3; // 3 values per set
459 qreal scaleY = (height / rangeY);
459 qreal scaleY = (height / rangeY);
460 qreal scaleX = (width / rangeX);
460 qreal scaleX = (width / rangeX);
461
461
462 qreal setCount = series->count();
462 qreal setCount = series->count();
463 qreal domainMinY = 0; // These come from internal domain used by barseries.
463 qreal domainMinY = 0; // These come from internal domain used by barseries.
464 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
464 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
465 qreal rectWidth = (scaleX / setCount) * series->barWidth();
465 qreal rectWidth = (scaleX / setCount) * series->barWidth();
466
466
467 QVector<QRectF> layout;
467 QVector<QRectF> layout;
468
468
469 // 3 = count of values in set
469 // 3 = count of values in set
470 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
470 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
471 for (int i = 0; i < 3; i++) {
471 for (int i = 0; i < 3; i++) {
472 qreal yPos = height + scaleY * domainMinY + plotArea.top();
472 qreal yPos = height + scaleY * domainMinY + plotArea.top();
473 for (int set = 0; set < setCount; set++) {
473 for (int set = 0; set < setCount; set++) {
474 qreal xPos = (i - domainMinX) * scaleX + plotArea.left();
474 qreal xPos = (i - domainMinX) * scaleX + plotArea.left();
475 xPos -= series->count()*rectWidth/2;
475 xPos -= series->count()*rectWidth/2;
476 xPos += set*rectWidth;
476 xPos += set*rectWidth;
477
477
478 qreal rectHeight = barSets.at(set)->at(i) * scaleY;
478 qreal rectHeight = barSets.at(set)->at(i) * scaleY;
479 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
479 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
480 layout.append(rect);
480 layout.append(rect);
481 }
481 }
482 }
482 }
483
483
484 //====================================================================================
484 //====================================================================================
485 // barset 1, bar 0
485 // barset 1, bar 0
486 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
486 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
487 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
487 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
488
488
489 QCOMPARE(seriesSpy.count(), 1);
489 QCOMPARE(seriesSpy.count(), 1);
490 QCOMPARE(setSpy1.count(), 1);
490 QCOMPARE(setSpy1.count(), 1);
491 QCOMPARE(setSpy2.count(), 0);
491 QCOMPARE(setSpy2.count(), 0);
492
492
493 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
493 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
494 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
494 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
495 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
495 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
496 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
496 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
497
497
498 QList<QVariant> setSpyArg = setSpy1.takeFirst();
498 QList<QVariant> setSpyArg = setSpy1.takeFirst();
499 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
499 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
500 QVERIFY(setSpyArg.at(0).toInt() == 0);
500 QVERIFY(setSpyArg.at(0).toInt() == 0);
501
501
502 //====================================================================================
502 //====================================================================================
503 // barset 1, bar 1
503 // barset 1, bar 1
504 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
504 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
505 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
505 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
506
506
507 QCOMPARE(seriesSpy.count(), 1);
507 QCOMPARE(seriesSpy.count(), 1);
508 QCOMPARE(setSpy1.count(), 1);
508 QCOMPARE(setSpy1.count(), 1);
509 QCOMPARE(setSpy2.count(), 0);
509 QCOMPARE(setSpy2.count(), 0);
510
510
511 seriesSpyArg = seriesSpy.takeFirst();
511 seriesSpyArg = seriesSpy.takeFirst();
512 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
512 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
513 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
513 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
514 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
514 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
515
515
516 setSpyArg = setSpy1.takeFirst();
516 setSpyArg = setSpy1.takeFirst();
517 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
517 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
518 QVERIFY(setSpyArg.at(0).toInt() == 1);
518 QVERIFY(setSpyArg.at(0).toInt() == 1);
519
519
520 //====================================================================================
520 //====================================================================================
521 // barset 1, bar 2
521 // barset 1, bar 2
522 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
522 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
523 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
523 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
524
524
525 QCOMPARE(seriesSpy.count(), 1);
525 QCOMPARE(seriesSpy.count(), 1);
526 QCOMPARE(setSpy1.count(), 1);
526 QCOMPARE(setSpy1.count(), 1);
527 QCOMPARE(setSpy2.count(), 0);
527 QCOMPARE(setSpy2.count(), 0);
528
528
529 seriesSpyArg = seriesSpy.takeFirst();
529 seriesSpyArg = seriesSpy.takeFirst();
530 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
530 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
531 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
531 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
532 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
532 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
533
533
534 setSpyArg = setSpy1.takeFirst();
534 setSpyArg = setSpy1.takeFirst();
535 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
535 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
536 QVERIFY(setSpyArg.at(0).toInt() == 2);
536 QVERIFY(setSpyArg.at(0).toInt() == 2);
537
537
538 //====================================================================================
538 //====================================================================================
539 // barset 2, bar 0
539 // barset 2, bar 0
540 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
540 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
541 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
541 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
542
542
543 QCOMPARE(seriesSpy.count(), 1);
543 QCOMPARE(seriesSpy.count(), 1);
544 QCOMPARE(setSpy1.count(), 0);
544 QCOMPARE(setSpy1.count(), 0);
545 QCOMPARE(setSpy2.count(), 1);
545 QCOMPARE(setSpy2.count(), 1);
546
546
547 seriesSpyArg = seriesSpy.takeFirst();
547 seriesSpyArg = seriesSpy.takeFirst();
548 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
548 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
549 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
549 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
550 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
550 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
551
551
552 setSpyArg = setSpy2.takeFirst();
552 setSpyArg = setSpy2.takeFirst();
553 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
553 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
554 QVERIFY(setSpyArg.at(0).toInt() == 0);
554 QVERIFY(setSpyArg.at(0).toInt() == 0);
555
555
556 //====================================================================================
556 //====================================================================================
557 // barset 2, bar 1
557 // barset 2, bar 1
558 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
558 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
559 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
559 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
560
560
561 QCOMPARE(seriesSpy.count(), 1);
561 QCOMPARE(seriesSpy.count(), 1);
562 QCOMPARE(setSpy1.count(), 0);
562 QCOMPARE(setSpy1.count(), 0);
563 QCOMPARE(setSpy2.count(), 1);
563 QCOMPARE(setSpy2.count(), 1);
564
564
565 seriesSpyArg = seriesSpy.takeFirst();
565 seriesSpyArg = seriesSpy.takeFirst();
566 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
566 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
567 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
567 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
568 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
568 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
569
569
570 setSpyArg = setSpy2.takeFirst();
570 setSpyArg = setSpy2.takeFirst();
571 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
571 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
572 QVERIFY(setSpyArg.at(0).toInt() == 1);
572 QVERIFY(setSpyArg.at(0).toInt() == 1);
573
573
574 //====================================================================================
574 //====================================================================================
575 // barset 2, bar 2
575 // barset 2, bar 2
576 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
576 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
577 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
577 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
578
578
579 QCOMPARE(seriesSpy.count(), 1);
579 QCOMPARE(seriesSpy.count(), 1);
580 QCOMPARE(setSpy1.count(), 0);
580 QCOMPARE(setSpy1.count(), 0);
581 QCOMPARE(setSpy2.count(), 1);
581 QCOMPARE(setSpy2.count(), 1);
582
582
583 seriesSpyArg = seriesSpy.takeFirst();
583 seriesSpyArg = seriesSpy.takeFirst();
584 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
584 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
585 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
585 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
586 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
586 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
587
587
588 setSpyArg = setSpy2.takeFirst();
588 setSpyArg = setSpy2.takeFirst();
589 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
589 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
590 QVERIFY(setSpyArg.at(0).toInt() == 2);
590 QVERIFY(setSpyArg.at(0).toInt() == 2);
591 }
591 }
592
592
593 void tst_QBarSeries::mousehovered_data()
593 void tst_QBarSeries::mousehovered_data()
594 {
594 {
595
595
596 }
596 }
597
597
598 void tst_QBarSeries::mousehovered()
598 void tst_QBarSeries::mousehovered()
599 {
599 {
600 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
600 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
601
601
602 QBarSeries* series = new QBarSeries();
602 QBarSeries* series = new QBarSeries();
603
603
604 QBarSet* set1 = new QBarSet(QString("set 1"));
604 QBarSet* set1 = new QBarSet(QString("set 1"));
605 *set1 << 10 << 10 << 10;
605 *set1 << 10 << 10 << 10;
606 series->append(set1);
606 series->append(set1);
607
607
608 QBarSet* set2 = new QBarSet(QString("set 2"));
608 QBarSet* set2 = new QBarSet(QString("set 2"));
609 *set2 << 10 << 10 << 10;
609 *set2 << 10 << 10 << 10;
610 series->append(set2);
610 series->append(set2);
611 QList<QBarSet*> barSets = series->barSets();
611 QList<QBarSet*> barSets = series->barSets();
612
612
613 QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*)));
614 QSignalSpy seriesIndexSpy(series, SIGNAL(hovered(bool, int, QBarSet*)));
613 QSignalSpy seriesIndexSpy(series, SIGNAL(hovered(bool, int, QBarSet*)));
615 QSignalSpy setSpy1(set1, SIGNAL(hovered(bool)));
616 QSignalSpy setSpy2(set2, SIGNAL(hovered(bool)));
617 QSignalSpy setIndexSpy1(set1, SIGNAL(hovered(bool, int)));
614 QSignalSpy setIndexSpy1(set1, SIGNAL(hovered(bool, int)));
618 QSignalSpy setIndexSpy2(set2, SIGNAL(hovered(bool, int)));
615 QSignalSpy setIndexSpy2(set2, SIGNAL(hovered(bool, int)));
619
616
620 QChartView view(new QChart());
617 QChartView view(new QChart());
621 view.resize(400,300);
618 view.resize(400,300);
622 view.chart()->addSeries(series);
619 view.chart()->addSeries(series);
623 view.show();
620 view.show();
624 QTest::qWaitForWindowShown(&view);
621 QTest::qWaitForWindowShown(&view);
625
622
626 //this is hack since view does not get events otherwise
623 //this is hack since view does not get events otherwise
627 view.setMouseTracking(true);
624 view.setMouseTracking(true);
628
625
629 // Calculate expected layout for bars
626 // Calculate expected layout for bars
630 QRectF plotArea = view.chart()->plotArea();
627 QRectF plotArea = view.chart()->plotArea();
631 qreal width = plotArea.width();
628 qreal width = plotArea.width();
632 qreal height = plotArea.height();
629 qreal height = plotArea.height();
633 qreal rangeY = 10; // From 0 to 10 because of maximum value in set is 10
630 qreal rangeY = 10; // From 0 to 10 because of maximum value in set is 10
634 qreal rangeX = 3; // 3 values per set
631 qreal rangeX = 3; // 3 values per set
635 qreal scaleY = (height / rangeY);
632 qreal scaleY = (height / rangeY);
636 qreal scaleX = (width / rangeX);
633 qreal scaleX = (width / rangeX);
637
634
638 qreal setCount = series->count();
635 qreal setCount = series->count();
639 qreal domainMinY = 0; // These come from internal domain used by barseries.
636 qreal domainMinY = 0; // These come from internal domain used by barseries.
640 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
637 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
641 qreal rectWidth = (scaleX / setCount) * series->barWidth();
638 qreal rectWidth = (scaleX / setCount) * series->barWidth();
642
639
643 QVector<QRectF> layout;
640 QVector<QRectF> layout;
644
641
645 // 3 = count of values in set
642 // 3 = count of values in set
646 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
643 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
647 for (int i = 0; i < 3; i++) {
644 for (int i = 0; i < 3; i++) {
648 qreal yPos = height + scaleY * domainMinY + plotArea.top();
645 qreal yPos = height + scaleY * domainMinY + plotArea.top();
649 for (int set = 0; set < setCount; set++) {
646 for (int set = 0; set < setCount; set++) {
650 qreal xPos = (i - domainMinX) * scaleX + plotArea.left();
647 qreal xPos = (i - domainMinX) * scaleX + plotArea.left();
651 xPos -= series->count()*rectWidth/2;
648 xPos -= series->count()*rectWidth/2;
652 xPos += set*rectWidth;
649 xPos += set*rectWidth;
653
650
654 qreal rectHeight = barSets.at(set)->at(i) * scaleY;
651 qreal rectHeight = barSets.at(set)->at(i) * scaleY;
655 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
652 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
656 layout.append(rect);
653 layout.append(rect);
657 }
654 }
658 }
655 }
659
656
660 //=======================================================================
657 //=======================================================================
661 // move mouse to left border
658 // move mouse to left border
662 QTest::mouseMove(view.viewport(), QPoint(0, layout.at(0).center().y()));
659 QTest::mouseMove(view.viewport(), QPoint(0, layout.at(0).center().y()));
663 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
660 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
664 TRY_COMPARE(seriesSpy.count(), 0);
665 TRY_COMPARE(seriesIndexSpy.count(), 0);
661 TRY_COMPARE(seriesIndexSpy.count(), 0);
666 TRY_COMPARE(setSpy1.count(), 0);
667 TRY_COMPARE(setSpy2.count(), 0);
668 TRY_COMPARE(setIndexSpy1.count(), 0);
662 TRY_COMPARE(setIndexSpy1.count(), 0);
669 TRY_COMPARE(setIndexSpy2.count(), 0);
663 TRY_COMPARE(setIndexSpy2.count(), 0);
670
664
671 //=======================================================================
665 //=======================================================================
672 // move mouse on top of set1
666 // move mouse on top of set1
673 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
667 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
674 TRY_COMPARE(seriesSpy.count(), 1);
675 TRY_COMPARE(seriesIndexSpy.count(), 1);
668 TRY_COMPARE(seriesIndexSpy.count(), 1);
676 TRY_COMPARE(setSpy1.count(), 1);
677 TRY_COMPARE(setSpy2.count(), 0);
678 TRY_COMPARE(setIndexSpy1.count(), 1);
669 TRY_COMPARE(setIndexSpy1.count(), 1);
679 TRY_COMPARE(setIndexSpy2.count(), 0);
670 TRY_COMPARE(setIndexSpy2.count(), 0);
680
671
681 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
682 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
683 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
684 QVERIFY(seriesSpyArg.at(0).toBool() == true);
685
686 QList<QVariant> seriesIndexSpyArg = seriesIndexSpy.takeFirst();
672 QList<QVariant> seriesIndexSpyArg = seriesIndexSpy.takeFirst();
687 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
673 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
688 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
674 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
689 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
675 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
690
676
691 QList<QVariant> setSpyArg = setSpy1.takeFirst();
692 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
693 QVERIFY(setSpyArg.at(0).toBool() == true);
694
695 QList<QVariant> setIndexSpyArg = setIndexSpy1.takeFirst();
677 QList<QVariant> setIndexSpyArg = setIndexSpy1.takeFirst();
696 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
678 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
697 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
679 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
698
680
699 //=======================================================================
681 //=======================================================================
700 // move mouse from top of set1 to top of set2
682 // move mouse from top of set1 to top of set2
701 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
683 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
702 TRY_COMPARE(seriesSpy.count(), 2);
703 TRY_COMPARE(seriesIndexSpy.count(), 2);
684 TRY_COMPARE(seriesIndexSpy.count(), 2);
704 TRY_COMPARE(setSpy1.count(), 1);
705 TRY_COMPARE(setSpy2.count(), 1);
706 TRY_COMPARE(setIndexSpy1.count(), 1);
685 TRY_COMPARE(setIndexSpy1.count(), 1);
707 TRY_COMPARE(setIndexSpy2.count(), 1);
686 TRY_COMPARE(setIndexSpy2.count(), 1);
708
687
709 // should leave set1
688 // should leave set1
710 seriesSpyArg = seriesSpy.takeFirst();
711 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
712 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
713 QVERIFY(seriesSpyArg.at(0).toBool() == false);
714
715 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
689 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
716 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
690 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
717 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
691 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
718 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
692 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
719
693
720 setSpyArg = setSpy1.takeFirst();
721 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
722 QVERIFY(setSpyArg.at(0).toBool() == false);
723
724 setIndexSpyArg = setIndexSpy1.takeFirst();
694 setIndexSpyArg = setIndexSpy1.takeFirst();
725 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
695 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
726 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
696 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
727
697
728 // should enter set2
698 // should enter set2
729 seriesSpyArg = seriesSpy.takeFirst();
730 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
731 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
732 QVERIFY(seriesSpyArg.at(0).toBool() == true);
733
734 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
699 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
735 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
700 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
736 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
701 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
737 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
702 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
738
703
739 setSpyArg = setSpy2.takeFirst();
740 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
741 QVERIFY(setSpyArg.at(0).toBool() == true);
742
743 setIndexSpyArg = setIndexSpy2.takeFirst();
704 setIndexSpyArg = setIndexSpy2.takeFirst();
744 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
705 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
745 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
706 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
746
707
747 //=======================================================================
708 //=======================================================================
748 // move mouse from top of set2 to background
709 // move mouse from top of set2 to background
749 QTest::mouseMove(view.viewport(), QPoint(layout.at(1).center().x(), 0));
710 QTest::mouseMove(view.viewport(), QPoint(layout.at(1).center().x(), 0));
750 TRY_COMPARE(seriesSpy.count(), 1);
751 TRY_COMPARE(seriesIndexSpy.count(), 1);
711 TRY_COMPARE(seriesIndexSpy.count(), 1);
752 TRY_COMPARE(setSpy1.count(), 0);
753 TRY_COMPARE(setSpy2.count(), 1);
754 TRY_COMPARE(setIndexSpy1.count(), 0);
712 TRY_COMPARE(setIndexSpy1.count(), 0);
755 TRY_COMPARE(setIndexSpy2.count(), 1);
713 TRY_COMPARE(setIndexSpy2.count(), 1);
756
714
757 // should leave set2
715 // should leave set2
758 seriesSpyArg = seriesSpy.takeFirst();
759 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
760 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
761 QVERIFY(seriesSpyArg.at(0).toBool() == false);
762
763 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
716 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
764 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
717 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
765 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
718 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
766 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
719 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
767
720
768 setSpyArg = setSpy2.takeFirst();
769 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
770 QVERIFY(setSpyArg.at(0).toBool() == false);
771
772 setIndexSpyArg = setIndexSpy2.takeFirst();
721 setIndexSpyArg = setIndexSpy2.takeFirst();
773 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
722 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
774 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
723 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
775
724
776 //=======================================================================
725 //=======================================================================
777 // move mouse on top of set1, bar0 to check the index (hover into set1)
726 // move mouse on top of set1, bar0 to check the index (hover into set1)
778 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
727 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
779
728
780 TRY_COMPARE(seriesSpy.count(), 1);
781 TRY_COMPARE(seriesIndexSpy.count(), 1);
729 TRY_COMPARE(seriesIndexSpy.count(), 1);
782 TRY_COMPARE(setSpy1.count(), 1);
783 TRY_COMPARE(setSpy2.count(), 0);
784 TRY_COMPARE(setIndexSpy1.count(), 1);
730 TRY_COMPARE(setIndexSpy1.count(), 1);
785 TRY_COMPARE(setIndexSpy2.count(), 0);
731 TRY_COMPARE(setIndexSpy2.count(), 0);
786
732
787 //should enter set1, bar0
733 //should enter set1, bar0
788 seriesSpyArg = seriesSpy.takeFirst();
789 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
790 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
791 QVERIFY(seriesSpyArg.at(0).toBool() == true);
792
793 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
734 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
794 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
735 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
795 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
736 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
796 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
737 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
797 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
738 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
798 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
739 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
799
740
800 setSpyArg = setSpy1.takeFirst();
801 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
802 QVERIFY(setSpyArg.at(0).toBool() == true);
803
804 setIndexSpyArg = setIndexSpy1.takeFirst();
741 setIndexSpyArg = setIndexSpy1.takeFirst();
805 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
742 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
806 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
743 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
807 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
744 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
808 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
745 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
809
746
810 //=======================================================================
747 //=======================================================================
811 // move mouse on top of set2, bar0 to check the index (hover out set1,
748 // move mouse on top of set2, bar0 to check the index (hover out set1,
812 // hover in set1)
749 // hover in set1)
813 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
750 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
814
751
815 TRY_COMPARE(seriesSpy.count(), 2);
816 TRY_COMPARE(seriesIndexSpy.count(), 2);
752 TRY_COMPARE(seriesIndexSpy.count(), 2);
817 TRY_COMPARE(setSpy1.count(), 1);
818 TRY_COMPARE(setSpy2.count(), 1);
819 TRY_COMPARE(setIndexSpy1.count(), 1);
753 TRY_COMPARE(setIndexSpy1.count(), 1);
820 TRY_COMPARE(setIndexSpy2.count(), 1);
754 TRY_COMPARE(setIndexSpy2.count(), 1);
821
755
822 // should leave set1, bar0
756 // should leave set1, bar0
823 seriesSpyArg = seriesSpy.takeFirst();
824 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
825 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
826 QVERIFY(seriesSpyArg.at(0).toBool() == false);
827
828 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
757 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
829 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
758 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
830 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
759 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
831 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
760 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
832 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
761 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
833 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
762 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
834
763
835 setSpyArg = setSpy1.takeFirst();
836 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
837 QVERIFY(setSpyArg.at(0).toBool() == false);
838
839 setIndexSpyArg = setIndexSpy1.takeFirst();
764 setIndexSpyArg = setIndexSpy1.takeFirst();
840 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
765 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
841 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
766 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
842 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
767 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
843 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
768 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
844
769
845 // should enter set2, bar0
770 // should enter set2, bar0
846 seriesSpyArg = seriesSpy.takeFirst();
847 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
848 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
849 QVERIFY(seriesSpyArg.at(0).toBool() == true);
850
851 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
771 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
852 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
772 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
853 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
773 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
854 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
774 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
855 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
775 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
856 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
776 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
857
777
858 setSpyArg = setSpy2.takeFirst();
859 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
860 QVERIFY(setSpyArg.at(0).toBool() == true);
861
862 setIndexSpyArg = setIndexSpy2.takeFirst();
778 setIndexSpyArg = setIndexSpy2.takeFirst();
863 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
779 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
864 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
780 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
865 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
781 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
866 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
782 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
867
783
868 //=======================================================================
784 //=======================================================================
869 // move mouse on top of set1, bar1 to check the index (hover out set 2,
785 // move mouse on top of set1, bar1 to check the index (hover out set 2,
870 // hover in set1)
786 // hover in set1)
871 QTest::mouseMove(view.viewport(), layout.at(2).center().toPoint());
787 QTest::mouseMove(view.viewport(), layout.at(2).center().toPoint());
872
788
873 TRY_COMPARE(seriesSpy.count(), 2);
874 TRY_COMPARE(seriesIndexSpy.count(), 2);
789 TRY_COMPARE(seriesIndexSpy.count(), 2);
875 TRY_COMPARE(setSpy1.count(), 1);
876 TRY_COMPARE(setSpy2.count(), 1);
877 TRY_COMPARE(setIndexSpy1.count(), 1);
790 TRY_COMPARE(setIndexSpy1.count(), 1);
878 TRY_COMPARE(setIndexSpy2.count(), 1);
791 TRY_COMPARE(setIndexSpy2.count(), 1);
879
792
880 // should leave set2, bar0
793 // should leave set2, bar0
881 seriesSpyArg = seriesSpy.takeFirst();
882 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
883 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
884 QVERIFY(seriesSpyArg.at(0).toBool() == false);
885
886 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
794 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
887 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
795 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
888 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
796 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
889 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
797 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
890 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
798 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
891 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
799 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
892
800
893 setSpyArg = setSpy2.takeFirst();
894 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
895 QVERIFY(setSpyArg.at(0).toBool() == false);
896
897 setIndexSpyArg = setIndexSpy2.takeFirst();
801 setIndexSpyArg = setIndexSpy2.takeFirst();
898 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
802 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
899 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
803 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
900 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
804 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
901 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
805 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
902
806
903 // should enter set1, bar1
807 // should enter set1, bar1
904 seriesSpyArg = seriesSpy.takeFirst();
905 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
906 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
907 QVERIFY(seriesSpyArg.at(0).toBool() == true);
908
909 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
808 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
910 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
809 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
911 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
810 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
912 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
811 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
913 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
812 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
914 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
813 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
915
814
916 setSpyArg = setSpy1.takeFirst();
917 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
918 QVERIFY(setSpyArg.at(0).toBool() == true);
919
920 setIndexSpyArg = setIndexSpy1.takeFirst();
815 setIndexSpyArg = setIndexSpy1.takeFirst();
921 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
816 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
922 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
817 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
923 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
818 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
924 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
819 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
925
820
926 //=======================================================================
821 //=======================================================================
927 // move mouse on top of view between set1 and set2 to check the index
822 // move mouse on top of view between set1 and set2 to check the index
928 // (hover out set1)
823 // (hover out set1)
929 QTest::mouseMove(view.viewport(), QPoint((layout.at(2).right() + layout.at(3).left()) / 2, 0));
824 QTest::mouseMove(view.viewport(), QPoint((layout.at(2).right() + layout.at(3).left()) / 2, 0));
930
825
931 TRY_COMPARE(seriesSpy.count(), 1);
932 TRY_COMPARE(seriesIndexSpy.count(), 1);
826 TRY_COMPARE(seriesIndexSpy.count(), 1);
933 TRY_COMPARE(setSpy1.count(), 1);
934 TRY_COMPARE(setSpy2.count(), 0);
935 TRY_COMPARE(setIndexSpy1.count(), 1);
827 TRY_COMPARE(setIndexSpy1.count(), 1);
936 TRY_COMPARE(setIndexSpy2.count(), 0);
828 TRY_COMPARE(setIndexSpy2.count(), 0);
937
829
938 // should leave set1, bar1
830 // should leave set1, bar1
939 seriesSpyArg = seriesSpy.takeFirst();
940 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
941 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
942 QVERIFY(seriesSpyArg.at(0).toBool() == false);
943
944 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
831 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
945 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
832 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
946 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
833 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
947 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
834 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
948 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
835 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
949 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
836 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
950
837
951 setSpyArg = setSpy1.takeFirst();
952 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
953 QVERIFY(setSpyArg.at(0).toBool() == false);
954
955 setIndexSpyArg = setIndexSpy1.takeFirst();
838 setIndexSpyArg = setIndexSpy1.takeFirst();
956 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
839 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
957 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
840 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
958 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
841 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
959 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
842 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
960
843
961 //=======================================================================
844 //=======================================================================
962 // move mouse on top of set2, bar1 to check the index (hover in set2)
845 // move mouse on top of set2, bar1 to check the index (hover in set2)
963 QTest::mouseMove(view.viewport(), layout.at(3).center().toPoint());
846 QTest::mouseMove(view.viewport(), layout.at(3).center().toPoint());
964
847
965 TRY_COMPARE(seriesSpy.count(), 1);
966 TRY_COMPARE(seriesIndexSpy.count(), 1);
848 TRY_COMPARE(seriesIndexSpy.count(), 1);
967 TRY_COMPARE(setSpy1.count(), 0);
968 TRY_COMPARE(setSpy2.count(), 1);
969 TRY_COMPARE(setIndexSpy1.count(), 0);
849 TRY_COMPARE(setIndexSpy1.count(), 0);
970 TRY_COMPARE(setIndexSpy2.count(), 1);
850 TRY_COMPARE(setIndexSpy2.count(), 1);
971
851
972 // should enter set2, bar1
852 // should enter set2, bar1
973 seriesSpyArg = seriesSpy.takeFirst();
974 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
975 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
976 QVERIFY(seriesSpyArg.at(0).toBool() == true);
977
978 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
853 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
979 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
854 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
980 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
855 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
981 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
856 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
982 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
857 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
983 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
858 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
984
859
985 setSpyArg = setSpy2.takeFirst();
986 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
987 QVERIFY(setSpyArg.at(0).toBool() == true);
988
989 setIndexSpyArg = setIndexSpy2.takeFirst();
860 setIndexSpyArg = setIndexSpy2.takeFirst();
990 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
861 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
991 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
862 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
992 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
863 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
993 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
864 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
994
865
995 //=======================================================================
866 //=======================================================================
996 // move mouse on top of the view between bar1 and bar2 to check the index
867 // move mouse on top of the view between bar1 and bar2 to check the index
997 //(hover out set2)
868 //(hover out set2)
998 QTest::mouseMove(view.viewport(), QPoint((layout.at(3).right() + layout.at(3).left()) / 2, 0));
869 QTest::mouseMove(view.viewport(), QPoint((layout.at(3).right() + layout.at(3).left()) / 2, 0));
999
870
1000 TRY_COMPARE(seriesSpy.count(), 1);
1001 TRY_COMPARE(seriesIndexSpy.count(), 1);
871 TRY_COMPARE(seriesIndexSpy.count(), 1);
1002 TRY_COMPARE(setSpy1.count(), 0);
1003 TRY_COMPARE(setSpy2.count(), 1);
1004 TRY_COMPARE(setIndexSpy1.count(), 0);
872 TRY_COMPARE(setIndexSpy1.count(), 0);
1005 TRY_COMPARE(setIndexSpy2.count(), 1);
873 TRY_COMPARE(setIndexSpy2.count(), 1);
1006
874
1007 // should leave set2, bar1
875 // should leave set2, bar1
1008 seriesSpyArg = seriesSpy.takeFirst();
1009 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
1010 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
1011 QVERIFY(seriesSpyArg.at(0).toBool() == false);
1012
1013 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
876 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
1014 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
877 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
1015 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
878 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
1016 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
879 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
1017 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
880 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
1018 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
881 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
1019
882
1020 setSpyArg = setSpy2.takeFirst();
1021 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
1022 QVERIFY(setSpyArg.at(0).toBool() == false);
1023
1024 setIndexSpyArg = setIndexSpy2.takeFirst();
883 setIndexSpyArg = setIndexSpy2.takeFirst();
1025 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
884 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
1026 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
885 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
1027 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
886 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
1028 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
887 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
1029 }
888 }
1030
889
1031 void tst_QBarSeries::clearWithAnimations()
890 void tst_QBarSeries::clearWithAnimations()
1032 {
891 {
1033 QBarSeries* series = new QBarSeries();
892 QBarSeries* series = new QBarSeries();
1034
893
1035 QBarSet* set1 = new QBarSet(QString("set 1"));
894 QBarSet* set1 = new QBarSet(QString("set 1"));
1036 *set1 << 10 << 10 << 10;
895 *set1 << 10 << 10 << 10;
1037 series->append(set1);
896 series->append(set1);
1038
897
1039 QBarSet* set2 = new QBarSet(QString("set 2"));
898 QBarSet* set2 = new QBarSet(QString("set 2"));
1040 *set2 << 10 << 10 << 10;
899 *set2 << 10 << 10 << 10;
1041 series->append(set2);
900 series->append(set2);
1042
901
1043 QChartView view(new QChart());
902 QChartView view(new QChart());
1044 view.resize(400,300);
903 view.resize(400,300);
1045 view.chart()->setAnimationOptions(QChart::SeriesAnimations);
904 view.chart()->setAnimationOptions(QChart::SeriesAnimations);
1046 view.chart()->addSeries(series);
905 view.chart()->addSeries(series);
1047 view.show();
906 view.show();
1048
907
1049 series->clear();
908 series->clear();
1050 }
909 }
1051
910
1052 void tst_QBarSeries::destruction()
911 void tst_QBarSeries::destruction()
1053 {
912 {
1054 // add a barset
913 // add a barset
1055 QBarSeries *series = new QBarSeries();
914 QBarSeries *series = new QBarSeries();
1056 QBarSet *set = new QBarSet("testset");
915 QBarSet *set = new QBarSet("testset");
1057 QSignalSpy spy1(set, SIGNAL(destroyed()));
916 QSignalSpy spy1(set, SIGNAL(destroyed()));
1058 series->append(set);
917 series->append(set);
1059
918
1060 // delete the series
919 // delete the series
1061 delete series;
920 delete series;
1062
921
1063 // check that series deletes the set
922 // check that series deletes the set
1064 QCOMPARE(spy1.count(), 1);
923 QCOMPARE(spy1.count(), 1);
1065 }
924 }
1066
925
1067 QTEST_MAIN(tst_QBarSeries)
926 QTEST_MAIN(tst_QBarSeries)
1068
927
1069 #include "tst_qbarseries.moc"
928 #include "tst_qbarseries.moc"
1070
929
@@ -1,1003 +1,862
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 <QtCharts/QHorizontalBarSeries>
22 #include <QtCharts/QHorizontalBarSeries>
23 #include <QtCharts/QBarSet>
23 #include <QtCharts/QBarSet>
24 #include <QtCharts/QChartView>
24 #include <QtCharts/QChartView>
25 #include <QtCharts/QChart>
25 #include <QtCharts/QChart>
26 #include "tst_definitions.h"
26 #include "tst_definitions.h"
27
27
28 QT_CHARTS_USE_NAMESPACE
28 QT_CHARTS_USE_NAMESPACE
29
29
30 Q_DECLARE_METATYPE(QBarSet*)
30 Q_DECLARE_METATYPE(QBarSet*)
31 Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition)
31 Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition)
32
32
33 class tst_QHorizontalBarSeries : public QObject
33 class tst_QHorizontalBarSeries : public QObject
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36
36
37 public slots:
37 public slots:
38 void initTestCase();
38 void initTestCase();
39 void cleanupTestCase();
39 void cleanupTestCase();
40 void init();
40 void init();
41 void cleanup();
41 void cleanup();
42
42
43 private slots:
43 private slots:
44 void qhorizontalbarseries_data();
44 void qhorizontalbarseries_data();
45 void qhorizontalbarseries();
45 void qhorizontalbarseries();
46 void type_data();
46 void type_data();
47 void type();
47 void type();
48 void append_data();
48 void append_data();
49 void append();
49 void append();
50 void remove_data();
50 void remove_data();
51 void remove();
51 void remove();
52 void appendList_data();
52 void appendList_data();
53 void appendList();
53 void appendList();
54 void count_data();
54 void count_data();
55 void count();
55 void count();
56 void barSets_data();
56 void barSets_data();
57 void barSets();
57 void barSets();
58 void setLabelsVisible_data();
58 void setLabelsVisible_data();
59 void setLabelsVisible();
59 void setLabelsVisible();
60 void setLabelsFormat();
60 void setLabelsFormat();
61 void setLabelsPosition();
61 void setLabelsPosition();
62 void mouseclicked_data();
62 void mouseclicked_data();
63 void mouseclicked();
63 void mouseclicked();
64 void mousehovered_data();
64 void mousehovered_data();
65 void mousehovered();
65 void mousehovered();
66 void clearWithAnimations();
66 void clearWithAnimations();
67
67
68 private:
68 private:
69 QHorizontalBarSeries* m_barseries;
69 QHorizontalBarSeries* m_barseries;
70 QHorizontalBarSeries* m_barseries_with_sets;
70 QHorizontalBarSeries* m_barseries_with_sets;
71
71
72 QList<QBarSet*> m_testSets;
72 QList<QBarSet*> m_testSets;
73
73
74 };
74 };
75
75
76 void tst_QHorizontalBarSeries::initTestCase()
76 void tst_QHorizontalBarSeries::initTestCase()
77 {
77 {
78 qRegisterMetaType<QBarSet*>("QBarSet*");
78 qRegisterMetaType<QBarSet*>("QBarSet*");
79 qRegisterMetaType<QAbstractBarSeries::LabelsPosition>("QAbstractBarSeries::LabelsPosition");
79 qRegisterMetaType<QAbstractBarSeries::LabelsPosition>("QAbstractBarSeries::LabelsPosition");
80 }
80 }
81
81
82 void tst_QHorizontalBarSeries::cleanupTestCase()
82 void tst_QHorizontalBarSeries::cleanupTestCase()
83 {
83 {
84 }
84 }
85
85
86 void tst_QHorizontalBarSeries::init()
86 void tst_QHorizontalBarSeries::init()
87 {
87 {
88 m_barseries = new QHorizontalBarSeries();
88 m_barseries = new QHorizontalBarSeries();
89 m_barseries_with_sets = new QHorizontalBarSeries();
89 m_barseries_with_sets = new QHorizontalBarSeries();
90
90
91 for (int i=0; i<5; i++) {
91 for (int i=0; i<5; i++) {
92 m_testSets.append(new QBarSet("testset"));
92 m_testSets.append(new QBarSet("testset"));
93 m_barseries_with_sets->append(m_testSets.at(i));
93 m_barseries_with_sets->append(m_testSets.at(i));
94 }
94 }
95 }
95 }
96
96
97 void tst_QHorizontalBarSeries::cleanup()
97 void tst_QHorizontalBarSeries::cleanup()
98 {
98 {
99 foreach (QBarSet* s, m_testSets) {
99 foreach (QBarSet* s, m_testSets) {
100 m_barseries_with_sets->remove(s);
100 m_barseries_with_sets->remove(s);
101 }
101 }
102 m_testSets.clear();
102 m_testSets.clear();
103
103
104 delete m_barseries;
104 delete m_barseries;
105 m_barseries = 0;
105 m_barseries = 0;
106 delete m_barseries_with_sets;
106 delete m_barseries_with_sets;
107 m_barseries_with_sets = 0;
107 m_barseries_with_sets = 0;
108 }
108 }
109
109
110 void tst_QHorizontalBarSeries::qhorizontalbarseries_data()
110 void tst_QHorizontalBarSeries::qhorizontalbarseries_data()
111 {
111 {
112 }
112 }
113
113
114 void tst_QHorizontalBarSeries::qhorizontalbarseries()
114 void tst_QHorizontalBarSeries::qhorizontalbarseries()
115 {
115 {
116 QHorizontalBarSeries *barseries = new QHorizontalBarSeries();
116 QHorizontalBarSeries *barseries = new QHorizontalBarSeries();
117 QVERIFY(barseries != 0);
117 QVERIFY(barseries != 0);
118 }
118 }
119
119
120 void tst_QHorizontalBarSeries::type_data()
120 void tst_QHorizontalBarSeries::type_data()
121 {
121 {
122
122
123 }
123 }
124
124
125 void tst_QHorizontalBarSeries::type()
125 void tst_QHorizontalBarSeries::type()
126 {
126 {
127 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeHorizontalBar);
127 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeHorizontalBar);
128 }
128 }
129
129
130 void tst_QHorizontalBarSeries::append_data()
130 void tst_QHorizontalBarSeries::append_data()
131 {
131 {
132 }
132 }
133
133
134 void tst_QHorizontalBarSeries::append()
134 void tst_QHorizontalBarSeries::append()
135 {
135 {
136 QVERIFY(m_barseries->count() == 0);
136 QVERIFY(m_barseries->count() == 0);
137
137
138 bool ret = false;
138 bool ret = false;
139
139
140 // Try adding barset
140 // Try adding barset
141 QBarSet *barset = new QBarSet("testset");
141 QBarSet *barset = new QBarSet("testset");
142 ret = m_barseries->append(barset);
142 ret = m_barseries->append(barset);
143
143
144 QVERIFY(ret == true);
144 QVERIFY(ret == true);
145 QVERIFY(m_barseries->count() == 1);
145 QVERIFY(m_barseries->count() == 1);
146
146
147 // Try adding another set
147 // Try adding another set
148 QBarSet *barset2 = new QBarSet("testset2");
148 QBarSet *barset2 = new QBarSet("testset2");
149 ret = m_barseries->append(barset2);
149 ret = m_barseries->append(barset2);
150
150
151 QVERIFY(ret == true);
151 QVERIFY(ret == true);
152 QVERIFY(m_barseries->count() == 2);
152 QVERIFY(m_barseries->count() == 2);
153
153
154 // Try adding same set again
154 // Try adding same set again
155 ret = m_barseries->append(barset2);
155 ret = m_barseries->append(barset2);
156 QVERIFY(ret == false);
156 QVERIFY(ret == false);
157 QVERIFY(m_barseries->count() == 2);
157 QVERIFY(m_barseries->count() == 2);
158
158
159 // Try adding null set
159 // Try adding null set
160 ret = m_barseries->append(0);
160 ret = m_barseries->append(0);
161 QVERIFY(ret == false);
161 QVERIFY(ret == false);
162 QVERIFY(m_barseries->count() == 2);
162 QVERIFY(m_barseries->count() == 2);
163
163
164 }
164 }
165
165
166 void tst_QHorizontalBarSeries::remove_data()
166 void tst_QHorizontalBarSeries::remove_data()
167 {
167 {
168 }
168 }
169
169
170 void tst_QHorizontalBarSeries::remove()
170 void tst_QHorizontalBarSeries::remove()
171 {
171 {
172 int count = m_testSets.count();
172 int count = m_testSets.count();
173 QVERIFY(m_barseries_with_sets->count() == count);
173 QVERIFY(m_barseries_with_sets->count() == count);
174
174
175 // Try to remove null pointer (should not remove, should not crash)
175 // Try to remove null pointer (should not remove, should not crash)
176 bool ret = false;
176 bool ret = false;
177 ret = m_barseries_with_sets->remove(0);
177 ret = m_barseries_with_sets->remove(0);
178 QVERIFY(ret == false);
178 QVERIFY(ret == false);
179 QVERIFY(m_barseries_with_sets->count() == count);
179 QVERIFY(m_barseries_with_sets->count() == count);
180
180
181 // Try to remove invalid pointer (should not remove, should not crash)
181 // Try to remove invalid pointer (should not remove, should not crash)
182 ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) );
182 ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) );
183 QVERIFY(ret == false);
183 QVERIFY(ret == false);
184 QVERIFY(m_barseries_with_sets->count() == count);
184 QVERIFY(m_barseries_with_sets->count() == count);
185
185
186 // remove some sets
186 // remove some sets
187 ret = m_barseries_with_sets->remove(m_testSets.at(2));
187 ret = m_barseries_with_sets->remove(m_testSets.at(2));
188 QVERIFY(ret == true);
188 QVERIFY(ret == true);
189 ret = m_barseries_with_sets->remove(m_testSets.at(3));
189 ret = m_barseries_with_sets->remove(m_testSets.at(3));
190 QVERIFY(ret == true);
190 QVERIFY(ret == true);
191 ret = m_barseries_with_sets->remove(m_testSets.at(4));
191 ret = m_barseries_with_sets->remove(m_testSets.at(4));
192 QVERIFY(ret == true);
192 QVERIFY(ret == true);
193
193
194 QVERIFY(m_barseries_with_sets->count() == 2);
194 QVERIFY(m_barseries_with_sets->count() == 2);
195
195
196 QList<QBarSet*> verifysets = m_barseries_with_sets->barSets();
196 QList<QBarSet*> verifysets = m_barseries_with_sets->barSets();
197
197
198 QVERIFY(verifysets.at(0) == m_testSets.at(0));
198 QVERIFY(verifysets.at(0) == m_testSets.at(0));
199 QVERIFY(verifysets.at(1) == m_testSets.at(1));
199 QVERIFY(verifysets.at(1) == m_testSets.at(1));
200
200
201 // Try removing all sets again (should be ok, even if some sets have already been removed)
201 // Try removing all sets again (should be ok, even if some sets have already been removed)
202 ret = false;
202 ret = false;
203 for (int i=0; i<count; i++) {
203 for (int i=0; i<count; i++) {
204 ret |= m_barseries_with_sets->remove(m_testSets.at(i));
204 ret |= m_barseries_with_sets->remove(m_testSets.at(i));
205 }
205 }
206
206
207 QVERIFY(ret == true);
207 QVERIFY(ret == true);
208 QVERIFY(m_barseries_with_sets->count() == 0);
208 QVERIFY(m_barseries_with_sets->count() == 0);
209 }
209 }
210
210
211 void tst_QHorizontalBarSeries::appendList_data()
211 void tst_QHorizontalBarSeries::appendList_data()
212 {
212 {
213
213
214 }
214 }
215
215
216 void tst_QHorizontalBarSeries::appendList()
216 void tst_QHorizontalBarSeries::appendList()
217 {
217 {
218 int count = 5;
218 int count = 5;
219 QVERIFY(m_barseries->count() == 0);
219 QVERIFY(m_barseries->count() == 0);
220
220
221 QList<QBarSet*> sets;
221 QList<QBarSet*> sets;
222 for (int i=0; i<count; i++) {
222 for (int i=0; i<count; i++) {
223 sets.append(new QBarSet("testset"));
223 sets.append(new QBarSet("testset"));
224 }
224 }
225
225
226 // Append new sets (should succeed, count should match the count of sets)
226 // Append new sets (should succeed, count should match the count of sets)
227 bool ret = false;
227 bool ret = false;
228 ret = m_barseries->append(sets);
228 ret = m_barseries->append(sets);
229 QVERIFY(ret == true);
229 QVERIFY(ret == true);
230 QVERIFY(m_barseries->count() == count);
230 QVERIFY(m_barseries->count() == count);
231
231
232 // Append same sets again (should fail, count should remain same)
232 // Append same sets again (should fail, count should remain same)
233 ret = m_barseries->append(sets);
233 ret = m_barseries->append(sets);
234 QVERIFY(ret == false);
234 QVERIFY(ret == false);
235 QVERIFY(m_barseries->count() == count);
235 QVERIFY(m_barseries->count() == count);
236
236
237 // Try append empty list (should succeed, but count should remain same)
237 // Try append empty list (should succeed, but count should remain same)
238 QList<QBarSet*> invalidList;
238 QList<QBarSet*> invalidList;
239 ret = m_barseries->append(invalidList);
239 ret = m_barseries->append(invalidList);
240 QVERIFY(ret == true);
240 QVERIFY(ret == true);
241 QVERIFY(m_barseries->count() == count);
241 QVERIFY(m_barseries->count() == count);
242
242
243 // Try append list with one new and one existing set (should fail, count remains same)
243 // Try append list with one new and one existing set (should fail, count remains same)
244 invalidList.append(new QBarSet("ok set"));
244 invalidList.append(new QBarSet("ok set"));
245 invalidList.append(sets.at(0));
245 invalidList.append(sets.at(0));
246 ret = m_barseries->append(invalidList);
246 ret = m_barseries->append(invalidList);
247 QVERIFY(ret == false);
247 QVERIFY(ret == false);
248 QVERIFY(m_barseries->count() == count);
248 QVERIFY(m_barseries->count() == count);
249
249
250 // Try append list with null pointers (should fail, count remains same)
250 // Try append list with null pointers (should fail, count remains same)
251 QList<QBarSet*> invalidList2;
251 QList<QBarSet*> invalidList2;
252 invalidList2.append(0);
252 invalidList2.append(0);
253 invalidList2.append(0);
253 invalidList2.append(0);
254 invalidList2.append(0);
254 invalidList2.append(0);
255 ret = m_barseries->append(invalidList2);
255 ret = m_barseries->append(invalidList2);
256 QVERIFY(ret == false);
256 QVERIFY(ret == false);
257 QVERIFY(m_barseries->count() == count);
257 QVERIFY(m_barseries->count() == count);
258 }
258 }
259
259
260 void tst_QHorizontalBarSeries::count_data()
260 void tst_QHorizontalBarSeries::count_data()
261 {
261 {
262
262
263 }
263 }
264
264
265 void tst_QHorizontalBarSeries::count()
265 void tst_QHorizontalBarSeries::count()
266 {
266 {
267 QVERIFY(m_barseries->count() == 0);
267 QVERIFY(m_barseries->count() == 0);
268 QVERIFY(m_barseries_with_sets->count() == m_testSets.count());
268 QVERIFY(m_barseries_with_sets->count() == m_testSets.count());
269 }
269 }
270
270
271 void tst_QHorizontalBarSeries::barSets_data()
271 void tst_QHorizontalBarSeries::barSets_data()
272 {
272 {
273
273
274 }
274 }
275
275
276 void tst_QHorizontalBarSeries::barSets()
276 void tst_QHorizontalBarSeries::barSets()
277 {
277 {
278 QVERIFY(m_barseries->barSets().count() == 0);
278 QVERIFY(m_barseries->barSets().count() == 0);
279
279
280 QList<QBarSet*> sets = m_barseries_with_sets->barSets();
280 QList<QBarSet*> sets = m_barseries_with_sets->barSets();
281 QVERIFY(sets.count() == m_testSets.count());
281 QVERIFY(sets.count() == m_testSets.count());
282
282
283 for (int i=0; i<m_testSets.count(); i++) {
283 for (int i=0; i<m_testSets.count(); i++) {
284 QVERIFY(sets.at(i) == m_testSets.at(i));
284 QVERIFY(sets.at(i) == m_testSets.at(i));
285 }
285 }
286 }
286 }
287
287
288 void tst_QHorizontalBarSeries::setLabelsVisible_data()
288 void tst_QHorizontalBarSeries::setLabelsVisible_data()
289 {
289 {
290
290
291 }
291 }
292
292
293 void tst_QHorizontalBarSeries::setLabelsVisible()
293 void tst_QHorizontalBarSeries::setLabelsVisible()
294 {
294 {
295 // labels should be invisible by default
295 // labels should be invisible by default
296 QVERIFY(m_barseries->isLabelsVisible() == false);
296 QVERIFY(m_barseries->isLabelsVisible() == false);
297 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
297 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
298
298
299 // turn labels to visible
299 // turn labels to visible
300 m_barseries_with_sets->setLabelsVisible(true);
300 m_barseries_with_sets->setLabelsVisible(true);
301 // TODO: test the signal
301 // TODO: test the signal
302 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
302 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
303
303
304 // turn labels to invisible
304 // turn labels to invisible
305 m_barseries_with_sets->setLabelsVisible(false);
305 m_barseries_with_sets->setLabelsVisible(false);
306 // TODO: test the signal
306 // TODO: test the signal
307 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
307 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
308
308
309 // without parameter, should turn labels to visible
309 // without parameter, should turn labels to visible
310 m_barseries_with_sets->setLabelsVisible();
310 m_barseries_with_sets->setLabelsVisible();
311 // TODO: test the signal
311 // TODO: test the signal
312 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
312 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
313 }
313 }
314
314
315 void tst_QHorizontalBarSeries::setLabelsFormat()
315 void tst_QHorizontalBarSeries::setLabelsFormat()
316 {
316 {
317 QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString)));
317 QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString)));
318 QCOMPARE(m_barseries->labelsFormat(), QString());
318 QCOMPARE(m_barseries->labelsFormat(), QString());
319
319
320 QString format("(@value)");
320 QString format("(@value)");
321 m_barseries->setLabelsFormat(format);
321 m_barseries->setLabelsFormat(format);
322 TRY_COMPARE(labelsFormatSpy.count(), 1);
322 TRY_COMPARE(labelsFormatSpy.count(), 1);
323 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
323 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
324 QVERIFY(arguments.at(0).toString() == format);
324 QVERIFY(arguments.at(0).toString() == format);
325 QCOMPARE(m_barseries->labelsFormat(), format);
325 QCOMPARE(m_barseries->labelsFormat(), format);
326
326
327 m_barseries->setLabelsFormat(QString());
327 m_barseries->setLabelsFormat(QString());
328 TRY_COMPARE(labelsFormatSpy.count(), 1);
328 TRY_COMPARE(labelsFormatSpy.count(), 1);
329 arguments = labelsFormatSpy.takeFirst();
329 arguments = labelsFormatSpy.takeFirst();
330 QVERIFY(arguments.at(0).toString() == QString());
330 QVERIFY(arguments.at(0).toString() == QString());
331 QCOMPARE(m_barseries->labelsFormat(), QString());
331 QCOMPARE(m_barseries->labelsFormat(), QString());
332 }
332 }
333
333
334 void tst_QHorizontalBarSeries::setLabelsPosition()
334 void tst_QHorizontalBarSeries::setLabelsPosition()
335 {
335 {
336 QSignalSpy labelsPositionSpy(m_barseries,
336 QSignalSpy labelsPositionSpy(m_barseries,
337 SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)));
337 SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)));
338 QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsCenter);
338 QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsCenter);
339
339
340 m_barseries->setLabelsPosition(QHorizontalBarSeries::LabelsInsideEnd);
340 m_barseries->setLabelsPosition(QHorizontalBarSeries::LabelsInsideEnd);
341 TRY_COMPARE(labelsPositionSpy.count(), 1);
341 TRY_COMPARE(labelsPositionSpy.count(), 1);
342 QList<QVariant> arguments = labelsPositionSpy.takeFirst();
342 QList<QVariant> arguments = labelsPositionSpy.takeFirst();
343 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
343 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
344 == QHorizontalBarSeries::LabelsInsideEnd);
344 == QHorizontalBarSeries::LabelsInsideEnd);
345 QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsInsideEnd);
345 QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsInsideEnd);
346
346
347 m_barseries->setLabelsPosition(QHorizontalBarSeries::LabelsInsideBase);
347 m_barseries->setLabelsPosition(QHorizontalBarSeries::LabelsInsideBase);
348 TRY_COMPARE(labelsPositionSpy.count(), 1);
348 TRY_COMPARE(labelsPositionSpy.count(), 1);
349 arguments = labelsPositionSpy.takeFirst();
349 arguments = labelsPositionSpy.takeFirst();
350 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
350 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
351 == QHorizontalBarSeries::LabelsInsideBase);
351 == QHorizontalBarSeries::LabelsInsideBase);
352 QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsInsideBase);
352 QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsInsideBase);
353
353
354 m_barseries->setLabelsPosition(QHorizontalBarSeries::LabelsOutsideEnd);
354 m_barseries->setLabelsPosition(QHorizontalBarSeries::LabelsOutsideEnd);
355 TRY_COMPARE(labelsPositionSpy.count(), 1);
355 TRY_COMPARE(labelsPositionSpy.count(), 1);
356 arguments = labelsPositionSpy.takeFirst();
356 arguments = labelsPositionSpy.takeFirst();
357 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
357 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
358 == QHorizontalBarSeries::LabelsOutsideEnd);
358 == QHorizontalBarSeries::LabelsOutsideEnd);
359 QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsOutsideEnd);
359 QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsOutsideEnd);
360
360
361 m_barseries->setLabelsPosition(QHorizontalBarSeries::LabelsCenter);
361 m_barseries->setLabelsPosition(QHorizontalBarSeries::LabelsCenter);
362 TRY_COMPARE(labelsPositionSpy.count(), 1);
362 TRY_COMPARE(labelsPositionSpy.count(), 1);
363 arguments = labelsPositionSpy.takeFirst();
363 arguments = labelsPositionSpy.takeFirst();
364 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
364 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
365 == QHorizontalBarSeries::LabelsCenter);
365 == QHorizontalBarSeries::LabelsCenter);
366 QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsCenter);
366 QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsCenter);
367 }
367 }
368
368
369 void tst_QHorizontalBarSeries::mouseclicked_data()
369 void tst_QHorizontalBarSeries::mouseclicked_data()
370 {
370 {
371
371
372 }
372 }
373
373
374 void tst_QHorizontalBarSeries::mouseclicked()
374 void tst_QHorizontalBarSeries::mouseclicked()
375 {
375 {
376 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
376 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
377
377
378 QHorizontalBarSeries* series = new QHorizontalBarSeries();
378 QHorizontalBarSeries* series = new QHorizontalBarSeries();
379
379
380 QBarSet* set1 = new QBarSet(QString("set 1"));
380 QBarSet* set1 = new QBarSet(QString("set 1"));
381 *set1 << 10 << 10 << 10;
381 *set1 << 10 << 10 << 10;
382 series->append(set1);
382 series->append(set1);
383
383
384 QBarSet* set2 = new QBarSet(QString("set 2"));
384 QBarSet* set2 = new QBarSet(QString("set 2"));
385 *set2 << 10 << 10 << 10;
385 *set2 << 10 << 10 << 10;
386 series->append(set2);
386 series->append(set2);
387
387
388 QList<QBarSet*> barSets = series->barSets();
388 QList<QBarSet*> barSets = series->barSets();
389
389
390 QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*)));
390 QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*)));
391 QSignalSpy setSpy1(set1, SIGNAL(clicked(int)));
391 QSignalSpy setSpy1(set1, SIGNAL(clicked(int)));
392 QSignalSpy setSpy2(set2, SIGNAL(clicked(int)));
392 QSignalSpy setSpy2(set2, SIGNAL(clicked(int)));
393
393
394 QChartView view(new QChart());
394 QChartView view(new QChart());
395 view.resize(400,300);
395 view.resize(400,300);
396 view.chart()->addSeries(series);
396 view.chart()->addSeries(series);
397 view.show();
397 view.show();
398 QTest::qWaitForWindowShown(&view);
398 QTest::qWaitForWindowShown(&view);
399
399
400 // Calculate expected layout for bars
400 // Calculate expected layout for bars
401 QRectF plotArea = view.chart()->plotArea();
401 QRectF plotArea = view.chart()->plotArea();
402 qreal width = plotArea.width();
402 qreal width = plotArea.width();
403 qreal height = plotArea.height();
403 qreal height = plotArea.height();
404 qreal rangeX = 10; // From 0 to 10 because of maximum value in set is 10
404 qreal rangeX = 10; // From 0 to 10 because of maximum value in set is 10
405 qreal rangeY = 3; // 3 values per set
405 qreal rangeY = 3; // 3 values per set
406 qreal scaleY = (height / rangeY);
406 qreal scaleY = (height / rangeY);
407 qreal scaleX = (width / rangeX);
407 qreal scaleX = (width / rangeX);
408
408
409 qreal setCount = series->count();
409 qreal setCount = series->count();
410 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
410 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
411 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
411 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
412 qreal rectHeight = (scaleY / setCount) * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
412 qreal rectHeight = (scaleY / setCount) * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
413
413
414 QVector<QRectF> layout;
414 QVector<QRectF> layout;
415
415
416 // 3 = count of values in set
416 // 3 = count of values in set
417 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
417 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
418 for (int i = 0; i < 3; i++) {
418 for (int i = 0; i < 3; i++) {
419 qreal xPos = -scaleX * domainMinX + plotArea.left();
419 qreal xPos = -scaleX * domainMinX + plotArea.left();
420 for (int set = 0; set < setCount; set++) {
420 for (int set = 0; set < setCount; set++) {
421 qreal yPos = plotArea.bottom() + (domainMinY - i) * scaleY;
421 qreal yPos = plotArea.bottom() + (domainMinY - i) * scaleY;
422 yPos += setCount*rectHeight/2;
422 yPos += setCount*rectHeight/2;
423 yPos -= set*rectHeight;
423 yPos -= set*rectHeight;
424
424
425 qreal rectWidth = barSets.at(set)->at(i) * scaleX;
425 qreal rectWidth = barSets.at(set)->at(i) * scaleX;
426 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
426 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
427 layout.append(rect);
427 layout.append(rect);
428 }
428 }
429 }
429 }
430
430
431 //====================================================================================
431 //====================================================================================
432 // barset 1, bar 0
432 // barset 1, bar 0
433 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
433 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
434 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
434 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
435
435
436 QCOMPARE(seriesSpy.count(), 1);
436 QCOMPARE(seriesSpy.count(), 1);
437 QCOMPARE(setSpy1.count(), 1);
437 QCOMPARE(setSpy1.count(), 1);
438 QCOMPARE(setSpy2.count(), 0);
438 QCOMPARE(setSpy2.count(), 0);
439
439
440 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
440 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
441 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
441 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
442 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
442 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
443 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
443 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
444
444
445 QList<QVariant> setSpyArg = setSpy1.takeFirst();
445 QList<QVariant> setSpyArg = setSpy1.takeFirst();
446 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
446 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
447 QVERIFY(setSpyArg.at(0).toInt() == 0);
447 QVERIFY(setSpyArg.at(0).toInt() == 0);
448
448
449 //====================================================================================
449 //====================================================================================
450 // barset 1, bar 1
450 // barset 1, bar 1
451 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
451 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
452 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
452 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
453
453
454 QCOMPARE(seriesSpy.count(), 1);
454 QCOMPARE(seriesSpy.count(), 1);
455 QCOMPARE(setSpy1.count(), 1);
455 QCOMPARE(setSpy1.count(), 1);
456 QCOMPARE(setSpy2.count(), 0);
456 QCOMPARE(setSpy2.count(), 0);
457
457
458 seriesSpyArg = seriesSpy.takeFirst();
458 seriesSpyArg = seriesSpy.takeFirst();
459 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
459 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
460 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
460 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
461 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
461 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
462
462
463 setSpyArg = setSpy1.takeFirst();
463 setSpyArg = setSpy1.takeFirst();
464 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
464 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
465 QVERIFY(setSpyArg.at(0).toInt() == 1);
465 QVERIFY(setSpyArg.at(0).toInt() == 1);
466
466
467 //====================================================================================
467 //====================================================================================
468 // barset 1, bar 2
468 // barset 1, bar 2
469 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
469 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
470 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
470 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
471
471
472 QCOMPARE(seriesSpy.count(), 1);
472 QCOMPARE(seriesSpy.count(), 1);
473 QCOMPARE(setSpy1.count(), 1);
473 QCOMPARE(setSpy1.count(), 1);
474 QCOMPARE(setSpy2.count(), 0);
474 QCOMPARE(setSpy2.count(), 0);
475
475
476 seriesSpyArg = seriesSpy.takeFirst();
476 seriesSpyArg = seriesSpy.takeFirst();
477 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
477 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
478 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
478 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
479 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
479 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
480
480
481 setSpyArg = setSpy1.takeFirst();
481 setSpyArg = setSpy1.takeFirst();
482 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
482 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
483 QVERIFY(setSpyArg.at(0).toInt() == 2);
483 QVERIFY(setSpyArg.at(0).toInt() == 2);
484
484
485 //====================================================================================
485 //====================================================================================
486 // barset 2, bar 0
486 // barset 2, bar 0
487 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
487 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
488 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
488 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
489
489
490 QCOMPARE(seriesSpy.count(), 1);
490 QCOMPARE(seriesSpy.count(), 1);
491 QCOMPARE(setSpy1.count(), 0);
491 QCOMPARE(setSpy1.count(), 0);
492 QCOMPARE(setSpy2.count(), 1);
492 QCOMPARE(setSpy2.count(), 1);
493
493
494 seriesSpyArg = seriesSpy.takeFirst();
494 seriesSpyArg = seriesSpy.takeFirst();
495 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
495 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
496 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
496 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
497 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
497 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
498
498
499 setSpyArg = setSpy2.takeFirst();
499 setSpyArg = setSpy2.takeFirst();
500 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
500 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
501 QVERIFY(setSpyArg.at(0).toInt() == 0);
501 QVERIFY(setSpyArg.at(0).toInt() == 0);
502
502
503 //====================================================================================
503 //====================================================================================
504 // barset 2, bar 1
504 // barset 2, bar 1
505 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
505 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
506 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
506 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
507
507
508 QCOMPARE(seriesSpy.count(), 1);
508 QCOMPARE(seriesSpy.count(), 1);
509 QCOMPARE(setSpy1.count(), 0);
509 QCOMPARE(setSpy1.count(), 0);
510 QCOMPARE(setSpy2.count(), 1);
510 QCOMPARE(setSpy2.count(), 1);
511
511
512 seriesSpyArg = seriesSpy.takeFirst();
512 seriesSpyArg = seriesSpy.takeFirst();
513 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
513 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
514 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
514 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
515 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
515 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
516
516
517 setSpyArg = setSpy2.takeFirst();
517 setSpyArg = setSpy2.takeFirst();
518 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
518 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
519 QVERIFY(setSpyArg.at(0).toInt() == 1);
519 QVERIFY(setSpyArg.at(0).toInt() == 1);
520
520
521 //====================================================================================
521 //====================================================================================
522 // barset 2, bar 2
522 // barset 2, bar 2
523 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
523 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
524 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
524 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
525
525
526 QCOMPARE(seriesSpy.count(), 1);
526 QCOMPARE(seriesSpy.count(), 1);
527 QCOMPARE(setSpy1.count(), 0);
527 QCOMPARE(setSpy1.count(), 0);
528 QCOMPARE(setSpy2.count(), 1);
528 QCOMPARE(setSpy2.count(), 1);
529
529
530 seriesSpyArg = seriesSpy.takeFirst();
530 seriesSpyArg = seriesSpy.takeFirst();
531 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
531 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
532 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
532 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
533 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
533 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
534
534
535 setSpyArg = setSpy2.takeFirst();
535 setSpyArg = setSpy2.takeFirst();
536 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
536 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
537 QVERIFY(setSpyArg.at(0).toInt() == 2);
537 QVERIFY(setSpyArg.at(0).toInt() == 2);
538 }
538 }
539
539
540 void tst_QHorizontalBarSeries::mousehovered_data()
540 void tst_QHorizontalBarSeries::mousehovered_data()
541 {
541 {
542
542
543 }
543 }
544
544
545 void tst_QHorizontalBarSeries::mousehovered()
545 void tst_QHorizontalBarSeries::mousehovered()
546 {
546 {
547 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
547 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
548
548
549 QHorizontalBarSeries* series = new QHorizontalBarSeries();
549 QHorizontalBarSeries* series = new QHorizontalBarSeries();
550
550
551 QBarSet* set1 = new QBarSet(QString("set 1"));
551 QBarSet* set1 = new QBarSet(QString("set 1"));
552 *set1 << 10 << 10 << 10;
552 *set1 << 10 << 10 << 10;
553 series->append(set1);
553 series->append(set1);
554
554
555 QBarSet* set2 = new QBarSet(QString("set 2"));
555 QBarSet* set2 = new QBarSet(QString("set 2"));
556 *set2 << 10 << 10 << 10;
556 *set2 << 10 << 10 << 10;
557 series->append(set2);
557 series->append(set2);
558
558
559 QList<QBarSet*> barSets = series->barSets();
559 QList<QBarSet*> barSets = series->barSets();
560
560
561 QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*)));
562 QSignalSpy seriesIndexSpy(series, SIGNAL(hovered(bool, int, QBarSet*)));
561 QSignalSpy seriesIndexSpy(series, SIGNAL(hovered(bool, int, QBarSet*)));
563 QSignalSpy setSpy1(set1, SIGNAL(hovered(bool)));
564 QSignalSpy setSpy2(set2, SIGNAL(hovered(bool)));
565 QSignalSpy setIndexSpy1(set1, SIGNAL(hovered(bool, int)));
562 QSignalSpy setIndexSpy1(set1, SIGNAL(hovered(bool, int)));
566 QSignalSpy setIndexSpy2(set2, SIGNAL(hovered(bool, int)));
563 QSignalSpy setIndexSpy2(set2, SIGNAL(hovered(bool, int)));
567
564
568 QChartView view(new QChart());
565 QChartView view(new QChart());
569 view.resize(400,300);
566 view.resize(400,300);
570 view.chart()->addSeries(series);
567 view.chart()->addSeries(series);
571 view.show();
568 view.show();
572 QTest::qWaitForWindowShown(&view);
569 QTest::qWaitForWindowShown(&view);
573
570
574 //this is hack since view does not get events otherwise
571 //this is hack since view does not get events otherwise
575 view.setMouseTracking(true);
572 view.setMouseTracking(true);
576
573
577 // Calculate expected layout for bars
574 // Calculate expected layout for bars
578 QRectF plotArea = view.chart()->plotArea();
575 QRectF plotArea = view.chart()->plotArea();
579 qreal width = plotArea.width();
576 qreal width = plotArea.width();
580 qreal height = plotArea.height();
577 qreal height = plotArea.height();
581 qreal rangeX = 10; // From 0 to 10 because of maximum value in set is 10
578 qreal rangeX = 10; // From 0 to 10 because of maximum value in set is 10
582 qreal rangeY = 3; // 3 values per set
579 qreal rangeY = 3; // 3 values per set
583 qreal scaleY = (height / rangeY);
580 qreal scaleY = (height / rangeY);
584 qreal scaleX = (width / rangeX);
581 qreal scaleX = (width / rangeX);
585
582
586 qreal setCount = series->count();
583 qreal setCount = series->count();
587 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
584 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
588 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
585 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
589 qreal rectHeight = (scaleY / setCount) * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
586 qreal rectHeight = (scaleY / setCount) * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
590
587
591 QVector<QRectF> layout;
588 QVector<QRectF> layout;
592
589
593 // 3 = count of values in set
590 // 3 = count of values in set
594 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
591 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
595 for (int i = 0; i < 3; i++) {
592 for (int i = 0; i < 3; i++) {
596 qreal xPos = -scaleX * domainMinX + plotArea.left();
593 qreal xPos = -scaleX * domainMinX + plotArea.left();
597 for (int set = 0; set < setCount; set++) {
594 for (int set = 0; set < setCount; set++) {
598 qreal yPos = plotArea.bottom() + (domainMinY - i) * scaleY;
595 qreal yPos = plotArea.bottom() + (domainMinY - i) * scaleY;
599 yPos += setCount*rectHeight/2;
596 yPos += setCount*rectHeight/2;
600 yPos -= set*rectHeight;
597 yPos -= set*rectHeight;
601
598
602 qreal rectWidth = barSets.at(set)->at(i) * scaleX;
599 qreal rectWidth = barSets.at(set)->at(i) * scaleX;
603 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
600 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
604 layout.append(rect);
601 layout.append(rect);
605 }
602 }
606 }
603 }
607
604
608 //=======================================================================
605 //=======================================================================
609 // move mouse to bottom border
606 // move mouse to bottom border
610 QTest::mouseMove(view.viewport(), QPoint(layout.at(0).center().x(), 300));
607 QTest::mouseMove(view.viewport(), QPoint(layout.at(0).center().x(), 300));
611 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
608 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
612 TRY_COMPARE(seriesSpy.count(), 0);
613 TRY_COMPARE(seriesIndexSpy.count(), 0);
609 TRY_COMPARE(seriesIndexSpy.count(), 0);
614 TRY_COMPARE(setSpy1.count(), 0);
615 TRY_COMPARE(setSpy2.count(), 0);
616 TRY_COMPARE(setIndexSpy1.count(), 0);
610 TRY_COMPARE(setIndexSpy1.count(), 0);
617 TRY_COMPARE(setIndexSpy2.count(), 0);
611 TRY_COMPARE(setIndexSpy2.count(), 0);
618
612
619 //=======================================================================
613 //=======================================================================
620 // move mouse on top of set1
614 // move mouse on top of set1
621 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
615 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
622 TRY_COMPARE(seriesSpy.count(), 1);
623 TRY_COMPARE(seriesIndexSpy.count(), 1);
616 TRY_COMPARE(seriesIndexSpy.count(), 1);
624 TRY_COMPARE(setSpy1.count(), 1);
625 TRY_COMPARE(setSpy2.count(), 0);
626 TRY_COMPARE(setIndexSpy1.count(), 1);
617 TRY_COMPARE(setIndexSpy1.count(), 1);
627 TRY_COMPARE(setIndexSpy2.count(), 0);
618 TRY_COMPARE(setIndexSpy2.count(), 0);
628
619
629 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
630 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
631 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
632 QVERIFY(seriesSpyArg.at(0).toBool() == true);
633
634 QList<QVariant> seriesIndexSpyArg = seriesIndexSpy.takeFirst();
620 QList<QVariant> seriesIndexSpyArg = seriesIndexSpy.takeFirst();
635 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
621 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
636 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
622 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
637 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
623 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
638
624
639 QList<QVariant> setSpyArg = setSpy1.takeFirst();
640 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
641 QVERIFY(setSpyArg.at(0).toBool() == true);
642
643 QList<QVariant> setIndexSpyArg = setIndexSpy1.takeFirst();
625 QList<QVariant> setIndexSpyArg = setIndexSpy1.takeFirst();
644 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
626 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
645 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
627 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
646
628
647 //=======================================================================
629 //=======================================================================
648 // move mouse from top of set1 to top of set2
630 // move mouse from top of set1 to top of set2
649 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
631 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
650 TRY_COMPARE(seriesSpy.count(), 2);
651 TRY_COMPARE(seriesIndexSpy.count(), 2);
632 TRY_COMPARE(seriesIndexSpy.count(), 2);
652 TRY_COMPARE(setSpy1.count(), 1);
653 TRY_COMPARE(setSpy2.count(), 1);
654 TRY_COMPARE(setIndexSpy1.count(), 1);
633 TRY_COMPARE(setIndexSpy1.count(), 1);
655 TRY_COMPARE(setIndexSpy2.count(), 1);
634 TRY_COMPARE(setIndexSpy2.count(), 1);
656
635
657 // should leave set1
636 // should leave set1
658 seriesSpyArg = seriesSpy.takeFirst();
659 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
660 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
661 QVERIFY(seriesSpyArg.at(0).toBool() == false);
662
663 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
637 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
664 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
638 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
665 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
639 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
666 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
640 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
667
641
668 setSpyArg = setSpy1.takeFirst();
669 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
670 QVERIFY(setSpyArg.at(0).toBool() == false);
671
672 setIndexSpyArg = setIndexSpy1.takeFirst();
642 setIndexSpyArg = setIndexSpy1.takeFirst();
673 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
643 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
674 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
644 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
675
645
676 // should enter set2
646 // should enter set2
677 seriesSpyArg = seriesSpy.takeFirst();
678 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
679 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
680 QVERIFY(seriesSpyArg.at(0).toBool() == true);
681
682 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
647 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
683 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
648 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
684 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
649 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
685 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
650 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
686
651
687 setSpyArg = setSpy2.takeFirst();
688 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
689 QVERIFY(setSpyArg.at(0).toBool() == true);
690
691 setIndexSpyArg = setIndexSpy2.takeFirst();
652 setIndexSpyArg = setIndexSpy2.takeFirst();
692 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
653 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
693 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
654 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
694
655
695 //=======================================================================
656 //=======================================================================
696 // move mouse from top of set2 to background
657 // move mouse from top of set2 to background
697 QTest::mouseMove(view.viewport(), QPoint(0, layout.at(0).center().y()));
658 QTest::mouseMove(view.viewport(), QPoint(0, layout.at(0).center().y()));
698 TRY_COMPARE(seriesSpy.count(), 1);
699 TRY_COMPARE(seriesIndexSpy.count(), 1);
659 TRY_COMPARE(seriesIndexSpy.count(), 1);
700 TRY_COMPARE(setSpy1.count(), 0);
701 TRY_COMPARE(setSpy2.count(), 1);
702 TRY_COMPARE(setIndexSpy1.count(), 0);
660 TRY_COMPARE(setIndexSpy1.count(), 0);
703 TRY_COMPARE(setIndexSpy2.count(), 1);
661 TRY_COMPARE(setIndexSpy2.count(), 1);
704
662
705 // should leave set2
663 // should leave set2
706 seriesSpyArg = seriesSpy.takeFirst();
707 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
708 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
709 QVERIFY(seriesSpyArg.at(0).toBool() == false);
710
711 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
664 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
712 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
665 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
713 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
666 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
714 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
667 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
715
668
716 setSpyArg = setSpy2.takeFirst();
717 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
718 QVERIFY(setSpyArg.at(0).toBool() == false);
719
720 setIndexSpyArg = setIndexSpy2.takeFirst();
669 setIndexSpyArg = setIndexSpy2.takeFirst();
721 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
670 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
722 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
671 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
723
672
724 //=======================================================================
673 //=======================================================================
725 // move mouse on top of set1, bar0 to check the index (hover into set1)
674 // move mouse on top of set1, bar0 to check the index (hover into set1)
726 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
675 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
727
676
728 TRY_COMPARE(seriesSpy.count(), 1);
729 TRY_COMPARE(seriesIndexSpy.count(), 1);
677 TRY_COMPARE(seriesIndexSpy.count(), 1);
730 TRY_COMPARE(setSpy1.count(), 1);
731 TRY_COMPARE(setSpy2.count(), 0);
732 TRY_COMPARE(setIndexSpy1.count(), 1);
678 TRY_COMPARE(setIndexSpy1.count(), 1);
733 TRY_COMPARE(setIndexSpy2.count(), 0);
679 TRY_COMPARE(setIndexSpy2.count(), 0);
734
680
735 //should enter set1, bar0
681 //should enter set1, bar0
736 seriesSpyArg = seriesSpy.takeFirst();
737 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
738 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
739 QVERIFY(seriesSpyArg.at(0).toBool() == true);
740
741 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
682 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
742 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
683 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
743 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
684 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
744 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
685 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
745 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
686 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
746 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
687 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
747
688
748 setSpyArg = setSpy1.takeFirst();
749 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
750 QVERIFY(setSpyArg.at(0).toBool() == true);
751
752 setIndexSpyArg = setIndexSpy1.takeFirst();
689 setIndexSpyArg = setIndexSpy1.takeFirst();
753 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
690 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
754 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
691 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
755 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
692 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
756 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
693 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
757
694
758 //=======================================================================
695 //=======================================================================
759 // move mouse on top of set2, bar0 to check the index (hover out set1,
696 // move mouse on top of set2, bar0 to check the index (hover out set1,
760 // hover in set1)
697 // hover in set1)
761 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
698 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
762
699
763 TRY_COMPARE(seriesSpy.count(), 2);
764 TRY_COMPARE(seriesIndexSpy.count(), 2);
700 TRY_COMPARE(seriesIndexSpy.count(), 2);
765 TRY_COMPARE(setSpy1.count(), 1);
766 TRY_COMPARE(setSpy2.count(), 1);
767 TRY_COMPARE(setIndexSpy1.count(), 1);
701 TRY_COMPARE(setIndexSpy1.count(), 1);
768 TRY_COMPARE(setIndexSpy2.count(), 1);
702 TRY_COMPARE(setIndexSpy2.count(), 1);
769
703
770 // should leave set1, bar0
704 // should leave set1, bar0
771 seriesSpyArg = seriesSpy.takeFirst();
772 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
773 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
774 QVERIFY(seriesSpyArg.at(0).toBool() == false);
775
776 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
705 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
777 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
706 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
778 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
707 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
779 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
708 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
780 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
709 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
781 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
710 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
782
711
783 setSpyArg = setSpy1.takeFirst();
784 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
785 QVERIFY(setSpyArg.at(0).toBool() == false);
786
787 setIndexSpyArg = setIndexSpy1.takeFirst();
712 setIndexSpyArg = setIndexSpy1.takeFirst();
788 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
713 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
789 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
714 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
790 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
715 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
791 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
716 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
792
717
793 // should enter set2, bar0
718 // should enter set2, bar0
794 seriesSpyArg = seriesSpy.takeFirst();
795 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
796 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
797 QVERIFY(seriesSpyArg.at(0).toBool() == true);
798
799 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
719 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
800 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
720 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
801 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
721 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
802 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
722 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
803 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
723 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
804 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
724 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
805
725
806 setSpyArg = setSpy2.takeFirst();
807 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
808 QVERIFY(setSpyArg.at(0).toBool() == true);
809
810 setIndexSpyArg = setIndexSpy2.takeFirst();
726 setIndexSpyArg = setIndexSpy2.takeFirst();
811 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
727 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
812 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
728 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
813 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
729 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
814 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
730 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
815
731
816 //=======================================================================
732 //=======================================================================
817 // move mouse on top of set1, bar1 to check the index (hover out set 2,
733 // move mouse on top of set1, bar1 to check the index (hover out set 2,
818 // hover in set1)
734 // hover in set1)
819 QTest::mouseMove(view.viewport(), layout.at(2).center().toPoint());
735 QTest::mouseMove(view.viewport(), layout.at(2).center().toPoint());
820
736
821 TRY_COMPARE(seriesSpy.count(), 2);
822 TRY_COMPARE(seriesIndexSpy.count(), 2);
737 TRY_COMPARE(seriesIndexSpy.count(), 2);
823 TRY_COMPARE(setSpy1.count(), 1);
824 TRY_COMPARE(setSpy2.count(), 1);
825 TRY_COMPARE(setIndexSpy1.count(), 1);
738 TRY_COMPARE(setIndexSpy1.count(), 1);
826 TRY_COMPARE(setIndexSpy2.count(), 1);
739 TRY_COMPARE(setIndexSpy2.count(), 1);
827
740
828 // should leave set2, bar0
741 // should leave set2, bar0
829 seriesSpyArg = seriesSpy.takeFirst();
830 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
831 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
832 QVERIFY(seriesSpyArg.at(0).toBool() == false);
833
834 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
742 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
835 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
743 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
836 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
744 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
837 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
745 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
838 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
746 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
839 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
747 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
840
748
841 setSpyArg = setSpy2.takeFirst();
842 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
843 QVERIFY(setSpyArg.at(0).toBool() == false);
844
845 setIndexSpyArg = setIndexSpy2.takeFirst();
749 setIndexSpyArg = setIndexSpy2.takeFirst();
846 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
750 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
847 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
751 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
848 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
752 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
849 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
753 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
850
754
851 // should enter set1, bar1
755 // should enter set1, bar1
852 seriesSpyArg = seriesSpy.takeFirst();
853 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
854 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
855 QVERIFY(seriesSpyArg.at(0).toBool() == true);
856
857 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
756 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
858 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
757 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
859 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
758 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
860 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
759 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
861 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
760 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
862 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
761 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
863
762
864 setSpyArg = setSpy1.takeFirst();
865 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
866 QVERIFY(setSpyArg.at(0).toBool() == true);
867
868 setIndexSpyArg = setIndexSpy1.takeFirst();
763 setIndexSpyArg = setIndexSpy1.takeFirst();
869 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
764 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
870 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
765 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
871 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
766 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
872 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
767 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
873
768
874 //=======================================================================
769 //=======================================================================
875 // move mouse on top of view between set1 and set2 to check the index
770 // move mouse on top of view between set1 and set2 to check the index
876 // (hover out set1)
771 // (hover out set1)
877 QTest::mouseMove(view.viewport(), QPoint(0, (layout.at(2).top() + layout.at(3).bottom()) / 2));
772 QTest::mouseMove(view.viewport(), QPoint(0, (layout.at(2).top() + layout.at(3).bottom()) / 2));
878
773
879 TRY_COMPARE(seriesSpy.count(), 1);
880 TRY_COMPARE(seriesIndexSpy.count(), 1);
774 TRY_COMPARE(seriesIndexSpy.count(), 1);
881 TRY_COMPARE(setSpy1.count(), 1);
882 TRY_COMPARE(setSpy2.count(), 0);
883 TRY_COMPARE(setIndexSpy1.count(), 1);
775 TRY_COMPARE(setIndexSpy1.count(), 1);
884 TRY_COMPARE(setIndexSpy2.count(), 0);
776 TRY_COMPARE(setIndexSpy2.count(), 0);
885
777
886 // should leave set1, bar1
778 // should leave set1, bar1
887 seriesSpyArg = seriesSpy.takeFirst();
888 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
889 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
890 QVERIFY(seriesSpyArg.at(0).toBool() == false);
891
892 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
779 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
893 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
780 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
894 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
781 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
895 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
782 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
896 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
783 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
897 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
784 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
898
785
899 setSpyArg = setSpy1.takeFirst();
900 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
901 QVERIFY(setSpyArg.at(0).toBool() == false);
902
903 setIndexSpyArg = setIndexSpy1.takeFirst();
786 setIndexSpyArg = setIndexSpy1.takeFirst();
904 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
787 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
905 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
788 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
906 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
789 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
907 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
790 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
908
791
909 //=======================================================================
792 //=======================================================================
910 // move mouse on top of set2, bar1 to check the index (hover in set2)
793 // move mouse on top of set2, bar1 to check the index (hover in set2)
911 QTest::mouseMove(view.viewport(), layout.at(3).center().toPoint());
794 QTest::mouseMove(view.viewport(), layout.at(3).center().toPoint());
912
795
913 TRY_COMPARE(seriesSpy.count(), 1);
914 TRY_COMPARE(seriesIndexSpy.count(), 1);
796 TRY_COMPARE(seriesIndexSpy.count(), 1);
915 TRY_COMPARE(setSpy1.count(), 0);
916 TRY_COMPARE(setSpy2.count(), 1);
917 TRY_COMPARE(setIndexSpy1.count(), 0);
797 TRY_COMPARE(setIndexSpy1.count(), 0);
918 TRY_COMPARE(setIndexSpy2.count(), 1);
798 TRY_COMPARE(setIndexSpy2.count(), 1);
919
799
920 // should enter set2, bar1
800 // should enter set2, bar1
921 seriesSpyArg = seriesSpy.takeFirst();
922 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
923 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
924 QVERIFY(seriesSpyArg.at(0).toBool() == true);
925
926 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
801 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
927 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
802 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
928 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
803 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
929 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
804 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
930 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
805 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
931 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
806 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
932
807
933 setSpyArg = setSpy2.takeFirst();
934 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
935 QVERIFY(setSpyArg.at(0).toBool() == true);
936
937 setIndexSpyArg = setIndexSpy2.takeFirst();
808 setIndexSpyArg = setIndexSpy2.takeFirst();
938 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
809 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
939 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
810 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
940 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
811 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
941 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
812 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
942
813
943 //=======================================================================
814 //=======================================================================
944 // move mouse on top of the view between bar1 and bar2 to check the index
815 // move mouse on top of the view between bar1 and bar2 to check the index
945 //(hover out set2)
816 //(hover out set2)
946 QTest::mouseMove(view.viewport(), QPoint(0, (layout.at(3).top() + layout.at(3).bottom()) / 2));
817 QTest::mouseMove(view.viewport(), QPoint(0, (layout.at(3).top() + layout.at(3).bottom()) / 2));
947
818
948 TRY_COMPARE(seriesSpy.count(), 1);
949 TRY_COMPARE(seriesIndexSpy.count(), 1);
819 TRY_COMPARE(seriesIndexSpy.count(), 1);
950 TRY_COMPARE(setSpy1.count(), 0);
951 TRY_COMPARE(setSpy2.count(), 1);
952 TRY_COMPARE(setIndexSpy1.count(), 0);
820 TRY_COMPARE(setIndexSpy1.count(), 0);
953 TRY_COMPARE(setIndexSpy2.count(), 1);
821 TRY_COMPARE(setIndexSpy2.count(), 1);
954
822
955 // should leave set2, bar1
823 // should leave set2, bar1
956 seriesSpyArg = seriesSpy.takeFirst();
957 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
958 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
959 QVERIFY(seriesSpyArg.at(0).toBool() == false);
960
961 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
824 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
962 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
825 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
963 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
826 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
964 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
827 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
965 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
828 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
966 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
829 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
967
830
968 setSpyArg = setSpy2.takeFirst();
969 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
970 QVERIFY(setSpyArg.at(0).toBool() == false);
971
972 setIndexSpyArg = setIndexSpy2.takeFirst();
831 setIndexSpyArg = setIndexSpy2.takeFirst();
973 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
832 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
974 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
833 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
975 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
834 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
976 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
835 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
977 }
836 }
978
837
979 void tst_QHorizontalBarSeries::clearWithAnimations()
838 void tst_QHorizontalBarSeries::clearWithAnimations()
980 {
839 {
981 QHorizontalBarSeries* series = new QHorizontalBarSeries();
840 QHorizontalBarSeries* series = new QHorizontalBarSeries();
982
841
983 QBarSet* set1 = new QBarSet(QString("set 1"));
842 QBarSet* set1 = new QBarSet(QString("set 1"));
984 *set1 << 10 << 10 << 10;
843 *set1 << 10 << 10 << 10;
985 series->append(set1);
844 series->append(set1);
986
845
987 QBarSet* set2 = new QBarSet(QString("set 2"));
846 QBarSet* set2 = new QBarSet(QString("set 2"));
988 *set2 << 10 << 10 << 10;
847 *set2 << 10 << 10 << 10;
989 series->append(set2);
848 series->append(set2);
990
849
991 QChartView view(new QChart());
850 QChartView view(new QChart());
992 view.resize(400,300);
851 view.resize(400,300);
993 view.chart()->setAnimationOptions(QChart::SeriesAnimations);
852 view.chart()->setAnimationOptions(QChart::SeriesAnimations);
994 view.chart()->addSeries(series);
853 view.chart()->addSeries(series);
995 view.show();
854 view.show();
996
855
997 series->clear();
856 series->clear();
998 }
857 }
999
858
1000 QTEST_MAIN(tst_QHorizontalBarSeries)
859 QTEST_MAIN(tst_QHorizontalBarSeries)
1001
860
1002 #include "tst_qhorizontalbarseries.moc"
861 #include "tst_qhorizontalbarseries.moc"
1003
862
@@ -1,679 +1,608
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 <QtCharts/QHorizontalPercentBarSeries>
22 #include <QtCharts/QHorizontalPercentBarSeries>
23 #include <QtCharts/QBarSet>
23 #include <QtCharts/QBarSet>
24 #include <QtCharts/QChartView>
24 #include <QtCharts/QChartView>
25 #include <QtCharts/QChart>
25 #include <QtCharts/QChart>
26 #include "tst_definitions.h"
26 #include "tst_definitions.h"
27
27
28 QT_CHARTS_USE_NAMESPACE
28 QT_CHARTS_USE_NAMESPACE
29
29
30 Q_DECLARE_METATYPE(QBarSet*)
30 Q_DECLARE_METATYPE(QBarSet*)
31 Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition)
31 Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition)
32
32
33 class tst_QHorizontalPercentBarSeries : public QObject
33 class tst_QHorizontalPercentBarSeries : public QObject
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36
36
37 public slots:
37 public slots:
38 void initTestCase();
38 void initTestCase();
39 void cleanupTestCase();
39 void cleanupTestCase();
40 void init();
40 void init();
41 void cleanup();
41 void cleanup();
42
42
43 private slots:
43 private slots:
44 void qhorizontalpercentbarseries_data();
44 void qhorizontalpercentbarseries_data();
45 void qhorizontalpercentbarseries();
45 void qhorizontalpercentbarseries();
46 void type_data();
46 void type_data();
47 void type();
47 void type();
48 void setLabelsFormat();
48 void setLabelsFormat();
49 void setLabelsPosition();
49 void setLabelsPosition();
50 void mouseclicked_data();
50 void mouseclicked_data();
51 void mouseclicked();
51 void mouseclicked();
52 void mousehovered_data();
52 void mousehovered_data();
53 void mousehovered();
53 void mousehovered();
54 void zeroValuesInSeries();
54 void zeroValuesInSeries();
55
55
56 private:
56 private:
57 QHorizontalPercentBarSeries* m_barseries;
57 QHorizontalPercentBarSeries* m_barseries;
58 };
58 };
59
59
60 void tst_QHorizontalPercentBarSeries::initTestCase()
60 void tst_QHorizontalPercentBarSeries::initTestCase()
61 {
61 {
62 qRegisterMetaType<QBarSet*>("QBarSet*");
62 qRegisterMetaType<QBarSet*>("QBarSet*");
63 qRegisterMetaType<QAbstractBarSeries::LabelsPosition>("QAbstractBarSeries::LabelsPosition");
63 qRegisterMetaType<QAbstractBarSeries::LabelsPosition>("QAbstractBarSeries::LabelsPosition");
64 }
64 }
65
65
66 void tst_QHorizontalPercentBarSeries::cleanupTestCase()
66 void tst_QHorizontalPercentBarSeries::cleanupTestCase()
67 {
67 {
68 }
68 }
69
69
70 void tst_QHorizontalPercentBarSeries::init()
70 void tst_QHorizontalPercentBarSeries::init()
71 {
71 {
72 m_barseries = new QHorizontalPercentBarSeries();
72 m_barseries = new QHorizontalPercentBarSeries();
73 }
73 }
74
74
75 void tst_QHorizontalPercentBarSeries::cleanup()
75 void tst_QHorizontalPercentBarSeries::cleanup()
76 {
76 {
77 delete m_barseries;
77 delete m_barseries;
78 m_barseries = 0;
78 m_barseries = 0;
79 }
79 }
80
80
81 void tst_QHorizontalPercentBarSeries::qhorizontalpercentbarseries_data()
81 void tst_QHorizontalPercentBarSeries::qhorizontalpercentbarseries_data()
82 {
82 {
83 }
83 }
84
84
85 void tst_QHorizontalPercentBarSeries::qhorizontalpercentbarseries()
85 void tst_QHorizontalPercentBarSeries::qhorizontalpercentbarseries()
86 {
86 {
87 QHorizontalPercentBarSeries *barseries = new QHorizontalPercentBarSeries();
87 QHorizontalPercentBarSeries *barseries = new QHorizontalPercentBarSeries();
88 QVERIFY(barseries != 0);
88 QVERIFY(barseries != 0);
89 }
89 }
90
90
91 void tst_QHorizontalPercentBarSeries::type_data()
91 void tst_QHorizontalPercentBarSeries::type_data()
92 {
92 {
93
93
94 }
94 }
95
95
96 void tst_QHorizontalPercentBarSeries::type()
96 void tst_QHorizontalPercentBarSeries::type()
97 {
97 {
98 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeHorizontalPercentBar);
98 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeHorizontalPercentBar);
99 }
99 }
100
100
101 void tst_QHorizontalPercentBarSeries::setLabelsFormat()
101 void tst_QHorizontalPercentBarSeries::setLabelsFormat()
102 {
102 {
103 QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString)));
103 QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString)));
104 QCOMPARE(m_barseries->labelsFormat(), QString());
104 QCOMPARE(m_barseries->labelsFormat(), QString());
105
105
106 QString format("(@value)");
106 QString format("(@value)");
107 m_barseries->setLabelsFormat(format);
107 m_barseries->setLabelsFormat(format);
108 TRY_COMPARE(labelsFormatSpy.count(), 1);
108 TRY_COMPARE(labelsFormatSpy.count(), 1);
109 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
109 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
110 QVERIFY(arguments.at(0).toString() == format);
110 QVERIFY(arguments.at(0).toString() == format);
111 QCOMPARE(m_barseries->labelsFormat(), format);
111 QCOMPARE(m_barseries->labelsFormat(), format);
112
112
113 m_barseries->setLabelsFormat(QString());
113 m_barseries->setLabelsFormat(QString());
114 TRY_COMPARE(labelsFormatSpy.count(), 1);
114 TRY_COMPARE(labelsFormatSpy.count(), 1);
115 arguments = labelsFormatSpy.takeFirst();
115 arguments = labelsFormatSpy.takeFirst();
116 QVERIFY(arguments.at(0).toString() == QString());
116 QVERIFY(arguments.at(0).toString() == QString());
117 QCOMPARE(m_barseries->labelsFormat(), QString());
117 QCOMPARE(m_barseries->labelsFormat(), QString());
118 }
118 }
119
119
120 void tst_QHorizontalPercentBarSeries::setLabelsPosition()
120 void tst_QHorizontalPercentBarSeries::setLabelsPosition()
121 {
121 {
122 QSignalSpy labelsPositionSpy(m_barseries,
122 QSignalSpy labelsPositionSpy(m_barseries,
123 SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)));
123 SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)));
124 QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsCenter);
124 QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsCenter);
125
125
126 m_barseries->setLabelsPosition(QHorizontalPercentBarSeries::LabelsInsideEnd);
126 m_barseries->setLabelsPosition(QHorizontalPercentBarSeries::LabelsInsideEnd);
127 TRY_COMPARE(labelsPositionSpy.count(), 1);
127 TRY_COMPARE(labelsPositionSpy.count(), 1);
128 QList<QVariant> arguments = labelsPositionSpy.takeFirst();
128 QList<QVariant> arguments = labelsPositionSpy.takeFirst();
129 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
129 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
130 == QHorizontalPercentBarSeries::LabelsInsideEnd);
130 == QHorizontalPercentBarSeries::LabelsInsideEnd);
131 QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsInsideEnd);
131 QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsInsideEnd);
132
132
133 m_barseries->setLabelsPosition(QHorizontalPercentBarSeries::LabelsInsideBase);
133 m_barseries->setLabelsPosition(QHorizontalPercentBarSeries::LabelsInsideBase);
134 TRY_COMPARE(labelsPositionSpy.count(), 1);
134 TRY_COMPARE(labelsPositionSpy.count(), 1);
135 arguments = labelsPositionSpy.takeFirst();
135 arguments = labelsPositionSpy.takeFirst();
136 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
136 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
137 == QHorizontalPercentBarSeries::LabelsInsideBase);
137 == QHorizontalPercentBarSeries::LabelsInsideBase);
138 QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsInsideBase);
138 QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsInsideBase);
139
139
140 m_barseries->setLabelsPosition(QHorizontalPercentBarSeries::LabelsOutsideEnd);
140 m_barseries->setLabelsPosition(QHorizontalPercentBarSeries::LabelsOutsideEnd);
141 TRY_COMPARE(labelsPositionSpy.count(), 1);
141 TRY_COMPARE(labelsPositionSpy.count(), 1);
142 arguments = labelsPositionSpy.takeFirst();
142 arguments = labelsPositionSpy.takeFirst();
143 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
143 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
144 == QHorizontalPercentBarSeries::LabelsOutsideEnd);
144 == QHorizontalPercentBarSeries::LabelsOutsideEnd);
145 QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsOutsideEnd);
145 QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsOutsideEnd);
146
146
147 m_barseries->setLabelsPosition(QHorizontalPercentBarSeries::LabelsCenter);
147 m_barseries->setLabelsPosition(QHorizontalPercentBarSeries::LabelsCenter);
148 TRY_COMPARE(labelsPositionSpy.count(), 1);
148 TRY_COMPARE(labelsPositionSpy.count(), 1);
149 arguments = labelsPositionSpy.takeFirst();
149 arguments = labelsPositionSpy.takeFirst();
150 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
150 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
151 == QHorizontalPercentBarSeries::LabelsCenter);
151 == QHorizontalPercentBarSeries::LabelsCenter);
152 QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsCenter);
152 QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsCenter);
153 }
153 }
154
154
155 void tst_QHorizontalPercentBarSeries::mouseclicked_data()
155 void tst_QHorizontalPercentBarSeries::mouseclicked_data()
156 {
156 {
157
157
158 }
158 }
159
159
160 void tst_QHorizontalPercentBarSeries::mouseclicked()
160 void tst_QHorizontalPercentBarSeries::mouseclicked()
161 {
161 {
162 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
162 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
163
163
164 QHorizontalPercentBarSeries* series = new QHorizontalPercentBarSeries();
164 QHorizontalPercentBarSeries* series = new QHorizontalPercentBarSeries();
165
165
166 QBarSet* set1 = new QBarSet(QString("set 1"));
166 QBarSet* set1 = new QBarSet(QString("set 1"));
167 *set1 << 10 << 10 << 10;
167 *set1 << 10 << 10 << 10;
168 series->append(set1);
168 series->append(set1);
169
169
170 QBarSet* set2 = new QBarSet(QString("set 2"));
170 QBarSet* set2 = new QBarSet(QString("set 2"));
171 *set2 << 10 << 10 << 10;
171 *set2 << 10 << 10 << 10;
172 series->append(set2);
172 series->append(set2);
173
173
174 QList<QBarSet*> barSets = series->barSets();
174 QList<QBarSet*> barSets = series->barSets();
175
175
176 QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*)));
176 QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*)));
177
177
178 QChartView view(new QChart());
178 QChartView view(new QChart());
179 view.resize(400,300);
179 view.resize(400,300);
180 view.chart()->addSeries(series);
180 view.chart()->addSeries(series);
181 view.show();
181 view.show();
182 QTest::qWaitForWindowShown(&view);
182 QTest::qWaitForWindowShown(&view);
183
183
184 // Calculate expected layout for bars
184 // Calculate expected layout for bars
185 QRectF plotArea = view.chart()->plotArea();
185 QRectF plotArea = view.chart()->plotArea();
186 qreal width = plotArea.width();
186 qreal width = plotArea.width();
187 qreal height = plotArea.height();
187 qreal height = plotArea.height();
188 qreal rangeY = 3; // 3 values per set
188 qreal rangeY = 3; // 3 values per set
189 qreal rangeX = 100; // From 0 to 100 because of scaling to 100%
189 qreal rangeX = 100; // From 0 to 100 because of scaling to 100%
190 qreal scaleY = (height / rangeY);
190 qreal scaleY = (height / rangeY);
191 qreal scaleX = (width / rangeX);
191 qreal scaleX = (width / rangeX);
192
192
193 qreal setCount = series->count();
193 qreal setCount = series->count();
194 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
194 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
195 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
195 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
196 qreal rectHeight = scaleY * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
196 qreal rectHeight = scaleY * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
197
197
198 QVector<QRectF> layout;
198 QVector<QRectF> layout;
199
199
200 // 3 = count of values in set
200 // 3 = count of values in set
201 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
201 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
202 for (int i = 0; i < 3; i++) {
202 for (int i = 0; i < 3; i++) {
203 qreal colSum = 20; // Sum of values in column (10 + 10 in our test case)
203 qreal colSum = 20; // Sum of values in column (10 + 10 in our test case)
204 qreal percentage = (100 / colSum);
204 qreal percentage = (100 / colSum);
205 qreal xPos = -scaleX * domainMinX + plotArea.left();
205 qreal xPos = -scaleX * domainMinX + plotArea.left();
206 for (int set = 0; set < setCount; set++) {
206 for (int set = 0; set < setCount; set++) {
207 qreal yPos = (domainMinY +0.5 -i) * scaleY + plotArea.bottom() - rectHeight/2;
207 qreal yPos = (domainMinY +0.5 -i) * scaleY + plotArea.bottom() - rectHeight/2;
208 qreal rectWidth = barSets.at(set)->at(i) * percentage * scaleX;
208 qreal rectWidth = barSets.at(set)->at(i) * percentage * scaleX;
209 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
209 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
210 layout.append(rect);
210 layout.append(rect);
211 xPos += rectWidth;
211 xPos += rectWidth;
212 }
212 }
213 }
213 }
214
214
215 //====================================================================================
215 //====================================================================================
216 // barset 1, bar 0
216 // barset 1, bar 0
217 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
217 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
218 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
218 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
219
219
220 QCOMPARE(seriesSpy.count(), 1);
220 QCOMPARE(seriesSpy.count(), 1);
221
221
222 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
222 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
223 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
223 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
224 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
224 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
225 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
225 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
226
226
227 //====================================================================================
227 //====================================================================================
228 // barset 1, bar 1
228 // barset 1, bar 1
229 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
229 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
230 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
230 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
231
231
232 QCOMPARE(seriesSpy.count(), 1);
232 QCOMPARE(seriesSpy.count(), 1);
233
233
234 seriesSpyArg = seriesSpy.takeFirst();
234 seriesSpyArg = seriesSpy.takeFirst();
235 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
235 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
236 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
236 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
237 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
237 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
238
238
239 //====================================================================================
239 //====================================================================================
240 // barset 1, bar 2
240 // barset 1, bar 2
241 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
241 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
242 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
242 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
243
243
244 QCOMPARE(seriesSpy.count(), 1);
244 QCOMPARE(seriesSpy.count(), 1);
245
245
246 seriesSpyArg = seriesSpy.takeFirst();
246 seriesSpyArg = seriesSpy.takeFirst();
247 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
247 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
248 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
248 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
249 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
249 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
250
250
251 //====================================================================================
251 //====================================================================================
252 // barset 2, bar 0
252 // barset 2, bar 0
253 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
253 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
254 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
254 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
255
255
256 QCOMPARE(seriesSpy.count(), 1);
256 QCOMPARE(seriesSpy.count(), 1);
257
257
258 seriesSpyArg = seriesSpy.takeFirst();
258 seriesSpyArg = seriesSpy.takeFirst();
259 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
259 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
260 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
260 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
261 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
261 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
262
262
263 //====================================================================================
263 //====================================================================================
264 // barset 2, bar 1
264 // barset 2, bar 1
265 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
265 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
266 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
266 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
267
267
268 QCOMPARE(seriesSpy.count(), 1);
268 QCOMPARE(seriesSpy.count(), 1);
269
269
270 seriesSpyArg = seriesSpy.takeFirst();
270 seriesSpyArg = seriesSpy.takeFirst();
271 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
271 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
272 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
272 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
273 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
273 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
274
274
275 //====================================================================================
275 //====================================================================================
276 // barset 2, bar 2
276 // barset 2, bar 2
277 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
277 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
278 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
278 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
279
279
280 QCOMPARE(seriesSpy.count(), 1);
280 QCOMPARE(seriesSpy.count(), 1);
281
281
282 seriesSpyArg = seriesSpy.takeFirst();
282 seriesSpyArg = seriesSpy.takeFirst();
283 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
283 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
284 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
284 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
285 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
285 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
286 }
286 }
287
287
288 void tst_QHorizontalPercentBarSeries::mousehovered_data()
288 void tst_QHorizontalPercentBarSeries::mousehovered_data()
289 {
289 {
290
290
291 }
291 }
292
292
293 void tst_QHorizontalPercentBarSeries::mousehovered()
293 void tst_QHorizontalPercentBarSeries::mousehovered()
294 {
294 {
295 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
295 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
296
296
297 QHorizontalPercentBarSeries* series = new QHorizontalPercentBarSeries();
297 QHorizontalPercentBarSeries* series = new QHorizontalPercentBarSeries();
298
298
299 QBarSet* set1 = new QBarSet(QString("set 1"));
299 QBarSet* set1 = new QBarSet(QString("set 1"));
300 *set1 << 10 << 10 << 10;
300 *set1 << 10 << 10 << 10;
301 series->append(set1);
301 series->append(set1);
302
302
303 QBarSet* set2 = new QBarSet(QString("set 2"));
303 QBarSet* set2 = new QBarSet(QString("set 2"));
304 *set2 << 10 << 10 << 10;
304 *set2 << 10 << 10 << 10;
305 series->append(set2);
305 series->append(set2);
306
306
307 QList<QBarSet*> barSets = series->barSets();
307 QList<QBarSet*> barSets = series->barSets();
308
308
309 QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*)));
310 QSignalSpy seriesIndexSpy(series, SIGNAL(hovered(bool, int, QBarSet*)));
309 QSignalSpy seriesIndexSpy(series, SIGNAL(hovered(bool, int, QBarSet*)));
311 QSignalSpy setIndexSpy1(set1, SIGNAL(hovered(bool, int)));
310 QSignalSpy setIndexSpy1(set1, SIGNAL(hovered(bool, int)));
312 QSignalSpy setIndexSpy2(set2, SIGNAL(hovered(bool, int)));
311 QSignalSpy setIndexSpy2(set2, SIGNAL(hovered(bool, int)));
313
312
314 QChartView view(new QChart());
313 QChartView view(new QChart());
315 view.resize(400,300);
314 view.resize(400,300);
316 view.chart()->addSeries(series);
315 view.chart()->addSeries(series);
317 view.show();
316 view.show();
318 QTest::qWaitForWindowShown(&view);
317 QTest::qWaitForWindowShown(&view);
319
318
320 //this is hack since view does not get events otherwise
319 //this is hack since view does not get events otherwise
321 view.setMouseTracking(true);
320 view.setMouseTracking(true);
322
321
323 // Calculate expected layout for bars
322 // Calculate expected layout for bars
324 QRectF plotArea = view.chart()->plotArea();
323 QRectF plotArea = view.chart()->plotArea();
325 qreal width = plotArea.width();
324 qreal width = plotArea.width();
326 qreal height = plotArea.height();
325 qreal height = plotArea.height();
327 qreal rangeY = 3; // 3 values per set
326 qreal rangeY = 3; // 3 values per set
328 qreal rangeX = 100; // From 0 to 100 because of scaling to 100%
327 qreal rangeX = 100; // From 0 to 100 because of scaling to 100%
329 qreal scaleY = (height / rangeY);
328 qreal scaleY = (height / rangeY);
330 qreal scaleX = (width / rangeX);
329 qreal scaleX = (width / rangeX);
331
330
332 qreal setCount = series->count();
331 qreal setCount = series->count();
333 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
332 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
334 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
333 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
335 qreal rectHeight = scaleY * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
334 qreal rectHeight = scaleY * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
336
335
337 QVector<QRectF> layout;
336 QVector<QRectF> layout;
338
337
339 // 3 = count of values in set
338 // 3 = count of values in set
340 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
339 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
341 for (int i = 0; i < 3; i++) {
340 for (int i = 0; i < 3; i++) {
342 qreal colSum = 20; // Sum of values in column (10 + 10 in our test case)
341 qreal colSum = 20; // Sum of values in column (10 + 10 in our test case)
343 qreal percentage = (100 / colSum);
342 qreal percentage = (100 / colSum);
344 qreal xPos = -scaleX * domainMinX + plotArea.left();
343 qreal xPos = -scaleX * domainMinX + plotArea.left();
345 for (int set = 0; set < setCount; set++) {
344 for (int set = 0; set < setCount; set++) {
346 qreal yPos = (domainMinY +0.5 -i) * scaleY + plotArea.bottom() - rectHeight/2;
345 qreal yPos = (domainMinY +0.5 -i) * scaleY + plotArea.bottom() - rectHeight/2;
347 qreal rectWidth = barSets.at(set)->at(i) * percentage * scaleX;
346 qreal rectWidth = barSets.at(set)->at(i) * percentage * scaleX;
348 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
347 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
349 layout.append(rect);
348 layout.append(rect);
350 xPos += rectWidth;
349 xPos += rectWidth;
351 }
350 }
352 }
351 }
353
352
354 //=======================================================================
353 //=======================================================================
355 // move mouse to left border
354 // move mouse to left border
356 QTest::mouseMove(view.viewport(), QPoint(0, layout.at(4).center().y()));
355 QTest::mouseMove(view.viewport(), QPoint(0, layout.at(4).center().y()));
357 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
356 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
358 TRY_COMPARE(seriesSpy.count(), 0);
359 TRY_COMPARE(seriesIndexSpy.count(), 0);
357 TRY_COMPARE(seriesIndexSpy.count(), 0);
360
358
361 //=======================================================================
359 //=======================================================================
362 // move mouse on top of set1
360 // move mouse on top of set1
363 QTest::mouseMove(view.viewport(), layout.at(4).center().toPoint());
361 QTest::mouseMove(view.viewport(), layout.at(4).center().toPoint());
364 TRY_COMPARE(seriesSpy.count(), 1);
365 TRY_COMPARE(seriesIndexSpy.count(), 1);
362 TRY_COMPARE(seriesIndexSpy.count(), 1);
366 TRY_COMPARE(setIndexSpy1.count(), 1);
363 TRY_COMPARE(setIndexSpy1.count(), 1);
367 TRY_COMPARE(setIndexSpy2.count(), 0);
364 TRY_COMPARE(setIndexSpy2.count(), 0);
368
365
369 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
370 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
371 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
372 QVERIFY(seriesSpyArg.at(0).toBool() == true);
373
374 QList<QVariant> seriesIndexSpyArg = seriesIndexSpy.takeFirst();
366 QList<QVariant> seriesIndexSpyArg = seriesIndexSpy.takeFirst();
375 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
367 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
376 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
368 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
377 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
369 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
378
370
379 QList<QVariant> setIndexSpyArg = setIndexSpy1.takeFirst();
371 QList<QVariant> setIndexSpyArg = setIndexSpy1.takeFirst();
380 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
372 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
381 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
373 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
382
374
383 //=======================================================================
375 //=======================================================================
384 // move mouse from top of set1 to top of set2
376 // move mouse from top of set1 to top of set2
385 QTest::mouseMove(view.viewport(), layout.at(5).center().toPoint());
377 QTest::mouseMove(view.viewport(), layout.at(5).center().toPoint());
386 TRY_COMPARE(seriesSpy.count(), 2);
387 TRY_COMPARE(seriesIndexSpy.count(), 2);
378 TRY_COMPARE(seriesIndexSpy.count(), 2);
388 TRY_COMPARE(setIndexSpy1.count(), 1);
379 TRY_COMPARE(setIndexSpy1.count(), 1);
389 TRY_COMPARE(setIndexSpy2.count(), 1);
380 TRY_COMPARE(setIndexSpy2.count(), 1);
390
381
391 // should leave set1
382 // should leave set1
392 seriesSpyArg = seriesSpy.takeFirst();
393 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
394 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
395 QVERIFY(seriesSpyArg.at(0).toBool() == false);
396
397 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
383 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
398 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
384 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
399 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
385 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
400 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
386 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
401
387
402 setIndexSpyArg = setIndexSpy1.takeFirst();
388 setIndexSpyArg = setIndexSpy1.takeFirst();
403 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
389 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
404 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
390 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
405
391
406 // should enter set2
392 // should enter set2
407 seriesSpyArg = seriesSpy.takeFirst();
408 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
409 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
410 QVERIFY(seriesSpyArg.at(0).toBool() == true);
411
412 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
393 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
413 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
394 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
414 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
395 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
415 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
396 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
416
397
417 setIndexSpyArg = setIndexSpy2.takeFirst();
398 setIndexSpyArg = setIndexSpy2.takeFirst();
418 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
399 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
419 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
400 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
420
401
421 //=======================================================================
402 //=======================================================================
422 // move mouse from top of set2 to background
403 // move mouse from top of set2 to background
423 QTest::mouseMove(view.viewport(), QPoint(layout.at(5).center().x(), 0));
404 QTest::mouseMove(view.viewport(), QPoint(layout.at(5).center().x(), 0));
424 TRY_COMPARE(seriesSpy.count(), 1);
425 TRY_COMPARE(seriesIndexSpy.count(), 1);
405 TRY_COMPARE(seriesIndexSpy.count(), 1);
426 TRY_COMPARE(setIndexSpy1.count(), 0);
406 TRY_COMPARE(setIndexSpy1.count(), 0);
427 TRY_COMPARE(setIndexSpy2.count(), 1);
407 TRY_COMPARE(setIndexSpy2.count(), 1);
428
408
429 // should leave set2
409 // should leave set2
430 seriesSpyArg = seriesSpy.takeFirst();
431 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
432 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
433 QVERIFY(seriesSpyArg.at(0).toBool() == false);
434
435 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
410 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
436 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
411 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
437 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
412 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
438 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
413 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
439
414
440 setIndexSpyArg = setIndexSpy2.takeFirst();
415 setIndexSpyArg = setIndexSpy2.takeFirst();
441 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
416 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
442 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
417 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
443
418
444 //=======================================================================
419 //=======================================================================
445 // move mouse on top of set1, bar0 to check the index (hover into set1)
420 // move mouse on top of set1, bar0 to check the index (hover into set1)
446 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
421 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
447
422
448 TRY_COMPARE(seriesSpy.count(), 1);
449 TRY_COMPARE(seriesIndexSpy.count(), 1);
423 TRY_COMPARE(seriesIndexSpy.count(), 1);
450 TRY_COMPARE(setIndexSpy1.count(), 1);
424 TRY_COMPARE(setIndexSpy1.count(), 1);
451 TRY_COMPARE(setIndexSpy2.count(), 0);
425 TRY_COMPARE(setIndexSpy2.count(), 0);
452
426
453 //should enter set1, bar0
427 //should enter set1, bar0
454 seriesSpyArg = seriesSpy.takeFirst();
455 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
456 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
457 QVERIFY(seriesSpyArg.at(0).toBool() == true);
458
459 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
428 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
460 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
429 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
461 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
430 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
462 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
431 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
463 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
432 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
464 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
433 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
465
434
466 setIndexSpyArg = setIndexSpy1.takeFirst();
435 setIndexSpyArg = setIndexSpy1.takeFirst();
467 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
436 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
468 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
437 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
469 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
438 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
470 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
439 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
471
440
472 //=======================================================================
441 //=======================================================================
473 // move mouse on top of set2, bar0 to check the index (hover out set1,
442 // move mouse on top of set2, bar0 to check the index (hover out set1,
474 // hover in set2)
443 // hover in set2)
475 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
444 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
476 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
445 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
477
446
478 TRY_COMPARE(seriesSpy.count(), 2);
479 TRY_COMPARE(seriesIndexSpy.count(), 2);
447 TRY_COMPARE(seriesIndexSpy.count(), 2);
480 TRY_COMPARE(setIndexSpy1.count(), 1);
448 TRY_COMPARE(setIndexSpy1.count(), 1);
481 TRY_COMPARE(setIndexSpy2.count(), 1);
449 TRY_COMPARE(setIndexSpy2.count(), 1);
482
450
483 //should leave set1, bar0
451 //should leave set1, bar0
484 seriesSpyArg = seriesSpy.takeFirst();
485 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
486 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
487 QVERIFY(seriesSpyArg.at(0).toBool() == false);
488
489 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
452 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
490 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
453 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
491 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
454 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
492 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
455 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
493 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
456 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
494 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
457 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
495
458
496 setIndexSpyArg = setIndexSpy1.takeFirst();
459 setIndexSpyArg = setIndexSpy1.takeFirst();
497 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
460 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
498 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
461 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
499 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
462 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
500 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
463 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
501
464
502 //should enter set2, bar0
465 //should enter set2, bar0
503 seriesSpyArg = seriesSpy.takeFirst();
504 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
505 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
506 QVERIFY(seriesSpyArg.at(0).toBool() == true);
507
508 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
466 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
509 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
467 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
510 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
468 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
511 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
469 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
512 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
470 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
513 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
471 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
514
472
515 setIndexSpyArg = setIndexSpy2.takeFirst();
473 setIndexSpyArg = setIndexSpy2.takeFirst();
516 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
474 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
517 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
475 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
518 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
476 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
519 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
477 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
520
478
521 //=======================================================================
479 //=======================================================================
522 // move mouse on top of set1, bar1 to check the index (hover out set2,
480 // move mouse on top of set1, bar1 to check the index (hover out set2,
523 // hover in set1)
481 // hover in set1)
524 QTest::mouseMove(view.viewport(), layout.at(2).center().toPoint());
482 QTest::mouseMove(view.viewport(), layout.at(2).center().toPoint());
525
483
526 TRY_COMPARE(seriesSpy.count(), 2);
527 TRY_COMPARE(seriesIndexSpy.count(), 2);
484 TRY_COMPARE(seriesIndexSpy.count(), 2);
528 TRY_COMPARE(setIndexSpy1.count(), 1);
485 TRY_COMPARE(setIndexSpy1.count(), 1);
529 TRY_COMPARE(setIndexSpy2.count(), 1);
486 TRY_COMPARE(setIndexSpy2.count(), 1);
530
487
531 //should leave set2, bar0
488 //should leave set2, bar0
532 seriesSpyArg = seriesSpy.takeFirst();
533 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
534 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
535 QVERIFY(seriesSpyArg.at(0).toBool() == false);
536
537 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
489 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
538 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
490 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
539 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
491 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
540 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
492 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
541 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
493 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
542 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
494 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
543
495
544 setIndexSpyArg = setIndexSpy2.takeFirst();
496 setIndexSpyArg = setIndexSpy2.takeFirst();
545 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
497 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
546 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
498 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
547 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
499 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
548 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
500 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
549
501
550 //should enter set1, bar1
502 //should enter set1, bar1
551 seriesSpyArg = seriesSpy.takeFirst();
552 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
553 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
554 QVERIFY(seriesSpyArg.at(0).toBool() == true);
555
556 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
503 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
557 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
504 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
558 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
505 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
559 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
506 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
560 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
507 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
561 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
508 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
562
509
563 setIndexSpyArg = setIndexSpy1.takeFirst();
510 setIndexSpyArg = setIndexSpy1.takeFirst();
564 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
511 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
565 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
512 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
566 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
513 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
567 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
514 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
568
515
569 //=======================================================================
516 //=======================================================================
570 // move mouse between set1 and set2 (hover out set1)
517 // move mouse between set1 and set2 (hover out set1)
571 QTest::mouseMove(view.viewport(), QPoint(layout.at(3).left(),
518 QTest::mouseMove(view.viewport(), QPoint(layout.at(3).left(),
572 (layout.at(3).top() + layout.at(4).bottom()) / 2));
519 (layout.at(3).top() + layout.at(4).bottom()) / 2));
573
520
574 TRY_COMPARE(seriesSpy.count(), 1);
575 TRY_COMPARE(seriesIndexSpy.count(), 1);
521 TRY_COMPARE(seriesIndexSpy.count(), 1);
576 TRY_COMPARE(setIndexSpy1.count(), 1);
522 TRY_COMPARE(setIndexSpy1.count(), 1);
577 TRY_COMPARE(setIndexSpy2.count(), 0);
523 TRY_COMPARE(setIndexSpy2.count(), 0);
578
524
579 //should leave set1, bar1
525 //should leave set1, bar1
580 seriesSpyArg = seriesSpy.takeFirst();
581 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
582 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
583 QVERIFY(seriesSpyArg.at(0).toBool() == false);
584
585 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
526 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
586 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
527 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
587 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
528 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
588 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
529 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
589 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
530 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
590 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
531 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
591
532
592 setIndexSpyArg = setIndexSpy1.takeFirst();
533 setIndexSpyArg = setIndexSpy1.takeFirst();
593 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
534 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
594 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
535 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
595 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
536 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
596 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
537 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
597
538
598 //=======================================================================
539 //=======================================================================
599 // move mouse on top of set2, bar1 to check the index (hover in set2)
540 // move mouse on top of set2, bar1 to check the index (hover in set2)
600 QTest::mouseMove(view.viewport(), layout.at(3).center().toPoint());
541 QTest::mouseMove(view.viewport(), layout.at(3).center().toPoint());
601
542
602 TRY_COMPARE(seriesSpy.count(), 1);
603 TRY_COMPARE(seriesIndexSpy.count(), 1);
543 TRY_COMPARE(seriesIndexSpy.count(), 1);
604 TRY_COMPARE(setIndexSpy1.count(), 0);
544 TRY_COMPARE(setIndexSpy1.count(), 0);
605 TRY_COMPARE(setIndexSpy2.count(), 1);
545 TRY_COMPARE(setIndexSpy2.count(), 1);
606
546
607 //should enter set2, bar1
547 //should enter set2, bar1
608 seriesSpyArg = seriesSpy.takeFirst();
609 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
610 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
611 QVERIFY(seriesSpyArg.at(0).toBool() == true);
612
613 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
548 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
614 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
549 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
615 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
550 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
616 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
551 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
617 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
552 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
618 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
553 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
619
554
620 setIndexSpyArg = setIndexSpy2.takeFirst();
555 setIndexSpyArg = setIndexSpy2.takeFirst();
621 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
556 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
622 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
557 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
623 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
558 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
624 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
559 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
625
560
626 //=======================================================================
561 //=======================================================================
627 // move mouse between set1 and set2 (hover out set2)
562 // move mouse between set1 and set2 (hover out set2)
628 QTest::mouseMove(view.viewport(), QPoint(layout.at(3).left(),
563 QTest::mouseMove(view.viewport(), QPoint(layout.at(3).left(),
629 (layout.at(3).top() + layout.at(4).bottom()) / 2));
564 (layout.at(3).top() + layout.at(4).bottom()) / 2));
630
565
631 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
566 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
632 TRY_COMPARE(seriesSpy.count(), 1);
633 TRY_COMPARE(seriesIndexSpy.count(), 1);
567 TRY_COMPARE(seriesIndexSpy.count(), 1);
634 TRY_COMPARE(setIndexSpy1.count(), 0);
568 TRY_COMPARE(setIndexSpy1.count(), 0);
635 TRY_COMPARE(setIndexSpy2.count(), 1);
569 TRY_COMPARE(setIndexSpy2.count(), 1);
636
570
637 //should leave set1, bar1
571 //should leave set1, bar1
638 seriesSpyArg = seriesSpy.takeFirst();
639 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
640 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
641 QVERIFY(seriesSpyArg.at(0).toBool() == false);
642
643 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
572 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
644 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
573 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
645 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
574 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
646 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
575 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
647 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
576 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
648 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
577 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
649
578
650 setIndexSpyArg = setIndexSpy2.takeFirst();
579 setIndexSpyArg = setIndexSpy2.takeFirst();
651 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
580 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
652 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
581 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
653 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
582 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
654 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
583 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
655 }
584 }
656
585
657 void tst_QHorizontalPercentBarSeries::zeroValuesInSeries()
586 void tst_QHorizontalPercentBarSeries::zeroValuesInSeries()
658 {
587 {
659 QHorizontalPercentBarSeries *series = new QHorizontalPercentBarSeries();
588 QHorizontalPercentBarSeries *series = new QHorizontalPercentBarSeries();
660 QBarSet *set1 = new QBarSet(QString("set 1"));
589 QBarSet *set1 = new QBarSet(QString("set 1"));
661 *set1 << 100 << 0.0 << 10;
590 *set1 << 100 << 0.0 << 10;
662 series->append(set1);
591 series->append(set1);
663
592
664 QBarSet *set2 = new QBarSet(QString("set 2"));
593 QBarSet *set2 = new QBarSet(QString("set 2"));
665 *set2 << 0.0 << 0.0 << 70;
594 *set2 << 0.0 << 0.0 << 70;
666 series->append(set2);
595 series->append(set2);
667
596
668 QChartView view(new QChart());
597 QChartView view(new QChart());
669 view.chart()->addSeries(series);
598 view.chart()->addSeries(series);
670 view.chart()->createDefaultAxes();
599 view.chart()->createDefaultAxes();
671 view.show();
600 view.show();
672
601
673 QTest::qWaitForWindowShown(&view);
602 QTest::qWaitForWindowShown(&view);
674 }
603 }
675
604
676 QTEST_MAIN(tst_QHorizontalPercentBarSeries)
605 QTEST_MAIN(tst_QHorizontalPercentBarSeries)
677
606
678 #include "tst_qhorizontalpercentbarseries.moc"
607 #include "tst_qhorizontalpercentbarseries.moc"
679
608
@@ -1,669 +1,598
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 <QtCharts/QHorizontalStackedBarSeries>
22 #include <QtCharts/QHorizontalStackedBarSeries>
23 #include <QtCharts/QBarSet>
23 #include <QtCharts/QBarSet>
24 #include <QtCharts/QChartView>
24 #include <QtCharts/QChartView>
25 #include <QtCharts/QChart>
25 #include <QtCharts/QChart>
26 #include "tst_definitions.h"
26 #include "tst_definitions.h"
27
27
28 QT_CHARTS_USE_NAMESPACE
28 QT_CHARTS_USE_NAMESPACE
29
29
30 Q_DECLARE_METATYPE(QBarSet*)
30 Q_DECLARE_METATYPE(QBarSet*)
31 Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition)
31 Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition)
32
32
33 class tst_QHorizontalStackedBarSeries : public QObject
33 class tst_QHorizontalStackedBarSeries : public QObject
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36
36
37 public slots:
37 public slots:
38 void initTestCase();
38 void initTestCase();
39 void cleanupTestCase();
39 void cleanupTestCase();
40 void init();
40 void init();
41 void cleanup();
41 void cleanup();
42
42
43 private slots:
43 private slots:
44 void qhorizontalstackedbarseries_data();
44 void qhorizontalstackedbarseries_data();
45 void qhorizontalstackedbarseries();
45 void qhorizontalstackedbarseries();
46 void type_data();
46 void type_data();
47 void type();
47 void type();
48 void setLabelsFormat();
48 void setLabelsFormat();
49 void setLabelsPosition();
49 void setLabelsPosition();
50 void mouseclicked_data();
50 void mouseclicked_data();
51 void mouseclicked();
51 void mouseclicked();
52 void mousehovered_data();
52 void mousehovered_data();
53 void mousehovered();
53 void mousehovered();
54
54
55 private:
55 private:
56 QHorizontalStackedBarSeries* m_barseries;
56 QHorizontalStackedBarSeries* m_barseries;
57 };
57 };
58
58
59 void tst_QHorizontalStackedBarSeries::initTestCase()
59 void tst_QHorizontalStackedBarSeries::initTestCase()
60 {
60 {
61 qRegisterMetaType<QBarSet*>("QBarSet*");
61 qRegisterMetaType<QBarSet*>("QBarSet*");
62 qRegisterMetaType<QAbstractBarSeries::LabelsPosition>("QAbstractBarSeries::LabelsPosition");
62 qRegisterMetaType<QAbstractBarSeries::LabelsPosition>("QAbstractBarSeries::LabelsPosition");
63 }
63 }
64
64
65 void tst_QHorizontalStackedBarSeries::cleanupTestCase()
65 void tst_QHorizontalStackedBarSeries::cleanupTestCase()
66 {
66 {
67 }
67 }
68
68
69 void tst_QHorizontalStackedBarSeries::init()
69 void tst_QHorizontalStackedBarSeries::init()
70 {
70 {
71 m_barseries = new QHorizontalStackedBarSeries();
71 m_barseries = new QHorizontalStackedBarSeries();
72 }
72 }
73
73
74 void tst_QHorizontalStackedBarSeries::cleanup()
74 void tst_QHorizontalStackedBarSeries::cleanup()
75 {
75 {
76 delete m_barseries;
76 delete m_barseries;
77 m_barseries = 0;
77 m_barseries = 0;
78 }
78 }
79
79
80 void tst_QHorizontalStackedBarSeries::qhorizontalstackedbarseries_data()
80 void tst_QHorizontalStackedBarSeries::qhorizontalstackedbarseries_data()
81 {
81 {
82 }
82 }
83
83
84 void tst_QHorizontalStackedBarSeries::qhorizontalstackedbarseries()
84 void tst_QHorizontalStackedBarSeries::qhorizontalstackedbarseries()
85 {
85 {
86 QHorizontalStackedBarSeries *barseries = new QHorizontalStackedBarSeries();
86 QHorizontalStackedBarSeries *barseries = new QHorizontalStackedBarSeries();
87 QVERIFY(barseries != 0);
87 QVERIFY(barseries != 0);
88 }
88 }
89
89
90 void tst_QHorizontalStackedBarSeries::type_data()
90 void tst_QHorizontalStackedBarSeries::type_data()
91 {
91 {
92
92
93 }
93 }
94
94
95 void tst_QHorizontalStackedBarSeries::type()
95 void tst_QHorizontalStackedBarSeries::type()
96 {
96 {
97 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeHorizontalStackedBar);
97 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeHorizontalStackedBar);
98 }
98 }
99
99
100 void tst_QHorizontalStackedBarSeries::setLabelsFormat()
100 void tst_QHorizontalStackedBarSeries::setLabelsFormat()
101 {
101 {
102 QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString)));
102 QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString)));
103 QCOMPARE(m_barseries->labelsFormat(), QString());
103 QCOMPARE(m_barseries->labelsFormat(), QString());
104
104
105 QString format("(@value)");
105 QString format("(@value)");
106 m_barseries->setLabelsFormat(format);
106 m_barseries->setLabelsFormat(format);
107 TRY_COMPARE(labelsFormatSpy.count(), 1);
107 TRY_COMPARE(labelsFormatSpy.count(), 1);
108 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
108 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
109 QVERIFY(arguments.at(0).toString() == format);
109 QVERIFY(arguments.at(0).toString() == format);
110 QCOMPARE(m_barseries->labelsFormat(), format);
110 QCOMPARE(m_barseries->labelsFormat(), format);
111
111
112 m_barseries->setLabelsFormat(QString());
112 m_barseries->setLabelsFormat(QString());
113 TRY_COMPARE(labelsFormatSpy.count(), 1);
113 TRY_COMPARE(labelsFormatSpy.count(), 1);
114 arguments = labelsFormatSpy.takeFirst();
114 arguments = labelsFormatSpy.takeFirst();
115 QVERIFY(arguments.at(0).toString() == QString());
115 QVERIFY(arguments.at(0).toString() == QString());
116 QCOMPARE(m_barseries->labelsFormat(), QString());
116 QCOMPARE(m_barseries->labelsFormat(), QString());
117 }
117 }
118
118
119 void tst_QHorizontalStackedBarSeries::setLabelsPosition()
119 void tst_QHorizontalStackedBarSeries::setLabelsPosition()
120 {
120 {
121 QSignalSpy labelsPositionSpy(m_barseries,
121 QSignalSpy labelsPositionSpy(m_barseries,
122 SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)));
122 SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)));
123 QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsCenter);
123 QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsCenter);
124
124
125 m_barseries->setLabelsPosition(QHorizontalStackedBarSeries::LabelsInsideEnd);
125 m_barseries->setLabelsPosition(QHorizontalStackedBarSeries::LabelsInsideEnd);
126 TRY_COMPARE(labelsPositionSpy.count(), 1);
126 TRY_COMPARE(labelsPositionSpy.count(), 1);
127 QList<QVariant> arguments = labelsPositionSpy.takeFirst();
127 QList<QVariant> arguments = labelsPositionSpy.takeFirst();
128 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
128 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
129 == QHorizontalStackedBarSeries::LabelsInsideEnd);
129 == QHorizontalStackedBarSeries::LabelsInsideEnd);
130 QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsInsideEnd);
130 QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsInsideEnd);
131
131
132 m_barseries->setLabelsPosition(QHorizontalStackedBarSeries::LabelsInsideBase);
132 m_barseries->setLabelsPosition(QHorizontalStackedBarSeries::LabelsInsideBase);
133 TRY_COMPARE(labelsPositionSpy.count(), 1);
133 TRY_COMPARE(labelsPositionSpy.count(), 1);
134 arguments = labelsPositionSpy.takeFirst();
134 arguments = labelsPositionSpy.takeFirst();
135 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
135 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
136 == QHorizontalStackedBarSeries::LabelsInsideBase);
136 == QHorizontalStackedBarSeries::LabelsInsideBase);
137 QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsInsideBase);
137 QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsInsideBase);
138
138
139 m_barseries->setLabelsPosition(QHorizontalStackedBarSeries::LabelsOutsideEnd);
139 m_barseries->setLabelsPosition(QHorizontalStackedBarSeries::LabelsOutsideEnd);
140 TRY_COMPARE(labelsPositionSpy.count(), 1);
140 TRY_COMPARE(labelsPositionSpy.count(), 1);
141 arguments = labelsPositionSpy.takeFirst();
141 arguments = labelsPositionSpy.takeFirst();
142 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
142 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
143 == QHorizontalStackedBarSeries::LabelsOutsideEnd);
143 == QHorizontalStackedBarSeries::LabelsOutsideEnd);
144 QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsOutsideEnd);
144 QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsOutsideEnd);
145
145
146 m_barseries->setLabelsPosition(QHorizontalStackedBarSeries::LabelsCenter);
146 m_barseries->setLabelsPosition(QHorizontalStackedBarSeries::LabelsCenter);
147 TRY_COMPARE(labelsPositionSpy.count(), 1);
147 TRY_COMPARE(labelsPositionSpy.count(), 1);
148 arguments = labelsPositionSpy.takeFirst();
148 arguments = labelsPositionSpy.takeFirst();
149 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
149 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
150 == QHorizontalStackedBarSeries::LabelsCenter);
150 == QHorizontalStackedBarSeries::LabelsCenter);
151 QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsCenter);
151 QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsCenter);
152 }
152 }
153
153
154 void tst_QHorizontalStackedBarSeries::mouseclicked_data()
154 void tst_QHorizontalStackedBarSeries::mouseclicked_data()
155 {
155 {
156
156
157 }
157 }
158
158
159 void tst_QHorizontalStackedBarSeries::mouseclicked()
159 void tst_QHorizontalStackedBarSeries::mouseclicked()
160 {
160 {
161 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
161 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
162
162
163 QHorizontalStackedBarSeries* series = new QHorizontalStackedBarSeries();
163 QHorizontalStackedBarSeries* series = new QHorizontalStackedBarSeries();
164
164
165 QBarSet* set1 = new QBarSet(QString("set 1"));
165 QBarSet* set1 = new QBarSet(QString("set 1"));
166 *set1 << 10 << 10 << 10;
166 *set1 << 10 << 10 << 10;
167 series->append(set1);
167 series->append(set1);
168
168
169 QBarSet* set2 = new QBarSet(QString("set 2"));
169 QBarSet* set2 = new QBarSet(QString("set 2"));
170 *set2 << 10 << 10 << 10;
170 *set2 << 10 << 10 << 10;
171 series->append(set2);
171 series->append(set2);
172
172
173 QList<QBarSet*> barSets = series->barSets();
173 QList<QBarSet*> barSets = series->barSets();
174
174
175 QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*)));
175 QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*)));
176
176
177 QChartView view(new QChart());
177 QChartView view(new QChart());
178 view.resize(400,300);
178 view.resize(400,300);
179 view.chart()->addSeries(series);
179 view.chart()->addSeries(series);
180 view.show();
180 view.show();
181 QTest::qWaitForWindowShown(&view);
181 QTest::qWaitForWindowShown(&view);
182
182
183 // Calculate expected layout for bars
183 // Calculate expected layout for bars
184 QRectF plotArea = view.chart()->plotArea();
184 QRectF plotArea = view.chart()->plotArea();
185 qreal width = plotArea.width();
185 qreal width = plotArea.width();
186 qreal height = plotArea.height();
186 qreal height = plotArea.height();
187 qreal rangeY = 3; // 3 values per set
187 qreal rangeY = 3; // 3 values per set
188 qreal rangeX = 20; // From 0 to 20 because bars are stacked (this should be height of highest stack)
188 qreal rangeX = 20; // From 0 to 20 because bars are stacked (this should be height of highest stack)
189 qreal scaleY = (height / rangeY);
189 qreal scaleY = (height / rangeY);
190 qreal scaleX = (width / rangeX);
190 qreal scaleX = (width / rangeX);
191
191
192 qreal setCount = series->count();
192 qreal setCount = series->count();
193 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
193 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
194 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
194 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
195 qreal rectHeight = scaleY * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
195 qreal rectHeight = scaleY * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
196
196
197 QVector<QRectF> layout;
197 QVector<QRectF> layout;
198
198
199 // 3 = count of values in set
199 // 3 = count of values in set
200 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
200 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
201 for (int i = 0; i < 3; i++) {
201 for (int i = 0; i < 3; i++) {
202 qreal xMax = -scaleX * domainMinX + plotArea.left();
202 qreal xMax = -scaleX * domainMinX + plotArea.left();
203 qreal xMin = -scaleX * domainMinX + plotArea.left();
203 qreal xMin = -scaleX * domainMinX + plotArea.left();
204 for (int set = 0; set < setCount; set++) {
204 for (int set = 0; set < setCount; set++) {
205 qreal yPos = (domainMinY +0.5 -i) * scaleY + plotArea.bottom() - rectHeight/2;
205 qreal yPos = (domainMinY +0.5 -i) * scaleY + plotArea.bottom() - rectHeight/2;
206 qreal rectWidth = barSets.at(set)->at(i) * scaleX;
206 qreal rectWidth = barSets.at(set)->at(i) * scaleX;
207 if (rectWidth > 0) {
207 if (rectWidth > 0) {
208 QRectF rect(xMax, yPos - rectHeight, rectWidth, rectHeight);
208 QRectF rect(xMax, yPos - rectHeight, rectWidth, rectHeight);
209 layout.append(rect);
209 layout.append(rect);
210 xMax += rectWidth;
210 xMax += rectWidth;
211 } else {
211 } else {
212 QRectF rect(xMin, yPos - rectHeight, rectWidth, rectHeight);
212 QRectF rect(xMin, yPos - rectHeight, rectWidth, rectHeight);
213 layout.append(rect);
213 layout.append(rect);
214 xMin += rectWidth;
214 xMin += rectWidth;
215 }
215 }
216 }
216 }
217 }
217 }
218
218
219 //====================================================================================
219 //====================================================================================
220 // barset 1, bar 0
220 // barset 1, bar 0
221 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
221 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
222 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
222 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
223
223
224 QCOMPARE(seriesSpy.count(), 1);
224 QCOMPARE(seriesSpy.count(), 1);
225
225
226 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
226 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
227 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
227 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
228 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
228 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
229 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
229 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
230
230
231 //====================================================================================
231 //====================================================================================
232 // barset 1, bar 1
232 // barset 1, bar 1
233 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
233 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
234 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
234 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
235
235
236 QCOMPARE(seriesSpy.count(), 1);
236 QCOMPARE(seriesSpy.count(), 1);
237
237
238 seriesSpyArg = seriesSpy.takeFirst();
238 seriesSpyArg = seriesSpy.takeFirst();
239 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
239 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
240 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
240 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
241 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
241 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
242
242
243 //====================================================================================
243 //====================================================================================
244 // barset 1, bar 2
244 // barset 1, bar 2
245 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
245 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
246 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
246 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
247
247
248 QCOMPARE(seriesSpy.count(), 1);
248 QCOMPARE(seriesSpy.count(), 1);
249
249
250 seriesSpyArg = seriesSpy.takeFirst();
250 seriesSpyArg = seriesSpy.takeFirst();
251 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
251 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
252 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
252 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
253 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
253 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
254
254
255 //====================================================================================
255 //====================================================================================
256 // barset 2, bar 0
256 // barset 2, bar 0
257 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
257 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
258 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
258 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
259
259
260 QCOMPARE(seriesSpy.count(), 1);
260 QCOMPARE(seriesSpy.count(), 1);
261
261
262 seriesSpyArg = seriesSpy.takeFirst();
262 seriesSpyArg = seriesSpy.takeFirst();
263 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
263 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
264 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
264 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
265 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
265 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
266
266
267 //====================================================================================
267 //====================================================================================
268 // barset 2, bar 1
268 // barset 2, bar 1
269 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
269 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
270 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
270 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
271
271
272 QCOMPARE(seriesSpy.count(), 1);
272 QCOMPARE(seriesSpy.count(), 1);
273
273
274 seriesSpyArg = seriesSpy.takeFirst();
274 seriesSpyArg = seriesSpy.takeFirst();
275 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
275 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
276 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
276 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
277 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
277 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
278
278
279 //====================================================================================
279 //====================================================================================
280 // barset 2, bar 2
280 // barset 2, bar 2
281 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
281 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
282 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
282 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
283
283
284 QCOMPARE(seriesSpy.count(), 1);
284 QCOMPARE(seriesSpy.count(), 1);
285
285
286 seriesSpyArg = seriesSpy.takeFirst();
286 seriesSpyArg = seriesSpy.takeFirst();
287 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
287 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
288 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
288 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
289 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
289 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
290 }
290 }
291
291
292 void tst_QHorizontalStackedBarSeries::mousehovered_data()
292 void tst_QHorizontalStackedBarSeries::mousehovered_data()
293 {
293 {
294
294
295 }
295 }
296
296
297 void tst_QHorizontalStackedBarSeries::mousehovered()
297 void tst_QHorizontalStackedBarSeries::mousehovered()
298 {
298 {
299 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
299 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
300
300
301 QHorizontalStackedBarSeries* series = new QHorizontalStackedBarSeries();
301 QHorizontalStackedBarSeries* series = new QHorizontalStackedBarSeries();
302
302
303 QBarSet* set1 = new QBarSet(QString("set 1"));
303 QBarSet* set1 = new QBarSet(QString("set 1"));
304 *set1 << 10 << 10 << 10;
304 *set1 << 10 << 10 << 10;
305 series->append(set1);
305 series->append(set1);
306
306
307 QBarSet* set2 = new QBarSet(QString("set 2"));
307 QBarSet* set2 = new QBarSet(QString("set 2"));
308 *set2 << 10 << 10 << 10;
308 *set2 << 10 << 10 << 10;
309 series->append(set2);
309 series->append(set2);
310
310
311 QList<QBarSet*> barSets = series->barSets();
311 QList<QBarSet*> barSets = series->barSets();
312
312
313 QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*)));
314 QSignalSpy seriesIndexSpy(series, SIGNAL(hovered(bool, int, QBarSet*)));
313 QSignalSpy seriesIndexSpy(series, SIGNAL(hovered(bool, int, QBarSet*)));
315 QSignalSpy setIndexSpy1(set1, SIGNAL(hovered(bool, int)));
314 QSignalSpy setIndexSpy1(set1, SIGNAL(hovered(bool, int)));
316 QSignalSpy setIndexSpy2(set2, SIGNAL(hovered(bool, int)));
315 QSignalSpy setIndexSpy2(set2, SIGNAL(hovered(bool, int)));
317
316
318 QChartView view(new QChart());
317 QChartView view(new QChart());
319 view.resize(400,300);
318 view.resize(400,300);
320 view.chart()->addSeries(series);
319 view.chart()->addSeries(series);
321 view.show();
320 view.show();
322 QTest::qWaitForWindowShown(&view);
321 QTest::qWaitForWindowShown(&view);
323
322
324 //this is hack since view does not get events otherwise
323 //this is hack since view does not get events otherwise
325 view.setMouseTracking(true);
324 view.setMouseTracking(true);
326
325
327 // Calculate expected layout for bars
326 // Calculate expected layout for bars
328 QRectF plotArea = view.chart()->plotArea();
327 QRectF plotArea = view.chart()->plotArea();
329 qreal width = plotArea.width();
328 qreal width = plotArea.width();
330 qreal height = plotArea.height();
329 qreal height = plotArea.height();
331 qreal rangeY = 3; // 3 values per set
330 qreal rangeY = 3; // 3 values per set
332 qreal rangeX = 20; // From 0 to 20 because bars are stacked (this should be height of highest stack)
331 qreal rangeX = 20; // From 0 to 20 because bars are stacked (this should be height of highest stack)
333 qreal scaleY = (height / rangeY);
332 qreal scaleY = (height / rangeY);
334 qreal scaleX = (width / rangeX);
333 qreal scaleX = (width / rangeX);
335
334
336 qreal setCount = series->count();
335 qreal setCount = series->count();
337 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
336 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
338 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
337 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
339 qreal rectHeight = scaleY * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
338 qreal rectHeight = scaleY * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
340
339
341 QVector<QRectF> layout;
340 QVector<QRectF> layout;
342
341
343 // 3 = count of values in set
342 // 3 = count of values in set
344 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
343 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
345 for (int i = 0; i < 3; i++) {
344 for (int i = 0; i < 3; i++) {
346 qreal xMax = -scaleX * domainMinX + plotArea.left();
345 qreal xMax = -scaleX * domainMinX + plotArea.left();
347 qreal xMin = -scaleX * domainMinX + plotArea.left();
346 qreal xMin = -scaleX * domainMinX + plotArea.left();
348 for (int set = 0; set < setCount; set++) {
347 for (int set = 0; set < setCount; set++) {
349 qreal yPos = (domainMinY +0.5 -i) * scaleY + plotArea.bottom() - rectHeight/2;
348 qreal yPos = (domainMinY +0.5 -i) * scaleY + plotArea.bottom() - rectHeight/2;
350 qreal rectWidth = barSets.at(set)->at(i) * scaleX;
349 qreal rectWidth = barSets.at(set)->at(i) * scaleX;
351 if (rectWidth > 0) {
350 if (rectWidth > 0) {
352 QRectF rect(xMax, yPos - rectHeight, rectWidth, rectHeight);
351 QRectF rect(xMax, yPos - rectHeight, rectWidth, rectHeight);
353 layout.append(rect);
352 layout.append(rect);
354 xMax += rectWidth;
353 xMax += rectWidth;
355 } else {
354 } else {
356 QRectF rect(xMin, yPos - rectHeight, rectWidth, rectHeight);
355 QRectF rect(xMin, yPos - rectHeight, rectWidth, rectHeight);
357 layout.append(rect);
356 layout.append(rect);
358 xMin += rectWidth;
357 xMin += rectWidth;
359 }
358 }
360 }
359 }
361 }
360 }
362
361
363 //=======================================================================
362 //=======================================================================
364 // move mouse to left border
363 // move mouse to left border
365 QTest::mouseMove(view.viewport(), QPoint(0, layout.at(4).center().y()));
364 QTest::mouseMove(view.viewport(), QPoint(0, layout.at(4).center().y()));
366 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
365 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
367 TRY_COMPARE(seriesSpy.count(), 0);
368 TRY_COMPARE(seriesIndexSpy.count(), 0);
366 TRY_COMPARE(seriesIndexSpy.count(), 0);
369
367
370 //=======================================================================
368 //=======================================================================
371 // move mouse on top of set1
369 // move mouse on top of set1
372 QTest::mouseMove(view.viewport(), layout.at(4).center().toPoint());
370 QTest::mouseMove(view.viewport(), layout.at(4).center().toPoint());
373 TRY_COMPARE(seriesSpy.count(), 1);
374 TRY_COMPARE(seriesIndexSpy.count(), 1);
371 TRY_COMPARE(seriesIndexSpy.count(), 1);
375 TRY_COMPARE(setIndexSpy1.count(), 1);
372 TRY_COMPARE(setIndexSpy1.count(), 1);
376 TRY_COMPARE(setIndexSpy2.count(), 0);
373 TRY_COMPARE(setIndexSpy2.count(), 0);
377
374
378 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
379 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
380 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
381 QVERIFY(seriesSpyArg.at(0).toBool() == true);
382
383 QList<QVariant> seriesIndexSpyArg = seriesIndexSpy.takeFirst();
375 QList<QVariant> seriesIndexSpyArg = seriesIndexSpy.takeFirst();
384 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
376 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
385 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
377 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
386 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
378 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
387
379
388 QList<QVariant> setIndexSpyArg = setIndexSpy1.takeFirst();
380 QList<QVariant> setIndexSpyArg = setIndexSpy1.takeFirst();
389 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
381 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
390 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
382 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
391
383
392 //=======================================================================
384 //=======================================================================
393 // move mouse from top of set1 to top of set2
385 // move mouse from top of set1 to top of set2
394 QTest::mouseMove(view.viewport(), layout.at(5).center().toPoint());
386 QTest::mouseMove(view.viewport(), layout.at(5).center().toPoint());
395 TRY_COMPARE(seriesSpy.count(), 2);
396 TRY_COMPARE(seriesIndexSpy.count(), 2);
387 TRY_COMPARE(seriesIndexSpy.count(), 2);
397 TRY_COMPARE(setIndexSpy1.count(), 1);
388 TRY_COMPARE(setIndexSpy1.count(), 1);
398 TRY_COMPARE(setIndexSpy2.count(), 1);
389 TRY_COMPARE(setIndexSpy2.count(), 1);
399
390
400 // should leave set1
391 // should leave set1
401 seriesSpyArg = seriesSpy.takeFirst();
402 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
403 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
404 QVERIFY(seriesSpyArg.at(0).toBool() == false);
405
406 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
392 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
407 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
393 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
408 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
394 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
409 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
395 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
410
396
411 setIndexSpyArg = setIndexSpy1.takeFirst();
397 setIndexSpyArg = setIndexSpy1.takeFirst();
412 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
398 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
413 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
399 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
414
400
415 // should enter set2
401 // should enter set2
416 seriesSpyArg = seriesSpy.takeFirst();
417 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
418 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
419 QVERIFY(seriesSpyArg.at(0).toBool() == true);
420
421 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
402 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
422 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
403 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
423 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
404 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
424 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
405 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
425
406
426 setIndexSpyArg = setIndexSpy2.takeFirst();
407 setIndexSpyArg = setIndexSpy2.takeFirst();
427 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
408 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
428 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
409 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
429
410
430 //=======================================================================
411 //=======================================================================
431 // move mouse from top of set2 to background
412 // move mouse from top of set2 to background
432 QTest::mouseMove(view.viewport(), QPoint(layout.at(5).center().y(), 0));
413 QTest::mouseMove(view.viewport(), QPoint(layout.at(5).center().y(), 0));
433 TRY_COMPARE(seriesSpy.count(), 1);
434 TRY_COMPARE(seriesIndexSpy.count(), 1);
414 TRY_COMPARE(seriesIndexSpy.count(), 1);
435 TRY_COMPARE(setIndexSpy1.count(), 0);
415 TRY_COMPARE(setIndexSpy1.count(), 0);
436 TRY_COMPARE(setIndexSpy2.count(), 1);
416 TRY_COMPARE(setIndexSpy2.count(), 1);
437
417
438 // should leave set2
418 // should leave set2
439 seriesSpyArg = seriesSpy.takeFirst();
440 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
441 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
442 QVERIFY(seriesSpyArg.at(0).toBool() == false);
443
444 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
419 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
445 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
420 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
446 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
421 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
447 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
422 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
448
423
449 setIndexSpyArg = setIndexSpy2.takeFirst();
424 setIndexSpyArg = setIndexSpy2.takeFirst();
450 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
425 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
451 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
426 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
452
427
453 //=======================================================================
428 //=======================================================================
454 // move mouse on top of set1, bar0 to check the index (hover into set1)
429 // move mouse on top of set1, bar0 to check the index (hover into set1)
455 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
430 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
456
431
457 TRY_COMPARE(seriesSpy.count(), 1);
458 TRY_COMPARE(seriesIndexSpy.count(), 1);
432 TRY_COMPARE(seriesIndexSpy.count(), 1);
459 TRY_COMPARE(setIndexSpy1.count(), 1);
433 TRY_COMPARE(setIndexSpy1.count(), 1);
460 TRY_COMPARE(setIndexSpy2.count(), 0);
434 TRY_COMPARE(setIndexSpy2.count(), 0);
461
435
462 //should enter set1, bar0
436 //should enter set1, bar0
463 seriesSpyArg = seriesSpy.takeFirst();
464 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
465 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
466 QVERIFY(seriesSpyArg.at(0).toBool() == true);
467
468 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
437 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
469 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
438 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
470 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
439 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
471 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
440 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
472 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
441 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
473 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
442 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
474
443
475 setIndexSpyArg = setIndexSpy1.takeFirst();
444 setIndexSpyArg = setIndexSpy1.takeFirst();
476 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
445 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
477 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
446 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
478 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
447 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
479 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
448 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
480
449
481 //=======================================================================
450 //=======================================================================
482 // move mouse on top of set2, bar0 to check the index (hover out set1,
451 // move mouse on top of set2, bar0 to check the index (hover out set1,
483 // hover in set2)
452 // hover in set2)
484 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
453 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
485 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
454 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
486
455
487 TRY_COMPARE(seriesSpy.count(), 2);
488 TRY_COMPARE(seriesIndexSpy.count(), 2);
456 TRY_COMPARE(seriesIndexSpy.count(), 2);
489 TRY_COMPARE(setIndexSpy1.count(), 1);
457 TRY_COMPARE(setIndexSpy1.count(), 1);
490 TRY_COMPARE(setIndexSpy2.count(), 1);
458 TRY_COMPARE(setIndexSpy2.count(), 1);
491
459
492 //should leave set1, bar0
460 //should leave set1, bar0
493 seriesSpyArg = seriesSpy.takeFirst();
494 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
495 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
496 QVERIFY(seriesSpyArg.at(0).toBool() == false);
497
498 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
461 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
499 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
462 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
500 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
463 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
501 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
464 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
502 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
465 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
503 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
466 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
504
467
505 setIndexSpyArg = setIndexSpy1.takeFirst();
468 setIndexSpyArg = setIndexSpy1.takeFirst();
506 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
469 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
507 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
470 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
508 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
471 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
509 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
472 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
510
473
511 //should enter set2, bar0
474 //should enter set2, bar0
512 seriesSpyArg = seriesSpy.takeFirst();
513 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
514 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
515 QVERIFY(seriesSpyArg.at(0).toBool() == true);
516
517 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
475 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
518 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
476 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
519 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
477 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
520 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
478 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
521 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
479 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
522 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
480 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
523
481
524 setIndexSpyArg = setIndexSpy2.takeFirst();
482 setIndexSpyArg = setIndexSpy2.takeFirst();
525 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
483 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
526 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
484 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
527 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
485 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
528 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
486 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
529
487
530 //=======================================================================
488 //=======================================================================
531 // move mouse on top of set1, bar1 to check the index (hover out set2,
489 // move mouse on top of set1, bar1 to check the index (hover out set2,
532 // hover in set1)
490 // hover in set1)
533 QTest::mouseMove(view.viewport(), layout.at(2).center().toPoint());
491 QTest::mouseMove(view.viewport(), layout.at(2).center().toPoint());
534
492
535 TRY_COMPARE(seriesSpy.count(), 2);
536 TRY_COMPARE(seriesIndexSpy.count(), 2);
493 TRY_COMPARE(seriesIndexSpy.count(), 2);
537 TRY_COMPARE(setIndexSpy1.count(), 1);
494 TRY_COMPARE(setIndexSpy1.count(), 1);
538 TRY_COMPARE(setIndexSpy2.count(), 1);
495 TRY_COMPARE(setIndexSpy2.count(), 1);
539
496
540 //should leave set2, bar0
497 //should leave set2, bar0
541 seriesSpyArg = seriesSpy.takeFirst();
542 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
543 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
544 QVERIFY(seriesSpyArg.at(0).toBool() == false);
545
546 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
498 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
547 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
499 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
548 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
500 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
549 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
501 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
550 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
502 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
551 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
503 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
552
504
553 setIndexSpyArg = setIndexSpy2.takeFirst();
505 setIndexSpyArg = setIndexSpy2.takeFirst();
554 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
506 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
555 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
507 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
556 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
508 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
557 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
509 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
558
510
559 //should enter set1, bar1
511 //should enter set1, bar1
560 seriesSpyArg = seriesSpy.takeFirst();
561 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
562 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
563 QVERIFY(seriesSpyArg.at(0).toBool() == true);
564
565 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
512 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
566 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
513 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
567 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
514 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
568 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
515 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
569 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
516 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
570 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
517 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
571
518
572 setIndexSpyArg = setIndexSpy1.takeFirst();
519 setIndexSpyArg = setIndexSpy1.takeFirst();
573 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
520 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
574 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
521 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
575 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
522 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
576 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
523 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
577
524
578 //=======================================================================
525 //=======================================================================
579 // move mouse between set1 and set2 (hover out set1)
526 // move mouse between set1 and set2 (hover out set1)
580 QTest::mouseMove(view.viewport(), QPoint(layout.at(3).left(),
527 QTest::mouseMove(view.viewport(), QPoint(layout.at(3).left(),
581 (layout.at(3).top() + layout.at(4).bottom()) / 2));
528 (layout.at(3).top() + layout.at(4).bottom()) / 2));
582
529
583 TRY_COMPARE(seriesSpy.count(), 1);
584 TRY_COMPARE(seriesIndexSpy.count(), 1);
530 TRY_COMPARE(seriesIndexSpy.count(), 1);
585 TRY_COMPARE(setIndexSpy1.count(), 1);
531 TRY_COMPARE(setIndexSpy1.count(), 1);
586 TRY_COMPARE(setIndexSpy2.count(), 0);
532 TRY_COMPARE(setIndexSpy2.count(), 0);
587
533
588 //should leave set1, bar1
534 //should leave set1, bar1
589 seriesSpyArg = seriesSpy.takeFirst();
590 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
591 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
592 QVERIFY(seriesSpyArg.at(0).toBool() == false);
593
594 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
535 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
595 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
536 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
596 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
537 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
597 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
538 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
598 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
539 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
599 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
540 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
600
541
601 setIndexSpyArg = setIndexSpy1.takeFirst();
542 setIndexSpyArg = setIndexSpy1.takeFirst();
602 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
543 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
603 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
544 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
604 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
545 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
605 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
546 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
606
547
607 //=======================================================================
548 //=======================================================================
608 // move mouse on top of set2, bar1 to check the index (hover in set2)
549 // move mouse on top of set2, bar1 to check the index (hover in set2)
609 QTest::mouseMove(view.viewport(), layout.at(3).center().toPoint());
550 QTest::mouseMove(view.viewport(), layout.at(3).center().toPoint());
610
551
611 TRY_COMPARE(seriesSpy.count(), 1);
612 TRY_COMPARE(seriesIndexSpy.count(), 1);
552 TRY_COMPARE(seriesIndexSpy.count(), 1);
613 TRY_COMPARE(setIndexSpy1.count(), 0);
553 TRY_COMPARE(setIndexSpy1.count(), 0);
614 TRY_COMPARE(setIndexSpy2.count(), 1);
554 TRY_COMPARE(setIndexSpy2.count(), 1);
615
555
616 //should enter set2, bar1
556 //should enter set2, bar1
617 seriesSpyArg = seriesSpy.takeFirst();
618 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
619 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
620 QVERIFY(seriesSpyArg.at(0).toBool() == true);
621
622 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
557 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
623 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
558 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
624 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
559 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
625 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
560 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
626 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
561 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
627 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
562 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
628
563
629 setIndexSpyArg = setIndexSpy2.takeFirst();
564 setIndexSpyArg = setIndexSpy2.takeFirst();
630 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
565 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
631 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
566 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
632 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
567 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
633 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
568 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
634
569
635 //=======================================================================
570 //=======================================================================
636 // move mouse between set1 and set2 (hover out set2)
571 // move mouse between set1 and set2 (hover out set2)
637 QTest::mouseMove(view.viewport(), QPoint(layout.at(3).left(),
572 QTest::mouseMove(view.viewport(), QPoint(layout.at(3).left(),
638 (layout.at(3).top() + layout.at(4).bottom()) / 2));
573 (layout.at(3).top() + layout.at(4).bottom()) / 2));
639
574
640 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
575 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
641 TRY_COMPARE(seriesSpy.count(), 1);
642 TRY_COMPARE(seriesIndexSpy.count(), 1);
576 TRY_COMPARE(seriesIndexSpy.count(), 1);
643 TRY_COMPARE(setIndexSpy1.count(), 0);
577 TRY_COMPARE(setIndexSpy1.count(), 0);
644 TRY_COMPARE(setIndexSpy2.count(), 1);
578 TRY_COMPARE(setIndexSpy2.count(), 1);
645
579
646 //should leave set1, bar1
580 //should leave set1, bar1
647 seriesSpyArg = seriesSpy.takeFirst();
648 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
649 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
650 QVERIFY(seriesSpyArg.at(0).toBool() == false);
651
652 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
581 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
653 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
582 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
654 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
583 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
655 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
584 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
656 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
585 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
657 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
586 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
658
587
659 setIndexSpyArg = setIndexSpy2.takeFirst();
588 setIndexSpyArg = setIndexSpy2.takeFirst();
660 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
589 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
661 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
590 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
662 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
591 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
663 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
592 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
664 }
593 }
665
594
666 QTEST_MAIN(tst_QHorizontalStackedBarSeries)
595 QTEST_MAIN(tst_QHorizontalStackedBarSeries)
667
596
668 #include "tst_qhorizontalstackedbarseries.moc"
597 #include "tst_qhorizontalstackedbarseries.moc"
669
598
@@ -1,683 +1,612
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 <QtCharts/QPercentBarSeries>
22 #include <QtCharts/QPercentBarSeries>
23 #include <QtCharts/QBarSet>
23 #include <QtCharts/QBarSet>
24 #include <QtCharts/QChartView>
24 #include <QtCharts/QChartView>
25 #include <QtCharts/QChart>
25 #include <QtCharts/QChart>
26 #include "tst_definitions.h"
26 #include "tst_definitions.h"
27
27
28 QT_CHARTS_USE_NAMESPACE
28 QT_CHARTS_USE_NAMESPACE
29
29
30 Q_DECLARE_METATYPE(QBarSet*)
30 Q_DECLARE_METATYPE(QBarSet*)
31 Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition)
31 Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition)
32
32
33 class tst_QPercentBarSeries : public QObject
33 class tst_QPercentBarSeries : public QObject
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36
36
37 public slots:
37 public slots:
38 void initTestCase();
38 void initTestCase();
39 void cleanupTestCase();
39 void cleanupTestCase();
40 void init();
40 void init();
41 void cleanup();
41 void cleanup();
42
42
43 private slots:
43 private slots:
44 void qpercentbarseries_data();
44 void qpercentbarseries_data();
45 void qpercentbarseries();
45 void qpercentbarseries();
46 void type_data();
46 void type_data();
47 void type();
47 void type();
48 void setLabelsFormat();
48 void setLabelsFormat();
49 void setLabelsPosition();
49 void setLabelsPosition();
50 void mouseclicked_data();
50 void mouseclicked_data();
51 void mouseclicked();
51 void mouseclicked();
52 void mousehovered_data();
52 void mousehovered_data();
53 void mousehovered();
53 void mousehovered();
54 void zeroValuesInSeries();
54 void zeroValuesInSeries();
55
55
56 private:
56 private:
57 QPercentBarSeries* m_barseries;
57 QPercentBarSeries* m_barseries;
58 };
58 };
59
59
60 void tst_QPercentBarSeries::initTestCase()
60 void tst_QPercentBarSeries::initTestCase()
61 {
61 {
62 qRegisterMetaType<QBarSet*>("QBarSet*");
62 qRegisterMetaType<QBarSet*>("QBarSet*");
63 qRegisterMetaType<QAbstractBarSeries::LabelsPosition>("QAbstractBarSeries::LabelsPosition");
63 qRegisterMetaType<QAbstractBarSeries::LabelsPosition>("QAbstractBarSeries::LabelsPosition");
64 }
64 }
65
65
66 void tst_QPercentBarSeries::cleanupTestCase()
66 void tst_QPercentBarSeries::cleanupTestCase()
67 {
67 {
68 }
68 }
69
69
70 void tst_QPercentBarSeries::init()
70 void tst_QPercentBarSeries::init()
71 {
71 {
72 m_barseries = new QPercentBarSeries();
72 m_barseries = new QPercentBarSeries();
73 }
73 }
74
74
75 void tst_QPercentBarSeries::cleanup()
75 void tst_QPercentBarSeries::cleanup()
76 {
76 {
77 delete m_barseries;
77 delete m_barseries;
78 m_barseries = 0;
78 m_barseries = 0;
79 }
79 }
80
80
81 void tst_QPercentBarSeries::qpercentbarseries_data()
81 void tst_QPercentBarSeries::qpercentbarseries_data()
82 {
82 {
83 }
83 }
84
84
85 void tst_QPercentBarSeries::qpercentbarseries()
85 void tst_QPercentBarSeries::qpercentbarseries()
86 {
86 {
87 QPercentBarSeries *barseries = new QPercentBarSeries();
87 QPercentBarSeries *barseries = new QPercentBarSeries();
88 QVERIFY(barseries != 0);
88 QVERIFY(barseries != 0);
89 }
89 }
90
90
91 void tst_QPercentBarSeries::type_data()
91 void tst_QPercentBarSeries::type_data()
92 {
92 {
93
93
94 }
94 }
95
95
96 void tst_QPercentBarSeries::type()
96 void tst_QPercentBarSeries::type()
97 {
97 {
98 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypePercentBar);
98 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypePercentBar);
99 }
99 }
100
100
101 void tst_QPercentBarSeries::mouseclicked_data()
101 void tst_QPercentBarSeries::mouseclicked_data()
102 {
102 {
103
103
104 }
104 }
105
105
106 void tst_QPercentBarSeries::setLabelsFormat()
106 void tst_QPercentBarSeries::setLabelsFormat()
107 {
107 {
108 QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString)));
108 QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString)));
109 QCOMPARE(m_barseries->labelsFormat(), QString());
109 QCOMPARE(m_barseries->labelsFormat(), QString());
110
110
111 QString format("(@value)");
111 QString format("(@value)");
112 m_barseries->setLabelsFormat(format);
112 m_barseries->setLabelsFormat(format);
113 TRY_COMPARE(labelsFormatSpy.count(), 1);
113 TRY_COMPARE(labelsFormatSpy.count(), 1);
114 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
114 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
115 QVERIFY(arguments.at(0).toString() == format);
115 QVERIFY(arguments.at(0).toString() == format);
116 QCOMPARE(m_barseries->labelsFormat(), format);
116 QCOMPARE(m_barseries->labelsFormat(), format);
117
117
118 m_barseries->setLabelsFormat(QString());
118 m_barseries->setLabelsFormat(QString());
119 TRY_COMPARE(labelsFormatSpy.count(), 1);
119 TRY_COMPARE(labelsFormatSpy.count(), 1);
120 arguments = labelsFormatSpy.takeFirst();
120 arguments = labelsFormatSpy.takeFirst();
121 QVERIFY(arguments.at(0).toString() == QString());
121 QVERIFY(arguments.at(0).toString() == QString());
122 QCOMPARE(m_barseries->labelsFormat(), QString());
122 QCOMPARE(m_barseries->labelsFormat(), QString());
123 }
123 }
124
124
125 void tst_QPercentBarSeries::setLabelsPosition()
125 void tst_QPercentBarSeries::setLabelsPosition()
126 {
126 {
127 QSignalSpy labelsPositionSpy(m_barseries,
127 QSignalSpy labelsPositionSpy(m_barseries,
128 SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)));
128 SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)));
129 QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsCenter);
129 QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsCenter);
130
130
131 m_barseries->setLabelsPosition(QPercentBarSeries::LabelsInsideEnd);
131 m_barseries->setLabelsPosition(QPercentBarSeries::LabelsInsideEnd);
132 TRY_COMPARE(labelsPositionSpy.count(), 1);
132 TRY_COMPARE(labelsPositionSpy.count(), 1);
133 QList<QVariant> arguments = labelsPositionSpy.takeFirst();
133 QList<QVariant> arguments = labelsPositionSpy.takeFirst();
134 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
134 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
135 == QPercentBarSeries::LabelsInsideEnd);
135 == QPercentBarSeries::LabelsInsideEnd);
136 QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsInsideEnd);
136 QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsInsideEnd);
137
137
138 m_barseries->setLabelsPosition(QPercentBarSeries::LabelsInsideBase);
138 m_barseries->setLabelsPosition(QPercentBarSeries::LabelsInsideBase);
139 TRY_COMPARE(labelsPositionSpy.count(), 1);
139 TRY_COMPARE(labelsPositionSpy.count(), 1);
140 arguments = labelsPositionSpy.takeFirst();
140 arguments = labelsPositionSpy.takeFirst();
141 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
141 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
142 == QPercentBarSeries::LabelsInsideBase);
142 == QPercentBarSeries::LabelsInsideBase);
143 QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsInsideBase);
143 QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsInsideBase);
144
144
145 m_barseries->setLabelsPosition(QPercentBarSeries::LabelsOutsideEnd);
145 m_barseries->setLabelsPosition(QPercentBarSeries::LabelsOutsideEnd);
146 TRY_COMPARE(labelsPositionSpy.count(), 1);
146 TRY_COMPARE(labelsPositionSpy.count(), 1);
147 arguments = labelsPositionSpy.takeFirst();
147 arguments = labelsPositionSpy.takeFirst();
148 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
148 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
149 == QPercentBarSeries::LabelsOutsideEnd);
149 == QPercentBarSeries::LabelsOutsideEnd);
150 QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsOutsideEnd);
150 QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsOutsideEnd);
151
151
152 m_barseries->setLabelsPosition(QPercentBarSeries::LabelsCenter);
152 m_barseries->setLabelsPosition(QPercentBarSeries::LabelsCenter);
153 TRY_COMPARE(labelsPositionSpy.count(), 1);
153 TRY_COMPARE(labelsPositionSpy.count(), 1);
154 arguments = labelsPositionSpy.takeFirst();
154 arguments = labelsPositionSpy.takeFirst();
155 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
155 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
156 == QPercentBarSeries::LabelsCenter);
156 == QPercentBarSeries::LabelsCenter);
157 QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsCenter);
157 QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsCenter);
158 }
158 }
159
159
160 void tst_QPercentBarSeries::mouseclicked()
160 void tst_QPercentBarSeries::mouseclicked()
161 {
161 {
162 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
162 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
163
163
164 QPercentBarSeries* series = new QPercentBarSeries();
164 QPercentBarSeries* series = new QPercentBarSeries();
165
165
166 QBarSet* set1 = new QBarSet(QString("set 1"));
166 QBarSet* set1 = new QBarSet(QString("set 1"));
167 *set1 << 10 << 10 << 10;
167 *set1 << 10 << 10 << 10;
168 series->append(set1);
168 series->append(set1);
169
169
170 QBarSet* set2 = new QBarSet(QString("set 2"));
170 QBarSet* set2 = new QBarSet(QString("set 2"));
171 *set2 << 10 << 10 << 10;
171 *set2 << 10 << 10 << 10;
172 series->append(set2);
172 series->append(set2);
173
173
174 QList<QBarSet*> barSets = series->barSets();
174 QList<QBarSet*> barSets = series->barSets();
175
175
176 QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*)));
176 QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*)));
177
177
178 QChartView view(new QChart());
178 QChartView view(new QChart());
179 view.resize(400,300);
179 view.resize(400,300);
180 view.chart()->addSeries(series);
180 view.chart()->addSeries(series);
181 view.show();
181 view.show();
182 QTest::qWaitForWindowShown(&view);
182 QTest::qWaitForWindowShown(&view);
183
183
184 // Calculate expected layout for bars
184 // Calculate expected layout for bars
185 QRectF plotArea = view.chart()->plotArea();
185 QRectF plotArea = view.chart()->plotArea();
186 qreal width = plotArea.width();
186 qreal width = plotArea.width();
187 qreal height = plotArea.height();
187 qreal height = plotArea.height();
188 qreal rangeY = 100; // From 0 to 100 because range is scaled to 100%
188 qreal rangeY = 100; // From 0 to 100 because range is scaled to 100%
189 qreal rangeX = 3; // 3 values per set
189 qreal rangeX = 3; // 3 values per set
190 qreal scaleY = (height / rangeY);
190 qreal scaleY = (height / rangeY);
191 qreal scaleX = (width / rangeX);
191 qreal scaleX = (width / rangeX);
192
192
193 qreal setCount = series->count();
193 qreal setCount = series->count();
194 qreal domainMinY = 0; // These come from internal domain used by barseries.
194 qreal domainMinY = 0; // These come from internal domain used by barseries.
195 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
195 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
196 qreal rectWidth = scaleX * series->barWidth();
196 qreal rectWidth = scaleX * series->barWidth();
197
197
198 QVector<QRectF> layout;
198 QVector<QRectF> layout;
199
199
200 // 3 = count of values in set
200 // 3 = count of values in set
201 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
201 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
202 for (int i = 0; i < 3; i++) {
202 for (int i = 0; i < 3; i++) {
203 qreal colSum = 20; // Sum of values in column (10 + 10 in our test case)
203 qreal colSum = 20; // Sum of values in column (10 + 10 in our test case)
204 qreal percentage = (100 / colSum);
204 qreal percentage = (100 / colSum);
205 qreal yPos = height + scaleY * domainMinY + plotArea.top();
205 qreal yPos = height + scaleY * domainMinY + plotArea.top();
206
206
207 for (int set = 0; set < setCount; set++) {
207 for (int set = 0; set < setCount; set++) {
208 qreal xPos = (i - domainMinX) * scaleX + plotArea.left() - rectWidth/2;
208 qreal xPos = (i - domainMinX) * scaleX + plotArea.left() - rectWidth/2;
209 qreal rectHeigth = barSets.at(set)->at(i) * percentage * scaleY;
209 qreal rectHeigth = barSets.at(set)->at(i) * percentage * scaleY;
210
210
211 QRectF rect(xPos, yPos-rectHeigth, rectWidth, rectHeigth);
211 QRectF rect(xPos, yPos-rectHeigth, rectWidth, rectHeigth);
212 layout.append(rect);
212 layout.append(rect);
213 yPos -= rectHeigth;
213 yPos -= rectHeigth;
214 }
214 }
215 }
215 }
216
216
217 //====================================================================================
217 //====================================================================================
218 // barset 1, bar 0
218 // barset 1, bar 0
219 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
219 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
220 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
220 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
221
221
222 QCOMPARE(seriesSpy.count(), 1);
222 QCOMPARE(seriesSpy.count(), 1);
223
223
224 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
224 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
225 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
225 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
226 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
226 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
227 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
227 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
228
228
229 //====================================================================================
229 //====================================================================================
230 // barset 1, bar 1
230 // barset 1, bar 1
231 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
231 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
232 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
232 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
233
233
234 QCOMPARE(seriesSpy.count(), 1);
234 QCOMPARE(seriesSpy.count(), 1);
235
235
236 seriesSpyArg = seriesSpy.takeFirst();
236 seriesSpyArg = seriesSpy.takeFirst();
237 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
237 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
238 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
238 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
239 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
239 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
240
240
241 //====================================================================================
241 //====================================================================================
242 // barset 1, bar 2
242 // barset 1, bar 2
243 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
243 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
244 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
244 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
245
245
246 QCOMPARE(seriesSpy.count(), 1);
246 QCOMPARE(seriesSpy.count(), 1);
247
247
248 seriesSpyArg = seriesSpy.takeFirst();
248 seriesSpyArg = seriesSpy.takeFirst();
249 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
249 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
250 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
250 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
251 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
251 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
252
252
253 //====================================================================================
253 //====================================================================================
254 // barset 2, bar 0
254 // barset 2, bar 0
255 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
255 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
256 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
256 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
257
257
258 QCOMPARE(seriesSpy.count(), 1);
258 QCOMPARE(seriesSpy.count(), 1);
259
259
260 seriesSpyArg = seriesSpy.takeFirst();
260 seriesSpyArg = seriesSpy.takeFirst();
261 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
261 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
262 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
262 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
263 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
263 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
264
264
265 //====================================================================================
265 //====================================================================================
266 // barset 2, bar 1
266 // barset 2, bar 1
267 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
267 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
268 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
268 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
269
269
270 QCOMPARE(seriesSpy.count(), 1);
270 QCOMPARE(seriesSpy.count(), 1);
271
271
272 seriesSpyArg = seriesSpy.takeFirst();
272 seriesSpyArg = seriesSpy.takeFirst();
273 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
273 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
274 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
274 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
275 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
275 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
276
276
277 //====================================================================================
277 //====================================================================================
278 // barset 2, bar 2
278 // barset 2, bar 2
279 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
279 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
280 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
280 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
281
281
282 QCOMPARE(seriesSpy.count(), 1);
282 QCOMPARE(seriesSpy.count(), 1);
283
283
284 seriesSpyArg = seriesSpy.takeFirst();
284 seriesSpyArg = seriesSpy.takeFirst();
285 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
285 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
286 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
286 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
287 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
287 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
288 }
288 }
289
289
290 void tst_QPercentBarSeries::mousehovered_data()
290 void tst_QPercentBarSeries::mousehovered_data()
291 {
291 {
292
292
293 }
293 }
294
294
295 void tst_QPercentBarSeries::mousehovered()
295 void tst_QPercentBarSeries::mousehovered()
296 {
296 {
297 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
297 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
298
298
299 QPercentBarSeries* series = new QPercentBarSeries();
299 QPercentBarSeries* series = new QPercentBarSeries();
300
300
301 QBarSet* set1 = new QBarSet(QString("set 1"));
301 QBarSet* set1 = new QBarSet(QString("set 1"));
302 *set1 << 10 << 10 << 10;
302 *set1 << 10 << 10 << 10;
303 series->append(set1);
303 series->append(set1);
304
304
305 QBarSet* set2 = new QBarSet(QString("set 2"));
305 QBarSet* set2 = new QBarSet(QString("set 2"));
306 *set2 << 10 << 10 << 10;
306 *set2 << 10 << 10 << 10;
307 series->append(set2);
307 series->append(set2);
308
308
309 QList<QBarSet*> barSets = series->barSets();
309 QList<QBarSet*> barSets = series->barSets();
310
310
311 QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*)));
312 QSignalSpy seriesIndexSpy(series, SIGNAL(hovered(bool, int, QBarSet*)));
311 QSignalSpy seriesIndexSpy(series, SIGNAL(hovered(bool, int, QBarSet*)));
313 QSignalSpy setIndexSpy1(set1, SIGNAL(hovered(bool, int)));
312 QSignalSpy setIndexSpy1(set1, SIGNAL(hovered(bool, int)));
314 QSignalSpy setIndexSpy2(set2, SIGNAL(hovered(bool, int)));
313 QSignalSpy setIndexSpy2(set2, SIGNAL(hovered(bool, int)));
315
314
316 QChartView view(new QChart());
315 QChartView view(new QChart());
317 view.resize(400,300);
316 view.resize(400,300);
318 view.chart()->addSeries(series);
317 view.chart()->addSeries(series);
319 view.show();
318 view.show();
320 QTest::qWaitForWindowShown(&view);
319 QTest::qWaitForWindowShown(&view);
321
320
322 //this is hack since view does not get events otherwise
321 //this is hack since view does not get events otherwise
323 view.setMouseTracking(true);
322 view.setMouseTracking(true);
324
323
325 // Calculate expected layout for bars
324 // Calculate expected layout for bars
326 QRectF plotArea = view.chart()->plotArea();
325 QRectF plotArea = view.chart()->plotArea();
327 qreal width = plotArea.width();
326 qreal width = plotArea.width();
328 qreal height = plotArea.height();
327 qreal height = plotArea.height();
329 qreal rangeY = 100; // From 0 to 100 because range is scaled to 100%
328 qreal rangeY = 100; // From 0 to 100 because range is scaled to 100%
330 qreal rangeX = 3; // 3 values per set
329 qreal rangeX = 3; // 3 values per set
331 qreal scaleY = (height / rangeY);
330 qreal scaleY = (height / rangeY);
332 qreal scaleX = (width / rangeX);
331 qreal scaleX = (width / rangeX);
333
332
334 qreal setCount = series->count();
333 qreal setCount = series->count();
335 qreal domainMinY = 0; // These come from internal domain used by barseries.
334 qreal domainMinY = 0; // These come from internal domain used by barseries.
336 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
335 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
337 qreal rectWidth = scaleX * series->barWidth();
336 qreal rectWidth = scaleX * series->barWidth();
338
337
339 QVector<QRectF> layout;
338 QVector<QRectF> layout;
340
339
341 // 3 = count of values in set
340 // 3 = count of values in set
342 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
341 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
343 for (int i = 0; i < 3; i++) {
342 for (int i = 0; i < 3; i++) {
344 qreal colSum = 20; // Sum of values in column (10 + 10 in our test case)
343 qreal colSum = 20; // Sum of values in column (10 + 10 in our test case)
345 qreal percentage = (100 / colSum);
344 qreal percentage = (100 / colSum);
346 qreal yPos = height + scaleY * domainMinY + plotArea.top();
345 qreal yPos = height + scaleY * domainMinY + plotArea.top();
347
346
348 for (int set = 0; set < setCount; set++) {
347 for (int set = 0; set < setCount; set++) {
349 qreal xPos = (i - domainMinX) * scaleX + plotArea.left() - rectWidth/2;
348 qreal xPos = (i - domainMinX) * scaleX + plotArea.left() - rectWidth/2;
350 qreal rectHeight = barSets.at(set)->at(i) * percentage * scaleY;
349 qreal rectHeight = barSets.at(set)->at(i) * percentage * scaleY;
351
350
352 QRectF rect(xPos, yPos-rectHeight, rectWidth, rectHeight);
351 QRectF rect(xPos, yPos-rectHeight, rectWidth, rectHeight);
353 layout.append(rect);
352 layout.append(rect);
354 yPos -= rectHeight;
353 yPos -= rectHeight;
355 }
354 }
356 }
355 }
357
356
358 //=======================================================================
357 //=======================================================================
359 // move mouse to left border
358 // move mouse to left border
360 QTest::mouseMove(view.viewport(), QPoint(0, layout.at(0).center().y()));
359 QTest::mouseMove(view.viewport(), QPoint(0, layout.at(0).center().y()));
361 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
360 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
362 TRY_COMPARE(seriesSpy.count(), 0);
363 TRY_COMPARE(seriesIndexSpy.count(), 0);
361 TRY_COMPARE(seriesIndexSpy.count(), 0);
364
362
365 //=======================================================================
363 //=======================================================================
366 // move mouse on top of set1
364 // move mouse on top of set1
367 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
365 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
368 TRY_COMPARE(seriesSpy.count(), 1);
369 TRY_COMPARE(seriesIndexSpy.count(), 1);
366 TRY_COMPARE(seriesIndexSpy.count(), 1);
370 TRY_COMPARE(setIndexSpy1.count(), 1);
367 TRY_COMPARE(setIndexSpy1.count(), 1);
371 TRY_COMPARE(setIndexSpy2.count(), 0);
368 TRY_COMPARE(setIndexSpy2.count(), 0);
372
369
373 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
374 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
375 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
376 QVERIFY(seriesSpyArg.at(0).toBool() == true);
377
378 QList<QVariant> seriesIndexSpyArg = seriesIndexSpy.takeFirst();
370 QList<QVariant> seriesIndexSpyArg = seriesIndexSpy.takeFirst();
379 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
371 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
380 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
372 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
381 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
373 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
382
374
383 QList<QVariant> setIndexSpyArg = setIndexSpy1.takeFirst();
375 QList<QVariant> setIndexSpyArg = setIndexSpy1.takeFirst();
384 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
376 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
385 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
377 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
386
378
387 //=======================================================================
379 //=======================================================================
388 // move mouse from top of set1 to top of set2
380 // move mouse from top of set1 to top of set2
389 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
381 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
390 TRY_COMPARE(seriesSpy.count(), 2);
391 TRY_COMPARE(seriesIndexSpy.count(), 2);
382 TRY_COMPARE(seriesIndexSpy.count(), 2);
392 TRY_COMPARE(setIndexSpy1.count(), 1);
383 TRY_COMPARE(setIndexSpy1.count(), 1);
393 TRY_COMPARE(setIndexSpy2.count(), 1);
384 TRY_COMPARE(setIndexSpy2.count(), 1);
394
385
395 // should leave set1
386 // should leave set1
396 seriesSpyArg = seriesSpy.takeFirst();
397 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
398 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
399 QVERIFY(seriesSpyArg.at(0).toBool() == false);
400
401 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
387 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
402 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
388 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
403 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
389 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
404 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
390 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
405
391
406 setIndexSpyArg = setIndexSpy1.takeFirst();
392 setIndexSpyArg = setIndexSpy1.takeFirst();
407 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
393 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
408 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
394 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
409
395
410 // should enter set2
396 // should enter set2
411 seriesSpyArg = seriesSpy.takeFirst();
412 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
413 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
414 QVERIFY(seriesSpyArg.at(0).toBool() == true);
415
416 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
397 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
417 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
398 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
418 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
399 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
419 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
400 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
420
401
421 setIndexSpyArg = setIndexSpy2.takeFirst();
402 setIndexSpyArg = setIndexSpy2.takeFirst();
422 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
403 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
423 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
404 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
424
405
425 //=======================================================================
406 //=======================================================================
426 // move mouse from top of set2 to background
407 // move mouse from top of set2 to background
427 QTest::mouseMove(view.viewport(), QPoint(layout.at(1).center().x(), 0));
408 QTest::mouseMove(view.viewport(), QPoint(layout.at(1).center().x(), 0));
428 TRY_COMPARE(seriesSpy.count(), 1);
429 TRY_COMPARE(seriesIndexSpy.count(), 1);
409 TRY_COMPARE(seriesIndexSpy.count(), 1);
430 TRY_COMPARE(setIndexSpy1.count(), 0);
410 TRY_COMPARE(setIndexSpy1.count(), 0);
431 TRY_COMPARE(setIndexSpy2.count(), 1);
411 TRY_COMPARE(setIndexSpy2.count(), 1);
432
412
433 // should leave set2
413 // should leave set2
434 seriesSpyArg = seriesSpy.takeFirst();
435 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
436 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
437 QVERIFY(seriesSpyArg.at(0).toBool() == false);
438
439 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
414 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
440 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
415 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
441 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
416 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
442 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
417 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
443
418
444 setIndexSpyArg = setIndexSpy2.takeFirst();
419 setIndexSpyArg = setIndexSpy2.takeFirst();
445 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
420 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
446 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
421 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
447
422
448 //=======================================================================
423 //=======================================================================
449 // move mouse on top of set1, bar0 to check the index (hover into set1)
424 // move mouse on top of set1, bar0 to check the index (hover into set1)
450 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
425 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
451
426
452 TRY_COMPARE(seriesSpy.count(), 1);
453 TRY_COMPARE(seriesIndexSpy.count(), 1);
427 TRY_COMPARE(seriesIndexSpy.count(), 1);
454 TRY_COMPARE(setIndexSpy1.count(), 1);
428 TRY_COMPARE(setIndexSpy1.count(), 1);
455 TRY_COMPARE(setIndexSpy2.count(), 0);
429 TRY_COMPARE(setIndexSpy2.count(), 0);
456
430
457 //should enter set1, bar0
431 //should enter set1, bar0
458 seriesSpyArg = seriesSpy.takeFirst();
459 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
460 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
461 QVERIFY(seriesSpyArg.at(0).toBool() == true);
462
463 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
432 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
464 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
433 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
465 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
434 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
466 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
435 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
467 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
436 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
468 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
437 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
469
438
470 setIndexSpyArg = setIndexSpy1.takeFirst();
439 setIndexSpyArg = setIndexSpy1.takeFirst();
471 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
440 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
472 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
441 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
473 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
442 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
474 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
443 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
475
444
476 //=======================================================================
445 //=======================================================================
477 // move mouse on top of set2, bar0 to check the index (hover out set1,
446 // move mouse on top of set2, bar0 to check the index (hover out set1,
478 // hover in set2)
447 // hover in set2)
479 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
448 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
480
449
481 TRY_COMPARE(seriesSpy.count(), 2);
482 TRY_COMPARE(seriesIndexSpy.count(), 2);
450 TRY_COMPARE(seriesIndexSpy.count(), 2);
483 TRY_COMPARE(setIndexSpy1.count(), 1);
451 TRY_COMPARE(setIndexSpy1.count(), 1);
484 TRY_COMPARE(setIndexSpy2.count(), 1);
452 TRY_COMPARE(setIndexSpy2.count(), 1);
485
453
486 //should leave set1, bar0
454 //should leave set1, bar0
487 seriesSpyArg = seriesSpy.takeFirst();
488 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
489 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
490 QVERIFY(seriesSpyArg.at(0).toBool() == false);
491
492 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
455 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
493 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
456 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
494 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
457 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
495 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
458 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
496 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
459 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
497 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
460 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
498
461
499 setIndexSpyArg = setIndexSpy1.takeFirst();
462 setIndexSpyArg = setIndexSpy1.takeFirst();
500 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
463 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
501 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
464 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
502 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
465 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
503 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
466 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
504
467
505 //should enter set2, bar0
468 //should enter set2, bar0
506 seriesSpyArg = seriesSpy.takeFirst();
507 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
508 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
509 QVERIFY(seriesSpyArg.at(0).toBool() == true);
510
511 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
469 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
512 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
470 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
513 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
471 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
514 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
472 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
515 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
473 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
516 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
474 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
517
475
518 setIndexSpyArg = setIndexSpy2.takeFirst();
476 setIndexSpyArg = setIndexSpy2.takeFirst();
519 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
477 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
520 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
478 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
521 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
479 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
522 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
480 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
523
481
524 //=======================================================================
482 //=======================================================================
525 // move mouse on top of set1, bar1 to check the index (hover out set2,
483 // move mouse on top of set1, bar1 to check the index (hover out set2,
526 // hover in set1)
484 // hover in set1)
527 QTest::mouseMove(view.viewport(), layout.at(2).center().toPoint());
485 QTest::mouseMove(view.viewport(), layout.at(2).center().toPoint());
528
486
529 TRY_COMPARE(seriesSpy.count(), 2);
530 TRY_COMPARE(seriesIndexSpy.count(), 2);
487 TRY_COMPARE(seriesIndexSpy.count(), 2);
531 TRY_COMPARE(setIndexSpy1.count(), 1);
488 TRY_COMPARE(setIndexSpy1.count(), 1);
532 TRY_COMPARE(setIndexSpy2.count(), 1);
489 TRY_COMPARE(setIndexSpy2.count(), 1);
533
490
534 //should leave set2, bar0
491 //should leave set2, bar0
535 seriesSpyArg = seriesSpy.takeFirst();
536 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
537 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
538 QVERIFY(seriesSpyArg.at(0).toBool() == false);
539
540 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
492 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
541 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
493 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
542 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
494 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
543 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
495 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
544 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
496 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
545 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
497 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
546
498
547 setIndexSpyArg = setIndexSpy2.takeFirst();
499 setIndexSpyArg = setIndexSpy2.takeFirst();
548 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
500 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
549 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
501 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
550 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
502 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
551 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
503 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
552
504
553 //should enter set1, bar1
505 //should enter set1, bar1
554 seriesSpyArg = seriesSpy.takeFirst();
555 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
556 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
557 QVERIFY(seriesSpyArg.at(0).toBool() == true);
558
559 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
506 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
560 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
507 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
561 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
508 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
562 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
509 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
563 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
510 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
564 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
511 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
565
512
566 setIndexSpyArg = setIndexSpy1.takeFirst();
513 setIndexSpyArg = setIndexSpy1.takeFirst();
567 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
514 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
568 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
515 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
569 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
516 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
570 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
517 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
571
518
572 //=======================================================================
519 //=======================================================================
573 // move mouse between set1 and set2 (hover out set1)
520 // move mouse between set1 and set2 (hover out set1)
574 QTest::mouseMove(view.viewport(), QPoint((layout.at(3).right() + layout.at(4).left()) /2,
521 QTest::mouseMove(view.viewport(), QPoint((layout.at(3).right() + layout.at(4).left()) /2,
575 layout.at(2).top()));
522 layout.at(2).top()));
576
523
577 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
524 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
578 TRY_COMPARE(seriesSpy.count(), 1);
579 TRY_COMPARE(seriesIndexSpy.count(), 1);
525 TRY_COMPARE(seriesIndexSpy.count(), 1);
580 TRY_COMPARE(setIndexSpy1.count(), 1);
526 TRY_COMPARE(setIndexSpy1.count(), 1);
581 TRY_COMPARE(setIndexSpy2.count(), 0);
527 TRY_COMPARE(setIndexSpy2.count(), 0);
582
528
583 //should leave set1, bar1
529 //should leave set1, bar1
584 seriesSpyArg = seriesSpy.takeFirst();
585 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
586 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
587 QVERIFY(seriesSpyArg.at(0).toBool() == false);
588
589 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
530 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
590 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
531 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
591 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
532 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
592 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
533 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
593 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
534 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
594 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
535 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
595
536
596 setIndexSpyArg = setIndexSpy1.takeFirst();
537 setIndexSpyArg = setIndexSpy1.takeFirst();
597 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
538 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
598 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
539 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
599 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
540 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
600 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
541 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
601
542
602 //=======================================================================
543 //=======================================================================
603 // move mouse on top of set2, bar1 to check the index (hover in set2)
544 // move mouse on top of set2, bar1 to check the index (hover in set2)
604 QTest::mouseMove(view.viewport(), layout.at(3).center().toPoint());
545 QTest::mouseMove(view.viewport(), layout.at(3).center().toPoint());
605
546
606 TRY_COMPARE(seriesSpy.count(), 1);
607 TRY_COMPARE(seriesIndexSpy.count(), 1);
547 TRY_COMPARE(seriesIndexSpy.count(), 1);
608 TRY_COMPARE(setIndexSpy1.count(), 0);
548 TRY_COMPARE(setIndexSpy1.count(), 0);
609 TRY_COMPARE(setIndexSpy2.count(), 1);
549 TRY_COMPARE(setIndexSpy2.count(), 1);
610
550
611 //should enter set2, bar1
551 //should enter set2, bar1
612 seriesSpyArg = seriesSpy.takeFirst();
613 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
614 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
615 QVERIFY(seriesSpyArg.at(0).toBool() == true);
616
617 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
552 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
618 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
553 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
619 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
554 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
620 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
555 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
621 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
556 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
622 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
557 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
623
558
624 setIndexSpyArg = setIndexSpy2.takeFirst();
559 setIndexSpyArg = setIndexSpy2.takeFirst();
625 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
560 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
626 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
561 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
627 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
562 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
628 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
563 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
629
564
630 //=======================================================================
565 //=======================================================================
631 // move mouse between set1 and set2 (hover out set2)
566 // move mouse between set1 and set2 (hover out set2)
632 QTest::mouseMove(view.viewport(), QPoint((layout.at(3).right() + layout.at(4).left()) /2,
567 QTest::mouseMove(view.viewport(), QPoint((layout.at(3).right() + layout.at(4).left()) /2,
633 layout.at(2).top()));
568 layout.at(2).top()));
634
569
635 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
570 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
636 TRY_COMPARE(seriesSpy.count(), 1);
637 TRY_COMPARE(seriesIndexSpy.count(), 1);
571 TRY_COMPARE(seriesIndexSpy.count(), 1);
638 TRY_COMPARE(setIndexSpy1.count(), 0);
572 TRY_COMPARE(setIndexSpy1.count(), 0);
639 TRY_COMPARE(setIndexSpy2.count(), 1);
573 TRY_COMPARE(setIndexSpy2.count(), 1);
640
574
641 //should leave set1, bar1
575 //should leave set1, bar1
642 seriesSpyArg = seriesSpy.takeFirst();
643 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
644 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
645 QVERIFY(seriesSpyArg.at(0).toBool() == false);
646
647 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
576 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
648 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
577 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
649 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
578 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
650 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
579 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
651 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
580 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
652 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
581 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
653
582
654 setIndexSpyArg = setIndexSpy2.takeFirst();
583 setIndexSpyArg = setIndexSpy2.takeFirst();
655 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
584 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
656 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
585 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
657 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
586 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
658 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
587 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
659 }
588 }
660
589
661 void tst_QPercentBarSeries::zeroValuesInSeries()
590 void tst_QPercentBarSeries::zeroValuesInSeries()
662 {
591 {
663 QPercentBarSeries *series = new QPercentBarSeries();
592 QPercentBarSeries *series = new QPercentBarSeries();
664 QBarSet *set1 = new QBarSet(QString("set 1"));
593 QBarSet *set1 = new QBarSet(QString("set 1"));
665 *set1 << 100 << 0.0 << 10;
594 *set1 << 100 << 0.0 << 10;
666 series->append(set1);
595 series->append(set1);
667
596
668 QBarSet *set2 = new QBarSet(QString("set 2"));
597 QBarSet *set2 = new QBarSet(QString("set 2"));
669 *set2 << 0.0 << 0.0 << 70;
598 *set2 << 0.0 << 0.0 << 70;
670 series->append(set2);
599 series->append(set2);
671
600
672 QChartView view(new QChart());
601 QChartView view(new QChart());
673 view.chart()->addSeries(series);
602 view.chart()->addSeries(series);
674 view.chart()->createDefaultAxes();
603 view.chart()->createDefaultAxes();
675 view.show();
604 view.show();
676
605
677 QTest::qWaitForWindowShown(&view);
606 QTest::qWaitForWindowShown(&view);
678 }
607 }
679
608
680 QTEST_MAIN(tst_QPercentBarSeries)
609 QTEST_MAIN(tst_QPercentBarSeries)
681
610
682 #include "tst_qpercentbarseries.moc"
611 #include "tst_qpercentbarseries.moc"
683
612
@@ -1,670 +1,599
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 <QtCharts/QStackedBarSeries>
22 #include <QtCharts/QStackedBarSeries>
23 #include <QtCharts/QBarSet>
23 #include <QtCharts/QBarSet>
24 #include <QtCharts/QChartView>
24 #include <QtCharts/QChartView>
25 #include <QtCharts/QChart>
25 #include <QtCharts/QChart>
26 #include "tst_definitions.h"
26 #include "tst_definitions.h"
27
27
28 QT_CHARTS_USE_NAMESPACE
28 QT_CHARTS_USE_NAMESPACE
29
29
30 Q_DECLARE_METATYPE(QBarSet*)
30 Q_DECLARE_METATYPE(QBarSet*)
31 Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition)
31 Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition)
32
32
33 class tst_QStackedBarSeries : public QObject
33 class tst_QStackedBarSeries : public QObject
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36
36
37 public slots:
37 public slots:
38 void initTestCase();
38 void initTestCase();
39 void cleanupTestCase();
39 void cleanupTestCase();
40 void init();
40 void init();
41 void cleanup();
41 void cleanup();
42
42
43 private slots:
43 private slots:
44 void qstackedbarseries_data();
44 void qstackedbarseries_data();
45 void qstackedbarseries();
45 void qstackedbarseries();
46 void type_data();
46 void type_data();
47 void type();
47 void type();
48 void setLabelsFormat();
48 void setLabelsFormat();
49 void setLabelsPosition();
49 void setLabelsPosition();
50 void mouseclicked_data();
50 void mouseclicked_data();
51 void mouseclicked();
51 void mouseclicked();
52 void mousehovered_data();
52 void mousehovered_data();
53 void mousehovered();
53 void mousehovered();
54
54
55 private:
55 private:
56 QStackedBarSeries* m_barseries;
56 QStackedBarSeries* m_barseries;
57 };
57 };
58
58
59 void tst_QStackedBarSeries::initTestCase()
59 void tst_QStackedBarSeries::initTestCase()
60 {
60 {
61 qRegisterMetaType<QBarSet*>("QBarSet*");
61 qRegisterMetaType<QBarSet*>("QBarSet*");
62 qRegisterMetaType<QAbstractBarSeries::LabelsPosition>("QAbstractBarSeries::LabelsPosition");
62 qRegisterMetaType<QAbstractBarSeries::LabelsPosition>("QAbstractBarSeries::LabelsPosition");
63 }
63 }
64
64
65 void tst_QStackedBarSeries::cleanupTestCase()
65 void tst_QStackedBarSeries::cleanupTestCase()
66 {
66 {
67 }
67 }
68
68
69 void tst_QStackedBarSeries::init()
69 void tst_QStackedBarSeries::init()
70 {
70 {
71 m_barseries = new QStackedBarSeries();
71 m_barseries = new QStackedBarSeries();
72 }
72 }
73
73
74 void tst_QStackedBarSeries::cleanup()
74 void tst_QStackedBarSeries::cleanup()
75 {
75 {
76 delete m_barseries;
76 delete m_barseries;
77 m_barseries = 0;
77 m_barseries = 0;
78 }
78 }
79
79
80 void tst_QStackedBarSeries::qstackedbarseries_data()
80 void tst_QStackedBarSeries::qstackedbarseries_data()
81 {
81 {
82 }
82 }
83
83
84 void tst_QStackedBarSeries::qstackedbarseries()
84 void tst_QStackedBarSeries::qstackedbarseries()
85 {
85 {
86 QStackedBarSeries *barseries = new QStackedBarSeries();
86 QStackedBarSeries *barseries = new QStackedBarSeries();
87 QVERIFY(barseries != 0);
87 QVERIFY(barseries != 0);
88 }
88 }
89
89
90 void tst_QStackedBarSeries::type_data()
90 void tst_QStackedBarSeries::type_data()
91 {
91 {
92
92
93 }
93 }
94
94
95 void tst_QStackedBarSeries::type()
95 void tst_QStackedBarSeries::type()
96 {
96 {
97 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeStackedBar);
97 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeStackedBar);
98 }
98 }
99
99
100 void tst_QStackedBarSeries::setLabelsFormat()
100 void tst_QStackedBarSeries::setLabelsFormat()
101 {
101 {
102 QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString)));
102 QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString)));
103 QCOMPARE(m_barseries->labelsFormat(), QString());
103 QCOMPARE(m_barseries->labelsFormat(), QString());
104
104
105 QString format("(@value)");
105 QString format("(@value)");
106 m_barseries->setLabelsFormat(format);
106 m_barseries->setLabelsFormat(format);
107 TRY_COMPARE(labelsFormatSpy.count(), 1);
107 TRY_COMPARE(labelsFormatSpy.count(), 1);
108 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
108 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
109 QVERIFY(arguments.at(0).toString() == format);
109 QVERIFY(arguments.at(0).toString() == format);
110 QCOMPARE(m_barseries->labelsFormat(), format);
110 QCOMPARE(m_barseries->labelsFormat(), format);
111
111
112 m_barseries->setLabelsFormat(QString());
112 m_barseries->setLabelsFormat(QString());
113 TRY_COMPARE(labelsFormatSpy.count(), 1);
113 TRY_COMPARE(labelsFormatSpy.count(), 1);
114 arguments = labelsFormatSpy.takeFirst();
114 arguments = labelsFormatSpy.takeFirst();
115 QVERIFY(arguments.at(0).toString() == QString());
115 QVERIFY(arguments.at(0).toString() == QString());
116 QCOMPARE(m_barseries->labelsFormat(), QString());
116 QCOMPARE(m_barseries->labelsFormat(), QString());
117 }
117 }
118
118
119 void tst_QStackedBarSeries::setLabelsPosition()
119 void tst_QStackedBarSeries::setLabelsPosition()
120 {
120 {
121 QSignalSpy labelsPositionSpy(m_barseries,
121 QSignalSpy labelsPositionSpy(m_barseries,
122 SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)));
122 SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)));
123 QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsCenter);
123 QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsCenter);
124
124
125 m_barseries->setLabelsPosition(QStackedBarSeries::LabelsInsideEnd);
125 m_barseries->setLabelsPosition(QStackedBarSeries::LabelsInsideEnd);
126 TRY_COMPARE(labelsPositionSpy.count(), 1);
126 TRY_COMPARE(labelsPositionSpy.count(), 1);
127 QList<QVariant> arguments = labelsPositionSpy.takeFirst();
127 QList<QVariant> arguments = labelsPositionSpy.takeFirst();
128 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
128 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
129 == QStackedBarSeries::LabelsInsideEnd);
129 == QStackedBarSeries::LabelsInsideEnd);
130 QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsInsideEnd);
130 QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsInsideEnd);
131
131
132 m_barseries->setLabelsPosition(QStackedBarSeries::LabelsInsideBase);
132 m_barseries->setLabelsPosition(QStackedBarSeries::LabelsInsideBase);
133 TRY_COMPARE(labelsPositionSpy.count(), 1);
133 TRY_COMPARE(labelsPositionSpy.count(), 1);
134 arguments = labelsPositionSpy.takeFirst();
134 arguments = labelsPositionSpy.takeFirst();
135 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
135 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
136 == QStackedBarSeries::LabelsInsideBase);
136 == QStackedBarSeries::LabelsInsideBase);
137 QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsInsideBase);
137 QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsInsideBase);
138
138
139 m_barseries->setLabelsPosition(QStackedBarSeries::LabelsOutsideEnd);
139 m_barseries->setLabelsPosition(QStackedBarSeries::LabelsOutsideEnd);
140 TRY_COMPARE(labelsPositionSpy.count(), 1);
140 TRY_COMPARE(labelsPositionSpy.count(), 1);
141 arguments = labelsPositionSpy.takeFirst();
141 arguments = labelsPositionSpy.takeFirst();
142 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
142 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
143 == QStackedBarSeries::LabelsOutsideEnd);
143 == QStackedBarSeries::LabelsOutsideEnd);
144 QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsOutsideEnd);
144 QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsOutsideEnd);
145
145
146 m_barseries->setLabelsPosition(QStackedBarSeries::LabelsCenter);
146 m_barseries->setLabelsPosition(QStackedBarSeries::LabelsCenter);
147 TRY_COMPARE(labelsPositionSpy.count(), 1);
147 TRY_COMPARE(labelsPositionSpy.count(), 1);
148 arguments = labelsPositionSpy.takeFirst();
148 arguments = labelsPositionSpy.takeFirst();
149 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
149 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
150 == QStackedBarSeries::LabelsCenter);
150 == QStackedBarSeries::LabelsCenter);
151 QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsCenter);
151 QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsCenter);
152 }
152 }
153
153
154 void tst_QStackedBarSeries::mouseclicked_data()
154 void tst_QStackedBarSeries::mouseclicked_data()
155 {
155 {
156
156
157 }
157 }
158
158
159 void tst_QStackedBarSeries::mouseclicked()
159 void tst_QStackedBarSeries::mouseclicked()
160 {
160 {
161 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
161 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
162
162
163 QStackedBarSeries* series = new QStackedBarSeries();
163 QStackedBarSeries* series = new QStackedBarSeries();
164
164
165 QBarSet* set1 = new QBarSet(QString("set 1"));
165 QBarSet* set1 = new QBarSet(QString("set 1"));
166 *set1 << 10 << 10 << 10;
166 *set1 << 10 << 10 << 10;
167 series->append(set1);
167 series->append(set1);
168
168
169 QBarSet* set2 = new QBarSet(QString("set 2"));
169 QBarSet* set2 = new QBarSet(QString("set 2"));
170 *set2 << 10 << 10 << 10;
170 *set2 << 10 << 10 << 10;
171 series->append(set2);
171 series->append(set2);
172
172
173 QList<QBarSet*> barSets = series->barSets();
173 QList<QBarSet*> barSets = series->barSets();
174
174
175 QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*)));
175 QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*)));
176
176
177 QChartView view(new QChart());
177 QChartView view(new QChart());
178 view.resize(400,300);
178 view.resize(400,300);
179 view.chart()->addSeries(series);
179 view.chart()->addSeries(series);
180 view.show();
180 view.show();
181 QTest::qWaitForWindowShown(&view);
181 QTest::qWaitForWindowShown(&view);
182
182
183 // Calculate expected layout for bars
183 // Calculate expected layout for bars
184 QRectF plotArea = view.chart()->plotArea();
184 QRectF plotArea = view.chart()->plotArea();
185 qreal width = plotArea.width();
185 qreal width = plotArea.width();
186 qreal height = plotArea.height();
186 qreal height = plotArea.height();
187 qreal rangeY = 20; // From 0 to 20 because sets are stacked (this should be height of highest stack)
187 qreal rangeY = 20; // From 0 to 20 because sets are stacked (this should be height of highest stack)
188 qreal rangeX = 3; // 3 values per set
188 qreal rangeX = 3; // 3 values per set
189 qreal scaleY = (height / rangeY);
189 qreal scaleY = (height / rangeY);
190 qreal scaleX = (width / rangeX);
190 qreal scaleX = (width / rangeX);
191
191
192 qreal setCount = series->count();
192 qreal setCount = series->count();
193 qreal domainMinY = 0; // These come from internal domain used by barseries.
193 qreal domainMinY = 0; // These come from internal domain used by barseries.
194 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
194 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
195 qreal rectWidth = scaleX * series->barWidth();
195 qreal rectWidth = scaleX * series->barWidth();
196
196
197 QVector<QRectF> layout;
197 QVector<QRectF> layout;
198
198
199 // 3 = count of values in set
199 // 3 = count of values in set
200 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
200 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
201 for (int i = 0; i < 3; i++) {
201 for (int i = 0; i < 3; i++) {
202 qreal yMax = height + scaleY * domainMinY + plotArea.top();
202 qreal yMax = height + scaleY * domainMinY + plotArea.top();
203 qreal yMin = height + scaleY * domainMinY + plotArea.top();
203 qreal yMin = height + scaleY * domainMinY + plotArea.top();
204 for (int set = 0; set < setCount; set++) {
204 for (int set = 0; set < setCount; set++) {
205 qreal xPos = (i - domainMinX) * scaleX + plotArea.left() - rectWidth/2;
205 qreal xPos = (i - domainMinX) * scaleX + plotArea.left() - rectWidth/2;
206 qreal rectHeight = barSets.at(set)->at(i) * scaleY;
206 qreal rectHeight = barSets.at(set)->at(i) * scaleY;
207 if (rectHeight < 0) {
207 if (rectHeight < 0) {
208 QRectF rect(xPos, yMax-rectHeight, rectWidth, rectHeight);
208 QRectF rect(xPos, yMax-rectHeight, rectWidth, rectHeight);
209 layout.append(rect);
209 layout.append(rect);
210 yMax -= rectHeight;
210 yMax -= rectHeight;
211 } else {
211 } else {
212 QRectF rect(xPos, yMin-rectHeight, rectWidth, rectHeight);
212 QRectF rect(xPos, yMin-rectHeight, rectWidth, rectHeight);
213 layout.append(rect);
213 layout.append(rect);
214 yMin -= rectHeight;
214 yMin -= rectHeight;
215 }
215 }
216 }
216 }
217 }
217 }
218
218
219 //====================================================================================
219 //====================================================================================
220 // barset 1, bar 0
220 // barset 1, bar 0
221 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
221 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
222 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
222 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
223
223
224 QCOMPARE(seriesSpy.count(), 1);
224 QCOMPARE(seriesSpy.count(), 1);
225
225
226 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
226 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
227 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
227 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
228 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
228 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
229 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
229 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
230
230
231 //====================================================================================
231 //====================================================================================
232 // barset 1, bar 1
232 // barset 1, bar 1
233 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
233 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
234 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
234 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
235
235
236 QCOMPARE(seriesSpy.count(), 1);
236 QCOMPARE(seriesSpy.count(), 1);
237
237
238 seriesSpyArg = seriesSpy.takeFirst();
238 seriesSpyArg = seriesSpy.takeFirst();
239 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
239 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
240 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
240 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
241 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
241 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
242
242
243 //====================================================================================
243 //====================================================================================
244 // barset 1, bar 2
244 // barset 1, bar 2
245 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
245 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
246 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
246 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
247
247
248 QCOMPARE(seriesSpy.count(), 1);
248 QCOMPARE(seriesSpy.count(), 1);
249
249
250 seriesSpyArg = seriesSpy.takeFirst();
250 seriesSpyArg = seriesSpy.takeFirst();
251 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
251 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
252 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
252 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
253 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
253 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
254
254
255 //====================================================================================
255 //====================================================================================
256 // barset 2, bar 0
256 // barset 2, bar 0
257 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
257 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
258 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
258 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
259
259
260 QCOMPARE(seriesSpy.count(), 1);
260 QCOMPARE(seriesSpy.count(), 1);
261
261
262 seriesSpyArg = seriesSpy.takeFirst();
262 seriesSpyArg = seriesSpy.takeFirst();
263 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
263 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
264 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
264 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
265 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
265 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
266
266
267 //====================================================================================
267 //====================================================================================
268 // barset 2, bar 1
268 // barset 2, bar 1
269 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
269 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
270 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
270 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
271
271
272 QCOMPARE(seriesSpy.count(), 1);
272 QCOMPARE(seriesSpy.count(), 1);
273
273
274 seriesSpyArg = seriesSpy.takeFirst();
274 seriesSpyArg = seriesSpy.takeFirst();
275 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
275 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
276 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
276 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
277 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
277 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
278
278
279 //====================================================================================
279 //====================================================================================
280 // barset 2, bar 2
280 // barset 2, bar 2
281 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
281 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
282 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
282 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
283
283
284 QCOMPARE(seriesSpy.count(), 1);
284 QCOMPARE(seriesSpy.count(), 1);
285
285
286 seriesSpyArg = seriesSpy.takeFirst();
286 seriesSpyArg = seriesSpy.takeFirst();
287 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
287 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
288 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
288 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
289 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
289 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
290 }
290 }
291
291
292 void tst_QStackedBarSeries::mousehovered_data()
292 void tst_QStackedBarSeries::mousehovered_data()
293 {
293 {
294
294
295 }
295 }
296
296
297 void tst_QStackedBarSeries::mousehovered()
297 void tst_QStackedBarSeries::mousehovered()
298 {
298 {
299 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
299 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
300
300
301 QStackedBarSeries* series = new QStackedBarSeries();
301 QStackedBarSeries* series = new QStackedBarSeries();
302
302
303 QBarSet* set1 = new QBarSet(QString("set 1"));
303 QBarSet* set1 = new QBarSet(QString("set 1"));
304 *set1 << 10 << 10 << 10;
304 *set1 << 10 << 10 << 10;
305 series->append(set1);
305 series->append(set1);
306
306
307 QBarSet* set2 = new QBarSet(QString("set 2"));
307 QBarSet* set2 = new QBarSet(QString("set 2"));
308 *set2 << 10 << 10 << 10;
308 *set2 << 10 << 10 << 10;
309 series->append(set2);
309 series->append(set2);
310
310
311 QList<QBarSet*> barSets = series->barSets();
311 QList<QBarSet*> barSets = series->barSets();
312
312
313 QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*)));
314 QSignalSpy seriesIndexSpy(series, SIGNAL(hovered(bool, int, QBarSet*)));
313 QSignalSpy seriesIndexSpy(series, SIGNAL(hovered(bool, int, QBarSet*)));
315 QSignalSpy setIndexSpy1(set1, SIGNAL(hovered(bool, int)));
314 QSignalSpy setIndexSpy1(set1, SIGNAL(hovered(bool, int)));
316 QSignalSpy setIndexSpy2(set2, SIGNAL(hovered(bool, int)));
315 QSignalSpy setIndexSpy2(set2, SIGNAL(hovered(bool, int)));
317
316
318 QChartView view(new QChart());
317 QChartView view(new QChart());
319 view.resize(400,300);
318 view.resize(400,300);
320 view.chart()->addSeries(series);
319 view.chart()->addSeries(series);
321 view.show();
320 view.show();
322 QTest::qWaitForWindowShown(&view);
321 QTest::qWaitForWindowShown(&view);
323
322
324 //this is hack since view does not get events otherwise
323 //this is hack since view does not get events otherwise
325 view.setMouseTracking(true);
324 view.setMouseTracking(true);
326
325
327 // Calculate expected layout for bars
326 // Calculate expected layout for bars
328 QRectF plotArea = view.chart()->plotArea();
327 QRectF plotArea = view.chart()->plotArea();
329 qreal width = plotArea.width();
328 qreal width = plotArea.width();
330 qreal height = plotArea.height();
329 qreal height = plotArea.height();
331 qreal rangeY = 20; // From 0 to 20 because sets are stacked (this should be height of highest stack)
330 qreal rangeY = 20; // From 0 to 20 because sets are stacked (this should be height of highest stack)
332 qreal rangeX = 3; // 3 values per set
331 qreal rangeX = 3; // 3 values per set
333 qreal scaleY = (height / rangeY);
332 qreal scaleY = (height / rangeY);
334 qreal scaleX = (width / rangeX);
333 qreal scaleX = (width / rangeX);
335
334
336 qreal setCount = series->count();
335 qreal setCount = series->count();
337 qreal domainMinY = 0; // These come from internal domain used by barseries.
336 qreal domainMinY = 0; // These come from internal domain used by barseries.
338 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
337 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
339 qreal rectWidth = scaleX * series->barWidth();
338 qreal rectWidth = scaleX * series->barWidth();
340
339
341 QVector<QRectF> layout;
340 QVector<QRectF> layout;
342
341
343 // 3 = count of values in set
342 // 3 = count of values in set
344 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
343 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
345 for (int i = 0; i < 3; i++) {
344 for (int i = 0; i < 3; i++) {
346 qreal yMax = height + scaleY * domainMinY + plotArea.top();
345 qreal yMax = height + scaleY * domainMinY + plotArea.top();
347 qreal yMin = height + scaleY * domainMinY + plotArea.top();
346 qreal yMin = height + scaleY * domainMinY + plotArea.top();
348 for (int set = 0; set < setCount; set++) {
347 for (int set = 0; set < setCount; set++) {
349 qreal xPos = (i - domainMinX) * scaleX + plotArea.left() - rectWidth/2;
348 qreal xPos = (i - domainMinX) * scaleX + plotArea.left() - rectWidth/2;
350 qreal rectHeight = barSets.at(set)->at(i) * scaleY;
349 qreal rectHeight = barSets.at(set)->at(i) * scaleY;
351
350
352 if (rectHeight < 0) {
351 if (rectHeight < 0) {
353 QRectF rect(xPos, yMax-rectHeight, rectWidth, rectHeight);
352 QRectF rect(xPos, yMax-rectHeight, rectWidth, rectHeight);
354 layout.append(rect);
353 layout.append(rect);
355 yMax -= rectHeight;
354 yMax -= rectHeight;
356 } else {
355 } else {
357 QRectF rect(xPos, yMin-rectHeight, rectWidth, rectHeight);
356 QRectF rect(xPos, yMin-rectHeight, rectWidth, rectHeight);
358 layout.append(rect);
357 layout.append(rect);
359 yMin -= rectHeight;
358 yMin -= rectHeight;
360 }
359 }
361 }
360 }
362 }
361 }
363
362
364 //=======================================================================
363 //=======================================================================
365 // move mouse to left border
364 // move mouse to left border
366 QTest::mouseMove(view.viewport(), QPoint(0, layout.at(0).center().y()));
365 QTest::mouseMove(view.viewport(), QPoint(0, layout.at(0).center().y()));
367 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
366 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
368 TRY_COMPARE(seriesSpy.count(), 0);
369 TRY_COMPARE(seriesIndexSpy.count(), 0);
367 TRY_COMPARE(seriesIndexSpy.count(), 0);
370
368
371 //=======================================================================
369 //=======================================================================
372 // move mouse on top of set1
370 // move mouse on top of set1
373 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
371 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
374 TRY_COMPARE(seriesSpy.count(), 1);
375 TRY_COMPARE(seriesIndexSpy.count(), 1);
372 TRY_COMPARE(seriesIndexSpy.count(), 1);
376 TRY_COMPARE(setIndexSpy1.count(), 1);
373 TRY_COMPARE(setIndexSpy1.count(), 1);
377 TRY_COMPARE(setIndexSpy2.count(), 0);
374 TRY_COMPARE(setIndexSpy2.count(), 0);
378
375
379 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
380 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
381 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
382 QVERIFY(seriesSpyArg.at(0).toBool() == true);
383
384 QList<QVariant> seriesIndexSpyArg = seriesIndexSpy.takeFirst();
376 QList<QVariant> seriesIndexSpyArg = seriesIndexSpy.takeFirst();
385 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
377 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
386 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
378 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
387 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
379 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
388
380
389 QList<QVariant> setIndexSpyArg = setIndexSpy1.takeFirst();
381 QList<QVariant> setIndexSpyArg = setIndexSpy1.takeFirst();
390 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
382 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
391 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
383 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
392
384
393 //=======================================================================
385 //=======================================================================
394 // move mouse from top of set1 to top of set2
386 // move mouse from top of set1 to top of set2
395 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
387 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
396 TRY_COMPARE(seriesSpy.count(), 2);
397 TRY_COMPARE(seriesIndexSpy.count(), 2);
388 TRY_COMPARE(seriesIndexSpy.count(), 2);
398 TRY_COMPARE(setIndexSpy1.count(), 1);
389 TRY_COMPARE(setIndexSpy1.count(), 1);
399 TRY_COMPARE(setIndexSpy2.count(), 1);
390 TRY_COMPARE(setIndexSpy2.count(), 1);
400
391
401 // should leave set1
392 // should leave set1
402 seriesSpyArg = seriesSpy.takeFirst();
403 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
404 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
405 QVERIFY(seriesSpyArg.at(0).toBool() == false);
406
407 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
393 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
408 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
394 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
409 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
395 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
410 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
396 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
411
397
412 setIndexSpyArg = setIndexSpy1.takeFirst();
398 setIndexSpyArg = setIndexSpy1.takeFirst();
413 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
399 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
414 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
400 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
415
401
416 // should enter set2
402 // should enter set2
417 seriesSpyArg = seriesSpy.takeFirst();
418 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
419 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
420 QVERIFY(seriesSpyArg.at(0).toBool() == true);
421
422 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
403 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
423 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
404 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
424 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
405 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
425 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
406 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
426
407
427 setIndexSpyArg = setIndexSpy2.takeFirst();
408 setIndexSpyArg = setIndexSpy2.takeFirst();
428 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
409 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
429 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
410 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
430
411
431 //=======================================================================
412 //=======================================================================
432 // move mouse from top of set2 to background
413 // move mouse from top of set2 to background
433 QTest::mouseMove(view.viewport(), QPoint(layout.at(1).center().x(), 0));
414 QTest::mouseMove(view.viewport(), QPoint(layout.at(1).center().x(), 0));
434 TRY_COMPARE(seriesSpy.count(), 1);
435 TRY_COMPARE(seriesIndexSpy.count(), 1);
415 TRY_COMPARE(seriesIndexSpy.count(), 1);
436 TRY_COMPARE(setIndexSpy1.count(), 0);
416 TRY_COMPARE(setIndexSpy1.count(), 0);
437 TRY_COMPARE(setIndexSpy2.count(), 1);
417 TRY_COMPARE(setIndexSpy2.count(), 1);
438
418
439 // should leave set2
419 // should leave set2
440 seriesSpyArg = seriesSpy.takeFirst();
441 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
442 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
443 QVERIFY(seriesSpyArg.at(0).toBool() == false);
444
445 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
420 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
446 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
421 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
447 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
422 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
448 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
423 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
449
424
450 setIndexSpyArg = setIndexSpy2.takeFirst();
425 setIndexSpyArg = setIndexSpy2.takeFirst();
451 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
426 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
452 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
427 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
453
428
454 //=======================================================================
429 //=======================================================================
455 // move mouse on top of set1, bar0 to check the index (hover into set1)
430 // move mouse on top of set1, bar0 to check the index (hover into set1)
456 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
431 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
457
432
458 TRY_COMPARE(seriesSpy.count(), 1);
459 TRY_COMPARE(seriesIndexSpy.count(), 1);
433 TRY_COMPARE(seriesIndexSpy.count(), 1);
460 TRY_COMPARE(setIndexSpy1.count(), 1);
434 TRY_COMPARE(setIndexSpy1.count(), 1);
461 TRY_COMPARE(setIndexSpy2.count(), 0);
435 TRY_COMPARE(setIndexSpy2.count(), 0);
462
436
463 //should enter set1, bar0
437 //should enter set1, bar0
464 seriesSpyArg = seriesSpy.takeFirst();
465 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
466 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
467 QVERIFY(seriesSpyArg.at(0).toBool() == true);
468
469 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
438 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
470 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
439 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
471 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
440 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
472 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
441 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
473 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
442 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
474 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
443 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
475
444
476 setIndexSpyArg = setIndexSpy1.takeFirst();
445 setIndexSpyArg = setIndexSpy1.takeFirst();
477 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
446 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
478 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
447 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
479 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
448 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
480 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
449 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
481
450
482 //=======================================================================
451 //=======================================================================
483 // move mouse on top of set2, bar0 to check the index (hover out set1,
452 // move mouse on top of set2, bar0 to check the index (hover out set1,
484 // hover in set2)
453 // hover in set2)
485 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
454 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
486
455
487 TRY_COMPARE(seriesSpy.count(), 2);
488 TRY_COMPARE(seriesIndexSpy.count(), 2);
456 TRY_COMPARE(seriesIndexSpy.count(), 2);
489 TRY_COMPARE(setIndexSpy1.count(), 1);
457 TRY_COMPARE(setIndexSpy1.count(), 1);
490 TRY_COMPARE(setIndexSpy2.count(), 1);
458 TRY_COMPARE(setIndexSpy2.count(), 1);
491
459
492 //should leave set1, bar0
460 //should leave set1, bar0
493 seriesSpyArg = seriesSpy.takeFirst();
494 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
495 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
496 QVERIFY(seriesSpyArg.at(0).toBool() == false);
497
498 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
461 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
499 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
462 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
500 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
463 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
501 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
464 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
502 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
465 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
503 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
466 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
504
467
505 setIndexSpyArg = setIndexSpy1.takeFirst();
468 setIndexSpyArg = setIndexSpy1.takeFirst();
506 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
469 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
507 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
470 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
508 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
471 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
509 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
472 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
510
473
511 //should enter set2, bar0
474 //should enter set2, bar0
512 seriesSpyArg = seriesSpy.takeFirst();
513 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
514 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
515 QVERIFY(seriesSpyArg.at(0).toBool() == true);
516
517 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
475 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
518 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
476 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
519 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
477 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
520 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
478 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
521 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
479 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
522 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
480 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
523
481
524 setIndexSpyArg = setIndexSpy2.takeFirst();
482 setIndexSpyArg = setIndexSpy2.takeFirst();
525 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
483 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
526 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
484 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
527 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
485 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
528 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
486 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
529
487
530 //=======================================================================
488 //=======================================================================
531 // move mouse on top of set1, bar1 to check the index (hover out set2,
489 // move mouse on top of set1, bar1 to check the index (hover out set2,
532 // hover in set1)
490 // hover in set1)
533 QTest::mouseMove(view.viewport(), layout.at(2).center().toPoint());
491 QTest::mouseMove(view.viewport(), layout.at(2).center().toPoint());
534
492
535 TRY_COMPARE(seriesSpy.count(), 2);
536 TRY_COMPARE(seriesIndexSpy.count(), 2);
493 TRY_COMPARE(seriesIndexSpy.count(), 2);
537 TRY_COMPARE(setIndexSpy1.count(), 1);
494 TRY_COMPARE(setIndexSpy1.count(), 1);
538 TRY_COMPARE(setIndexSpy2.count(), 1);
495 TRY_COMPARE(setIndexSpy2.count(), 1);
539
496
540 //should leave set2, bar0
497 //should leave set2, bar0
541 seriesSpyArg = seriesSpy.takeFirst();
542 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
543 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
544 QVERIFY(seriesSpyArg.at(0).toBool() == false);
545
546 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
498 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
547 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
499 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
548 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
500 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
549 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
501 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
550 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
502 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
551 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
503 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0);
552
504
553 setIndexSpyArg = setIndexSpy2.takeFirst();
505 setIndexSpyArg = setIndexSpy2.takeFirst();
554 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
506 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
555 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
507 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
556 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
508 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
557 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
509 QVERIFY(setIndexSpyArg.at(1).toInt() == 0);
558
510
559 //should enter set1, bar1
511 //should enter set1, bar1
560 seriesSpyArg = seriesSpy.takeFirst();
561 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
562 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
563 QVERIFY(seriesSpyArg.at(0).toBool() == true);
564
565 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
512 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
566 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
513 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
567 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
514 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
568 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
515 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
569 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
516 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
570 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
517 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
571
518
572 setIndexSpyArg = setIndexSpy1.takeFirst();
519 setIndexSpyArg = setIndexSpy1.takeFirst();
573 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
520 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
574 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
521 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
575 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
522 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
576 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
523 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
577
524
578 //=======================================================================
525 //=======================================================================
579 // move mouse between set1 and set2 (hover out set1)
526 // move mouse between set1 and set2 (hover out set1)
580 QTest::mouseMove(view.viewport(), QPoint((layout.at(3).right() + layout.at(4).left()) /2,
527 QTest::mouseMove(view.viewport(), QPoint((layout.at(3).right() + layout.at(4).left()) /2,
581 layout.at(2).top()));
528 layout.at(2).top()));
582
529
583 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
530 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
584 TRY_COMPARE(seriesSpy.count(), 1);
585 TRY_COMPARE(seriesIndexSpy.count(), 1);
531 TRY_COMPARE(seriesIndexSpy.count(), 1);
586 TRY_COMPARE(setIndexSpy1.count(), 1);
532 TRY_COMPARE(setIndexSpy1.count(), 1);
587 TRY_COMPARE(setIndexSpy2.count(), 0);
533 TRY_COMPARE(setIndexSpy2.count(), 0);
588
534
589 //should leave set1, bar1
535 //should leave set1, bar1
590 seriesSpyArg = seriesSpy.takeFirst();
591 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
592 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
593 QVERIFY(seriesSpyArg.at(0).toBool() == false);
594
595 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
536 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
596 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
537 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1);
597 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
538 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
598 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
539 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
599 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
540 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
600 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
541 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
601
542
602 setIndexSpyArg = setIndexSpy1.takeFirst();
543 setIndexSpyArg = setIndexSpy1.takeFirst();
603 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
544 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
604 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
545 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
605 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
546 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
606 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
547 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
607
548
608 //=======================================================================
549 //=======================================================================
609 // move mouse on top of set2, bar1 to check the index (hover in set2)
550 // move mouse on top of set2, bar1 to check the index (hover in set2)
610 QTest::mouseMove(view.viewport(), layout.at(3).center().toPoint());
551 QTest::mouseMove(view.viewport(), layout.at(3).center().toPoint());
611
552
612 TRY_COMPARE(seriesSpy.count(), 1);
613 TRY_COMPARE(seriesIndexSpy.count(), 1);
553 TRY_COMPARE(seriesIndexSpy.count(), 1);
614 TRY_COMPARE(setIndexSpy1.count(), 0);
554 TRY_COMPARE(setIndexSpy1.count(), 0);
615 TRY_COMPARE(setIndexSpy2.count(), 1);
555 TRY_COMPARE(setIndexSpy2.count(), 1);
616
556
617 //should enter set2, bar1
557 //should enter set2, bar1
618 seriesSpyArg = seriesSpy.takeFirst();
619 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
620 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
621 QVERIFY(seriesSpyArg.at(0).toBool() == true);
622
623 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
558 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
624 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
559 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
625 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
560 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
626 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
561 QVERIFY(seriesIndexSpyArg.at(0).toBool() == true);
627 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
562 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
628 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
563 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
629
564
630 setIndexSpyArg = setIndexSpy2.takeFirst();
565 setIndexSpyArg = setIndexSpy2.takeFirst();
631 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
566 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
632 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
567 QVERIFY(setIndexSpyArg.at(0).toBool() == true);
633 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
568 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
634 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
569 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
635
570
636 //=======================================================================
571 //=======================================================================
637 // move mouse between set1 and set2 (hover out set2)
572 // move mouse between set1 and set2 (hover out set2)
638 QTest::mouseMove(view.viewport(), QPoint((layout.at(3).right() + layout.at(4).left()) /2,
573 QTest::mouseMove(view.viewport(), QPoint((layout.at(3).right() + layout.at(4).left()) /2,
639 layout.at(2).top()));
574 layout.at(2).top()));
640
575
641 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
576 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
642 TRY_COMPARE(seriesSpy.count(), 1);
643 TRY_COMPARE(seriesIndexSpy.count(), 1);
577 TRY_COMPARE(seriesIndexSpy.count(), 1);
644 TRY_COMPARE(setIndexSpy1.count(), 0);
578 TRY_COMPARE(setIndexSpy1.count(), 0);
645 TRY_COMPARE(setIndexSpy2.count(), 1);
579 TRY_COMPARE(setIndexSpy2.count(), 1);
646
580
647 //should leave set1, bar1
581 //should leave set1, bar1
648 seriesSpyArg = seriesSpy.takeFirst();
649 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
650 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
651 QVERIFY(seriesSpyArg.at(0).toBool() == false);
652
653 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
582 seriesIndexSpyArg = seriesIndexSpy.takeFirst();
654 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
583 QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2);
655 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
584 QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool);
656 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
585 QVERIFY(seriesIndexSpyArg.at(0).toBool() == false);
657 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
586 QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int);
658 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
587 QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1);
659
588
660 setIndexSpyArg = setIndexSpy2.takeFirst();
589 setIndexSpyArg = setIndexSpy2.takeFirst();
661 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
590 QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool);
662 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
591 QVERIFY(setIndexSpyArg.at(0).toBool() == false);
663 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
592 QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int);
664 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
593 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
665 }
594 }
666
595
667 QTEST_MAIN(tst_QStackedBarSeries)
596 QTEST_MAIN(tst_QStackedBarSeries)
668
597
669 #include "tst_qstackedbarseries.moc"
598 #include "tst_qstackedbarseries.moc"
670
599
General Comments 0
You need to be logged in to leave comments. Login now