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