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 |
#include <qtabwidget.h>
|
|
45 |
#include <qdebug.h>
|
|
46 |
#include <qapplication.h>
|
|
47 |
#include <qlabel.h>
|
|
48 |
|
|
49 |
//TESTED_CLASS=
|
|
50 |
//TESTED_FILES=
|
|
51 |
|
|
52 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
|
|
53 |
# include <qt_windows.h>
|
|
54 |
#define Q_CHECK_PAINTEVENTS \
|
|
55 |
if (::SwitchDesktop(::GetThreadDesktop(::GetCurrentThreadId())) == 0) \
|
|
56 |
QSKIP("desktop is not visible, this test would fail", SkipSingle);
|
|
57 |
#else
|
|
58 |
#define Q_CHECK_PAINTEVENTS
|
|
59 |
#endif
|
|
60 |
#if defined(Q_WS_X11)
|
|
61 |
# include <private/qt_x11_p.h>
|
|
62 |
# include <qx11info_x11.h>
|
|
63 |
#elif defined(Q_WS_QWS)
|
|
64 |
# include <qwindowsystem_qws.h>
|
|
65 |
#endif
|
|
66 |
|
|
67 |
#ifndef Q_CHECK_PAINTEVENTS
|
|
68 |
#define Q_CHECK_PAINTEVENTS
|
|
69 |
#endif //Q_CHECK_PAINTEVENTS
|
|
70 |
|
|
71 |
|
|
72 |
class QTabWidgetChild:public QTabWidget {
|
|
73 |
public:
|
|
74 |
QTabWidgetChild():tabCount(0) {
|
|
75 |
QVERIFY(tabBar() != NULL);
|
|
76 |
QWidget *w = new QWidget;
|
|
77 |
int index = addTab(w, "test");
|
|
78 |
QCOMPARE(tabCount, 1);
|
|
79 |
removeTab(index);
|
|
80 |
QCOMPARE(tabCount, 0);
|
|
81 |
|
|
82 |
// Test bad arguments
|
|
83 |
// This will assert, so don't do it :)
|
|
84 |
//setTabBar(NULL);
|
|
85 |
};
|
|
86 |
|
|
87 |
protected:
|
|
88 |
virtual void tabInserted(int /*index */ ) {
|
|
89 |
tabCount++;
|
|
90 |
};
|
|
91 |
virtual void tabRemoved(int /*index */ ) {
|
|
92 |
tabCount--;
|
|
93 |
};
|
|
94 |
int tabCount;
|
|
95 |
};
|
|
96 |
|
|
97 |
class tst_QTabWidget:public QObject {
|
|
98 |
Q_OBJECT
|
|
99 |
public:
|
|
100 |
tst_QTabWidget();
|
|
101 |
|
|
102 |
public slots:
|
|
103 |
void init();
|
|
104 |
void cleanup();
|
|
105 |
private slots:
|
|
106 |
void getSetCheck();
|
|
107 |
void testChild();
|
|
108 |
void addRemoveTab();
|
|
109 |
void tabPosition();
|
|
110 |
void tabEnabled();
|
|
111 |
void tabText();
|
|
112 |
void tabShape();
|
|
113 |
void tabTooltip();
|
|
114 |
void tabIcon();
|
|
115 |
void indexOf();
|
|
116 |
void currentWidget();
|
|
117 |
void currentIndex();
|
|
118 |
void cornerWidget();
|
|
119 |
void removeTab();
|
|
120 |
void clear();
|
|
121 |
void keyboardNavigation();
|
|
122 |
void paintEventCount();
|
|
123 |
|
|
124 |
private:
|
|
125 |
int addPage();
|
|
126 |
void removePage(int index);
|
|
127 |
QTabWidget *tw;
|
|
128 |
};
|
|
129 |
|
|
130 |
// Testing get/set functions
|
|
131 |
void tst_QTabWidget::getSetCheck()
|
|
132 |
{
|
|
133 |
QTabWidget obj1;
|
|
134 |
QWidget *w1 = new QWidget;
|
|
135 |
QWidget *w2 = new QWidget;
|
|
136 |
QWidget *w3 = new QWidget;
|
|
137 |
QWidget *w4 = new QWidget;
|
|
138 |
QWidget *w5 = new QWidget;
|
|
139 |
|
|
140 |
obj1.addTab(w1, "Page 1");
|
|
141 |
obj1.addTab(w2, "Page 2");
|
|
142 |
obj1.addTab(w3, "Page 3");
|
|
143 |
obj1.addTab(w4, "Page 4");
|
|
144 |
obj1.addTab(w5, "Page 5");
|
|
145 |
|
|
146 |
// TabShape QTabWidget::tabShape()
|
|
147 |
// void QTabWidget::setTabShape(TabShape)
|
|
148 |
obj1.setTabShape(QTabWidget::TabShape(QTabWidget::Rounded));
|
|
149 |
QCOMPARE(QTabWidget::TabShape(QTabWidget::Rounded), obj1.tabShape());
|
|
150 |
obj1.setTabShape(QTabWidget::TabShape(QTabWidget::Triangular));
|
|
151 |
QCOMPARE(QTabWidget::TabShape(QTabWidget::Triangular), obj1.tabShape());
|
|
152 |
|
|
153 |
// int QTabWidget::currentIndex()
|
|
154 |
// void QTabWidget::setCurrentIndex(int)
|
|
155 |
obj1.setCurrentIndex(0);
|
|
156 |
QCOMPARE(0, obj1.currentIndex());
|
|
157 |
obj1.setCurrentIndex(INT_MIN);
|
|
158 |
QCOMPARE(0, obj1.currentIndex());
|
|
159 |
obj1.setCurrentIndex(INT_MAX);
|
|
160 |
QCOMPARE(0, obj1.currentIndex());
|
|
161 |
obj1.setCurrentIndex(4);
|
|
162 |
QCOMPARE(4, obj1.currentIndex());
|
|
163 |
|
|
164 |
// QWidget * QTabWidget::currentWidget()
|
|
165 |
// void QTabWidget::setCurrentWidget(QWidget *)
|
|
166 |
obj1.setCurrentWidget(w1);
|
|
167 |
QCOMPARE(w1, obj1.currentWidget());
|
|
168 |
obj1.setCurrentWidget(w5);
|
|
169 |
QCOMPARE(w5, obj1.currentWidget());
|
|
170 |
obj1.setCurrentWidget((QWidget *)0);
|
|
171 |
QCOMPARE(w5, obj1.currentWidget()); // current not changed
|
|
172 |
}
|
|
173 |
|
|
174 |
tst_QTabWidget::tst_QTabWidget()
|
|
175 |
{
|
|
176 |
}
|
|
177 |
|
|
178 |
void tst_QTabWidget::init()
|
|
179 |
{
|
|
180 |
tw = new QTabWidget(0);
|
|
181 |
QCOMPARE(tw->count(), 0);
|
|
182 |
QCOMPARE(tw->currentIndex(), -1);
|
|
183 |
QVERIFY(tw->currentWidget() == NULL);
|
|
184 |
}
|
|
185 |
|
|
186 |
void tst_QTabWidget::cleanup()
|
|
187 |
{
|
|
188 |
delete tw;
|
|
189 |
tw = 0;
|
|
190 |
}
|
|
191 |
|
|
192 |
void tst_QTabWidget::testChild()
|
|
193 |
{
|
|
194 |
QTabWidgetChild t;
|
|
195 |
}
|
|
196 |
|
|
197 |
#define LABEL "TEST"
|
|
198 |
#define TIP "TIP"
|
|
199 |
int tst_QTabWidget::addPage()
|
|
200 |
{
|
|
201 |
QWidget *w = new QWidget();
|
|
202 |
return tw->addTab(w, LABEL);
|
|
203 |
}
|
|
204 |
|
|
205 |
void tst_QTabWidget::removePage(int index)
|
|
206 |
{
|
|
207 |
QWidget *w = tw->widget(index);
|
|
208 |
tw->removeTab(index);
|
|
209 |
delete w;
|
|
210 |
}
|
|
211 |
|
|
212 |
/**
|
|
213 |
* Tests:
|
|
214 |
* addTab(...) which really calls -> insertTab(...)
|
|
215 |
* widget(...)
|
|
216 |
* removeTab(...);
|
|
217 |
* If this fails then many others probably will too.
|
|
218 |
*/
|
|
219 |
void tst_QTabWidget::addRemoveTab()
|
|
220 |
{
|
|
221 |
// Test bad arguments
|
|
222 |
tw->addTab(NULL, LABEL);
|
|
223 |
QCOMPARE(tw->count(), 0);
|
|
224 |
tw->removeTab(-1);
|
|
225 |
QCOMPARE(tw->count(), 0);
|
|
226 |
QVERIFY(tw->widget(-1) == 0);
|
|
227 |
|
|
228 |
QWidget *w = new QWidget();
|
|
229 |
int index = tw->addTab(w, LABEL);
|
|
230 |
// return value
|
|
231 |
QCOMPARE(tw->indexOf(w), index);
|
|
232 |
|
|
233 |
QCOMPARE(tw->count(), 1);
|
|
234 |
QVERIFY(tw->widget(index) == w);
|
|
235 |
QCOMPARE(tw->tabText(index), QString(LABEL));
|
|
236 |
|
|
237 |
removePage(index);
|
|
238 |
QCOMPARE(tw->count(), 0);
|
|
239 |
}
|
|
240 |
|
|
241 |
void tst_QTabWidget::tabPosition()
|
|
242 |
{
|
|
243 |
tw->setTabPosition(QTabWidget::North);
|
|
244 |
QCOMPARE(tw->tabPosition(), QTabWidget::North);
|
|
245 |
tw->setTabPosition(QTabWidget::South);
|
|
246 |
QCOMPARE(tw->tabPosition(), QTabWidget::South);
|
|
247 |
tw->setTabPosition(QTabWidget::East);
|
|
248 |
QCOMPARE(tw->tabPosition(), QTabWidget::East);
|
|
249 |
tw->setTabPosition(QTabWidget::West);
|
|
250 |
QCOMPARE(tw->tabPosition(), QTabWidget::West);
|
|
251 |
}
|
|
252 |
|
|
253 |
void tst_QTabWidget::tabEnabled()
|
|
254 |
{
|
|
255 |
// Test bad arguments
|
|
256 |
QVERIFY(tw->isTabEnabled(-1) == false);
|
|
257 |
tw->setTabEnabled(-1, false);
|
|
258 |
|
|
259 |
int index = addPage();
|
|
260 |
|
|
261 |
tw->setTabEnabled(index, true);
|
|
262 |
QVERIFY(tw->isTabEnabled(index) == true);
|
|
263 |
tw->setTabEnabled(index, false);
|
|
264 |
QVERIFY(tw->isTabEnabled(index) == false);
|
|
265 |
tw->setTabEnabled(index, true);
|
|
266 |
QVERIFY(tw->isTabEnabled(index) == true);
|
|
267 |
|
|
268 |
removePage(index);
|
|
269 |
}
|
|
270 |
|
|
271 |
void tst_QTabWidget::tabText()
|
|
272 |
{
|
|
273 |
// Test bad arguments
|
|
274 |
QCOMPARE(tw->tabText(-1), QString(""));
|
|
275 |
tw->setTabText(-1, LABEL);
|
|
276 |
|
|
277 |
int index = addPage();
|
|
278 |
|
|
279 |
tw->setTabText(index, "new");
|
|
280 |
QCOMPARE(tw->tabText(index), QString("new"));
|
|
281 |
tw->setTabText(index, LABEL);
|
|
282 |
QCOMPARE(tw->tabText(index), QString(LABEL));
|
|
283 |
|
|
284 |
removePage(index);
|
|
285 |
}
|
|
286 |
|
|
287 |
void tst_QTabWidget::tabShape()
|
|
288 |
{
|
|
289 |
int index = addPage();
|
|
290 |
|
|
291 |
tw->setTabShape(QTabWidget::Rounded);
|
|
292 |
QCOMPARE(tw->tabShape(), QTabWidget::Rounded);
|
|
293 |
tw->setTabShape(QTabWidget::Triangular);
|
|
294 |
QCOMPARE(tw->tabShape(), QTabWidget::Triangular);
|
|
295 |
tw->setTabShape(QTabWidget::Rounded);
|
|
296 |
QCOMPARE(tw->tabShape(), QTabWidget::Rounded);
|
|
297 |
|
|
298 |
removePage(index);
|
|
299 |
}
|
|
300 |
|
|
301 |
void tst_QTabWidget::tabTooltip()
|
|
302 |
{
|
|
303 |
// Test bad arguments
|
|
304 |
QCOMPARE(tw->tabToolTip(-1), QString(""));
|
|
305 |
tw->setTabText(-1, TIP);
|
|
306 |
|
|
307 |
int index = addPage();
|
|
308 |
|
|
309 |
tw->setTabToolTip(index, "tip");
|
|
310 |
QCOMPARE(tw->tabToolTip(index), QString("tip"));
|
|
311 |
tw->setTabToolTip(index, TIP);
|
|
312 |
QCOMPARE(tw->tabToolTip(index), QString(TIP));
|
|
313 |
|
|
314 |
removePage(index);
|
|
315 |
}
|
|
316 |
|
|
317 |
void tst_QTabWidget::tabIcon()
|
|
318 |
{
|
|
319 |
// Test bad arguments
|
|
320 |
QVERIFY(tw->tabToolTip(-1).isNull());
|
|
321 |
tw->setTabIcon(-1, QIcon());
|
|
322 |
|
|
323 |
int index = addPage();
|
|
324 |
|
|
325 |
QIcon icon;
|
|
326 |
tw->setTabIcon(index, icon);
|
|
327 |
QVERIFY(tw->tabIcon(index).isNull());
|
|
328 |
|
|
329 |
removePage(index);
|
|
330 |
}
|
|
331 |
|
|
332 |
void tst_QTabWidget::indexOf()
|
|
333 |
{
|
|
334 |
// Test bad arguments
|
|
335 |
QCOMPARE(tw->indexOf(NULL), -1);
|
|
336 |
|
|
337 |
int index = addPage();
|
|
338 |
QWidget *w = tw->widget(index);
|
|
339 |
QCOMPARE(tw->indexOf(w), index);
|
|
340 |
|
|
341 |
removePage(index);
|
|
342 |
}
|
|
343 |
|
|
344 |
void tst_QTabWidget::currentWidget()
|
|
345 |
{
|
|
346 |
// Test bad arguments
|
|
347 |
tw->setCurrentWidget(NULL);
|
|
348 |
QVERIFY(tw->currentWidget() == NULL);
|
|
349 |
|
|
350 |
int index = addPage();
|
|
351 |
QWidget *w = tw->widget(index);
|
|
352 |
QVERIFY(tw->currentWidget() == w);
|
|
353 |
QCOMPARE(tw->currentIndex(), index);
|
|
354 |
|
|
355 |
tw->setCurrentWidget(NULL);
|
|
356 |
QVERIFY(tw->currentWidget() == w);
|
|
357 |
QCOMPARE(tw->currentIndex(), index);
|
|
358 |
|
|
359 |
int index2 = addPage();
|
|
360 |
QWidget *w2 = tw->widget(index2);
|
|
361 |
Q_UNUSED(w2);
|
|
362 |
QVERIFY(tw->currentWidget() == w);
|
|
363 |
QCOMPARE(tw->currentIndex(), index);
|
|
364 |
|
|
365 |
removePage(index2);
|
|
366 |
removePage(index);
|
|
367 |
}
|
|
368 |
|
|
369 |
/**
|
|
370 |
* setCurrentWidget(..) calls setCurrentIndex(..)
|
|
371 |
* currentChanged(..) SIGNAL
|
|
372 |
*/
|
|
373 |
void tst_QTabWidget::currentIndex()
|
|
374 |
{
|
|
375 |
// Test bad arguments
|
|
376 |
QSignalSpy spy(tw, SIGNAL(currentChanged(int)));
|
|
377 |
#ifdef QT3_SUPPORT
|
|
378 |
QSignalSpy spySupport(tw, SIGNAL(currentChanged(QWidget *)));
|
|
379 |
#endif
|
|
380 |
QCOMPARE(tw->currentIndex(), -1);
|
|
381 |
tw->setCurrentIndex(-1);
|
|
382 |
QCOMPARE(tw->currentIndex(), -1);
|
|
383 |
QCOMPARE(spy.count(), 0);
|
|
384 |
|
|
385 |
int firstIndex = addPage();
|
|
386 |
tw->setCurrentIndex(firstIndex);
|
|
387 |
QCOMPARE(tw->currentIndex(), firstIndex);
|
|
388 |
QCOMPARE(spy.count(), 1);
|
|
389 |
QList<QVariant> arguments = spy.takeFirst();
|
|
390 |
QVERIFY(arguments.at(0).toInt() == firstIndex);
|
|
391 |
#ifdef QT3_SUPPORT
|
|
392 |
QCOMPARE(spySupport.count(), 1);
|
|
393 |
#endif
|
|
394 |
|
|
395 |
int index = addPage();
|
|
396 |
QCOMPARE(tw->currentIndex(), firstIndex);
|
|
397 |
tw->setCurrentIndex(index);
|
|
398 |
QCOMPARE(tw->currentIndex(), index);
|
|
399 |
QCOMPARE(spy.count(), 1);
|
|
400 |
arguments = spy.takeFirst();
|
|
401 |
QVERIFY(arguments.at(0).toInt() == index);
|
|
402 |
#ifdef QT3_SUPPORT
|
|
403 |
QCOMPARE(spySupport.count(), 2);
|
|
404 |
#endif
|
|
405 |
|
|
406 |
removePage(index);
|
|
407 |
QCOMPARE(tw->currentIndex(), firstIndex);
|
|
408 |
QCOMPARE(spy.count(), 1);
|
|
409 |
arguments = spy.takeFirst();
|
|
410 |
QVERIFY(arguments.at(0).toInt() == firstIndex);
|
|
411 |
#ifdef QT3_SUPPORT
|
|
412 |
QCOMPARE(spySupport.count(), 3);
|
|
413 |
#endif
|
|
414 |
|
|
415 |
removePage(firstIndex);
|
|
416 |
QCOMPARE(tw->currentIndex(), -1);
|
|
417 |
QCOMPARE(spy.count(), 1);
|
|
418 |
arguments = spy.takeFirst();
|
|
419 |
QVERIFY(arguments.at(0).toInt() == -1);
|
|
420 |
#ifdef QT3_SUPPORT
|
|
421 |
QCOMPARE(spySupport.count(), 4);
|
|
422 |
#endif
|
|
423 |
|
|
424 |
}
|
|
425 |
|
|
426 |
void tst_QTabWidget::cornerWidget()
|
|
427 |
{
|
|
428 |
// Test bad arguments
|
|
429 |
tw->setCornerWidget(NULL, Qt::TopRightCorner);
|
|
430 |
|
|
431 |
QVERIFY(tw->cornerWidget(Qt::TopLeftCorner) == 0);
|
|
432 |
QVERIFY(tw->cornerWidget(Qt::TopRightCorner) == 0);
|
|
433 |
QVERIFY(tw->cornerWidget(Qt::BottomLeftCorner) == 0);
|
|
434 |
QVERIFY(tw->cornerWidget(Qt::BottomRightCorner) == 0);
|
|
435 |
|
|
436 |
QWidget *w = new QWidget(0);
|
|
437 |
tw->setCornerWidget(w, Qt::TopLeftCorner);
|
|
438 |
QCOMPARE(w->parent(), (QObject *)tw);
|
|
439 |
QVERIFY(tw->cornerWidget(Qt::TopLeftCorner) == w);
|
|
440 |
tw->setCornerWidget(w, Qt::TopRightCorner);
|
|
441 |
QVERIFY(tw->cornerWidget(Qt::TopRightCorner) == w);
|
|
442 |
tw->setCornerWidget(w, Qt::BottomLeftCorner);
|
|
443 |
QVERIFY(tw->cornerWidget(Qt::BottomLeftCorner) == w);
|
|
444 |
tw->setCornerWidget(w, Qt::BottomRightCorner);
|
|
445 |
QVERIFY(tw->cornerWidget(Qt::BottomRightCorner) == w);
|
|
446 |
|
|
447 |
tw->setCornerWidget(0, Qt::TopRightCorner);
|
|
448 |
QVERIFY(tw->cornerWidget(Qt::TopRightCorner) == 0);
|
|
449 |
QCOMPARE(w->isHidden(), true);
|
|
450 |
}
|
|
451 |
|
|
452 |
//test that the QTabWidget::count() is correct at the moment the currentChanged signal is emit
|
|
453 |
class RemoveTabObject : public QObject
|
|
454 |
{
|
|
455 |
Q_OBJECT
|
|
456 |
public:
|
|
457 |
RemoveTabObject(QTabWidget *_tw) : tw(_tw), count(-1) {
|
|
458 |
connect(tw, SIGNAL(currentChanged(int)), this, SLOT(currentChanged()));
|
|
459 |
}
|
|
460 |
|
|
461 |
QTabWidget *tw;
|
|
462 |
int count;
|
|
463 |
public slots:
|
|
464 |
void currentChanged() { count = tw->count(); }
|
|
465 |
};
|
|
466 |
|
|
467 |
void tst_QTabWidget::removeTab()
|
|
468 |
{
|
|
469 |
tw->show();
|
|
470 |
QCOMPARE(tw->count(), 0);
|
|
471 |
RemoveTabObject ob(tw);
|
|
472 |
tw->addTab(new QLabel("1"), "1");
|
|
473 |
QCOMPARE(ob.count, 1);
|
|
474 |
tw->addTab(new QLabel("2"), "2");
|
|
475 |
tw->addTab(new QLabel("3"), "3");
|
|
476 |
tw->addTab(new QLabel("4"), "4");
|
|
477 |
tw->addTab(new QLabel("5"), "5");
|
|
478 |
QCOMPARE(ob.count, 1);
|
|
479 |
QCOMPARE(tw->count(), 5);
|
|
480 |
|
|
481 |
tw->setCurrentIndex(4);
|
|
482 |
QCOMPARE(ob.count,5);
|
|
483 |
tw->removeTab(4);
|
|
484 |
QCOMPARE(ob.count, 4);
|
|
485 |
QCOMPARE(tw->count(), 4);
|
|
486 |
QCOMPARE(tw->currentIndex(), 3);
|
|
487 |
|
|
488 |
tw->setCurrentIndex(1);
|
|
489 |
tw->removeTab(1);
|
|
490 |
QCOMPARE(ob.count, 3);
|
|
491 |
QCOMPARE(tw->count(), 3);
|
|
492 |
QCOMPARE(tw->currentIndex(), 1);
|
|
493 |
|
|
494 |
delete tw->widget(1);
|
|
495 |
QCOMPARE(tw->count(), 2);
|
|
496 |
QCOMPARE(ob.count, 2);
|
|
497 |
QCOMPARE(tw->currentIndex(), 1);
|
|
498 |
delete tw->widget(1);
|
|
499 |
QCOMPARE(tw->count(), 1);
|
|
500 |
QCOMPARE(ob.count, 1);
|
|
501 |
tw->removeTab(0);
|
|
502 |
QCOMPARE(tw->count(), 0);
|
|
503 |
QCOMPARE(ob.count, 0);
|
|
504 |
}
|
|
505 |
|
|
506 |
void tst_QTabWidget::clear()
|
|
507 |
{
|
|
508 |
tw->addTab(new QWidget, "1");
|
|
509 |
tw->addTab(new QWidget, "2");
|
|
510 |
tw->addTab(new QWidget, "3");
|
|
511 |
tw->addTab(new QWidget, "4");
|
|
512 |
tw->addTab(new QWidget, "5");
|
|
513 |
tw->setCurrentIndex(4);
|
|
514 |
tw->clear();
|
|
515 |
QCOMPARE(tw->count(), 0);
|
|
516 |
QCOMPARE(tw->currentIndex(), -1);
|
|
517 |
}
|
|
518 |
|
|
519 |
void tst_QTabWidget::keyboardNavigation()
|
|
520 |
{
|
|
521 |
int firstIndex = addPage();
|
|
522 |
addPage();
|
|
523 |
addPage();
|
|
524 |
tw->setCurrentIndex(firstIndex);
|
|
525 |
QCOMPARE(tw->currentIndex(), firstIndex);
|
|
526 |
|
|
527 |
QTest::keyClick(tw, Qt::Key_Tab, Qt::ControlModifier);
|
|
528 |
QCOMPARE(tw->currentIndex(), 1);
|
|
529 |
QTest::keyClick(tw, Qt::Key_Tab, Qt::ControlModifier);
|
|
530 |
QCOMPARE(tw->currentIndex(), 2);
|
|
531 |
QTest::keyClick(tw, Qt::Key_Tab, Qt::ControlModifier);
|
|
532 |
QCOMPARE(tw->currentIndex(), 0);
|
|
533 |
tw->setTabEnabled(1, false);
|
|
534 |
QTest::keyClick(tw, Qt::Key_Tab, Qt::ControlModifier);
|
|
535 |
QCOMPARE(tw->currentIndex(), 2);
|
|
536 |
|
|
537 |
QTest::keyClick(tw, Qt::Key_Tab, Qt::ControlModifier | Qt::ShiftModifier);
|
|
538 |
QCOMPARE(tw->currentIndex(), 0);
|
|
539 |
QTest::keyClick(tw, Qt::Key_Tab, Qt::ControlModifier | Qt::ShiftModifier);
|
|
540 |
QCOMPARE(tw->currentIndex(), 2);
|
|
541 |
tw->setTabEnabled(1, true);
|
|
542 |
QTest::keyClick(tw, Qt::Key_Tab, Qt::ControlModifier | Qt::ShiftModifier);
|
|
543 |
QCOMPARE(tw->currentIndex(), 1);
|
|
544 |
QTest::keyClick(tw, Qt::Key_Tab, Qt::ControlModifier | Qt::ShiftModifier);
|
|
545 |
QCOMPARE(tw->currentIndex(), 0);
|
|
546 |
QTest::keyClick(tw, Qt::Key_Tab, Qt::ControlModifier | Qt::ShiftModifier);
|
|
547 |
QCOMPARE(tw->currentIndex(), 2);
|
|
548 |
QTest::keyClick(tw, Qt::Key_Tab, Qt::ControlModifier);
|
|
549 |
QCOMPARE(tw->currentIndex(), 0);
|
|
550 |
|
|
551 |
// Disable all and try to go to the next. It should not move anywhere, and more importantly
|
|
552 |
// it should not loop forever. (a naive "search for the first enabled tabbar") implementation
|
|
553 |
// might do that)
|
|
554 |
tw->setTabEnabled(0, false);
|
|
555 |
tw->setTabEnabled(1, false);
|
|
556 |
tw->setTabEnabled(2, false);
|
|
557 |
QTest::keyClick(tw, Qt::Key_Tab, Qt::ControlModifier);
|
|
558 |
// TODO: Disabling the current tab will move current tab to the next,
|
|
559 |
// but what if next tab is also disabled. We should look into this.
|
|
560 |
QVERIFY(tw->currentIndex() < 3 && tw->currentIndex() >= 0);
|
|
561 |
}
|
|
562 |
|
|
563 |
class PaintCounter : public QWidget
|
|
564 |
{
|
|
565 |
public:
|
|
566 |
PaintCounter() :count(0) { setAttribute(Qt::WA_OpaquePaintEvent); }
|
|
567 |
int count;
|
|
568 |
protected:
|
|
569 |
void paintEvent(QPaintEvent*) {
|
|
570 |
++count;
|
|
571 |
}
|
|
572 |
};
|
|
573 |
|
|
574 |
|
|
575 |
void tst_QTabWidget::paintEventCount()
|
|
576 |
{
|
|
577 |
Q_CHECK_PAINTEVENTS
|
|
578 |
|
|
579 |
PaintCounter *tab1 = new PaintCounter;
|
|
580 |
PaintCounter *tab2 = new PaintCounter;
|
|
581 |
|
|
582 |
tw->addTab(tab1, "one");
|
|
583 |
tw->addTab(tab2, "two");
|
|
584 |
|
|
585 |
QCOMPARE(tab1->count, 0);
|
|
586 |
QCOMPARE(tab2->count, 0);
|
|
587 |
QCOMPARE(tw->currentIndex(), 0);
|
|
588 |
|
|
589 |
tw->show();
|
|
590 |
|
|
591 |
QTest::qWait(1000);
|
|
592 |
|
|
593 |
// Mac, Windows and Windows CE get multiple repaints on the first show, so use those as a starting point.
|
|
594 |
static const int MaxInitialPaintCount =
|
|
595 |
#if defined(Q_OS_WINCE)
|
|
596 |
4;
|
|
597 |
#elif defined(Q_WS_WIN)
|
|
598 |
2;
|
|
599 |
#elif defined(Q_WS_MAC)
|
|
600 |
5;
|
|
601 |
#else
|
|
602 |
2;
|
|
603 |
#endif
|
|
604 |
QVERIFY(tab1->count <= MaxInitialPaintCount);
|
|
605 |
QCOMPARE(tab2->count, 0);
|
|
606 |
|
|
607 |
const int initalPaintCount = tab1->count;
|
|
608 |
|
|
609 |
tw->setCurrentIndex(1);
|
|
610 |
|
|
611 |
QTest::qWait(100);
|
|
612 |
|
|
613 |
QCOMPARE(tab1->count, initalPaintCount);
|
|
614 |
QCOMPARE(tab2->count, 1);
|
|
615 |
|
|
616 |
tw->setCurrentIndex(0);
|
|
617 |
|
|
618 |
QTest::qWait(100);
|
|
619 |
|
|
620 |
QCOMPARE(tab1->count, initalPaintCount + 1);
|
|
621 |
QCOMPARE(tab2->count, 1);
|
|
622 |
}
|
|
623 |
|
|
624 |
|
|
625 |
QTEST_MAIN(tst_QTabWidget)
|
|
626 |
#include "tst_qtabwidget.moc"
|