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