##// END OF EJS Templates
legendmarker hover signal test and fix
sauimone -
r2210:68629cc35cc4
parent child
Show More
@@ -1,165 +1,189
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QPainter>
21 #include <QPainter>
22 #include <QGraphicsSceneEvent>
22 #include <QGraphicsSceneEvent>
23 #include <QGraphicsSimpleTextItem>
23 #include <QGraphicsSimpleTextItem>
24
24
25 #include "qlegend.h"
25 #include "qlegend.h"
26 #include "qlegend_p.h"
26 #include "qlegend_p.h"
27 #include "qlegendmarker.h"
27 #include "qlegendmarker.h"
28 #include "qlegendmarker_p.h"
28 #include "qlegendmarker_p.h"
29 #include "legendmarkeritem_p.h"
29 #include "legendmarkeritem_p.h"
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) :
33 LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) :
34 QGraphicsObject(parent),
34 QGraphicsObject(parent),
35 m_marker(marker),
35 m_marker(marker),
36 m_markerRect(0,0,10.0,10.0),
36 m_markerRect(0,0,10.0,10.0),
37 m_boundingRect(0,0,0,0),
37 m_boundingRect(0,0,0,0),
38 m_textItem(new QGraphicsSimpleTextItem(this)),
38 m_textItem(new QGraphicsSimpleTextItem(this)),
39 m_rectItem(new QGraphicsRectItem(this)),
39 m_rectItem(new QGraphicsRectItem(this)),
40 m_margin(4),
40 m_margin(4),
41 m_space(4),
41 m_space(4),
42 m_hovering(false),
42 m_pressPos(0, 0)
43 m_pressPos(0, 0)
43 {
44 {
44 m_rectItem->setRect(m_markerRect);
45 m_rectItem->setRect(m_markerRect);
46 setAcceptsHoverEvents(true);
47 }
48
49 LegendMarkerItem::~LegendMarkerItem()
50 {
51 if (m_hovering) {
52 emit m_marker->q_ptr->hovered(false);
53 }
45 }
54 }
46
55
47 void LegendMarkerItem::setPen(const QPen &pen)
56 void LegendMarkerItem::setPen(const QPen &pen)
48 {
57 {
49 m_rectItem->setPen(pen);
58 m_rectItem->setPen(pen);
50 }
59 }
51
60
52 QPen LegendMarkerItem::pen() const
61 QPen LegendMarkerItem::pen() const
53 {
62 {
54 return m_rectItem->pen();
63 return m_rectItem->pen();
55 }
64 }
56
65
57 void LegendMarkerItem::setBrush(const QBrush &brush)
66 void LegendMarkerItem::setBrush(const QBrush &brush)
58 {
67 {
59 m_rectItem->setBrush(brush);
68 m_rectItem->setBrush(brush);
60 }
69 }
61
70
62 QBrush LegendMarkerItem::brush() const
71 QBrush LegendMarkerItem::brush() const
63 {
72 {
64 return m_rectItem->brush();
73 return m_rectItem->brush();
65 }
74 }
66
75
67 void LegendMarkerItem::setFont(const QFont &font)
76 void LegendMarkerItem::setFont(const QFont &font)
68 {
77 {
69 m_textItem->setFont(font);
78 m_textItem->setFont(font);
70 QFontMetrics fn(font);
79 QFontMetrics fn(font);
71 m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2);
80 m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2);
72 updateGeometry();
81 updateGeometry();
73 }
82 }
74
83
75 QFont LegendMarkerItem::font() const
84 QFont LegendMarkerItem::font() const
76 {
85 {
77 return m_textItem->font();
86 return m_textItem->font();
78 }
87 }
79
88
80 void LegendMarkerItem::setLabel(const QString label)
89 void LegendMarkerItem::setLabel(const QString label)
81 {
90 {
82 m_label = label;
91 m_label = label;
83 updateGeometry();
92 updateGeometry();
84 }
93 }
85
94
86 QString LegendMarkerItem::label() const
95 QString LegendMarkerItem::label() const
87 {
96 {
88 return m_label;
97 return m_label;
89 }
98 }
90
99
91 void LegendMarkerItem::setLabelBrush(const QBrush &brush)
100 void LegendMarkerItem::setLabelBrush(const QBrush &brush)
92 {
101 {
93 m_textItem->setBrush(brush);
102 m_textItem->setBrush(brush);
94 }
103 }
95
104
96 QBrush LegendMarkerItem::labelBrush() const
105 QBrush LegendMarkerItem::labelBrush() const
97 {
106 {
98 return m_textItem->brush();
107 return m_textItem->brush();
99 }
108 }
100
109
101 void LegendMarkerItem::setGeometry(const QRectF &rect)
110 void LegendMarkerItem::setGeometry(const QRectF &rect)
102 {
111 {
103 QFontMetrics fn (m_font);
112 QFontMetrics fn (m_font);
104
113
105 int width = rect.width();
114 int width = rect.width();
106 qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
115 qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
107 qreal y = qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin);
116 qreal y = qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin);
108
117
109 if (fn.boundingRect(m_label).width() + x > width)
118 if (fn.boundingRect(m_label).width() + x > width)
110 {
119 {
111 QString string = m_label + "...";
120 QString string = m_label + "...";
112 while(fn.boundingRect(string).width() + x > width && string.length() > 3)
121 while(fn.boundingRect(string).width() + x > width && string.length() > 3)
113 string.remove(string.length() - 4, 1);
122 string.remove(string.length() - 4, 1);
114 m_textItem->setText(string);
123 m_textItem->setText(string);
115 }
124 }
116 else
125 else
117 m_textItem->setText(m_label);
126 m_textItem->setText(m_label);
118
127
119 const QRectF &textRect = m_textItem->boundingRect();
128 const QRectF &textRect = m_textItem->boundingRect();
120
129
121
130
122 m_textItem->setPos(x-m_margin,y/2 - textRect.height()/2);
131 m_textItem->setPos(x-m_margin,y/2 - textRect.height()/2);
123 m_rectItem->setRect(m_markerRect);
132 m_rectItem->setRect(m_markerRect);
124 m_rectItem->setPos(m_margin,y/2 - m_markerRect.height()/2);
133 m_rectItem->setPos(m_margin,y/2 - m_markerRect.height()/2);
125
134
126 prepareGeometryChange();
135 prepareGeometryChange();
127 m_boundingRect = QRectF(0,0,x+textRect.width()+m_margin,y);
136 m_boundingRect = QRectF(0,0,x+textRect.width()+m_margin,y);
128 }
137 }
129
138
130 QRectF LegendMarkerItem::boundingRect() const
139 QRectF LegendMarkerItem::boundingRect() const
131 {
140 {
132 return m_boundingRect;
141 return m_boundingRect;
133 }
142 }
134
143
135 void LegendMarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
144 void LegendMarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
136 {
145 {
137 Q_UNUSED(option)
146 Q_UNUSED(option)
138 Q_UNUSED(widget)
147 Q_UNUSED(widget)
139 Q_UNUSED(painter)
148 Q_UNUSED(painter)
140 }
149 }
141
150
142 QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
151 QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
143 {
152 {
144 Q_UNUSED(constraint)
153 Q_UNUSED(constraint)
145
154
146 QFontMetrics fn(m_textItem->font());
155 QFontMetrics fn(m_textItem->font());
147 QSizeF sh;
156 QSizeF sh;
148
157
149 switch (which) {
158 switch (which) {
150 case Qt::MinimumSize:
159 case Qt::MinimumSize:
151 sh = QSizeF(fn.boundingRect("...").width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
160 sh = QSizeF(fn.boundingRect("...").width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
152 break;
161 break;
153 case Qt::PreferredSize:
162 case Qt::PreferredSize:
154 sh = QSizeF(fn.boundingRect(m_label).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
163 sh = QSizeF(fn.boundingRect(m_label).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
155 break;
164 break;
156 default:
165 default:
157 break;
166 break;
158 }
167 }
159
168
160 return sh;
169 return sh;
161 }
170 }
162
171
172 void LegendMarkerItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
173 {
174 Q_UNUSED(event)
175 m_hovering = true;
176 emit m_marker->q_ptr->hovered(true);
177 }
178
179 void LegendMarkerItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
180 {
181 Q_UNUSED(event)
182 m_hovering = false;
183 emit m_marker->q_ptr->hovered(false);
184 }
185
186
163 #include "moc_legendmarkeritem_p.cpp"
187 #include "moc_legendmarkeritem_p.cpp"
164
188
165 QTCOMMERCIALCHART_END_NAMESPACE
189 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,98 +1,102
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef LEGENDMARKERITEM_P_H
30 #ifndef LEGENDMARKERITEM_P_H
31 #define LEGENDMARKERITEM_P_H
31 #define LEGENDMARKERITEM_P_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include <QGraphicsObject>
34 #include <QGraphicsObject>
35 #include <QFont>
35 #include <QFont>
36 #include <QBrush>
36 #include <QBrush>
37 #include <QPen>
37 #include <QPen>
38 #include <QGraphicsSimpleTextItem>
38 #include <QGraphicsSimpleTextItem>
39 #include <QGraphicsLayoutItem>
39 #include <QGraphicsLayoutItem>
40
40
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
42
42
43 class QLegendMarkerPrivate;
43 class QLegendMarkerPrivate;
44
44
45 class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem
45 class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem
46 {
46 {
47 Q_OBJECT
47 Q_OBJECT
48 Q_INTERFACES(QGraphicsLayoutItem)
48 Q_INTERFACES(QGraphicsLayoutItem)
49 public:
49 public:
50 explicit LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent = 0);
50 explicit LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent = 0);
51 ~LegendMarkerItem();
51
52
52 void setPen(const QPen &pen);
53 void setPen(const QPen &pen);
53 QPen pen() const;
54 QPen pen() const;
54
55
55 void setBrush(const QBrush &brush);
56 void setBrush(const QBrush &brush);
56 QBrush brush() const;
57 QBrush brush() const;
57
58
58 void setFont(const QFont &font);
59 void setFont(const QFont &font);
59 QFont font() const;
60 QFont font() const;
60
61
61 void setLabel(const QString label);
62 void setLabel(const QString label);
62 QString label() const;
63 QString label() const;
63
64
64 void setLabelBrush(const QBrush &brush);
65 void setLabelBrush(const QBrush &brush);
65 QBrush labelBrush() const;
66 QBrush labelBrush() const;
66
67
67 void setGeometry(const QRectF &rect);
68 void setGeometry(const QRectF &rect);
68 QRectF boundingRect() const;
69 QRectF boundingRect() const;
69
70
70 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
71 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
71 QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint) const;
72 QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint) const;
72
73
74 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
75 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
76
73 protected:
77 protected:
74 QLegendMarkerPrivate *m_marker; // Knows
78 QLegendMarkerPrivate *m_marker; // Knows
75 QRectF m_markerRect;
79 QRectF m_markerRect;
76 QRectF m_boundingRect;
80 QRectF m_boundingRect;
77 QGraphicsSimpleTextItem *m_textItem;
81 QGraphicsSimpleTextItem *m_textItem;
78 QGraphicsRectItem *m_rectItem;
82 QGraphicsRectItem *m_rectItem;
79 qreal m_margin;
83 qreal m_margin;
80 qreal m_space;
84 qreal m_space;
81 QString m_label;
85 QString m_label;
82
86
83 QBrush m_labelBrush;
87 QBrush m_labelBrush;
84 QFont m_font;
88 QFont m_font;
85 QPen m_pen;
89 QPen m_pen;
86 QBrush m_brush;
90 QBrush m_brush;
87 bool m_visible;
91 bool m_hovering;
88
92
89 QPointF m_pressPos;
93 QPointF m_pressPos;
90
94
91 friend class QLegendMarker;
95 friend class QLegendMarker;
92 friend class QLegendMarkerPrivate;
96 friend class QLegendMarkerPrivate;
93 friend class LegendLayout;
97 friend class LegendLayout;
94 };
98 };
95
99
96 QTCOMMERCIALCHART_END_NAMESPACE
100 QTCOMMERCIALCHART_END_NAMESPACE
97
101
98 #endif // LEGENDMARKERITEM_P_H
102 #endif // LEGENDMARKERITEM_P_H
@@ -1,485 +1,551
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qchartview.h>
22 #include <qchartview.h>
23 #include <qlegend.h>
23 #include <qlegend.h>
24 #include <qpieseries.h>
24 #include <qpieseries.h>
25 #include <qpielegendmarker.h>
25 #include <qpielegendmarker.h>
26 #include <qareaseries.h>
26 #include <qareaseries.h>
27 #include <qarealegendmarker.h>
27 #include <qarealegendmarker.h>
28 #include <qlineseries.h>
28 #include <qlineseries.h>
29 #include <qxylegendmarker.h>
29 #include <qxylegendmarker.h>
30 #include <qscatterseries.h>
30 #include <qscatterseries.h>
31 #include <qbarseries.h>
31 #include <qbarseries.h>
32 #include <qbarset.h>
32 #include <qbarset.h>
33 #include <qbarlegendmarker.h>
33 #include <qbarlegendmarker.h>
34 #include "tst_definitions.h"
34 #include "tst_definitions.h"
35
35
36 QTCOMMERCIALCHART_USE_NAMESPACE
36 QTCOMMERCIALCHART_USE_NAMESPACE
37
37
38 class tst_QLegend : public QObject
38 class tst_QLegend : public QObject
39 {
39 {
40 Q_OBJECT
40 Q_OBJECT
41
41
42 public slots:
42 public slots:
43 void initTestCase();
43 void initTestCase();
44 void cleanupTestCase();
44 void cleanupTestCase();
45 void init();
45 void init();
46 void cleanup();
46 void cleanup();
47
47
48 private slots:
48 private slots:
49 void qlegend();
49 void qlegend();
50 void qpieLegendMarker();
50 void qpieLegendMarker();
51 void qareaLegendMarker();
51 void qareaLegendMarker();
52 void qxyLegendMarker();
52 void qxyLegendMarker();
53 void qbarLegendMarker();
53 void qbarLegendMarker();
54 void markers();
54 void markers();
55 void addAndRemoveSeries();
55 void addAndRemoveSeries();
56 void pieMarkerProperties();
56 void pieMarkerProperties();
57 void barMarkerProperties();
57 void barMarkerProperties();
58 void areaMarkerProperties();
58 void areaMarkerProperties();
59 void xyMarkerPropertiesLine();
59 void xyMarkerPropertiesLine();
60 void xyMarkerPropertiesScatter();
60 void xyMarkerPropertiesScatter();
61 void markerSignals();
61
62
62 private:
63 private:
63
64
64 QChart *m_chart;
65 QChart *m_chart;
65
66
66 };
67 };
67
68
68 void tst_QLegend::initTestCase()
69 void tst_QLegend::initTestCase()
69 {
70 {
70 }
71 }
71
72
72 void tst_QLegend::cleanupTestCase()
73 void tst_QLegend::cleanupTestCase()
73 {
74 {
74 }
75 }
75
76
76 void tst_QLegend::init()
77 void tst_QLegend::init()
77 {
78 {
78 m_chart = new QChart();
79 m_chart = new QChart();
79 }
80 }
80
81
81 void tst_QLegend::cleanup()
82 void tst_QLegend::cleanup()
82 {
83 {
83 delete m_chart;
84 delete m_chart;
84 m_chart = 0;
85 m_chart = 0;
85 }
86 }
86
87
87 void tst_QLegend::qlegend()
88 void tst_QLegend::qlegend()
88 {
89 {
89 QVERIFY(m_chart);
90 QVERIFY(m_chart);
90
91
91 QLegend *legend = m_chart->legend();
92 QLegend *legend = m_chart->legend();
92 QVERIFY(legend);
93 QVERIFY(legend);
93
94
94 QList<QLegendMarker*> markers = legend->markers();
95 QList<QLegendMarker*> markers = legend->markers();
95 QVERIFY(markers.count() == 0);
96 QVERIFY(markers.count() == 0);
96 }
97 }
97
98
98 void tst_QLegend::qpieLegendMarker()
99 void tst_QLegend::qpieLegendMarker()
99 {
100 {
100 QVERIFY(m_chart);
101 QVERIFY(m_chart);
101 QLegend *legend = m_chart->legend();
102 QLegend *legend = m_chart->legend();
102
103
103 QPieSeries *series = new QPieSeries();
104 QPieSeries *series = new QPieSeries();
104 QPieSlice *s1 = new QPieSlice(QString("s1"), 111.0);
105 QPieSlice *s1 = new QPieSlice(QString("s1"), 111.0);
105 series->append(s1);
106 series->append(s1);
106 m_chart->addSeries(series);
107 m_chart->addSeries(series);
107
108
108 // Should have one marker
109 // Should have one marker
109 QList<QLegendMarker*> markers = legend->markers();
110 QList<QLegendMarker*> markers = legend->markers();
110 QVERIFY(markers.count() == 1);
111 QVERIFY(markers.count() == 1);
111 QLegendMarker *m = markers.at(0);
112 QLegendMarker *m = markers.at(0);
112
113
113 // Should be piemarker
114 // Should be piemarker
114 QVERIFY(m->type() == QLegendMarker::LegendMarkerTypePie);
115 QVERIFY(m->type() == QLegendMarker::LegendMarkerTypePie);
115
116
116 // Related series and slice must match
117 // Related series and slice must match
117 QPieLegendMarker *pm = qobject_cast<QPieLegendMarker *> (m);
118 QPieLegendMarker *pm = qobject_cast<QPieLegendMarker *> (m);
118 QVERIFY(pm);
119 QVERIFY(pm);
119 QVERIFY(pm->series() == series);
120 QVERIFY(pm->series() == series);
120 QVERIFY(pm->slice() == s1);
121 QVERIFY(pm->slice() == s1);
121
122
122 // Add another slice
123 // Add another slice
123 QPieSlice *s2 = new QPieSlice(QString("s2"), 111.0);
124 QPieSlice *s2 = new QPieSlice(QString("s2"), 111.0);
124 series->append(s2);
125 series->append(s2);
125
126
126 markers = legend->markers();
127 markers = legend->markers();
127 QVERIFY(markers.count() == 2);
128 QVERIFY(markers.count() == 2);
128 m = markers.at(1);
129 m = markers.at(1);
129
130
130 QVERIFY(m->type() == QLegendMarker::LegendMarkerTypePie);
131 QVERIFY(m->type() == QLegendMarker::LegendMarkerTypePie);
131
132
132 // Related series and slice must match
133 // Related series and slice must match
133 pm = qobject_cast<QPieLegendMarker *> (m);
134 pm = qobject_cast<QPieLegendMarker *> (m);
134 QVERIFY(pm);
135 QVERIFY(pm);
135 QVERIFY(pm->series() == series);
136 QVERIFY(pm->series() == series);
136 QVERIFY(pm->slice() == s2);
137 QVERIFY(pm->slice() == s2);
137 }
138 }
138
139
139 void tst_QLegend::qareaLegendMarker()
140 void tst_QLegend::qareaLegendMarker()
140 {
141 {
141 QVERIFY(m_chart);
142 QVERIFY(m_chart);
142 QLegend *legend = m_chart->legend();
143 QLegend *legend = m_chart->legend();
143 QAreaSeries *series = new QAreaSeries();
144 QAreaSeries *series = new QAreaSeries();
144
145
145 QLineSeries *upper = new QLineSeries();
146 QLineSeries *upper = new QLineSeries();
146 QLineSeries *lower = new QLineSeries();
147 QLineSeries *lower = new QLineSeries();
147
148
148 upper->append(1,1);
149 upper->append(1,1);
149 lower->append(1,0);
150 lower->append(1,0);
150
151
151 series->setUpperSeries(upper);
152 series->setUpperSeries(upper);
152 series->setLowerSeries(lower);
153 series->setLowerSeries(lower);
153
154
154 m_chart->addSeries(series);
155 m_chart->addSeries(series);
155
156
156 // Should have one marker
157 // Should have one marker
157 QList<QLegendMarker *> markers = legend->markers();
158 QList<QLegendMarker *> markers = legend->markers();
158 QVERIFY(markers.count() == 1);
159 QVERIFY(markers.count() == 1);
159 QLegendMarker *m = markers.at(0);
160 QLegendMarker *m = markers.at(0);
160
161
161 QVERIFY(m->series() == series);
162 QVERIFY(m->series() == series);
162 QVERIFY(m->type() == QLegendMarker::LegendMarkerTypeArea);
163 QVERIFY(m->type() == QLegendMarker::LegendMarkerTypeArea);
163
164
164 QAreaLegendMarker *pm = qobject_cast<QAreaLegendMarker *> (m);
165 QAreaLegendMarker *pm = qobject_cast<QAreaLegendMarker *> (m);
165 QVERIFY(pm);
166 QVERIFY(pm);
166 QVERIFY(pm->series() == series);
167 QVERIFY(pm->series() == series);
167 }
168 }
168
169
169 void tst_QLegend::qxyLegendMarker()
170 void tst_QLegend::qxyLegendMarker()
170 {
171 {
171 QVERIFY(m_chart);
172 QVERIFY(m_chart);
172 QLegend *legend = m_chart->legend();
173 QLegend *legend = m_chart->legend();
173
174
174 QLineSeries *series = new QLineSeries();
175 QLineSeries *series = new QLineSeries();
175 m_chart->addSeries(series);
176 m_chart->addSeries(series);
176
177
177 // Should have one marker
178 // Should have one marker
178 QList<QLegendMarker *> markers = legend->markers();
179 QList<QLegendMarker *> markers = legend->markers();
179 QVERIFY(markers.count() == 1);
180 QVERIFY(markers.count() == 1);
180 QLegendMarker *m = markers.at(0);
181 QLegendMarker *m = markers.at(0);
181
182
182 QVERIFY(m->series() == series);
183 QVERIFY(m->series() == series);
183 QVERIFY(m->type() == QLegendMarker::LegendMarkerTypeXY);
184 QVERIFY(m->type() == QLegendMarker::LegendMarkerTypeXY);
184
185
185 QXYLegendMarker *pm = qobject_cast<QXYLegendMarker *> (m);
186 QXYLegendMarker *pm = qobject_cast<QXYLegendMarker *> (m);
186 QVERIFY(pm);
187 QVERIFY(pm);
187 QVERIFY(pm->series() == series);
188 QVERIFY(pm->series() == series);
188 }
189 }
189
190
190 void tst_QLegend::qbarLegendMarker()
191 void tst_QLegend::qbarLegendMarker()
191 {
192 {
192 QVERIFY(m_chart);
193 QVERIFY(m_chart);
193 QLegend *legend = m_chart->legend();
194 QLegend *legend = m_chart->legend();
194
195
195 QBarSeries *series = new QBarSeries();
196 QBarSeries *series = new QBarSeries();
196 QBarSet *set0 = new QBarSet(QString("set0"));
197 QBarSet *set0 = new QBarSet(QString("set0"));
197 series->append(set0);
198 series->append(set0);
198 m_chart->addSeries(series);
199 m_chart->addSeries(series);
199
200
200 // Should have one marker
201 // Should have one marker
201 QList<QLegendMarker *> markers = legend->markers();
202 QList<QLegendMarker *> markers = legend->markers();
202 QVERIFY(markers.count() == 1);
203 QVERIFY(markers.count() == 1);
203 QLegendMarker *m = markers.at(0);
204 QLegendMarker *m = markers.at(0);
204
205
205 QVERIFY(m->series() == series);
206 QVERIFY(m->series() == series);
206 QVERIFY(m->type() == QLegendMarker::LegendMarkerTypeBar);
207 QVERIFY(m->type() == QLegendMarker::LegendMarkerTypeBar);
207
208
208 QBarLegendMarker *pm = qobject_cast<QBarLegendMarker *> (m);
209 QBarLegendMarker *pm = qobject_cast<QBarLegendMarker *> (m);
209 QVERIFY(pm);
210 QVERIFY(pm);
210 QVERIFY(pm->series() == series);
211 QVERIFY(pm->series() == series);
211 QVERIFY(pm->barset() == set0);
212 QVERIFY(pm->barset() == set0);
212
213
213 // Add another barset
214 // Add another barset
214 QBarSet *set1 = new QBarSet(QString("set1"));
215 QBarSet *set1 = new QBarSet(QString("set1"));
215 series->append(set1);
216 series->append(set1);
216
217
217 markers = legend->markers();
218 markers = legend->markers();
218 QVERIFY(markers.count() == 2);
219 QVERIFY(markers.count() == 2);
219 m = markers.at(1);
220 m = markers.at(1);
220
221
221 QVERIFY(m->series() == series);
222 QVERIFY(m->series() == series);
222 QVERIFY(m->type() == QLegendMarker::LegendMarkerTypeBar);
223 QVERIFY(m->type() == QLegendMarker::LegendMarkerTypeBar);
223
224
224 pm = qobject_cast<QBarLegendMarker *> (m);
225 pm = qobject_cast<QBarLegendMarker *> (m);
225 QVERIFY(pm);
226 QVERIFY(pm);
226 QVERIFY(pm->series() == series);
227 QVERIFY(pm->series() == series);
227 QVERIFY(pm->barset() == set1);
228 QVERIFY(pm->barset() == set1);
228 }
229 }
229
230
230 void tst_QLegend::markers()
231 void tst_QLegend::markers()
231 {
232 {
232 QVERIFY(m_chart);
233 QVERIFY(m_chart);
233 QLegend *legend = m_chart->legend();
234 QLegend *legend = m_chart->legend();
234
235
235 QPieSeries *pie = new QPieSeries();
236 QPieSeries *pie = new QPieSeries();
236 pie->append(QString("slice1"), 1);
237 pie->append(QString("slice1"), 1);
237 pie->append(QString("slice2"), 2);
238 pie->append(QString("slice2"), 2);
238 pie->append(QString("slice3"), 3);
239 pie->append(QString("slice3"), 3);
239 m_chart->addSeries(pie);
240 m_chart->addSeries(pie);
240 QList<QPieSlice *> slices = pie->slices();
241 QList<QPieSlice *> slices = pie->slices();
241
242
242 QBarSeries *bar = new QBarSeries();
243 QBarSeries *bar = new QBarSeries();
243 QList<QBarSet *> sets;
244 QList<QBarSet *> sets;
244 sets.append(new QBarSet(QString("set0")));
245 sets.append(new QBarSet(QString("set0")));
245 sets.append(new QBarSet(QString("set1")));
246 sets.append(new QBarSet(QString("set1")));
246 bar->append(sets);
247 bar->append(sets);
247 m_chart->addSeries(bar);
248 m_chart->addSeries(bar);
248
249
249 QLineSeries *line = new QLineSeries();
250 QLineSeries *line = new QLineSeries();
250 line->setName(QString("line1"));
251 line->setName(QString("line1"));
251 m_chart->addSeries(line);
252 m_chart->addSeries(line);
252
253
253 QAreaSeries *area = new QAreaSeries();
254 QAreaSeries *area = new QAreaSeries();
254 QLineSeries *upper = new QLineSeries();
255 QLineSeries *upper = new QLineSeries();
255 QLineSeries *lower = new QLineSeries();
256 QLineSeries *lower = new QLineSeries();
256 upper->append(1,1);
257 upper->append(1,1);
257 lower->append(1,0);
258 lower->append(1,0);
258 area->setUpperSeries(upper);
259 area->setUpperSeries(upper);
259 area->setLowerSeries(lower);
260 area->setLowerSeries(lower);
260
261
261 m_chart->addSeries(area);
262 m_chart->addSeries(area);
262
263
263 QVERIFY(legend->markers(pie).count() == 3);
264 QVERIFY(legend->markers(pie).count() == 3);
264 QVERIFY(legend->markers(bar).count() == 2);
265 QVERIFY(legend->markers(bar).count() == 2);
265 QVERIFY(legend->markers(line).count() == 1);
266 QVERIFY(legend->markers(line).count() == 1);
266 QVERIFY(legend->markers(area).count() == 1);
267 QVERIFY(legend->markers(area).count() == 1);
267 QVERIFY(legend->markers().count() == 3+2+1+1);
268 QVERIFY(legend->markers().count() == 3+2+1+1);
268 }
269 }
269
270
270 void tst_QLegend::addAndRemoveSeries()
271 void tst_QLegend::addAndRemoveSeries()
271 {
272 {
272 QVERIFY(m_chart);
273 QVERIFY(m_chart);
273 QLegend *legend = m_chart->legend();
274 QLegend *legend = m_chart->legend();
274
275
275 QPieSeries *pie = new QPieSeries();
276 QPieSeries *pie = new QPieSeries();
276 pie->append(QString("slice1"), 1);
277 pie->append(QString("slice1"), 1);
277 pie->append(QString("slice2"), 2);
278 pie->append(QString("slice2"), 2);
278 pie->append(QString("slice3"), 3);
279 pie->append(QString("slice3"), 3);
279
280
280 m_chart->addSeries(pie);
281 m_chart->addSeries(pie);
281
282
282 QList<QLegendMarker *> markers = legend->markers();
283 QList<QLegendMarker *> markers = legend->markers();
283 QVERIFY(markers.count() == 3);
284 QVERIFY(markers.count() == 3);
284
285
285 m_chart->removeSeries(pie);
286 m_chart->removeSeries(pie);
286
287
287 markers = legend->markers();
288 markers = legend->markers();
288 QVERIFY(markers.count() == 0);
289 QVERIFY(markers.count() == 0);
289 }
290 }
290
291
291 void tst_QLegend::pieMarkerProperties()
292 void tst_QLegend::pieMarkerProperties()
292 {
293 {
293 QVERIFY(m_chart);
294 QVERIFY(m_chart);
294 QLegend *legend = m_chart->legend();
295 QLegend *legend = m_chart->legend();
295
296
296 QPieSeries *pie = new QPieSeries();
297 QPieSeries *pie = new QPieSeries();
297 QPieSlice *slice = pie->append(QString("Slice1"), 1);
298 QPieSlice *slice = pie->append(QString("Slice1"), 1);
298 m_chart->addSeries(pie);
299 m_chart->addSeries(pie);
299
300
300 QLegendMarker *m = legend->markers(pie).at(0);
301 QLegendMarker *m = legend->markers(pie).at(0);
301 QPieLegendMarker *pm = qobject_cast<QPieLegendMarker *> (m);
302 QPieLegendMarker *pm = qobject_cast<QPieLegendMarker *> (m);
302 QVERIFY(pm);
303 QVERIFY(pm);
303
304
304 QBrush b1(QColor(12,34,56,78));
305 QBrush b1(QColor(12,34,56,78));
305 QBrush b2(QColor(34,56,78,90));
306 QBrush b2(QColor(34,56,78,90));
306
307
307 // Change brush
308 // Change brush
308 slice->setBrush(b1);
309 slice->setBrush(b1);
309 QVERIFY(pm->brush() == b1);
310 QVERIFY(pm->brush() == b1);
310 slice->setBrush(b2);
311 slice->setBrush(b2);
311 QVERIFY(pm->brush() == b2);
312 QVERIFY(pm->brush() == b2);
312
313
313 // Change label
314 // Change label
314 QVERIFY(pm->label().compare(QString("Slice1")) == 0);
315 QVERIFY(pm->label().compare(QString("Slice1")) == 0);
315 slice->setLabel(QString("foo"));
316 slice->setLabel(QString("foo"));
316 QVERIFY(pm->label().compare(QString("foo")) == 0);
317 QVERIFY(pm->label().compare(QString("foo")) == 0);
317 slice->setLabel(QString("bar"));
318 slice->setLabel(QString("bar"));
318 QVERIFY(pm->label().compare(QString("bar")) == 0);
319 QVERIFY(pm->label().compare(QString("bar")) == 0);
319
320
320 // Change visibility
321 // Change visibility
321 pie->setVisible(false);
322 pie->setVisible(false);
322 TRY_COMPARE(pm->isVisible(), false);
323 TRY_COMPARE(pm->isVisible(), false);
323 pie->setVisible(true);
324 pie->setVisible(true);
324 TRY_COMPARE(pm->isVisible(), true);
325 TRY_COMPARE(pm->isVisible(), true);
325 }
326 }
326
327
327 void tst_QLegend::barMarkerProperties()
328 void tst_QLegend::barMarkerProperties()
328 {
329 {
329 QVERIFY(m_chart);
330 QVERIFY(m_chart);
330 QLegend *legend = m_chart->legend();
331 QLegend *legend = m_chart->legend();
331
332
332 QBarSeries *bar = new QBarSeries();
333 QBarSeries *bar = new QBarSeries();
333 QBarSet *barSet = new QBarSet(QString("Set0"));
334 QBarSet *barSet = new QBarSet(QString("Set0"));
334 *barSet << 1;
335 *barSet << 1;
335 bar->append(barSet);
336 bar->append(barSet);
336 m_chart->addSeries(bar);
337 m_chart->addSeries(bar);
337
338
338 QLegendMarker *m = legend->markers(bar).at(0);
339 QLegendMarker *m = legend->markers(bar).at(0);
339 QBarLegendMarker *pm = qobject_cast<QBarLegendMarker *> (m);
340 QBarLegendMarker *pm = qobject_cast<QBarLegendMarker *> (m);
340 QVERIFY(pm);
341 QVERIFY(pm);
341
342
342 QBrush b1(QColor(12,34,56,78));
343 QBrush b1(QColor(12,34,56,78));
343 QBrush b2(QColor(34,56,78,90));
344 QBrush b2(QColor(34,56,78,90));
344
345
345 // Change brush
346 // Change brush
346 barSet->setBrush(b1);
347 barSet->setBrush(b1);
347 QVERIFY(pm->brush() == b1);
348 QVERIFY(pm->brush() == b1);
348 barSet->setBrush(b2);
349 barSet->setBrush(b2);
349 QVERIFY(pm->brush() == b2);
350 QVERIFY(pm->brush() == b2);
350
351
351 // Change label
352 // Change label
352 QVERIFY(pm->label().compare(QString("Set0")) == 0);
353 QVERIFY(pm->label().compare(QString("Set0")) == 0);
353 barSet->setLabel(QString("foo"));
354 barSet->setLabel(QString("foo"));
354 QVERIFY(pm->label().compare(QString("foo")) == 0);
355 QVERIFY(pm->label().compare(QString("foo")) == 0);
355 barSet->setLabel(QString("bar"));
356 barSet->setLabel(QString("bar"));
356 QVERIFY(pm->label().compare(QString("bar")) == 0);
357 QVERIFY(pm->label().compare(QString("bar")) == 0);
357
358
358 // Change visibility
359 // Change visibility
359 bar->setVisible(false);
360 bar->setVisible(false);
360 TRY_COMPARE(pm->isVisible(), false);
361 TRY_COMPARE(pm->isVisible(), false);
361 bar->setVisible(true);
362 bar->setVisible(true);
362 TRY_COMPARE(pm->isVisible(), true);
363 TRY_COMPARE(pm->isVisible(), true);
363 }
364 }
364
365
365 void tst_QLegend::areaMarkerProperties()
366 void tst_QLegend::areaMarkerProperties()
366 {
367 {
367 QVERIFY(m_chart);
368 QVERIFY(m_chart);
368 QLegend *legend = m_chart->legend();
369 QLegend *legend = m_chart->legend();
369
370
370 QAreaSeries *area = new QAreaSeries();
371 QAreaSeries *area = new QAreaSeries();
371 area->setName(QString("Area"));
372 area->setName(QString("Area"));
372 QLineSeries *upper = new QLineSeries();
373 QLineSeries *upper = new QLineSeries();
373 QLineSeries *lower = new QLineSeries();
374 QLineSeries *lower = new QLineSeries();
374 upper->append(1,1);
375 upper->append(1,1);
375 lower->append(1,0);
376 lower->append(1,0);
376 area->setUpperSeries(upper);
377 area->setUpperSeries(upper);
377 area->setLowerSeries(lower);
378 area->setLowerSeries(lower);
378 m_chart->addSeries(area);
379 m_chart->addSeries(area);
379
380
380 QLegendMarker *m = legend->markers(area).at(0);
381 QLegendMarker *m = legend->markers(area).at(0);
381 QAreaLegendMarker *pm = qobject_cast<QAreaLegendMarker *> (m);
382 QAreaLegendMarker *pm = qobject_cast<QAreaLegendMarker *> (m);
382 QVERIFY(pm);
383 QVERIFY(pm);
383
384
384 QBrush b1(QColor(12,34,56,78));
385 QBrush b1(QColor(12,34,56,78));
385 QBrush b2(QColor(34,56,78,90));
386 QBrush b2(QColor(34,56,78,90));
386
387
387 // Change brush
388 // Change brush
388 area->setBrush(b1);
389 area->setBrush(b1);
389 QVERIFY(pm->brush() == b1);
390 QVERIFY(pm->brush() == b1);
390 area->setBrush(b2);
391 area->setBrush(b2);
391 QVERIFY(pm->brush() == b2);
392 QVERIFY(pm->brush() == b2);
392
393
393 // Change name
394 // Change name
394 QVERIFY(pm->label().compare(QString("Area")) == 0);
395 QVERIFY(pm->label().compare(QString("Area")) == 0);
395 area->setName(QString("foo"));
396 area->setName(QString("foo"));
396 QVERIFY(pm->label().compare(QString("foo")) == 0);
397 QVERIFY(pm->label().compare(QString("foo")) == 0);
397 area->setName(QString("bar"));
398 area->setName(QString("bar"));
398 QVERIFY(pm->label().compare(QString("bar")) == 0);
399 QVERIFY(pm->label().compare(QString("bar")) == 0);
399
400
400 // Change visibility
401 // Change visibility
401 area->setVisible(false);
402 area->setVisible(false);
402 TRY_COMPARE(pm->isVisible(), false);
403 TRY_COMPARE(pm->isVisible(), false);
403 area->setVisible(true);
404 area->setVisible(true);
404 TRY_COMPARE(pm->isVisible(), true);
405 TRY_COMPARE(pm->isVisible(), true);
405 }
406 }
406
407
407 void tst_QLegend::xyMarkerPropertiesLine()
408 void tst_QLegend::xyMarkerPropertiesLine()
408 {
409 {
409 QVERIFY(m_chart);
410 QVERIFY(m_chart);
410 QLegend *legend = m_chart->legend();
411 QLegend *legend = m_chart->legend();
411
412
412 QLineSeries *line = new QLineSeries();
413 QLineSeries *line = new QLineSeries();
413 line->setName(QString("Line"));
414 line->setName(QString("Line"));
414 line->append(1,1);
415 line->append(1,1);
415 m_chart->addSeries(line);
416 m_chart->addSeries(line);
416
417
417 QLegendMarker *m = legend->markers(line).at(0);
418 QLegendMarker *m = legend->markers(line).at(0);
418 QXYLegendMarker *pm = qobject_cast<QXYLegendMarker *> (m);
419 QXYLegendMarker *pm = qobject_cast<QXYLegendMarker *> (m);
419 QVERIFY(pm);
420 QVERIFY(pm);
420
421
421 // With line series, the marker is colored after pen, not brush
422 // With line series, the marker is colored after pen, not brush
422 QPen b1(QColor(12,34,56,78));
423 QPen b1(QColor(12,34,56,78));
423 QPen b2(QColor(34,56,78,90));
424 QPen b2(QColor(34,56,78,90));
424
425
425 // Change brush
426 // Change brush
426 line->setPen(b1);
427 line->setPen(b1);
427 QVERIFY(pm->brush().color() == b1.color());
428 QVERIFY(pm->brush().color() == b1.color());
428 line->setPen(b2);
429 line->setPen(b2);
429 QVERIFY(pm->brush().color() == b2.color());
430 QVERIFY(pm->brush().color() == b2.color());
430
431
431 // Change name
432 // Change name
432 QVERIFY(pm->label().compare(QString("Line")) == 0);
433 QVERIFY(pm->label().compare(QString("Line")) == 0);
433 line->setName(QString("foo"));
434 line->setName(QString("foo"));
434 QVERIFY(pm->label().compare(QString("foo")) == 0);
435 QVERIFY(pm->label().compare(QString("foo")) == 0);
435 line->setName(QString("bar"));
436 line->setName(QString("bar"));
436 QVERIFY(pm->label().compare(QString("bar")) == 0);
437 QVERIFY(pm->label().compare(QString("bar")) == 0);
437
438
438 // Change visibility
439 // Change visibility
439 line->setVisible(false);
440 line->setVisible(false);
440 TRY_COMPARE(pm->isVisible(), false);
441 TRY_COMPARE(pm->isVisible(), false);
441 line->setVisible(true);
442 line->setVisible(true);
442 TRY_COMPARE(pm->isVisible(), true);
443 TRY_COMPARE(pm->isVisible(), true);
443 }
444 }
444
445
445 void tst_QLegend::xyMarkerPropertiesScatter()
446 void tst_QLegend::xyMarkerPropertiesScatter()
446 {
447 {
447 QVERIFY(m_chart);
448 QVERIFY(m_chart);
448 QLegend *legend = m_chart->legend();
449 QLegend *legend = m_chart->legend();
449
450
450 QScatterSeries *scatter = new QScatterSeries();
451 QScatterSeries *scatter = new QScatterSeries();
451 scatter->setName(QString("Scatter"));
452 scatter->setName(QString("Scatter"));
452 scatter->append(1,1);
453 scatter->append(1,1);
453 m_chart->addSeries(scatter);
454 m_chart->addSeries(scatter);
454
455
455 QLegendMarker *m = legend->markers(scatter).at(0);
456 QLegendMarker *m = legend->markers(scatter).at(0);
456 QXYLegendMarker *pm = qobject_cast<QXYLegendMarker *> (m);
457 QXYLegendMarker *pm = qobject_cast<QXYLegendMarker *> (m);
457 QVERIFY(pm);
458 QVERIFY(pm);
458
459
459 QBrush b1(QColor(12,34,56,78));
460 QBrush b1(QColor(12,34,56,78));
460 QBrush b2(QColor(34,56,78,90));
461 QBrush b2(QColor(34,56,78,90));
461
462
462 // Change brush
463 // Change brush
463 scatter->setBrush(b1);
464 scatter->setBrush(b1);
464 QVERIFY(pm->brush() == b1);
465 QVERIFY(pm->brush() == b1);
465 scatter->setBrush(b2);
466 scatter->setBrush(b2);
466 QVERIFY(pm->brush() == b2);
467 QVERIFY(pm->brush() == b2);
467
468
468 // Change name
469 // Change name
469 QVERIFY(pm->label().compare(QString("Scatter")) == 0);
470 QVERIFY(pm->label().compare(QString("Scatter")) == 0);
470 scatter->setName(QString("foo"));
471 scatter->setName(QString("foo"));
471 QVERIFY(pm->label().compare(QString("foo")) == 0);
472 QVERIFY(pm->label().compare(QString("foo")) == 0);
472 scatter->setName(QString("bar"));
473 scatter->setName(QString("bar"));
473 QVERIFY(pm->label().compare(QString("bar")) == 0);
474 QVERIFY(pm->label().compare(QString("bar")) == 0);
474
475
475 // Change visibility
476 // Change visibility
476 scatter->setVisible(false);
477 scatter->setVisible(false);
477 TRY_COMPARE(pm->isVisible(), false);
478 TRY_COMPARE(pm->isVisible(), false);
478 scatter->setVisible(true);
479 scatter->setVisible(true);
479 TRY_COMPARE(pm->isVisible(), true);
480 TRY_COMPARE(pm->isVisible(), true);
480 }
481 }
481
482
483 void tst_QLegend::markerSignals()
484 {
485 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
486 QChart *chart = new QChart();
487 QLegend *legend = chart->legend();
488
489 QBarSeries *bar = new QBarSeries();
490 QBarSet *set1 = new QBarSet(QString("set 1"));
491 *set1 << 10 << 10 << 10;
492 bar->append(set1);
493 QBarSet *set2 = new QBarSet(QString("set 2"));
494 *set2 << 10 << 10 << 10;
495 bar->append(set2);
496 chart->addSeries(bar);
497
498 QPieSeries *pie = new QPieSeries();
499 pie->append(QString("slice1"), 1);
500 pie->append(QString("slice2"), 2);
501 pie->append(QString("slice3"), 3);
502 chart->addSeries(pie);
503 legend->setAlignment(Qt::AlignRight);
504
505 QLineSeries *line = new QLineSeries();
506 line->setName(QString("Line 1"));
507 line->append(1,1);
508 chart->addSeries(line);
509
510 QAreaSeries *area = new QAreaSeries();
511 area->setName(QString("Area 1"));
512 QLineSeries *upper = new QLineSeries();
513 QLineSeries *lower = new QLineSeries();
514 upper->append(2,2);
515 lower->append(1,1);
516 area->setUpperSeries(upper);
517 area->setLowerSeries(lower);
518 chart->addSeries(area);
519
520 QScatterSeries *scatter = new QScatterSeries();
521 scatter->setName(QString("Scatter"));
522 scatter->append(3,3);
523 chart->addSeries(scatter);
524
525 QList<QSignalSpy *> spies;
526 foreach(QLegendMarker *m, legend->markers()) {
527 QSignalSpy *spy = new QSignalSpy(m, SIGNAL(hovered(bool)));
528 spies.append(spy);
529 }
530
531 QChartView view(chart);
532 view.resize(400,300);
533 view.show();
534 QTest::qWaitForWindowShown(&view);
535
536 // Sweep mouse over all legend items
537 for ( int i = 0; i < 300; i++ ) {
538 QTest::mouseMove(view.viewport(), QPoint(333,i));
539 }
540
541 foreach(QSignalSpy *spy, spies) {
542 TRY_COMPARE(spy->count(), 2);
543 }
544
545 qDeleteAll(spies);
546 }
547
482 QTEST_MAIN(tst_QLegend)
548 QTEST_MAIN(tst_QLegend)
483
549
484 #include "tst_qlegend.moc"
550 #include "tst_qlegend.moc"
485
551
General Comments 0
You need to be logged in to leave comments. Login now