0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
|
|
43 |
#include <QtTest/QtTest>
|
|
44 |
|
|
45 |
|
|
46 |
#include "qbuttongroup.h"
|
|
47 |
#include <qaction.h>
|
|
48 |
#include <qapplication.h>
|
|
49 |
#include <qdialog.h>
|
|
50 |
#include <qlayout.h>
|
|
51 |
#include <qgroupbox.h>
|
|
52 |
#include <qradiobutton.h>
|
|
53 |
#include <qpushbutton.h>
|
|
54 |
#include <qlineedit.h>
|
|
55 |
#include <qtoolbutton.h>
|
|
56 |
#ifdef Q_WS_MAC
|
|
57 |
#include <qsettings.h>
|
|
58 |
#endif
|
|
59 |
|
|
60 |
#include "../../shared/util.h"
|
|
61 |
|
|
62 |
class SpecialRadioButton: public QRadioButton
|
|
63 |
{
|
|
64 |
public:
|
|
65 |
SpecialRadioButton(QWidget *parent) : QRadioButton(parent)
|
|
66 |
{ }
|
|
67 |
|
|
68 |
protected:
|
|
69 |
void focusInEvent(QFocusEvent *)
|
|
70 |
{
|
|
71 |
QCoreApplication::postEvent(this, new QKeyEvent(QEvent::KeyPress,
|
|
72 |
Qt::Key_Down, Qt::NoModifier));
|
|
73 |
}
|
|
74 |
};
|
|
75 |
|
|
76 |
#include <qbuttongroup.h>
|
|
77 |
|
|
78 |
//TESTED_CLASS=
|
|
79 |
//TESTED_FILES=
|
|
80 |
|
|
81 |
class tst_QButtonGroup : public QObject
|
|
82 |
{
|
|
83 |
Q_OBJECT
|
|
84 |
public:
|
|
85 |
tst_QButtonGroup();
|
|
86 |
|
|
87 |
public slots:
|
|
88 |
void initTestCase();
|
|
89 |
void cleanupTestCase();
|
|
90 |
void init();
|
|
91 |
void cleanup();
|
|
92 |
private slots:
|
|
93 |
void arrowKeyNavigation();
|
|
94 |
void exclusive();
|
|
95 |
void exclusiveWithActions();
|
|
96 |
void testSignals();
|
|
97 |
void checkedButton();
|
|
98 |
|
|
99 |
void task106609();
|
|
100 |
|
|
101 |
// fixed for Qt 4.6.0
|
|
102 |
#if QT_VERSION >= 0x040600
|
|
103 |
void autoIncrementId();
|
|
104 |
#endif
|
|
105 |
|
|
106 |
void task209485_removeFromGroupInEventHandler_data();
|
|
107 |
void task209485_removeFromGroupInEventHandler();
|
|
108 |
};
|
|
109 |
|
|
110 |
tst_QButtonGroup::tst_QButtonGroup()
|
|
111 |
{
|
|
112 |
}
|
|
113 |
|
|
114 |
|
|
115 |
void tst_QButtonGroup::initTestCase()
|
|
116 |
{
|
|
117 |
}
|
|
118 |
|
|
119 |
void tst_QButtonGroup::cleanupTestCase()
|
|
120 |
{
|
|
121 |
}
|
|
122 |
|
|
123 |
void tst_QButtonGroup::init()
|
|
124 |
{
|
|
125 |
}
|
|
126 |
|
|
127 |
void tst_QButtonGroup::cleanup()
|
|
128 |
{
|
|
129 |
}
|
|
130 |
|
|
131 |
QT_BEGIN_NAMESPACE
|
|
132 |
extern bool Q_GUI_EXPORT qt_tab_all_widgets;
|
|
133 |
QT_END_NAMESPACE
|
|
134 |
|
|
135 |
|
|
136 |
void tst_QButtonGroup::arrowKeyNavigation()
|
|
137 |
{
|
|
138 |
if (!qt_tab_all_widgets)
|
|
139 |
QSKIP("This test requires full keyboard control to be enabled.", SkipAll);
|
|
140 |
|
|
141 |
QDialog dlg(0);
|
|
142 |
QHBoxLayout layout(&dlg);
|
|
143 |
QGroupBox g1("1", &dlg);
|
|
144 |
QHBoxLayout g1layout(&g1);
|
|
145 |
QRadioButton bt1("Radio1", &g1);
|
|
146 |
QPushButton pb("PB", &g1);
|
|
147 |
QLineEdit le(&g1);
|
|
148 |
QRadioButton bt2("Radio2", &g1);
|
|
149 |
g1layout.addWidget(&bt1);
|
|
150 |
g1layout.addWidget(&pb);
|
|
151 |
g1layout.addWidget(&le);
|
|
152 |
g1layout.addWidget(&bt2);
|
|
153 |
|
|
154 |
// create a mixed button group with radion buttons and push
|
|
155 |
// buttons. Not very useful, but it tests borderline cases wrt
|
|
156 |
// focus handling.
|
|
157 |
QButtonGroup bgrp1(&g1);
|
|
158 |
bgrp1.addButton(&bt1);
|
|
159 |
bgrp1.addButton(&pb);
|
|
160 |
bgrp1.addButton(&bt2);
|
|
161 |
|
|
162 |
QGroupBox g2("2", &dlg);
|
|
163 |
QVBoxLayout g2layout(&g2);
|
|
164 |
// we don't need a button group here, because radio buttons are
|
|
165 |
// auto exclusive, i.e. they group themselves in he same parent
|
|
166 |
// widget.
|
|
167 |
QRadioButton bt3("Radio3", &g2);
|
|
168 |
QRadioButton bt4("Radio4", &g2);
|
|
169 |
g2layout.addWidget(&bt3);
|
|
170 |
g2layout.addWidget(&bt4);
|
|
171 |
|
|
172 |
layout.addWidget(&g1);
|
|
173 |
layout.addWidget(&g2);
|
|
174 |
|
|
175 |
dlg.show();
|
|
176 |
qApp->setActiveWindow(&dlg);
|
|
177 |
QTest::qWaitForWindowShown(&dlg);
|
|
178 |
|
|
179 |
bt1.setFocus();
|
|
180 |
|
|
181 |
QTRY_VERIFY(bt1.hasFocus());
|
|
182 |
|
|
183 |
QTest::keyClick(&bt1, Qt::Key_Right);
|
|
184 |
QVERIFY(pb.hasFocus());
|
|
185 |
QTest::keyClick(&pb, Qt::Key_Right);
|
|
186 |
QVERIFY(bt2.hasFocus());
|
|
187 |
QTest::keyClick(&bt2, Qt::Key_Right);
|
|
188 |
QVERIFY(bt2.hasFocus());
|
|
189 |
QTest::keyClick(&bt2, Qt::Key_Left);
|
|
190 |
QVERIFY(pb.hasFocus());
|
|
191 |
QTest::keyClick(&pb, Qt::Key_Left);
|
|
192 |
QVERIFY(bt1.hasFocus());
|
|
193 |
|
|
194 |
QTest::keyClick(&bt1, Qt::Key_Tab);
|
|
195 |
QVERIFY(pb.hasFocus());
|
|
196 |
QTest::keyClick(&pb, Qt::Key_Tab);
|
|
197 |
|
|
198 |
QVERIFY(le.hasFocus());
|
|
199 |
QCOMPARE(le.selectedText(), le.text());
|
|
200 |
QTest::keyClick(&le, Qt::Key_Tab);
|
|
201 |
|
|
202 |
QVERIFY(bt2.hasFocus());
|
|
203 |
QTest::keyClick(&bt2, Qt::Key_Tab);
|
|
204 |
QVERIFY(bt3.hasFocus());
|
|
205 |
|
|
206 |
QTest::keyClick(&bt3, Qt::Key_Down);
|
|
207 |
QVERIFY(bt4.hasFocus());
|
|
208 |
QTest::keyClick(&bt4, Qt::Key_Down);
|
|
209 |
QVERIFY(bt4.hasFocus());
|
|
210 |
|
|
211 |
QTest::keyClick(&bt4, Qt::Key_Up);
|
|
212 |
QVERIFY(bt3.hasFocus());
|
|
213 |
QTest::keyClick(&bt3, Qt::Key_Up);
|
|
214 |
QVERIFY(bt3.hasFocus());
|
|
215 |
}
|
|
216 |
|
|
217 |
void tst_QButtonGroup::exclusiveWithActions()
|
|
218 |
{
|
|
219 |
QDialog dlg(0);
|
|
220 |
QHBoxLayout layout(&dlg);
|
|
221 |
QAction *action1 = new QAction("Action 1", &dlg);
|
|
222 |
action1->setCheckable(true);
|
|
223 |
QAction *action2 = new QAction("Action 2", &dlg);
|
|
224 |
action2->setCheckable(true);
|
|
225 |
QAction *action3 = new QAction("Action 3", &dlg);
|
|
226 |
action3->setCheckable(true);
|
|
227 |
QToolButton *toolButton1 = new QToolButton(&dlg);
|
|
228 |
QToolButton *toolButton2 = new QToolButton(&dlg);
|
|
229 |
QToolButton *toolButton3 = new QToolButton(&dlg);
|
|
230 |
toolButton1->setDefaultAction(action1);
|
|
231 |
toolButton2->setDefaultAction(action2);
|
|
232 |
toolButton3->setDefaultAction(action3);
|
|
233 |
layout.addWidget(toolButton1);
|
|
234 |
layout.addWidget(toolButton2);
|
|
235 |
layout.addWidget(toolButton3);
|
|
236 |
QButtonGroup *buttonGroup = new QButtonGroup( &dlg );
|
|
237 |
buttonGroup->setExclusive(true);
|
|
238 |
buttonGroup->addButton(toolButton1, 1);
|
|
239 |
buttonGroup->addButton(toolButton2, 2);
|
|
240 |
buttonGroup->addButton(toolButton3, 3);
|
|
241 |
dlg.show();
|
|
242 |
|
|
243 |
QTest::mouseClick(toolButton1, Qt::LeftButton);
|
|
244 |
QVERIFY(toolButton1->isChecked());
|
|
245 |
QVERIFY(action1->isChecked());
|
|
246 |
QVERIFY(!toolButton2->isChecked());
|
|
247 |
QVERIFY(!toolButton3->isChecked());
|
|
248 |
QVERIFY(!action2->isChecked());
|
|
249 |
QVERIFY(!action3->isChecked());
|
|
250 |
|
|
251 |
QTest::mouseClick(toolButton2, Qt::LeftButton);
|
|
252 |
QVERIFY(toolButton2->isChecked());
|
|
253 |
QVERIFY(action2->isChecked());
|
|
254 |
QVERIFY(!toolButton1->isChecked());
|
|
255 |
QVERIFY(!toolButton3->isChecked());
|
|
256 |
QVERIFY(!action1->isChecked());
|
|
257 |
QVERIFY(!action3->isChecked());
|
|
258 |
|
|
259 |
QTest::mouseClick(toolButton3, Qt::LeftButton);
|
|
260 |
QVERIFY(toolButton3->isChecked());
|
|
261 |
QVERIFY(action3->isChecked());
|
|
262 |
QVERIFY(!toolButton1->isChecked());
|
|
263 |
QVERIFY(!toolButton2->isChecked());
|
|
264 |
QVERIFY(!action1->isChecked());
|
|
265 |
QVERIFY(!action2->isChecked());
|
|
266 |
|
|
267 |
QTest::mouseClick(toolButton2, Qt::LeftButton);
|
|
268 |
QVERIFY(toolButton2->isChecked());
|
|
269 |
QVERIFY(action2->isChecked());
|
|
270 |
QVERIFY(!toolButton1->isChecked());
|
|
271 |
QVERIFY(!toolButton3->isChecked());
|
|
272 |
QVERIFY(!action1->isChecked());
|
|
273 |
QVERIFY(!action3->isChecked());
|
|
274 |
}
|
|
275 |
|
|
276 |
void tst_QButtonGroup::exclusive()
|
|
277 |
{
|
|
278 |
QDialog dlg(0);
|
|
279 |
QHBoxLayout layout(&dlg);
|
|
280 |
QPushButton *pushButton1 = new QPushButton(&dlg);
|
|
281 |
QPushButton *pushButton2 = new QPushButton(&dlg);
|
|
282 |
QPushButton *pushButton3 = new QPushButton(&dlg);
|
|
283 |
pushButton1->setCheckable(true);
|
|
284 |
pushButton2->setCheckable(true);
|
|
285 |
pushButton3->setCheckable(true);
|
|
286 |
layout.addWidget(pushButton1);
|
|
287 |
layout.addWidget(pushButton2);
|
|
288 |
layout.addWidget(pushButton3);
|
|
289 |
QButtonGroup *buttonGroup = new QButtonGroup( &dlg );
|
|
290 |
buttonGroup->setExclusive(true);
|
|
291 |
buttonGroup->addButton(pushButton1, 1);
|
|
292 |
buttonGroup->addButton(pushButton2, 2);
|
|
293 |
buttonGroup->addButton(pushButton3, 3);
|
|
294 |
dlg.show();
|
|
295 |
|
|
296 |
QTest::mouseClick(pushButton1, Qt::LeftButton);
|
|
297 |
QVERIFY(pushButton1->isChecked());
|
|
298 |
QVERIFY(!pushButton2->isChecked());
|
|
299 |
QVERIFY(!pushButton3->isChecked());
|
|
300 |
|
|
301 |
QTest::mouseClick(pushButton2, Qt::LeftButton);
|
|
302 |
QVERIFY(pushButton2->isChecked());
|
|
303 |
QVERIFY(!pushButton1->isChecked());
|
|
304 |
QVERIFY(!pushButton3->isChecked());
|
|
305 |
|
|
306 |
QTest::mouseClick(pushButton3, Qt::LeftButton);
|
|
307 |
QVERIFY(pushButton3->isChecked());
|
|
308 |
QVERIFY(!pushButton1->isChecked());
|
|
309 |
QVERIFY(!pushButton2->isChecked());
|
|
310 |
|
|
311 |
QTest::mouseClick(pushButton2, Qt::LeftButton);
|
|
312 |
QVERIFY(pushButton2->isChecked());
|
|
313 |
QVERIFY(!pushButton1->isChecked());
|
|
314 |
QVERIFY(!pushButton3->isChecked());
|
|
315 |
}
|
|
316 |
|
|
317 |
void tst_QButtonGroup::testSignals()
|
|
318 |
{
|
|
319 |
QButtonGroup buttons;
|
|
320 |
QPushButton pb1;
|
|
321 |
QPushButton pb2;
|
|
322 |
QPushButton pb3;
|
|
323 |
buttons.addButton(&pb1);
|
|
324 |
buttons.addButton(&pb2, 23);
|
|
325 |
buttons.addButton(&pb3);
|
|
326 |
|
|
327 |
qRegisterMetaType<QAbstractButton *>("QAbstractButton *");
|
|
328 |
QSignalSpy clickedSpy(&buttons, SIGNAL(buttonClicked(QAbstractButton *)));
|
|
329 |
QSignalSpy clickedIdSpy(&buttons, SIGNAL(buttonClicked(int)));
|
|
330 |
QSignalSpy pressedSpy(&buttons, SIGNAL(buttonPressed(QAbstractButton *)));
|
|
331 |
QSignalSpy pressedIdSpy(&buttons, SIGNAL(buttonPressed(int)));
|
|
332 |
QSignalSpy releasedSpy(&buttons, SIGNAL(buttonReleased(QAbstractButton *)));
|
|
333 |
QSignalSpy releasedIdSpy(&buttons, SIGNAL(buttonReleased(int)));
|
|
334 |
|
|
335 |
pb1.animateClick();
|
|
336 |
QTestEventLoop::instance().enterLoop(1);
|
|
337 |
|
|
338 |
QCOMPARE(clickedSpy.count(), 1);
|
|
339 |
QCOMPARE(clickedIdSpy.count(), 1);
|
|
340 |
|
|
341 |
int expectedId = -1;
|
|
342 |
#if QT_VERSION >= 0x040600
|
|
343 |
expectedId = -2;
|
|
344 |
#endif
|
|
345 |
|
|
346 |
QVERIFY(clickedIdSpy.takeFirst().at(0).toInt() == expectedId);
|
|
347 |
QCOMPARE(pressedSpy.count(), 1);
|
|
348 |
QCOMPARE(pressedIdSpy.count(), 1);
|
|
349 |
QVERIFY(pressedIdSpy.takeFirst().at(0).toInt() == expectedId);
|
|
350 |
QCOMPARE(releasedSpy.count(), 1);
|
|
351 |
QCOMPARE(releasedIdSpy.count(), 1);
|
|
352 |
QVERIFY(releasedIdSpy.takeFirst().at(0).toInt() == expectedId);
|
|
353 |
|
|
354 |
clickedSpy.clear();
|
|
355 |
clickedIdSpy.clear();
|
|
356 |
pressedSpy.clear();
|
|
357 |
pressedIdSpy.clear();
|
|
358 |
releasedSpy.clear();
|
|
359 |
releasedIdSpy.clear();
|
|
360 |
|
|
361 |
pb2.animateClick();
|
|
362 |
QTestEventLoop::instance().enterLoop(1);
|
|
363 |
|
|
364 |
QCOMPARE(clickedSpy.count(), 1);
|
|
365 |
QCOMPARE(clickedIdSpy.count(), 1);
|
|
366 |
QVERIFY(clickedIdSpy.takeFirst().at(0).toInt() == 23);
|
|
367 |
QCOMPARE(pressedSpy.count(), 1);
|
|
368 |
QCOMPARE(pressedIdSpy.count(), 1);
|
|
369 |
QVERIFY(pressedIdSpy.takeFirst().at(0).toInt() == 23);
|
|
370 |
QCOMPARE(releasedSpy.count(), 1);
|
|
371 |
QCOMPARE(releasedIdSpy.count(), 1);
|
|
372 |
QVERIFY(releasedIdSpy.takeFirst().at(0).toInt() == 23);
|
|
373 |
}
|
|
374 |
|
|
375 |
void tst_QButtonGroup::task106609()
|
|
376 |
{
|
|
377 |
// task is:
|
|
378 |
// sometimes, only one of the two signals in QButtonGroup get emitted
|
|
379 |
// they get emitted when using the mouse, but when using the keyboard, only one is
|
|
380 |
//
|
|
381 |
|
|
382 |
QDialog dlg(0);
|
|
383 |
QButtonGroup *buttons = new QButtonGroup(&dlg);
|
|
384 |
QVBoxLayout *vbox = new QVBoxLayout(&dlg);
|
|
385 |
|
|
386 |
SpecialRadioButton *radio1 = new SpecialRadioButton(&dlg);
|
|
387 |
radio1->setText("radio1");
|
|
388 |
SpecialRadioButton *radio2 = new SpecialRadioButton(&dlg);
|
|
389 |
radio2->setText("radio2");
|
|
390 |
QRadioButton *radio3 = new QRadioButton(&dlg);
|
|
391 |
radio3->setText("radio3");
|
|
392 |
|
|
393 |
buttons->addButton(radio1, 1);
|
|
394 |
vbox->addWidget(radio1);
|
|
395 |
buttons->addButton(radio2, 2);
|
|
396 |
vbox->addWidget(radio2);
|
|
397 |
buttons->addButton(radio3, 3);
|
|
398 |
vbox->addWidget(radio3);
|
|
399 |
|
|
400 |
radio1->setFocus();
|
|
401 |
radio1->setChecked(true);
|
|
402 |
dlg.show();
|
|
403 |
|
|
404 |
qRegisterMetaType<QAbstractButton*>("QAbstractButton*");
|
|
405 |
QSignalSpy spy1(buttons, SIGNAL(buttonClicked(QAbstractButton*)));
|
|
406 |
QSignalSpy spy2(buttons, SIGNAL(buttonClicked(int)));
|
|
407 |
|
|
408 |
QTestEventLoop::instance().enterLoop(1);
|
|
409 |
QApplication::setActiveWindow(&dlg);
|
|
410 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget*>(&dlg));
|
|
411 |
|
|
412 |
//qDebug() << "int:" << spy2.count() << "QAbstractButton*:" << spy1.count();
|
|
413 |
QCOMPARE(spy2.count(), 2);
|
|
414 |
QCOMPARE(spy1.count(), 2);
|
|
415 |
}
|
|
416 |
|
|
417 |
void tst_QButtonGroup::checkedButton()
|
|
418 |
{
|
|
419 |
QButtonGroup buttons;
|
|
420 |
buttons.setExclusive(false);
|
|
421 |
QPushButton pb1;
|
|
422 |
pb1.setCheckable(true);
|
|
423 |
QPushButton pb2;
|
|
424 |
pb2.setCheckable(true);
|
|
425 |
buttons.addButton(&pb1);
|
|
426 |
buttons.addButton(&pb2, 23);
|
|
427 |
|
|
428 |
QVERIFY(buttons.checkedButton() == 0);
|
|
429 |
pb1.setChecked(true);
|
|
430 |
QVERIFY(buttons.checkedButton() == &pb1);
|
|
431 |
pb2.setChecked(true);
|
|
432 |
QVERIFY(buttons.checkedButton() == &pb2);
|
|
433 |
pb2.setChecked(false);
|
|
434 |
QVERIFY(buttons.checkedButton() == &pb1);
|
|
435 |
pb1.setChecked(false);
|
|
436 |
QVERIFY(buttons.checkedButton() == 0);
|
|
437 |
|
|
438 |
buttons.setExclusive(true);
|
|
439 |
QVERIFY(buttons.checkedButton() == 0);
|
|
440 |
pb1.setChecked(true);
|
|
441 |
QVERIFY(buttons.checkedButton() == &pb1);
|
|
442 |
pb2.setChecked(true);
|
|
443 |
QVERIFY(buttons.checkedButton() == &pb2);
|
|
444 |
// checked button cannot be unchecked
|
|
445 |
pb2.setChecked(false);
|
|
446 |
QVERIFY(buttons.checkedButton() == &pb2);
|
|
447 |
}
|
|
448 |
|
|
449 |
class task209485_ButtonDeleter : public QObject
|
|
450 |
{
|
|
451 |
Q_OBJECT
|
|
452 |
|
|
453 |
public:
|
|
454 |
task209485_ButtonDeleter(QButtonGroup *group, bool deleteButton)
|
|
455 |
: group(group)
|
|
456 |
, deleteButton(deleteButton)
|
|
457 |
{
|
|
458 |
connect(group, SIGNAL(buttonClicked(int)), SLOT(buttonClicked(int)));
|
|
459 |
}
|
|
460 |
|
|
461 |
private slots:
|
|
462 |
void buttonClicked(int)
|
|
463 |
{
|
|
464 |
if (deleteButton)
|
|
465 |
group->removeButton(group->buttons().first());
|
|
466 |
}
|
|
467 |
|
|
468 |
private:
|
|
469 |
QButtonGroup *group;
|
|
470 |
bool deleteButton;
|
|
471 |
};
|
|
472 |
|
|
473 |
void tst_QButtonGroup::task209485_removeFromGroupInEventHandler_data()
|
|
474 |
{
|
|
475 |
QTest::addColumn<bool>("deleteButton");
|
|
476 |
QTest::addColumn<int>("signalCount");
|
|
477 |
QTest::newRow("buttonPress 1") << true << 1;
|
|
478 |
QTest::newRow("buttonPress 2") << false << 2;
|
|
479 |
}
|
|
480 |
|
|
481 |
void tst_QButtonGroup::task209485_removeFromGroupInEventHandler()
|
|
482 |
{
|
|
483 |
QFETCH(bool, deleteButton);
|
|
484 |
QFETCH(int, signalCount);
|
|
485 |
qRegisterMetaType<QAbstractButton *>("QAbstractButton *");
|
|
486 |
|
|
487 |
QPushButton *button = new QPushButton;
|
|
488 |
QButtonGroup group;
|
|
489 |
group.addButton(button);
|
|
490 |
|
|
491 |
task209485_ButtonDeleter buttonDeleter(&group, deleteButton);
|
|
492 |
|
|
493 |
QSignalSpy spy1(&group, SIGNAL(buttonClicked(QAbstractButton *)));
|
|
494 |
QSignalSpy spy2(&group, SIGNAL(buttonClicked(int)));
|
|
495 |
|
|
496 |
// NOTE: Reintroducing the bug of this task will cause the following line to crash:
|
|
497 |
QTest::mouseClick(button, Qt::LeftButton);
|
|
498 |
|
|
499 |
QCOMPARE(spy1.count() + spy2.count(), signalCount);
|
|
500 |
}
|
|
501 |
|
|
502 |
#if QT_VERSION >= 0x040600
|
|
503 |
void tst_QButtonGroup::autoIncrementId()
|
|
504 |
{
|
|
505 |
QDialog dlg(0);
|
|
506 |
QButtonGroup *buttons = new QButtonGroup(&dlg);
|
|
507 |
QVBoxLayout *vbox = new QVBoxLayout(&dlg);
|
|
508 |
|
|
509 |
QRadioButton *radio1 = new QRadioButton(&dlg);
|
|
510 |
radio1->setText("radio1");
|
|
511 |
QRadioButton *radio2 = new QRadioButton(&dlg);
|
|
512 |
radio2->setText("radio2");
|
|
513 |
QRadioButton *radio3 = new QRadioButton(&dlg);
|
|
514 |
radio3->setText("radio3");
|
|
515 |
|
|
516 |
buttons->addButton(radio1);
|
|
517 |
vbox->addWidget(radio1);
|
|
518 |
buttons->addButton(radio2);
|
|
519 |
vbox->addWidget(radio2);
|
|
520 |
buttons->addButton(radio3);
|
|
521 |
vbox->addWidget(radio3);
|
|
522 |
|
|
523 |
radio1->setChecked(true);
|
|
524 |
|
|
525 |
QVERIFY(buttons->id(radio1) == -2);
|
|
526 |
QVERIFY(buttons->id(radio2) == -3);
|
|
527 |
QVERIFY(buttons->id(radio3) == -4);
|
|
528 |
|
|
529 |
dlg.show();
|
|
530 |
}
|
|
531 |
#endif
|
|
532 |
|
|
533 |
QTEST_MAIN(tst_QButtonGroup)
|
|
534 |
#include "tst_qbuttongroup.moc"
|