1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
|
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of QtUiTest.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qtuitestwidgetinterface.h"
#include "qtuitestnamespace.h"
#include <QRect>
#include <QRegion>
#include <QApplication>
#include <QWidget>
#include <QVariant>
/*!
\preliminary
\class QtUiTest::WidgetFactory
\inpublicgroup QtUiTestModule
\brief The WidgetFactory class provides a factory interface
for QtUiTest widget wrapper classes.
QtUiTest::WidgetFactory is an abstract base class which enables the
creation of QtUiTest wrapper objects around Qt widgets.
Customizing QtUiTest behaviour for particular widgets is achieved by
implementing one or more test widget classes which inherit from
one or more QtUiTest widget interfaces,
subclassing QtUiTest::WidgetFactory, reimplementing the pure virtual
keys() and create() functions to create instances of the custom test
widget classes, and exporting the factory class using the
Q_EXPORT_PLUGIN2() macro.
*/
/*!
\fn QtUiTest::WidgetFactory::create(QObject* object)
Attempts to create a test widget to wrap \a object. Returns the created
test widget. Returns 0 if this factory does not support wrapping
\a object.
The returned object is suitable for use with
\l{QtUiTest}{qtuitest_cast}.
This function will only be called for objects which inherit one of the
classes returned by keys().
*/
/*!
Returns a widget or test widget of \a type, or 0 if none can be found.
Reimplement this function to provide custom behaviour for
QtUiTest::findWidget(). For example, if a custom soft menu widget is
being used rather than the shipped ContextLabel class, this function
must be reimplemented to return a pointer to the custom widget.
The base implementation always returns 0.
*/
QObject* QtUiTest::WidgetFactory::find(QtUiTest::WidgetType type)
{ Q_UNUSED(type); return 0; }
/*!
\fn QtUiTest::WidgetFactory::keys() const
Returns the list of C++ class names this factory can generate test widgets
for.
Note that returning a class from this function does not guarantee that the
factory will always be able to generate a test widget for that class.
*/
/*!
\preliminary
\class QtUiTest::Widget
\inpublicgroup QtUiTestModule
\brief The Widget class provides an abstract base class
for all test widgets.
QtUiTest::Widget contains functionality which maps
closely to QWidget. It encapsulates important information
and functionality related to two-dimensional GUI elements.
All test widgets should implement the QtUiTest::Widget interface,
using multiple inheritance to implement other QtUiTest interfaces
where suitable.
*/
/*!
\fn const QRect& QtUiTest::Widget::geometry() const
Returns the geometry of this widget in parent coordinates.
\sa QWidget::geometry()
*/
/*!
Returns the bounding rect of this widget in widget coordinates.
The base implementation returns geometry(), transformed to widget
coordinates.
\sa QWidget::rect()
*/
QRect QtUiTest::Widget::rect() const
{
QRect ret(geometry());
ret.moveTopLeft(QPoint(0,0));
return ret;
}
/*!
Returns the left of the widget, in global coordinates.
\sa mapToGlobal()
*/
int QtUiTest::Widget::x() const
{
return mapToGlobal(QPoint()).x();
}
/*!
Returns the top of the widget, in global coordinates.
\sa mapToGlobal()
*/
int QtUiTest::Widget::y() const
{
return mapToGlobal(QPoint()).y();
}
/*!
Returns the width of the widget.
\sa geometry()
*/
int QtUiTest::Widget::width() const
{
return geometry().width();
}
/*!
Returns the height of the widget.
\sa geometry()
*/
int QtUiTest::Widget::height() const
{
return geometry().height();
}
/*!
\fn bool QtUiTest::Widget::isVisible() const
Returns true if this widget is currently visible.
In this context, "visible" has the same meaning as in QWidget::isVisible().
Therefore, this function returning \c{true} is not a guarantee that this
widget is currently on screen and unobscured. To test this,
visibleRegion() can be used.
\sa QWidget::isVisible(), visibleRegion()
*/
/*!
\fn QRegion QtUiTest::Widget::visibleRegion() const
Returns the currently on-screen, unobscured region of this widget,
in widget coordinates.
\sa QWidget::visibleRegion()
*/
/*!
\fn bool QtUiTest::Widget::ensureVisibleRegion(const QRegion& region)
Simulate whatever user input is necessary to ensure that \a region
(in local coordinates) is on-screen and unobscured.
Returns true if \a region was successfully made visible.
\sa visibleRegion()
*/
/*!
Simulate whatever user input is necessary to ensure that \a point
(in local coordinates) is on-screen and unobscured.
This convenience function calls ensureVisibleRegion() with a region
containing only \a point.
Returns true if \a point was successfully made visible.
\sa visibleRegion(), ensureVisibleRegion()
*/
bool QtUiTest::Widget::ensureVisiblePoint(const QPoint& point)
{
return ensureVisibleRegion( QRegion(point.x(), point.y(), 1, 1) );
}
/*!
\fn QObject* QtUiTest::Widget::parent() const
Returns the parent of this widget, or 0 if this widget has no parent.
The returned object may be an actual QWidget, or may be a wrapping
test widget. Therefore, the only safe way to use the returned value
of this function is to cast it to the desired QtUiTest interface
using \l{QtUiTest}{qtuitest_cast}.
\sa QObject::parent(), QWidget::parentWidget(), children()
*/
/*!
Returns the window title (caption).
The returned string will typically be empty for all widgets other than
top-level widgets.
The default implementation returns an empty string.
\sa QWidget::windowTitle()
*/
QString QtUiTest::Widget::windowTitle() const
{ return QString(); }
/*!
\fn const QObjectList& QtUiTest::Widget::children() const
Returns all children of this widget.
The returned objects may be actual QWidget instances, or may be wrapping
test widgets. Therefore, the only safe way to use the returned objects
are to cast them to the desired QtUiTest interface using
\l{QtUiTest}{qtuitest_cast}.
Reimplementing this function allows widgets which are conceptually
widgets but are not QObject subclasses to be wrapped. This can be
achieved by returning a list of test widgets which do not necessarily
have underlying QWidget instances.
\sa QObject::children(), parent()
*/
/*!
Returns all descendants of this widget.
\sa children(), parent()
*/
void QtUiTest::Widget::descendants(QObjectList &list) const
{
foreach (QObject *child, children()) {
if (!list.contains(child)) {
list << child;
QtUiTest::Widget* qw = qtuitest_cast<QtUiTest::Widget*>(child);
if (qw)
qw->descendants(list);
}
}
}
/*!
Returns the currently on-screen, unobscured region of all
child widgets of this widget, in widget coordinates. This does not
include the visible region of this widget.
The base implementation calculates the visible region by calling
visibleRegion() and childrenVisibleRegion() on all children().
\sa QWidget::visibleRegion(), children(), visibleRegion()
*/
QRegion QtUiTest::Widget::childrenVisibleRegion() const
{
QRegion ret;
foreach (QObject *o, children()) {
Widget *w = qtuitest_cast<Widget*>(o);
if (w) ret |= ((w->childrenVisibleRegion() | w->visibleRegion())
.translated( -w->geometry().topLeft() ) );
}
return ret;
}
/*!
\fn QPoint QtUiTest::Widget::mapToGlobal(const QPoint& pos) const
Maps \a pos from widget coordinates to global screen coordinates and
returns the result.
\sa QWidget::mapToGlobal()
*/
/*!
\fn QPoint QtUiTest::Widget::mapFromGlobal(const QPoint& pos) const
Maps \a pos from global screen coordinates to widget coordinates and
returns the result.
\sa QWidget::mapFromGlobal()
*/
/*!
Returns the center point of the widget. The base implementation
returns geometry().center().
\sa QtUiTest::Widget::geometry()
*/
QPoint QtUiTest::Widget::center() const
{
QPoint ret;
ret = mapToGlobal( geometry().center() );
return ret;
}
/*!
Simulate the user input necessary to move keyboard focus to this
widget.
The base implementation uses the result of hasFocus() to determine if the
widget currently has focus. If in keypad mode, a sequence of Up or Down
key presses will be used to move focus until this widget has focus.
If in mouse mode, the center of this widget will be clicked once.
Due to the way this function works in keypad mode, it is very important
that focusOutEvent() is correctly implemented for all widgets to dismiss
any "grab" effects on keyboard focus.
When reimplementing this function, it is necessary to call focusOutEvent()
on any widget before taking any action which could cause that widget to
lose focus.
Returns true if focus was successfully given to this widget, false
otherwise.
\sa QWidget::setFocus(), focusOutEvent()
*/
bool QtUiTest::Widget::setFocus()
{
if (hasFocus()) return true;
// xxx Try using findWidget(Focus) here instead.
struct Focus {
static QWidget* focusWidget() {
QWidget *w = QApplication::focusWidget();
if (!w) w = QApplication::activeWindow();
if (!w) w = QApplication::activePopupWidget();
if (!w) w = QApplication::activeModalWidget();
return w;
}
};
using namespace QtUiTest;
if (!mousePreferred()) {
bool backwards = false;
QWidget *w = Focus::focusWidget();
QWidget *initialFocus = w;
Widget *tw = qtuitest_cast<Widget*>(w);
if (!tw) {
setErrorString("Can't find currently focused widget!");
return false;
}
if (y() < tw->y() || (y() == tw->y() && x() < tw->x())) {
backwards = true;
}
const int maxtries = 100;
int i = 0;
QWidget *pw = 0;
while (!hasFocus() && i < maxtries) {
tw->focusOutEvent();
#if defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)
if (backwards) {
keyClick(Qt::Key_Up);
} else {
keyClick(Qt::Key_Down);
}
#else
if (backwards) {
keyClick(Qt::Key_Tab, Qt::ShiftModifier);
} else {
keyClick(Qt::Key_Tab);
}
#endif
pw = w;
if (w != pw && !QtUiTest::waitForSignal(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)))) {
setErrorString("Could not change widget focus using the keyboard");
return false;
}
//FIXME: Additional wait for Greenphone
QtUiTest::wait(200);
++i;
w = Focus::focusWidget();
if (w == initialFocus && w != pw) {
// Back to square one...
break;
}
tw = qtuitest_cast<Widget*>(w);
if (!tw) {
setErrorString("Can't find currently focused widget!");
return false;
}
}
if (!hasFocus()) {
setErrorString(QString("Failed to give focus to widget after %1 keyclicks")
.arg(maxtries));
}
} else {
Widget* tw = qtuitest_cast<Widget*>(Focus::focusWidget());
if (tw) tw->focusOutEvent();
QPoint center = rect().center();
ensureVisiblePoint(center);
center = mapToGlobal(center);
// In the past, bugs have existed which make one click
// be consumed somewhere.
// Keep working in that case, but give a warning.
int i = 0;
do {
mouseClick( center );
QtUiTest::waitForSignal(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)));
if (hasFocus()) break;
} while(++i < 2);
if (hasFocus() && 1 == i)
qWarning("QtUitest: possible bug, took more than one click to "
"give focus to a widget.");
}
return hasFocus();
}
/*!
\fn bool QtUiTest::Widget::setEditFocus(bool enable)
Simulate the user input necessary to \a enable or disable edit focus for
this widget. Enabling edit focus will implicitly call setFocus() when
necessary.
The concept of edit focus only exists in Qt Embedded. This function must
be implemented when using Qt Embedded. On other platforms,
this function will behave the same as setFocus() when enable is true, and
will have no effect when enable is false.
Returns true if edit focus was successfully enabled or disabled for this
widget, false otherwise.
\sa QWidget::setEditFocus(), hasEditFocus()
*/
#ifndef Q_WS_QWS
bool QtUiTest::Widget::setEditFocus(bool enable)
{
if (!enable) return true;
return hasFocus() || setFocus();
}
#endif
/*!
\fn bool QtUiTest::Widget::hasEditFocus() const
Returns true if this widget currently has edit focus.
The concept of edit focus only exists in Qt Embedded. This function must
be implemented on Qt Embedded. On other platforms, the base implementation
will return the same as hasFocus().
\sa QWidget::hasEditFocus(), setEditFocus()
*/
#ifndef Q_WS_QWS
bool QtUiTest::Widget::hasEditFocus() const
{ return hasFocus(); }
#endif
/*!
This function is called when this widget is about to lose keyboard focus.
The base implementation does nothing.
This function should be reimplemented to put this widget in a state where
subsequent up/down key clicks will result in non-destructive navigation
between widgets.
For example, if this function is called on a combo box which
currently has a list popped up, it should dismiss the list
so that subsequent key clicks will navigate between widgets rather
than navigating within the list.
\code
void MyComboBox::focusOutEvent() {
// Assuming q is a QComboBox...
// If the list is currently popped up...
if (q->view()->isVisible()) {
// Press the Select key to commit the currently highlighted
// item and ensure we are ready to navigate by keys.
QtUiTest::keyClick(Qt::Key_Select);
}
}
\endcode
\sa QWidget::focusOutEvent(), setFocus(), hasFocus()
*/
void QtUiTest::Widget::focusOutEvent()
{}
/*!
\fn bool QtUiTest::Widget::hasFocus() const
Returns true if this widget currently has keyboard focus.
\sa QWidget::hasFocus()
*/
/*!
Returns the focus proxy of this widget, or 0 if this widget has no focus proxy.
A widget may "have focus", but have a child widget that actually handles the
focus.
The returned object may be an actual QWidget, or may be a wrapping
test widget. Therefore, the only safe way to use the returned value
of this function is to cast it to the desired QtUiTest interface
using \l{QtUiTest}{qtuitest_cast}.
\sa QWidget::focusProxy()
*/
QObject* QtUiTest::Widget::focusProxy() const
{
return 0;
}
/*!
Returns the focus policy of this widget.
The default implementation returns Qt::NoFocus, indicating that the widget
does not accept focus.
\sa QWidget::focusPolicy()
*/
Qt::FocusPolicy QtUiTest::Widget::focusPolicy () const
{
return Qt::NoFocus;
}
/*!
Returns the flags set on this widget.
The default implementation returns 0, which is equivalent to a plain
Qt::Widget with no special flags set.
*/
Qt::WindowFlags QtUiTest::Widget::windowFlags() const
{ return 0; }
/*!
Returns true if this widget is of the given \a type.
The base implementation always returns false.
*/
bool QtUiTest::Widget::inherits(QtUiTest::WidgetType type) const
{ Q_UNUSED(type); return false; }
/*!
Sets \a pixmap to image of the widget. Returns true on success.
The base implementation always returns false.
*/
bool QtUiTest::Widget::grabPixmap(QPixmap &pixmap) const
{ Q_UNUSED(pixmap); return false; }
/*!
Returns true if this widget should be ignored by QtUiTest. If
a widget is ignored, any child widgets will still be processed.
The base implementation always returns false.
\sa {Query Paths}, {Querying Objects}
*/
bool QtUiTest::Widget::ignoreScan() const
{ return false; }
/*!
Returns true if this widget should not considered a possible
buddy for a label when resolving query paths.
Note that if the widget is returned as a buddy by
QtUiTest::Label::buddy() then this value will be ignored.
The base implementation always returns false.
\sa QtUiTest::Label::buddy(), {Query Paths}, {Querying Objects}
*/
bool QtUiTest::Widget::ignoreBuddy() const
{ return false; }
/*!
\fn void QtUiTest::Widget::gotFocus()
This signal is emitted when this widget gains focus by any means.
\sa QApplication::focusChanged()
*/
QVariant QtUiTest::Widget::getProperty(const QString&) const
{
return QVariant();
}
bool QtUiTest::Widget::setProperty(const QString&, const QVariant&)
{
return false;
}
/*!
\preliminary
\class QtUiTest::ActivateWidget
\inpublicgroup QtUiTestModule
\brief The ActivateWidget class provides an abstract base class
for all test widgets which can conceptually be "activated" by a user.
"Activation" occurs when user input causes an action, possibly
non-reversible, on a widget which exists solely for the purpose of
causing that action.
Examples of widgets suitable for this interface include QAbstractButton.
*/
/*!
\fn bool QtUiTest::ActivateWidget::activate()
Simulate the user input necessary to activate this widget.
Returns true if this widget was successfully activated.
For example, a button would reimplement this function to simulate
a click on itself, or to navigate to itself and hit the "Select" key.
*/
/*!
\fn void QtUiTest::ActivateWidget::activated()
This signal is emitted when this widget is activated.
*/
/*!
\preliminary
\class QtUiTest::LabelWidget
\inpublicgroup QtUiTestModule
\brief The LabelWidget class provides an abstract base class
for all test widgets which are conceptually labels.
Some widgets may act as labels for themselves while also providing
other functionality. For example, a button widget labels itself
and is also an ActivateWidget.
Examples of widgets suitable for this interface include QLabel.
*/
/*!
\fn QString QtUiTest::LabelWidget::labelText() const
Returns the text displayed on this label.
Most label widgets will also implement \l{QtUiTest::TextWidget}.
Most commonly, labelText() returns the same value as \l{QtUiTest::TextWidget::text()}.
*/
/*!
Returns the label's buddy widget, or 0 if this widget has no buddy.
The buddy-label relationship is used by QtUiTest as part of query path
resolution.
The returned object may be an actual QWidget, or may be a wrapping
test widget. Therefore, the only safe way to use the returned value
of this function is to cast it to the desired QtUiTest interface
using \l{QtUiTest}{qtuitest_cast}.
\sa QLabel::buddy(), {Query Paths}, {Querying Objects}
*/
QObject* QtUiTest::LabelWidget::buddy() const
{
return 0;
}
/*!
\preliminary
\class QtUiTest::CheckWidget
\inpublicgroup QtUiTestModule
\brief The CheckWidget class provides an abstract base class
for all test widgets which support 'checked' and 'unchecked' states.
QtUiTest::CheckWidget exposes the current check state of widgets
which can be checked or unchecked.
Examples of widgets suitable for this interface include QCheckBox
and QAbstractButton.
*/
/*!
Returns true if this widget has three possible states, i.e. the widget
can be in state Qt::PartiallyChecked.
The base implementation returns false.
\sa QCheckBox::isTristate()
*/
bool QtUiTest::CheckWidget::isTristate() const
{ return false; }
/*!
\fn Qt::CheckState QtUiTest::CheckWidget::checkState() const
Returns the current check state of this widget.
\sa QCheckBox::checkState(), setCheckState()
*/
/*!
Simulates the user input necessary to set the current check state
to \a state, returning true on success.
The default implementation does nothing and returns false.
\sa QCheckBox::setCheckState(), checkState()
*/
bool QtUiTest::CheckWidget::setCheckState(Qt::CheckState state)
{ Q_UNUSED(state); return false; }
/*!
\fn void QtUiTest::CheckWidget::stateChanged(int state)
This signal is emitted when the check state of this widget changes
to \a state. \a state is compatible with Qt::CheckState.
*/
/*!
\preliminary
\class QtUiTest::TextWidget
\inpublicgroup QtUiTestModule
\brief The TextWidget class provides an abstract base class
for all test widgets which display text to the user.
The QtUiTest::TextWidget interface should be implemented on any widget
which shows any text at all. This is the primary interface QtUiTest
uses to determine text->widget mappings, and it is used to implement
\l{QSystemTest::}{getText()}, a heavily used verification mechanism.
This interface is closely related to QtUiTest::InputWidget, which
provides an interface for entering text into a widget. Any widgets
which contain user-editable text will typically implement both
QtUiTest::InputWidget and QtUiTest::TextWidget.
Examples of widgets suitable for this interface include QLabel,
QAbstractButton, QLineEdit, QTextEdit and many more.
\sa QtUiTest::InputWidget
*/
/*!
Returns the text in this widget which is currently selected / highlighted.
If the widget does not support the concept of selected text, this function
should return the same as text().
The base implementation calls text().
\sa QLineEdit::selectedText()
*/
QString QtUiTest::TextWidget::selectedText() const
{ return text(); }
/*!
Returns the value in this widget which is currently selected / highlighted.
If the widget does not support the concept of a selected value, this function
should return the same as value().
The base implementation calls selectedText().
*/
QVariant QtUiTest::TextWidget::selectedValue() const
{ return selectedText(); }
/*!
\fn QString QtUiTest::TextWidget::text() const
Returns all of the text this widget is currently presenting to the user.
*/
/*!
Returns the value this widget is currently presenting to the user.
The returned value will be of whatever type is most appropriate for this widget.
For example, a QLineEdit would return a literal copy of its text (giving the same
result as the text() function), while a QTimeEdit may return a QTime.
*/
QVariant QtUiTest::TextWidget::value() const
{ return text(); }
/*!
\preliminary
\class QtUiTest::ListWidget
\inpublicgroup QtUiTestModule
\brief The ListWidget class provides an abstract base class
for all test widgets which display a list of items to the user.
QtUiTest::ListWidget allows a widget which is conceptually a list to
be enumerated. This is closely related to QtUiTest::SelectWidget,
which may be implemented to allow a user to select an item from a list.
Examples of widgets suitable for this interface include QAbstractItemView,
QComboBox and QMenu.
\sa QtUiTest::SelectWidget
*/
/*!
\fn QStringList QtUiTest::ListWidget::list() const
Returns a list containing a text representation of each item in this list
widget.
*/
/*!
\fn QRect QtUiTest::ListWidget::visualRect(const QString& item) const
Returns the bounding rect of \a item, in widget coordinates.
If \a item isn't currently shown in this widget, returns a null rect.
\sa QAbstractItemView::visualRect()
*/
/*!
Simulates the user input necessary to navigate this widget until \a item
is currently visible and return true on success.
For example, in a QAbstractItemView with vertical scrollbars, if \a item
exists further down the list than currently shown, this function might
simulate 'Down' key clicks until it becomes visible.
The base implementation does nothing and returns true.
*/
bool QtUiTest::ListWidget::ensureVisible(const QString& item)
{ Q_UNUSED(item); return true; }
/*!
\preliminary
\class QtUiTest::InputWidget
\inpublicgroup QtUiTestModule
\brief The InputWidget class provides an abstract base class
for all test widgets which allow the user to input text.
QtUiTest::InputWidget encapsulates a widget in which a user may enter
and remove text. This is closely related to QtUiTest::TextWidget, which
provides an interface for retrieving text from a widget. Any widgets
which contain user-editable text will typically implement both
QtUiTest::InputWidget and QtUiTest::TextWidget.
Examples of widgets suitable for this interface include QLineEdit and
QTextEdit.
\sa QtUiTest::TextWidget
*/
/*!
\fn bool QtUiTest::InputWidget::canEnter(const QVariant& item) const
Returns true if \a item can possibly be entered into this widget.
For example, for a QLineEdit, QLineEdit::validator() would be used to
ensure that \l{QVariant::toString()}{item.toString()} constitutes
valid input for this line edit.
*/
/*!
\fn bool QtUiTest::InputWidget::enter(const QVariant& item, bool noCommit)
Simulates the user input necessary to enter \a item into this widget.
Returns true on success.
\a item can potentially be any type representable in a QVariant.
Most widgets will only be interested in text, in which case
\l{QVariant::toString()}{item.toString()} can be called to retrieve
a string. Examples of widgets which may handle types other than text
are QDateEdit and QTimeEdit, which may handle dates and times.
If \a noCommit is true, no attempt is made to commit the input (for example,
by clicking the Select key). Normally this value will be false, which will
result in the input being committed. This value is not applicable to all
widget types.
If canEnter() returns true and this function returns false, an error
has occurred and this widget is left in an undefined state.
*/
/*!
Returns the input proxy of this widget, or 0 if this widget has no input proxy.
The input proxy is an object that receives input on behalf of the widget (for
example, an input method). It must be cast to the desired QtUiTest interface
using \l{QtUiTest}{qtuitest_cast}.
*/
QObject* QtUiTest::InputWidget::inputProxy() const
{
return 0;
}
/*!
\fn void QtUiTest::InputWidget::entered(const QVariant& item)
This signal is emitted when \a item is entered into the widget
by the user.
*/
/*!
\preliminary
\class QtUiTest::SelectWidget
\inpublicgroup QtUiTestModule
\brief The SelectWidget class provides an abstract base class
for all test widgets which allow the user to select from a range of items.
QtUiTest::SelectWidget encapsulates a widget which provides the user
with a choice from a (possibly unlimited) range. This is closely related
to QtUiTest::ListWidget, which may be implemented to allow a user to
enumerate all items from a list.
Examples of widgets suitable for this interface include QAbstractItemView,
QComboBox and QMenu.
\sa QtUiTest::ListWidget
*/
/*!
Returns true if this widget supports the selection of multiple items at
the same time.
The base implementation returns false.
*/
bool QtUiTest::SelectWidget::isMultiSelection() const
{ return false; }
/*!
\fn bool QtUiTest::SelectWidget::canSelect(const QString& item) const
Returns true if \a item can possibly be selected from this widget.
*/
/*!
Returns true if all of the given \a items can be selected from this widget
at the same time.
The base implementation returns true if isMultiSelection() returns true
and canSelect() returns true for every item in \a items.
*/
bool QtUiTest::SelectWidget::canSelectMulti(const QStringList& items) const
{
if (!isMultiSelection()) return false;
foreach (QString item, items)
if (!canSelect(item)) return false;
return true;
}
/*!
\fn bool QtUiTest::SelectWidget::select(const QString& item)
Simulates the user input necessary to select \a item from this widget.
Returns true if \a item was successfully selected.
If canSelect() returns true and this function returns false, an error
has occurred and this widget's state is undefined.
*/
/*!
Simulates the user input necessary to select all \a items from this widget
at the same time.
Returns true if \a items were all successfully selected.
If canSelectMulti() returns true and this function returns false, an error
has occurred and this widget's state is undefined.
The base implementation calls canSelectMulti() to check if \a items can
be selected, then calls select() on each item in \a items.
*/
bool QtUiTest::SelectWidget::selectMulti(const QStringList& items)
{
if (!canSelectMulti(items)) return false;
foreach (QString item, items)
if (!select(item)) return false;
return true;
}
/*!
\fn void QtUiTest::SelectWidget::selected(const QString& item)
This signal is emitted when \a item is selected from this widget.
*/
/*!
\preliminary
\class QtUiTest::CheckItemWidget
\inpublicgroup QtUiTestModule
\brief The CheckItemWidget class provides an abstract base class for all
test widgets which include items that support 'checked' and 'unchecked' states.
Examples of widgets suitable for this interface include QMenu.
*/
/*!
Returns true if \a item can be checked (has a selectable on/off state).
*/
bool QtUiTest::CheckItemWidget::isCheckable(const QString& item)
{ Q_UNUSED(item); return false; }
/*!
\fn bool QtUiTest::CheckItemWidget::isChecked(const QString& item)
Returns the check state of the \a item specified.
*/
/*!
\fn bool QtUiTest::CheckItemWidget::setChecked(const QString& item, bool state)
Set the check state of the \a item. Returns false if the check state cannot be set.
*/
/*!
\preliminary
\class QtUiTest::IndexedWidget
\inpublicgroup QtUiTestModule
\brief The IndexedWidget class provides an abstract base class
for all test widgets which allow the user to select items based on index.
Examples of widgets suitable for this interface include QAbstractItemView.
\sa QtUiTest::ListWidget, QtUiTest::SelectWidget
*/
/*!
Selects the item with the specified \a index from an item view. The index should
be specified in QtScript as an array, in the form [parentRow, parentColumn, ..., row, column].
This function can be used in situations where \l{QSystemTest::}{select()} would be inappropriate,
typically in larger, more complex item views or those containing items with duplicate names.
\code
// Select row 3, column 5 from tableView
selectIndex([3, 5], tableView);
// Select row 2, column 4 beneath parent item at row 1, column 0 from treeView
selectIndex([1, 0, 2, 4], treeView);
\endcode
\sa select(), selectedIndex()
*/
bool QtUiTest::IndexedWidget::selectIndex(const QVariantList& index)
{
Q_UNUSED(index);
return false;
}
/*!
Returns the index of the item currently selected in an item view. This is returned
as a QVariantList, as required by selectIndex().
\sa selectIndex()
*/
QVariantList QtUiTest::IndexedWidget::selectedIndex() const
{
return QVariantList();
}
|