##// END OF EJS Templates
Add pressed, released and doubleClicked signals...
Titta Heikkala -
r2739:f78be8da2422
parent child
Show More
@@ -60,7 +60,7 int main(int argc, char *argv[])
60 chart->setAxisY(axisY, series);
60 chart->setAxisY(axisY, series);
61 axisY->setRange(0, 13);
61 axisY->setRange(0, 13);
62
62
63 QObject::connect(series, SIGNAL(clicked(QPointF)), chart, SLOT(clickPoint(QPointF)));
63 QObject::connect(series, SIGNAL(pressed(QPointF)), chart, SLOT(clickPoint(QPointF)));
64
64
65 ChartView *chartView = new ChartView(chart);
65 ChartView *chartView = new ChartView(chart);
66 chartView->setRenderHint(QPainter::Antialiasing);
66 chartView->setRenderHint(QPainter::Antialiasing);
@@ -40,9 +40,11 AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item)
40 m_pointLabelsVisible(false),
40 m_pointLabelsVisible(false),
41 m_pointLabelsFormat(areaSeries->pointLabelsFormat()),
41 m_pointLabelsFormat(areaSeries->pointLabelsFormat()),
42 m_pointLabelsFont(areaSeries->pointLabelsFont()),
42 m_pointLabelsFont(areaSeries->pointLabelsFont()),
43 m_pointLabelsColor(areaSeries->pointLabelsColor())
43 m_pointLabelsColor(areaSeries->pointLabelsColor()),
44 m_mousePressed(false)
44 {
45 {
45 setAcceptHoverEvents(true);
46 setAcceptHoverEvents(true);
47 setFlag(QGraphicsItem::ItemIsSelectable, true);
46 setZValue(ChartPresenter::LineChartZValue);
48 setZValue(ChartPresenter::LineChartZValue);
47 if (m_series->upperSeries())
49 if (m_series->upperSeries())
48 m_upper = new AreaBoundItem(this, m_series->upperSeries());
50 m_upper = new AreaBoundItem(this, m_series->upperSeries());
@@ -54,6 +56,10 AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item)
54 QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated()));
56 QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated()));
55 QObject::connect(this, SIGNAL(clicked(QPointF)), areaSeries, SIGNAL(clicked(QPointF)));
57 QObject::connect(this, SIGNAL(clicked(QPointF)), areaSeries, SIGNAL(clicked(QPointF)));
56 QObject::connect(this, SIGNAL(hovered(QPointF,bool)), areaSeries, SIGNAL(hovered(QPointF,bool)));
58 QObject::connect(this, SIGNAL(hovered(QPointF,bool)), areaSeries, SIGNAL(hovered(QPointF,bool)));
59 QObject::connect(this, SIGNAL(pressed(QPointF)), areaSeries, SIGNAL(pressed(QPointF)));
60 QObject::connect(this, SIGNAL(released(QPointF)), areaSeries, SIGNAL(released(QPointF)));
61 QObject::connect(this, SIGNAL(doubleClicked(QPointF)),
62 areaSeries, SIGNAL(doubleClicked(QPointF)));
57 QObject::connect(areaSeries, SIGNAL(pointLabelsFormatChanged(QString)),
63 QObject::connect(areaSeries, SIGNAL(pointLabelsFormatChanged(QString)),
58 this, SLOT(handleUpdated()));
64 this, SLOT(handleUpdated()));
59 QObject::connect(areaSeries, SIGNAL(pointLabelsVisibilityChanged(bool)),
65 QObject::connect(areaSeries, SIGNAL(pointLabelsVisibilityChanged(bool)),
@@ -239,7 +245,9 void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
239
245
240 void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
246 void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
241 {
247 {
242 emit clicked(m_upper->domain()->calculateDomainPoint(event->pos()));
248 emit pressed(m_upper->domain()->calculateDomainPoint(event->pos()));
249 m_lastMousePos = event->pos();
250 m_mousePressed = true;
243 ChartItem::mousePressEvent(event);
251 ChartItem::mousePressEvent(event);
244 }
252 }
245
253
@@ -257,6 +265,21 void AreaChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
257 // QGraphicsItem::hoverEnterEvent(event);
265 // QGraphicsItem::hoverEnterEvent(event);
258 }
266 }
259
267
268 void AreaChartItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
269 {
270 emit released(m_upper->domain()->calculateDomainPoint(event->pos()));
271 if (m_lastMousePos == event->pos() && m_mousePressed)
272 emit clicked(m_upper->domain()->calculateDomainPoint(event->pos()));
273 m_mousePressed = false;
274 ChartItem::mouseReleaseEvent(event);
275 }
276
277 void AreaChartItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
278 {
279 emit doubleClicked(m_upper->domain()->calculateDomainPoint(event->pos()));
280 ChartItem::mouseDoubleClickEvent(event);
281 }
282
260 #include "moc_areachartitem_p.cpp"
283 #include "moc_areachartitem_p.cpp"
261
284
262 QT_CHARTS_END_NAMESPACE
285 QT_CHARTS_END_NAMESPACE
@@ -63,10 +63,15 protected:
63 void mousePressEvent(QGraphicsSceneMouseEvent *event);
63 void mousePressEvent(QGraphicsSceneMouseEvent *event);
64 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
64 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
65 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
65 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
66 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
67 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
66
68
67 Q_SIGNALS:
69 Q_SIGNALS:
68 void clicked(const QPointF &point);
70 void clicked(const QPointF &point);
69 void hovered(const QPointF &point, bool state);
71 void hovered(const QPointF &point, bool state);
72 void pressed(const QPointF &point);
73 void released(const QPointF &point);
74 void doubleClicked(const QPointF &point);
70
75
71 public Q_SLOTS:
76 public Q_SLOTS:
72 void handleUpdated();
77 void handleUpdated();
@@ -88,6 +93,9 private:
88 QFont m_pointLabelsFont;
93 QFont m_pointLabelsFont;
89 QColor m_pointLabelsColor;
94 QColor m_pointLabelsColor;
90
95
96 QPointF m_lastMousePos;
97 bool m_mousePressed;
98
91 };
99 };
92
100
93 class AreaBoundItem : public LineChartItem
101 class AreaBoundItem : public LineChartItem
@@ -168,6 +168,33 QT_CHARTS_BEGIN_NAMESPACE
168 */
168 */
169
169
170 /*!
170 /*!
171 \fn void QAreaSeries::pressed(const QPointF& point)
172 \brief Signal is emitted when user presses the \a point on area chart.
173 */
174 /*!
175 \qmlsignal AreaSeries::onPressed(QPointF point)
176 Signal is emitted when user presses the \a point on area chart.
177 */
178
179 /*!
180 \fn void QAreaSeries::released(const QPointF& point)
181 \brief Signal is emitted when user releases the \a point on area chart.
182 */
183 /*!
184 \qmlsignal AreaSeries::onReleased(QPointF point)
185 Signal is emitted when user releases the \a point on area chart.
186 */
187
188 /*!
189 \fn void QAreaSeries::doubleClicked(const QPointF& point)
190 \brief Signal is emitted when user doubleclicks the \a point on area chart.
191 */
192 /*!
193 \qmlsignal AreaSeries::onDoubleClicked(QPointF point)
194 Signal is emitted when user doubleclicks the \a point on area chart.
195 */
196
197 /*!
171 \fn void QAreaSeries::selected()
198 \fn void QAreaSeries::selected()
172 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
199 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
173 implemented by the user of QAreaSeries API.
200 implemented by the user of QAreaSeries API.
@@ -85,6 +85,9 public:
85 Q_SIGNALS:
85 Q_SIGNALS:
86 void clicked(const QPointF &point);
86 void clicked(const QPointF &point);
87 void hovered(const QPointF &point, bool state);
87 void hovered(const QPointF &point, bool state);
88 void pressed(const QPointF &point);
89 void released(const QPointF &point);
90 void doubleClicked(const QPointF &point);
88 void selected();
91 void selected();
89 void colorChanged(QColor color);
92 void colorChanged(QColor color);
90 void borderColorChanged(QColor color);
93 void borderColorChanged(QColor color);
@@ -42,6 +42,7 AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, QGraphics
42 {
42 {
43
43
44 setFlag(ItemClipsChildrenToShape);
44 setFlag(ItemClipsChildrenToShape);
45 setFlag(QGraphicsItem::ItemIsSelectable);
45 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
46 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
46 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars()));
47 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars()));
47 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
48 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
@@ -163,8 +164,16 void AbstractBarChartItem::handleDataStructureChanged()
163 m_bars.append(bar);
164 m_bars.append(bar);
164 connect(bar, SIGNAL(clicked(int,QBarSet*)), m_series, SIGNAL(clicked(int,QBarSet*)));
165 connect(bar, SIGNAL(clicked(int,QBarSet*)), m_series, SIGNAL(clicked(int,QBarSet*)));
165 connect(bar, SIGNAL(hovered(bool, int, QBarSet*)), m_series, SIGNAL(hovered(bool, int, QBarSet*)));
166 connect(bar, SIGNAL(hovered(bool, int, QBarSet*)), m_series, SIGNAL(hovered(bool, int, QBarSet*)));
167 connect(bar, SIGNAL(pressed(int, QBarSet*)), m_series, SIGNAL(pressed(int, QBarSet*)));
168 connect(bar, SIGNAL(released(int, QBarSet*)),
169 m_series, SIGNAL(released(int, QBarSet*)));
170 connect(bar, SIGNAL(doubleClicked(int, QBarSet*)),
171 m_series, SIGNAL(doubleClicked(int, QBarSet*)));
166 connect(bar, SIGNAL(clicked(int,QBarSet*)), set, SIGNAL(clicked(int)));
172 connect(bar, SIGNAL(clicked(int,QBarSet*)), set, SIGNAL(clicked(int)));
167 connect(bar, SIGNAL(hovered(bool, int, QBarSet*)), set, SIGNAL(hovered(bool, int)));
173 connect(bar, SIGNAL(hovered(bool, int, QBarSet*)), set, SIGNAL(hovered(bool, int)));
174 connect(bar, SIGNAL(pressed(int, QBarSet*)), set, SIGNAL(pressed(int)));
175 connect(bar, SIGNAL(released(int, QBarSet*)), set, SIGNAL(released(int)));
176 connect(bar, SIGNAL(doubleClicked(int, QBarSet*)), set, SIGNAL(doubleClicked(int)));
168 // m_layout.append(QRectF(0, 0, 1, 1));
177 // m_layout.append(QRectF(0, 0, 1, 1));
169
178
170 // Labels
179 // Labels
@@ -21,16 +21,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 #include <QtWidgets/QStyleOptionGraphicsItem>
25 #include <QtWidgets/QStyle>
24
26
25 QT_CHARTS_BEGIN_NAMESPACE
27 QT_CHARTS_BEGIN_NAMESPACE
26
28
27 Bar::Bar(QBarSet *barset, int index, QGraphicsItem *parent) : QGraphicsRectItem(parent),
29 Bar::Bar(QBarSet *barset, int index, QGraphicsItem *parent) : QGraphicsRectItem(parent),
28 m_index(index),
30 m_index(index),
29 m_barset(barset),
31 m_barset(barset),
30 m_hovering(false)
32 m_hovering(false),
33 m_mousePressed(false)
31 {
34 {
32 setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
35 setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
33 setAcceptHoverEvents(true);
36 setAcceptHoverEvents(true);
37 setFlag(QGraphicsItem::ItemIsSelectable);
34 }
38 }
35
39
36 Bar::~Bar()
40 Bar::~Bar()
@@ -42,8 +46,9 Bar::~Bar()
42
46
43 void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event)
47 void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event)
44 {
48 {
45 Q_UNUSED(event)
49 emit pressed(m_index, m_barset);
46 emit clicked(m_index, m_barset);
50 m_lastMousePos = event->pos();
51 m_mousePressed = true;
47 QGraphicsItem::mousePressEvent(event);
52 QGraphicsItem::mousePressEvent(event);
48 }
53 }
49
54
@@ -62,6 +67,29 void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
62 emit hovered(false, m_index, m_barset);
67 emit hovered(false, m_index, m_barset);
63 }
68 }
64
69
70 void Bar::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
71 {
72 emit released(m_index, m_barset);
73 if (m_lastMousePos == event->pos() && m_mousePressed)
74 emit clicked(m_index, m_barset);
75 m_mousePressed = false;
76 QGraphicsItem::mouseReleaseEvent(event);
77 }
78
79 void Bar::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
80 {
81 emit doubleClicked(m_index, m_barset);
82 QGraphicsItem::mouseDoubleClickEvent(event);
83 }
84
85 void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
86 {
87 // Remove selection border around bar
88 QStyleOptionGraphicsItem barOption(*option);
89 barOption.state &= ~QStyle::State_Selected;
90 QGraphicsRectItem::paint(painter, &barOption, widget);
91 }
92
65 #include "moc_bar_p.cpp"
93 #include "moc_bar_p.cpp"
66
94
67 QT_CHARTS_END_NAMESPACE
95 QT_CHARTS_END_NAMESPACE
@@ -49,15 +49,25 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 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
53 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
54
55 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
52
56
53 Q_SIGNALS:
57 Q_SIGNALS:
54 void clicked(int index, QBarSet *barset);
58 void clicked(int index, QBarSet *barset);
55 void hovered(bool status, int index, QBarSet *barset);
59 void hovered(bool status, int index, QBarSet *barset);
60 void pressed(int index, QBarSet *barset);
61 void released(int index, QBarSet *barset);
62 void doubleClicked(int index, QBarSet *barset);
56
63
57 private:
64 private:
58 int m_index;
65 int m_index;
59 QBarSet *m_barset;
66 QBarSet *m_barset;
60 bool m_hovering;
67 bool m_hovering;
68
69 QPointF m_lastMousePos;
70 bool m_mousePressed;
61 };
71 };
62
72
63 QT_CHARTS_END_NAMESPACE
73 QT_CHARTS_END_NAMESPACE
@@ -211,6 +211,39 QT_CHARTS_BEGIN_NAMESPACE
211 */
211 */
212
212
213 /*!
213 /*!
214 \fn void QAbstractBarSeries::pressed(int index, QBarSet *barset)
215 The signal is emitted if the user presses with a mouse on top of QBarSet \a barset.
216 Pressed bar inside set is indexed by \a index
217 */
218 /*!
219 \qmlsignal AbstractBarSeries::onPressed(int index, BarSet barset)
220 The signal is emitted if the user presses with a mouse on top of BarSet.
221 Pressed bar inside set is indexed by \a index
222 */
223
224 /*!
225 \fn void QAbstractBarSeries::released(int index, QBarSet *barset)
226 The signal is emitted if the user releases with a mouse on top of QBarSet \a barset.
227 Released bar inside set is indexed by \a index
228 */
229 /*!
230 \qmlsignal AbstractBarSeries::onReleased(int index, BarSet barset)
231 The signal is emitted if the user releases with a mouse on top of BarSet.
232 Released bar inside set is indexed by \a index
233 */
234
235 /*!
236 \fn void QAbstractBarSeries::doubleClicked(int index, QBarSet *barset)
237 The signal is emitted if the user doubleclicks with a mouse on top of QBarSet \a barset.
238 DoubleClicked bar inside set is indexed by \a index
239 */
240 /*!
241 \qmlsignal AbstractBarSeries::onDoubleClicked(int index, BarSet barset)
242 The signal is emitted if the user doubleclicks with a mouse on top of BarSet.
243 Doubleclicked bar inside set is indexed by \a index
244 */
245
246 /*!
214 \fn void QAbstractBarSeries::hovered(bool status, int index, QBarSet* barset)
247 \fn void QAbstractBarSeries::hovered(bool status, int index, QBarSet* barset)
215
248
216 The signal is emitted if mouse is hovered on top of series.
249 The signal is emitted if mouse is hovered on top of series.
@@ -78,6 +78,9 protected:
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, int index, QBarSet *barset);
80 void hovered(bool status, int index, QBarSet *barset);
81 void pressed(int index, QBarSet *barset);
82 void released(int index, QBarSet *barset);
83 void doubleClicked(int index, QBarSet *barset);
81 void countChanged();
84 void countChanged();
82 void labelsVisibleChanged();
85 void labelsVisibleChanged();
83 void labelsFormatChanged(const QString &format);
86 void labelsFormatChanged(const QString &format);
@@ -89,6 +89,9 public:
89
89
90 Q_SIGNALS:
90 Q_SIGNALS:
91 void clicked(int index, QBarSet *barset);
91 void clicked(int index, QBarSet *barset);
92 void pressed(int index, QBarSet *barset);
93 void released(int index, QBarSet *barset);
94 void doubleClicked(int index, QBarSet *barset);
92 void updatedBars();
95 void updatedBars();
93 void updatedLayout();
96 void updatedLayout();
94 void restructuredBars();
97 void restructuredBars();
@@ -134,6 +134,27 QT_CHARTS_BEGIN_NAMESPACE
134 */
134 */
135
135
136 /*!
136 /*!
137 \fn void QBarSet::pressed(int index)
138
139 The signal is emitted if the user presses with a mouse on top of bar set.
140 Pressed bar inside set is indexed by \a index
141 */
142
143 /*!
144 \fn void QBarSet::released(int index)
145
146 The signal is emitted if the user releases with a mouse on top of bar set.
147 Released bar inside set is indexed by \a index
148 */
149
150 /*!
151 \fn void QBarSet::doubleClicked(int index)
152
153 The signal is emitted if the user doubleclicks with a mouse on top of bar set.
154 Doubleclicked bar inside set is indexed by \a index
155 */
156
157 /*!
137 \fn void QBarSet::hovered(bool status, int index)
158 \fn void QBarSet::hovered(bool status, int index)
138
159
139 The signal is emitted if mouse is hovered on top of bar set.
160 The signal is emitted if mouse is hovered on top of bar set.
@@ -85,6 +85,9 public:
85 Q_SIGNALS:
85 Q_SIGNALS:
86 void clicked(int index);
86 void clicked(int index);
87 void hovered(bool status, int index);
87 void hovered(bool status, int index);
88 void pressed(int index);
89 void released(int index);
90 void doubleClicked(int index);
88 void penChanged();
91 void penChanged();
89 void brushChanged();
92 void brushChanged();
90 void labelChanged();
93 void labelChanged();
@@ -78,8 +78,15 void BoxPlotChartItem::handleDataStructureChanged()
78 m_boxTable.insert(set, box);
78 m_boxTable.insert(set, box);
79 connect(box, SIGNAL(clicked(QBoxSet *)), m_series, SIGNAL(clicked(QBoxSet *)));
79 connect(box, SIGNAL(clicked(QBoxSet *)), m_series, SIGNAL(clicked(QBoxSet *)));
80 connect(box, SIGNAL(hovered(bool, QBoxSet *)), m_series, SIGNAL(hovered(bool, QBoxSet *)));
80 connect(box, SIGNAL(hovered(bool, QBoxSet *)), m_series, SIGNAL(hovered(bool, QBoxSet *)));
81 connect(box, SIGNAL(pressed(QBoxSet *)), m_series, SIGNAL(pressed(QBoxSet *)));
82 connect(box, SIGNAL(released(QBoxSet *)), m_series, SIGNAL(released(QBoxSet *)));
83 connect(box, SIGNAL(doubleClicked(QBoxSet *)),
84 m_series, SIGNAL(doubleClicked(QBoxSet *)));
81 connect(box, SIGNAL(clicked(QBoxSet *)), set, SIGNAL(clicked()));
85 connect(box, SIGNAL(clicked(QBoxSet *)), set, SIGNAL(clicked()));
82 connect(box, SIGNAL(hovered(bool, QBoxSet *)), set, SIGNAL(hovered(bool)));
86 connect(box, SIGNAL(hovered(bool, QBoxSet *)), set, SIGNAL(hovered(bool)));
87 connect(box, SIGNAL(pressed(QBoxSet *)), set, SIGNAL(pressed()));
88 connect(box, SIGNAL(released(QBoxSet *)), set, SIGNAL(released()));
89 connect(box, SIGNAL(doubleClicked(QBoxSet *)), set, SIGNAL(doubleClicked()));
83
90
84 // Set the decorative issues for the newly created box
91 // Set the decorative issues for the newly created box
85 // so that the brush and pen already defined for the set are kept.
92 // so that the brush and pen already defined for the set are kept.
@@ -21,16 +21,19
21 #include <private/boxwhiskers_p.h>
21 #include <private/boxwhiskers_p.h>
22 #include <QtGui/QPainter>
22 #include <QtGui/QPainter>
23 #include <QtWidgets/QWidget>
23 #include <QtWidgets/QWidget>
24 #include <QtWidgets/QGraphicsSceneMouseEvent>
24
25
25 QT_CHARTS_BEGIN_NAMESPACE
26 QT_CHARTS_BEGIN_NAMESPACE
26
27
27 BoxWhiskers::BoxWhiskers(QBoxSet *set, AbstractDomain *domain, QGraphicsObject *parent) :
28 BoxWhiskers::BoxWhiskers(QBoxSet *set, AbstractDomain *domain, QGraphicsObject *parent) :
28 QGraphicsObject(parent),
29 QGraphicsObject(parent),
29 m_boxSet(set),
30 m_boxSet(set),
30 m_domain(domain)
31 m_domain(domain),
32 m_mousePressed(false)
31 {
33 {
32 setAcceptHoverEvents(true);
34 setAcceptHoverEvents(true);
33 setAcceptedMouseButtons(Qt::MouseButtonMask);
35 setAcceptedMouseButtons(Qt::MouseButtonMask);
36 setFlag(QGraphicsObject::ItemIsSelectable);
34 }
37 }
35
38
36 BoxWhiskers::~BoxWhiskers()
39 BoxWhiskers::~BoxWhiskers()
@@ -39,8 +42,9 BoxWhiskers::~BoxWhiskers()
39
42
40 void BoxWhiskers::mousePressEvent(QGraphicsSceneMouseEvent *event)
43 void BoxWhiskers::mousePressEvent(QGraphicsSceneMouseEvent *event)
41 {
44 {
42 Q_UNUSED(event)
45 emit pressed(m_boxSet);
43 emit clicked(m_boxSet);
46 m_lastMousePos = event->pos();
47 m_mousePressed = true;
44 }
48 }
45
49
46 void BoxWhiskers::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
50 void BoxWhiskers::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
@@ -55,6 +59,21 void BoxWhiskers::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
55 emit hovered(false, m_boxSet);
59 emit hovered(false, m_boxSet);
56 }
60 }
57
61
62 void BoxWhiskers::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
63 {
64 emit released(m_boxSet);
65 if (m_lastMousePos == event->pos() && m_mousePressed)
66 emit clicked(m_boxSet);
67 }
68
69 void BoxWhiskers::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
70 {
71 Q_UNUSED(event)
72 // For Box a press signal needs to be explicitly fired for mouseDoubleClickEvent
73 emit pressed(m_boxSet);
74 emit doubleClicked(m_boxSet);
75 }
76
58 void BoxWhiskers::setBrush(const QBrush &brush)
77 void BoxWhiskers::setBrush(const QBrush &brush)
59 {
78 {
60 m_brush = brush;
79 m_brush = brush;
@@ -60,6 +60,8 public:
60 void mousePressEvent(QGraphicsSceneMouseEvent *event);
60 void mousePressEvent(QGraphicsSceneMouseEvent *event);
61 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
61 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
62 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
62 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
63 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
64 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
63
65
64 QRectF boundingRect() const;
66 QRectF boundingRect() const;
65 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
67 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
@@ -72,6 +74,9 protected:
72 Q_SIGNALS:
74 Q_SIGNALS:
73 void clicked(QBoxSet *boxset);
75 void clicked(QBoxSet *boxset);
74 void hovered(bool status, QBoxSet *boxset);
76 void hovered(bool status, QBoxSet *boxset);
77 void pressed(QBoxSet *boxset);
78 void released(QBoxSet *boxset);
79 void doubleClicked(QBoxSet *boxset);
75
80
76 private:
81 private:
77 friend class BoxPlotChartItem;
82 friend class BoxPlotChartItem;
@@ -95,6 +100,9 private:
95 qreal m_geometryMedian;
100 qreal m_geometryMedian;
96 qreal m_geometryLeft;
101 qreal m_geometryLeft;
97 qreal m_geometryRight;
102 qreal m_geometryRight;
103
104 QPointF m_lastMousePos;
105 bool m_mousePressed;
98 };
106 };
99
107
100 QT_CHARTS_END_NAMESPACE
108 QT_CHARTS_END_NAMESPACE
@@ -62,6 +62,18 QT_CHARTS_BEGIN_NAMESPACE
62 \brief Signal is emitted when the user clicks the \a boxset on the chart.
62 \brief Signal is emitted when the user clicks the \a boxset on the chart.
63 */
63 */
64 /*!
64 /*!
65 \fn QBoxPlotSeries::pressed(QBoxSet *boxset)
66 \brief Signal is emitted when the user presses the \a boxset on the chart.
67 */
68 /*!
69 \fn QBoxPlotSeries::released(QBoxSet *boxset)
70 \brief Signal is emitted when the user releases the \a boxset on the chart.
71 */
72 /*!
73 \fn QBoxPlotSeries::doubleClicked(QBoxSet *boxset)
74 \brief Signal is emitted when the user doubleclicks the \a boxset on the chart.
75 */
76 /*!
65 \fn QBoxPlotSeries::hovered(bool status, QBoxSet *boxset)
77 \fn QBoxPlotSeries::hovered(bool status, QBoxSet *boxset)
66 \brief Signal is emitted when there is change in hover \a status over \a boxset.
78 \brief Signal is emitted when there is change in hover \a status over \a boxset.
67 */
79 */
@@ -64,6 +64,9 public:
64 Q_SIGNALS:
64 Q_SIGNALS:
65 void clicked(QBoxSet *boxset);
65 void clicked(QBoxSet *boxset);
66 void hovered(bool status, QBoxSet *boxset);
66 void hovered(bool status, QBoxSet *boxset);
67 void pressed(QBoxSet *boxset);
68 void released(QBoxSet *boxset);
69 void doubleClicked(QBoxSet *boxset);
67 void countChanged();
70 void countChanged();
68 void penChanged();
71 void penChanged();
69 void brushChanged();
72 void brushChanged();
@@ -74,6 +74,9 private:
74 Q_SIGNALS:
74 Q_SIGNALS:
75 void updated();
75 void updated();
76 void clicked(int index, QBoxSet *barset);
76 void clicked(int index, QBoxSet *barset);
77 void pressed(int index, QBoxSet *barset);
78 void released(int index, QBoxSet *barset);
79 void doubleClicked(int index, QBoxSet *barset);
77 void updatedBoxes();
80 void updatedBoxes();
78 void updatedLayout();
81 void updatedLayout();
79 void restructuredBoxes();
82 void restructuredBoxes();
@@ -66,6 +66,22 QT_CHARTS_BEGIN_NAMESPACE
66 \fn void QBoxSet::clicked()
66 \fn void QBoxSet::clicked()
67 The signal is emitted if the user clicks with a mouse on top of box-and-whisker item.
67 The signal is emitted if the user clicks with a mouse on top of box-and-whisker item.
68 */
68 */
69
70 /*!
71 \fn void QBoxSet::pressed()
72 The signal is emitted if the user presses with a mouse on top of box-and-whisker item.
73 */
74
75 /*!
76 \fn void QBoxSet::released()
77 The signal is emitted if the user releases with a mouse on top of box-and-whisker item.
78 */
79
80 /*!
81 \fn void QBoxSet::doubleClicked()
82 The signal is emitted if the user doubleclicks with a mouse on top of box-and-whisker item.
83 */
84
69 /*!
85 /*!
70 \fn void QBoxSet::hovered(bool status)
86 \fn void QBoxSet::hovered(bool status)
71
87
@@ -73,6 +73,9 public:
73 Q_SIGNALS:
73 Q_SIGNALS:
74 void clicked();
74 void clicked();
75 void hovered(bool status);
75 void hovered(bool status);
76 void pressed();
77 void released();
78 void doubleClicked();
76 void penChanged();
79 void penChanged();
77 void brushChanged();
80 void brushChanged();
78
81
@@ -40,9 +40,11 LineChartItem::LineChartItem(QLineSeries *series, QGraphicsItem *item)
40 m_pointLabelsVisible(false),
40 m_pointLabelsVisible(false),
41 m_pointLabelsFormat(series->pointLabelsFormat()),
41 m_pointLabelsFormat(series->pointLabelsFormat()),
42 m_pointLabelsFont(series->pointLabelsFont()),
42 m_pointLabelsFont(series->pointLabelsFont()),
43 m_pointLabelsColor(series->pointLabelsColor())
43 m_pointLabelsColor(series->pointLabelsColor()),
44 m_mousePressed(false)
44 {
45 {
45 setAcceptHoverEvents(true);
46 setAcceptHoverEvents(true);
47 setFlag(QGraphicsItem::ItemIsSelectable);
46 setZValue(ChartPresenter::LineChartZValue);
48 setZValue(ChartPresenter::LineChartZValue);
47 QObject::connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
49 QObject::connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
48 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
50 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
@@ -382,7 +384,9 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
382
384
383 void LineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
385 void LineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
384 {
386 {
385 emit XYChart::clicked(domain()->calculateDomainPoint(event->pos()));
387 emit XYChart::pressed(domain()->calculateDomainPoint(event->pos()));
388 m_lastMousePos = event->pos();
389 m_mousePressed = true;
386 QGraphicsItem::mousePressEvent(event);
390 QGraphicsItem::mousePressEvent(event);
387 }
391 }
388
392
@@ -400,6 +404,21 void LineChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
400 QGraphicsItem::hoverEnterEvent(event);
404 QGraphicsItem::hoverEnterEvent(event);
401 }
405 }
402
406
407 void LineChartItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
408 {
409 emit XYChart::released(domain()->calculateDomainPoint(event->pos()));
410 if (m_lastMousePos == event->pos() && m_mousePressed)
411 emit XYChart::clicked(domain()->calculateDomainPoint(event->pos()));
412 m_mousePressed = false;
413 QGraphicsItem::mouseReleaseEvent(event);
414 }
415
416 void LineChartItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
417 {
418 emit XYChart::doubleClicked(domain()->calculateDomainPoint(event->pos()));
419 QGraphicsItem::mouseDoubleClickEvent(event);
420 }
421
403 #include "moc_linechartitem_p.cpp"
422 #include "moc_linechartitem_p.cpp"
404
423
405 QT_CHARTS_END_NAMESPACE
424 QT_CHARTS_END_NAMESPACE
@@ -63,6 +63,8 protected:
63 void mousePressEvent(QGraphicsSceneMouseEvent *event);
63 void mousePressEvent(QGraphicsSceneMouseEvent *event);
64 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
64 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
65 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
65 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
66 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
67 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
66 void suppressPoints() { m_pointsVisible = false; }
68 void suppressPoints() { m_pointsVisible = false; }
67 void forceChartType(QChart::ChartType chartType) { m_chartType = chartType; }
69 void forceChartType(QChart::ChartType chartType) { m_chartType = chartType; }
68
70
@@ -84,6 +86,9 private:
84 QString m_pointLabelsFormat;
86 QString m_pointLabelsFormat;
85 QFont m_pointLabelsFont;
87 QFont m_pointLabelsFont;
86 QColor m_pointLabelsColor;
88 QColor m_pointLabelsColor;
89
90 QPointF m_lastMousePos;
91 bool m_mousePressed;
87 };
92 };
88
93
89 QT_CHARTS_END_NAMESPACE
94 QT_CHARTS_END_NAMESPACE
@@ -53,6 +53,8 PieChartItem::PieChartItem(QPieSeries *series, QGraphicsItem* item)
53 setZValue(ChartPresenter::PieSeriesZValue);
53 setZValue(ChartPresenter::PieSeriesZValue);
54
54
55 // Note: will not create slice items until we have a proper rectangle to draw on.
55 // Note: will not create slice items until we have a proper rectangle to draw on.
56
57 setFlag(QGraphicsItem::ItemIsSelectable);
56 }
58 }
57
59
58 PieChartItem::~PieChartItem()
60 PieChartItem::~PieChartItem()
@@ -153,6 +155,9 void PieChartItem::handleSlicesAdded(QList<QPieSlice *> slices)
153
155
154 connect(sliceItem, SIGNAL(clicked(Qt::MouseButtons)), slice, SIGNAL(clicked()));
156 connect(sliceItem, SIGNAL(clicked(Qt::MouseButtons)), slice, SIGNAL(clicked()));
155 connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool)));
157 connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool)));
158 connect(sliceItem, SIGNAL(pressed(Qt::MouseButtons)), slice, SIGNAL(pressed()));
159 connect(sliceItem, SIGNAL(released(Qt::MouseButtons)), slice, SIGNAL(released()));
160 connect(sliceItem, SIGNAL(doubleClicked(Qt::MouseButtons)), slice, SIGNAL(doubleClicked()));
156
161
157 PieSliceData sliceData = updateSliceGeometry(slice);
162 PieSliceData sliceData = updateSliceGeometry(slice);
158 if (m_animation)
163 if (m_animation)
@@ -41,11 +41,13 QPointF offset(qreal angle, qreal length)
41
41
42 PieSliceItem::PieSliceItem(QGraphicsItem *parent)
42 PieSliceItem::PieSliceItem(QGraphicsItem *parent)
43 : QGraphicsObject(parent),
43 : QGraphicsObject(parent),
44 m_hovered(false)
44 m_hovered(false),
45 m_mousePressed(false)
45 {
46 {
46 setAcceptHoverEvents(true);
47 setAcceptHoverEvents(true);
47 setAcceptedMouseButtons(Qt::MouseButtonMask);
48 setAcceptedMouseButtons(Qt::MouseButtonMask);
48 setZValue(ChartPresenter::PieSeriesZValue);
49 setZValue(ChartPresenter::PieSeriesZValue);
50 setFlag(QGraphicsItem::ItemIsSelectable);
49 m_labelItem = new QGraphicsTextItem(this);
51 m_labelItem = new QGraphicsTextItem(this);
50 m_labelItem->document()->setDocumentMargin(1.0);
52 m_labelItem->document()->setDocumentMargin(1.0);
51 }
53 }
@@ -108,7 +110,23 void PieSliceItem::hoverLeaveEvent(QGraphicsSceneHoverEvent * /*event*/)
108
110
109 void PieSliceItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
111 void PieSliceItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
110 {
112 {
111 emit clicked(event->buttons());
113 emit pressed(event->buttons());
114 m_lastMousePos = event->pos();
115 m_mousePressed = true;
116 }
117
118 void PieSliceItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
119 {
120 emit released(event->buttons());
121 if (m_lastMousePos == event->pos() && m_mousePressed)
122 emit clicked(event->buttons());
123 }
124
125 void PieSliceItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
126 {
127 // For Pie slice a press signal needs to be explicitly fired for mouseDoubleClickEvent
128 emit pressed(event->buttons());
129 emit doubleClicked(event->buttons());
112 }
130 }
113
131
114 void PieSliceItem::setLayout(const PieSliceData &sliceData)
132 void PieSliceItem::setLayout(const PieSliceData &sliceData)
@@ -61,6 +61,8 public:
61 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
61 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
62 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
62 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
63 void mousePressEvent(QGraphicsSceneMouseEvent *event);
63 void mousePressEvent(QGraphicsSceneMouseEvent *event);
64 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
65 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
64
66
65 void setLayout(const PieSliceData &sliceData);
67 void setLayout(const PieSliceData &sliceData);
66 static QPointF sliceCenter(QPointF point, qreal radius, QPieSlice *slice);
68 static QPointF sliceCenter(QPointF point, qreal radius, QPieSlice *slice);
@@ -68,6 +70,9 public:
68 Q_SIGNALS:
70 Q_SIGNALS:
69 void clicked(Qt::MouseButtons buttons);
71 void clicked(Qt::MouseButtons buttons);
70 void hovered(bool state);
72 void hovered(bool state);
73 void pressed(Qt::MouseButtons buttons);
74 void released(Qt::MouseButtons buttons);
75 void doubleClicked(Qt::MouseButtons buttons);
71
76
72 private:
77 private:
73 void updateGeometry();
78 void updateGeometry();
@@ -83,6 +88,9 private:
83 bool m_hovered;
88 bool m_hovered;
84 QGraphicsTextItem *m_labelItem;
89 QGraphicsTextItem *m_labelItem;
85
90
91 QPointF m_lastMousePos;
92 bool m_mousePressed;
93
86 friend class PieSliceAnimation;
94 friend class PieSliceAnimation;
87 };
95 };
88
96
@@ -316,6 +316,36 QT_CHARTS_BEGIN_NAMESPACE
316 */
316 */
317
317
318 /*!
318 /*!
319 \fn void QPieSeries::pressed(QPieSlice* slice)
320 This signal is emitted when a \a slice has been pressed.
321 \sa QPieSlice::pressed()
322 */
323 /*!
324 \qmlsignal PieSeries::onPressed(PieSlice slice)
325 This signal is emitted when a \a slice has been pressed.
326 */
327
328 /*!
329 \fn void QPieSeries::released(QPieSlice* slice)
330 This signal is emitted when a \a slice has been released.
331 \sa QPieSlice::released()
332 */
333 /*!
334 \qmlsignal PieSeries::onReleased(PieSlice slice)
335 This signal is emitted when a \a slice has been released.
336 */
337
338 /*!
339 \fn void QPieSeries::doubleClicked(QPieSlice* slice)
340 This signal is emitted when a \a slice has been doubleClicked.
341 \sa QPieSlice::doubleClicked()
342 */
343 /*!
344 \qmlsignal PieSeries::onDoubleClicked(PieSlice slice)
345 This signal is emitted when a \a slice has been doubleClicked.
346 */
347
348 /*!
319 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
349 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
320 This signal is emitted when user has hovered over or away from the \a slice.
350 This signal is emitted when user has hovered over or away from the \a slice.
321 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
351 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
@@ -424,6 +454,9 bool QPieSeries::append(QList<QPieSlice *> slices)
424 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
454 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
425 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
455 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
426 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
456 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
457 connect(s, SIGNAL(pressed()), d, SLOT(slicePressed()));
458 connect(s, SIGNAL(released()), d, SLOT(sliceReleased()));
459 connect(s, SIGNAL(doubleClicked()), d, SLOT(sliceDoubleClicked()));
427 }
460 }
428
461
429 emit added(slices);
462 emit added(slices);
@@ -490,6 +523,9 bool QPieSeries::insert(int index, QPieSlice *slice)
490 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
523 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
491 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
524 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
492 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
525 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
526 connect(slice, SIGNAL(pressed()), d, SLOT(slicePressed()));
527 connect(slice, SIGNAL(released()), d, SLOT(sliceReleased()));
528 connect(slice, SIGNAL(doubleClicked()), d, SLOT(sliceDoubleClicked()));
493
529
494 emit added(QList<QPieSlice *>() << slice);
530 emit added(QList<QPieSlice *>() << slice);
495 emit countChanged();
531 emit countChanged();
@@ -854,6 +890,30 void QPieSeriesPrivate::sliceHovered(bool state)
854 }
890 }
855 }
891 }
856
892
893 void QPieSeriesPrivate::slicePressed()
894 {
895 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
896 Q_ASSERT(m_slices.contains(slice));
897 Q_Q(QPieSeries);
898 emit q->pressed(slice);
899 }
900
901 void QPieSeriesPrivate::sliceReleased()
902 {
903 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
904 Q_ASSERT(m_slices.contains(slice));
905 Q_Q(QPieSeries);
906 emit q->released(slice);
907 }
908
909 void QPieSeriesPrivate::sliceDoubleClicked()
910 {
911 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
912 Q_ASSERT(m_slices.contains(slice));
913 Q_Q(QPieSeries);
914 emit q->doubleClicked(slice);
915 }
916
857 void QPieSeriesPrivate::initializeDomain()
917 void QPieSeriesPrivate::initializeDomain()
858 {
918 {
859 // does not apply to pie
919 // does not apply to pie
@@ -89,6 +89,9 Q_SIGNALS:
89 void removed(QList<QPieSlice *> slices);
89 void removed(QList<QPieSlice *> slices);
90 void clicked(QPieSlice *slice);
90 void clicked(QPieSlice *slice);
91 void hovered(QPieSlice *slice, bool state);
91 void hovered(QPieSlice *slice, bool state);
92 void pressed(QPieSlice *slice);
93 void released(QPieSlice *slice);
94 void doubleClicked(QPieSlice *slice);
92 void countChanged();
95 void countChanged();
93 void sumChanged();
96 void sumChanged();
94
97
@@ -72,6 +72,9 public Q_SLOTS:
72 void sliceValueChanged();
72 void sliceValueChanged();
73 void sliceClicked();
73 void sliceClicked();
74 void sliceHovered(bool state);
74 void sliceHovered(bool state);
75 void slicePressed();
76 void sliceReleased();
77 void sliceDoubleClicked();
75
78
76 private:
79 private:
77 QList<QPieSlice *> m_slices;
80 QList<QPieSlice *> m_slices;
@@ -432,6 +432,36 QT_CHARTS_BEGIN_NAMESPACE
432 */
432 */
433
433
434 /*!
434 /*!
435 \fn void QPieSlice::pressed()
436 This signal is emitted when user has pressed the slice.
437 \sa QPieSeries::pressed()
438 */
439 /*!
440 \qmlsignal PieSlice::onPressed()
441 This signal is emitted when user has pressed the slice.
442 */
443
444 /*!
445 \fn void QPieSlice::released()
446 This signal is emitted when user has released the slice.
447 \sa QPieSeries::released()
448 */
449 /*!
450 \qmlsignal PieSlice::onReleased()
451 This signal is emitted when user has released the slice.
452 */
453
454 /*!
455 \fn void QPieSlice::doubleClicked()
456 This signal is emitted when user has doubleclicked the slice.
457 \sa QPieSeries::doubleClicked()
458 */
459 /*!
460 \qmlsignal PieSlice::onDoubleClicked()
461 This signal is emitted when user has doubleclicked the slice.
462 */
463
464 /*!
435 \fn void QPieSlice::hovered(bool state)
465 \fn void QPieSlice::hovered(bool state)
436 This signal is emitted when user has hovered over or away from the slice.
466 This signal is emitted when user has hovered over or away from the slice.
437 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
467 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
@@ -121,6 +121,9 public:
121 Q_SIGNALS:
121 Q_SIGNALS:
122 void clicked();
122 void clicked();
123 void hovered(bool state);
123 void hovered(bool state);
124 void pressed();
125 void released();
126 void doubleClicked();
124 void labelChanged();
127 void labelChanged();
125 void valueChanged();
128 void valueChanged();
126 void labelVisibleChanged();
129 void labelVisibleChanged();
@@ -41,7 +41,8 ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem *item)
41 m_pointLabelsVisible(false),
41 m_pointLabelsVisible(false),
42 m_pointLabelsFormat(series->pointLabelsFormat()),
42 m_pointLabelsFormat(series->pointLabelsFormat()),
43 m_pointLabelsFont(series->pointLabelsFont()),
43 m_pointLabelsFont(series->pointLabelsFont()),
44 m_pointLabelsColor(series->pointLabelsColor())
44 m_pointLabelsColor(series->pointLabelsColor()),
45 m_mousePressed(false)
45 {
46 {
46 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
47 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
47 QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
48 QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
@@ -55,6 +56,7 ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem *item)
55
56
56 setZValue(ChartPresenter::ScatterSeriesZValue);
57 setZValue(ChartPresenter::ScatterSeriesZValue);
57 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
58 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
59 setFlag(QGraphicsItem::ItemIsSelectable);
58
60
59 handleUpdated();
61 handleUpdated();
60
62
@@ -112,6 +114,21 void ScatterChartItem::markerHovered(QGraphicsItem *marker, bool state)
112 emit XYChart::hovered(m_markerMap[marker], state);
114 emit XYChart::hovered(m_markerMap[marker], state);
113 }
115 }
114
116
117 void ScatterChartItem::markerPressed(QGraphicsItem *marker)
118 {
119 emit XYChart::pressed(m_markerMap[marker]);
120 }
121
122 void ScatterChartItem::markerReleased(QGraphicsItem *marker)
123 {
124 emit XYChart::released(m_markerMap[marker]);
125 }
126
127 void ScatterChartItem::markerDoubleClicked(QGraphicsItem *marker)
128 {
129 emit XYChart::doubleClicked(m_markerMap[marker]);
130 }
131
115 void ScatterChartItem::updateGeometry()
132 void ScatterChartItem::updateGeometry()
116 {
133 {
117
134
@@ -34,6 +34,7
34 #include <private/xychart_p.h>
34 #include <private/xychart_p.h>
35 #include <QtWidgets/QGraphicsEllipseItem>
35 #include <QtWidgets/QGraphicsEllipseItem>
36 #include <QtGui/QPen>
36 #include <QtGui/QPen>
37 #include <QtWidgets/QGraphicsSceneMouseEvent>
37
38
38 QT_CHARTS_BEGIN_NAMESPACE
39 QT_CHARTS_BEGIN_NAMESPACE
39
40
@@ -56,6 +57,15 public:
56
57
57 void markerSelected(QGraphicsItem *item);
58 void markerSelected(QGraphicsItem *item);
58 void markerHovered(QGraphicsItem *item, bool state);
59 void markerHovered(QGraphicsItem *item, bool state);
60 void markerPressed(QGraphicsItem *item);
61 void markerReleased(QGraphicsItem *item);
62 void markerDoubleClicked(QGraphicsItem *item);
63
64 void setLastMousePosition(const QPointF pos) {m_lastMousePos = pos;}
65 QPointF lastMousePosition() const {return m_lastMousePos;}
66 void setMousePressed(bool pressed = true) {m_mousePressed = pressed;}
67 bool mousePressed() {return m_mousePressed;}
68
59
69
60 public Q_SLOTS:
70 public Q_SLOTS:
61 void handleUpdated();
71 void handleUpdated();
@@ -80,6 +90,9 private:
80 QString m_pointLabelsFormat;
90 QString m_pointLabelsFormat;
81 QFont m_pointLabelsFont;
91 QFont m_pointLabelsFont;
82 QColor m_pointLabelsColor;
92 QColor m_pointLabelsColor;
93
94 QPointF m_lastMousePos;
95 bool m_mousePressed;
83 };
96 };
84
97
85 class CircleMarker: public QGraphicsEllipseItem
98 class CircleMarker: public QGraphicsEllipseItem
@@ -91,13 +104,16 public:
91 m_parent(parent)
104 m_parent(parent)
92 {
105 {
93 setAcceptHoverEvents(true);
106 setAcceptHoverEvents(true);
107 setFlag(QGraphicsItem::ItemIsSelectable);
94 }
108 }
95
109
96 protected:
110 protected:
97 void mousePressEvent(QGraphicsSceneMouseEvent *event)
111 void mousePressEvent(QGraphicsSceneMouseEvent *event)
98 {
112 {
99 QGraphicsEllipseItem::mousePressEvent(event);
113 QGraphicsEllipseItem::mousePressEvent(event);
100 m_parent->markerSelected(this);
114 m_parent->markerPressed(this);
115 m_parent->setLastMousePosition(event->pos());
116 m_parent->setMousePressed();
101 }
117 }
102 void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
118 void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
103 {
119 {
@@ -109,6 +125,19 protected:
109 QGraphicsEllipseItem::hoverLeaveEvent(event);
125 QGraphicsEllipseItem::hoverLeaveEvent(event);
110 m_parent->markerHovered(this, false);
126 m_parent->markerHovered(this, false);
111 }
127 }
128 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
129 {
130 QGraphicsEllipseItem::mouseReleaseEvent(event);
131 m_parent->markerReleased(this);
132 if (m_parent->lastMousePosition() == event->pos() && m_parent->mousePressed())
133 m_parent->markerSelected(this);
134 m_parent->setMousePressed(false);
135 }
136 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
137 {
138 QGraphicsEllipseItem::mouseDoubleClickEvent(event);
139 m_parent->markerDoubleClicked(this);
140 }
112
141
113 private:
142 private:
114 ScatterChartItem *m_parent;
143 ScatterChartItem *m_parent;
@@ -123,13 +152,16 public:
123 m_parent(parent)
152 m_parent(parent)
124 {
153 {
125 setAcceptHoverEvents(true);
154 setAcceptHoverEvents(true);
155 setFlag(QGraphicsItem::ItemIsSelectable);
126 }
156 }
127
157
128 protected:
158 protected:
129 void mousePressEvent(QGraphicsSceneMouseEvent *event)
159 void mousePressEvent(QGraphicsSceneMouseEvent *event)
130 {
160 {
131 QGraphicsRectItem::mousePressEvent(event);
161 QGraphicsRectItem::mousePressEvent(event);
132 m_parent->markerSelected(this);
162 m_parent->markerPressed(this);
163 m_parent->setLastMousePosition(event->pos());
164 m_parent->setMousePressed();
133 }
165 }
134 void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
166 void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
135 {
167 {
@@ -141,6 +173,19 protected:
141 QGraphicsRectItem::hoverLeaveEvent(event);
173 QGraphicsRectItem::hoverLeaveEvent(event);
142 m_parent->markerHovered(this, false);
174 m_parent->markerHovered(this, false);
143 }
175 }
176 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
177 {
178 QGraphicsRectItem::mouseReleaseEvent(event);
179 m_parent->markerReleased(this);
180 if (m_parent->lastMousePosition() == event->pos() && m_parent->mousePressed())
181 m_parent->markerSelected(this);
182 m_parent->setMousePressed(false);
183 }
184 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
185 {
186 QGraphicsRectItem::mouseDoubleClickEvent(event);
187 m_parent->markerDoubleClicked(this);
188 }
144
189
145 private:
190 private:
146 ScatterChartItem *m_parent;
191 ScatterChartItem *m_parent;
@@ -36,9 +36,11 SplineChartItem::SplineChartItem(QSplineSeries *series, QGraphicsItem *item)
36 m_pointLabelsVisible(false),
36 m_pointLabelsVisible(false),
37 m_pointLabelsFormat(series->pointLabelsFormat()),
37 m_pointLabelsFormat(series->pointLabelsFormat()),
38 m_pointLabelsFont(series->pointLabelsFont()),
38 m_pointLabelsFont(series->pointLabelsFont()),
39 m_pointLabelsColor(series->pointLabelsColor())
39 m_pointLabelsColor(series->pointLabelsColor()),
40 m_mousePressed(false)
40 {
41 {
41 setAcceptHoverEvents(true);
42 setAcceptHoverEvents(true);
43 setFlag(QGraphicsItem::ItemIsSelectable);
42 setZValue(ChartPresenter::SplineChartZValue);
44 setZValue(ChartPresenter::SplineChartZValue);
43 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
45 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
44 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
46 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
@@ -464,7 +466,9 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
464
466
465 void SplineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
467 void SplineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
466 {
468 {
467 emit XYChart::clicked(domain()->calculateDomainPoint(event->pos()));
469 emit XYChart::pressed(domain()->calculateDomainPoint(event->pos()));
470 m_lastMousePos = event->pos();
471 m_mousePressed = true;
468 QGraphicsItem::mousePressEvent(event);
472 QGraphicsItem::mousePressEvent(event);
469 }
473 }
470
474
@@ -480,6 +484,21 void SplineChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
480 QGraphicsItem::hoverLeaveEvent(event);
484 QGraphicsItem::hoverLeaveEvent(event);
481 }
485 }
482
486
487 void SplineChartItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
488 {
489 emit XYChart::released(domain()->calculateDomainPoint(event->pos()));
490 if (m_lastMousePos == event->pos() && m_mousePressed)
491 emit XYChart::clicked(domain()->calculateDomainPoint(event->pos()));
492 m_mousePressed = false;
493 QGraphicsItem::mouseReleaseEvent(event);
494 }
495
496 void SplineChartItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
497 {
498 emit XYChart::doubleClicked(domain()->calculateDomainPoint(event->pos()));
499 QGraphicsItem::mouseDoubleClickEvent(event);
500 }
501
483 #include "moc_splinechartitem_p.cpp"
502 #include "moc_splinechartitem_p.cpp"
484
503
485 QT_CHARTS_END_NAMESPACE
504 QT_CHARTS_END_NAMESPACE
@@ -66,6 +66,8 protected:
66 void mousePressEvent(QGraphicsSceneMouseEvent *event);
66 void mousePressEvent(QGraphicsSceneMouseEvent *event);
67 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
67 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
68 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
68 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
69 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
70 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
69
71
70 private:
72 private:
71 QSplineSeries *m_series;
73 QSplineSeries *m_series;
@@ -86,6 +88,9 private:
86 QFont m_pointLabelsFont;
88 QFont m_pointLabelsFont;
87 QColor m_pointLabelsColor;
89 QColor m_pointLabelsColor;
88
90
91 QPointF m_lastMousePos;
92 bool m_mousePressed;
93
89 friend class SplineAnimation;
94 friend class SplineAnimation;
90 };
95 };
91
96
@@ -255,6 +255,54 QT_CHARTS_BEGIN_NAMESPACE
255 */
255 */
256
256
257 /*!
257 /*!
258 \fn void QXYSeries::pressed(const QPointF& point)
259 \brief Signal is emitted when user presses the \a point on chart.
260 */
261 /*!
262 \qmlsignal XYSeries::onPressed(QPointF point)
263 Signal is emitted when user presses the \a point on chart. For example:
264 \code
265 LineSeries {
266 XYPoint { x: 0; y: 0 }
267 XYPoint { x: 1.1; y: 2.1 }
268 onPressed: console.log("onPressed: " + point.x + ", " + point.y);
269 }
270 \endcode
271 */
272
273 /*!
274 \fn void QXYSeries::released(const QPointF& point)
275 \brief Signal is emitted when user releases the \a point on chart.
276 */
277 /*!
278 \qmlsignal XYSeries::onReleased(QPointF point)
279 Signal is emitted when user releases the \a point on chart. For example:
280 \code
281 LineSeries {
282 XYPoint { x: 0; y: 0 }
283 XYPoint { x: 1.1; y: 2.1 }
284 onReleased: console.log("onReleased: " + point.x + ", " + point.y);
285 }
286 \endcode
287 */
288
289 /*!
290 \fn void QXYSeries::doubleClicked(const QPointF& point)
291 \brief Signal is emitted when user doubleclicks the \a point on chart.
292 */
293 /*!
294 \qmlsignal XYSeries::onDoubleClicked(QPointF point)
295 Signal is emitted when user doubleclicks the \a point on chart. For example:
296 \code
297 LineSeries {
298 XYPoint { x: 0; y: 0 }
299 XYPoint { x: 1.1; y: 2.1 }
300 onDoubleClicked: console.log("onDoubleClicked: " + point.x + ", " + point.y);
301 }
302 \endcode
303 */
304
305 /*!
258 \fn void QXYSeries::pointReplaced(int index)
306 \fn void QXYSeries::pointReplaced(int index)
259 Signal is emitted when a point has been replaced at \a index.
307 Signal is emitted when a point has been replaced at \a index.
260 \sa replace()
308 \sa replace()
@@ -288,6 +336,7 QT_CHARTS_BEGIN_NAMESPACE
288 Signal is emitted when a point has been removed from \a index.
336 Signal is emitted when a point has been removed from \a index.
289 \sa remove()
337 \sa remove()
290 */
338 */
339
291 /*!
340 /*!
292 \qmlsignal XYSeries::onPointRemoved(int index)
341 \qmlsignal XYSeries::onPointRemoved(int index)
293 Signal is emitted when a point has been removed from \a index.
342 Signal is emitted when a point has been removed from \a index.
@@ -97,6 +97,9 public:
97 Q_SIGNALS:
97 Q_SIGNALS:
98 void clicked(const QPointF &point);
98 void clicked(const QPointF &point);
99 void hovered(const QPointF &point, bool state);
99 void hovered(const QPointF &point, bool state);
100 void pressed(const QPointF &point);
101 void released(const QPointF &point);
102 void doubleClicked(const QPointF &point);
100 void pointReplaced(int index);
103 void pointReplaced(int index);
101 void pointRemoved(int index);
104 void pointRemoved(int index);
102 void pointAdded(int index);
105 void pointAdded(int index);
@@ -43,6 +43,9 XYChart::XYChart(QXYSeries *series, QGraphicsItem *item):
43 QObject::connect(series, SIGNAL(pointRemoved(int)), this, SLOT(handlePointRemoved(int)));
43 QObject::connect(series, SIGNAL(pointRemoved(int)), this, SLOT(handlePointRemoved(int)));
44 QObject::connect(this, SIGNAL(clicked(QPointF)), series, SIGNAL(clicked(QPointF)));
44 QObject::connect(this, SIGNAL(clicked(QPointF)), series, SIGNAL(clicked(QPointF)));
45 QObject::connect(this, SIGNAL(hovered(QPointF,bool)), series, SIGNAL(hovered(QPointF,bool)));
45 QObject::connect(this, SIGNAL(hovered(QPointF,bool)), series, SIGNAL(hovered(QPointF,bool)));
46 QObject::connect(this, SIGNAL(pressed(QPointF)), series, SIGNAL(pressed(QPointF)));
47 QObject::connect(this, SIGNAL(released(QPointF)), series, SIGNAL(released(QPointF)));
48 QObject::connect(this, SIGNAL(doubleClicked(QPointF)), series, SIGNAL(doubleClicked(QPointF)));
46 }
49 }
47
50
48 void XYChart::setGeometryPoints(const QVector<QPointF> &points)
51 void XYChart::setGeometryPoints(const QVector<QPointF> &points)
@@ -71,6 +71,9 public Q_SLOTS:
71 Q_SIGNALS:
71 Q_SIGNALS:
72 void clicked(const QPointF &point);
72 void clicked(const QPointF &point);
73 void hovered(const QPointF &point, bool state);
73 void hovered(const QPointF &point, bool state);
74 void pressed(const QPointF &point);
75 void released(const QPointF &point);
76 void doubleClicked(const QPointF &point);
74
77
75 protected:
78 protected:
76 virtual void updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index = -1);
79 virtual void updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index = -1);
@@ -72,6 +72,18 QT_CHARTS_BEGIN_NAMESPACE
72 This signal is emitted when the user clicks with a mouse on top of box-and-whiskers item.
72 This signal is emitted when the user clicks with a mouse on top of box-and-whiskers item.
73 */
73 */
74 /*!
74 /*!
75 \qmlsignal BoxSet::onPressed()
76 This signal is emitted when the user presses with a mouse on top of box-and-whiskers item.
77 */
78 /*!
79 \qmlsignal BoxSet::onReleased()
80 This signal is emitted when the user releases with a mouse on top of box-and-whiskers item.
81 */
82 /*!
83 \qmlsignal BoxSet::onDoubleClicked()
84 This signal is emitted when the user doubleclicks with a mouse on top of box-and-whiskers item.
85 */
86 /*!
75 \qmlsignal BoxSet::onHovered(bool status)
87 \qmlsignal BoxSet::onHovered(bool status)
76 The signal is emitted if mouse is hovered on top of box-and-whiskers item.
88 The signal is emitted if mouse is hovered on top of box-and-whiskers item.
77 Parameter \a status is true, if mouse entered on top of the item, and false if mouse left from top of the item.
89 Parameter \a status is true, if mouse entered on top of the item, and false if mouse left from top of the item.
@@ -335,6 +347,9 DeclarativeBoxPlotSeries::DeclarativeBoxPlotSeries(QQuickItem *parent) :
335 connect(this, SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(onHovered(bool, QBoxSet*)));
347 connect(this, SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(onHovered(bool, QBoxSet*)));
336 connect(this, SIGNAL(clicked(QBoxSet*)), this, SLOT(onClicked(QBoxSet*)));
348 connect(this, SIGNAL(clicked(QBoxSet*)), this, SLOT(onClicked(QBoxSet*)));
337 connect(this, SIGNAL(brushChanged()), this, SLOT(handleBrushChanged()));
349 connect(this, SIGNAL(brushChanged()), this, SLOT(handleBrushChanged()));
350 connect(this, SIGNAL(pressed(QBoxSet*)), this, SLOT(onPressed(QBoxSet*)));
351 connect(this, SIGNAL(released(QBoxSet*)), this, SLOT(onReleased(QBoxSet*)));
352 connect(this, SIGNAL(doubleClicked(QBoxSet*)), this, SLOT(onDoubleClicked(QBoxSet*)));
338 }
353 }
339
354
340 void DeclarativeBoxPlotSeries::classBegin()
355 void DeclarativeBoxPlotSeries::classBegin()
@@ -394,6 +409,21 void DeclarativeBoxPlotSeries::onClicked(QBoxSet *boxset)
394 emit clicked(qobject_cast<DeclarativeBoxSet *>(boxset));
409 emit clicked(qobject_cast<DeclarativeBoxSet *>(boxset));
395 }
410 }
396
411
412 void DeclarativeBoxPlotSeries::onPressed(QBoxSet *boxset)
413 {
414 emit pressed(qobject_cast<DeclarativeBoxSet *>(boxset));
415 }
416
417 void DeclarativeBoxPlotSeries::onReleased(QBoxSet *boxset)
418 {
419 emit released(qobject_cast<DeclarativeBoxSet *>(boxset));
420 }
421
422 void DeclarativeBoxPlotSeries::onDoubleClicked(QBoxSet *boxset)
423 {
424 emit doubleClicked(qobject_cast<DeclarativeBoxSet *>(boxset));
425 }
426
397 QString DeclarativeBoxPlotSeries::brushFilename() const
427 QString DeclarativeBoxPlotSeries::brushFilename() const
398 {
428 {
399 return m_brushFilename;
429 return m_brushFilename;
@@ -119,12 +119,18 Q_SIGNALS:
119 void axisYRightChanged(QAbstractAxis *axis);
119 void axisYRightChanged(QAbstractAxis *axis);
120 void clicked(DeclarativeBoxSet *boxset);
120 void clicked(DeclarativeBoxSet *boxset);
121 void hovered(bool status, DeclarativeBoxSet *boxset);
121 void hovered(bool status, DeclarativeBoxSet *boxset);
122 void pressed(DeclarativeBoxSet *boxset);
123 void released(DeclarativeBoxSet *boxset);
124 void doubleClicked(DeclarativeBoxSet *boxset);
122 Q_REVISION(1) void brushFilenameChanged(const QString &brushFilename);
125 Q_REVISION(1) void brushFilenameChanged(const QString &brushFilename);
123
126
124 public Q_SLOTS:
127 public Q_SLOTS:
125 static void appendSeriesChildren(QQmlListProperty<QObject> *list, QObject *element);
128 static void appendSeriesChildren(QQmlListProperty<QObject> *list, QObject *element);
126 void onHovered(bool status, QBoxSet *boxset);
129 void onHovered(bool status, QBoxSet *boxset);
127 void onClicked(QBoxSet *boxset);
130 void onClicked(QBoxSet *boxset);
131 void onPressed(QBoxSet *boxset);
132 void onReleased(QBoxSet *boxset);
133 void onDoubleClicked(QBoxSet *boxset);
128
134
129 private Q_SLOTS:
135 private Q_SLOTS:
130 void handleBrushChanged();
136 void handleBrushChanged();
@@ -588,6 +588,31 void DeclarativeChart::hoverMoveEvent(QHoverEvent *event)
588 QApplication::sendEvent(m_scene, &mouseEvent);
588 QApplication::sendEvent(m_scene, &mouseEvent);
589 }
589 }
590
590
591 void DeclarativeChart::mouseDoubleClickEvent(QMouseEvent *event)
592 {
593 m_mousePressScenePoint = event->pos();
594 m_mousePressScreenPoint = event->globalPos();
595 m_lastMouseMoveScenePoint = m_mousePressScenePoint;
596 m_lastMouseMoveScreenPoint = m_mousePressScreenPoint;
597 m_mousePressButton = event->button();
598 m_mousePressButtons = event->buttons();
599
600 QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseDoubleClick);
601 mouseEvent.setWidget(0);
602 mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint);
603 mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint);
604 mouseEvent.setScenePos(m_mousePressScenePoint);
605 mouseEvent.setScreenPos(m_mousePressScreenPoint);
606 mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint);
607 mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint);
608 mouseEvent.setButtons(m_mousePressButtons);
609 mouseEvent.setButton(m_mousePressButton);
610 mouseEvent.setModifiers(event->modifiers());
611 mouseEvent.setAccepted(false);
612
613 QApplication::sendEvent(m_scene, &mouseEvent);
614 }
615
591 void DeclarativeChart::handleAntialiasingChanged(bool enable)
616 void DeclarativeChart::handleAntialiasingChanged(bool enable)
592 {
617 {
593 setAntialiasing(enable);
618 setAntialiasing(enable);
@@ -112,6 +112,7 protected:
112 void mousePressEvent(QMouseEvent *event);
112 void mousePressEvent(QMouseEvent *event);
113 void mouseReleaseEvent(QMouseEvent *event);
113 void mouseReleaseEvent(QMouseEvent *event);
114 void hoverMoveEvent(QHoverEvent *event);
114 void hoverMoveEvent(QHoverEvent *event);
115 void mouseDoubleClickEvent(QMouseEvent *event);
115 private Q_SLOTS:
116 private Q_SLOTS:
116 void handleAntialiasingChanged(bool enable);
117 void handleAntialiasingChanged(bool enable);
117 void sceneChanged(QList<QRectF> region);
118 void sceneChanged(QList<QRectF> region);
@@ -306,6 +306,18 Module {
306 Parameter { name: "boxset"; type: "DeclarativeBoxSet"; isPointer: true }
306 Parameter { name: "boxset"; type: "DeclarativeBoxSet"; isPointer: true }
307 }
307 }
308 Signal {
308 Signal {
309 name: "pressed"
310 Parameter { name: "boxset"; type: "DeclarativeBoxSet"; isPointer: true }
311 }
312 Signal {
313 name: "released"
314 Parameter { name: "boxset"; type: "DeclarativeBoxSet"; isPointer: true }
315 }
316 Signal {
317 name: "doubleClicked"
318 Parameter { name: "boxset"; type: "DeclarativeBoxSet"; isPointer: true }
319 }
320 Signal {
309 name: "brushFilenameChanged"
321 name: "brushFilenameChanged"
310 revision: 1
322 revision: 1
311 Parameter { name: "brushFilename"; type: "string" }
323 Parameter { name: "brushFilename"; type: "string" }
@@ -325,6 +337,18 Module {
325 Parameter { name: "boxset"; type: "QBoxSet"; isPointer: true }
337 Parameter { name: "boxset"; type: "QBoxSet"; isPointer: true }
326 }
338 }
327 Method {
339 Method {
340 name: "onPressed"
341 Parameter { name: "boxset"; type: "QBoxSet"; isPointer: true }
342 }
343 Method {
344 name: "onReleased"
345 Parameter { name: "boxset"; type: "QBoxSet"; isPointer: true }
346 }
347 Method {
348 name: "onDoubleClicked"
349 Parameter { name: "boxset"; type: "QBoxSet"; isPointer: true }
350 }
351 Method {
328 name: "at"
352 name: "at"
329 type: "DeclarativeBoxSet*"
353 type: "DeclarativeBoxSet*"
330 Parameter { name: "index"; type: "int" }
354 Parameter { name: "index"; type: "int" }
@@ -1615,11 +1639,21 Module {
1615 Signal {
1639 Signal {
1616 name: "hovered"
1640 name: "hovered"
1617 Parameter { name: "status"; type: "bool" }
1641 Parameter { name: "status"; type: "bool" }
1642 Parameter { name: "index"; type: "int" }
1618 Parameter { name: "barset"; type: "QBarSet"; isPointer: true }
1643 Parameter { name: "barset"; type: "QBarSet"; isPointer: true }
1619 }
1644 }
1620 Signal {
1645 Signal {
1621 name: "hovered"
1646 name: "pressed"
1622 Parameter { name: "status"; type: "bool" }
1647 Parameter { name: "index"; type: "int" }
1648 Parameter { name: "barset"; type: "QBarSet"; isPointer: true }
1649 }
1650 Signal {
1651 name: "released"
1652 Parameter { name: "index"; type: "int" }
1653 Parameter { name: "barset"; type: "QBarSet"; isPointer: true }
1654 }
1655 Signal {
1656 name: "doubleClicked"
1623 Parameter { name: "index"; type: "int" }
1657 Parameter { name: "index"; type: "int" }
1624 Parameter { name: "barset"; type: "QBarSet"; isPointer: true }
1658 Parameter { name: "barset"; type: "QBarSet"; isPointer: true }
1625 }
1659 }
@@ -1691,6 +1725,18 Module {
1691 Parameter { name: "point"; type: "QPointF" }
1725 Parameter { name: "point"; type: "QPointF" }
1692 Parameter { name: "state"; type: "bool" }
1726 Parameter { name: "state"; type: "bool" }
1693 }
1727 }
1728 Signal {
1729 name: "pressed"
1730 Parameter { name: "point"; type: "QPointF" }
1731 }
1732 Signal {
1733 name: "released"
1734 Parameter { name: "point"; type: "QPointF" }
1735 }
1736 Signal {
1737 name: "doubleClicked"
1738 Parameter { name: "point"; type: "QPointF" }
1739 }
1694 Signal { name: "selected" }
1740 Signal { name: "selected" }
1695 Signal {
1741 Signal {
1696 name: "colorChanged"
1742 name: "colorChanged"
@@ -1777,10 +1823,18 Module {
1777 Signal {
1823 Signal {
1778 name: "hovered"
1824 name: "hovered"
1779 Parameter { name: "status"; type: "bool" }
1825 Parameter { name: "status"; type: "bool" }
1826 Parameter { name: "index"; type: "int" }
1780 }
1827 }
1781 Signal {
1828 Signal {
1782 name: "hovered"
1829 name: "pressed"
1783 Parameter { name: "status"; type: "bool" }
1830 Parameter { name: "index"; type: "int" }
1831 }
1832 Signal {
1833 name: "released"
1834 Parameter { name: "index"; type: "int" }
1835 }
1836 Signal {
1837 name: "doubleClicked"
1784 Parameter { name: "index"; type: "int" }
1838 Parameter { name: "index"; type: "int" }
1785 }
1839 }
1786 Signal {
1840 Signal {
@@ -1834,6 +1888,18 Module {
1834 Parameter { name: "status"; type: "bool" }
1888 Parameter { name: "status"; type: "bool" }
1835 Parameter { name: "boxset"; type: "QBoxSet"; isPointer: true }
1889 Parameter { name: "boxset"; type: "QBoxSet"; isPointer: true }
1836 }
1890 }
1891 Signal {
1892 name: "pressed"
1893 Parameter { name: "boxset"; type: "QBoxSet"; isPointer: true }
1894 }
1895 Signal {
1896 name: "released"
1897 Parameter { name: "boxset"; type: "QBoxSet"; isPointer: true }
1898 }
1899 Signal {
1900 name: "doubleClicked"
1901 Parameter { name: "boxset"; type: "QBoxSet"; isPointer: true }
1902 }
1837 Signal { name: "boxOutlineVisibilityChanged" }
1903 Signal { name: "boxOutlineVisibilityChanged" }
1838 Signal {
1904 Signal {
1839 name: "boxsetsAdded"
1905 name: "boxsetsAdded"
@@ -1854,6 +1920,9 Module {
1854 name: "hovered"
1920 name: "hovered"
1855 Parameter { name: "status"; type: "bool" }
1921 Parameter { name: "status"; type: "bool" }
1856 }
1922 }
1923 Signal { name: "pressed" }
1924 Signal { name: "released" }
1925 Signal { name: "doubleClicked" }
1857 Signal { name: "valuesChanged" }
1926 Signal { name: "valuesChanged" }
1858 Signal {
1927 Signal {
1859 name: "valueChanged"
1928 name: "valueChanged"
@@ -2073,6 +2142,18 Module {
2073 Parameter { name: "slice"; type: "QPieSlice"; isPointer: true }
2142 Parameter { name: "slice"; type: "QPieSlice"; isPointer: true }
2074 Parameter { name: "state"; type: "bool" }
2143 Parameter { name: "state"; type: "bool" }
2075 }
2144 }
2145 Signal {
2146 name: "pressed"
2147 Parameter { name: "slice"; type: "QPieSlice"; isPointer: true }
2148 }
2149 Signal {
2150 name: "released"
2151 Parameter { name: "slice"; type: "QPieSlice"; isPointer: true }
2152 }
2153 Signal {
2154 name: "doubleClicked"
2155 Parameter { name: "slice"; type: "QPieSlice"; isPointer: true }
2156 }
2076 }
2157 }
2077 Component {
2158 Component {
2078 name: "QtCharts::QPieSlice"
2159 name: "QtCharts::QPieSlice"
@@ -2111,6 +2192,9 Module {
2111 name: "hovered"
2192 name: "hovered"
2112 Parameter { name: "state"; type: "bool" }
2193 Parameter { name: "state"; type: "bool" }
2113 }
2194 }
2195 Signal { name: "pressed" }
2196 Signal { name: "released" }
2197 Signal { name: "doubleClicked" }
2114 }
2198 }
2115 Component {
2199 Component {
2116 name: "QtCharts::QScatterSeries"
2200 name: "QtCharts::QScatterSeries"
@@ -2269,6 +2353,18 Module {
2269 Parameter { name: "state"; type: "bool" }
2353 Parameter { name: "state"; type: "bool" }
2270 }
2354 }
2271 Signal {
2355 Signal {
2356 name: "pressed"
2357 Parameter { name: "point"; type: "QPointF" }
2358 }
2359 Signal {
2360 name: "released"
2361 Parameter { name: "point"; type: "QPointF" }
2362 }
2363 Signal {
2364 name: "doubleClicked"
2365 Parameter { name: "point"; type: "QPointF" }
2366 }
2367 Signal {
2272 name: "pointReplaced"
2368 name: "pointReplaced"
2273 Parameter { name: "index"; type: "int" }
2369 Parameter { name: "index"; type: "int" }
2274 }
2370 }
@@ -69,6 +69,9 private slots:
69 void mousehovered();
69 void mousehovered();
70 void clearWithAnimations();
70 void clearWithAnimations();
71 void destruction();
71 void destruction();
72 void mousePressed();
73 void mouseReleased();
74 void mouseDoubleClicked();
72
75
73 private:
76 private:
74 QBarSeries* m_barseries;
77 QBarSeries* m_barseries;
@@ -926,6 +929,410 void tst_QBarSeries::destruction()
926 QCOMPARE(spy1.count(), 1);
929 QCOMPARE(spy1.count(), 1);
927 }
930 }
928
931
932 void tst_QBarSeries::mousePressed()
933 {
934 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
935
936 QBarSeries* series = new QBarSeries();
937
938 QBarSet* set1 = new QBarSet(QString("set 1"));
939 *set1 << 10 << 10 << 10;
940 series->append(set1);
941
942 QBarSet* set2 = new QBarSet(QString("set 2"));
943 *set2 << 10 << 10 << 10;
944 series->append(set2);
945 QList<QBarSet*> barSets = series->barSets();
946
947 QSignalSpy seriesSpy(series,SIGNAL(pressed(int,QBarSet*)));
948 QSignalSpy setSpy1(set1, SIGNAL(pressed(int)));
949 QSignalSpy setSpy2(set2, SIGNAL(pressed(int)));
950
951 QChartView view(new QChart());
952 view.resize(400,300);
953 view.chart()->addSeries(series);
954 view.show();
955 QTest::qWaitForWindowShown(&view);
956
957 // Calculate expected layout for bars
958 QRectF plotArea = view.chart()->plotArea();
959 qreal width = plotArea.width();
960 qreal height = plotArea.height();
961 qreal rangeY = 10; // From 0 to 10 because of maximum value in set is 10
962 qreal rangeX = 3; // 3 values per set
963 qreal scaleY = (height / rangeY);
964 qreal scaleX = (width / rangeX);
965
966 qreal setCount = series->count();
967 qreal domainMinY = 0; // These come from internal domain used by barseries.
968 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
969 qreal rectWidth = (scaleX / setCount) * series->barWidth();
970
971 QVector<QRectF> layout;
972
973 // 3 = count of values in set
974 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
975 for (int i = 0; i < 3; i++) {
976 qreal yPos = height + scaleY * domainMinY + plotArea.top();
977 for (int set = 0; set < setCount; set++) {
978 qreal xPos = (i - domainMinX) * scaleX + plotArea.left();
979 xPos -= series->count()*rectWidth/2;
980 xPos += set*rectWidth;
981
982 qreal rectHeight = barSets.at(set)->at(i) * scaleY;
983 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
984 layout.append(rect);
985 }
986 }
987
988 //====================================================================================
989 // barset 1, bar 0
990 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
991 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
992
993 QCOMPARE(seriesSpy.count(), 1);
994 QCOMPARE(setSpy1.count(), 1);
995 QCOMPARE(setSpy2.count(), 0);
996
997 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
998 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
999 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1000 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
1001
1002 QList<QVariant> setSpyArg = setSpy1.takeFirst();
1003 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1004 QVERIFY(setSpyArg.at(0).toInt() == 0);
1005
1006 //====================================================================================
1007 // barset 1, bar 1
1008 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
1009 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1010
1011 QCOMPARE(seriesSpy.count(), 1);
1012 QCOMPARE(setSpy1.count(), 1);
1013 QCOMPARE(setSpy2.count(), 0);
1014
1015 seriesSpyArg = seriesSpy.takeFirst();
1016 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
1017 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1018 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
1019
1020 setSpyArg = setSpy1.takeFirst();
1021 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1022 QVERIFY(setSpyArg.at(0).toInt() == 1);
1023
1024 //====================================================================================
1025 // barset 1, bar 2
1026 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
1027 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1028
1029 QCOMPARE(seriesSpy.count(), 1);
1030 QCOMPARE(setSpy1.count(), 1);
1031 QCOMPARE(setSpy2.count(), 0);
1032
1033 seriesSpyArg = seriesSpy.takeFirst();
1034 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
1035 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1036 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
1037
1038 setSpyArg = setSpy1.takeFirst();
1039 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1040 QVERIFY(setSpyArg.at(0).toInt() == 2);
1041
1042 //====================================================================================
1043 // barset 2, bar 0
1044 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
1045 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1046
1047 QCOMPARE(seriesSpy.count(), 1);
1048 QCOMPARE(setSpy1.count(), 0);
1049 QCOMPARE(setSpy2.count(), 1);
1050
1051 seriesSpyArg = seriesSpy.takeFirst();
1052 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
1053 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1054 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
1055
1056 setSpyArg = setSpy2.takeFirst();
1057 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1058 QVERIFY(setSpyArg.at(0).toInt() == 0);
1059
1060 //====================================================================================
1061 // barset 2, bar 1
1062 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
1063 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1064
1065 QCOMPARE(seriesSpy.count(), 1);
1066 QCOMPARE(setSpy1.count(), 0);
1067 QCOMPARE(setSpy2.count(), 1);
1068
1069 seriesSpyArg = seriesSpy.takeFirst();
1070 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
1071 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1072 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
1073
1074 setSpyArg = setSpy2.takeFirst();
1075 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1076 QVERIFY(setSpyArg.at(0).toInt() == 1);
1077
1078 //====================================================================================
1079 // barset 2, bar 2
1080 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
1081 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1082
1083 QCOMPARE(seriesSpy.count(), 1);
1084 QCOMPARE(setSpy1.count(), 0);
1085 QCOMPARE(setSpy2.count(), 1);
1086
1087 seriesSpyArg = seriesSpy.takeFirst();
1088 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
1089 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1090 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
1091
1092 setSpyArg = setSpy2.takeFirst();
1093 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1094 QVERIFY(setSpyArg.at(0).toInt() == 2);
1095 }
1096
1097 void tst_QBarSeries::mouseReleased()
1098 {
1099 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
1100
1101 QBarSeries* series = new QBarSeries();
1102
1103 QBarSet* set1 = new QBarSet(QString("set 1"));
1104 *set1 << 10 << 10 << 10;
1105 series->append(set1);
1106
1107 QBarSet* set2 = new QBarSet(QString("set 2"));
1108 *set2 << 10 << 10 << 10;
1109 series->append(set2);
1110 QList<QBarSet*> barSets = series->barSets();
1111
1112 QSignalSpy seriesSpy(series,SIGNAL(released(int,QBarSet*)));
1113 QSignalSpy setSpy1(set1, SIGNAL(released(int)));
1114 QSignalSpy setSpy2(set2, SIGNAL(released(int)));
1115
1116 QChartView view(new QChart());
1117 view.resize(400,300);
1118 view.chart()->addSeries(series);
1119 view.show();
1120 QTest::qWaitForWindowShown(&view);
1121
1122 // Calculate expected layout for bars
1123 QRectF plotArea = view.chart()->plotArea();
1124 qreal width = plotArea.width();
1125 qreal height = plotArea.height();
1126 qreal rangeY = 10; // From 0 to 10 because of maximum value in set is 10
1127 qreal rangeX = 3; // 3 values per set
1128 qreal scaleY = (height / rangeY);
1129 qreal scaleX = (width / rangeX);
1130
1131 qreal setCount = series->count();
1132 qreal domainMinY = 0; // These come from internal domain used by barseries.
1133 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
1134 qreal rectWidth = (scaleX / setCount) * series->barWidth();
1135
1136 QVector<QRectF> layout;
1137
1138 // 3 = count of values in set
1139 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
1140 for (int i = 0; i < 3; i++) {
1141 qreal yPos = height + scaleY * domainMinY + plotArea.top();
1142 for (int set = 0; set < setCount; set++) {
1143 qreal xPos = (i - domainMinX) * scaleX + plotArea.left();
1144 xPos -= series->count()*rectWidth/2;
1145 xPos += set*rectWidth;
1146
1147 qreal rectHeight = barSets.at(set)->at(i) * scaleY;
1148 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
1149 layout.append(rect);
1150 }
1151 }
1152
1153 //====================================================================================
1154 // barset 1, bar 0
1155 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
1156 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1157
1158 QCOMPARE(seriesSpy.count(), 1);
1159 QCOMPARE(setSpy1.count(), 1);
1160 QCOMPARE(setSpy2.count(), 0);
1161
1162 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
1163 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
1164 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1165 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
1166
1167 QList<QVariant> setSpyArg = setSpy1.takeFirst();
1168 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1169 QVERIFY(setSpyArg.at(0).toInt() == 0);
1170
1171 //====================================================================================
1172 // barset 1, bar 1
1173 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
1174 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1175
1176 QCOMPARE(seriesSpy.count(), 1);
1177 QCOMPARE(setSpy1.count(), 1);
1178 QCOMPARE(setSpy2.count(), 0);
1179
1180 seriesSpyArg = seriesSpy.takeFirst();
1181 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
1182 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1183 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
1184
1185 setSpyArg = setSpy1.takeFirst();
1186 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1187 QVERIFY(setSpyArg.at(0).toInt() == 1);
1188
1189 //====================================================================================
1190 // barset 1, bar 2
1191 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
1192 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1193
1194 QCOMPARE(seriesSpy.count(), 1);
1195 QCOMPARE(setSpy1.count(), 1);
1196 QCOMPARE(setSpy2.count(), 0);
1197
1198 seriesSpyArg = seriesSpy.takeFirst();
1199 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
1200 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1201 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
1202
1203 setSpyArg = setSpy1.takeFirst();
1204 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1205 QVERIFY(setSpyArg.at(0).toInt() == 2);
1206
1207 //====================================================================================
1208 // barset 2, bar 0
1209 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
1210 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1211
1212 QCOMPARE(seriesSpy.count(), 1);
1213 QCOMPARE(setSpy1.count(), 0);
1214 QCOMPARE(setSpy2.count(), 1);
1215
1216 seriesSpyArg = seriesSpy.takeFirst();
1217 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
1218 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1219 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
1220
1221 setSpyArg = setSpy2.takeFirst();
1222 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1223 QVERIFY(setSpyArg.at(0).toInt() == 0);
1224
1225 //====================================================================================
1226 // barset 2, bar 1
1227 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
1228 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1229
1230 QCOMPARE(seriesSpy.count(), 1);
1231 QCOMPARE(setSpy1.count(), 0);
1232 QCOMPARE(setSpy2.count(), 1);
1233
1234 seriesSpyArg = seriesSpy.takeFirst();
1235 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
1236 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1237 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
1238
1239 setSpyArg = setSpy2.takeFirst();
1240 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1241 QVERIFY(setSpyArg.at(0).toInt() == 1);
1242
1243 //====================================================================================
1244 // barset 2, bar 2
1245 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
1246 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1247
1248 QCOMPARE(seriesSpy.count(), 1);
1249 QCOMPARE(setSpy1.count(), 0);
1250 QCOMPARE(setSpy2.count(), 1);
1251
1252 seriesSpyArg = seriesSpy.takeFirst();
1253 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
1254 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1255 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
1256
1257 setSpyArg = setSpy2.takeFirst();
1258 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1259 QVERIFY(setSpyArg.at(0).toInt() == 2);
1260 }
1261
1262 void tst_QBarSeries::mouseDoubleClicked()
1263 {
1264 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
1265
1266 QBarSeries* series = new QBarSeries();
1267
1268 QBarSet* set1 = new QBarSet(QString("set 1"));
1269 *set1 << 10 << 10 << 10;
1270 series->append(set1);
1271
1272 QBarSet* set2 = new QBarSet(QString("set 2"));
1273 *set2 << 10 << 10 << 10;
1274 series->append(set2);
1275 QList<QBarSet*> barSets = series->barSets();
1276
1277 QSignalSpy seriesSpy(series,SIGNAL(doubleClicked(int,QBarSet*)));
1278 QSignalSpy setSpy1(set1, SIGNAL(doubleClicked(int)));
1279 QSignalSpy setSpy2(set2, SIGNAL(doubleClicked(int)));
1280
1281 QChartView view(new QChart());
1282 view.resize(400,300);
1283 view.chart()->addSeries(series);
1284 view.show();
1285 QTest::qWaitForWindowShown(&view);
1286
1287 // Calculate expected layout for bars
1288 QRectF plotArea = view.chart()->plotArea();
1289 qreal width = plotArea.width();
1290 qreal height = plotArea.height();
1291 qreal rangeY = 10; // From 0 to 10 because of maximum value in set is 10
1292 qreal rangeX = 3; // 3 values per set
1293 qreal scaleY = (height / rangeY);
1294 qreal scaleX = (width / rangeX);
1295
1296 qreal setCount = series->count();
1297 qreal domainMinY = 0; // These come from internal domain used by barseries.
1298 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
1299 qreal rectWidth = (scaleX / setCount) * series->barWidth();
1300
1301 QVector<QRectF> layout;
1302
1303 // 3 = count of values in set
1304 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
1305 for (int i = 0; i < 3; i++) {
1306 qreal yPos = height + scaleY * domainMinY + plotArea.top();
1307 for (int set = 0; set < setCount; set++) {
1308 qreal xPos = (i - domainMinX) * scaleX + plotArea.left();
1309 xPos -= series->count()*rectWidth/2;
1310 xPos += set*rectWidth;
1311
1312 qreal rectHeight = barSets.at(set)->at(i) * scaleY;
1313 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
1314 layout.append(rect);
1315 }
1316 }
1317
1318 // barset 1, bar 0
1319 QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
1320 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1321
1322 QCOMPARE(seriesSpy.count(), 1);
1323 QCOMPARE(setSpy1.count(), 1);
1324 QCOMPARE(setSpy2.count(), 0);
1325
1326 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
1327 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
1328 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1329 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
1330
1331 QList<QVariant> setSpyArg = setSpy1.takeFirst();
1332 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1333 QVERIFY(setSpyArg.at(0).toInt() == 0);
1334 }
1335
929 QTEST_MAIN(tst_QBarSeries)
1336 QTEST_MAIN(tst_QBarSeries)
930
1337
931 #include "tst_qbarseries.moc"
1338 #include "tst_qbarseries.moc"
@@ -64,6 +64,9 private slots:
64 void mousehovered_data();
64 void mousehovered_data();
65 void mousehovered();
65 void mousehovered();
66 void clearWithAnimations();
66 void clearWithAnimations();
67 void mousePressed();
68 void mouseReleased();
69 void mouseDoubleClicked();
67
70
68 private:
71 private:
69 QHorizontalBarSeries* m_barseries;
72 QHorizontalBarSeries* m_barseries;
@@ -859,6 +862,409 void tst_QHorizontalBarSeries::clearWithAnimations()
859 series->clear();
862 series->clear();
860 }
863 }
861
864
865 void tst_QHorizontalBarSeries::mousePressed()
866 {
867 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
868
869 QHorizontalBarSeries* series = new QHorizontalBarSeries();
870
871 QBarSet* set1 = new QBarSet(QString("set 1"));
872 *set1 << 10 << 10 << 10;
873 series->append(set1);
874
875 QBarSet* set2 = new QBarSet(QString("set 2"));
876 *set2 << 10 << 10 << 10;
877 series->append(set2);
878 QList<QBarSet*> barSets = series->barSets();
879
880 QSignalSpy seriesSpy(series,SIGNAL(pressed(int,QBarSet*)));
881 QSignalSpy setSpy1(set1, SIGNAL(pressed(int)));
882 QSignalSpy setSpy2(set2, SIGNAL(pressed(int)));
883
884 QChartView view(new QChart());
885 view.resize(400,300);
886 view.chart()->addSeries(series);
887 view.show();
888 QTest::qWaitForWindowShown(&view);
889
890 // Calculate expected layout for bars
891 QRectF plotArea = view.chart()->plotArea();
892 qreal width = plotArea.width();
893 qreal height = plotArea.height();
894 qreal rangeX = 10; // From 0 to 10 because of maximum value in set is 10
895 qreal rangeY = 3; // 3 values per set
896 qreal scaleY = (height / rangeY);
897 qreal scaleX = (width / rangeX);
898
899 qreal setCount = series->count();
900 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
901 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
902 qreal rectHeight = (scaleY / setCount) * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
903
904 QVector<QRectF> layout;
905
906 // 3 = count of values in set
907 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
908 for (int i = 0; i < 3; i++) {
909 qreal xPos = -scaleX * domainMinX + plotArea.left();
910 for (int set = 0; set < setCount; set++) {
911 qreal yPos = plotArea.bottom() + (domainMinY - i) * scaleY;
912 yPos += setCount*rectHeight/2;
913 yPos -= set*rectHeight;
914
915 qreal rectWidth = barSets.at(set)->at(i) * scaleX;
916 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
917 layout.append(rect);
918 }
919 }
920
921 //====================================================================================
922 // barset 1, bar 0
923 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
924 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
925
926 QCOMPARE(seriesSpy.count(), 1);
927 QCOMPARE(setSpy1.count(), 1);
928 QCOMPARE(setSpy2.count(), 0);
929
930 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
931 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
932 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
933 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
934
935 QList<QVariant> setSpyArg = setSpy1.takeFirst();
936 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
937 QVERIFY(setSpyArg.at(0).toInt() == 0);
938
939 //====================================================================================
940 // barset 1, bar 1
941 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
942 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
943
944 QCOMPARE(seriesSpy.count(), 1);
945 QCOMPARE(setSpy1.count(), 1);
946 QCOMPARE(setSpy2.count(), 0);
947
948 seriesSpyArg = seriesSpy.takeFirst();
949 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
950 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
951 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
952
953 setSpyArg = setSpy1.takeFirst();
954 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
955 QVERIFY(setSpyArg.at(0).toInt() == 1);
956
957 //====================================================================================
958 // barset 1, bar 2
959 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
960 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
961
962 QCOMPARE(seriesSpy.count(), 1);
963 QCOMPARE(setSpy1.count(), 1);
964 QCOMPARE(setSpy2.count(), 0);
965
966 seriesSpyArg = seriesSpy.takeFirst();
967 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
968 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
969 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
970
971 setSpyArg = setSpy1.takeFirst();
972 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
973 QVERIFY(setSpyArg.at(0).toInt() == 2);
974
975 //====================================================================================
976 // barset 2, bar 0
977 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
978 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
979
980 QCOMPARE(seriesSpy.count(), 1);
981 QCOMPARE(setSpy1.count(), 0);
982 QCOMPARE(setSpy2.count(), 1);
983
984 seriesSpyArg = seriesSpy.takeFirst();
985 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
986 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
987 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
988
989 setSpyArg = setSpy2.takeFirst();
990 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
991 QVERIFY(setSpyArg.at(0).toInt() == 0);
992
993 //====================================================================================
994 // barset 2, bar 1
995 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
996 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
997
998 QCOMPARE(seriesSpy.count(), 1);
999 QCOMPARE(setSpy1.count(), 0);
1000 QCOMPARE(setSpy2.count(), 1);
1001
1002 seriesSpyArg = seriesSpy.takeFirst();
1003 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
1004 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1005 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
1006
1007 setSpyArg = setSpy2.takeFirst();
1008 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1009 QVERIFY(setSpyArg.at(0).toInt() == 1);
1010
1011 //====================================================================================
1012 // barset 2, bar 2
1013 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
1014 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1015
1016 QCOMPARE(seriesSpy.count(), 1);
1017 QCOMPARE(setSpy1.count(), 0);
1018 QCOMPARE(setSpy2.count(), 1);
1019
1020 seriesSpyArg = seriesSpy.takeFirst();
1021 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
1022 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1023 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
1024
1025 setSpyArg = setSpy2.takeFirst();
1026 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1027 QVERIFY(setSpyArg.at(0).toInt() == 2);
1028 }
1029
1030 void tst_QHorizontalBarSeries::mouseReleased()
1031 {
1032 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
1033
1034 QHorizontalBarSeries* series = new QHorizontalBarSeries();
1035
1036 QBarSet* set1 = new QBarSet(QString("set 1"));
1037 *set1 << 10 << 10 << 10;
1038 series->append(set1);
1039
1040 QBarSet* set2 = new QBarSet(QString("set 2"));
1041 *set2 << 10 << 10 << 10;
1042 series->append(set2);
1043 QList<QBarSet*> barSets = series->barSets();
1044
1045 QSignalSpy seriesSpy(series,SIGNAL(released(int,QBarSet*)));
1046 QSignalSpy setSpy1(set1, SIGNAL(released(int)));
1047 QSignalSpy setSpy2(set2, SIGNAL(released(int)));
1048
1049 QChartView view(new QChart());
1050 view.resize(400,300);
1051 view.chart()->addSeries(series);
1052 view.show();
1053 QTest::qWaitForWindowShown(&view);
1054
1055 // Calculate expected layout for bars
1056 QRectF plotArea = view.chart()->plotArea();
1057 qreal width = plotArea.width();
1058 qreal height = plotArea.height();
1059 qreal rangeX = 10; // From 0 to 10 because of maximum value in set is 10
1060 qreal rangeY = 3; // 3 values per set
1061 qreal scaleY = (height / rangeY);
1062 qreal scaleX = (width / rangeX);
1063
1064 qreal setCount = series->count();
1065 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
1066 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
1067 qreal rectHeight = (scaleY / setCount) * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
1068
1069 QVector<QRectF> layout;
1070
1071 // 3 = count of values in set
1072 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
1073 for (int i = 0; i < 3; i++) {
1074 qreal xPos = -scaleX * domainMinX + plotArea.left();
1075 for (int set = 0; set < setCount; set++) {
1076 qreal yPos = plotArea.bottom() + (domainMinY - i) * scaleY;
1077 yPos += setCount*rectHeight/2;
1078 yPos -= set*rectHeight;
1079
1080 qreal rectWidth = barSets.at(set)->at(i) * scaleX;
1081 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
1082 layout.append(rect);
1083 }
1084 }
1085
1086 //====================================================================================
1087 // barset 1, bar 0
1088 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
1089 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1090
1091 QCOMPARE(seriesSpy.count(), 1);
1092 QCOMPARE(setSpy1.count(), 1);
1093 QCOMPARE(setSpy2.count(), 0);
1094
1095 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
1096 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
1097 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1098 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
1099
1100 QList<QVariant> setSpyArg = setSpy1.takeFirst();
1101 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1102 QVERIFY(setSpyArg.at(0).toInt() == 0);
1103
1104 //====================================================================================
1105 // barset 1, bar 1
1106 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
1107 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1108
1109 QCOMPARE(seriesSpy.count(), 1);
1110 QCOMPARE(setSpy1.count(), 1);
1111 QCOMPARE(setSpy2.count(), 0);
1112
1113 seriesSpyArg = seriesSpy.takeFirst();
1114 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
1115 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1116 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
1117
1118 setSpyArg = setSpy1.takeFirst();
1119 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1120 QVERIFY(setSpyArg.at(0).toInt() == 1);
1121
1122 //====================================================================================
1123 // barset 1, bar 2
1124 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
1125 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1126
1127 QCOMPARE(seriesSpy.count(), 1);
1128 QCOMPARE(setSpy1.count(), 1);
1129 QCOMPARE(setSpy2.count(), 0);
1130
1131 seriesSpyArg = seriesSpy.takeFirst();
1132 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
1133 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1134 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
1135
1136 setSpyArg = setSpy1.takeFirst();
1137 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1138 QVERIFY(setSpyArg.at(0).toInt() == 2);
1139
1140 //====================================================================================
1141 // barset 2, bar 0
1142 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
1143 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1144
1145 QCOMPARE(seriesSpy.count(), 1);
1146 QCOMPARE(setSpy1.count(), 0);
1147 QCOMPARE(setSpy2.count(), 1);
1148
1149 seriesSpyArg = seriesSpy.takeFirst();
1150 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
1151 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1152 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
1153
1154 setSpyArg = setSpy2.takeFirst();
1155 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1156 QVERIFY(setSpyArg.at(0).toInt() == 0);
1157
1158 //====================================================================================
1159 // barset 2, bar 1
1160 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
1161 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1162
1163 QCOMPARE(seriesSpy.count(), 1);
1164 QCOMPARE(setSpy1.count(), 0);
1165 QCOMPARE(setSpy2.count(), 1);
1166
1167 seriesSpyArg = seriesSpy.takeFirst();
1168 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
1169 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1170 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
1171
1172 setSpyArg = setSpy2.takeFirst();
1173 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1174 QVERIFY(setSpyArg.at(0).toInt() == 1);
1175
1176 //====================================================================================
1177 // barset 2, bar 2
1178 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
1179 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1180
1181 QCOMPARE(seriesSpy.count(), 1);
1182 QCOMPARE(setSpy1.count(), 0);
1183 QCOMPARE(setSpy2.count(), 1);
1184
1185 seriesSpyArg = seriesSpy.takeFirst();
1186 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
1187 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1188 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
1189
1190 setSpyArg = setSpy2.takeFirst();
1191 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1192 QVERIFY(setSpyArg.at(0).toInt() == 2);
1193 }
1194
1195 void tst_QHorizontalBarSeries::mouseDoubleClicked()
1196 {
1197 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
1198
1199 QHorizontalBarSeries* series = new QHorizontalBarSeries();
1200
1201 QBarSet* set1 = new QBarSet(QString("set 1"));
1202 *set1 << 10 << 10 << 10;
1203 series->append(set1);
1204
1205 QBarSet* set2 = new QBarSet(QString("set 2"));
1206 *set2 << 10 << 10 << 10;
1207 series->append(set2);
1208 QList<QBarSet*> barSets = series->barSets();
1209
1210 QSignalSpy seriesSpy(series,SIGNAL(doubleClicked(int,QBarSet*)));
1211 QSignalSpy setSpy1(set1, SIGNAL(doubleClicked(int)));
1212 QSignalSpy setSpy2(set2, SIGNAL(doubleClicked(int)));
1213
1214 QChartView view(new QChart());
1215 view.resize(400,300);
1216 view.chart()->addSeries(series);
1217 view.show();
1218 QTest::qWaitForWindowShown(&view);
1219
1220 // Calculate expected layout for bars
1221 QRectF plotArea = view.chart()->plotArea();
1222 qreal width = plotArea.width();
1223 qreal height = plotArea.height();
1224 qreal rangeX = 10; // From 0 to 10 because of maximum value in set is 10
1225 qreal rangeY = 3; // 3 values per set
1226 qreal scaleY = (height / rangeY);
1227 qreal scaleX = (width / rangeX);
1228
1229 qreal setCount = series->count();
1230 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
1231 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
1232 qreal rectHeight = (scaleY / setCount) * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
1233
1234 QVector<QRectF> layout;
1235
1236 // 3 = count of values in set
1237 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
1238 for (int i = 0; i < 3; i++) {
1239 qreal xPos = -scaleX * domainMinX + plotArea.left();
1240 for (int set = 0; set < setCount; set++) {
1241 qreal yPos = plotArea.bottom() + (domainMinY - i) * scaleY;
1242 yPos += setCount*rectHeight/2;
1243 yPos -= set*rectHeight;
1244
1245 qreal rectWidth = barSets.at(set)->at(i) * scaleX;
1246 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
1247 layout.append(rect);
1248 }
1249 }
1250
1251 // barset 1, bar 0
1252 QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
1253 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1254
1255 QCOMPARE(seriesSpy.count(), 1);
1256 QCOMPARE(setSpy1.count(), 1);
1257 QCOMPARE(setSpy2.count(), 0);
1258
1259 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
1260 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
1261 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1262 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
1263
1264 QList<QVariant> setSpyArg = setSpy1.takeFirst();
1265 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1266 QVERIFY(setSpyArg.at(0).toInt() == 0);
1267 }
862 QTEST_MAIN(tst_QHorizontalBarSeries)
1268 QTEST_MAIN(tst_QHorizontalBarSeries)
863
1269
864 #include "tst_qhorizontalbarseries.moc"
1270 #include "tst_qhorizontalbarseries.moc"
@@ -52,6 +52,9 private slots:
52 void mousehovered_data();
52 void mousehovered_data();
53 void mousehovered();
53 void mousehovered();
54 void zeroValuesInSeries();
54 void zeroValuesInSeries();
55 void mousePressed();
56 void mouseReleased();
57 void mouseDoubleClicked();
55
58
56 private:
59 private:
57 QHorizontalPercentBarSeries* m_barseries;
60 QHorizontalPercentBarSeries* m_barseries;
@@ -604,6 +607,411 void tst_QHorizontalPercentBarSeries::zeroValuesInSeries()
604 QTest::qWaitForWindowShown(&view);
607 QTest::qWaitForWindowShown(&view);
605 }
608 }
606
609
610
611 void tst_QHorizontalPercentBarSeries::mousePressed()
612 {
613 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
614
615 QHorizontalPercentBarSeries* series = new QHorizontalPercentBarSeries();
616
617 QBarSet* set1 = new QBarSet(QString("set 1"));
618 *set1 << 10 << 10 << 10;
619 series->append(set1);
620
621 QBarSet* set2 = new QBarSet(QString("set 2"));
622 *set2 << 10 << 10 << 10;
623 series->append(set2);
624 QList<QBarSet*> barSets = series->barSets();
625
626 QSignalSpy seriesSpy(series,SIGNAL(pressed(int,QBarSet*)));
627 QSignalSpy setSpy1(set1, SIGNAL(pressed(int)));
628 QSignalSpy setSpy2(set2, SIGNAL(pressed(int)));
629
630 QChartView view(new QChart());
631 view.resize(400,300);
632 view.chart()->addSeries(series);
633 view.show();
634 QTest::qWaitForWindowShown(&view);
635
636 // Calculate expected layout for bars
637 QRectF plotArea = view.chart()->plotArea();
638 qreal width = plotArea.width();
639 qreal height = plotArea.height();
640 qreal rangeX = 100; // From 0 to 100 because of scaling to 100%
641 qreal rangeY = 3; // 3 values per set
642 qreal scaleY = (height / rangeY);
643 qreal scaleX = (width / rangeX);
644
645 qreal setCount = series->count();
646 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
647 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
648 qreal rectHeight = scaleY * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
649
650 QVector<QRectF> layout;
651
652 // 3 = count of values in set
653 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
654 for (int i = 0; i < 3; i++) {
655 qreal colSum = 20; // Sum of values in column (10 + 10 in our test case)
656 qreal percentage = (100 / colSum);
657 qreal xPos = -scaleX * domainMinX + plotArea.left();
658 for (int set = 0; set < setCount; set++) {
659 qreal yPos = (domainMinY +0.5 -i) * scaleY + plotArea.bottom() - rectHeight/2;
660 qreal rectWidth = barSets.at(set)->at(i) * percentage * scaleX;
661 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
662 layout.append(rect);
663 xPos += rectWidth;
664 }
665 }
666
667 //====================================================================================
668 // barset 1, bar 0
669 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
670 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
671
672 QCOMPARE(seriesSpy.count(), 1);
673 QCOMPARE(setSpy1.count(), 1);
674 QCOMPARE(setSpy2.count(), 0);
675
676 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
677 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
678 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
679 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
680
681 QList<QVariant> setSpyArg = setSpy1.takeFirst();
682 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
683 QVERIFY(setSpyArg.at(0).toInt() == 0);
684
685 //====================================================================================
686 // barset 1, bar 1
687 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
688 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
689
690 QCOMPARE(seriesSpy.count(), 1);
691 QCOMPARE(setSpy1.count(), 1);
692 QCOMPARE(setSpy2.count(), 0);
693
694 seriesSpyArg = seriesSpy.takeFirst();
695 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
696 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
697 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
698
699 setSpyArg = setSpy1.takeFirst();
700 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
701 QVERIFY(setSpyArg.at(0).toInt() == 1);
702
703 //====================================================================================
704 // barset 1, bar 2
705 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
706 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
707
708 QCOMPARE(seriesSpy.count(), 1);
709 QCOMPARE(setSpy1.count(), 1);
710 QCOMPARE(setSpy2.count(), 0);
711
712 seriesSpyArg = seriesSpy.takeFirst();
713 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
714 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
715 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
716
717 setSpyArg = setSpy1.takeFirst();
718 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
719 QVERIFY(setSpyArg.at(0).toInt() == 2);
720
721 //====================================================================================
722 // barset 2, bar 0
723 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
724 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
725
726 QCOMPARE(seriesSpy.count(), 1);
727 QCOMPARE(setSpy1.count(), 0);
728 QCOMPARE(setSpy2.count(), 1);
729
730 seriesSpyArg = seriesSpy.takeFirst();
731 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
732 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
733 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
734
735 setSpyArg = setSpy2.takeFirst();
736 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
737 QVERIFY(setSpyArg.at(0).toInt() == 0);
738
739 //====================================================================================
740 // barset 2, bar 1
741 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
742 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
743
744 QCOMPARE(seriesSpy.count(), 1);
745 QCOMPARE(setSpy1.count(), 0);
746 QCOMPARE(setSpy2.count(), 1);
747
748 seriesSpyArg = seriesSpy.takeFirst();
749 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
750 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
751 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
752
753 setSpyArg = setSpy2.takeFirst();
754 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
755 QVERIFY(setSpyArg.at(0).toInt() == 1);
756
757 //====================================================================================
758 // barset 2, bar 2
759 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
760 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
761
762 QCOMPARE(seriesSpy.count(), 1);
763 QCOMPARE(setSpy1.count(), 0);
764 QCOMPARE(setSpy2.count(), 1);
765
766 seriesSpyArg = seriesSpy.takeFirst();
767 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
768 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
769 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
770
771 setSpyArg = setSpy2.takeFirst();
772 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
773 QVERIFY(setSpyArg.at(0).toInt() == 2);
774 }
775
776 void tst_QHorizontalPercentBarSeries::mouseReleased()
777 {
778 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
779
780 QHorizontalPercentBarSeries* series = new QHorizontalPercentBarSeries();
781
782 QBarSet* set1 = new QBarSet(QString("set 1"));
783 *set1 << 10 << 10 << 10;
784 series->append(set1);
785
786 QBarSet* set2 = new QBarSet(QString("set 2"));
787 *set2 << 10 << 10 << 10;
788 series->append(set2);
789 QList<QBarSet*> barSets = series->barSets();
790
791 QSignalSpy seriesSpy(series,SIGNAL(released(int,QBarSet*)));
792 QSignalSpy setSpy1(set1, SIGNAL(released(int)));
793 QSignalSpy setSpy2(set2, SIGNAL(released(int)));
794
795 QChartView view(new QChart());
796 view.resize(400,300);
797 view.chart()->addSeries(series);
798 view.show();
799 QTest::qWaitForWindowShown(&view);
800
801 // Calculate expected layout for bars
802 QRectF plotArea = view.chart()->plotArea();
803 qreal width = plotArea.width();
804 qreal height = plotArea.height();
805 qreal rangeX = 100; // From 0 to 100 because of scaling to 100%
806 qreal rangeY = 3; // 3 values per set
807 qreal scaleY = (height / rangeY);
808 qreal scaleX = (width / rangeX);
809
810 qreal setCount = series->count();
811 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
812 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
813 qreal rectHeight = scaleY * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
814
815 QVector<QRectF> layout;
816
817 // 3 = count of values in set
818 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
819 for (int i = 0; i < 3; i++) {
820 qreal colSum = 20; // Sum of values in column (10 + 10 in our test case)
821 qreal percentage = (100 / colSum);
822 qreal xPos = -scaleX * domainMinX + plotArea.left();
823 for (int set = 0; set < setCount; set++) {
824 qreal yPos = (domainMinY +0.5 -i) * scaleY + plotArea.bottom() - rectHeight/2;
825 qreal rectWidth = barSets.at(set)->at(i) * percentage * scaleX;
826 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
827 layout.append(rect);
828 xPos += rectWidth;
829 }
830 }
831
832 //====================================================================================
833 // barset 1, bar 0
834 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
835 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
836
837 QCOMPARE(seriesSpy.count(), 1);
838 QCOMPARE(setSpy1.count(), 1);
839 QCOMPARE(setSpy2.count(), 0);
840
841 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
842 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
843 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
844 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
845
846 QList<QVariant> setSpyArg = setSpy1.takeFirst();
847 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
848 QVERIFY(setSpyArg.at(0).toInt() == 0);
849
850 //====================================================================================
851 // barset 1, bar 1
852 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
853 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
854
855 QCOMPARE(seriesSpy.count(), 1);
856 QCOMPARE(setSpy1.count(), 1);
857 QCOMPARE(setSpy2.count(), 0);
858
859 seriesSpyArg = seriesSpy.takeFirst();
860 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
861 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
862 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
863
864 setSpyArg = setSpy1.takeFirst();
865 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
866 QVERIFY(setSpyArg.at(0).toInt() == 1);
867
868 //====================================================================================
869 // barset 1, bar 2
870 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
871 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
872
873 QCOMPARE(seriesSpy.count(), 1);
874 QCOMPARE(setSpy1.count(), 1);
875 QCOMPARE(setSpy2.count(), 0);
876
877 seriesSpyArg = seriesSpy.takeFirst();
878 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
879 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
880 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
881
882 setSpyArg = setSpy1.takeFirst();
883 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
884 QVERIFY(setSpyArg.at(0).toInt() == 2);
885
886 //====================================================================================
887 // barset 2, bar 0
888 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
889 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
890
891 QCOMPARE(seriesSpy.count(), 1);
892 QCOMPARE(setSpy1.count(), 0);
893 QCOMPARE(setSpy2.count(), 1);
894
895 seriesSpyArg = seriesSpy.takeFirst();
896 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
897 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
898 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
899
900 setSpyArg = setSpy2.takeFirst();
901 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
902 QVERIFY(setSpyArg.at(0).toInt() == 0);
903
904 //====================================================================================
905 // barset 2, bar 1
906 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
907 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
908
909 QCOMPARE(seriesSpy.count(), 1);
910 QCOMPARE(setSpy1.count(), 0);
911 QCOMPARE(setSpy2.count(), 1);
912
913 seriesSpyArg = seriesSpy.takeFirst();
914 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
915 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
916 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
917
918 setSpyArg = setSpy2.takeFirst();
919 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
920 QVERIFY(setSpyArg.at(0).toInt() == 1);
921
922 //====================================================================================
923 // barset 2, bar 2
924 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
925 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
926
927 QCOMPARE(seriesSpy.count(), 1);
928 QCOMPARE(setSpy1.count(), 0);
929 QCOMPARE(setSpy2.count(), 1);
930
931 seriesSpyArg = seriesSpy.takeFirst();
932 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
933 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
934 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
935
936 setSpyArg = setSpy2.takeFirst();
937 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
938 QVERIFY(setSpyArg.at(0).toInt() == 2);
939 }
940
941 void tst_QHorizontalPercentBarSeries::mouseDoubleClicked()
942 {
943 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
944
945 QHorizontalPercentBarSeries* series = new QHorizontalPercentBarSeries();
946
947 QBarSet* set1 = new QBarSet(QString("set 1"));
948 *set1 << 10 << 10 << 10;
949 series->append(set1);
950
951 QBarSet* set2 = new QBarSet(QString("set 2"));
952 *set2 << 10 << 10 << 10;
953 series->append(set2);
954 QList<QBarSet*> barSets = series->barSets();
955
956 QSignalSpy seriesSpy(series,SIGNAL(doubleClicked(int,QBarSet*)));
957 QSignalSpy setSpy1(set1, SIGNAL(doubleClicked(int)));
958 QSignalSpy setSpy2(set2, SIGNAL(doubleClicked(int)));
959
960 QChartView view(new QChart());
961 view.resize(400,300);
962 view.chart()->addSeries(series);
963 view.show();
964 QTest::qWaitForWindowShown(&view);
965
966 // Calculate expected layout for bars
967 QRectF plotArea = view.chart()->plotArea();
968 qreal width = plotArea.width();
969 qreal height = plotArea.height();
970 qreal rangeX = 100; // From 0 to 100 because of scaling to 100%
971 qreal rangeY = 3; // 3 values per set
972 qreal scaleY = (height / rangeY);
973 qreal scaleX = (width / rangeX);
974
975 qreal setCount = series->count();
976 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
977 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
978 qreal rectHeight = scaleY * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
979
980 QVector<QRectF> layout;
981
982 // 3 = count of values in set
983 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
984 for (int i = 0; i < 3; i++) {
985 qreal colSum = 20; // Sum of values in column (10 + 10 in our test case)
986 qreal percentage = (100 / colSum);
987 qreal xPos = -scaleX * domainMinX + plotArea.left();
988 for (int set = 0; set < setCount; set++) {
989 qreal yPos = (domainMinY +0.5 -i) * scaleY + plotArea.bottom() - rectHeight/2;
990 qreal rectWidth = barSets.at(set)->at(i) * percentage * scaleX;
991 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
992 layout.append(rect);
993 xPos += rectWidth;
994 }
995 }
996
997 // barset 1, bar 0
998 QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
999 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1000
1001 QCOMPARE(seriesSpy.count(), 1);
1002 QCOMPARE(setSpy1.count(), 1);
1003 QCOMPARE(setSpy2.count(), 0);
1004
1005 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
1006 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
1007 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1008 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
1009
1010 QList<QVariant> setSpyArg = setSpy1.takeFirst();
1011 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1012 QVERIFY(setSpyArg.at(0).toInt() == 0);
1013 }
1014
607 QTEST_MAIN(tst_QHorizontalPercentBarSeries)
1015 QTEST_MAIN(tst_QHorizontalPercentBarSeries)
608
1016
609 #include "tst_qhorizontalpercentbarseries.moc"
1017 #include "tst_qhorizontalpercentbarseries.moc"
@@ -51,6 +51,9 private slots:
51 void mouseclicked();
51 void mouseclicked();
52 void mousehovered_data();
52 void mousehovered_data();
53 void mousehovered();
53 void mousehovered();
54 void mousePressed();
55 void mouseReleased();
56 void mouseDoubleClicked();
54
57
55 private:
58 private:
56 QHorizontalStackedBarSeries* m_barseries;
59 QHorizontalStackedBarSeries* m_barseries;
@@ -594,6 +597,424 void tst_QHorizontalStackedBarSeries::mousehovered()
594 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
597 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
595 }
598 }
596
599
600 void tst_QHorizontalStackedBarSeries::mousePressed()
601 {
602 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
603
604 QHorizontalStackedBarSeries* series = new QHorizontalStackedBarSeries();
605
606 QBarSet* set1 = new QBarSet(QString("set 1"));
607 *set1 << 10 << 10 << 10;
608 series->append(set1);
609
610 QBarSet* set2 = new QBarSet(QString("set 2"));
611 *set2 << 10 << 10 << 10;
612 series->append(set2);
613 QList<QBarSet*> barSets = series->barSets();
614
615 QSignalSpy seriesSpy(series,SIGNAL(pressed(int,QBarSet*)));
616 QSignalSpy setSpy1(set1, SIGNAL(pressed(int)));
617 QSignalSpy setSpy2(set2, SIGNAL(pressed(int)));
618
619 QChartView view(new QChart());
620 view.resize(400,300);
621 view.chart()->addSeries(series);
622 view.show();
623 QTest::qWaitForWindowShown(&view);
624
625 // Calculate expected layout for bars
626 QRectF plotArea = view.chart()->plotArea();
627 qreal width = plotArea.width();
628 qreal height = plotArea.height();
629 qreal rangeY = 3; // 3 values per set
630 qreal rangeX = 20; // From 0 to 20 because bars are stacked (this should be height of highest stack)
631 qreal scaleY = (height / rangeY);
632 qreal scaleX = (width / rangeX);
633
634 qreal setCount = series->count();
635 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
636 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
637 qreal rectHeight = scaleY * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
638
639 QVector<QRectF> layout;
640
641 // 3 = count of values in set
642 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
643 for (int i = 0; i < 3; i++) {
644 qreal xMax = -scaleX * domainMinX + plotArea.left();
645 qreal xMin = -scaleX * domainMinX + plotArea.left();
646 for (int set = 0; set < setCount; set++) {
647 qreal yPos = (domainMinY +0.5 -i) * scaleY + plotArea.bottom() - rectHeight/2;
648 qreal rectWidth = barSets.at(set)->at(i) * scaleX;
649 if (rectWidth > 0) {
650 QRectF rect(xMax, yPos - rectHeight, rectWidth, rectHeight);
651 layout.append(rect);
652 xMax += rectWidth;
653 } else {
654 QRectF rect(xMin, yPos - rectHeight, rectWidth, rectHeight);
655 layout.append(rect);
656 xMin += rectWidth;
657 }
658 }
659 }
660
661 //====================================================================================
662 // barset 1, bar 0
663 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
664 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
665
666 QCOMPARE(seriesSpy.count(), 1);
667 QCOMPARE(setSpy1.count(), 1);
668 QCOMPARE(setSpy2.count(), 0);
669
670 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
671 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
672 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
673 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
674
675 QList<QVariant> setSpyArg = setSpy1.takeFirst();
676 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
677 QVERIFY(setSpyArg.at(0).toInt() == 0);
678
679 //====================================================================================
680 // barset 1, bar 1
681 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
682 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
683
684 QCOMPARE(seriesSpy.count(), 1);
685 QCOMPARE(setSpy1.count(), 1);
686 QCOMPARE(setSpy2.count(), 0);
687
688 seriesSpyArg = seriesSpy.takeFirst();
689 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
690 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
691 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
692
693 setSpyArg = setSpy1.takeFirst();
694 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
695 QVERIFY(setSpyArg.at(0).toInt() == 1);
696
697 //====================================================================================
698 // barset 1, bar 2
699 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
700 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
701
702 QCOMPARE(seriesSpy.count(), 1);
703 QCOMPARE(setSpy1.count(), 1);
704 QCOMPARE(setSpy2.count(), 0);
705
706 seriesSpyArg = seriesSpy.takeFirst();
707 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
708 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
709 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
710
711 setSpyArg = setSpy1.takeFirst();
712 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
713 QVERIFY(setSpyArg.at(0).toInt() == 2);
714
715 //====================================================================================
716 // barset 2, bar 0
717 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
718 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
719
720 QCOMPARE(seriesSpy.count(), 1);
721 QCOMPARE(setSpy1.count(), 0);
722 QCOMPARE(setSpy2.count(), 1);
723
724 seriesSpyArg = seriesSpy.takeFirst();
725 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
726 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
727 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
728
729 setSpyArg = setSpy2.takeFirst();
730 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
731 QVERIFY(setSpyArg.at(0).toInt() == 0);
732
733 //====================================================================================
734 // barset 2, bar 1
735 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
736 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
737
738 QCOMPARE(seriesSpy.count(), 1);
739 QCOMPARE(setSpy1.count(), 0);
740 QCOMPARE(setSpy2.count(), 1);
741
742 seriesSpyArg = seriesSpy.takeFirst();
743 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
744 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
745 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
746
747 setSpyArg = setSpy2.takeFirst();
748 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
749 QVERIFY(setSpyArg.at(0).toInt() == 1);
750
751 //====================================================================================
752 // barset 2, bar 2
753 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
754 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
755
756 QCOMPARE(seriesSpy.count(), 1);
757 QCOMPARE(setSpy1.count(), 0);
758 QCOMPARE(setSpy2.count(), 1);
759
760 seriesSpyArg = seriesSpy.takeFirst();
761 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
762 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
763 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
764
765 setSpyArg = setSpy2.takeFirst();
766 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
767 QVERIFY(setSpyArg.at(0).toInt() == 2);
768 }
769
770 void tst_QHorizontalStackedBarSeries::mouseReleased()
771 {
772 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
773
774 QHorizontalStackedBarSeries* series = new QHorizontalStackedBarSeries();
775
776 QBarSet* set1 = new QBarSet(QString("set 1"));
777 *set1 << 10 << 10 << 10;
778 series->append(set1);
779
780 QBarSet* set2 = new QBarSet(QString("set 2"));
781 *set2 << 10 << 10 << 10;
782 series->append(set2);
783 QList<QBarSet*> barSets = series->barSets();
784
785 QSignalSpy seriesSpy(series,SIGNAL(released(int,QBarSet*)));
786 QSignalSpy setSpy1(set1, SIGNAL(released(int)));
787 QSignalSpy setSpy2(set2, SIGNAL(released(int)));
788
789 QChartView view(new QChart());
790 view.resize(400,300);
791 view.chart()->addSeries(series);
792 view.show();
793 QTest::qWaitForWindowShown(&view);
794
795 // Calculate expected layout for bars
796 QRectF plotArea = view.chart()->plotArea();
797 qreal width = plotArea.width();
798 qreal height = plotArea.height();
799 qreal rangeY = 3; // 3 values per set
800 qreal rangeX = 20; // From 0 to 20 because bars are stacked (this should be height of highest stack)
801 qreal scaleY = (height / rangeY);
802 qreal scaleX = (width / rangeX);
803
804 qreal setCount = series->count();
805 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
806 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
807 qreal rectHeight = scaleY * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
808
809 QVector<QRectF> layout;
810
811 // 3 = count of values in set
812 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
813 for (int i = 0; i < 3; i++) {
814 qreal xMax = -scaleX * domainMinX + plotArea.left();
815 qreal xMin = -scaleX * domainMinX + plotArea.left();
816 for (int set = 0; set < setCount; set++) {
817 qreal yPos = (domainMinY +0.5 -i) * scaleY + plotArea.bottom() - rectHeight/2;
818 qreal rectWidth = barSets.at(set)->at(i) * scaleX;
819 if (rectWidth > 0) {
820 QRectF rect(xMax, yPos - rectHeight, rectWidth, rectHeight);
821 layout.append(rect);
822 xMax += rectWidth;
823 } else {
824 QRectF rect(xMin, yPos - rectHeight, rectWidth, rectHeight);
825 layout.append(rect);
826 xMin += rectWidth;
827 }
828 }
829 }
830
831 //====================================================================================
832 // barset 1, bar 0
833 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
834 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
835
836 QCOMPARE(seriesSpy.count(), 1);
837 QCOMPARE(setSpy1.count(), 1);
838 QCOMPARE(setSpy2.count(), 0);
839
840 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
841 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
842 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
843 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
844
845 QList<QVariant> setSpyArg = setSpy1.takeFirst();
846 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
847 QVERIFY(setSpyArg.at(0).toInt() == 0);
848
849 //====================================================================================
850 // barset 1, bar 1
851 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
852 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
853
854 QCOMPARE(seriesSpy.count(), 1);
855 QCOMPARE(setSpy1.count(), 1);
856 QCOMPARE(setSpy2.count(), 0);
857
858 seriesSpyArg = seriesSpy.takeFirst();
859 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
860 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
861 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
862
863 setSpyArg = setSpy1.takeFirst();
864 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
865 QVERIFY(setSpyArg.at(0).toInt() == 1);
866
867 //====================================================================================
868 // barset 1, bar 2
869 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
870 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
871
872 QCOMPARE(seriesSpy.count(), 1);
873 QCOMPARE(setSpy1.count(), 1);
874 QCOMPARE(setSpy2.count(), 0);
875
876 seriesSpyArg = seriesSpy.takeFirst();
877 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
878 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
879 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
880
881 setSpyArg = setSpy1.takeFirst();
882 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
883 QVERIFY(setSpyArg.at(0).toInt() == 2);
884
885 //====================================================================================
886 // barset 2, bar 0
887 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
888 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
889
890 QCOMPARE(seriesSpy.count(), 1);
891 QCOMPARE(setSpy1.count(), 0);
892 QCOMPARE(setSpy2.count(), 1);
893
894 seriesSpyArg = seriesSpy.takeFirst();
895 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
896 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
897 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
898
899 setSpyArg = setSpy2.takeFirst();
900 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
901 QVERIFY(setSpyArg.at(0).toInt() == 0);
902
903 //====================================================================================
904 // barset 2, bar 1
905 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
906 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
907
908 QCOMPARE(seriesSpy.count(), 1);
909 QCOMPARE(setSpy1.count(), 0);
910 QCOMPARE(setSpy2.count(), 1);
911
912 seriesSpyArg = seriesSpy.takeFirst();
913 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
914 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
915 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
916
917 setSpyArg = setSpy2.takeFirst();
918 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
919 QVERIFY(setSpyArg.at(0).toInt() == 1);
920
921 //====================================================================================
922 // barset 2, bar 2
923 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
924 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
925
926 QCOMPARE(seriesSpy.count(), 1);
927 QCOMPARE(setSpy1.count(), 0);
928 QCOMPARE(setSpy2.count(), 1);
929
930 seriesSpyArg = seriesSpy.takeFirst();
931 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
932 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
933 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
934
935 setSpyArg = setSpy2.takeFirst();
936 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
937 QVERIFY(setSpyArg.at(0).toInt() == 2);
938 }
939
940 void tst_QHorizontalStackedBarSeries::mouseDoubleClicked()
941 {
942 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
943
944 QHorizontalStackedBarSeries* series = new QHorizontalStackedBarSeries();
945
946 QBarSet* set1 = new QBarSet(QString("set 1"));
947 *set1 << 10 << 10 << 10;
948 series->append(set1);
949
950 QBarSet* set2 = new QBarSet(QString("set 2"));
951 *set2 << 10 << 10 << 10;
952 series->append(set2);
953 QList<QBarSet*> barSets = series->barSets();
954
955 QSignalSpy seriesSpy(series,SIGNAL(doubleClicked(int,QBarSet*)));
956 QSignalSpy setSpy1(set1, SIGNAL(doubleClicked(int)));
957 QSignalSpy setSpy2(set2, SIGNAL(doubleClicked(int)));
958
959 QChartView view(new QChart());
960 view.resize(400,300);
961 view.chart()->addSeries(series);
962 view.show();
963 QTest::qWaitForWindowShown(&view);
964
965 // Calculate expected layout for bars
966 QRectF plotArea = view.chart()->plotArea();
967 qreal width = plotArea.width();
968 qreal height = plotArea.height();
969 qreal rangeY = 3; // 3 values per set
970 qreal rangeX = 20; // From 0 to 20 because bars are stacked (this should be height of highest stack)
971 qreal scaleY = (height / rangeY);
972 qreal scaleX = (width / rangeX);
973
974 qreal setCount = series->count();
975 qreal domainMinY = -0.5; // These come from internal domain used by barseries.
976 qreal domainMinX = 0; // No access to domain from outside, so use hard coded values.
977 qreal rectHeight = scaleY * series->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
978
979 QVector<QRectF> layout;
980
981 // 3 = count of values in set
982 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
983 for (int i = 0; i < 3; i++) {
984 qreal xMax = -scaleX * domainMinX + plotArea.left();
985 qreal xMin = -scaleX * domainMinX + plotArea.left();
986 for (int set = 0; set < setCount; set++) {
987 qreal yPos = (domainMinY +0.5 -i) * scaleY + plotArea.bottom() - rectHeight/2;
988 qreal rectWidth = barSets.at(set)->at(i) * scaleX;
989 if (rectWidth > 0) {
990 QRectF rect(xMax, yPos - rectHeight, rectWidth, rectHeight);
991 layout.append(rect);
992 xMax += rectWidth;
993 } else {
994 QRectF rect(xMin, yPos - rectHeight, rectWidth, rectHeight);
995 layout.append(rect);
996 xMin += rectWidth;
997 }
998 }
999 }
1000
1001 // barset 1, bar 0
1002 QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
1003 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1004
1005 QCOMPARE(seriesSpy.count(), 1);
1006 QCOMPARE(setSpy1.count(), 1);
1007 QCOMPARE(setSpy2.count(), 0);
1008
1009 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
1010 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
1011 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1012 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
1013
1014 QList<QVariant> setSpyArg = setSpy1.takeFirst();
1015 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1016 QVERIFY(setSpyArg.at(0).toInt() == 0);
1017 }
597 QTEST_MAIN(tst_QHorizontalStackedBarSeries)
1018 QTEST_MAIN(tst_QHorizontalStackedBarSeries)
598
1019
599 #include "tst_qhorizontalstackedbarseries.moc"
1020 #include "tst_qhorizontalstackedbarseries.moc"
@@ -36,6 +36,9 public slots:
36 private slots:
36 private slots:
37 void qlineseries_data();
37 void qlineseries_data();
38 void qlineseries();
38 void qlineseries();
39 void pressedSignal();
40 void releasedSignal();
41 void doubleClickedSignal();
39 protected:
42 protected:
40 void pointsVisible_data();
43 void pointsVisible_data();
41 };
44 };
@@ -102,6 +105,99 void tst_QLineSeries::qlineseries()
102 QTest::qWaitForWindowShown(m_view);
105 QTest::qWaitForWindowShown(m_view);
103 }
106 }
104
107
108 void tst_QLineSeries::pressedSignal()
109 {
110 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
111
112 QPointF linePoint(4, 12);
113 QLineSeries *lineSeries = new QLineSeries();
114 lineSeries->append(QPointF(2, 1));
115 lineSeries->append(linePoint);
116 lineSeries->append(QPointF(6, 12));
117
118 QChartView view;
119 view.chart()->legend()->setVisible(false);
120 view.chart()->addSeries(lineSeries);
121 view.show();
122 QTest::qWaitForWindowShown(&view);
123
124 QSignalSpy seriesSpy(lineSeries, SIGNAL(pressed(QPointF)));
125
126 QPointF checkPoint = view.chart()->mapToPosition(linePoint);
127 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
128 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
129
130 QCOMPARE(seriesSpy.count(), 1);
131 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
132 // checkPoint is QPointF and for the mouseClick it it's changed to QPoint
133 // this causes small distinction in decimals so we round it before comparing
134 QPointF signalPoint = qvariant_cast<QPointF>(seriesSpyArg.at(0));
135 QCOMPARE(qRound(signalPoint.x()), qRound(linePoint.x()));
136 QCOMPARE(qRound(signalPoint.y()), qRound(linePoint.y()));
137 }
138
139 void tst_QLineSeries::releasedSignal()
140 {
141 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
142
143 QPointF linePoint(4, 12);
144 QLineSeries *lineSeries = new QLineSeries();
145 lineSeries->append(QPointF(2, 20));
146 lineSeries->append(linePoint);
147 lineSeries->append(QPointF(6, 12));
148
149 QChartView view;
150 view.chart()->legend()->setVisible(false);
151 view.chart()->addSeries(lineSeries);
152 view.show();
153 QTest::qWaitForWindowShown(&view);
154
155 QSignalSpy seriesSpy(lineSeries, SIGNAL(released(QPointF)));
156
157 QPointF checkPoint = view.chart()->mapToPosition(linePoint);
158 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
159 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
160
161 QCOMPARE(seriesSpy.count(), 1);
162 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
163 // checkPoint is QPointF and for the mouseClick it it's changed to QPoint
164 // this causes small distinction in decimals so we round it before comparing
165 QPointF signalPoint = qvariant_cast<QPointF>(seriesSpyArg.at(0));
166 QCOMPARE(qRound(signalPoint.x()), qRound(linePoint.x()));
167 QCOMPARE(qRound(signalPoint.y()), qRound(linePoint.y()));
168 }
169
170 void tst_QLineSeries::doubleClickedSignal()
171 {
172 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
173
174 QPointF linePoint(4, 12);
175 QLineSeries *lineSeries = new QLineSeries();
176 lineSeries->append(QPointF(2, 20));
177 lineSeries->append(linePoint);
178 lineSeries->append(QPointF(6, 12));
179
180 QChartView view;
181 view.chart()->legend()->setVisible(false);
182 view.chart()->addSeries(lineSeries);
183 view.show();
184 QTest::qWaitForWindowShown(&view);
185
186 QSignalSpy seriesSpy(lineSeries, SIGNAL(doubleClicked(QPointF)));
187
188 QPointF checkPoint = view.chart()->mapToPosition(linePoint);
189 QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
190 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
191
192 QCOMPARE(seriesSpy.count(), 1);
193 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
194 // checkPoint is QPointF and for the mouseClick it it's changed to QPoint
195 // this causes small distinction in decimals so we round it before comparing
196 QPointF signalPoint = qvariant_cast<QPointF>(seriesSpyArg.at(0));
197 QCOMPARE(qRound(signalPoint.x()), qRound(linePoint.x()));
198 QCOMPARE(qRound(signalPoint.y()), qRound(linePoint.y()));
199 }
200
105 QTEST_MAIN(tst_QLineSeries)
201 QTEST_MAIN(tst_QLineSeries)
106
202
107 #include "tst_qlineseries.moc"
203 #include "tst_qlineseries.moc"
@@ -52,6 +52,9 private slots:
52 void mousehovered_data();
52 void mousehovered_data();
53 void mousehovered();
53 void mousehovered();
54 void zeroValuesInSeries();
54 void zeroValuesInSeries();
55 void mousePressed();
56 void mouseReleased();
57 void mouseDoubleClicked();
55
58
56 private:
59 private:
57 QPercentBarSeries* m_barseries;
60 QPercentBarSeries* m_barseries;
@@ -608,6 +611,416 void tst_QPercentBarSeries::zeroValuesInSeries()
608 QTest::qWaitForWindowShown(&view);
611 QTest::qWaitForWindowShown(&view);
609 }
612 }
610
613
614 void tst_QPercentBarSeries::mousePressed()
615 {
616 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
617
618 QPercentBarSeries* series = new QPercentBarSeries();
619
620 QBarSet* set1 = new QBarSet(QString("set 1"));
621 *set1 << 10 << 10 << 10;
622 series->append(set1);
623
624 QBarSet* set2 = new QBarSet(QString("set 2"));
625 *set2 << 10 << 10 << 10;
626 series->append(set2);
627 QList<QBarSet*> barSets = series->barSets();
628
629 QSignalSpy seriesSpy(series,SIGNAL(pressed(int,QBarSet*)));
630 QSignalSpy setSpy1(set1, SIGNAL(pressed(int)));
631 QSignalSpy setSpy2(set2, SIGNAL(pressed(int)));
632
633 QChartView view(new QChart());
634 view.resize(400,300);
635 view.chart()->addSeries(series);
636 view.show();
637 QTest::qWaitForWindowShown(&view);
638
639 // Calculate expected layout for bars
640 QRectF plotArea = view.chart()->plotArea();
641 qreal width = plotArea.width();
642 qreal height = plotArea.height();
643 qreal rangeY = 100; // From 0 to 100 because range is scaled to 100%
644 qreal rangeX = 3; // 3 values per set
645 qreal scaleY = (height / rangeY);
646 qreal scaleX = (width / rangeX);
647
648 qreal setCount = series->count();
649 qreal domainMinY = 0; // These come from internal domain used by barseries.
650 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
651 qreal rectWidth = scaleX * series->barWidth();
652
653 QVector<QRectF> layout;
654
655 // 3 = count of values in set
656 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
657 for (int i = 0; i < 3; i++) {
658 qreal colSum = 20; // Sum of values in column (10 + 10 in our test case)
659 qreal percentage = (100 / colSum);
660 qreal yPos = height + scaleY * domainMinY + plotArea.top();
661
662 for (int set = 0; set < setCount; set++) {
663 qreal xPos = (i - domainMinX) * scaleX + plotArea.left() - rectWidth/2;
664 qreal rectHeigth = barSets.at(set)->at(i) * percentage * scaleY;
665
666 QRectF rect(xPos, yPos-rectHeigth, rectWidth, rectHeigth);
667 layout.append(rect);
668 yPos -= rectHeigth;
669 }
670 }
671
672 //====================================================================================
673 // barset 1, bar 0
674 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
675 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
676
677 QCOMPARE(seriesSpy.count(), 1);
678 QCOMPARE(setSpy1.count(), 1);
679 QCOMPARE(setSpy2.count(), 0);
680
681 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
682 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
683 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
684 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
685
686 QList<QVariant> setSpyArg = setSpy1.takeFirst();
687 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
688 QVERIFY(setSpyArg.at(0).toInt() == 0);
689
690 //====================================================================================
691 // barset 1, bar 1
692 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
693 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
694
695 QCOMPARE(seriesSpy.count(), 1);
696 QCOMPARE(setSpy1.count(), 1);
697 QCOMPARE(setSpy2.count(), 0);
698
699 seriesSpyArg = seriesSpy.takeFirst();
700 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
701 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
702 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
703
704 setSpyArg = setSpy1.takeFirst();
705 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
706 QVERIFY(setSpyArg.at(0).toInt() == 1);
707
708 //====================================================================================
709 // barset 1, bar 2
710 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
711 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
712
713 QCOMPARE(seriesSpy.count(), 1);
714 QCOMPARE(setSpy1.count(), 1);
715 QCOMPARE(setSpy2.count(), 0);
716
717 seriesSpyArg = seriesSpy.takeFirst();
718 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
719 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
720 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
721
722 setSpyArg = setSpy1.takeFirst();
723 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
724 QVERIFY(setSpyArg.at(0).toInt() == 2);
725
726 //====================================================================================
727 // barset 2, bar 0
728 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
729 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
730
731 QCOMPARE(seriesSpy.count(), 1);
732 QCOMPARE(setSpy1.count(), 0);
733 QCOMPARE(setSpy2.count(), 1);
734
735 seriesSpyArg = seriesSpy.takeFirst();
736 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
737 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
738 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
739
740 setSpyArg = setSpy2.takeFirst();
741 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
742 QVERIFY(setSpyArg.at(0).toInt() == 0);
743
744 //====================================================================================
745 // barset 2, bar 1
746 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
747 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
748
749 QCOMPARE(seriesSpy.count(), 1);
750 QCOMPARE(setSpy1.count(), 0);
751 QCOMPARE(setSpy2.count(), 1);
752
753 seriesSpyArg = seriesSpy.takeFirst();
754 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
755 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
756 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
757
758 setSpyArg = setSpy2.takeFirst();
759 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
760 QVERIFY(setSpyArg.at(0).toInt() == 1);
761
762 //====================================================================================
763 // barset 2, bar 2
764 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
765 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
766
767 QCOMPARE(seriesSpy.count(), 1);
768 QCOMPARE(setSpy1.count(), 0);
769 QCOMPARE(setSpy2.count(), 1);
770
771 seriesSpyArg = seriesSpy.takeFirst();
772 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
773 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
774 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
775
776 setSpyArg = setSpy2.takeFirst();
777 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
778 QVERIFY(setSpyArg.at(0).toInt() == 2);
779 }
780
781 void tst_QPercentBarSeries::mouseReleased()
782 {
783 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
784
785 QPercentBarSeries* series = new QPercentBarSeries();
786
787 QBarSet* set1 = new QBarSet(QString("set 1"));
788 *set1 << 10 << 10 << 10;
789 series->append(set1);
790
791 QBarSet* set2 = new QBarSet(QString("set 2"));
792 *set2 << 10 << 10 << 10;
793 series->append(set2);
794 QList<QBarSet*> barSets = series->barSets();
795
796 QSignalSpy seriesSpy(series,SIGNAL(released(int,QBarSet*)));
797 QSignalSpy setSpy1(set1, SIGNAL(released(int)));
798 QSignalSpy setSpy2(set2, SIGNAL(released(int)));
799
800 QChartView view(new QChart());
801 view.resize(400,300);
802 view.chart()->addSeries(series);
803 view.show();
804 QTest::qWaitForWindowShown(&view);
805
806 // Calculate expected layout for bars
807 QRectF plotArea = view.chart()->plotArea();
808 qreal width = plotArea.width();
809 qreal height = plotArea.height();
810 qreal rangeY = 100; // From 0 to 100 because range is scaled to 100%
811 qreal rangeX = 3; // 3 values per set
812 qreal scaleY = (height / rangeY);
813 qreal scaleX = (width / rangeX);
814
815 qreal setCount = series->count();
816 qreal domainMinY = 0; // These come from internal domain used by barseries.
817 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
818 qreal rectWidth = scaleX * series->barWidth();
819
820 QVector<QRectF> layout;
821
822 // 3 = count of values in set
823 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
824 for (int i = 0; i < 3; i++) {
825 qreal colSum = 20; // Sum of values in column (10 + 10 in our test case)
826 qreal percentage = (100 / colSum);
827 qreal yPos = height + scaleY * domainMinY + plotArea.top();
828
829 for (int set = 0; set < setCount; set++) {
830 qreal xPos = (i - domainMinX) * scaleX + plotArea.left() - rectWidth/2;
831 qreal rectHeigth = barSets.at(set)->at(i) * percentage * scaleY;
832
833 QRectF rect(xPos, yPos-rectHeigth, rectWidth, rectHeigth);
834 layout.append(rect);
835 yPos -= rectHeigth;
836 }
837 }
838
839 //====================================================================================
840 // barset 1, bar 0
841 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
842 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
843
844 QCOMPARE(seriesSpy.count(), 1);
845 QCOMPARE(setSpy1.count(), 1);
846 QCOMPARE(setSpy2.count(), 0);
847
848 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
849 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
850 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
851 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
852
853 QList<QVariant> setSpyArg = setSpy1.takeFirst();
854 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
855 QVERIFY(setSpyArg.at(0).toInt() == 0);
856
857 //====================================================================================
858 // barset 1, bar 1
859 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
860 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
861
862 QCOMPARE(seriesSpy.count(), 1);
863 QCOMPARE(setSpy1.count(), 1);
864 QCOMPARE(setSpy2.count(), 0);
865
866 seriesSpyArg = seriesSpy.takeFirst();
867 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
868 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
869 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
870
871 setSpyArg = setSpy1.takeFirst();
872 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
873 QVERIFY(setSpyArg.at(0).toInt() == 1);
874
875 //====================================================================================
876 // barset 1, bar 2
877 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
878 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
879
880 QCOMPARE(seriesSpy.count(), 1);
881 QCOMPARE(setSpy1.count(), 1);
882 QCOMPARE(setSpy2.count(), 0);
883
884 seriesSpyArg = seriesSpy.takeFirst();
885 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
886 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
887 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
888
889 setSpyArg = setSpy1.takeFirst();
890 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
891 QVERIFY(setSpyArg.at(0).toInt() == 2);
892
893 //====================================================================================
894 // barset 2, bar 0
895 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
896 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
897
898 QCOMPARE(seriesSpy.count(), 1);
899 QCOMPARE(setSpy1.count(), 0);
900 QCOMPARE(setSpy2.count(), 1);
901
902 seriesSpyArg = seriesSpy.takeFirst();
903 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
904 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
905 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
906
907 setSpyArg = setSpy2.takeFirst();
908 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
909 QVERIFY(setSpyArg.at(0).toInt() == 0);
910
911 //====================================================================================
912 // barset 2, bar 1
913 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
914 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
915
916 QCOMPARE(seriesSpy.count(), 1);
917 QCOMPARE(setSpy1.count(), 0);
918 QCOMPARE(setSpy2.count(), 1);
919
920 seriesSpyArg = seriesSpy.takeFirst();
921 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
922 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
923 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
924
925 setSpyArg = setSpy2.takeFirst();
926 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
927 QVERIFY(setSpyArg.at(0).toInt() == 1);
928
929 //====================================================================================
930 // barset 2, bar 2
931 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
932 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
933
934 QCOMPARE(seriesSpy.count(), 1);
935 QCOMPARE(setSpy1.count(), 0);
936 QCOMPARE(setSpy2.count(), 1);
937
938 seriesSpyArg = seriesSpy.takeFirst();
939 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
940 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
941 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
942
943 setSpyArg = setSpy2.takeFirst();
944 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
945 QVERIFY(setSpyArg.at(0).toInt() == 2);
946 }
947
948 void tst_QPercentBarSeries::mouseDoubleClicked()
949 {
950 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
951
952 QPercentBarSeries* series = new QPercentBarSeries();
953
954 QBarSet* set1 = new QBarSet(QString("set 1"));
955 *set1 << 10 << 10 << 10;
956 series->append(set1);
957
958 QBarSet* set2 = new QBarSet(QString("set 2"));
959 *set2 << 10 << 10 << 10;
960 series->append(set2);
961 QList<QBarSet*> barSets = series->barSets();
962
963 QSignalSpy seriesSpy(series,SIGNAL(doubleClicked(int,QBarSet*)));
964 QSignalSpy setSpy1(set1, SIGNAL(doubleClicked(int)));
965 QSignalSpy setSpy2(set2, SIGNAL(doubleClicked(int)));
966
967 QChartView view(new QChart());
968 view.resize(400,300);
969 view.chart()->addSeries(series);
970 view.show();
971 QTest::qWaitForWindowShown(&view);
972
973 // Calculate expected layout for bars
974 QRectF plotArea = view.chart()->plotArea();
975 qreal width = plotArea.width();
976 qreal height = plotArea.height();
977 qreal rangeY = 100; // From 0 to 100 because range is scaled to 100%
978 qreal rangeX = 3; // 3 values per set
979 qreal scaleY = (height / rangeY);
980 qreal scaleX = (width / rangeX);
981
982 qreal setCount = series->count();
983 qreal domainMinY = 0; // These come from internal domain used by barseries.
984 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
985 qreal rectWidth = scaleX * series->barWidth();
986
987 QVector<QRectF> layout;
988
989 // 3 = count of values in set
990 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
991 for (int i = 0; i < 3; i++) {
992 qreal colSum = 20; // Sum of values in column (10 + 10 in our test case)
993 qreal percentage = (100 / colSum);
994 qreal yPos = height + scaleY * domainMinY + plotArea.top();
995
996 for (int set = 0; set < setCount; set++) {
997 qreal xPos = (i - domainMinX) * scaleX + plotArea.left() - rectWidth/2;
998 qreal rectHeigth = barSets.at(set)->at(i) * percentage * scaleY;
999
1000 QRectF rect(xPos, yPos-rectHeigth, rectWidth, rectHeigth);
1001 layout.append(rect);
1002 yPos -= rectHeigth;
1003 }
1004 }
1005
1006 // barset 1, bar 0
1007 QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
1008 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1009
1010 QCOMPARE(seriesSpy.count(), 1);
1011 QCOMPARE(setSpy1.count(), 1);
1012 QCOMPARE(setSpy2.count(), 0);
1013
1014 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
1015 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
1016 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1017 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
1018
1019 QList<QVariant> setSpyArg = setSpy1.takeFirst();
1020 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1021 QVERIFY(setSpyArg.at(0).toInt() == 0);
1022 }
1023
611 QTEST_MAIN(tst_QPercentBarSeries)
1024 QTEST_MAIN(tst_QPercentBarSeries)
612
1025
613 #include "tst_qpercentbarseries.moc"
1026 #include "tst_qpercentbarseries.moc"
@@ -57,6 +57,9 private slots:
57 void hoverSignal();
57 void hoverSignal();
58 void sliceSeries();
58 void sliceSeries();
59 void destruction();
59 void destruction();
60 void pressedSignal();
61 void releasedSignal();
62 void doubleClickedSignal();
60
63
61 private:
64 private:
62 void verifyCalculatedData(const QPieSeries &series, bool *ok);
65 void verifyCalculatedData(const QPieSeries &series, bool *ok);
@@ -652,6 +655,139 QList<QPoint> tst_qpieseries::slicePoints(QRectF rect)
652 return points;
655 return points;
653 }
656 }
654
657
658 void tst_qpieseries::pressedSignal()
659 {
660 // NOTE:
661 // This test is the same as tst_qpieslice::pressedSignal()
662 // Just for different signals.
663
664 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
665
666 // add some slices
667 QPieSlice *s1 = m_series->append("slice 1", 1);
668 QPieSlice *s2 = m_series->append("slice 2", 1);
669 QPieSlice *s3 = m_series->append("slice 3", 1);
670 QPieSlice *s4 = m_series->append("slice 4", 1);
671 QSignalSpy clickSpy(m_series, SIGNAL(pressed(QPieSlice*)));
672
673 // add series to the chart
674 m_view->chart()->legend()->setVisible(false);
675 m_view->chart()->addSeries(m_series);
676 m_view->show();
677 QTest::qWaitForWindowShown(m_view);
678
679 // test maximum size
680 m_series->setPieSize(1.0);
681 QRectF pieRect = m_view->chart()->plotArea();
682 QList<QPoint> points = slicePoints(pieRect);
683 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(0));
684 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(1));
685 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(2));
686 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(3));
687 TRY_COMPARE(clickSpy.count(), 4);
688 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s1);
689 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s2);
690 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3);
691 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s4);
692 clickSpy.clear();
693
694 // test half size
695 m_series->setPieSize(0.5);
696 m_series->setVerticalPosition(0.25);
697 m_series->setHorizontalPosition(0.25);
698 pieRect = QRectF(m_view->chart()->plotArea().topLeft(), m_view->chart()->plotArea().center());
699 points = slicePoints(pieRect);
700 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(0));
701 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(1));
702 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(2));
703 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(3));
704 TRY_COMPARE(clickSpy.count(), 4);
705 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s1);
706 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s2);
707 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3);
708 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s4);
709 }
710
711 void tst_qpieseries::releasedSignal()
712 {
713 // NOTE:
714 // This test is the same as tst_qpieslice::pressedSignal()
715 // Just for different signals.
716
717 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
718
719 // add some slices
720 QPieSlice *s1 = m_series->append("slice 1", 1);
721 QPieSlice *s2 = m_series->append("slice 2", 1);
722 QPieSlice *s3 = m_series->append("slice 3", 1);
723 QPieSlice *s4 = m_series->append("slice 4", 1);
724 QSignalSpy clickSpy(m_series, SIGNAL(released(QPieSlice*)));
725
726 // add series to the chart
727 m_view->chart()->legend()->setVisible(false);
728 m_view->chart()->addSeries(m_series);
729 m_view->show();
730 QTest::qWaitForWindowShown(m_view);
731
732 // test maximum size
733 m_series->setPieSize(1.0);
734 QRectF pieRect = m_view->chart()->plotArea();
735 QList<QPoint> points = slicePoints(pieRect);
736 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(0));
737 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(1));
738 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(2));
739 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(3));
740 TRY_COMPARE(clickSpy.count(), 4);
741 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s1);
742 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s2);
743 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3);
744 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s4);
745 clickSpy.clear();
746
747 // test half size
748 m_series->setPieSize(0.5);
749 m_series->setVerticalPosition(0.25);
750 m_series->setHorizontalPosition(0.25);
751 pieRect = QRectF(m_view->chart()->plotArea().topLeft(), m_view->chart()->plotArea().center());
752 points = slicePoints(pieRect);
753 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(0));
754 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(1));
755 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(2));
756 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(3));
757 TRY_COMPARE(clickSpy.count(), 4);
758 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s1);
759 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s2);
760 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3);
761 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s4);
762 }
763
764 void tst_qpieseries::doubleClickedSignal()
765 {
766 // NOTE:
767 // This test is the same as tst_qpieslice::pressedSignal()
768 // Just for different signals.
769
770 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
771
772 // add some slices
773 QPieSlice *s1 = m_series->append("slice 1", 1);
774 QSignalSpy clickSpy(m_series, SIGNAL(doubleClicked(QPieSlice*)));
775
776 // add series to the chart
777 m_view->chart()->legend()->setVisible(false);
778 m_view->chart()->addSeries(m_series);
779 m_view->show();
780 QTest::qWaitForWindowShown(m_view);
781
782 // test maximum size
783 m_series->setPieSize(1.0);
784 QRectF pieRect = m_view->chart()->plotArea();
785 QList<QPoint> points = slicePoints(pieRect);
786 QTest::mouseDClick(m_view->viewport(), Qt::LeftButton, 0, points.at(0));
787 TRY_COMPARE(clickSpy.count(), 1);
788 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s1);
789 }
790
655 QTEST_MAIN(tst_qpieseries)
791 QTEST_MAIN(tst_qpieseries)
656
792
657 #include "tst_qpieseries.moc"
793 #include "tst_qpieseries.moc"
@@ -43,6 +43,9 private slots:
43 void customize();
43 void customize();
44 void clickedSignal();
44 void clickedSignal();
45 void hoverSignal();
45 void hoverSignal();
46 void pressedSignal();
47 void releasedSignal();
48 void doubleClickedSignal();
46
49
47 private:
50 private:
48 QList<QPoint> slicePoints(QRectF rect);
51 QList<QPoint> slicePoints(QRectF rect);
@@ -335,6 +338,114 QList<QPoint> tst_qpieslice::slicePoints(QRectF rect)
335 return points;
338 return points;
336 }
339 }
337
340
341 void tst_qpieslice::pressedSignal()
342 {
343 // NOTE:
344 // This test is the same as tst_qpieseries::pressedSignal()
345 // Just for different signals.
346
347 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
348
349 // create a pie series
350 QPieSeries *series = new QPieSeries();
351 QPieSlice *s1 = series->append("slice 1", 1);
352 QPieSlice *s2 = series->append("slice 2", 1);
353 QPieSlice *s3 = series->append("slice 3", 1);
354 QPieSlice *s4 = series->append("slice 4", 1);
355 QSignalSpy clickSpy1(s1, SIGNAL(pressed()));
356 QSignalSpy clickSpy2(s2, SIGNAL(pressed()));
357 QSignalSpy clickSpy3(s3, SIGNAL(pressed()));
358 QSignalSpy clickSpy4(s4, SIGNAL(pressed()));
359
360 // add series to the chart
361 QChartView view;
362 view.chart()->legend()->setVisible(false);
363 view.chart()->addSeries(series);
364 view.show();
365 QTest::qWaitForWindowShown(&view);
366
367 // simulate clicks
368 series->setPieSize(1.0);
369 QRectF pieRect = view.chart()->plotArea();
370 QList<QPoint> points = slicePoints(pieRect);
371 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(0));
372 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(1));
373 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(2));
374 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(3));
375 QCOMPARE(clickSpy1.count(), 1);
376 QCOMPARE(clickSpy2.count(), 1);
377 QCOMPARE(clickSpy3.count(), 1);
378 QCOMPARE(clickSpy4.count(), 1);
379 }
380
381 void tst_qpieslice::releasedSignal()
382 {
383 // NOTE:
384 // This test is the same as tst_qpieseries::releasedSignal()
385 // Just for different signals.
386
387 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
388
389 // create a pie series
390 QPieSeries *series = new QPieSeries();
391 QPieSlice *s1 = series->append("slice 1", 1);
392 QPieSlice *s2 = series->append("slice 2", 1);
393 QPieSlice *s3 = series->append("slice 3", 1);
394 QPieSlice *s4 = series->append("slice 4", 1);
395 QSignalSpy clickSpy1(s1, SIGNAL(released()));
396 QSignalSpy clickSpy2(s2, SIGNAL(released()));
397 QSignalSpy clickSpy3(s3, SIGNAL(released()));
398 QSignalSpy clickSpy4(s4, SIGNAL(released()));
399
400 // add series to the chart
401 QChartView view;
402 view.chart()->legend()->setVisible(false);
403 view.chart()->addSeries(series);
404 view.show();
405 QTest::qWaitForWindowShown(&view);
406
407 // simulate clicks
408 series->setPieSize(1.0);
409 QRectF pieRect = view.chart()->plotArea();
410 QList<QPoint> points = slicePoints(pieRect);
411 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(0));
412 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(1));
413 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(2));
414 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(3));
415 QCOMPARE(clickSpy1.count(), 1);
416 QCOMPARE(clickSpy2.count(), 1);
417 QCOMPARE(clickSpy3.count(), 1);
418 QCOMPARE(clickSpy4.count(), 1);
419 }
420
421 void tst_qpieslice::doubleClickedSignal()
422 {
423 // NOTE:
424 // This test is the same as tst_qpieseries::doubleClickedSignal()
425 // Just for different signals.
426
427 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
428
429 // create a pie series
430 QPieSeries *series = new QPieSeries();
431 QPieSlice *s1 = series->append("slice 1", 1);
432 QSignalSpy clickSpy1(s1, SIGNAL(doubleClicked()));
433
434 // add series to the chart
435 QChartView view;
436 view.chart()->legend()->setVisible(false);
437 view.chart()->addSeries(series);
438 view.show();
439 QTest::qWaitForWindowShown(&view);
440
441 // simulate clicks
442 series->setPieSize(1.0);
443 QRectF pieRect = view.chart()->plotArea();
444 QList<QPoint> points = slicePoints(pieRect);
445 QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, points.at(0));
446 QCOMPARE(clickSpy1.count(), 1);
447 }
448
338 QTEST_MAIN(tst_qpieslice)
449 QTEST_MAIN(tst_qpieslice)
339
450
340 #include "tst_qpieslice.moc"
451 #include "tst_qpieslice.moc"
@@ -36,6 +36,9 private slots:
36 void qscatterseries_data();
36 void qscatterseries_data();
37 void qscatterseries();
37 void qscatterseries();
38 void scatterChangedSignals();
38 void scatterChangedSignals();
39 void pressedSignal();
40 void releasedSignal();
41 void doubleClickedSignal();
39
42
40 protected:
43 protected:
41 void pointsVisible_data();
44 void pointsVisible_data();
@@ -126,6 +129,99 void tst_QScatterSeries::scatterChangedSignals()
126 TRY_COMPARE(colorSpy.count(), 2);
129 TRY_COMPARE(colorSpy.count(), 2);
127 }
130 }
128
131
132 void tst_QScatterSeries::pressedSignal()
133 {
134 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
135
136 QPointF scatterPoint(4, 12);
137 QScatterSeries *scatterSeries = new QScatterSeries();
138 scatterSeries->append(QPointF(2, 1));
139 scatterSeries->append(scatterPoint);
140 scatterSeries->append(QPointF(6, 12));
141
142 QChartView view;
143 view.chart()->legend()->setVisible(false);
144 view.chart()->addSeries(scatterSeries);
145 view.show();
146 QTest::qWaitForWindowShown(&view);
147
148 QSignalSpy seriesSpy(scatterSeries, SIGNAL(pressed(QPointF)));
149
150 QPointF checkPoint = view.chart()->mapToPosition(scatterPoint);
151 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
152 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
153
154 QCOMPARE(seriesSpy.count(), 1);
155 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
156 // checkPoint is QPointF and for the mouseClick it it's changed to QPoint
157 // this causes small distinction in decimals so we round it before comparing
158 QPointF signalPoint = qvariant_cast<QPointF>(seriesSpyArg.at(0));
159 QCOMPARE(qRound(signalPoint.x()), qRound(scatterPoint.x()));
160 QCOMPARE(qRound(signalPoint.y()), qRound(scatterPoint.y()));
161 }
162
163 void tst_QScatterSeries::releasedSignal()
164 {
165 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
166
167 QPointF scatterPoint(4, 12);
168 QScatterSeries *scatterSeries = new QScatterSeries();
169 scatterSeries->append(QPointF(2, 1));
170 scatterSeries->append(scatterPoint);
171 scatterSeries->append(QPointF(6, 12));
172
173 QChartView view;
174 view.chart()->legend()->setVisible(false);
175 view.chart()->addSeries(scatterSeries);
176 view.show();
177 QTest::qWaitForWindowShown(&view);
178
179 QSignalSpy seriesSpy(scatterSeries, SIGNAL(released(QPointF)));
180
181 QPointF checkPoint = view.chart()->mapToPosition(scatterPoint);
182 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
183 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
184
185 QCOMPARE(seriesSpy.count(), 1);
186 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
187 // checkPoint is QPointF and for the mouseClick it it's changed to QPoint
188 // this causes small distinction in decimals so we round it before comparing
189 QPointF signalPoint = qvariant_cast<QPointF>(seriesSpyArg.at(0));
190 QCOMPARE(qRound(signalPoint.x()), qRound(scatterPoint.x()));
191 QCOMPARE(qRound(signalPoint.y()), qRound(scatterPoint.y()));
192 }
193
194 void tst_QScatterSeries::doubleClickedSignal()
195 {
196 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
197
198 QPointF scatterPoint(4, 12);
199 QScatterSeries *scatterSeries = new QScatterSeries();
200 scatterSeries->append(QPointF(2, 1));
201 scatterSeries->append(scatterPoint);
202 scatterSeries->append(QPointF(6, 12));
203
204 QChartView view;
205 view.chart()->legend()->setVisible(false);
206 view.chart()->addSeries(scatterSeries);
207 view.show();
208 QTest::qWaitForWindowShown(&view);
209
210 QSignalSpy seriesSpy(scatterSeries, SIGNAL(doubleClicked(QPointF)));
211
212 QPointF checkPoint = view.chart()->mapToPosition(scatterPoint);
213 QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
214 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
215
216 QCOMPARE(seriesSpy.count(), 1);
217 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
218 // checkPoint is QPointF and for the mouseClick it it's changed to QPoint
219 // this causes small distinction in decimals so we round it before comparing
220 QPointF signalPoint = qvariant_cast<QPointF>(seriesSpyArg.at(0));
221 QCOMPARE(qRound(signalPoint.x()), qRound(scatterPoint.x()));
222 QCOMPARE(qRound(signalPoint.y()), qRound(scatterPoint.y()));
223 }
224
129 QTEST_MAIN(tst_QScatterSeries)
225 QTEST_MAIN(tst_QScatterSeries)
130
226
131 #include "tst_qscatterseries.moc"
227 #include "tst_qscatterseries.moc"
@@ -35,6 +35,9 public slots:
35 private slots:
35 private slots:
36 void qsplineseries_data();
36 void qsplineseries_data();
37 void qsplineseries();
37 void qsplineseries();
38 void pressedSignal();
39 void releasedSignal();
40 void doubleClickedSignal();
38 protected:
41 protected:
39 void pointsVisible_data();
42 void pointsVisible_data();
40 };
43 };
@@ -95,6 +98,98 void tst_QSplineSeries::qsplineseries()
95 QTest::qWaitForWindowShown(m_view);
98 QTest::qWaitForWindowShown(m_view);
96 }
99 }
97
100
101 void tst_QSplineSeries::pressedSignal()
102 {
103 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
104
105 QPointF splinePoint(4, 12);
106 QSplineSeries *splineSeries = new QSplineSeries();
107 splineSeries->append(QPointF(2, 1));
108 splineSeries->append(splinePoint);
109 splineSeries->append(QPointF(6, 12));
110
111 QChartView view;
112 view.chart()->legend()->setVisible(false);
113 view.chart()->addSeries(splineSeries);
114 view.show();
115 QTest::qWaitForWindowShown(&view);
116
117 QSignalSpy seriesSpy(splineSeries, SIGNAL(pressed(QPointF)));
118
119 QPointF checkPoint = view.chart()->mapToPosition(splinePoint);
120 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
121 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
122
123 QCOMPARE(seriesSpy.count(), 1);
124 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
125 // checkPoint is QPointF and for the mouseClick it it's changed to QPoint
126 // this causes small distinction in decimals so we round it before comparing
127 QPointF signalPoint = qvariant_cast<QPointF>(seriesSpyArg.at(0));
128 QCOMPARE(qRound(signalPoint.x()), qRound(splinePoint.x()));
129 QCOMPARE(qRound(signalPoint.y()), qRound(splinePoint.y()));
130 }
131
132 void tst_QSplineSeries::releasedSignal()
133 {
134 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
135
136 QPointF splinePoint(4, 12);
137 QSplineSeries *splineSeries = new QSplineSeries();
138 splineSeries->append(QPointF(2, 20));
139 splineSeries->append(splinePoint);
140 splineSeries->append(QPointF(6, 12));
141
142 QChartView view;
143 view.chart()->legend()->setVisible(false);
144 view.chart()->addSeries(splineSeries);
145 view.show();
146 QTest::qWaitForWindowShown(&view);
147
148 QSignalSpy seriesSpy(splineSeries, SIGNAL(released(QPointF)));
149
150 QPointF checkPoint = view.chart()->mapToPosition(splinePoint);
151 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
152 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
153
154 QCOMPARE(seriesSpy.count(), 1);
155 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
156 // checkPoint is QPointF and for the mouseClick it it's changed to QPoint
157 // this causes small distinction in decimals so we round it before comparing
158 QPointF signalPoint = qvariant_cast<QPointF>(seriesSpyArg.at(0));
159 QCOMPARE(qRound(signalPoint.x()), qRound(splinePoint.x()));
160 QCOMPARE(qRound(signalPoint.y()), qRound(splinePoint.y()));
161 }
162
163 void tst_QSplineSeries::doubleClickedSignal()
164 {
165 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
166
167 QPointF splinePoint(4, 12);
168 QSplineSeries *splineSeries = new QSplineSeries();
169 splineSeries->append(QPointF(2, 20));
170 splineSeries->append(splinePoint);
171 splineSeries->append(QPointF(6, 12));
172
173 QChartView view;
174 view.chart()->legend()->setVisible(false);
175 view.chart()->addSeries(splineSeries);
176 view.show();
177 QTest::qWaitForWindowShown(&view);
178
179 QSignalSpy seriesSpy(splineSeries, SIGNAL(doubleClicked(QPointF)));
180
181 QPointF checkPoint = view.chart()->mapToPosition(splinePoint);
182 QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
183 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
184
185 QCOMPARE(seriesSpy.count(), 1);
186 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
187 // checkPoint is QPointF and for the mouseClick it it's changed to QPoint
188 // this causes small distinction in decimals so we round it before comparing
189 QPointF signalPoint = qvariant_cast<QPointF>(seriesSpyArg.at(0));
190 QCOMPARE(qRound(signalPoint.x()), qRound(splinePoint.x()));
191 QCOMPARE(qRound(signalPoint.y()), qRound(splinePoint.y()));
192 }
98 QTEST_MAIN(tst_QSplineSeries)
193 QTEST_MAIN(tst_QSplineSeries)
99
194
100 #include "tst_qsplineseries.moc"
195 #include "tst_qsplineseries.moc"
@@ -51,6 +51,9 private slots:
51 void mouseclicked();
51 void mouseclicked();
52 void mousehovered_data();
52 void mousehovered_data();
53 void mousehovered();
53 void mousehovered();
54 void mousePressed();
55 void mouseReleased();
56 void mouseDoubleClicked();
54
57
55 private:
58 private:
56 QStackedBarSeries* m_barseries;
59 QStackedBarSeries* m_barseries;
@@ -595,6 +598,424 void tst_QStackedBarSeries::mousehovered()
595 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
598 QVERIFY(setIndexSpyArg.at(1).toInt() == 1);
596 }
599 }
597
600
601 void tst_QStackedBarSeries::mousePressed()
602 {
603 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
604
605 QStackedBarSeries* series = new QStackedBarSeries();
606
607 QBarSet* set1 = new QBarSet(QString("set 1"));
608 *set1 << 10 << 10 << 10;
609 series->append(set1);
610
611 QBarSet* set2 = new QBarSet(QString("set 2"));
612 *set2 << 10 << 10 << 10;
613 series->append(set2);
614 QList<QBarSet*> barSets = series->barSets();
615
616 QSignalSpy seriesSpy(series,SIGNAL(pressed(int,QBarSet*)));
617 QSignalSpy setSpy1(set1, SIGNAL(pressed(int)));
618 QSignalSpy setSpy2(set2, SIGNAL(pressed(int)));
619
620 QChartView view(new QChart());
621 view.resize(400,300);
622 view.chart()->addSeries(series);
623 view.show();
624 QTest::qWaitForWindowShown(&view);
625
626 // Calculate expected layout for bars
627 QRectF plotArea = view.chart()->plotArea();
628 qreal width = plotArea.width();
629 qreal height = plotArea.height();
630 qreal rangeY = 20; // From 0 to 20 because sets are stacked (this should be height of highest stack)
631 qreal rangeX = 3; // 3 values per set
632 qreal scaleY = (height / rangeY);
633 qreal scaleX = (width / rangeX);
634
635 qreal setCount = series->count();
636 qreal domainMinY = 0; // These come from internal domain used by barseries.
637 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
638 qreal rectWidth = scaleX * series->barWidth();
639
640 QVector<QRectF> layout;
641
642 // 3 = count of values in set
643 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
644 for (int i = 0; i < 3; i++) {
645 qreal yMax = height + scaleY * domainMinY + plotArea.top();
646 qreal yMin = height + scaleY * domainMinY + plotArea.top();
647 for (int set = 0; set < setCount; set++) {
648 qreal xPos = (i - domainMinX) * scaleX + plotArea.left() - rectWidth/2;
649 qreal rectHeight = barSets.at(set)->at(i) * scaleY;
650 if (rectHeight < 0) {
651 QRectF rect(xPos, yMax-rectHeight, rectWidth, rectHeight);
652 layout.append(rect);
653 yMax -= rectHeight;
654 } else {
655 QRectF rect(xPos, yMin-rectHeight, rectWidth, rectHeight);
656 layout.append(rect);
657 yMin -= rectHeight;
658 }
659 }
660 }
661
662 //====================================================================================
663 // barset 1, bar 0
664 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
665 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
666
667 QCOMPARE(seriesSpy.count(), 1);
668 QCOMPARE(setSpy1.count(), 1);
669 QCOMPARE(setSpy2.count(), 0);
670
671 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
672 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
673 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
674 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
675
676 QList<QVariant> setSpyArg = setSpy1.takeFirst();
677 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
678 QVERIFY(setSpyArg.at(0).toInt() == 0);
679
680 //====================================================================================
681 // barset 1, bar 1
682 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
683 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
684
685 QCOMPARE(seriesSpy.count(), 1);
686 QCOMPARE(setSpy1.count(), 1);
687 QCOMPARE(setSpy2.count(), 0);
688
689 seriesSpyArg = seriesSpy.takeFirst();
690 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
691 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
692 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
693
694 setSpyArg = setSpy1.takeFirst();
695 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
696 QVERIFY(setSpyArg.at(0).toInt() == 1);
697
698 //====================================================================================
699 // barset 1, bar 2
700 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
701 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
702
703 QCOMPARE(seriesSpy.count(), 1);
704 QCOMPARE(setSpy1.count(), 1);
705 QCOMPARE(setSpy2.count(), 0);
706
707 seriesSpyArg = seriesSpy.takeFirst();
708 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
709 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
710 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
711
712 setSpyArg = setSpy1.takeFirst();
713 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
714 QVERIFY(setSpyArg.at(0).toInt() == 2);
715
716 //====================================================================================
717 // barset 2, bar 0
718 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
719 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
720
721 QCOMPARE(seriesSpy.count(), 1);
722 QCOMPARE(setSpy1.count(), 0);
723 QCOMPARE(setSpy2.count(), 1);
724
725 seriesSpyArg = seriesSpy.takeFirst();
726 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
727 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
728 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
729
730 setSpyArg = setSpy2.takeFirst();
731 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
732 QVERIFY(setSpyArg.at(0).toInt() == 0);
733
734 //====================================================================================
735 // barset 2, bar 1
736 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
737 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
738
739 QCOMPARE(seriesSpy.count(), 1);
740 QCOMPARE(setSpy1.count(), 0);
741 QCOMPARE(setSpy2.count(), 1);
742
743 seriesSpyArg = seriesSpy.takeFirst();
744 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
745 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
746 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
747
748 setSpyArg = setSpy2.takeFirst();
749 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
750 QVERIFY(setSpyArg.at(0).toInt() == 1);
751
752 //====================================================================================
753 // barset 2, bar 2
754 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
755 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
756
757 QCOMPARE(seriesSpy.count(), 1);
758 QCOMPARE(setSpy1.count(), 0);
759 QCOMPARE(setSpy2.count(), 1);
760
761 seriesSpyArg = seriesSpy.takeFirst();
762 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
763 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
764 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
765
766 setSpyArg = setSpy2.takeFirst();
767 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
768 QVERIFY(setSpyArg.at(0).toInt() == 2);
769 }
770
771 void tst_QStackedBarSeries::mouseReleased()
772 {
773 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
774
775 QStackedBarSeries* series = new QStackedBarSeries();
776
777 QBarSet* set1 = new QBarSet(QString("set 1"));
778 *set1 << 10 << 10 << 10;
779 series->append(set1);
780
781 QBarSet* set2 = new QBarSet(QString("set 2"));
782 *set2 << 10 << 10 << 10;
783 series->append(set2);
784 QList<QBarSet*> barSets = series->barSets();
785
786 QSignalSpy seriesSpy(series,SIGNAL(released(int,QBarSet*)));
787 QSignalSpy setSpy1(set1, SIGNAL(released(int)));
788 QSignalSpy setSpy2(set2, SIGNAL(released(int)));
789
790 QChartView view(new QChart());
791 view.resize(400,300);
792 view.chart()->addSeries(series);
793 view.show();
794 QTest::qWaitForWindowShown(&view);
795
796 // Calculate expected layout for bars
797 QRectF plotArea = view.chart()->plotArea();
798 qreal width = plotArea.width();
799 qreal height = plotArea.height();
800 qreal rangeY = 20; // From 0 to 20 because sets are stacked (this should be height of highest stack)
801 qreal rangeX = 3; // 3 values per set
802 qreal scaleY = (height / rangeY);
803 qreal scaleX = (width / rangeX);
804
805 qreal setCount = series->count();
806 qreal domainMinY = 0; // These come from internal domain used by barseries.
807 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
808 qreal rectWidth = scaleX * series->barWidth();
809
810 QVector<QRectF> layout;
811
812 // 3 = count of values in set
813 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
814 for (int i = 0; i < 3; i++) {
815 qreal yMax = height + scaleY * domainMinY + plotArea.top();
816 qreal yMin = height + scaleY * domainMinY + plotArea.top();
817 for (int set = 0; set < setCount; set++) {
818 qreal xPos = (i - domainMinX) * scaleX + plotArea.left() - rectWidth/2;
819 qreal rectHeight = barSets.at(set)->at(i) * scaleY;
820 if (rectHeight < 0) {
821 QRectF rect(xPos, yMax-rectHeight, rectWidth, rectHeight);
822 layout.append(rect);
823 yMax -= rectHeight;
824 } else {
825 QRectF rect(xPos, yMin-rectHeight, rectWidth, rectHeight);
826 layout.append(rect);
827 yMin -= rectHeight;
828 }
829 }
830 }
831
832 //====================================================================================
833 // barset 1, bar 0
834 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
835 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
836
837 QCOMPARE(seriesSpy.count(), 1);
838 QCOMPARE(setSpy1.count(), 1);
839 QCOMPARE(setSpy2.count(), 0);
840
841 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
842 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
843 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
844 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
845
846 QList<QVariant> setSpyArg = setSpy1.takeFirst();
847 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
848 QVERIFY(setSpyArg.at(0).toInt() == 0);
849
850 //====================================================================================
851 // barset 1, bar 1
852 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
853 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
854
855 QCOMPARE(seriesSpy.count(), 1);
856 QCOMPARE(setSpy1.count(), 1);
857 QCOMPARE(setSpy2.count(), 0);
858
859 seriesSpyArg = seriesSpy.takeFirst();
860 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
861 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
862 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
863
864 setSpyArg = setSpy1.takeFirst();
865 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
866 QVERIFY(setSpyArg.at(0).toInt() == 1);
867
868 //====================================================================================
869 // barset 1, bar 2
870 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
871 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
872
873 QCOMPARE(seriesSpy.count(), 1);
874 QCOMPARE(setSpy1.count(), 1);
875 QCOMPARE(setSpy2.count(), 0);
876
877 seriesSpyArg = seriesSpy.takeFirst();
878 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
879 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
880 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
881
882 setSpyArg = setSpy1.takeFirst();
883 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
884 QVERIFY(setSpyArg.at(0).toInt() == 2);
885
886 //====================================================================================
887 // barset 2, bar 0
888 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
889 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
890
891 QCOMPARE(seriesSpy.count(), 1);
892 QCOMPARE(setSpy1.count(), 0);
893 QCOMPARE(setSpy2.count(), 1);
894
895 seriesSpyArg = seriesSpy.takeFirst();
896 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
897 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
898 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
899
900 setSpyArg = setSpy2.takeFirst();
901 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
902 QVERIFY(setSpyArg.at(0).toInt() == 0);
903
904 //====================================================================================
905 // barset 2, bar 1
906 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
907 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
908
909 QCOMPARE(seriesSpy.count(), 1);
910 QCOMPARE(setSpy1.count(), 0);
911 QCOMPARE(setSpy2.count(), 1);
912
913 seriesSpyArg = seriesSpy.takeFirst();
914 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
915 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
916 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
917
918 setSpyArg = setSpy2.takeFirst();
919 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
920 QVERIFY(setSpyArg.at(0).toInt() == 1);
921
922 //====================================================================================
923 // barset 2, bar 2
924 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
925 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
926
927 QCOMPARE(seriesSpy.count(), 1);
928 QCOMPARE(setSpy1.count(), 0);
929 QCOMPARE(setSpy2.count(), 1);
930
931 seriesSpyArg = seriesSpy.takeFirst();
932 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
933 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
934 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
935
936 setSpyArg = setSpy2.takeFirst();
937 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
938 QVERIFY(setSpyArg.at(0).toInt() == 2);
939 }
940
941 void tst_QStackedBarSeries::mouseDoubleClicked()
942 {
943 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
944
945 QStackedBarSeries* series = new QStackedBarSeries();
946
947 QBarSet* set1 = new QBarSet(QString("set 1"));
948 *set1 << 10 << 10 << 10;
949 series->append(set1);
950
951 QBarSet* set2 = new QBarSet(QString("set 2"));
952 *set2 << 10 << 10 << 10;
953 series->append(set2);
954 QList<QBarSet*> barSets = series->barSets();
955
956 QSignalSpy seriesSpy(series,SIGNAL(doubleClicked(int,QBarSet*)));
957 QSignalSpy setSpy1(set1, SIGNAL(doubleClicked(int)));
958 QSignalSpy setSpy2(set2, SIGNAL(doubleClicked(int)));
959
960 QChartView view(new QChart());
961 view.resize(400,300);
962 view.chart()->addSeries(series);
963 view.show();
964 QTest::qWaitForWindowShown(&view);
965
966 // Calculate expected layout for bars
967 QRectF plotArea = view.chart()->plotArea();
968 qreal width = plotArea.width();
969 qreal height = plotArea.height();
970 qreal rangeY = 20; // From 0 to 20 because sets are stacked (this should be height of highest stack)
971 qreal rangeX = 3; // 3 values per set
972 qreal scaleY = (height / rangeY);
973 qreal scaleX = (width / rangeX);
974
975 qreal setCount = series->count();
976 qreal domainMinY = 0; // These come from internal domain used by barseries.
977 qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
978 qreal rectWidth = scaleX * series->barWidth();
979
980 QVector<QRectF> layout;
981
982 // 3 = count of values in set
983 // Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
984 for (int i = 0; i < 3; i++) {
985 qreal yMax = height + scaleY * domainMinY + plotArea.top();
986 qreal yMin = height + scaleY * domainMinY + plotArea.top();
987 for (int set = 0; set < setCount; set++) {
988 qreal xPos = (i - domainMinX) * scaleX + plotArea.left() - rectWidth/2;
989 qreal rectHeight = barSets.at(set)->at(i) * scaleY;
990 if (rectHeight < 0) {
991 QRectF rect(xPos, yMax-rectHeight, rectWidth, rectHeight);
992 layout.append(rect);
993 yMax -= rectHeight;
994 } else {
995 QRectF rect(xPos, yMin-rectHeight, rectWidth, rectHeight);
996 layout.append(rect);
997 yMin -= rectHeight;
998 }
999 }
1000 }
1001
1002 // barset 1, bar 0
1003 QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
1004 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
1005
1006 QCOMPARE(seriesSpy.count(), 1);
1007 QCOMPARE(setSpy1.count(), 1);
1008 QCOMPARE(setSpy2.count(), 0);
1009
1010 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
1011 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
1012 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
1013 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
1014
1015 QList<QVariant> setSpyArg = setSpy1.takeFirst();
1016 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
1017 QVERIFY(setSpyArg.at(0).toInt() == 0);
1018 }
598 QTEST_MAIN(tst_QStackedBarSeries)
1019 QTEST_MAIN(tst_QStackedBarSeries)
599
1020
600 #include "tst_qstackedbarseries.moc"
1021 #include "tst_qstackedbarseries.moc"
@@ -250,8 +250,15 void MainWidget::addSeries()
250 m_series[m_seriesCount]->setName("Box & Whiskers");
250 m_series[m_seriesCount]->setName("Box & Whiskers");
251
251
252 connect(m_series[m_seriesCount], SIGNAL(clicked(QBoxSet*)), this, SLOT(boxClicked(QBoxSet*)));
252 connect(m_series[m_seriesCount], SIGNAL(clicked(QBoxSet*)), this, SLOT(boxClicked(QBoxSet*)));
253 connect(m_series[m_seriesCount], SIGNAL(pressed(QBoxSet*)), this, SLOT(boxPressed(QBoxSet*)));
254 connect(m_series[m_seriesCount], SIGNAL(released(QBoxSet*)), this, SLOT(boxReleased(QBoxSet*)));
255 connect(m_series[m_seriesCount], SIGNAL(doubleClicked(QBoxSet*)),
256 this, SLOT(boxDoubleClicked(QBoxSet*)));
253 connect(m_series[m_seriesCount], SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(boxHovered(bool, QBoxSet*)));
257 connect(m_series[m_seriesCount], SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(boxHovered(bool, QBoxSet*)));
254 connect(set1, SIGNAL(clicked()), this, SLOT(singleBoxClicked()));
258 connect(set1, SIGNAL(clicked()), this, SLOT(singleBoxClicked()));
259 connect(set1, SIGNAL(pressed()), this, SLOT(singleBoxPressed()));
260 connect(set1, SIGNAL(released()), this, SLOT(singleBoxReleased()));
261 connect(set1, SIGNAL(doubleClicked()), this, SLOT(singleBoxDoubleClicked()));
255 connect(set2, SIGNAL(hovered(bool)), this, SLOT(singleBoxHovered(bool)));
262 connect(set2, SIGNAL(hovered(bool)), this, SLOT(singleBoxHovered(bool)));
256
263
257 m_series[m_seriesCount]->setBoxOutlineVisible(m_boxOutlined->checkState());
264 m_series[m_seriesCount]->setBoxOutlineVisible(m_boxOutlined->checkState());
@@ -453,11 +460,41 void MainWidget::boxHovered(bool state, QBoxSet *set)
453 qDebug() << "box median " << set->at(QBoxSet::Median) << " hover ended";
460 qDebug() << "box median " << set->at(QBoxSet::Median) << " hover ended";
454 }
461 }
455
462
463 void MainWidget::boxPressed(QBoxSet *set)
464 {
465 qDebug() << "boxPressed, median = " << set->at(QBoxSet::Median);
466 }
467
468 void MainWidget::boxReleased(QBoxSet *set)
469 {
470 qDebug() << "boxReleased, median = " << set->at(QBoxSet::Median);
471 }
472
473 void MainWidget::boxDoubleClicked(QBoxSet *set)
474 {
475 qDebug() << "boxDoubleClicked, median = " << set->at(QBoxSet::Median);
476 }
477
456 void MainWidget::singleBoxClicked()
478 void MainWidget::singleBoxClicked()
457 {
479 {
458 qDebug() << "singleBoxClicked";
480 qDebug() << "singleBoxClicked";
459 }
481 }
460
482
483 void MainWidget::singleBoxPressed()
484 {
485 qDebug() << "singleBoxPressed";
486 }
487
488 void MainWidget::singleBoxReleased()
489 {
490 qDebug() << "singleBoxReleased";
491 }
492
493 void MainWidget::singleBoxDoubleClicked()
494 {
495 qDebug() << "singleBoxDoubleClicked";
496 }
497
461 void MainWidget::singleBoxHovered(bool state)
498 void MainWidget::singleBoxHovered(bool state)
462 {
499 {
463 if (state)
500 if (state)
@@ -66,8 +66,14 private slots:
66 void changeChartTheme(int themeIndex);
66 void changeChartTheme(int themeIndex);
67 void boxClicked(QBoxSet *set);
67 void boxClicked(QBoxSet *set);
68 void boxHovered(bool state, QBoxSet *set);
68 void boxHovered(bool state, QBoxSet *set);
69 void boxPressed(QBoxSet *set);
70 void boxReleased(QBoxSet *set);
71 void boxDoubleClicked(QBoxSet *set);
69 void singleBoxClicked();
72 void singleBoxClicked();
70 void singleBoxHovered(bool state);
73 void singleBoxHovered(bool state);
74 void singleBoxPressed();
75 void singleBoxReleased();
76 void singleBoxDoubleClicked();
71 void changePen();
77 void changePen();
72 void antialiasingToggled(bool);
78 void antialiasingToggled(bool);
73 void boxOutlineToggled(bool);
79 void boxOutlineToggled(bool);
@@ -81,6 +81,9 ChartView {
81 + font.family);
81 + font.family);
82 onPointLabelsColorChanged: console.log(name + ".onPointLabelsColorChanged: "
82 onPointLabelsColorChanged: console.log(name + ".onPointLabelsColorChanged: "
83 + color);
83 + color);
84 onPressed: console.log(name + ".onPressed: " + point.x + ", " + point.y);
85 onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
86 onDoubleClicked: console.log(name + ".onDoubleClicked: " + point.x + ", " + point.y);
84 }
87 }
85
88
86 AreaSeries {
89 AreaSeries {
@@ -107,5 +110,8 ChartView {
107 onSelected: console.log(name + ".onSelected");
110 onSelected: console.log(name + ".onSelected");
108 onColorChanged: console.log(name + ".onColorChanged: " + color);
111 onColorChanged: console.log(name + ".onColorChanged: " + color);
109 onBorderColorChanged: console.log(name + ".onBorderColorChanged: " + borderColor);
112 onBorderColorChanged: console.log(name + ".onBorderColorChanged: " + borderColor);
113 onPressed: console.log(name + ".onPressed: " + point.x + ", " + point.y);
114 onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
115 onDoubleClicked: console.log(name + ".onDoubleClicked: " + point.x + ", " + point.y);
110 }
116 }
111 }
117 }
@@ -51,6 +51,10 ChartView {
51 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
51 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
52 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
52 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
53 onValueChanged: console.log("barset.onValuesChanged: " + index);
53 onValueChanged: console.log("barset.onValuesChanged: " + index);
54 onPressed: console.log("barset.onPressed: " + index);
55 onReleased: console.log("barset.onReleased: " + index);
56 onDoubleClicked: console.log("barset.onDoubleClicked: " + index);
57
54 }
58 }
55 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
59 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
56 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
60 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
@@ -65,6 +69,9 ChartView {
65 onCountChanged: console.log("barSeries.onCountChanged: " + count);
69 onCountChanged: console.log("barSeries.onCountChanged: " + count);
66 onLabelsFormatChanged: console.log("barSeries.onLabelsFormatChanged: " + format);
70 onLabelsFormatChanged: console.log("barSeries.onLabelsFormatChanged: " + format);
67 onLabelsPositionChanged: console.log("barSeries.onLabelsPositionChanged: " + series.labelsPosition);
71 onLabelsPositionChanged: console.log("barSeries.onLabelsPositionChanged: " + series.labelsPosition);
72 onPressed: console.log("barSeries.onPressed: " + barset + " " + index);
73 onReleased: console.log("barSeries.onReleased: " + barset + " " + index);
74 onDoubleClicked: console.log("barSeries.onDoubleClicked: " + barset + " " + index);
68
75
69 function changeLabelsPosition() {
76 function changeLabelsPosition() {
70 if (labelsPosition === BarSeries.LabelsCenter)
77 if (labelsPosition === BarSeries.LabelsCenter)
@@ -50,6 +50,9 ChartView {
50 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
50 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
51 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
51 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
52 onValueChanged: console.log("barset.onValuesChanged: " + index);
52 onValueChanged: console.log("barset.onValuesChanged: " + index);
53 onPressed: console.log("barset.onPressed: " + index);
54 onReleased: console.log("barset.onReleased: " + index);
55 onDoubleClicked: console.log("barset.onDoubleClicked: " + index);
53 }
56 }
54 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
57 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
55 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
58 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
@@ -66,6 +69,9 ChartView {
66 + format);
69 + format);
67 onLabelsPositionChanged: console.log("horizontalBarSeries.onLabelsPositionChanged: "
70 onLabelsPositionChanged: console.log("horizontalBarSeries.onLabelsPositionChanged: "
68 + series.labelsPosition);
71 + series.labelsPosition);
72 onPressed: console.log("horizontalBarSeries.onPressed: " + barset + " " + index);
73 onReleased: console.log("horizontalBarSeries.onReleased: " + barset + " " + index);
74 onDoubleClicked: console.log("horizontalBarSeries.onDoubleClicked: " + barset + " " + index);
69
75
70 function changeLabelsPosition() {
76 function changeLabelsPosition() {
71 if (labelsPosition === BarSeries.LabelsCenter)
77 if (labelsPosition === BarSeries.LabelsCenter)
@@ -50,6 +50,9 ChartView {
50 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
50 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
51 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
51 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
52 onValueChanged: console.log("barset.onValuesChanged: " + index);
52 onValueChanged: console.log("barset.onValuesChanged: " + index);
53 onPressed: console.log("barset.onPressed: " + index);
54 onReleased: console.log("barset.onReleased: " + index);
55 onDoubleClicked: console.log("barset.onDoubleClicked: " + index);
53 }
56 }
54 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
57 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
55 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
58 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
@@ -68,6 +71,9 ChartView {
68 onLabelsPositionChanged: console.log(
71 onLabelsPositionChanged: console.log(
69 "horizontalPercentBarSeries.onLabelsPositionChanged: "
72 "horizontalPercentBarSeries.onLabelsPositionChanged: "
70 + series.labelsPosition);
73 + series.labelsPosition);
74 onPressed: console.log("horizontalPercentBarSeries.onPressed: " + barset + " " + index);
75 onReleased: console.log("horizontalPercentBarSeries.onReleased: " + barset + " " + index);
76 onDoubleClicked: console.log("horizontalPercentBarSeries.onDoubleClicked: " + barset + " " + index);
71
77
72 function changeLabelsPosition() {
78 function changeLabelsPosition() {
73 if (labelsPosition === BarSeries.LabelsCenter)
79 if (labelsPosition === BarSeries.LabelsCenter)
@@ -50,6 +50,9 ChartView {
50 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
50 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
51 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
51 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
52 onValueChanged: console.log("barset.onValuesChanged: " + index);
52 onValueChanged: console.log("barset.onValuesChanged: " + index);
53 onPressed: console.log("barset.onPressed: " + index);
54 onReleased: console.log("barset.onReleased: " + index);
55 onDoubleClicked: console.log("barset.onDoubleClicked: " + index);
53 }
56 }
54 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
57 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
55 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
58 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
@@ -68,6 +71,9 ChartView {
68 onLabelsPositionChanged: console.log(
71 onLabelsPositionChanged: console.log(
69 "horizontalStackedBarSeries.onLabelsPositionChanged: "
72 "horizontalStackedBarSeries.onLabelsPositionChanged: "
70 + series.labelsPosition);
73 + series.labelsPosition);
74 onPressed: console.log("horizontalStackedBarSeries.onPressed: " + barset + " " + index);
75 onReleased: console.log("horizontalStackedBarSeries.onReleased: " + barset + " " + index);
76 onDoubleClicked: console.log("horizontalStackedBarSeries.onDoubleClicked: " + barset + " " + index);
71
77
72 function changeLabelsPosition() {
78 function changeLabelsPosition() {
73 if (labelsPosition === BarSeries.LabelsCenter)
79 if (labelsPosition === BarSeries.LabelsCenter)
@@ -62,6 +62,9 ChartView {
62 + font.family);
62 + font.family);
63 onPointLabelsColorChanged: console.log("lineSeries.onPointLabelsColorChanged: "
63 onPointLabelsColorChanged: console.log("lineSeries.onPointLabelsColorChanged: "
64 + color);
64 + color);
65 onPressed: console.log(name + ".onPressed: " + point.x + ", " + point.y);
66 onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
67 onDoubleClicked: console.log(name + ".onDoubleClicked: " + point.x + ", " + point.y);
65 }
68 }
66
69
67 LineSeries {
70 LineSeries {
@@ -74,5 +77,8 ChartView {
74 XYPoint { x: 4.1; y: 2.3 }
77 XYPoint { x: 4.1; y: 2.3 }
75 onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y);
78 onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y);
76 onHovered: console.log(name + ".onHovered: " + point.x + ", " + point.y);
79 onHovered: console.log(name + ".onHovered: " + point.x + ", " + point.y);
80 onPressed: console.log(name + ".onPressed: " + point.x + ", " + point.y);
81 onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
82 onDoubleClicked: console.log(name + ".onDoubleClicked: " + point.x + ", " + point.y);
77 }
83 }
78 }
84 }
@@ -51,6 +51,9 ChartView {
51 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
51 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
52 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
52 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
53 onValueChanged: console.log("barset.onValuesChanged: " + index);
53 onValueChanged: console.log("barset.onValuesChanged: " + index);
54 onPressed: console.log("barset.onPressed: " + index);
55 onReleased: console.log("barset.onReleased: " + index);
56 onDoubleClicked: console.log("barset.onDoubleClicked: " + index);
54 }
57 }
55 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
58 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
56 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
59 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
@@ -67,6 +70,9 ChartView {
67 + format);
70 + format);
68 onLabelsPositionChanged: console.log("percentBarSeries.onLabelsPositionChanged: "
71 onLabelsPositionChanged: console.log("percentBarSeries.onLabelsPositionChanged: "
69 + series.labelsPosition);
72 + series.labelsPosition);
73 onPressed: console.log("percentBarSeries.onPressed: " + barset + " " + index);
74 onReleased: console.log("percentBarSeries.onReleased: " + barset + " " + index);
75 onDoubleClicked: console.log("percentBarSeries.onDoubleClicked: " + barset + " " + index);
70
76
71 function changeLabelsPosition() {
77 function changeLabelsPosition() {
72 if (labelsPosition === BarSeries.LabelsCenter)
78 if (labelsPosition === BarSeries.LabelsCenter)
@@ -47,6 +47,9 ChartView {
47 onAngleSpanChanged: console.log("slice.onAngleSpanChanged: " + angleSpan);
47 onAngleSpanChanged: console.log("slice.onAngleSpanChanged: " + angleSpan);
48 onClicked: console.log("slice.onClicked: " + label);
48 onClicked: console.log("slice.onClicked: " + label);
49 onHovered: console.log("slice.onHovered: " + state);
49 onHovered: console.log("slice.onHovered: " + state);
50 onPressed: console.log("slice.onPressed: " + label);
51 onReleased: console.log("slice.onReleased: " + label);
52 onDoubleClicked: console.log("slice.onDoubleClicked: " + label);
50 }
53 }
51 PieSlice { label: "slice2"; value: 22 }
54 PieSlice { label: "slice2"; value: 22 }
52 PieSlice { label: "slice3"; value: 33 }
55 PieSlice { label: "slice3"; value: 33 }
@@ -63,5 +66,8 ChartView {
63 onSliceRemoved: console.log("pieSeries.onSliceRemoved: " + slice.label);
66 onSliceRemoved: console.log("pieSeries.onSliceRemoved: " + slice.label);
64 onCountChanged: console.log("pieSeries.onCountChanged: " + count);
67 onCountChanged: console.log("pieSeries.onCountChanged: " + count);
65 onSumChanged: console.log("pieSeries.onSumChanged: " + sum);
68 onSumChanged: console.log("pieSeries.onSumChanged: " + sum);
69 onPressed: console.log("pieSeries.onPressed: " + slice.label);
70 onReleased: console.log("pieSeries.onReleased: " + slice.label);
71 onDoubleClicked: console.log("pieSeries.onDoubleClicked: " + slice.label);
66 }
72 }
67 }
73 }
@@ -59,6 +59,9 ChartView {
59 + font.family);
59 + font.family);
60 onPointLabelsColorChanged: console.log("lineSeries.onPointLabelsColorChanged: "
60 onPointLabelsColorChanged: console.log("lineSeries.onPointLabelsColorChanged: "
61 + color);
61 + color);
62 onPressed: console.log(name + ".onPressed: " + point.x + ", " + point.y);
63 onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
64 onDoubleClicked: console.log(name + ".onDoubleClicked: " + point.x + ", " + point.y);
62 }
65 }
63
66
64 ScatterSeries {
67 ScatterSeries {
@@ -71,5 +74,8 ChartView {
71 XYPoint { x: 2.67; y: 2.65 }
74 XYPoint { x: 2.67; y: 2.65 }
72 onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y);
75 onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y);
73 onHovered: console.log(name + ".onHovered: " + point.x + ", " + point.y);
76 onHovered: console.log(name + ".onHovered: " + point.x + ", " + point.y);
77 onPressed: console.log(name + ".onPressed: " + point.x + ", " + point.y);
78 onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
79 onDoubleClicked: console.log(name + ".onDoubleClicked: " + point.x + ", " + point.y);
74 }
80 }
75 }
81 }
@@ -61,6 +61,9 ChartView {
61 + font.family);
61 + font.family);
62 onPointLabelsColorChanged: console.log("splineSeries.onPointLabelsColorChanged: "
62 onPointLabelsColorChanged: console.log("splineSeries.onPointLabelsColorChanged: "
63 + color);
63 + color);
64 onPressed: console.log(name + ".onPressed: " + point.x + ", " + point.y);
65 onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
66 onDoubleClicked: console.log(name + ".onDoubleClicked: " + point.x + ", " + point.y);
64 }
67 }
65
68
66 SplineSeries {
69 SplineSeries {
@@ -73,5 +76,8 ChartView {
73 XYPoint { x: 4.1; y: 2.3 }
76 XYPoint { x: 4.1; y: 2.3 }
74 onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y);
77 onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y);
75 onHovered: console.log(name + ".onHovered: " + point.x + ", " + point.y);
78 onHovered: console.log(name + ".onHovered: " + point.x + ", " + point.y);
79 onPressed: console.log(name + ".onPressed: " + point.x + ", " + point.y);
80 onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
81 onDoubleClicked: console.log(name + ".onDoubleClicked: " + point.x + ", " + point.y);
76 }
82 }
77 }
83 }
@@ -50,6 +50,9 ChartView {
50 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
50 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
51 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
51 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
52 onValueChanged: console.log("barset.onValuesChanged: " + index);
52 onValueChanged: console.log("barset.onValuesChanged: " + index);
53 onPressed: console.log("barset.onPressed: " + index);
54 onReleased: console.log("barset.onReleased: " + index);
55 onDoubleClicked: console.log("barset.onDoubleClicked: " + index);
53 }
56 }
54 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
57 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
55 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
58 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
@@ -66,6 +69,9 ChartView {
66 + format);
69 + format);
67 onLabelsPositionChanged: console.log("stackedBarSeries.onLabelsPositionChanged: "
70 onLabelsPositionChanged: console.log("stackedBarSeries.onLabelsPositionChanged: "
68 + series.labelsPosition);
71 + series.labelsPosition);
72 onPressed: console.log("stackedBarSeries.onPressed: " + barset + " " + index);
73 onReleased: console.log("stackedBarSeries.onReleased: " + barset + " " + index);
74 onDoubleClicked: console.log("stackedBarSeries.onDoubleClicked: " + barset + " " + index);
69
75
70 function changeLabelsPosition() {
76 function changeLabelsPosition() {
71 if (labelsPosition === BarSeries.LabelsCenter)
77 if (labelsPosition === BarSeries.LabelsCenter)
General Comments 0
You need to be logged in to leave comments. Login now