author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
#include <QtTest/QtTest> |
|
43 |
||
44 |
#include "qcombobox.h" |
|
45 |
#include <private/qcombobox_p.h> |
|
46 |
||
47 |
#include <qfontcombobox.h> |
|
48 |
#include <qdesktopwidget.h> |
|
49 |
#include <qapplication.h> |
|
50 |
#include <qpushbutton.h> |
|
51 |
#include <qdialog.h> |
|
52 |
#include <qevent.h> |
|
53 |
#include <qlineedit.h> |
|
54 |
#include <qlistview.h> |
|
55 |
#include <qheaderview.h> |
|
56 |
#include <qlistwidget.h> |
|
57 |
#include <qtreewidget.h> |
|
58 |
#include <qtablewidget.h> |
|
59 |
#include <qscrollbar.h> |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
60 |
#include <qboxlayout.h> |
0 | 61 |
#ifdef Q_WS_MAC |
62 |
#include <qmacstyle_mac.h> |
|
63 |
#elif defined Q_WS_X11 |
|
64 |
#include <private/qt_x11_p.h> |
|
65 |
#endif |
|
66 |
||
67 |
#include <qstandarditemmodel.h> |
|
68 |
#include <qstringlistmodel.h> |
|
69 |
#include <qcombobox.h> |
|
70 |
#include <qpushbutton.h> |
|
71 |
#include <qdialog.h> |
|
72 |
#include <qstringlist.h> |
|
73 |
#include <qvalidator.h> |
|
74 |
#include <qcompleter.h> |
|
75 |
#ifndef QT_NO_STYLE_CLEANLOOKS |
|
76 |
#include <qcleanlooksstyle.h> |
|
77 |
#endif |
|
78 |
#include <qabstractitemview.h> |
|
79 |
#include "../../shared/util.h" |
|
80 |
#include <qstyleditemdelegate.h> |
|
81 |
#ifndef QT_NO_STYLE_WINDOWS |
|
82 |
#include <qwindowsstyle.h> |
|
83 |
#endif |
|
84 |
||
85 |
//TESTED_CLASS= |
|
86 |
//TESTED_FILES= |
|
87 |
||
88 |
class tst_QComboBox : public QObject |
|
89 |
{ |
|
90 |
Q_OBJECT |
|
91 |
||
92 |
public: |
|
93 |
tst_QComboBox(); |
|
94 |
~tst_QComboBox(); |
|
95 |
||
96 |
public slots: |
|
97 |
void initTestCase(); |
|
98 |
void cleanupTestCase(); |
|
99 |
void init(); |
|
100 |
void cleanup(); |
|
101 |
||
102 |
private slots: |
|
103 |
void getSetCheck(); |
|
104 |
void ensureReturnIsIgnored(); |
|
105 |
void setEditable(); |
|
106 |
void setPalette(); |
|
107 |
void sizeAdjustPolicy(); |
|
108 |
void clear(); |
|
109 |
void insertPolicy_data(); |
|
110 |
void insertPolicy(); |
|
111 |
void virtualAutocompletion(); |
|
112 |
void autoCompletionCaseSensitivity(); |
|
113 |
void hide(); |
|
114 |
void currentIndex_data(); |
|
115 |
void currentIndex(); |
|
116 |
void insertItems_data(); |
|
117 |
void insertItems(); |
|
118 |
void insertItem_data(); |
|
119 |
void insertItem(); |
|
120 |
void insertOnCurrentIndex(); |
|
121 |
void textpixmapdata_data(); |
|
122 |
void textpixmapdata(); |
|
123 |
void editTextChanged(); |
|
124 |
void setModel(); |
|
125 |
void modelDeleted(); |
|
126 |
void setMaxCount(); |
|
127 |
void setCurrentIndex(); |
|
128 |
void convenienceViews(); |
|
129 |
void findText_data(); |
|
130 |
void findText(); |
|
131 |
void flaggedItems_data(); |
|
132 |
void flaggedItems(); |
|
133 |
void pixmapIcon(); |
|
134 |
void mouseWheel_data(); |
|
135 |
void mouseWheel(); |
|
136 |
void layoutDirection(); |
|
137 |
void itemListPosition(); |
|
138 |
void separatorItem_data(); |
|
139 |
void separatorItem(); |
|
140 |
void task190351_layout(); |
|
141 |
void task191329_size(); |
|
142 |
void task166349_setEditableOnReturn(); |
|
143 |
void task190205_setModelAdjustToContents(); |
|
144 |
void task248169_popupWithMinimalSize(); |
|
145 |
void task247863_keyBoardSelection(); |
|
146 |
void task220195_keyBoardSelection2(); |
|
147 |
void setModelColumn(); |
|
148 |
void noScrollbar_data(); |
|
149 |
void noScrollbar(); |
|
150 |
void setItemDelegate(); |
|
151 |
void task253944_itemDelegateIsReset(); |
|
152 |
void subControlRectsWithOffset_data(); |
|
153 |
void subControlRectsWithOffset(); |
|
154 |
void task260974_menuItemRectangleForComboBoxPopup(); |
|
155 |
void removeItem(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
void resetModel(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
157 |
void keyBoardNavigationWithMouse(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
158 |
void task_QTBUG_1071_changingFocusEmitsActivated(); |
0 | 159 |
|
160 |
protected slots: |
|
161 |
void onEditTextChanged( const QString &newString ); |
|
162 |
||
163 |
private: |
|
164 |
QComboBox *testWidget; |
|
165 |
QDialog *parent; |
|
166 |
QPushButton* ok; |
|
167 |
int editTextCount; |
|
168 |
QString editText; |
|
169 |
}; |
|
170 |
||
171 |
class MyAbstractItemDelegate : public QAbstractItemDelegate |
|
172 |
{ |
|
173 |
public: |
|
174 |
MyAbstractItemDelegate() : QAbstractItemDelegate() {}; |
|
175 |
void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const {} |
|
176 |
QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const { return QSize(); } |
|
177 |
}; |
|
178 |
||
179 |
class MyAbstractItemModel: public QAbstractItemModel |
|
180 |
{ |
|
181 |
public: |
|
182 |
MyAbstractItemModel() : QAbstractItemModel() {}; |
|
183 |
QModelIndex index(int, int, const QModelIndex &) const { return QModelIndex(); } |
|
184 |
QModelIndex parent(const QModelIndex &) const { return QModelIndex(); } |
|
185 |
int rowCount(const QModelIndex &) const { return 0; } |
|
186 |
int columnCount(const QModelIndex &) const { return 0; } |
|
187 |
bool hasChildren(const QModelIndex &) const { return false; } |
|
188 |
QVariant data(const QModelIndex &, int) const { return QVariant(); } |
|
189 |
bool setData(const QModelIndex &, const QVariant &, int) { return false; } |
|
190 |
bool insertRows(int, int, const QModelIndex &) { return false; } |
|
191 |
bool insertColumns(int, int, const QModelIndex &) { return false; } |
|
192 |
void setPersistent(const QModelIndex &, const QModelIndex &) {} |
|
193 |
bool removeRows (int, int, const QModelIndex &) { return false; } |
|
194 |
bool removeColumns(int, int, const QModelIndex &) { return false; } |
|
195 |
void reset() {} |
|
196 |
}; |
|
197 |
||
198 |
class MyAbstractItemView : public QAbstractItemView |
|
199 |
{ |
|
200 |
public: |
|
201 |
MyAbstractItemView() : QAbstractItemView() {} |
|
202 |
QRect visualRect(const QModelIndex &) const { return QRect(); } |
|
203 |
void scrollTo(const QModelIndex &, ScrollHint) {} |
|
204 |
QModelIndex indexAt(const QPoint &) const { return QModelIndex(); } |
|
205 |
protected: |
|
206 |
QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers) { return QModelIndex(); } |
|
207 |
int horizontalOffset() const { return 0; } |
|
208 |
int verticalOffset() const { return 0; } |
|
209 |
bool isIndexHidden(const QModelIndex &) const { return false; } |
|
210 |
void setSelection(const QRect &, QItemSelectionModel::SelectionFlags) {} |
|
211 |
QRegion visualRegionForSelection(const QItemSelection &) const { return QRegion(); } |
|
212 |
}; |
|
213 |
||
214 |
// Testing get/set functions |
|
215 |
void tst_QComboBox::getSetCheck() |
|
216 |
{ |
|
217 |
QComboBox obj1; |
|
218 |
// int QComboBox::maxVisibleItems() |
|
219 |
// void QComboBox::setMaxVisibleItems(int) |
|
220 |
obj1.setMaxVisibleItems(100); |
|
221 |
QCOMPARE(100, obj1.maxVisibleItems()); |
|
222 |
obj1.setMaxVisibleItems(0); |
|
223 |
QCOMPARE(obj1.maxVisibleItems(), 0); |
|
224 |
QTest::ignoreMessage(QtWarningMsg, "QComboBox::setMaxVisibleItems: " |
|
225 |
"Invalid max visible items (-2147483648) must be >= 0"); |
|
226 |
obj1.setMaxVisibleItems(INT_MIN); |
|
227 |
QCOMPARE(obj1.maxVisibleItems(), 0); // Cannot be set to something negative => old value |
|
228 |
obj1.setMaxVisibleItems(INT_MAX); |
|
229 |
QCOMPARE(INT_MAX, obj1.maxVisibleItems()); |
|
230 |
||
231 |
// int QComboBox::maxCount() |
|
232 |
// void QComboBox::setMaxCount(int) |
|
233 |
obj1.setMaxCount(0); |
|
234 |
QCOMPARE(0, obj1.maxCount()); |
|
235 |
#ifndef QT_DEBUG |
|
236 |
QTest::ignoreMessage(QtWarningMsg, "QComboBox::setMaxCount: Invalid count (-2147483648) must be >= 0"); |
|
237 |
obj1.setMaxCount(INT_MIN); |
|
238 |
QCOMPARE(0, obj1.maxCount()); // Setting a value below 0 makes no sense, and shouldn't be allowed |
|
239 |
#endif |
|
240 |
obj1.setMaxCount(INT_MAX); |
|
241 |
QCOMPARE(INT_MAX, obj1.maxCount()); |
|
242 |
||
243 |
// bool QComboBox::autoCompletion() |
|
244 |
// void QComboBox::setAutoCompletion(bool) |
|
245 |
obj1.setAutoCompletion(false); |
|
246 |
QCOMPARE(false, obj1.autoCompletion()); |
|
247 |
obj1.setAutoCompletion(true); |
|
248 |
QCOMPARE(true, obj1.autoCompletion()); |
|
249 |
||
250 |
// bool QComboBox::duplicatesEnabled() |
|
251 |
// void QComboBox::setDuplicatesEnabled(bool) |
|
252 |
obj1.setDuplicatesEnabled(false); |
|
253 |
QCOMPARE(false, obj1.duplicatesEnabled()); |
|
254 |
obj1.setDuplicatesEnabled(true); |
|
255 |
QCOMPARE(true, obj1.duplicatesEnabled()); |
|
256 |
||
257 |
// InsertPolicy QComboBox::insertPolicy() |
|
258 |
// void QComboBox::setInsertPolicy(InsertPolicy) |
|
259 |
obj1.setInsertPolicy(QComboBox::InsertPolicy(QComboBox::NoInsert)); |
|
260 |
QCOMPARE(QComboBox::InsertPolicy(QComboBox::NoInsert), obj1.insertPolicy()); |
|
261 |
obj1.setInsertPolicy(QComboBox::InsertPolicy(QComboBox::InsertAtTop)); |
|
262 |
QCOMPARE(QComboBox::InsertPolicy(QComboBox::InsertAtTop), obj1.insertPolicy()); |
|
263 |
obj1.setInsertPolicy(QComboBox::InsertPolicy(QComboBox::InsertAtCurrent)); |
|
264 |
QCOMPARE(QComboBox::InsertPolicy(QComboBox::InsertAtCurrent), obj1.insertPolicy()); |
|
265 |
obj1.setInsertPolicy(QComboBox::InsertPolicy(QComboBox::InsertAtBottom)); |
|
266 |
QCOMPARE(QComboBox::InsertPolicy(QComboBox::InsertAtBottom), obj1.insertPolicy()); |
|
267 |
obj1.setInsertPolicy(QComboBox::InsertPolicy(QComboBox::InsertAfterCurrent)); |
|
268 |
QCOMPARE(QComboBox::InsertPolicy(QComboBox::InsertAfterCurrent), obj1.insertPolicy()); |
|
269 |
obj1.setInsertPolicy(QComboBox::InsertPolicy(QComboBox::InsertBeforeCurrent)); |
|
270 |
QCOMPARE(QComboBox::InsertPolicy(QComboBox::InsertBeforeCurrent), obj1.insertPolicy()); |
|
271 |
obj1.setInsertPolicy(QComboBox::InsertPolicy(QComboBox::InsertAlphabetically)); |
|
272 |
QCOMPARE(QComboBox::InsertPolicy(QComboBox::InsertAlphabetically), obj1.insertPolicy()); |
|
273 |
||
274 |
// SizeAdjustPolicy QComboBox::sizeAdjustPolicy() |
|
275 |
// void QComboBox::setSizeAdjustPolicy(SizeAdjustPolicy) |
|
276 |
obj1.setSizeAdjustPolicy(QComboBox::SizeAdjustPolicy(QComboBox::AdjustToContents)); |
|
277 |
QCOMPARE(QComboBox::SizeAdjustPolicy(QComboBox::AdjustToContents), obj1.sizeAdjustPolicy()); |
|
278 |
obj1.setSizeAdjustPolicy(QComboBox::SizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow)); |
|
279 |
QCOMPARE(QComboBox::SizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow), obj1.sizeAdjustPolicy()); |
|
280 |
obj1.setSizeAdjustPolicy(QComboBox::SizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength)); |
|
281 |
QCOMPARE(QComboBox::SizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength), obj1.sizeAdjustPolicy()); |
|
282 |
obj1.setSizeAdjustPolicy(QComboBox::SizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon)); |
|
283 |
QCOMPARE(QComboBox::SizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon), obj1.sizeAdjustPolicy()); |
|
284 |
||
285 |
// int QComboBox::minimumContentsLength() |
|
286 |
// void QComboBox::setMinimumContentsLength(int) |
|
287 |
obj1.setMinimumContentsLength(0); |
|
288 |
QCOMPARE(0, obj1.minimumContentsLength()); |
|
289 |
obj1.setMinimumContentsLength(100); |
|
290 |
QCOMPARE(100, obj1.minimumContentsLength()); |
|
291 |
obj1.setMinimumContentsLength(INT_MIN); |
|
292 |
QCOMPARE(100, obj1.minimumContentsLength()); // Cannot be set to something negative => old value |
|
293 |
obj1.setMinimumContentsLength(INT_MAX); |
|
294 |
QCOMPARE(INT_MAX, obj1.minimumContentsLength()); |
|
295 |
||
296 |
// QLineEdit * QComboBox::lineEdit() |
|
297 |
// void QComboBox::setLineEdit(QLineEdit *) |
|
298 |
QLineEdit *var8 = new QLineEdit(0); |
|
299 |
obj1.setLineEdit(var8); |
|
300 |
QCOMPARE(var8, obj1.lineEdit()); |
|
301 |
QTest::ignoreMessage(QtWarningMsg, "QComboBox::setLineEdit: cannot set a 0 line edit"); |
|
302 |
obj1.setLineEdit((QLineEdit *)0); |
|
303 |
QCOMPARE(var8, obj1.lineEdit()); |
|
304 |
// delete var8; // No delete, since QComboBox takes ownership |
|
305 |
||
306 |
// const QValidator * QComboBox::validator() |
|
307 |
// void QComboBox::setValidator(const QValidator *) |
|
308 |
QIntValidator *var9 = new QIntValidator(0); |
|
309 |
obj1.setValidator(var9); |
|
310 |
QCOMPARE(obj1.validator(), (const QValidator *)var9); |
|
311 |
obj1.setValidator((QValidator *)0); |
|
312 |
QCOMPARE(obj1.validator(), (const QValidator *)0); |
|
313 |
delete var9; |
|
314 |
||
315 |
// QAbstractItemDelegate * QComboBox::itemDelegate() |
|
316 |
// void QComboBox::setItemDelegate(QAbstractItemDelegate *) |
|
317 |
MyAbstractItemDelegate *var10 = new MyAbstractItemDelegate; |
|
318 |
obj1.setItemDelegate(var10); |
|
319 |
QCOMPARE(obj1.itemDelegate(), (QAbstractItemDelegate *)var10); |
|
320 |
QTest::ignoreMessage(QtWarningMsg, "QComboBox::setItemDelegate: cannot set a 0 delegate"); |
|
321 |
obj1.setItemDelegate((QAbstractItemDelegate *)0); |
|
322 |
QCOMPARE(obj1.itemDelegate(), (QAbstractItemDelegate *)var10); |
|
323 |
// delete var10; // No delete, since QComboBox takes ownership |
|
324 |
||
325 |
// QAbstractItemModel * QComboBox::model() |
|
326 |
// void QComboBox::setModel(QAbstractItemModel *) |
|
327 |
MyAbstractItemModel *var11 = new MyAbstractItemModel; |
|
328 |
obj1.setModel(var11); |
|
329 |
QCOMPARE(obj1.model(), (QAbstractItemModel *)var11); |
|
330 |
QTest::ignoreMessage(QtWarningMsg, "QComboBox::setModel: cannot set a 0 model"); |
|
331 |
obj1.setModel((QAbstractItemModel *)0); |
|
332 |
QCOMPARE(obj1.model(), (QAbstractItemModel *)var11); |
|
333 |
delete var11; |
|
334 |
obj1.model(); |
|
335 |
||
336 |
// int QComboBox::modelColumn() |
|
337 |
// void QComboBox::setModelColumn(int) |
|
338 |
obj1.setModelColumn(0); |
|
339 |
QCOMPARE(0, obj1.modelColumn()); |
|
340 |
obj1.setModelColumn(INT_MIN); |
|
341 |
// QCOMPARE(0, obj1.modelColumn()); // Cannot be set to something negative => column 0 |
|
342 |
obj1.setModelColumn(INT_MAX); |
|
343 |
QCOMPARE(INT_MAX, obj1.modelColumn()); |
|
344 |
obj1.setModelColumn(0); // back to normal |
|
345 |
||
346 |
// QAbstractItemView * QComboBox::view() |
|
347 |
// void QComboBox::setView(QAbstractItemView *) |
|
348 |
MyAbstractItemView *var13 = new MyAbstractItemView; |
|
349 |
obj1.setView(var13); |
|
350 |
QCOMPARE(obj1.view(), (QAbstractItemView *)var13); |
|
351 |
QTest::ignoreMessage(QtWarningMsg, "QComboBox::setView: cannot set a 0 view"); |
|
352 |
obj1.setView((QAbstractItemView *)0); |
|
353 |
QCOMPARE(obj1.view(), (QAbstractItemView *)var13); |
|
354 |
delete var13; |
|
355 |
||
356 |
// int QComboBox::currentIndex() |
|
357 |
// void QComboBox::setCurrentIndex(int) |
|
358 |
obj1.setEditable(false); |
|
359 |
obj1.setCurrentIndex(0); |
|
360 |
QCOMPARE(-1, obj1.currentIndex()); |
|
361 |
obj1.setCurrentIndex(INT_MIN); |
|
362 |
QCOMPARE(-1, obj1.currentIndex()); |
|
363 |
obj1.setCurrentIndex(INT_MAX); |
|
364 |
QCOMPARE(-1, obj1.currentIndex()); |
|
365 |
obj1.addItems(QStringList() << "1" << "2" << "3" << "4" << "5"); |
|
366 |
obj1.setCurrentIndex(0); |
|
367 |
QCOMPARE(0, obj1.currentIndex()); // Valid |
|
368 |
obj1.setCurrentIndex(INT_MIN); |
|
369 |
QCOMPARE(-1, obj1.currentIndex()); // Invalid => -1 |
|
370 |
obj1.setCurrentIndex(4); |
|
371 |
QCOMPARE(4, obj1.currentIndex()); // Valid |
|
372 |
obj1.setCurrentIndex(INT_MAX); |
|
373 |
QCOMPARE(-1, obj1.currentIndex()); // Invalid => -1 |
|
374 |
} |
|
375 |
||
376 |
typedef QList<QVariant> VariantList; |
|
377 |
typedef QList<QIcon> IconList; |
|
378 |
||
379 |
Q_DECLARE_METATYPE(VariantList) |
|
380 |
Q_DECLARE_METATYPE(IconList) |
|
381 |
Q_DECLARE_METATYPE(QComboBox::InsertPolicy) |
|
382 |
||
383 |
tst_QComboBox::tst_QComboBox() |
|
384 |
{ |
|
385 |
qRegisterMetaType<QModelIndex>("QModelIndex"); |
|
386 |
parent = 0; |
|
387 |
} |
|
388 |
||
389 |
tst_QComboBox::~tst_QComboBox() |
|
390 |
{ |
|
391 |
} |
|
392 |
||
393 |
||
394 |
void tst_QComboBox::initTestCase() |
|
395 |
{ |
|
396 |
// Create the test class |
|
397 |
parent = new QDialog(0); |
|
398 |
parent->setObjectName("parent"); |
|
399 |
parent->resize(400, 400); |
|
400 |
testWidget = new QComboBox(parent); |
|
401 |
testWidget->setObjectName("testObject"); |
|
402 |
testWidget->setGeometry(0, 0, 100, 100); |
|
403 |
editTextCount = 0; |
|
404 |
editText.clear(); |
|
405 |
connect(testWidget, SIGNAL(editTextChanged(const QString&)), |
|
406 |
this, SLOT(onEditTextChanged(const QString&))); |
|
407 |
parent->show(); |
|
408 |
} |
|
409 |
||
410 |
void tst_QComboBox::cleanupTestCase() |
|
411 |
{ |
|
412 |
delete parent; |
|
413 |
parent = 0; |
|
414 |
} |
|
415 |
||
416 |
||
417 |
void tst_QComboBox::init() |
|
418 |
{ |
|
419 |
// all tests starts with a clean non-editable combobox |
|
420 |
testWidget->setEditable(false); |
|
421 |
testWidget->clear(); |
|
422 |
#ifdef Q_OS_WINCE //disable magic for WindowsCE |
|
423 |
qApp->setAutoMaximizeThreshold(-1); |
|
424 |
#endif |
|
425 |
} |
|
426 |
||
427 |
void tst_QComboBox::cleanup() |
|
428 |
{ |
|
429 |
//nothing |
|
430 |
} |
|
431 |
||
432 |
||
433 |
void tst_QComboBox::setEditable() |
|
434 |
{ |
|
435 |
// make sure we have no lineedit |
|
436 |
QVERIFY(!testWidget->lineEdit()); |
|
437 |
// test setEditable(true) |
|
438 |
testWidget->setEditable(true); |
|
439 |
QVERIFY(testWidget->lineEdit()); |
|
440 |
testWidget->addItem("foo"); |
|
441 |
QCOMPARE(testWidget->lineEdit()->text(), QString("foo")); |
|
442 |
// test setEditable(false) |
|
443 |
||
444 |
QLineEdit *lineEdit = testWidget->lineEdit(); |
|
445 |
// line edit is visible when combobox is editable |
|
446 |
QVERIFY(lineEdit->isVisible()); |
|
447 |
testWidget->setEditable(false); |
|
448 |
QVERIFY(!testWidget->lineEdit()); |
|
449 |
// line edit should have been explicitly hidden when editable was turned off |
|
450 |
QVERIFY(!lineEdit->isVisible()); |
|
451 |
} |
|
452 |
||
453 |
||
454 |
void tst_QComboBox::setPalette() |
|
455 |
{ |
|
456 |
#ifdef Q_WS_MAC |
|
457 |
if (qobject_cast<QMacStyle *>(testWidget->style())) { |
|
458 |
QSKIP("This test doesn't make sense for pixmap-based styles", SkipAll); |
|
459 |
} |
|
460 |
#endif |
|
461 |
QPalette pal = testWidget->palette(); |
|
462 |
pal.setColor(QPalette::Base, Qt::red); |
|
463 |
testWidget->setPalette(pal); |
|
464 |
testWidget->setEditable(!testWidget->isEditable()); |
|
465 |
||
466 |
pal.setColor(QPalette::Base, Qt::blue); |
|
467 |
testWidget->setPalette(pal); |
|
468 |
||
469 |
const QObjectList comboChildren = testWidget->children(); |
|
470 |
for (int i = 0; i < comboChildren.size(); ++i) { |
|
471 |
QObject *o = comboChildren.at(i); |
|
472 |
if (o->isWidgetType()) { |
|
473 |
QVERIFY(((QWidget*)o)->palette() == pal); |
|
474 |
} |
|
475 |
} |
|
476 |
} |
|
477 |
||
478 |
void tst_QComboBox::sizeAdjustPolicy() |
|
479 |
{ |
|
480 |
// test that adding new items will not change the sizehint for AdjustToContentsOnFirstShow |
|
481 |
QVERIFY(!testWidget->count()); |
|
482 |
QVERIFY(testWidget->sizeAdjustPolicy() == QComboBox::AdjustToContentsOnFirstShow); |
|
483 |
QVERIFY(testWidget->isVisible()); |
|
484 |
QSize firstShow = testWidget->sizeHint(); |
|
485 |
testWidget->addItem("normal item"); |
|
486 |
QCOMPARE(testWidget->sizeHint(), firstShow); |
|
487 |
||
488 |
// check that with minimumContentsLength/AdjustToMinimumContentsLength sizehint changes |
|
489 |
testWidget->setMinimumContentsLength(30); |
|
490 |
QCOMPARE(testWidget->sizeHint(), firstShow); |
|
491 |
testWidget->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength); |
|
492 |
QSize minimumContentsLength = testWidget->sizeHint(); |
|
493 |
QVERIFY(minimumContentsLength.width() > firstShow.width()); |
|
494 |
testWidget->setMinimumContentsLength(60); |
|
495 |
QVERIFY(minimumContentsLength.width() < testWidget->sizeHint().width()); |
|
496 |
||
497 |
// check that with minimumContentsLength/AdjustToMinimumContentsLengthWithIcon sizehint changes |
|
498 |
testWidget->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon); |
|
499 |
testWidget->setMinimumContentsLength(30); |
|
500 |
minimumContentsLength = testWidget->sizeHint(); |
|
501 |
QVERIFY(minimumContentsLength.width() > firstShow.width()); |
|
502 |
testWidget->setMinimumContentsLength(60); |
|
503 |
QVERIFY(minimumContentsLength.width() < testWidget->sizeHint().width()); |
|
504 |
minimumContentsLength = testWidget->sizeHint(); |
|
505 |
testWidget->setIconSize(QSize(128,128)); |
|
506 |
QVERIFY(minimumContentsLength.width() < testWidget->sizeHint().width()); |
|
507 |
||
508 |
// check AdjustToContents changes with content |
|
509 |
testWidget->setSizeAdjustPolicy(QComboBox::AdjustToContents); |
|
510 |
QSize content = testWidget->sizeHint(); |
|
511 |
testWidget->addItem("small"); |
|
512 |
QCOMPARE(testWidget->sizeHint(), content); |
|
513 |
testWidget->addItem("looooooooooooooooooooooong item"); |
|
514 |
// minimumContentsLength() > sizeof("looooooooooooooooooooooong item"), so the sizeHint() |
|
515 |
// stays the same |
|
516 |
QCOMPARE(testWidget->sizeHint(), content); |
|
517 |
// over 60 characters (cf. setMinimumContentsLength() call above) |
|
518 |
testWidget->addItem("loooooooooooooooooooooooooooooooooooooooooooooo" |
|
519 |
"ooooooooooooooooooooooooooooooooooooooooooooooo" |
|
520 |
"ooooooooooooooooooooooooooooong item"); |
|
521 |
QVERIFY(testWidget->sizeHint().width() > content.width()); |
|
522 |
||
523 |
// check AdjustToContents also shrinks when item changes |
|
524 |
content = testWidget->sizeHint(); |
|
525 |
for (int i=0; i<testWidget->count(); ++i) |
|
526 |
testWidget->setItemText(i, "XXXXXXXXXX"); |
|
527 |
QVERIFY(testWidget->sizeHint().width() < content.width()); |
|
528 |
||
529 |
// check AdjustToContents shrinks when items are removed |
|
530 |
content = testWidget->sizeHint(); |
|
531 |
while (testWidget->count()) |
|
532 |
testWidget->removeItem(0); |
|
533 |
QCOMPARE(testWidget->sizeHint(), content); |
|
534 |
testWidget->setMinimumContentsLength(0); |
|
535 |
QVERIFY(testWidget->sizeHint().width() < content.width()); |
|
536 |
} |
|
537 |
||
538 |
void tst_QComboBox::clear() |
|
539 |
{ |
|
540 |
// first non editable combobox |
|
541 |
testWidget->addItem("foo"); |
|
542 |
testWidget->addItem("bar"); |
|
543 |
QVERIFY(testWidget->count() > 0); |
|
544 |
QCOMPARE(testWidget->currentIndex(), 0); |
|
545 |
||
546 |
testWidget->clear(); |
|
547 |
QCOMPARE(testWidget->count(), 0); |
|
548 |
QCOMPARE(testWidget->currentIndex(), -1); |
|
549 |
QVERIFY(testWidget->currentText().isEmpty()); |
|
550 |
||
551 |
// then editable combobox |
|
552 |
testWidget->clear(); |
|
553 |
testWidget->setEditable(true); |
|
554 |
testWidget->addItem("foo"); |
|
555 |
testWidget->addItem("bar"); |
|
556 |
QVERIFY(testWidget->count() > 0); |
|
557 |
QCOMPARE(testWidget->currentIndex(), 0); |
|
558 |
QVERIFY(testWidget->lineEdit()); |
|
559 |
QVERIFY(!testWidget->lineEdit()->text().isEmpty()); |
|
560 |
testWidget->clear(); |
|
561 |
QCOMPARE(testWidget->count(), 0); |
|
562 |
QCOMPARE(testWidget->currentIndex(), -1); |
|
563 |
QVERIFY(testWidget->currentText().isEmpty()); |
|
564 |
QVERIFY(testWidget->lineEdit()->text().isEmpty()); |
|
565 |
} |
|
566 |
||
567 |
void tst_QComboBox::insertPolicy_data() |
|
568 |
{ |
|
569 |
QTest::addColumn<QStringList>("initialEntries"); |
|
570 |
QTest::addColumn<QComboBox::InsertPolicy>("insertPolicy"); |
|
571 |
QTest::addColumn<int>("currentIndex"); |
|
572 |
QTest::addColumn<QString>("userInput"); |
|
573 |
QTest::addColumn<QStringList>("result"); |
|
574 |
||
575 |
/* Each insertPolicy should test at least: |
|
576 |
no initial entries |
|
577 |
one initial entry |
|
578 |
five initial entries, current is first item |
|
579 |
five initial entries, current is third item |
|
580 |
five initial entries, current is last item |
|
581 |
*/ |
|
582 |
||
583 |
/* QComboBox::NoInsert - the string will not be inserted into the combobox. |
|
584 |
QComboBox::InsertAtTop - insert the string as the first item in the combobox. |
|
585 |
QComboBox::InsertAtCurrent - replace the previously selected item with the string the user has entered. |
|
586 |
QComboBox::InsertAtBottom - insert the string as the last item in the combobox. |
|
587 |
QComboBox::InsertAfterCurrent - insert the string after the previously selected item. |
|
588 |
QComboBox::InsertBeforeCurrent - insert the string before the previously selected item. |
|
589 |
QComboBox::InsertAlphabetically - insert the string at the alphabetic position. |
|
590 |
*/ |
|
591 |
QStringList initial; |
|
592 |
QStringList oneEntry("One"); |
|
593 |
QStringList fiveEntries; |
|
594 |
fiveEntries << "One" << "Two" << "Three" << "Four" << "Five"; |
|
595 |
QString input("insert"); |
|
596 |
||
597 |
{ |
|
598 |
QTest::newRow("NoInsert-NoInitial") << initial << QComboBox::NoInsert << 0 << input << initial; |
|
599 |
QTest::newRow("NoInsert-OneInitial") << oneEntry << QComboBox::NoInsert << 0 << input << oneEntry; |
|
600 |
QTest::newRow("NoInsert-FiveInitial-FirstCurrent") << fiveEntries << QComboBox::NoInsert << 0 << input << fiveEntries; |
|
601 |
QTest::newRow("NoInsert-FiveInitial-ThirdCurrent") << fiveEntries << QComboBox::NoInsert << 2 << input << fiveEntries; |
|
602 |
QTest::newRow("NoInsert-FiveInitial-LastCurrent") << fiveEntries << QComboBox::NoInsert << 4 << input << fiveEntries; |
|
603 |
} |
|
604 |
||
605 |
{ |
|
606 |
QStringList initialAtTop("insert"); |
|
607 |
QStringList oneAtTop; |
|
608 |
oneAtTop << "insert" << "One"; |
|
609 |
QStringList fiveAtTop; |
|
610 |
fiveAtTop << "insert" << "One" << "Two" << "Three" << "Four" << "Five"; |
|
611 |
||
612 |
QTest::newRow("AtTop-NoInitial") << initial << QComboBox::InsertAtTop << 0 << input << initialAtTop; |
|
613 |
QTest::newRow("AtTop-OneInitial") << oneEntry << QComboBox::InsertAtTop << 0 << input << oneAtTop; |
|
614 |
QTest::newRow("AtTop-FiveInitial-FirstCurrent") << fiveEntries << QComboBox::InsertAtTop << 0 << input << fiveAtTop; |
|
615 |
QTest::newRow("AtTop-FiveInitial-ThirdCurrent") << fiveEntries << QComboBox::InsertAtTop << 2 << input << fiveAtTop; |
|
616 |
QTest::newRow("AtTop-FiveInitial-LastCurrent") << fiveEntries << QComboBox::InsertAtTop << 4 << input << fiveAtTop; |
|
617 |
} |
|
618 |
||
619 |
{ |
|
620 |
QStringList initialAtCurrent("insert"); |
|
621 |
QStringList oneAtCurrent("insert"); |
|
622 |
QStringList fiveAtCurrentFirst; |
|
623 |
fiveAtCurrentFirst << "insert" << "Two" << "Three" << "Four" << "Five"; |
|
624 |
QStringList fiveAtCurrentThird; |
|
625 |
fiveAtCurrentThird << "One" << "Two" << "insert" << "Four" << "Five"; |
|
626 |
QStringList fiveAtCurrentLast; |
|
627 |
fiveAtCurrentLast << "One" << "Two" << "Three" << "Four" << "insert"; |
|
628 |
||
629 |
QTest::newRow("AtCurrent-NoInitial") << initial << QComboBox::InsertAtCurrent << 0 << input << initialAtCurrent; |
|
630 |
QTest::newRow("AtCurrent-OneInitial") << oneEntry << QComboBox::InsertAtCurrent << 0 << input << oneAtCurrent; |
|
631 |
QTest::newRow("AtCurrent-FiveInitial-FirstCurrent") << fiveEntries << QComboBox::InsertAtCurrent << 0 << input << fiveAtCurrentFirst; |
|
632 |
QTest::newRow("AtCurrent-FiveInitial-ThirdCurrent") << fiveEntries << QComboBox::InsertAtCurrent << 2 << input << fiveAtCurrentThird; |
|
633 |
QTest::newRow("AtCurrent-FiveInitial-LastCurrent") << fiveEntries << QComboBox::InsertAtCurrent << 4 << input << fiveAtCurrentLast; |
|
634 |
} |
|
635 |
||
636 |
{ |
|
637 |
QStringList initialAtBottom("insert"); |
|
638 |
QStringList oneAtBottom; |
|
639 |
oneAtBottom << "One" << "insert"; |
|
640 |
QStringList fiveAtBottom; |
|
641 |
fiveAtBottom << "One" << "Two" << "Three" << "Four" << "Five" << "insert"; |
|
642 |
||
643 |
QTest::newRow("AtBottom-NoInitial") << initial << QComboBox::InsertAtBottom << 0 << input << initialAtBottom; |
|
644 |
QTest::newRow("AtBottom-OneInitial") << oneEntry << QComboBox::InsertAtBottom << 0 << input << oneAtBottom; |
|
645 |
QTest::newRow("AtBottom-FiveInitial-FirstCurrent") << fiveEntries << QComboBox::InsertAtBottom << 0 << input << fiveAtBottom; |
|
646 |
QTest::newRow("AtBottom-FiveInitial-ThirdCurrent") << fiveEntries << QComboBox::InsertAtBottom << 2 << input << fiveAtBottom; |
|
647 |
QTest::newRow("AtBottom-FiveInitial-LastCurrent") << fiveEntries << QComboBox::InsertAtBottom << 4 << input << fiveAtBottom; |
|
648 |
} |
|
649 |
||
650 |
{ |
|
651 |
QStringList initialAfterCurrent("insert"); |
|
652 |
QStringList oneAfterCurrent; |
|
653 |
oneAfterCurrent << "One" << "insert"; |
|
654 |
QStringList fiveAfterCurrentFirst; |
|
655 |
fiveAfterCurrentFirst << "One" << "insert" << "Two" << "Three" << "Four" << "Five"; |
|
656 |
QStringList fiveAfterCurrentThird; |
|
657 |
fiveAfterCurrentThird << "One" << "Two" << "Three" << "insert" << "Four" << "Five"; |
|
658 |
QStringList fiveAfterCurrentLast; |
|
659 |
fiveAfterCurrentLast << "One" << "Two" << "Three" << "Four" << "Five" << "insert"; |
|
660 |
||
661 |
QTest::newRow("AfterCurrent-NoInitial") << initial << QComboBox::InsertAfterCurrent << 0 << input << initialAfterCurrent; |
|
662 |
QTest::newRow("AfterCurrent-OneInitial") << oneEntry << QComboBox::InsertAfterCurrent << 0 << input << oneAfterCurrent; |
|
663 |
QTest::newRow("AfterCurrent-FiveInitial-FirstCurrent") << fiveEntries << QComboBox::InsertAfterCurrent << 0 << input << fiveAfterCurrentFirst; |
|
664 |
QTest::newRow("AfterCurrent-FiveInitial-ThirdCurrent") << fiveEntries << QComboBox::InsertAfterCurrent << 2 << input << fiveAfterCurrentThird; |
|
665 |
QTest::newRow("AfterCurrent-FiveInitial-LastCurrent") << fiveEntries << QComboBox::InsertAfterCurrent << 4 << input << fiveAfterCurrentLast; |
|
666 |
} |
|
667 |
||
668 |
{ |
|
669 |
QStringList initialBeforeCurrent("insert"); |
|
670 |
QStringList oneBeforeCurrent; |
|
671 |
oneBeforeCurrent << "insert" << "One"; |
|
672 |
QStringList fiveBeforeCurrentFirst; |
|
673 |
fiveBeforeCurrentFirst << "insert" << "One" << "Two" << "Three" << "Four" << "Five"; |
|
674 |
QStringList fiveBeforeCurrentThird; |
|
675 |
fiveBeforeCurrentThird << "One" << "Two" << "insert" << "Three" << "Four" << "Five"; |
|
676 |
QStringList fiveBeforeCurrentLast; |
|
677 |
fiveBeforeCurrentLast << "One" << "Two" << "Three" << "Four" << "insert" << "Five"; |
|
678 |
||
679 |
QTest::newRow("BeforeCurrent-NoInitial") << initial << QComboBox::InsertBeforeCurrent << 0 << input << initialBeforeCurrent; |
|
680 |
QTest::newRow("BeforeCurrent-OneInitial") << oneEntry << QComboBox::InsertBeforeCurrent << 0 << input << oneBeforeCurrent; |
|
681 |
QTest::newRow("BeforeCurrent-FiveInitial-FirstCurrent") << fiveEntries << QComboBox::InsertBeforeCurrent << 0 << input << fiveBeforeCurrentFirst; |
|
682 |
QTest::newRow("BeforeCurrent-FiveInitial-ThirdCurrent") << fiveEntries << QComboBox::InsertBeforeCurrent << 2 << input << fiveBeforeCurrentThird; |
|
683 |
QTest::newRow("BeforeCurrent-FiveInitial-LastCurrent") << fiveEntries << QComboBox::InsertBeforeCurrent << 4 << input << fiveBeforeCurrentLast; |
|
684 |
} |
|
685 |
||
686 |
{ |
|
687 |
oneEntry.clear(); |
|
688 |
oneEntry << "foobar"; |
|
689 |
fiveEntries.clear(); |
|
690 |
fiveEntries << "bar" << "foo" << "initial" << "Item" << "stamp"; |
|
691 |
||
692 |
QStringList initialAlphabetically("insert"); |
|
693 |
QStringList oneAlphabetically; |
|
694 |
oneAlphabetically << "foobar" << "insert"; |
|
695 |
QStringList fiveAlphabetically; |
|
696 |
fiveAlphabetically << "bar" << "foo" << "initial" << "insert" << "Item" << "stamp"; |
|
697 |
||
698 |
QTest::newRow("Alphabetically-NoInitial") << initial << QComboBox::InsertAlphabetically << 0 << input << initialAlphabetically; |
|
699 |
QTest::newRow("Alphabetically-OneInitial") << oneEntry << QComboBox::InsertAlphabetically << 0 << input << oneAlphabetically; |
|
700 |
QTest::newRow("Alphabetically-FiveInitial-FirstCurrent") << fiveEntries << QComboBox::InsertAlphabetically << 0 << input << fiveAlphabetically; |
|
701 |
QTest::newRow("Alphabetically-FiveInitial-ThirdCurrent") << fiveEntries << QComboBox::InsertAlphabetically << 2 << input << fiveAlphabetically; |
|
702 |
QTest::newRow("Alphabetically-FiveInitial-LastCurrent") << fiveEntries << QComboBox::InsertAlphabetically << 4 << input << fiveAlphabetically; |
|
703 |
} |
|
704 |
} |
|
705 |
||
706 |
void tst_QComboBox::insertPolicy() |
|
707 |
{ |
|
708 |
QFETCH(QStringList, initialEntries); |
|
709 |
QFETCH(QComboBox::InsertPolicy, insertPolicy); |
|
710 |
QFETCH(int, currentIndex); |
|
711 |
QFETCH(QString, userInput); |
|
712 |
QFETCH(QStringList, result); |
|
713 |
||
714 |
testWidget->clear(); |
|
715 |
testWidget->setInsertPolicy(insertPolicy); |
|
716 |
testWidget->addItems(initialEntries); |
|
717 |
testWidget->setEditable(true); |
|
718 |
if (initialEntries.count() > 0) |
|
719 |
testWidget->setCurrentIndex(currentIndex); |
|
720 |
||
721 |
// clear |
|
722 |
QTest::mouseDClick(testWidget->lineEdit(), Qt::LeftButton); |
|
723 |
QTest::keyClick(testWidget->lineEdit(), Qt::Key_Delete); |
|
724 |
||
725 |
QTest::keyClicks(testWidget->lineEdit(), userInput); |
|
726 |
QTest::keyClick(testWidget->lineEdit(), Qt::Key_Return); |
|
727 |
||
728 |
// First check that there is the right number of entries, or |
|
729 |
// we may unwittingly pass |
|
730 |
QVERIFY((int)result.count() == testWidget->count()); |
|
731 |
||
732 |
// No need to compare if there are no strings to compare |
|
733 |
if (result.count() > 0) { |
|
734 |
for (int i=0; i<testWidget->count(); ++i) { |
|
735 |
QCOMPARE(testWidget->itemText(i), result.at(i)); |
|
736 |
} |
|
737 |
} |
|
738 |
} |
|
739 |
||
740 |
||
741 |
void tst_QComboBox::virtualAutocompletion() |
|
742 |
{ |
|
743 |
testWidget->clear(); |
|
744 |
testWidget->setAutoCompletion(true); |
|
745 |
testWidget->addItem("Foo"); |
|
746 |
testWidget->addItem("Bar"); |
|
747 |
testWidget->addItem("Boat"); |
|
748 |
testWidget->addItem("Boost"); |
|
749 |
testWidget->clearEditText(); |
|
750 |
||
751 |
// We need to set the keyboard input interval to a higher value |
|
752 |
// as the processEvent() call takes too much time, so it restarts |
|
753 |
// the keyboard search then |
|
754 |
#if defined(QT_ARCH_ARM) || defined(QT_ARCH_MIPS) || defined(QT_ARCH_SYMBIAN) |
|
755 |
int oldInterval = QApplication::keyboardInputInterval(); |
|
756 |
QApplication::setKeyboardInputInterval(1500); |
|
757 |
#endif |
|
758 |
||
759 |
// NOTE: |
|
760 |
// Cannot use keyClick for this test, as it simulates keyclicks too well |
|
761 |
// The virtual keyboards we're trying to catch here, do not perform that |
|
762 |
// well, and send a keypress & keyrelease right after each other. |
|
763 |
// This provokes the actual error, as there's no events in between to do |
|
764 |
// the text completion. |
|
765 |
QKeyEvent kp1(QEvent::KeyPress, Qt::Key_B, 0, "b"); |
|
766 |
QKeyEvent kr1(QEvent::KeyRelease, Qt::Key_B, 0, "b"); |
|
767 |
QApplication::sendEvent(testWidget, &kp1); |
|
768 |
QApplication::sendEvent(testWidget, &kr1); |
|
769 |
||
770 |
qApp->processEvents(); // Process events to trigger autocompletion |
|
771 |
QTRY_VERIFY(testWidget->currentIndex() == 1); |
|
772 |
||
773 |
#ifdef QTEST_RUNNING_USING_VALGRIND |
|
774 |
QSKIP("App running with valgrind are not fast enough", SkipAll); |
|
775 |
#endif |
|
776 |
||
777 |
QKeyEvent kp2(QEvent::KeyPress, Qt::Key_O, 0, "o"); |
|
778 |
QKeyEvent kr2(QEvent::KeyRelease, Qt::Key_O, 0, "o"); |
|
779 |
||
780 |
QApplication::sendEvent(testWidget, &kp2); |
|
781 |
QApplication::sendEvent(testWidget, &kr2); |
|
782 |
||
783 |
qApp->processEvents(); // Process events to trigger autocompletion |
|
784 |
QTRY_COMPARE(testWidget->currentIndex(), 2); |
|
785 |
||
786 |
QApplication::sendEvent(testWidget, &kp2); |
|
787 |
QApplication::sendEvent(testWidget, &kr2); |
|
788 |
qApp->processEvents(); // Process events to trigger autocompletion |
|
789 |
QTRY_COMPARE(testWidget->currentIndex(), 3); |
|
790 |
#if defined(QT_ARCH_ARM) || defined(QT_ARCH_MIPS) || defined(QT_ARCH_SYMBIAN) |
|
791 |
QApplication::setKeyboardInputInterval(oldInterval); |
|
792 |
#endif |
|
793 |
} |
|
794 |
||
795 |
void tst_QComboBox::autoCompletionCaseSensitivity() |
|
796 |
{ |
|
797 |
//we have put the focus because the completer |
|
798 |
//is only used when the widget actually has the focus |
|
799 |
testWidget->setFocus(); |
|
800 |
qApp->setActiveWindow(testWidget); |
|
801 |
QTRY_COMPARE(qApp->focusWidget(), (QWidget *)testWidget); |
|
802 |
||
803 |
testWidget->clear(); |
|
804 |
testWidget->setAutoCompletion(true); |
|
805 |
testWidget->addItem("Cow"); |
|
806 |
testWidget->addItem("irrelevant1"); |
|
807 |
testWidget->addItem("aww"); |
|
808 |
testWidget->addItem("A*"); |
|
809 |
testWidget->addItem("irrelevant2"); |
|
810 |
testWidget->addItem("aBCDEF"); |
|
811 |
testWidget->addItem("irrelevant3"); |
|
812 |
testWidget->addItem("abcdef"); |
|
813 |
testWidget->addItem("abCdef"); |
|
814 |
testWidget->setEditable(true); |
|
815 |
||
816 |
// case insensitive |
|
817 |
testWidget->clearEditText(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
818 |
QSignalSpy spyReturn(testWidget, SIGNAL(activated(int))); |
0 | 819 |
testWidget->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive); |
820 |
QVERIFY(testWidget->autoCompletionCaseSensitivity() == Qt::CaseInsensitive); |
|
821 |
||
822 |
QTest::keyClick(testWidget->lineEdit(), Qt::Key_A); |
|
823 |
qApp->processEvents(); |
|
824 |
QCOMPARE(testWidget->currentText(), QString("aww")); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
825 |
QCOMPARE(spyReturn.count(), 0); |
0 | 826 |
|
827 |
QTest::keyClick(testWidget->lineEdit(), Qt::Key_B); |
|
828 |
qApp->processEvents(); |
|
829 |
// autocompletions preserve userkey-case from 4.2 |
|
830 |
QCOMPARE(testWidget->currentText(), QString("abCDEF")); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
831 |
QCOMPARE(spyReturn.count(), 0); |
0 | 832 |
|
833 |
QTest::keyClick(testWidget->lineEdit(), Qt::Key_Enter); |
|
834 |
qApp->processEvents(); |
|
835 |
QCOMPARE(testWidget->currentText(), QString("aBCDEF")); // case restored to item's case |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
836 |
QCOMPARE(spyReturn.count(), 1); |
0 | 837 |
|
838 |
testWidget->clearEditText(); |
|
839 |
QTest::keyClick(testWidget->lineEdit(), 'c'); |
|
840 |
QCOMPARE(testWidget->currentText(), QString("cow")); |
|
841 |
QTest::keyClick(testWidget->lineEdit(), Qt::Key_Enter); |
|
842 |
QCOMPARE(testWidget->currentText(), QString("Cow")); // case restored to item's case |
|
843 |
||
844 |
testWidget->clearEditText(); |
|
845 |
QTest::keyClick(testWidget->lineEdit(), 'a'); |
|
846 |
QTest::keyClick(testWidget->lineEdit(), '*'); |
|
847 |
QCOMPARE(testWidget->currentText(), QString("a*")); |
|
848 |
QTest::keyClick(testWidget->lineEdit(), Qt::Key_Enter); |
|
849 |
QCOMPARE(testWidget->currentText(), QString("A*")); |
|
850 |
||
851 |
// case sensitive |
|
852 |
testWidget->clearEditText(); |
|
853 |
testWidget->setAutoCompletionCaseSensitivity(Qt::CaseSensitive); |
|
854 |
QVERIFY(testWidget->autoCompletionCaseSensitivity() == Qt::CaseSensitive); |
|
855 |
QTest::keyClick(testWidget->lineEdit(), Qt::Key_A); |
|
856 |
qApp->processEvents(); |
|
857 |
QCOMPARE(testWidget->currentText(), QString("aww")); |
|
858 |
QTest::keyClick(testWidget->lineEdit(), Qt::Key_B); |
|
859 |
qApp->processEvents(); |
|
860 |
QCOMPARE(testWidget->currentText(), QString("abcdef")); |
|
861 |
||
862 |
testWidget->setCurrentIndex(0); // to reset the completion's "start" |
|
863 |
testWidget->clearEditText(); |
|
864 |
QTest::keyClick(testWidget->lineEdit(), 'a'); |
|
865 |
QTest::keyClick(testWidget->lineEdit(), 'b'); |
|
866 |
QCOMPARE(testWidget->currentText(), QString("abcdef")); |
|
867 |
QTest::keyClick(testWidget->lineEdit(), 'C'); |
|
868 |
qApp->processEvents(); |
|
869 |
QCOMPARE(testWidget->currentText(), QString("abCdef")); |
|
870 |
QTest::keyClick(testWidget->lineEdit(), Qt::Key_Enter); |
|
871 |
qApp->processEvents(); |
|
872 |
QCOMPARE(testWidget->currentText(), QString("abCdef")); // case restored to item's case |
|
873 |
||
874 |
testWidget->clearEditText(); |
|
875 |
QTest::keyClick(testWidget->lineEdit(), 'c'); |
|
876 |
QCOMPARE(testWidget->currentText(), QString("c")); |
|
877 |
QTest::keyClick(testWidget->lineEdit(), Qt::Key_Backspace); |
|
878 |
QTest::keyClick(testWidget->lineEdit(), 'C'); |
|
879 |
QCOMPARE(testWidget->currentText(), QString("Cow")); |
|
880 |
QTest::keyClick(testWidget->lineEdit(), Qt::Key_Enter); |
|
881 |
QCOMPARE(testWidget->currentText(), QString("Cow")); |
|
882 |
||
883 |
testWidget->clearEditText(); |
|
884 |
QTest::keyClick(testWidget->lineEdit(), 'a'); |
|
885 |
QTest::keyClick(testWidget->lineEdit(), '*'); |
|
886 |
QCOMPARE(testWidget->currentText(), QString("a*")); |
|
887 |
QTest::keyClick(testWidget->lineEdit(), Qt::Key_Enter); |
|
888 |
QCOMPARE(testWidget->currentText(), QString("a*")); // A* not matched |
|
889 |
} |
|
890 |
||
891 |
void tst_QComboBox::hide() |
|
892 |
{ |
|
893 |
testWidget->addItem("foo"); |
|
894 |
testWidget->showPopup(); |
|
895 |
//allow combobox effect to complete |
|
896 |
QTRY_VERIFY(testWidget->view()); |
|
897 |
QTRY_VERIFY(testWidget->view()->isVisible()); |
|
898 |
testWidget->hidePopup(); |
|
899 |
//allow combobox effect to complete |
|
900 |
QTRY_VERIFY(!testWidget->view()->isVisible()); |
|
901 |
testWidget->hide(); |
|
902 |
QVERIFY(!testWidget->isVisible()); |
|
903 |
} |
|
904 |
||
905 |
||
906 |
||
907 |
void tst_QComboBox::currentIndex_data() |
|
908 |
{ |
|
909 |
QTest::addColumn<QStringList>("initialItems"); |
|
910 |
QTest::addColumn<int>("setCurrentIndex"); |
|
911 |
QTest::addColumn<int>("removeIndex"); |
|
912 |
QTest::addColumn<int>("insertIndex"); |
|
913 |
QTest::addColumn<QString>("insertText"); |
|
914 |
QTest::addColumn<int>("expectedCurrentIndex"); |
|
915 |
QTest::addColumn<QString>("expectedCurrentText"); |
|
916 |
QTest::addColumn<int>("expectedSignalCount"); |
|
917 |
||
918 |
QStringList initialItems; |
|
919 |
int setCurrentIndex; |
|
920 |
int removeIndex; |
|
921 |
int insertIndex; |
|
922 |
QString insertText; |
|
923 |
int expectedCurrentIndex; |
|
924 |
QString expectedCurrentText; |
|
925 |
int expectedSignalCount; |
|
926 |
||
927 |
{ |
|
928 |
initialItems.clear(); |
|
929 |
initialItems << "foo" << "bar"; |
|
930 |
setCurrentIndex = -2; |
|
931 |
removeIndex = -1; |
|
932 |
insertIndex = -1; |
|
933 |
insertText = ""; |
|
934 |
expectedCurrentIndex = 0; |
|
935 |
expectedCurrentText = "foo"; |
|
936 |
expectedSignalCount = 1; |
|
937 |
QTest::newRow("first added item is set to current if there is no current") |
|
938 |
<< initialItems << setCurrentIndex << removeIndex |
|
939 |
<< insertIndex << insertText << expectedCurrentIndex << expectedCurrentText |
|
940 |
<< expectedSignalCount; |
|
941 |
} |
|
942 |
{ |
|
943 |
initialItems.clear(); |
|
944 |
initialItems << "foo" << "bar"; |
|
945 |
setCurrentIndex = 1; |
|
946 |
removeIndex = -1; |
|
947 |
insertIndex = -1; |
|
948 |
insertText = ""; |
|
949 |
expectedCurrentIndex = 1; |
|
950 |
expectedCurrentText = "bar"; |
|
951 |
expectedSignalCount = 2; |
|
952 |
QTest::newRow("check that setting the index works") |
|
953 |
<< initialItems << setCurrentIndex << removeIndex |
|
954 |
<< insertIndex << insertText << expectedCurrentIndex << expectedCurrentText |
|
955 |
<< expectedSignalCount; |
|
956 |
||
957 |
} |
|
958 |
{ |
|
959 |
initialItems.clear(); |
|
960 |
initialItems << "foo" << "bar"; |
|
961 |
setCurrentIndex = -1; // will invalidate the currentIndex |
|
962 |
removeIndex = -1; |
|
963 |
insertIndex = -1; |
|
964 |
insertText = ""; |
|
965 |
expectedCurrentIndex = -1; |
|
966 |
expectedCurrentText = ""; |
|
967 |
expectedSignalCount = 2; |
|
968 |
QTest::newRow("check that isetting the index to -1 works") |
|
969 |
<< initialItems << setCurrentIndex << removeIndex |
|
970 |
<< insertIndex << insertText << expectedCurrentIndex << expectedCurrentText |
|
971 |
<< expectedSignalCount; |
|
972 |
||
973 |
} |
|
974 |
{ |
|
975 |
initialItems.clear(); |
|
976 |
initialItems << "foo"; |
|
977 |
setCurrentIndex = 0; |
|
978 |
removeIndex = 0; |
|
979 |
insertIndex = -1; |
|
980 |
insertText = ""; |
|
981 |
expectedCurrentIndex = -1; |
|
982 |
expectedCurrentText = ""; |
|
983 |
expectedSignalCount = 2; |
|
984 |
QTest::newRow("check that current index is invalid when removing the only item") |
|
985 |
<< initialItems << setCurrentIndex << removeIndex |
|
986 |
<< insertIndex << insertText << expectedCurrentIndex << expectedCurrentText |
|
987 |
<< expectedSignalCount; |
|
988 |
} |
|
989 |
{ |
|
990 |
initialItems.clear(); |
|
991 |
initialItems << "foo" << "bar"; |
|
992 |
setCurrentIndex = 1; |
|
993 |
removeIndex = 0; |
|
994 |
insertIndex = -1; |
|
995 |
insertText = ""; |
|
996 |
expectedCurrentIndex = 0; |
|
997 |
expectedCurrentText = "bar"; |
|
998 |
expectedSignalCount = 3; |
|
999 |
QTest::newRow("check that the current index follows the item when removing an item above") |
|
1000 |
<< initialItems << setCurrentIndex << removeIndex |
|
1001 |
<< insertIndex << insertText << expectedCurrentIndex << expectedCurrentText |
|
1002 |
<< expectedSignalCount; |
|
1003 |
||
1004 |
} |
|
1005 |
{ |
|
1006 |
initialItems.clear(); |
|
1007 |
initialItems << "foo" << "bar" << "baz"; |
|
1008 |
setCurrentIndex = 1; |
|
1009 |
removeIndex = 1; |
|
1010 |
insertIndex = -1; |
|
1011 |
insertText = ""; |
|
1012 |
expectedCurrentIndex = 1; |
|
1013 |
expectedCurrentText = "baz"; |
|
1014 |
expectedSignalCount = 3; |
|
1015 |
QTest::newRow("check that the current index uses the next item if current is removed") |
|
1016 |
<< initialItems << setCurrentIndex << removeIndex |
|
1017 |
<< insertIndex << insertText << expectedCurrentIndex << expectedCurrentText |
|
1018 |
<< expectedSignalCount; |
|
1019 |
} |
|
1020 |
{ |
|
1021 |
initialItems.clear(); |
|
1022 |
initialItems << "foo" << "bar" << "baz"; |
|
1023 |
setCurrentIndex = 2; |
|
1024 |
removeIndex = 2; |
|
1025 |
insertIndex = -1; |
|
1026 |
insertText = ""; |
|
1027 |
expectedCurrentIndex = 1; |
|
1028 |
expectedCurrentText = "bar"; |
|
1029 |
expectedSignalCount = 3; |
|
1030 |
QTest::newRow("check that the current index is moved to the one before if current is removed") |
|
1031 |
<< initialItems << setCurrentIndex << removeIndex |
|
1032 |
<< insertIndex << insertText << expectedCurrentIndex << expectedCurrentText |
|
1033 |
<< expectedSignalCount; |
|
1034 |
} |
|
1035 |
{ |
|
1036 |
initialItems.clear(); |
|
1037 |
initialItems << "foo" << "bar" << "baz"; |
|
1038 |
setCurrentIndex = 1; |
|
1039 |
removeIndex = 2; |
|
1040 |
insertIndex = -1; |
|
1041 |
insertText = ""; |
|
1042 |
expectedCurrentIndex = 1; |
|
1043 |
expectedCurrentText = "bar"; |
|
1044 |
expectedSignalCount = 2; |
|
1045 |
QTest::newRow("check that the current index is unchanged if you remove an item after") |
|
1046 |
<< initialItems << setCurrentIndex << removeIndex |
|
1047 |
<< insertIndex << insertText << expectedCurrentIndex << expectedCurrentText |
|
1048 |
<< expectedSignalCount; |
|
1049 |
} |
|
1050 |
{ |
|
1051 |
initialItems.clear(); |
|
1052 |
initialItems << "foo" << "bar"; |
|
1053 |
setCurrentIndex = 1; |
|
1054 |
removeIndex = -1; |
|
1055 |
insertIndex = 0; |
|
1056 |
insertText = "baz"; |
|
1057 |
expectedCurrentIndex = 2; |
|
1058 |
expectedCurrentText = "bar"; |
|
1059 |
expectedSignalCount = 3; |
|
1060 |
QTest::newRow("check that the current index follows the item if you insert before current") |
|
1061 |
<< initialItems << setCurrentIndex << removeIndex |
|
1062 |
<< insertIndex << insertText << expectedCurrentIndex << expectedCurrentText |
|
1063 |
<< expectedSignalCount; |
|
1064 |
} |
|
1065 |
{ |
|
1066 |
initialItems.clear(); |
|
1067 |
initialItems << "foo"; |
|
1068 |
setCurrentIndex = 0; |
|
1069 |
removeIndex = -1; |
|
1070 |
insertIndex = 0; |
|
1071 |
insertText = "bar"; |
|
1072 |
expectedCurrentIndex = 1; |
|
1073 |
expectedCurrentText = "foo"; |
|
1074 |
expectedSignalCount = 2; |
|
1075 |
QTest::newRow("check that the current index follows the item if you insert on the current") |
|
1076 |
<< initialItems << setCurrentIndex << removeIndex |
|
1077 |
<< insertIndex << insertText << expectedCurrentIndex << expectedCurrentText |
|
1078 |
<< expectedSignalCount; |
|
1079 |
} |
|
1080 |
{ |
|
1081 |
initialItems.clear(); |
|
1082 |
initialItems << "foo"; |
|
1083 |
setCurrentIndex = 0; |
|
1084 |
removeIndex = -1; |
|
1085 |
insertIndex = 1; |
|
1086 |
insertText = "bar"; |
|
1087 |
expectedCurrentIndex = 0; |
|
1088 |
expectedCurrentText = "foo"; |
|
1089 |
expectedSignalCount = 1; |
|
1090 |
QTest::newRow("check that the current index stays the same if you insert after the current") |
|
1091 |
<< initialItems << setCurrentIndex << removeIndex |
|
1092 |
<< insertIndex << insertText << expectedCurrentIndex << expectedCurrentText |
|
1093 |
<< expectedSignalCount; |
|
1094 |
} |
|
1095 |
} |
|
1096 |
||
1097 |
void tst_QComboBox::currentIndex() |
|
1098 |
{ |
|
1099 |
QFETCH(QStringList, initialItems); |
|
1100 |
QFETCH(int, setCurrentIndex); |
|
1101 |
QFETCH(int, removeIndex); |
|
1102 |
QFETCH(int, insertIndex); |
|
1103 |
QFETCH(QString, insertText); |
|
1104 |
QFETCH(int, expectedCurrentIndex); |
|
1105 |
QFETCH(QString, expectedCurrentText); |
|
1106 |
QFETCH(int, expectedSignalCount); |
|
1107 |
||
1108 |
// test both editable/non-editable combobox |
|
1109 |
for (int edit = 0; edit < 2; ++edit) { |
|
1110 |
testWidget->clear(); |
|
1111 |
testWidget->setEditable(edit ? true : false); |
|
1112 |
if (edit) |
|
1113 |
QVERIFY(testWidget->lineEdit()); |
|
1114 |
||
1115 |
// verify it is empty, has no current index and no current text |
|
1116 |
QCOMPARE(testWidget->count(), 0); |
|
1117 |
QCOMPARE(testWidget->currentIndex(), -1); |
|
1118 |
QVERIFY(testWidget->currentText().isEmpty()); |
|
1119 |
||
1120 |
// spy on currentIndexChanged |
|
1121 |
QSignalSpy indexChangedInt(testWidget, SIGNAL(currentIndexChanged(int))); |
|
1122 |
QSignalSpy indexChangedString(testWidget, SIGNAL(currentIndexChanged(const QString&))); |
|
1123 |
||
1124 |
// stuff items into it |
|
1125 |
foreach(QString text, initialItems) { |
|
1126 |
testWidget->addItem(text); |
|
1127 |
} |
|
1128 |
QCOMPARE(testWidget->count(), initialItems.count()); |
|
1129 |
||
1130 |
// set current index, remove and/or insert |
|
1131 |
if (setCurrentIndex >= -1) { |
|
1132 |
testWidget->setCurrentIndex(setCurrentIndex); |
|
1133 |
QCOMPARE(testWidget->currentIndex(), setCurrentIndex); |
|
1134 |
} |
|
1135 |
||
1136 |
if (removeIndex >= 0) |
|
1137 |
testWidget->removeItem(removeIndex); |
|
1138 |
if (insertIndex >= 0) |
|
1139 |
testWidget->insertItem(insertIndex, insertText); |
|
1140 |
||
1141 |
// compare with expected index and text |
|
1142 |
QCOMPARE(testWidget->currentIndex(), expectedCurrentIndex); |
|
1143 |
QCOMPARE(testWidget->currentText(), expectedCurrentText); |
|
1144 |
||
1145 |
// check that signal count is correct |
|
1146 |
QCOMPARE(indexChangedInt.count(), expectedSignalCount); |
|
1147 |
QCOMPARE(indexChangedString.count(), expectedSignalCount); |
|
1148 |
||
1149 |
// compare with last sent signal values |
|
1150 |
if (indexChangedInt.count()) |
|
1151 |
QCOMPARE(indexChangedInt.at(indexChangedInt.count() - 1).at(0).toInt(), |
|
1152 |
testWidget->currentIndex()); |
|
1153 |
if (indexChangedString.count()) |
|
1154 |
QCOMPARE(indexChangedString.at(indexChangedString.count() - 1).at(0).toString(), |
|
1155 |
testWidget->currentText()); |
|
1156 |
||
1157 |
if (edit) { |
|
1158 |
testWidget->setCurrentIndex(-1); |
|
1159 |
testWidget->setInsertPolicy(QComboBox::InsertAtBottom); |
|
1160 |
QTest::keyPress(testWidget, 'a'); |
|
1161 |
QTest::keyPress(testWidget, 'b'); |
|
1162 |
QCOMPARE(testWidget->currentText(), QString("ab")); |
|
1163 |
QCOMPARE(testWidget->currentIndex(), -1); |
|
1164 |
int numItems = testWidget->count(); |
|
1165 |
QTest::keyPress(testWidget, Qt::Key_Return); |
|
1166 |
QCOMPARE(testWidget->count(), numItems + 1); |
|
1167 |
QCOMPARE(testWidget->currentIndex(), numItems); |
|
1168 |
testWidget->setCurrentIndex(-1); |
|
1169 |
QTest::keyPress(testWidget, 'a'); |
|
1170 |
QTest::keyPress(testWidget, 'b'); |
|
1171 |
QCOMPARE(testWidget->currentIndex(), -1); |
|
1172 |
} |
|
1173 |
} |
|
1174 |
} |
|
1175 |
||
1176 |
void tst_QComboBox::insertItems_data() |
|
1177 |
{ |
|
1178 |
QTest::addColumn<QStringList>("initialItems"); |
|
1179 |
QTest::addColumn<QStringList>("insertedItems"); |
|
1180 |
QTest::addColumn<int>("insertIndex"); |
|
1181 |
QTest::addColumn<int>("expectedIndex"); |
|
1182 |
||
1183 |
QStringList initialItems; |
|
1184 |
QStringList insertedItems; |
|
1185 |
||
1186 |
initialItems << "foo" << "bar"; |
|
1187 |
insertedItems << "mongo"; |
|
1188 |
||
1189 |
QTest::newRow("prepend") << initialItems << insertedItems << 0 << 0; |
|
1190 |
QTest::newRow("prepend with negative value") << initialItems << insertedItems << -1 << 0; |
|
1191 |
QTest::newRow("append") << initialItems << insertedItems << initialItems.count() << initialItems.count(); |
|
1192 |
QTest::newRow("append with too high value") << initialItems << insertedItems << 999 << initialItems.count(); |
|
1193 |
QTest::newRow("insert") << initialItems << insertedItems << 1 << 1; |
|
1194 |
} |
|
1195 |
||
1196 |
void tst_QComboBox::insertItems() |
|
1197 |
{ |
|
1198 |
QFETCH(QStringList, initialItems); |
|
1199 |
QFETCH(QStringList, insertedItems); |
|
1200 |
QFETCH(int, insertIndex); |
|
1201 |
QFETCH(int, expectedIndex); |
|
1202 |
||
1203 |
testWidget->insertItems(0, initialItems); |
|
1204 |
QCOMPARE(testWidget->count(), initialItems.count()); |
|
1205 |
||
1206 |
testWidget->insertItems(insertIndex, insertedItems); |
|
1207 |
||
1208 |
QCOMPARE(testWidget->count(), initialItems.count() + insertedItems.count()); |
|
1209 |
for (int i=0; i<insertedItems.count(); ++i) |
|
1210 |
QCOMPARE(testWidget->itemText(expectedIndex + i), insertedItems.at(i)); |
|
1211 |
} |
|
1212 |
||
1213 |
void tst_QComboBox::insertItem_data() |
|
1214 |
{ |
|
1215 |
QTest::addColumn<QStringList>("initialItems"); |
|
1216 |
QTest::addColumn<int>("insertIndex"); |
|
1217 |
QTest::addColumn<QString>("itemLabel"); |
|
1218 |
QTest::addColumn<int>("expectedIndex"); |
|
1219 |
QTest::addColumn<bool>("testQt3Support"); |
|
1220 |
QTest::addColumn<bool>("editable"); |
|
1221 |
||
1222 |
QStringList initialItems; |
|
1223 |
initialItems << "foo" << "bar"; |
|
1224 |
for(int e = 0 ; e<2 ; e++) { |
|
1225 |
bool editable = (e==0); |
|
1226 |
QTest::newRow("Insert less then 0") << initialItems << -1 << "inserted" << 0 << false << editable; |
|
1227 |
QTest::newRow("Insert at 0") << initialItems << 0 << "inserted" << 0 << false << editable; |
|
1228 |
QTest::newRow("Insert beyond count") << initialItems << 3 << "inserted" << 2 << false << editable; |
|
1229 |
QTest::newRow("Insert at count") << initialItems << 2 << "inserted" << 2 << false << editable; |
|
1230 |
QTest::newRow("Insert in the middle") << initialItems << 1 << "inserted" << 1 << false << editable; |
|
1231 |
#if defined(QT3_SUPPORT) |
|
1232 |
QTest::newRow("Qt3Support: Insert less then 0") << initialItems << -1 << "inserted" << 2 << true << editable; |
|
1233 |
#endif |
|
1234 |
} |
|
1235 |
} |
|
1236 |
||
1237 |
void tst_QComboBox::insertItem() |
|
1238 |
{ |
|
1239 |
QFETCH(QStringList, initialItems); |
|
1240 |
QFETCH(int, insertIndex); |
|
1241 |
QFETCH(QString, itemLabel); |
|
1242 |
QFETCH(int, expectedIndex); |
|
1243 |
QFETCH(bool, testQt3Support); |
|
1244 |
QFETCH(bool, editable); |
|
1245 |
||
1246 |
testWidget->insertItems(0, initialItems); |
|
1247 |
QCOMPARE(testWidget->count(), initialItems.count()); |
|
1248 |
||
1249 |
testWidget->setEditable(true); |
|
1250 |
if (editable) |
|
1251 |
testWidget->setEditText("FOO"); |
|
1252 |
#if defined (QT3_SUPPORT) |
|
1253 |
if (testQt3Support) |
|
1254 |
testWidget->insertItem(itemLabel, insertIndex); |
|
1255 |
else |
|
1256 |
testWidget->insertItem(insertIndex, itemLabel); |
|
1257 |
#else |
|
1258 |
Q_UNUSED(testQt3Support); |
|
1259 |
testWidget->insertItem(insertIndex, itemLabel); |
|
1260 |
#endif |
|
1261 |
||
1262 |
||
1263 |
QCOMPARE(testWidget->count(), initialItems.count() + 1); |
|
1264 |
QCOMPARE(testWidget->itemText(expectedIndex), itemLabel); |
|
1265 |
||
1266 |
if (editable) |
|
1267 |
QCOMPARE(testWidget->currentText(), QString("FOO")); |
|
1268 |
} |
|
1269 |
||
1270 |
void tst_QComboBox::insertOnCurrentIndex() |
|
1271 |
{ |
|
1272 |
testWidget->setEditable(true); |
|
1273 |
testWidget->addItem("first item"); |
|
1274 |
testWidget->setCurrentIndex(0); |
|
1275 |
testWidget->insertItem(0, "second item"); |
|
1276 |
QCOMPARE(testWidget->lineEdit()->text(), QString::fromAscii("first item")); |
|
1277 |
} |
|
1278 |
||
1279 |
void tst_QComboBox::textpixmapdata_data() |
|
1280 |
{ |
|
1281 |
QTest::addColumn<QStringList>("text"); |
|
1282 |
QTest::addColumn<IconList>("icons"); |
|
1283 |
QTest::addColumn<VariantList>("variant"); |
|
1284 |
||
1285 |
QStringList text; |
|
1286 |
IconList icon; |
|
1287 |
VariantList variant; |
|
1288 |
||
1289 |
{ |
|
1290 |
text.clear(); icon.clear(); variant.clear(); |
|
1291 |
text << "foo" << "bar"; |
|
1292 |
icon << QIcon() << QIcon(); |
|
1293 |
variant << QVariant() << QVariant(); |
|
1294 |
QTest::newRow("just text") << text << icon << variant; |
|
1295 |
} |
|
1296 |
{ |
|
1297 |
text.clear(); icon.clear(); variant.clear(); |
|
1298 |
text << QString() << QString(); |
|
1299 |
icon << QIcon(QPixmap("qtlogo.png")) << QIcon(QPixmap("qtlogoinverted.png")); |
|
1300 |
variant << QVariant() << QVariant(); |
|
1301 |
QTest::newRow("just icons") << text << icon << variant; |
|
1302 |
} |
|
1303 |
{ |
|
1304 |
text.clear(); icon.clear(); variant.clear(); |
|
1305 |
text << QString() << QString(); |
|
1306 |
icon << QIcon() << QIcon(); |
|
1307 |
variant << 12 << "bingo"; |
|
1308 |
QTest::newRow("just user data") << text << icon << variant; |
|
1309 |
} |
|
1310 |
{ |
|
1311 |
text.clear(); icon.clear(); variant.clear(); |
|
1312 |
text << "foo" << "bar"; |
|
1313 |
icon << QIcon(QPixmap("qtlogo.png")) << QIcon(QPixmap("qtlogoinverted.png")); |
|
1314 |
variant << 12 << "bingo"; |
|
1315 |
QTest::newRow("text, icons and user data") << text << icon << variant; |
|
1316 |
} |
|
1317 |
} |
|
1318 |
||
1319 |
void tst_QComboBox::textpixmapdata() |
|
1320 |
{ |
|
1321 |
QFETCH(QStringList, text); |
|
1322 |
QFETCH(IconList, icons); |
|
1323 |
QFETCH(VariantList, variant); |
|
1324 |
||
1325 |
QVERIFY(text.count() == icons.count() && text.count() == variant.count()); |
|
1326 |
||
1327 |
for (int i = 0; i<text.count(); ++i) { |
|
1328 |
testWidget->insertItem(i, text.at(i)); |
|
1329 |
testWidget->setItemIcon(i, icons.at(i)); |
|
1330 |
testWidget->setItemData(i, variant.at(i), Qt::UserRole); |
|
1331 |
} |
|
1332 |
||
1333 |
QCOMPARE(testWidget->count(), text.count()); |
|
1334 |
||
1335 |
for (int i = 0; i<text.count(); ++i) { |
|
1336 |
QIcon icon = testWidget->itemIcon(i); |
|
1337 |
QVERIFY(icon.serialNumber() == icons.at(i).serialNumber()); |
|
1338 |
QPixmap original = icons.at(i).pixmap(1024); |
|
1339 |
QPixmap pixmap = icon.pixmap(1024); |
|
1340 |
QVERIFY(pixmap.toImage() == original.toImage()); |
|
1341 |
} |
|
1342 |
||
1343 |
for (int i = 0; i<text.count(); ++i) { |
|
1344 |
QCOMPARE(testWidget->itemText(i), text.at(i)); |
|
1345 |
// ### we should test icons/pixmap as well, but I need to fix the api mismatch first |
|
1346 |
QCOMPARE(testWidget->itemData(i, Qt::UserRole), variant.at(i)); |
|
1347 |
} |
|
1348 |
} |
|
1349 |
||
1350 |
void tst_QComboBox::setCurrentIndex() |
|
1351 |
{ |
|
1352 |
QCOMPARE(testWidget->count(), 0); |
|
1353 |
testWidget->addItem("foo"); |
|
1354 |
testWidget->addItem("bar"); |
|
1355 |
QCOMPARE(testWidget->count(), 2); |
|
1356 |
||
1357 |
QCOMPARE(testWidget->currentIndex(), 0); |
|
1358 |
testWidget->setCurrentIndex(0); |
|
1359 |
QCOMPARE(testWidget->currentText(), QString("foo")); |
|
1360 |
||
1361 |
testWidget->setCurrentIndex(1); |
|
1362 |
QCOMPARE(testWidget->currentText(), QString("bar")); |
|
1363 |
||
1364 |
testWidget->setCurrentIndex(0); |
|
1365 |
QCOMPARE(testWidget->currentText(), QString("foo")); |
|
1366 |
} |
|
1367 |
||
1368 |
void tst_QComboBox::editTextChanged() |
|
1369 |
{ |
|
1370 |
QCOMPARE(testWidget->count(), 0); |
|
1371 |
testWidget->addItem("foo"); |
|
1372 |
testWidget->addItem("bar"); |
|
1373 |
QCOMPARE(testWidget->count(), 2); |
|
1374 |
||
1375 |
// first we test non editable |
|
1376 |
testWidget->setEditable(false); |
|
1377 |
QCOMPARE(testWidget->isEditable(), false); |
|
1378 |
||
1379 |
// no signal should be sent when current is set to the same |
|
1380 |
QCOMPARE(testWidget->currentIndex(), 0); |
|
1381 |
editTextCount = 0; |
|
1382 |
editText.clear(); |
|
1383 |
testWidget->setCurrentIndex(0); |
|
1384 |
QCOMPARE(testWidget->currentIndex(), 0); |
|
1385 |
QCOMPARE(editTextCount, 0); |
|
1386 |
QCOMPARE(editText.isEmpty(), true); |
|
1387 |
||
1388 |
// no signal should be sent when changing to other index because we are not editable |
|
1389 |
QCOMPARE(testWidget->currentIndex(), 0); |
|
1390 |
editTextCount = 0; |
|
1391 |
editText.clear(); |
|
1392 |
testWidget->setCurrentIndex(1); |
|
1393 |
QCOMPARE(testWidget->currentIndex(), 1); |
|
1394 |
QCOMPARE(editTextCount, 0); |
|
1395 |
QCOMPARE(editText.isEmpty(), true); |
|
1396 |
||
1397 |
// now set to editable and reset current index |
|
1398 |
testWidget->setEditable(true); |
|
1399 |
QCOMPARE(testWidget->isEditable(), true); |
|
1400 |
testWidget->setCurrentIndex(0); |
|
1401 |
||
1402 |
// no signal should be sent when current is set to the same |
|
1403 |
QCOMPARE(testWidget->currentIndex(), 0); |
|
1404 |
editTextCount = 0; |
|
1405 |
editText.clear(); |
|
1406 |
testWidget->setCurrentIndex(0); |
|
1407 |
QCOMPARE(testWidget->currentIndex(), 0); |
|
1408 |
QCOMPARE(editTextCount, 0); |
|
1409 |
QCOMPARE(editText.isEmpty(), true); |
|
1410 |
||
1411 |
// signal should be sent when changing to other index |
|
1412 |
QCOMPARE(testWidget->currentIndex(), 0); |
|
1413 |
editTextCount = 0; |
|
1414 |
editText.clear(); |
|
1415 |
testWidget->setCurrentIndex(1); |
|
1416 |
QCOMPARE(testWidget->currentIndex(), 1); |
|
1417 |
QCOMPARE(editTextCount, 1); |
|
1418 |
QCOMPARE(editText, QString("bar")); |
|
1419 |
||
1420 |
// insert some keys and notice they are all signaled |
|
1421 |
editTextCount = 0; |
|
1422 |
editText.clear(); |
|
1423 |
QTest::keyClicks(testWidget, "bingo"); |
|
1424 |
QCOMPARE(editTextCount, 5); |
|
1425 |
QCOMPARE(editText, QString("barbingo")); |
|
1426 |
} |
|
1427 |
||
1428 |
void tst_QComboBox::onEditTextChanged(const QString &text) |
|
1429 |
{ |
|
1430 |
editTextCount++; |
|
1431 |
editText = text; |
|
1432 |
} |
|
1433 |
||
1434 |
void tst_QComboBox::setModel() |
|
1435 |
{ |
|
1436 |
QComboBox box; |
|
1437 |
QCOMPARE(box.currentIndex(), -1); |
|
1438 |
box.addItems((QStringList() << "foo" << "bar")); |
|
1439 |
QCOMPARE(box.currentIndex(), 0); |
|
1440 |
box.setCurrentIndex(1); |
|
1441 |
QCOMPARE(box.currentIndex(), 1); |
|
1442 |
||
1443 |
// check that currentIndex is set to invalid |
|
1444 |
QAbstractItemModel *oldModel = box.model(); |
|
1445 |
box.setModel(new QStandardItemModel(&box)); |
|
1446 |
QCOMPARE(box.currentIndex(), -1); |
|
1447 |
QVERIFY(box.model() != oldModel); |
|
1448 |
||
1449 |
// check that currentIndex is set to first item |
|
1450 |
oldModel = box.model(); |
|
1451 |
box.setModel(new QStandardItemModel(2,1, &box)); |
|
1452 |
QCOMPARE(box.currentIndex(), 0); |
|
1453 |
QVERIFY(box.model() != oldModel); |
|
1454 |
} |
|
1455 |
||
1456 |
void tst_QComboBox::modelDeleted() |
|
1457 |
{ |
|
1458 |
QComboBox box; |
|
1459 |
QStandardItemModel *model = new QStandardItemModel; |
|
1460 |
box.setModel(model); |
|
1461 |
QCOMPARE(box.model(), static_cast<QAbstractItemModel *>(model)); |
|
1462 |
delete model; |
|
1463 |
QVERIFY(box.model()); |
|
1464 |
QCOMPARE(box.findText("bubu"), -1); |
|
1465 |
||
1466 |
delete box.model(); |
|
1467 |
QVERIFY(box.model()); |
|
1468 |
delete box.model(); |
|
1469 |
QVERIFY(box.model()); |
|
1470 |
} |
|
1471 |
||
1472 |
void tst_QComboBox::setMaxCount() |
|
1473 |
{ |
|
1474 |
QStringList items; |
|
1475 |
items << "1" << "2" << "3" << "4" << "5"; |
|
1476 |
||
1477 |
QComboBox box; |
|
1478 |
box.addItems(items); |
|
1479 |
QCOMPARE(box.count(), 5); |
|
1480 |
||
1481 |
box.setMaxCount(4); |
|
1482 |
QCOMPARE(box.count(), 4); |
|
1483 |
QCOMPARE(box.itemText(0), QString("1")); |
|
1484 |
QCOMPARE(box.itemText(1), QString("2")); |
|
1485 |
QCOMPARE(box.itemText(2), QString("3")); |
|
1486 |
QCOMPARE(box.itemText(3), QString("4")); |
|
1487 |
||
1488 |
// appending should do nothing |
|
1489 |
box.addItem("foo"); |
|
1490 |
QCOMPARE(box.count(), 4); |
|
1491 |
QCOMPARE(box.findText("foo"), -1); |
|
1492 |
||
1493 |
// inserting one item at top should remove the last |
|
1494 |
box.insertItem(0, "0"); |
|
1495 |
QCOMPARE(box.count(), 4); |
|
1496 |
QCOMPARE(box.itemText(0), QString("0")); |
|
1497 |
QCOMPARE(box.itemText(1), QString("1")); |
|
1498 |
QCOMPARE(box.itemText(2), QString("2")); |
|
1499 |
QCOMPARE(box.itemText(3), QString("3")); |
|
1500 |
||
1501 |
// insert 5 items in a box with maxCount 4 |
|
1502 |
box.insertItems(0, items); |
|
1503 |
QCOMPARE(box.count(), 4); |
|
1504 |
QCOMPARE(box.itemText(0), QString("1")); |
|
1505 |
QCOMPARE(box.itemText(1), QString("2")); |
|
1506 |
QCOMPARE(box.itemText(2), QString("3")); |
|
1507 |
QCOMPARE(box.itemText(3), QString("4")); |
|
1508 |
||
1509 |
// insert 5 items at pos 2. Make sure only two get inserted |
|
1510 |
QSignalSpy spy(box.model(), SIGNAL(rowsInserted(QModelIndex,int,int))); |
|
1511 |
box.insertItems(2, items); |
|
1512 |
QCOMPARE(spy.count(), 1); |
|
1513 |
QCOMPARE(spy.at(0).at(1).toInt(), 2); |
|
1514 |
QCOMPARE(spy.at(0).at(2).toInt(), 3); |
|
1515 |
||
1516 |
QCOMPARE(box.count(), 4); |
|
1517 |
QCOMPARE(box.itemText(0), QString("1")); |
|
1518 |
QCOMPARE(box.itemText(1), QString("2")); |
|
1519 |
QCOMPARE(box.itemText(2), QString("1")); |
|
1520 |
QCOMPARE(box.itemText(3), QString("2")); |
|
1521 |
||
1522 |
box.insertItems(0, QStringList()); |
|
1523 |
QCOMPARE(box.count(), 4); |
|
1524 |
||
1525 |
box.setMaxCount(0); |
|
1526 |
QCOMPARE(box.count(), 0); |
|
1527 |
box.addItem("foo"); |
|
1528 |
QCOMPARE(box.count(), 0); |
|
1529 |
box.addItems(items); |
|
1530 |
QCOMPARE(box.count(), 0); |
|
1531 |
} |
|
1532 |
||
1533 |
void tst_QComboBox::convenienceViews() |
|
1534 |
{ |
|
1535 |
// QListWidget |
|
1536 |
QComboBox listCombo; |
|
1537 |
QListWidget *list = new QListWidget(); |
|
1538 |
listCombo.setModel(list->model()); |
|
1539 |
listCombo.setView(list); |
|
1540 |
// add items |
|
1541 |
list->addItem("list0"); |
|
1542 |
listCombo.addItem("list1"); |
|
1543 |
QCOMPARE(listCombo.count(), 2); |
|
1544 |
QCOMPARE(listCombo.itemText(0), QString("list0")); |
|
1545 |
QCOMPARE(listCombo.itemText(1), QString("list1")); |
|
1546 |
||
1547 |
// QTreeWidget |
|
1548 |
QComboBox treeCombo; |
|
1549 |
QTreeWidget *tree = new QTreeWidget(); |
|
1550 |
tree->setColumnCount(1); |
|
1551 |
tree->header()->hide(); |
|
1552 |
treeCombo.setModel(tree->model()); |
|
1553 |
treeCombo.setView(tree); |
|
1554 |
// add items |
|
1555 |
tree->addTopLevelItem(new QTreeWidgetItem(QStringList("tree0"))); |
|
1556 |
treeCombo.addItem("tree1"); |
|
1557 |
QCOMPARE(treeCombo.count(), 2); |
|
1558 |
QCOMPARE(treeCombo.itemText(0), QString("tree0")); |
|
1559 |
QCOMPARE(treeCombo.itemText(1), QString("tree1")); |
|
1560 |
||
1561 |
// QTableWidget |
|
1562 |
QComboBox tableCombo; |
|
1563 |
QTableWidget *table = new QTableWidget(0,1); |
|
1564 |
table->verticalHeader()->hide(); |
|
1565 |
table->horizontalHeader()->hide(); |
|
1566 |
tableCombo.setModel(table->model()); |
|
1567 |
tableCombo.setView(table); |
|
1568 |
// add items |
|
1569 |
table->setRowCount(table->rowCount() + 1); |
|
1570 |
table->setItem(0, table->rowCount() - 1, new QTableWidgetItem("table0")); |
|
1571 |
tableCombo.addItem("table1"); |
|
1572 |
QCOMPARE(tableCombo.count(), 2); |
|
1573 |
QCOMPARE(tableCombo.itemText(0), QString("table0")); |
|
1574 |
QCOMPARE(tableCombo.itemText(1), QString("table1")); |
|
1575 |
} |
|
1576 |
||
1577 |
class ReturnClass : public QWidget |
|
1578 |
{ |
|
1579 |
Q_OBJECT |
|
1580 |
public: |
|
1581 |
ReturnClass(QWidget *parent = 0) |
|
1582 |
: QWidget(parent), received(false) |
|
1583 |
{ |
|
1584 |
QComboBox *box = new QComboBox(this); |
|
1585 |
box->setEditable(true); |
|
1586 |
edit = box->lineEdit(); |
|
1587 |
box->setGeometry(rect()); |
|
1588 |
} |
|
1589 |
||
1590 |
void keyPressEvent(QKeyEvent *e) |
|
1591 |
{ |
|
1592 |
received = (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter); |
|
1593 |
} |
|
1594 |
||
1595 |
QLineEdit *edit; |
|
1596 |
||
1597 |
bool received; |
|
1598 |
||
1599 |
}; |
|
1600 |
||
1601 |
||
1602 |
||
1603 |
void tst_QComboBox::ensureReturnIsIgnored() |
|
1604 |
{ |
|
1605 |
ReturnClass r; |
|
1606 |
r.show(); |
|
1607 |
||
1608 |
QTest::keyClick(r.edit, Qt::Key_Return); |
|
1609 |
QVERIFY(r.received); |
|
1610 |
r.received = false; |
|
1611 |
QTest::keyClick(r.edit, Qt::Key_Enter); |
|
1612 |
QVERIFY(r.received); |
|
1613 |
} |
|
1614 |
||
1615 |
||
1616 |
void tst_QComboBox::findText_data() |
|
1617 |
{ |
|
1618 |
QTest::addColumn<QStringList>("items"); |
|
1619 |
QTest::addColumn<int>("matchflags"); |
|
1620 |
QTest::addColumn<QString>("search"); |
|
1621 |
QTest::addColumn<int>("result"); |
|
1622 |
||
1623 |
QStringList list; |
|
1624 |
list << "One" << "Two" << "Three" << "Four" << "Five" << "Six" << "one"; |
|
1625 |
QTest::newRow("CaseSensitive_1") << list << (int)(Qt::MatchExactly|Qt::MatchCaseSensitive) |
|
1626 |
<< QString("Two") << 1; |
|
1627 |
QTest::newRow("CaseSensitive_2") << list << (int)(Qt::MatchExactly|Qt::MatchCaseSensitive) |
|
1628 |
<< QString("two") << -1; |
|
1629 |
QTest::newRow("CaseSensitive_3") << list << (int)(Qt::MatchExactly|Qt::MatchCaseSensitive) |
|
1630 |
<< QString("One") << 0; |
|
1631 |
QTest::newRow("CaseSensitive_4") << list << (int)(Qt::MatchExactly|Qt::MatchCaseSensitive) |
|
1632 |
<< QString("one") << 6; |
|
1633 |
QTest::newRow("CaseInsensitive_1") << list << (int)(Qt::MatchExactly) << QString("Two") << 1; |
|
1634 |
QTest::newRow("CaseInsensitive_2") << list << (int)(Qt::MatchExactly) << QString("two") << -1; |
|
1635 |
QTest::newRow("CaseInsensitive_3") << list << (int)(Qt::MatchExactly) << QString("One") << 0; |
|
1636 |
QTest::newRow("CaseInsensitive_4") << list << (int)(Qt::MatchExactly) << QString("one") << 6; |
|
1637 |
} |
|
1638 |
void tst_QComboBox::findText() |
|
1639 |
{ |
|
1640 |
QFETCH(QStringList, items); |
|
1641 |
QFETCH(int, matchflags); |
|
1642 |
QFETCH(QString, search); |
|
1643 |
QFETCH(int, result); |
|
1644 |
||
1645 |
testWidget->clear(); |
|
1646 |
testWidget->addItems(items); |
|
1647 |
||
1648 |
QCOMPARE(testWidget->findText(search, (Qt::MatchFlags)matchflags), result); |
|
1649 |
} |
|
1650 |
||
1651 |
typedef QList<int> IntList; |
|
1652 |
typedef QList<Qt::Key> KeyList; |
|
1653 |
Q_DECLARE_METATYPE(IntList) |
|
1654 |
Q_DECLARE_METATYPE(KeyList) |
|
1655 |
||
1656 |
void tst_QComboBox::flaggedItems_data() |
|
1657 |
{ |
|
1658 |
QTest::addColumn<QStringList>("itemList"); |
|
1659 |
QTest::addColumn<IntList>("deselectFlagList"); |
|
1660 |
QTest::addColumn<IntList>("disableFlagList"); |
|
1661 |
QTest::addColumn<KeyList>("keyMovementList"); |
|
1662 |
QTest::addColumn<bool>("editable"); |
|
1663 |
QTest::addColumn<int>("expectedIndex"); |
|
1664 |
||
1665 |
for (int editable=0;editable<2;editable++) { |
|
1666 |
QString testCase = editable ? "editable:" : "non-editable:"; |
|
1667 |
QStringList itemList; |
|
1668 |
itemList << "One" << "Two" << "Three" << "Four" << "Five" << "Six" << "Seven" << "Eight"; |
|
1669 |
IntList deselectFlagList; |
|
1670 |
IntList disableFlagList; |
|
1671 |
KeyList keyMovementList; |
|
1672 |
||
1673 |
keyMovementList << Qt::Key_Down << Qt::Key_Down << Qt::Key_Down << Qt::Key_Down; |
|
1674 |
QTest::newRow(testCase.toAscii() + "normal") << itemList << deselectFlagList << disableFlagList << keyMovementList << bool(editable) << 4; |
|
1675 |
||
1676 |
deselectFlagList.clear(); |
|
1677 |
disableFlagList.clear(); |
|
1678 |
deselectFlagList << 1 << 3; |
|
1679 |
QTest::newRow(testCase.toAscii() + "non-selectable") << itemList << deselectFlagList << disableFlagList << keyMovementList << bool(editable) << 4; |
|
1680 |
||
1681 |
deselectFlagList.clear(); |
|
1682 |
disableFlagList.clear(); |
|
1683 |
disableFlagList << 2; |
|
1684 |
QTest::newRow(testCase.toAscii() + "disabled") << itemList << deselectFlagList << disableFlagList << keyMovementList << bool(editable) << 5; |
|
1685 |
||
1686 |
deselectFlagList.clear(); |
|
1687 |
disableFlagList.clear(); |
|
1688 |
deselectFlagList << 1 << 3; |
|
1689 |
disableFlagList << 2 << 3; |
|
1690 |
QTest::newRow(testCase.toAscii() + "mixed") << itemList << deselectFlagList << disableFlagList << keyMovementList << bool(editable) << 6; |
|
1691 |
deselectFlagList.clear(); |
|
1692 |
disableFlagList.clear(); |
|
1693 |
disableFlagList << 0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
1694 |
QTest::newRow(testCase.toAscii() + "nearly-empty") << itemList << deselectFlagList << disableFlagList << keyMovementList << bool(editable) << 7; |
|
1695 |
||
1696 |
deselectFlagList.clear(); |
|
1697 |
disableFlagList.clear(); |
|
1698 |
disableFlagList << 0 << 1 << 2 << 3 << 5 << 6 << 7; |
|
1699 |
keyMovementList.clear(); |
|
1700 |
QTest::newRow(testCase.toAscii() + "only one enabled") << itemList << deselectFlagList << disableFlagList << keyMovementList << bool(editable) << 4; |
|
1701 |
||
1702 |
if (!editable) { |
|
1703 |
deselectFlagList.clear(); |
|
1704 |
disableFlagList.clear(); |
|
1705 |
keyMovementList.clear(); |
|
1706 |
disableFlagList << 0 << 2 << 3; |
|
1707 |
keyMovementList << Qt::Key_Down << Qt::Key_Home; |
|
1708 |
QTest::newRow(testCase.toAscii() + "home-disabled") << itemList << deselectFlagList << disableFlagList << keyMovementList << bool(editable) << 1; |
|
1709 |
||
1710 |
keyMovementList.clear(); |
|
1711 |
keyMovementList << Qt::Key_End; |
|
1712 |
QTest::newRow(testCase.toAscii() + "end-key") << itemList << deselectFlagList << disableFlagList << keyMovementList << bool(editable) << 7; |
|
1713 |
||
1714 |
disableFlagList.clear(); |
|
1715 |
disableFlagList << 1 ; |
|
1716 |
keyMovementList << Qt::Key_T; |
|
1717 |
QTest::newRow(testCase.toAscii() + "keyboard-search") << itemList << deselectFlagList << disableFlagList << keyMovementList << bool(editable) << 2; |
|
1718 |
||
1719 |
itemList << "nine" << "ten"; |
|
1720 |
keyMovementList << Qt::Key_T; |
|
1721 |
QTest::newRow(testCase.toAscii() + "search same start letter") << itemList << deselectFlagList << disableFlagList << keyMovementList << bool(editable) << 9; |
|
1722 |
||
1723 |
keyMovementList.clear(); |
|
1724 |
keyMovementList << Qt::Key_T << Qt::Key_H; |
|
1725 |
QTest::newRow(testCase.toAscii() + "keyboard search item") << itemList << deselectFlagList << disableFlagList << keyMovementList << bool(editable) << 2; |
|
1726 |
||
1727 |
disableFlagList.clear(); |
|
1728 |
disableFlagList << 1 << 3 << 5 << 7 << 9; |
|
1729 |
keyMovementList.clear(); |
|
1730 |
keyMovementList << Qt::Key_End << Qt::Key_Up << Qt::Key_Up << Qt::Key_PageDown << Qt::Key_PageUp << Qt::Key_PageUp << Qt::Key_Down; |
|
1731 |
QTest::newRow(testCase.toAscii() + "all key combinations") << itemList << deselectFlagList << disableFlagList << keyMovementList << bool(editable) << 4; |
|
1732 |
} else { |
|
1733 |
deselectFlagList.clear(); |
|
1734 |
disableFlagList.clear(); |
|
1735 |
disableFlagList << 1; |
|
1736 |
keyMovementList.clear(); |
|
1737 |
keyMovementList << Qt::Key_T << Qt::Key_Enter; |
|
1738 |
QTest::newRow(testCase.toAscii() + "disabled") << itemList << deselectFlagList << disableFlagList << keyMovementList << bool(editable) << 2; |
|
1739 |
QTest::newRow(testCase.toAscii() + "broken autocompletion") << itemList << deselectFlagList << disableFlagList << keyMovementList << bool(editable) << 2; |
|
1740 |
} |
|
1741 |
} |
|
1742 |
} |
|
1743 |
||
1744 |
void tst_QComboBox::flaggedItems() |
|
1745 |
{ |
|
1746 |
QFETCH(QStringList, itemList); |
|
1747 |
QFETCH(IntList, deselectFlagList); |
|
1748 |
QFETCH(IntList, disableFlagList); |
|
1749 |
QFETCH(KeyList, keyMovementList); |
|
1750 |
QFETCH(bool, editable); |
|
1751 |
QFETCH(int, expectedIndex); |
|
1752 |
||
1753 |
QComboBox comboBox; |
|
1754 |
QListWidget listWidget; |
|
1755 |
listWidget.addItems(itemList); |
|
1756 |
||
1757 |
comboBox.setEditable(editable); |
|
1758 |
foreach (int index, deselectFlagList) |
|
1759 |
listWidget.item(index)->setFlags(listWidget.item(index)->flags() & ~Qt::ItemIsSelectable); |
|
1760 |
||
1761 |
foreach (int index, disableFlagList) |
|
1762 |
listWidget.item(index)->setFlags(listWidget.item(index)->flags() & ~Qt::ItemIsEnabled); |
|
1763 |
||
1764 |
comboBox.setModel(listWidget.model()); |
|
1765 |
comboBox.setView(&listWidget); |
|
1766 |
comboBox.show(); |
|
1767 |
QApplication::setActiveWindow(&comboBox); |
|
1768 |
comboBox.activateWindow(); |
|
1769 |
comboBox.setFocus(); |
|
1770 |
QTRY_VERIFY(comboBox.isVisible()); |
|
1771 |
QTRY_VERIFY(comboBox.hasFocus()); |
|
1772 |
||
1773 |
if (editable) |
|
1774 |
comboBox.lineEdit()->selectAll(); |
|
1775 |
||
1776 |
QSignalSpy indexChangedInt(&comboBox, SIGNAL(currentIndexChanged(int))); |
|
1777 |
for (int i = 0; i < keyMovementList.count(); ++i) { |
|
1778 |
Qt::Key key = keyMovementList[i]; |
|
1779 |
QTest::keyClick(&comboBox, key); |
|
1780 |
if (indexChangedInt.count() != i + 1) { |
|
1781 |
QTest::qWait(400); |
|
1782 |
} |
|
1783 |
} |
|
1784 |
||
1785 |
QCOMPARE(comboBox.currentIndex() , expectedIndex); |
|
1786 |
} |
|
1787 |
||
1788 |
void tst_QComboBox::pixmapIcon() |
|
1789 |
{ |
|
1790 |
QComboBox box; |
|
1791 |
QStandardItemModel *model = new QStandardItemModel(2, 1, &box); |
|
1792 |
||
1793 |
QPixmap pix(10, 10); |
|
1794 |
pix.fill(Qt::red); |
|
1795 |
model->setData(model->index(0, 0), "Element 1"); |
|
1796 |
model->setData(model->index(0, 0), pix, Qt::DecorationRole); |
|
1797 |
||
1798 |
QIcon icon(pix); |
|
1799 |
model->setData(model->index(1, 0), "Element 2"); |
|
1800 |
model->setData(model->index(1, 0), icon, Qt::DecorationRole); |
|
1801 |
||
1802 |
box.setModel(model); |
|
1803 |
||
1804 |
QCOMPARE( box.itemIcon(0).isNull(), false ); |
|
1805 |
QCOMPARE( box.itemIcon(1).isNull(), false ); |
|
1806 |
} |
|
1807 |
||
1808 |
// defined to be 120 by the wheel mouse vendors according to the docs |
|
1809 |
#define WHEEL_DELTA 120 |
|
1810 |
||
1811 |
void tst_QComboBox::mouseWheel_data() |
|
1812 |
{ |
|
1813 |
QTest::addColumn<IntList>("disabledItems"); |
|
1814 |
QTest::addColumn<int>("startIndex"); |
|
1815 |
QTest::addColumn<int>("wheelDirection"); |
|
1816 |
QTest::addColumn<int>("expectedIndex"); |
|
1817 |
||
1818 |
IntList disabled; |
|
1819 |
disabled << 0 << 1 << 2 << 4; |
|
1820 |
int start = 3; |
|
1821 |
int wheel = 1; |
|
1822 |
int expected = 3; |
|
1823 |
QTest::newRow("upper locked") << disabled << start << wheel << expected; |
|
1824 |
||
1825 |
wheel = -1; |
|
1826 |
expected = 5; |
|
1827 |
QTest::newRow("jump over") << disabled << start << wheel << expected; |
|
1828 |
||
1829 |
disabled.clear(); |
|
1830 |
disabled << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9; |
|
1831 |
start = 0; |
|
1832 |
wheel = -1; |
|
1833 |
expected = 0; |
|
1834 |
QTest::newRow("single Item enabled") << disabled << start << wheel << expected; |
|
1835 |
} |
|
1836 |
||
1837 |
void tst_QComboBox::mouseWheel() |
|
1838 |
{ |
|
1839 |
QFETCH(IntList, disabledItems); |
|
1840 |
QFETCH(int, startIndex); |
|
1841 |
QFETCH(int, wheelDirection); |
|
1842 |
QFETCH(int, expectedIndex); |
|
1843 |
||
1844 |
QCoreApplication *applicationInstance = QCoreApplication::instance(); |
|
1845 |
QVERIFY(applicationInstance != 0); |
|
1846 |
||
1847 |
QComboBox box; |
|
1848 |
QStringList list; |
|
1849 |
list << "one" << "two" << "three" << "four" << "five" << "six" << "seven" << "eight" << "nine" << "ten"; |
|
1850 |
||
1851 |
QListWidget listWidget; |
|
1852 |
listWidget.addItems(list); |
|
1853 |
||
1854 |
foreach (int index, disabledItems) |
|
1855 |
listWidget.item(index)->setFlags(listWidget.item(index)->flags() & ~Qt::ItemIsEnabled); |
|
1856 |
||
1857 |
box.setModel(listWidget.model()); |
|
1858 |
box.setView(&listWidget); |
|
1859 |
for (int i=0; i < 2; ++i) { |
|
1860 |
box.setEditable(i==0?false:true); |
|
1861 |
box.setCurrentIndex(startIndex); |
|
1862 |
||
1863 |
QWheelEvent event = QWheelEvent(box.rect().bottomRight() , WHEEL_DELTA * wheelDirection, Qt::NoButton, Qt::NoModifier); |
|
1864 |
QVERIFY(applicationInstance->sendEvent(&box,&event)); |
|
1865 |
||
1866 |
QCOMPARE(box.currentIndex(), expectedIndex); |
|
1867 |
} |
|
1868 |
} |
|
1869 |
||
1870 |
void tst_QComboBox::layoutDirection() |
|
1871 |
{ |
|
1872 |
QComboBox box; |
|
1873 |
Qt::LayoutDirection dir; |
|
1874 |
QLineEdit *lineEdit; |
|
1875 |
||
1876 |
// RTL |
|
1877 |
box.setLayoutDirection(Qt::RightToLeft); |
|
1878 |
QStyleOptionComboBox opt; |
|
1879 |
opt.direction = Qt::RightToLeft; |
|
1880 |
dir = (Qt::LayoutDirection)box.style()->styleHint(QStyle::SH_ComboBox_LayoutDirection, &opt, &box); |
|
1881 |
||
1882 |
QCOMPARE(box.view()->layoutDirection(), dir); |
|
1883 |
box.setEditable(true); |
|
1884 |
QCOMPARE(box.lineEdit()->layoutDirection(), dir); |
|
1885 |
lineEdit = new QLineEdit; |
|
1886 |
QCOMPARE(lineEdit->layoutDirection(), qApp->layoutDirection()); |
|
1887 |
box.setLineEdit(lineEdit); |
|
1888 |
QCOMPARE(lineEdit->layoutDirection(), dir); |
|
1889 |
||
1890 |
// LTR |
|
1891 |
box.setLayoutDirection(Qt::LeftToRight); |
|
1892 |
qApp->setLayoutDirection(Qt::RightToLeft); |
|
1893 |
||
1894 |
opt.direction = Qt::LeftToRight; |
|
1895 |
dir = (Qt::LayoutDirection)box.style()->styleHint(QStyle::SH_ComboBox_LayoutDirection, &opt, &box); |
|
1896 |
||
1897 |
QCOMPARE(box.view()->layoutDirection(), dir); |
|
1898 |
box.setEditable(true); |
|
1899 |
QCOMPARE(box.lineEdit()->layoutDirection(), dir); |
|
1900 |
lineEdit = new QLineEdit; |
|
1901 |
QCOMPARE(lineEdit->layoutDirection(), qApp->layoutDirection()); |
|
1902 |
box.setLineEdit(lineEdit); |
|
1903 |
QCOMPARE(lineEdit->layoutDirection(), dir); |
|
1904 |
||
1905 |
} |
|
1906 |
||
1907 |
void tst_QComboBox::itemListPosition() |
|
1908 |
{ |
|
1909 |
//tests that the list is not out of the screen boundaries |
|
1910 |
||
1911 |
//put the QApplication layout back |
|
1912 |
QApplication::setLayoutDirection(Qt::LeftToRight); |
|
1913 |
||
1914 |
//we test QFontComboBox because it has the specific behaviour to set a fixed size |
|
1915 |
//to the list view |
|
1916 |
QFontComboBox combo; |
|
1917 |
||
1918 |
//the code to get the avaialbe screen space is copied from QComboBox code |
|
1919 |
const int scrNumber = QApplication::desktop()->screenNumber(&combo); |
|
1920 |
QRect screen; |
|
1921 |
#ifdef Q_WS_WIN |
|
1922 |
screen = QApplication::desktop()->screenGeometry(scrNumber); |
|
1923 |
#elif defined Q_WS_X11 |
|
1924 |
if (X11->desktopEnvironment == DE_KDE) |
|
1925 |
screen = QApplication::desktop()->screenGeometry(scrNumber); |
|
1926 |
else |
|
1927 |
screen = QApplication::desktop()->availableGeometry(scrNumber); |
|
1928 |
#else |
|
1929 |
screen = QApplication::desktop()->availableGeometry(scrNumber); |
|
1930 |
#endif |
|
1931 |
||
1932 |
combo.move(screen.width()-combo.sizeHint().width(), 0); //puts the combo to the top-right corner |
|
1933 |
||
1934 |
combo.show(); |
|
1935 |
//wait because the window manager can move the window if there is a right panel |
|
1936 |
QTRY_VERIFY(combo.isVisible()); |
|
1937 |
combo.showPopup(); |
|
1938 |
QTRY_VERIFY(combo.view()); |
|
1939 |
QTRY_VERIFY(combo.view()->isVisible()); |
|
1940 |
||
1941 |
#if defined(Q_WS_S60) |
|
1942 |
// Assuming that QtS60 style is used, here. But other ones would certainly also fail |
|
1943 |
QEXPECT_FAIL("", "QtS60Style does not yet position the combobox popup correctly", Continue); |
|
1944 |
#endif |
|
1945 |
QVERIFY( combo.view()->window()->x() + combo.view()->window()->width() <= screen.x() + screen.width() ); |
|
1946 |
||
1947 |
} |
|
1948 |
||
1949 |
void tst_QComboBox::separatorItem_data() |
|
1950 |
{ |
|
1951 |
QTest::addColumn<QStringList>("items"); |
|
1952 |
QTest::addColumn<IntList>("separators"); |
|
1953 |
||
1954 |
QTest::newRow("test") << (QStringList() << "one" << "two" << "three" << "other...") |
|
1955 |
<< (IntList() << 4); |
|
1956 |
} |
|
1957 |
||
1958 |
void tst_QComboBox::separatorItem() |
|
1959 |
{ |
|
1960 |
QFETCH(QStringList, items); |
|
1961 |
QFETCH(IntList, separators); |
|
1962 |
||
1963 |
QComboBox box; |
|
1964 |
box.addItems(items); |
|
1965 |
foreach(int index, separators) |
|
1966 |
box.insertSeparator(index); |
|
1967 |
QCOMPARE(box.count(), (items.count() + separators.count())); |
|
1968 |
for (int i = 0, s = 0; i < box.count(); ++i) { |
|
1969 |
if (i == separators.at(s)) { |
|
1970 |
QCOMPARE(box.itemText(i), QString()); |
|
1971 |
++s; |
|
1972 |
} else { |
|
1973 |
QCOMPARE(box.itemText(i), items.at(i - s)); |
|
1974 |
} |
|
1975 |
} |
|
1976 |
} |
|
1977 |
||
1978 |
void tst_QComboBox::task190351_layout() |
|
1979 |
{ |
|
1980 |
#ifndef QT_NO_STYLE_CLEANLOOKS |
|
1981 |
const QString oldStyle = QApplication::style()->objectName(); |
|
1982 |
QApplication::setStyle(new QCleanlooksStyle); |
|
1983 |
||
1984 |
QComboBox listCombo; |
|
1985 |
QListWidget *list = new QListWidget(); |
|
1986 |
listCombo.setModel(list->model()); |
|
1987 |
listCombo.setView(list); |
|
1988 |
for(int i = 1; i < 150; i++) |
|
1989 |
list->addItem(QLatin1String("list") + QString::number(i)); |
|
1990 |
||
1991 |
listCombo.show(); |
|
1992 |
QTest::qWaitForWindowShown(&listCombo); |
|
1993 |
QTRY_VERIFY(listCombo.isVisible()); |
|
1994 |
listCombo.setCurrentIndex(70); |
|
1995 |
listCombo.showPopup(); |
|
1996 |
QTRY_VERIFY(listCombo.view()); |
|
1997 |
QTest::qWaitForWindowShown(listCombo.view()); |
|
1998 |
QTRY_VERIFY(listCombo.view()->isVisible()); |
|
1999 |
QApplication::processEvents(); |
|
2000 |
||
2001 |
#ifdef QT_BUILD_INTERNAL |
|
2002 |
QFrame *container = qFindChild<QComboBoxPrivateContainer *>(&listCombo); |
|
2003 |
QVERIFY(container); |
|
2004 |
QCOMPARE(static_cast<QAbstractItemView *>(list), qFindChild<QAbstractItemView *>(container)); |
|
2005 |
QWidget *top = qFindChild<QComboBoxPrivateScroller *>(container); |
|
2006 |
QVERIFY(top); |
|
2007 |
QVERIFY(top->isVisible()); |
|
2008 |
QCOMPARE(top->mapToGlobal(QPoint(0, top->height())).y(), list->mapToGlobal(QPoint()).y()); |
|
2009 |
#endif |
|
2010 |
||
2011 |
QApplication::setStyle(oldStyle); |
|
2012 |
#else |
|
2013 |
QSKIP("Qt configured without cleanlooks style", SkipAll); |
|
2014 |
#endif |
|
2015 |
} |
|
2016 |
||
2017 |
class task166349_ComboBox : public QComboBox |
|
2018 |
{ |
|
2019 |
Q_OBJECT |
|
2020 |
public: |
|
2021 |
task166349_ComboBox(QWidget *parent = 0) : QComboBox(parent) |
|
2022 |
{ |
|
2023 |
QStringList list; |
|
2024 |
list << "one" << "two"; |
|
2025 |
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int))); |
|
2026 |
addItems(list); |
|
2027 |
} |
|
2028 |
public slots: |
|
2029 |
void onCurrentIndexChanged(int index) |
|
2030 |
{ |
|
2031 |
setEditable(index % 2 == 1); |
|
2032 |
} |
|
2033 |
}; |
|
2034 |
||
2035 |
void tst_QComboBox::task166349_setEditableOnReturn() |
|
2036 |
{ |
|
2037 |
task166349_ComboBox comboBox; |
|
2038 |
QTest::keyClick(&comboBox, Qt::Key_Down); |
|
2039 |
QTest::keyClick(&comboBox, Qt::Key_1); |
|
2040 |
QTest::keyClick(&comboBox, Qt::Key_Enter); |
|
2041 |
QCOMPARE(QLatin1String("two1"), comboBox.itemText(comboBox.count() - 1)); |
|
2042 |
} |
|
2043 |
||
2044 |
void tst_QComboBox::task191329_size() |
|
2045 |
{ |
|
2046 |
#ifndef QT_NO_STYLE_CLEANLOOKS |
|
2047 |
const QString oldStyle = QApplication::style()->objectName(); |
|
2048 |
QApplication::setStyle(new QCleanlooksStyle); |
|
2049 |
||
2050 |
QComboBox tableCombo; |
|
2051 |
int rows; |
|
2052 |
if (QApplication::desktop()->screenGeometry().height() < 480) |
|
2053 |
rows = 8; |
|
2054 |
else |
|
2055 |
rows = 15; |
|
2056 |
||
2057 |
QStandardItemModel model(rows, 2); |
|
2058 |
for (int row = 0; row < model.rowCount(); ++row) { |
|
2059 |
for (int column = 0; column < model.columnCount(); ++column) { |
|
2060 |
QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column)); |
|
2061 |
model.setItem(row, column, item); |
|
2062 |
} |
|
2063 |
} |
|
2064 |
QTableView *table = new QTableView(); |
|
2065 |
table->verticalHeader()->hide(); |
|
2066 |
table->horizontalHeader()->hide(); |
|
2067 |
tableCombo.setView(table); |
|
2068 |
tableCombo.setModel(&model); |
|
2069 |
||
2070 |
tableCombo.show(); |
|
2071 |
QTRY_VERIFY(tableCombo.isVisible()); |
|
2072 |
tableCombo.showPopup(); |
|
2073 |
QTRY_VERIFY(tableCombo.view()); |
|
2074 |
QTRY_VERIFY(tableCombo.view()->isVisible()); |
|
2075 |
||
2076 |
#ifdef QT_BUILD_INTERNAL |
|
2077 |
QFrame *container = qFindChild<QComboBoxPrivateContainer *>(&tableCombo); |
|
2078 |
QVERIFY(container); |
|
2079 |
QCOMPARE(static_cast<QAbstractItemView *>(table), qFindChild<QAbstractItemView *>(container)); |
|
2080 |
foreach (QWidget *button, qFindChildren<QComboBoxPrivateScroller *>(container)) { |
|
2081 |
//the popup should be large enough to contains everithing so the top and left button are hidden |
|
2082 |
QVERIFY(!button->isVisible()); |
|
2083 |
} |
|
2084 |
#endif |
|
2085 |
||
2086 |
QApplication::setStyle(oldStyle); |
|
2087 |
#else |
|
2088 |
QSKIP("Qt configured without cleanlooks style", SkipAll); |
|
2089 |
#endif |
|
2090 |
} |
|
2091 |
||
2092 |
void tst_QComboBox::task190205_setModelAdjustToContents() |
|
2093 |
{ |
|
2094 |
QStringList initialContent; |
|
2095 |
QStringList finalContent; |
|
2096 |
initialContent << "foo" << "bar"; |
|
2097 |
finalContent << "bar" << "foooooooobar"; |
|
2098 |
||
2099 |
QComboBox box; |
|
2100 |
box.setSizeAdjustPolicy(QComboBox::AdjustToContents); |
|
2101 |
box.addItems(initialContent); |
|
2102 |
box.show(); |
|
2103 |
||
2104 |
//wait needed in order to get the combo initial size |
|
2105 |
QTRY_VERIFY(box.isVisible()); |
|
2106 |
||
2107 |
box.setModel(new QStringListModel(finalContent)); |
|
2108 |
||
2109 |
QComboBox correctBox; |
|
2110 |
correctBox.addItems(finalContent); |
|
2111 |
correctBox.show(); |
|
2112 |
||
2113 |
QCoreApplication::processEvents(); |
|
2114 |
#ifdef Q_WS_X11 |
|
2115 |
qt_x11_wait_for_window_manager(&box); |
|
2116 |
qt_x11_wait_for_window_manager(&correctBox); |
|
2117 |
#endif |
|
2118 |
||
2119 |
// box should be resized to the same size as correctBox |
|
2120 |
QTRY_COMPARE(box.size(), correctBox.size()); |
|
2121 |
} |
|
2122 |
||
2123 |
void tst_QComboBox::task248169_popupWithMinimalSize() |
|
2124 |
{ |
|
2125 |
QStringList initialContent; |
|
2126 |
initialContent << "foo" << "bar" << "foobar"; |
|
2127 |
||
2128 |
QComboBox comboBox; |
|
2129 |
comboBox.addItems(initialContent); |
|
2130 |
QDesktopWidget desktop; |
|
2131 |
QRect desktopSize = desktop.availableGeometry(); |
|
2132 |
comboBox.view()->setMinimumWidth(desktopSize.width() / 2); |
|
2133 |
||
2134 |
comboBox.setGeometry(desktopSize.width() - (desktopSize.width() / 4), (desktopSize.width() / 4), (desktopSize.width() / 2), (desktopSize.width() / 4)); |
|
2135 |
||
2136 |
comboBox.show(); |
|
2137 |
QTest::qWaitForWindowShown(&comboBox); |
|
2138 |
QTRY_VERIFY(comboBox.isVisible()); |
|
2139 |
comboBox.showPopup(); |
|
2140 |
QTRY_VERIFY(comboBox.view()); |
|
2141 |
QTest::qWaitForWindowShown(comboBox.view()); |
|
2142 |
QTRY_VERIFY(comboBox.view()->isVisible()); |
|
2143 |
||
2144 |
#ifdef QT_BUILD_INTERNAL |
|
2145 |
QFrame *container = qFindChild<QComboBoxPrivateContainer *>(&comboBox); |
|
2146 |
QVERIFY(container); |
|
2147 |
QTRY_VERIFY(desktop.screenGeometry(container).contains(container->geometry())); |
|
2148 |
#endif |
|
2149 |
} |
|
2150 |
||
2151 |
void tst_QComboBox::task247863_keyBoardSelection() |
|
2152 |
{ |
|
2153 |
QComboBox combo; |
|
2154 |
combo.setEditable(false); |
|
2155 |
combo.addItem( QLatin1String("111")); |
|
2156 |
combo.addItem( QLatin1String("222")); |
|
2157 |
combo.show(); |
|
2158 |
QApplication::setActiveWindow(&combo); |
|
2159 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&combo)); |
|
2160 |
||
2161 |
QSignalSpy spy(&combo, SIGNAL(activated(const QString &))); |
|
2162 |
qApp->setEffectEnabled(Qt::UI_AnimateCombo, false); |
|
2163 |
QTest::keyClick(&combo, Qt::Key_Space); |
|
2164 |
qApp->setEffectEnabled(Qt::UI_AnimateCombo, true); |
|
2165 |
QTest::keyClick(0, Qt::Key_Down); |
|
2166 |
QTest::keyClick(0, Qt::Key_Enter); |
|
2167 |
QCOMPARE(combo.currentText(), QLatin1String("222")); |
|
2168 |
QCOMPARE(spy.count(), 1); |
|
2169 |
} |
|
2170 |
||
2171 |
void tst_QComboBox::task220195_keyBoardSelection2() |
|
2172 |
{ |
|
2173 |
QComboBox combo; |
|
2174 |
combo.setEditable(false); |
|
2175 |
combo.addItem( QLatin1String("foo1")); |
|
2176 |
combo.addItem( QLatin1String("foo2")); |
|
2177 |
combo.addItem( QLatin1String("foo3")); |
|
2178 |
combo.show(); |
|
2179 |
QApplication::setActiveWindow(&combo); |
|
2180 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&combo)); |
|
2181 |
||
2182 |
combo.setCurrentIndex(-1); |
|
2183 |
QVERIFY(combo.currentText().isNull()); |
|
2184 |
||
2185 |
QTest::keyClick(&combo, 'f'); |
|
2186 |
QCOMPARE(combo.currentText(), QLatin1String("foo1")); |
|
2187 |
QTest::qWait(QApplication::keyboardInputInterval() + 30); |
|
2188 |
QTest::keyClick(&combo, 'f'); |
|
2189 |
QCOMPARE(combo.currentText(), QLatin1String("foo2")); |
|
2190 |
QTest::qWait(QApplication::keyboardInputInterval() + 30); |
|
2191 |
QTest::keyClick(&combo, 'f'); |
|
2192 |
QCOMPARE(combo.currentText(), QLatin1String("foo3")); |
|
2193 |
QTest::qWait(QApplication::keyboardInputInterval() + 30); |
|
2194 |
QTest::keyClick(&combo, 'f'); |
|
2195 |
QCOMPARE(combo.currentText(), QLatin1String("foo1")); |
|
2196 |
QTest::qWait(QApplication::keyboardInputInterval() + 30); |
|
2197 |
||
2198 |
combo.setCurrentIndex(1); |
|
2199 |
QCOMPARE(combo.currentText(), QLatin1String("foo2")); |
|
2200 |
QTest::keyClick(&combo, 'f'); |
|
2201 |
QCOMPARE(combo.currentText(), QLatin1String("foo3")); |
|
2202 |
} |
|
2203 |
||
2204 |
||
2205 |
void tst_QComboBox::setModelColumn() |
|
2206 |
{ |
|
2207 |
QStandardItemModel model(5,3); |
|
2208 |
model.setItem(0,0, new QStandardItem("0")); |
|
2209 |
model.setItem(1,0, new QStandardItem("1")); |
|
2210 |
model.setItem(2,0, new QStandardItem("2")); |
|
2211 |
model.setItem(3,0, new QStandardItem("3")); |
|
2212 |
model.setItem(4,0, new QStandardItem("4")); |
|
2213 |
model.setItem(0,1, new QStandardItem("zero")); |
|
2214 |
model.setItem(1,1, new QStandardItem("un")); |
|
2215 |
model.setItem(2,1, new QStandardItem("deux")); |
|
2216 |
model.setItem(3,1, new QStandardItem("trois")); |
|
2217 |
model.setItem(4,1, new QStandardItem("quatre")); |
|
2218 |
model.setItem(0,2, new QStandardItem("a")); |
|
2219 |
model.setItem(1,2, new QStandardItem("b")); |
|
2220 |
model.setItem(2,2, new QStandardItem("c")); |
|
2221 |
model.setItem(3,2, new QStandardItem("d")); |
|
2222 |
model.setItem(4,2, new QStandardItem("e")); |
|
2223 |
||
2224 |
QComboBox box; |
|
2225 |
box.setModel(&model); |
|
2226 |
QCOMPARE(box.currentText(), QString("0")); |
|
2227 |
box.setModelColumn(1); |
|
2228 |
QCOMPARE(box.currentText(), QString("zero")); |
|
2229 |
} |
|
2230 |
||
2231 |
void tst_QComboBox::noScrollbar_data() |
|
2232 |
{ |
|
2233 |
QTest::addColumn<QString>("stylesheet"); |
|
2234 |
||
2235 |
QTest::newRow("normal") << QString(); |
|
2236 |
QTest::newRow("border") << QString::fromLatin1("QAbstractItemView { border: 12px solid blue;}"); |
|
2237 |
QTest::newRow("margin") << QString::fromLatin1("QAbstractItemView { margin: 12px 15px 13px 10px; }"); |
|
2238 |
QTest::newRow("padding") << QString::fromLatin1("QAbstractItemView { padding: 12px 15px 13px 10px;}"); |
|
2239 |
QTest::newRow("everything") << QString::fromLatin1("QAbstractItemView { border: 12px solid blue; " |
|
2240 |
" padding: 12px 15px 13px 10px; margin: 12px 15px 13px 10px; }"); |
|
2241 |
QTest::newRow("everything and more") << QString::fromLatin1("QAbstractItemView { border: 1px 3px 5px 1px solid blue; " |
|
2242 |
" padding: 2px 5px 3px 1px; margin: 2px 5px 3px 1px; } " |
|
2243 |
" QAbstractItemView::item { border: 2px solid green; " |
|
2244 |
" padding: 1px 1px 2px 2px; margin: 1px; } " ); |
|
2245 |
} |
|
2246 |
||
2247 |
void tst_QComboBox::noScrollbar() |
|
2248 |
{ |
|
2249 |
QStringList initialContent; |
|
2250 |
initialContent << "foo" << "bar" << "foobar" << "moo"; |
|
2251 |
QFETCH(QString, stylesheet); |
|
2252 |
QString oldCss = qApp->styleSheet(); |
|
2253 |
qApp->setStyleSheet(stylesheet); |
|
2254 |
||
2255 |
{ |
|
2256 |
QComboBox comboBox; |
|
2257 |
comboBox.addItems(initialContent); |
|
2258 |
comboBox.show(); |
|
2259 |
comboBox.resize(200, comboBox.height()); |
|
2260 |
QTRY_VERIFY(comboBox.isVisible()); |
|
2261 |
comboBox.showPopup(); |
|
2262 |
QTRY_VERIFY(comboBox.view()); |
|
2263 |
QTRY_VERIFY(comboBox.view()->isVisible()); |
|
2264 |
||
2265 |
QVERIFY(!comboBox.view()->horizontalScrollBar()->isVisible()); |
|
2266 |
QVERIFY(!comboBox.view()->verticalScrollBar()->isVisible()); |
|
2267 |
} |
|
2268 |
||
2269 |
{ |
|
2270 |
QTableWidget *table = new QTableWidget(2,2); |
|
2271 |
QComboBox comboBox; |
|
2272 |
comboBox.setModel(table->model()); |
|
2273 |
comboBox.setView(table); |
|
2274 |
comboBox.show(); |
|
2275 |
QTRY_VERIFY(comboBox.isVisible()); |
|
2276 |
comboBox.resize(200, comboBox.height()); |
|
2277 |
comboBox.showPopup(); |
|
2278 |
QTRY_VERIFY(comboBox.view()); |
|
2279 |
QTRY_VERIFY(comboBox.view()->isVisible()); |
|
2280 |
||
2281 |
QVERIFY(!comboBox.view()->horizontalScrollBar()->isVisible()); |
|
2282 |
QVERIFY(!comboBox.view()->verticalScrollBar()->isVisible()); |
|
2283 |
} |
|
2284 |
||
2285 |
qApp->setStyleSheet(oldCss); |
|
2286 |
} |
|
2287 |
||
2288 |
void tst_QComboBox::setItemDelegate() |
|
2289 |
{ |
|
2290 |
QComboBox comboBox; |
|
2291 |
QStyledItemDelegate *itemDelegate = new QStyledItemDelegate; |
|
2292 |
comboBox.setItemDelegate(itemDelegate); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2293 |
// the cast is a workaround for the XLC and Metrowerks compilers |
0 | 2294 |
QCOMPARE(static_cast<QStyledItemDelegate *>(comboBox.itemDelegate()), itemDelegate); |
2295 |
} |
|
2296 |
||
2297 |
void tst_QComboBox::task253944_itemDelegateIsReset() |
|
2298 |
{ |
|
2299 |
QComboBox comboBox; |
|
2300 |
QStyledItemDelegate *itemDelegate = new QStyledItemDelegate; |
|
2301 |
comboBox.setItemDelegate(itemDelegate); |
|
2302 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2303 |
// the casts are workarounds for the XLC and Metrowerks compilers |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2304 |
|
0 | 2305 |
comboBox.setEditable(true); |
2306 |
QCOMPARE(static_cast<QStyledItemDelegate *>(comboBox.itemDelegate()), itemDelegate); |
|
2307 |
||
2308 |
comboBox.setStyleSheet("QComboBox { border: 1px solid gray; }"); |
|
2309 |
QCOMPARE(static_cast<QStyledItemDelegate *>(comboBox.itemDelegate()), itemDelegate); |
|
2310 |
} |
|
2311 |
||
2312 |
||
2313 |
void tst_QComboBox::subControlRectsWithOffset_data() |
|
2314 |
{ |
|
2315 |
QTest::addColumn<bool>("editable"); |
|
2316 |
||
2317 |
QTest::newRow("editable = true") << true; |
|
2318 |
QTest::newRow("editable = false") << false; |
|
2319 |
} |
|
2320 |
||
2321 |
void tst_QComboBox::subControlRectsWithOffset() |
|
2322 |
{ |
|
2323 |
// The sub control rect relative position should not depends |
|
2324 |
// on the position of the combobox |
|
2325 |
||
2326 |
class FriendlyCombo : public QComboBox { |
|
2327 |
public: |
|
2328 |
void styleOption(QStyleOptionComboBox *optCombo) { |
|
2329 |
initStyleOption(optCombo); |
|
2330 |
} |
|
2331 |
} combo; |
|
2332 |
QStyleOptionComboBox optCombo; |
|
2333 |
combo.styleOption(&optCombo); |
|
2334 |
||
2335 |
||
2336 |
const QRect rectAtOrigin(0, 0, 80, 30); |
|
2337 |
const QPoint offset(25, 50); |
|
2338 |
const QRect rectWithOffset = rectAtOrigin.translated(offset); |
|
2339 |
||
2340 |
QStyle *style = combo.style(); |
|
2341 |
||
2342 |
QFETCH(bool, editable); |
|
2343 |
optCombo.editable = editable; |
|
2344 |
||
2345 |
optCombo.rect = rectAtOrigin; |
|
2346 |
QRect editFieldRect = style->subControlRect(QStyle::CC_ComboBox, &optCombo, QStyle::SC_ComboBoxEditField, 0); |
|
2347 |
QRect arrowRect = style->subControlRect(QStyle::CC_ComboBox, &optCombo, QStyle::SC_ComboBoxArrow, 0); |
|
2348 |
QRect listboxRect = style->subControlRect(QStyle::CC_ComboBox, &optCombo, QStyle::SC_ComboBoxListBoxPopup, 0); |
|
2349 |
||
2350 |
optCombo.rect = rectWithOffset; |
|
2351 |
QRect editFieldRectWithOffset = style->subControlRect(QStyle::CC_ComboBox, &optCombo, QStyle::SC_ComboBoxEditField, 0); |
|
2352 |
QRect arrowRectWithOffset = style->subControlRect(QStyle::CC_ComboBox, &optCombo, QStyle::SC_ComboBoxArrow, 0); |
|
2353 |
QRect listboxRectWithOffset = style->subControlRect(QStyle::CC_ComboBox, &optCombo, QStyle::SC_ComboBoxListBoxPopup, 0); |
|
2354 |
||
2355 |
QCOMPARE(editFieldRect, editFieldRectWithOffset.translated(-offset)); |
|
2356 |
QCOMPARE(arrowRect, arrowRectWithOffset.translated(-offset)); |
|
2357 |
QCOMPARE(listboxRect, listboxRectWithOffset.translated(-offset)); |
|
2358 |
||
2359 |
} |
|
2360 |
||
2361 |
void tst_QComboBox::task260974_menuItemRectangleForComboBoxPopup() |
|
2362 |
{ |
|
2363 |
#ifdef QT_NO_STYLE_WINDOWS |
|
2364 |
QSKIP("test depends on windows style", QTest::SkipAll); |
|
2365 |
#else |
|
2366 |
class TestStyle: public QWindowsStyle |
|
2367 |
{ |
|
2368 |
public: |
|
2369 |
int styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *ret) const |
|
2370 |
{ |
|
2371 |
if (hint == SH_ComboBox_Popup) return 1; |
|
2372 |
else return QCommonStyle::styleHint(hint, option, widget, ret); |
|
2373 |
} |
|
2374 |
||
2375 |
void drawControl(ControlElement element, const QStyleOption *option, QPainter *, const QWidget *) const |
|
2376 |
{ |
|
2377 |
if (element == CE_MenuItem) |
|
2378 |
discoveredRect = option->rect; |
|
2379 |
} |
|
2380 |
||
2381 |
mutable QRect discoveredRect; |
|
2382 |
} style; |
|
2383 |
||
2384 |
||
2385 |
{ |
|
2386 |
QComboBox comboBox; |
|
2387 |
comboBox.setStyle(&style); |
|
2388 |
comboBox.addItem("Item 1"); |
|
2389 |
||
2390 |
comboBox.show(); |
|
2391 |
QTRY_VERIFY(comboBox.isVisible()); |
|
2392 |
comboBox.showPopup(); |
|
2393 |
QTRY_VERIFY(comboBox.view()); |
|
2394 |
QTRY_VERIFY(comboBox.view()->isVisible()); |
|
2395 |
||
2396 |
QTRY_VERIFY(style.discoveredRect.width() <= comboBox.width()); |
|
2397 |
} |
|
2398 |
#endif |
|
2399 |
} |
|
2400 |
||
2401 |
void tst_QComboBox::removeItem() |
|
2402 |
{ |
|
2403 |
QComboBox cb; |
|
2404 |
cb.removeItem(-1); |
|
2405 |
cb.removeItem(1); |
|
2406 |
cb.removeItem(0); |
|
2407 |
QCOMPARE(cb.count(), 0); |
|
2408 |
||
2409 |
cb.addItem("foo"); |
|
2410 |
cb.removeItem(-1); |
|
2411 |
QCOMPARE(cb.count(), 1); |
|
2412 |
cb.removeItem(1); |
|
2413 |
QCOMPARE(cb.count(), 1); |
|
2414 |
cb.removeItem(0); |
|
2415 |
QCOMPARE(cb.count(), 0); |
|
2416 |
} |
|
2417 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2418 |
void tst_QComboBox::resetModel() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2419 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2420 |
class StringListModel : public QStringListModel |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2421 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2422 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2423 |
StringListModel(const QStringList &list) : QStringListModel(list) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2424 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2425 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2426 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2427 |
void reset() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2428 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2429 |
QStringListModel::reset(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2430 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2431 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2432 |
QComboBox cb; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2433 |
StringListModel model( QStringList() << "1" << "2"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2434 |
QSignalSpy spy(&cb, SIGNAL(currentIndexChanged(int))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2435 |
QCOMPARE(spy.count(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2436 |
QCOMPARE(cb.currentIndex(), -1); //no selection |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2437 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2438 |
cb.setModel(&model); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2439 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2440 |
QCOMPARE(spy.count(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2441 |
QCOMPARE(cb.currentIndex(), 0); //first item selected |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2442 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2443 |
model.reset(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2444 |
QCOMPARE(spy.count(), 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2445 |
QCOMPARE(cb.currentIndex(), -1); //no selection |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2446 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2447 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2448 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2449 |
void tst_QComboBox::keyBoardNavigationWithMouse() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2450 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2451 |
QComboBox combo; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2452 |
combo.setEditable(false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2453 |
for (int i = 0; i < 80; i++) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2454 |
combo.addItem( QString::number(i)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2455 |
combo.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2456 |
QApplication::setActiveWindow(&combo); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2457 |
QTest::qWaitForWindowShown(&combo); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2458 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&combo)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2459 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2460 |
QCOMPARE(combo.currentText(), QLatin1String("0")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2461 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2462 |
combo.setFocus(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2463 |
QTRY_VERIFY(combo.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2464 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2465 |
QTest::keyClick(testWidget->lineEdit(), Qt::Key_Space); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2466 |
QTest::qWait(30); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2467 |
QTRY_VERIFY(combo.view()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2468 |
QTRY_VERIFY(combo.view()->isVisible()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2469 |
QTest::qWait(130); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2470 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2471 |
QCOMPARE(combo.currentText(), QLatin1String("0")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2472 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2473 |
#ifdef Q_OS_WINCE |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2474 |
QSKIP("When calling cursor function, Windows CE responds with: This function is not supported on this system.", SkipAll); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2475 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2476 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2477 |
QCursor::setPos(combo.view()->mapToGlobal(combo.view()->rect().center())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2478 |
QTest::qWait(200); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2479 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2480 |
#define GET_SELECTION(SEL) \ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2481 |
QCOMPARE(combo.view()->selectionModel()->selection().count(), 1); \ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2482 |
QCOMPARE(combo.view()->selectionModel()->selection().indexes().count(), 1); \ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2483 |
SEL = combo.view()->selectionModel()->selection().indexes().first().row() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2484 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2485 |
int selection; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2486 |
GET_SELECTION(selection); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2487 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2488 |
//since we moved the mouse is in the middle it should even be around 5; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2489 |
QVERIFY(selection > 3); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2490 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2491 |
static const int final = 40; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2492 |
for (int i = selection + 1; i <= final; i++) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2493 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2494 |
QTest::keyClick(combo.view(), Qt::Key_Down); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2495 |
QTest::qWait(20); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2496 |
GET_SELECTION(selection); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2497 |
QCOMPARE(selection, i); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2498 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2499 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2500 |
QTest::keyClick(combo.view(), Qt::Key_Enter); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2501 |
QTRY_COMPARE(combo.currentText(), QString::number(final)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2502 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2503 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2504 |
void tst_QComboBox::task_QTBUG_1071_changingFocusEmitsActivated() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2505 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2506 |
QWidget w; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2507 |
QVBoxLayout layout(&w); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2508 |
QComboBox cb; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2509 |
cb.setEditable(true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2510 |
QSignalSpy spy(&cb, SIGNAL(activated(int))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2511 |
cb.addItem("0"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2512 |
cb.addItem("1"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2513 |
cb.addItem("2"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2514 |
QLineEdit edit; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2515 |
layout.addWidget(&cb); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2516 |
layout.addWidget(&edit); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2517 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2518 |
w.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2519 |
QApplication::setActiveWindow(&w); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2520 |
QTest::qWaitForWindowShown(&w); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2521 |
cb.clearEditText(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2522 |
cb.setFocus(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2523 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2524 |
QTRY_VERIFY(cb.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2525 |
QTest::keyClick(0, '1'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2526 |
QCOMPARE(spy.count(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2527 |
edit.setFocus(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2528 |
QTRY_VERIFY(edit.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2529 |
QTRY_COMPARE(spy.count(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2530 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2531 |
|
0 | 2532 |
QTEST_MAIN(tst_QComboBox) |
2533 |
#include "tst_qcombobox.moc" |