author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 0 | 1918ee327afb |
child 7 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
||
45 |
#include <qcoreapplication.h> |
|
46 |
#include <qdebug.h> |
|
47 |
#include <qfiledialog.h> |
|
48 |
#include <qabstractitemdelegate.h> |
|
49 |
#include <qdirmodel.h> |
|
50 |
#include <qitemdelegate.h> |
|
51 |
#include <qlistview.h> |
|
52 |
#include <qcombobox.h> |
|
53 |
#include <qpushbutton.h> |
|
54 |
#include <qtoolbutton.h> |
|
55 |
#include <qtreeview.h> |
|
56 |
#include <qheaderview.h> |
|
57 |
#include <qcompleter.h> |
|
58 |
#include <qaction.h> |
|
59 |
#include <qdialogbuttonbox.h> |
|
60 |
#include <qsortfilterproxymodel.h> |
|
61 |
#include <qlineedit.h> |
|
62 |
#include <qlayout.h> |
|
63 |
#include "../../shared/util.h" |
|
64 |
#include "../../../src/gui/dialogs/qsidebar_p.h" |
|
65 |
#include "../../../src/gui/dialogs/qfilesystemmodel_p.h" |
|
66 |
#include "../../../src/gui/dialogs/qfiledialog_p.h" |
|
67 |
||
68 |
#include "../network-settings.h" |
|
69 |
||
70 |
//TESTED_CLASS= |
|
71 |
//TESTED_FILES= |
|
72 |
||
73 |
#if defined(Q_OS_SYMBIAN) |
|
74 |
# define STRINGIFY(x) #x |
|
75 |
# define TOSTRING(x) STRINGIFY(x) |
|
76 |
# define SRCDIR "C:/Private/" TOSTRING(SYMBIAN_SRCDIR_UID) "/" |
|
77 |
#endif |
|
78 |
||
79 |
class QNonNativeFileDialog : public QFileDialog |
|
80 |
{ |
|
81 |
Q_OBJECT |
|
82 |
public: |
|
83 |
QNonNativeFileDialog(QWidget *parent = 0, const QString &caption = QString(), const QString &directory = QString(), const QString &filter = QString()) |
|
84 |
: QFileDialog(parent, caption, directory, filter) |
|
85 |
{ |
|
86 |
setOption(QFileDialog::DontUseNativeDialog, true); |
|
87 |
} |
|
88 |
}; |
|
89 |
||
90 |
class tst_QFiledialog : public QObject |
|
91 |
{ |
|
92 |
Q_OBJECT |
|
93 |
||
94 |
public: |
|
95 |
tst_QFiledialog(); |
|
96 |
virtual ~tst_QFiledialog(); |
|
97 |
||
98 |
public slots: |
|
99 |
void init(); |
|
100 |
void cleanup(); |
|
101 |
||
102 |
private slots: |
|
103 |
void currentChangedSignal(); |
|
104 |
void directoryEnteredSignal(); |
|
105 |
void filesSelectedSignal_data(); |
|
106 |
void filesSelectedSignal(); |
|
107 |
void filterSelectedSignal(); |
|
108 |
||
109 |
void args(); |
|
110 |
void directory(); |
|
111 |
void completer_data(); |
|
112 |
void completer(); |
|
113 |
void completer_up(); |
|
114 |
void acceptMode(); |
|
115 |
void confirmOverwrite(); |
|
116 |
void defaultSuffix(); |
|
117 |
void fileMode(); |
|
118 |
void filters(); |
|
119 |
void history(); |
|
120 |
void iconProvider(); |
|
121 |
void isReadOnly(); |
|
122 |
void itemDelegate(); |
|
123 |
void labelText(); |
|
124 |
void resolveSymlinks(); |
|
125 |
void selectFile_data(); |
|
126 |
void selectFile(); |
|
127 |
void selectFiles(); |
|
128 |
void selectFilter(); |
|
129 |
void viewMode(); |
|
130 |
void proxymodel(); |
|
131 |
void setNameFilter(); |
|
132 |
void focus(); |
|
133 |
void caption(); |
|
134 |
void historyBack(); |
|
135 |
void historyForward(); |
|
136 |
void disableSaveButton_data(); |
|
137 |
void disableSaveButton(); |
|
138 |
void saveButtonText_data(); |
|
139 |
void saveButtonText(); |
|
140 |
void clearLineEdit(); |
|
141 |
void enableChooseButton(); |
|
142 |
void hooks(); |
|
143 |
||
144 |
private: |
|
145 |
QByteArray userSettings; |
|
146 |
}; |
|
147 |
||
148 |
tst_QFiledialog::tst_QFiledialog() |
|
149 |
{ |
|
150 |
} |
|
151 |
||
152 |
tst_QFiledialog::~tst_QFiledialog() |
|
153 |
{ |
|
154 |
} |
|
155 |
||
156 |
void tst_QFiledialog::init() |
|
157 |
{ |
|
158 |
// Save the developers settings so they don't get mad when their sidebar folders are gone. |
|
159 |
QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); |
|
160 |
settings.beginGroup(QLatin1String("Qt")); |
|
161 |
userSettings = settings.value(QLatin1String("filedialog")).toByteArray(); |
|
162 |
settings.remove(QLatin1String("filedialog")); |
|
163 |
||
164 |
// populate it with some default settings |
|
165 |
QNonNativeFileDialog fd; |
|
166 |
#if defined(Q_OS_WINCE) |
|
167 |
QTest::qWait(1000); |
|
168 |
#endif |
|
169 |
} |
|
170 |
||
171 |
void tst_QFiledialog::cleanup() |
|
172 |
{ |
|
173 |
QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); |
|
174 |
settings.beginGroup(QLatin1String("Qt")); |
|
175 |
settings.setValue(QLatin1String("filedialog"), userSettings); |
|
176 |
} |
|
177 |
||
178 |
class MyAbstractItemDelegate : public QAbstractItemDelegate |
|
179 |
{ |
|
180 |
public: |
|
181 |
MyAbstractItemDelegate() : QAbstractItemDelegate() {}; |
|
182 |
void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const {} |
|
183 |
QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const { return QSize(); } |
|
184 |
}; |
|
185 |
||
186 |
// emited any time the selection model emits current changed |
|
187 |
void tst_QFiledialog::currentChangedSignal() |
|
188 |
{ |
|
189 |
QNonNativeFileDialog fd; |
|
190 |
fd.setViewMode(QFileDialog::List); |
|
191 |
QSignalSpy spyCurrentChanged(&fd, SIGNAL(currentChanged(const QString &))); |
|
192 |
||
193 |
QListView* listView = qFindChild<QListView*>(&fd, "listView"); |
|
194 |
QVERIFY(listView); |
|
195 |
fd.setDirectory(QDir::root()); |
|
196 |
QModelIndex root = listView->rootIndex(); |
|
197 |
QTRY_COMPARE(listView->model()->rowCount(root) > 0, true); |
|
198 |
||
199 |
QModelIndex folder; |
|
200 |
for (int i = 0; i < listView->model()->rowCount(root); ++i) { |
|
201 |
folder = listView->model()->index(i, 0, root); |
|
202 |
if (listView->model()->hasChildren(folder)) |
|
203 |
break; |
|
204 |
} |
|
205 |
QVERIFY(listView->model()->hasChildren(folder)); |
|
206 |
listView->setCurrentIndex(folder); |
|
207 |
||
208 |
QCOMPARE(spyCurrentChanged.count(), 1); |
|
209 |
} |
|
210 |
||
211 |
// only emited from the views, sidebar, or lookin combo |
|
212 |
void tst_QFiledialog::directoryEnteredSignal() |
|
213 |
{ |
|
214 |
#if defined QT_BUILD_INTERNAL |
|
215 |
QNonNativeFileDialog fd(0, "", QDir::root().path()); |
|
216 |
fd.setOptions(QFileDialog::DontUseNativeDialog); |
|
217 |
fd.show(); |
|
218 |
QTRY_COMPARE(fd.isVisible(), true); |
|
219 |
QSignalSpy spyDirectoryEntered(&fd, SIGNAL(directoryEntered(const QString &))); |
|
220 |
||
221 |
// sidebar |
|
222 |
QSidebar *sidebar = qFindChild<QSidebar*>(&fd, "sidebar"); |
|
223 |
sidebar->setCurrentIndex(sidebar->model()->index(1, 0)); |
|
224 |
QTest::keyPress(sidebar->viewport(), Qt::Key_Return); |
|
225 |
QCOMPARE(spyDirectoryEntered.count(), 1); |
|
226 |
spyDirectoryEntered.clear(); |
|
227 |
||
228 |
// lookInCombo |
|
229 |
QComboBox *comboBox = qFindChild<QComboBox*>(&fd, "lookInCombo"); |
|
230 |
comboBox->showPopup(); |
|
231 |
QVERIFY(comboBox->view()->model()->index(1, 0).isValid()); |
|
232 |
comboBox->view()->setCurrentIndex(comboBox->view()->model()->index(1, 0)); |
|
233 |
QTest::keyPress(comboBox->view()->viewport(), Qt::Key_Return); |
|
234 |
QCOMPARE(spyDirectoryEntered.count(), 1); |
|
235 |
spyDirectoryEntered.clear(); |
|
236 |
||
237 |
// view |
|
238 |
/* |
|
239 |
// platform specific |
|
240 |
fd.setViewMode(QFileDialog::ViewMode(QFileDialog::List)); |
|
241 |
QListView* listView = qFindChild<QListView*>(&fd, "listView"); |
|
242 |
QVERIFY(listView); |
|
243 |
QModelIndex root = listView->rootIndex(); |
|
244 |
QTRY_COMPARE(listView->model()->rowCount(root) > 0, true); |
|
245 |
||
246 |
QModelIndex folder; |
|
247 |
for (int i = 0; i < listView->model()->rowCount(root); ++i) { |
|
248 |
folder = listView->model()->index(i, 0, root); |
|
249 |
if (listView->model()->hasChildren(folder)) |
|
250 |
break; |
|
251 |
} |
|
252 |
QVERIFY(listView->model()->hasChildren(folder)); |
|
253 |
listView->setCurrentIndex(folder); |
|
254 |
QTRY_COMPARE((listView->indexAt(listView->visualRect(folder).center())), folder); |
|
255 |
QTest::mouseDClick(listView->viewport(), Qt::LeftButton, 0, listView->visualRect(folder).center()); |
|
256 |
QTRY_COMPARE(spyDirectoryEntered.count(), 1); |
|
257 |
*/ |
|
258 |
#endif |
|
259 |
} |
|
260 |
||
261 |
Q_DECLARE_METATYPE(QFileDialog::FileMode) |
|
262 |
void tst_QFiledialog::filesSelectedSignal_data() |
|
263 |
{ |
|
264 |
QTest::addColumn<QFileDialog::FileMode>("fileMode"); |
|
265 |
QTest::newRow("any") << QFileDialog::AnyFile; |
|
266 |
QTest::newRow("existing") << QFileDialog::ExistingFile; |
|
267 |
QTest::newRow("directory") << QFileDialog::Directory; |
|
268 |
QTest::newRow("directoryOnly") << QFileDialog::DirectoryOnly; |
|
269 |
QTest::newRow("existingFiles") << QFileDialog::ExistingFiles; |
|
270 |
} |
|
271 |
||
272 |
// emited when the dialog closes with the selected files |
|
273 |
void tst_QFiledialog::filesSelectedSignal() |
|
274 |
{ |
|
275 |
QNonNativeFileDialog fd; |
|
276 |
fd.setViewMode(QFileDialog::List); |
|
277 |
fd.setOptions(QFileDialog::DontUseNativeDialog); |
|
278 |
QDir testDir(SRCDIR"/../../.."); |
|
279 |
fd.setDirectory(testDir); |
|
280 |
QFETCH(QFileDialog::FileMode, fileMode); |
|
281 |
fd.setFileMode(fileMode); |
|
282 |
QSignalSpy spyFilesSelected(&fd, SIGNAL(filesSelected(const QStringList &))); |
|
283 |
||
284 |
fd.show(); |
|
285 |
QTest::qWait(500); |
|
286 |
QListView *listView = qFindChild<QListView*>(&fd, "listView"); |
|
287 |
QVERIFY(listView); |
|
288 |
||
289 |
QModelIndex root = listView->rootIndex(); |
|
290 |
QTRY_COMPARE(listView->model()->rowCount(root) > 0, true); |
|
291 |
QModelIndex file; |
|
292 |
for (int i = 0; i < listView->model()->rowCount(root); ++i) { |
|
293 |
file = listView->model()->index(i, 0, root); |
|
294 |
if (fileMode == QFileDialog::Directory || fileMode == QFileDialog::DirectoryOnly) { |
|
295 |
if (listView->model()->hasChildren(file)) |
|
296 |
break; |
|
297 |
} else { |
|
298 |
if (!listView->model()->hasChildren(file)) |
|
299 |
break; |
|
300 |
} |
|
301 |
file = QModelIndex(); |
|
302 |
} |
|
303 |
QVERIFY(file.isValid()); |
|
304 |
listView->selectionModel()->select(file, QItemSelectionModel::Select | QItemSelectionModel::Rows); |
|
305 |
listView->setCurrentIndex(file); |
|
306 |
||
307 |
QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(&fd, "buttonBox"); |
|
308 |
QPushButton *button = buttonBox->button(QDialogButtonBox::Open); |
|
309 |
QVERIFY(button); |
|
310 |
QVERIFY(button->isEnabled()); |
|
311 |
button->animateClick(); |
|
312 |
QTRY_COMPARE(fd.isVisible(), false); |
|
313 |
QCOMPARE(spyFilesSelected.count(), 1); |
|
314 |
} |
|
315 |
||
316 |
// only emited when the combo box is activated |
|
317 |
void tst_QFiledialog::filterSelectedSignal() |
|
318 |
{ |
|
319 |
QNonNativeFileDialog fd; |
|
320 |
fd.setAcceptMode(QFileDialog::AcceptSave); |
|
321 |
fd.show(); |
|
322 |
QSignalSpy spyFilterSelected(&fd, SIGNAL(filterSelected(const QString &))); |
|
323 |
||
324 |
QStringList filterChoices; |
|
325 |
filterChoices << "Image files (*.png *.xpm *.jpg)" |
|
326 |
<< "Text files (*.txt)" |
|
327 |
<< "Any files (*.*)"; |
|
328 |
fd.setFilters(filterChoices); |
|
329 |
QCOMPARE(fd.filters(), filterChoices); |
|
330 |
||
331 |
QComboBox *filters = qFindChild<QComboBox*>(&fd, "fileTypeCombo"); |
|
332 |
QVERIFY(filters); |
|
333 |
QVERIFY(filters->view()); |
|
334 |
QCOMPARE(filters->isVisible(), true); |
|
335 |
||
336 |
QTest::keyPress(filters, Qt::Key_Down); |
|
337 |
||
338 |
QCOMPARE(spyFilterSelected.count(), 1); |
|
339 |
} |
|
340 |
||
341 |
void tst_QFiledialog::args() |
|
342 |
{ |
|
343 |
QWidget *parent = 0; |
|
344 |
QString caption = "caption"; |
|
345 |
QString directory = QDir::tempPath(); |
|
346 |
QString filter = "*.mp3"; |
|
347 |
QNonNativeFileDialog fd(parent, caption, directory, filter); |
|
348 |
QCOMPARE(fd.parent(), (QObject *)parent); |
|
349 |
QCOMPARE(fd.windowTitle(), caption); |
|
350 |
#ifndef Q_OS_WIN |
|
351 |
QCOMPARE(fd.directory(), QDir(directory)); |
|
352 |
#endif |
|
353 |
QCOMPARE(fd.filters(), QStringList(filter)); |
|
354 |
} |
|
355 |
||
356 |
void tst_QFiledialog::directory() |
|
357 |
{ |
|
358 |
QNonNativeFileDialog fd; |
|
359 |
fd.setViewMode(QFileDialog::List); |
|
360 |
QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model"); |
|
361 |
QVERIFY(model); |
|
362 |
fd.setDirectory(QDir::currentPath()); |
|
363 |
QSignalSpy spyCurrentChanged(&fd, SIGNAL(currentChanged(const QString &))); |
|
364 |
QSignalSpy spyDirectoryEntered(&fd, SIGNAL(directoryEntered(const QString &))); |
|
365 |
QSignalSpy spyFilesSelected(&fd, SIGNAL(filesSelected(const QStringList &))); |
|
366 |
QSignalSpy spyFilterSelected(&fd, SIGNAL(filterSelected(const QString &))); |
|
367 |
||
368 |
QCOMPARE(QDir::current().absolutePath(), fd.directory().absolutePath()); |
|
369 |
QDir temp = QDir::temp(); |
|
370 |
QString tempPath = temp.absolutePath(); |
|
371 |
#ifdef Q_OS_WIN |
|
372 |
// since the user can have lowercase temp dir, check that we are actually case-insensitive. |
|
373 |
tempPath = tempPath.toLower(); |
|
374 |
#endif |
|
375 |
fd.setDirectory(tempPath); |
|
376 |
#ifndef Q_OS_WIN |
|
377 |
QCOMPARE(tempPath, fd.directory().absolutePath()); |
|
378 |
#endif |
|
379 |
QCOMPARE(spyCurrentChanged.count(), 0); |
|
380 |
QCOMPARE(spyDirectoryEntered.count(), 0); |
|
381 |
QCOMPARE(spyFilesSelected.count(), 0); |
|
382 |
QCOMPARE(spyFilterSelected.count(), 0); |
|
383 |
||
384 |
// Check my way |
|
385 |
QList<QListView*> list = qFindChildren<QListView*>(&fd, "listView"); |
|
386 |
QVERIFY(list.count() > 0); |
|
387 |
#ifdef Q_OS_WIN |
|
388 |
QCOMPARE(list.at(0)->rootIndex().data().toString().toLower(), temp.dirName().toLower()); |
|
389 |
#else |
|
390 |
QCOMPARE(list.at(0)->rootIndex().data().toString(), temp.dirName()); |
|
391 |
#endif |
|
392 |
QNonNativeFileDialog *dlg = new QNonNativeFileDialog(0, "", tempPath); |
|
393 |
QCOMPARE(model->index(tempPath), model->index(dlg->directory().absolutePath())); |
|
394 |
QCOMPARE(model->index(tempPath).data(QFileSystemModel::FileNameRole).toString(), |
|
395 |
model->index(dlg->directory().absolutePath()).data(QFileSystemModel::FileNameRole).toString()); |
|
396 |
delete dlg; |
|
397 |
dlg = new QNonNativeFileDialog(); |
|
398 |
QCOMPARE(model->index(tempPath), model->index(dlg->directory().absolutePath())); |
|
399 |
delete dlg; |
|
400 |
} |
|
401 |
||
402 |
void tst_QFiledialog::completer_data() |
|
403 |
{ |
|
404 |
QTest::addColumn<QString>("startPath"); |
|
405 |
QTest::addColumn<QString>("input"); |
|
406 |
QTest::addColumn<int>("expected"); |
|
407 |
||
408 |
QTest::newRow("r, 10") << "" << "r" << 10; |
|
409 |
QTest::newRow("x, 0") << "" << "x" << 0; |
|
410 |
QTest::newRow("../, -1") << "" << "../" << -1; |
|
411 |
||
412 |
QTest::newRow("goto root") << QString() << QDir::rootPath() << -1; |
|
413 |
QTest::newRow("start at root") << QDir::rootPath() << QString() << -1; |
|
414 |
||
415 |
QDir root = QDir::root(); |
|
416 |
QStringList list = root.entryList(); |
|
417 |
QString folder; |
|
418 |
for (int i = 0; i < list.count(); ++i) { |
|
419 |
if (list.at(0) == QChar('.')) |
|
420 |
continue; |
|
421 |
QFileInfo info(QDir::rootPath() + list[i]); |
|
422 |
if (info.isDir()) { |
|
423 |
folder = QDir::rootPath() + list[i]; |
|
424 |
break; |
|
425 |
} |
|
426 |
} |
|
427 |
||
428 |
QTest::newRow("start at one below root r") << folder << "r" << -1; |
|
429 |
QTest::newRow("start at one below root ../") << folder << "../" << -1; |
|
430 |
} |
|
431 |
||
432 |
void tst_QFiledialog::completer() |
|
433 |
{ |
|
434 |
QFETCH(QString, input); |
|
435 |
QFETCH(QString, startPath); |
|
436 |
QFETCH(int, expected); |
|
437 |
||
438 |
QString tempPath = QDir::tempPath() + '/' + "QFileDialogTestDir"; |
|
439 |
if (startPath.isEmpty()) |
|
440 |
startPath = tempPath; |
|
441 |
||
442 |
startPath = QDir::cleanPath(startPath); |
|
443 |
||
444 |
// make temp dir and files |
|
445 |
{ |
|
446 |
QDir cleanup(tempPath); |
|
447 |
QStringList x = cleanup.entryList(); |
|
448 |
for (int i = 0; i < x.count(); ++i) |
|
449 |
QFile::remove(tempPath + '/' + x[i]); |
|
450 |
cleanup.rmdir(tempPath); |
|
451 |
} |
|
452 |
QDir tmp(QDir::tempPath()); |
|
453 |
if (!tmp.exists(tempPath)) |
|
454 |
QVERIFY(tmp.mkdir("QFileDialogTestDir")); |
|
455 |
QList<QTemporaryFile*> files; |
|
456 |
QT_TRY { |
|
457 |
for (int i = 0; i < 10; ++i) { |
|
458 |
QScopedPointer<QTemporaryFile> file(new QTemporaryFile(tempPath + "/rXXXXXX")); |
|
459 |
file->open(); |
|
460 |
files.append(file.take()); |
|
461 |
} |
|
462 |
||
463 |
// ### flesh this out more |
|
464 |
QNonNativeFileDialog fd(0,QString("Test it"),startPath); |
|
465 |
fd.setOptions(QFileDialog::DontUseNativeDialog); |
|
466 |
fd.show(); |
|
467 |
QVERIFY(fd.isVisible()); |
|
468 |
QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model"); |
|
469 |
QVERIFY(model); |
|
470 |
QLineEdit *lineEdit = qFindChild<QLineEdit*>(&fd, "fileNameEdit"); |
|
471 |
QVERIFY(lineEdit); |
|
472 |
QCompleter *completer = lineEdit->completer(); |
|
473 |
QVERIFY(completer); |
|
474 |
QAbstractItemModel *cModel = completer->completionModel(); |
|
475 |
QVERIFY(cModel); |
|
476 |
||
477 |
//wait a bit |
|
478 |
QTest::qWait(500); |
|
479 |
||
480 |
// path C:\depot\qt\examples\dialogs\standarddialogs |
|
481 |
// files |
|
482 |
// [debug] [release] [tmp] dialog dialog main makefile makefile.debug makefile.release standarddialgos |
|
483 |
// |
|
484 |
// d -> D:\ debug dialog.cpp dialog.h |
|
485 |
// ..\ -> ..\classwizard ..\configdialog ..\dialogs.pro |
|
486 |
// c -> C:\ control panel |
|
487 |
// c: -> C:\ (nothing more) |
|
488 |
// C:\ -> C:\, C:\_viminfo, ... |
|
489 |
// \ -> \_viminfo |
|
490 |
// c:\depot -> 'nothing' |
|
491 |
// c:\depot\ -> C:\depot\devtools, C:\depot\dteske |
|
492 |
QCOMPARE(model->index(fd.directory().path()), model->index(startPath)); |
|
493 |
||
494 |
if (input.isEmpty()) { |
|
495 |
QModelIndex r = model->index(model->rootPath()); |
|
496 |
QVERIFY(model->rowCount(r) > 0); |
|
497 |
QModelIndex idx = model->index(0, 0, r); |
|
498 |
input = idx.data().toString().at(0); |
|
499 |
} |
|
500 |
||
501 |
// press 'keys' for the input |
|
502 |
for (int i = 0; i < input.count(); ++i) |
|
503 |
QTest::keyPress(lineEdit, input[i].toAscii()); |
|
504 |
||
505 |
QStringList expectedFiles; |
|
506 |
if (expected == -1) { |
|
507 |
QString fullPath = startPath.isEmpty() ? tempPath : startPath; |
|
508 |
if (!fullPath.endsWith(QLatin1Char('/'))) |
|
509 |
fullPath.append(QLatin1Char('/')); |
|
510 |
fullPath.append(input); |
|
511 |
bool inputStartsWithRootPath = false; |
|
512 |
if (input.startsWith(QDir::rootPath())) { |
|
513 |
fullPath = input; |
|
514 |
input.clear(); |
|
515 |
inputStartsWithRootPath = true; |
|
516 |
} |
|
517 |
||
518 |
QFileInfo fi(fullPath); |
|
519 |
QDir x(fi.absolutePath()); |
|
520 |
expectedFiles = x.entryList(model->filter()); |
|
521 |
expected = 0; |
|
522 |
if (input.startsWith("..")) |
|
523 |
input.clear(); |
|
524 |
for (int ii = 0; ii < expectedFiles.count(); ++ii) { |
|
525 |
#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) |
|
526 |
if (expectedFiles.at(ii).startsWith(input,Qt::CaseInsensitive)) |
|
527 |
#else |
|
528 |
if (expectedFiles.at(ii).startsWith(input)) |
|
529 |
#endif |
|
530 |
++expected; |
|
531 |
} |
|
532 |
#if !defined(Q_OS_WIN) |
|
533 |
if (inputStartsWithRootPath) |
|
534 |
expected++; |
|
535 |
#endif |
|
536 |
} |
|
537 |
||
538 |
QTest::qWait(1000); |
|
539 |
if (cModel->rowCount() != expected) { |
|
540 |
for (int i = 0; i < cModel->rowCount(); ++i) { |
|
541 |
QString file = cModel->index(i, 0).data().toString(); |
|
542 |
expectedFiles.removeAll(file); |
|
543 |
} |
|
544 |
//qDebug() << expectedFiles; |
|
545 |
} |
|
546 |
||
547 |
||
548 |
// ### FIXME: This will fail on Symbian on some tests and some environments until the file engine and QFileSystemModel |
|
549 |
// are fixed to properly capitalize paths, so that some folders are not duplicated in QFileSystemModel. |
|
550 |
QTRY_COMPARE(cModel->rowCount(), expected); |
|
551 |
} QT_CATCH(...) { |
|
552 |
qDeleteAll(files); |
|
553 |
QT_RETHROW; |
|
554 |
} |
|
555 |
qDeleteAll(files); |
|
556 |
} |
|
557 |
||
558 |
void tst_QFiledialog::completer_up() |
|
559 |
{ |
|
560 |
QNonNativeFileDialog fd; |
|
561 |
fd.setOptions(QFileDialog::DontUseNativeDialog); |
|
562 |
QSignalSpy spyCurrentChanged(&fd, SIGNAL(currentChanged(const QString &))); |
|
563 |
QSignalSpy spyDirectoryEntered(&fd, SIGNAL(directoryEntered(const QString &))); |
|
564 |
QSignalSpy spyFilesSelected(&fd, SIGNAL(filesSelected(const QStringList &))); |
|
565 |
QSignalSpy spyFilterSelected(&fd, SIGNAL(filterSelected(const QString &))); |
|
566 |
||
567 |
fd.show(); |
|
568 |
QLineEdit *lineEdit = qFindChild<QLineEdit*>(&fd, "fileNameEdit"); |
|
569 |
QVERIFY(lineEdit); |
|
570 |
QCOMPARE(spyFilesSelected.count(), 0); |
|
571 |
int depth = QDir::currentPath().split('/').count(); |
|
572 |
for (int i = 0; i <= depth * 3 + 1; ++i) { |
|
573 |
lineEdit->insert("../"); |
|
574 |
qApp->processEvents(); |
|
575 |
} |
|
576 |
QCOMPARE(spyCurrentChanged.count(), 0); |
|
577 |
QCOMPARE(spyDirectoryEntered.count(), 0); |
|
578 |
QCOMPARE(spyFilesSelected.count(), 0); |
|
579 |
QCOMPARE(spyFilterSelected.count(), 0); |
|
580 |
} |
|
581 |
||
582 |
void tst_QFiledialog::acceptMode() |
|
583 |
{ |
|
584 |
QNonNativeFileDialog fd; |
|
585 |
fd.show(); |
|
586 |
||
587 |
QToolButton* newButton = qFindChild<QToolButton*>(&fd, "newFolderButton"); |
|
588 |
QVERIFY(newButton); |
|
589 |
||
590 |
// default |
|
591 |
QCOMPARE(fd.acceptMode(), QFileDialog::AcceptOpen); |
|
592 |
QCOMPARE(newButton && newButton->isVisible(), true); |
|
593 |
||
594 |
//fd.setDetailsExpanded(true); |
|
595 |
fd.setAcceptMode(QFileDialog::AcceptSave); |
|
596 |
QCOMPARE(fd.acceptMode(), QFileDialog::AcceptSave); |
|
597 |
QCOMPARE(newButton->isVisible(), true); |
|
598 |
||
599 |
fd.setAcceptMode(QFileDialog::AcceptOpen); |
|
600 |
QCOMPARE(fd.acceptMode(), QFileDialog::AcceptOpen); |
|
601 |
QCOMPARE(newButton->isVisible(), true); |
|
602 |
} |
|
603 |
||
604 |
void tst_QFiledialog::confirmOverwrite() |
|
605 |
{ |
|
606 |
QNonNativeFileDialog fd; |
|
607 |
QCOMPARE(fd.confirmOverwrite(), true); |
|
608 |
fd.setConfirmOverwrite(true); |
|
609 |
QCOMPARE(fd.confirmOverwrite(), true); |
|
610 |
fd.setConfirmOverwrite(false); |
|
611 |
QCOMPARE(fd.confirmOverwrite(), false); |
|
612 |
fd.setConfirmOverwrite(true); |
|
613 |
QCOMPARE(fd.confirmOverwrite(), true); |
|
614 |
} |
|
615 |
||
616 |
void tst_QFiledialog::defaultSuffix() |
|
617 |
{ |
|
618 |
QNonNativeFileDialog fd; |
|
619 |
QCOMPARE(fd.defaultSuffix(), QString()); |
|
620 |
fd.setDefaultSuffix("txt"); |
|
621 |
QCOMPARE(fd.defaultSuffix(), QString("txt")); |
|
622 |
fd.setDefaultSuffix(QString()); |
|
623 |
QCOMPARE(fd.defaultSuffix(), QString()); |
|
624 |
} |
|
625 |
||
626 |
void tst_QFiledialog::fileMode() |
|
627 |
{ |
|
628 |
QNonNativeFileDialog fd; |
|
629 |
QCOMPARE(fd.fileMode(), QFileDialog::AnyFile); |
|
630 |
fd.setFileMode(QFileDialog::ExistingFile); |
|
631 |
QCOMPARE(fd.fileMode(), QFileDialog::ExistingFile); |
|
632 |
fd.setFileMode(QFileDialog::Directory); |
|
633 |
QCOMPARE(fd.fileMode(), QFileDialog::Directory); |
|
634 |
fd.setFileMode(QFileDialog::DirectoryOnly); |
|
635 |
QCOMPARE(fd.fileMode(), QFileDialog::DirectoryOnly); |
|
636 |
fd.setFileMode(QFileDialog::ExistingFiles); |
|
637 |
QCOMPARE(fd.fileMode(), QFileDialog::ExistingFiles); |
|
638 |
} |
|
639 |
||
640 |
void tst_QFiledialog::caption() |
|
641 |
{ |
|
642 |
QNonNativeFileDialog fd; |
|
643 |
fd.setWindowTitle("testing"); |
|
644 |
fd.setFileMode(QFileDialog::Directory); |
|
645 |
QCOMPARE(fd.windowTitle(), QString("testing")); |
|
646 |
} |
|
647 |
||
648 |
void tst_QFiledialog::filters() |
|
649 |
{ |
|
650 |
QNonNativeFileDialog fd; |
|
651 |
fd.setOptions(QFileDialog::DontUseNativeDialog); |
|
652 |
QSignalSpy spyCurrentChanged(&fd, SIGNAL(currentChanged(const QString &))); |
|
653 |
QSignalSpy spyDirectoryEntered(&fd, SIGNAL(directoryEntered(const QString &))); |
|
654 |
QSignalSpy spyFilesSelected(&fd, SIGNAL(filesSelected(const QStringList &))); |
|
655 |
QSignalSpy spyFilterSelected(&fd, SIGNAL(filterSelected(const QString &))); |
|
656 |
QCOMPARE(fd.filters(), QStringList("All Files (*)")); |
|
657 |
||
658 |
// effects |
|
659 |
QList<QComboBox*> views = qFindChildren<QComboBox*>(&fd, "fileTypeCombo"); |
|
660 |
QVERIFY(views.count() == 1); |
|
661 |
QCOMPARE(views.at(0)->isVisible(), false); |
|
662 |
||
663 |
QStringList filters; |
|
664 |
filters << "Image files (*.png *.xpm *.jpg)" |
|
665 |
<< "Text files (*.txt)" |
|
666 |
<< "Any files (*.*)"; |
|
667 |
fd.setFilters(filters); |
|
668 |
QCOMPARE(views.at(0)->isVisible(), false); |
|
669 |
fd.show(); |
|
670 |
fd.setAcceptMode(QFileDialog::AcceptSave); |
|
671 |
QCOMPARE(views.at(0)->isVisible(), true); |
|
672 |
QCOMPARE(fd.filters(), filters); |
|
673 |
fd.setFilter("Image files (*.png *.xpm *.jpg);;Text files (*.txt);;Any files (*.*)"); |
|
674 |
QCOMPARE(fd.filters(), filters); |
|
675 |
QCOMPARE(spyCurrentChanged.count(), 0); |
|
676 |
QCOMPARE(spyDirectoryEntered.count(), 0); |
|
677 |
QCOMPARE(spyFilesSelected.count(), 0); |
|
678 |
QCOMPARE(spyFilterSelected.count(), 0); |
|
679 |
||
680 |
// setting shouldn't emit any signals |
|
681 |
for (int i = views.at(0)->currentIndex(); i < views.at(0)->count(); ++i) |
|
682 |
views.at(0)->setCurrentIndex(i); |
|
683 |
QCOMPARE(spyFilterSelected.count(), 0); |
|
684 |
||
685 |
//Let check if filters with whitespaces |
|
686 |
QNonNativeFileDialog fd2; |
|
687 |
QStringList expected; |
|
688 |
expected << "C++ Source Files(*.cpp)"; |
|
689 |
expected << "Any(*.*)"; |
|
690 |
fd2.setFilter("C++ Source Files(*.cpp);;Any(*.*)"); |
|
691 |
QCOMPARE(expected, fd2.filters()); |
|
692 |
fd2.setFilter("C++ Source Files(*.cpp) ;;Any(*.*)"); |
|
693 |
QCOMPARE(expected, fd2.filters()); |
|
694 |
fd2.setFilter("C++ Source Files(*.cpp);; Any(*.*)"); |
|
695 |
QCOMPARE(expected, fd2.filters()); |
|
696 |
fd2.setFilter(" C++ Source Files(*.cpp);; Any(*.*)"); |
|
697 |
QCOMPARE(expected, fd2.filters()); |
|
698 |
fd2.setFilter("C++ Source Files(*.cpp) ;; Any(*.*)"); |
|
699 |
QCOMPARE(expected, fd2.filters()); |
|
700 |
} |
|
701 |
||
702 |
void tst_QFiledialog::selectFilter() |
|
703 |
{ |
|
704 |
QNonNativeFileDialog fd; |
|
705 |
QSignalSpy spyFilterSelected(&fd, SIGNAL(filterSelected(const QString &))); |
|
706 |
QCOMPARE(fd.selectedFilter(), QString("All Files (*)")); |
|
707 |
QStringList filters; |
|
708 |
filters << "Image files (*.png *.xpm *.jpg)" |
|
709 |
<< "Text files (*.txt)" |
|
710 |
<< "Any files (*.*)"; |
|
711 |
fd.setFilters(filters); |
|
712 |
QCOMPARE(fd.selectedFilter(), filters.at(0)); |
|
713 |
fd.selectFilter(filters.at(1)); |
|
714 |
QCOMPARE(fd.selectedFilter(), filters.at(1)); |
|
715 |
fd.selectFilter(filters.at(2)); |
|
716 |
QCOMPARE(fd.selectedFilter(), filters.at(2)); |
|
717 |
||
718 |
fd.selectFilter("bob"); |
|
719 |
QCOMPARE(fd.selectedFilter(), filters.at(2)); |
|
720 |
fd.selectFilter(""); |
|
721 |
QCOMPARE(fd.selectedFilter(), filters.at(2)); |
|
722 |
QCOMPARE(spyFilterSelected.count(), 0); |
|
723 |
} |
|
724 |
||
725 |
void tst_QFiledialog::history() |
|
726 |
{ |
|
727 |
QNonNativeFileDialog fd; |
|
728 |
fd.setViewMode(QFileDialog::List); |
|
729 |
QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model"); |
|
730 |
QVERIFY(model); |
|
731 |
QSignalSpy spyCurrentChanged(&fd, SIGNAL(currentChanged(const QString &))); |
|
732 |
QSignalSpy spyDirectoryEntered(&fd, SIGNAL(directoryEntered(const QString &))); |
|
733 |
QSignalSpy spyFilesSelected(&fd, SIGNAL(filesSelected(const QStringList &))); |
|
734 |
QSignalSpy spyFilterSelected(&fd, SIGNAL(filterSelected(const QString &))); |
|
735 |
QCOMPARE(model->index(fd.history().first()), model->index(QDir::toNativeSeparators(fd.directory().absolutePath()))); |
|
736 |
fd.setDirectory(QDir::current().absolutePath()); |
|
737 |
QStringList history; |
|
738 |
history << QDir::toNativeSeparators(QDir::current().absolutePath()) |
|
739 |
<< QDir::toNativeSeparators(QDir::home().absolutePath()) |
|
740 |
<< QDir::toNativeSeparators(QDir::temp().absolutePath()); |
|
741 |
fd.setHistory(history); |
|
742 |
if (fd.history() != history) { |
|
743 |
qDebug() << fd.history() << history; |
|
744 |
// quick and dirty output for windows failure. |
|
745 |
QListView* list = qFindChild<QListView*>(&fd, "listView"); |
|
746 |
QVERIFY(list); |
|
747 |
QModelIndex root = list->rootIndex(); |
|
748 |
while (root.isValid()) { |
|
749 |
qDebug() << root.data(); |
|
750 |
root = root.parent(); |
|
751 |
} |
|
752 |
} |
|
753 |
QCOMPARE(fd.history(), history); |
|
754 |
||
755 |
QStringList badHistory; |
|
756 |
badHistory << "junk"; |
|
757 |
fd.setHistory(badHistory); |
|
758 |
badHistory << QDir::toNativeSeparators(QDir::current().absolutePath()); |
|
759 |
QCOMPARE(fd.history(), badHistory); |
|
760 |
||
761 |
QCOMPARE(spyCurrentChanged.count(), 0); |
|
762 |
QCOMPARE(spyDirectoryEntered.count(), 0); |
|
763 |
QCOMPARE(spyFilesSelected.count(), 0); |
|
764 |
QCOMPARE(spyFilterSelected.count(), 0); |
|
765 |
} |
|
766 |
||
767 |
void tst_QFiledialog::iconProvider() |
|
768 |
{ |
|
769 |
QNonNativeFileDialog *fd = new QNonNativeFileDialog(); |
|
770 |
QVERIFY(fd->iconProvider() != 0); |
|
771 |
QFileIconProvider *ip = new QFileIconProvider(); |
|
772 |
fd->setIconProvider(ip); |
|
773 |
QCOMPARE(fd->iconProvider(), ip); |
|
774 |
delete fd; |
|
775 |
delete ip; |
|
776 |
} |
|
777 |
||
778 |
void tst_QFiledialog::isReadOnly() |
|
779 |
{ |
|
780 |
QNonNativeFileDialog fd; |
|
781 |
||
782 |
QPushButton* newButton = qFindChild<QPushButton*>(&fd, "newFolderButton"); |
|
783 |
QAction* renameAction = qFindChild<QAction*>(&fd, "qt_rename_action"); |
|
784 |
QAction* deleteAction = qFindChild<QAction*>(&fd, "qt_delete_action"); |
|
785 |
||
786 |
QCOMPARE(fd.isReadOnly(), false); |
|
787 |
||
788 |
// This is dependent upon the file/dir, find cross platform way to test |
|
789 |
//fd.setDirectory(QDir::home()); |
|
790 |
//QCOMPARE(newButton && newButton->isEnabled(), true); |
|
791 |
//QCOMPARE(renameAction && renameAction->isEnabled(), true); |
|
792 |
//QCOMPARE(deleteAction && deleteAction->isEnabled(), true); |
|
793 |
||
794 |
fd.setReadOnly(true); |
|
795 |
QCOMPARE(fd.isReadOnly(), true); |
|
796 |
||
797 |
QCOMPARE(newButton && newButton->isEnabled(), false); |
|
798 |
QCOMPARE(renameAction && renameAction->isEnabled(), false); |
|
799 |
QCOMPARE(deleteAction && deleteAction->isEnabled(), false); |
|
800 |
} |
|
801 |
||
802 |
void tst_QFiledialog::itemDelegate() |
|
803 |
{ |
|
804 |
QNonNativeFileDialog fd; |
|
805 |
QVERIFY(fd.itemDelegate() != 0); |
|
806 |
QItemDelegate *id = new QItemDelegate(&fd); |
|
807 |
fd.setItemDelegate(id); |
|
808 |
QCOMPARE(fd.itemDelegate(), (QAbstractItemDelegate *)id); |
|
809 |
} |
|
810 |
||
811 |
void tst_QFiledialog::labelText() |
|
812 |
{ |
|
813 |
QNonNativeFileDialog fd; |
|
814 |
QDialogButtonBox buttonBox; |
|
815 |
QPushButton *cancelButton = buttonBox.addButton(QDialogButtonBox::Cancel); |
|
816 |
QCOMPARE(fd.labelText(QFileDialog::LookIn), QString("Look in:")); |
|
817 |
QCOMPARE(fd.labelText(QFileDialog::FileName), QString("File &name:")); |
|
818 |
QCOMPARE(fd.labelText(QFileDialog::FileType), QString("Files of type:")); |
|
819 |
QCOMPARE(fd.labelText(QFileDialog::Accept), QString("&Open")); ///### see task 241462 |
|
820 |
QCOMPARE(fd.labelText(QFileDialog::Reject), cancelButton->text()); |
|
821 |
||
822 |
fd.setLabelText(QFileDialog::LookIn, "1"); |
|
823 |
QCOMPARE(fd.labelText(QFileDialog::LookIn), QString("1")); |
|
824 |
fd.setLabelText(QFileDialog::FileName, "2"); |
|
825 |
QCOMPARE(fd.labelText(QFileDialog::FileName), QString("2")); |
|
826 |
fd.setLabelText(QFileDialog::FileType, "3"); |
|
827 |
QCOMPARE(fd.labelText(QFileDialog::FileType), QString("3")); |
|
828 |
fd.setLabelText(QFileDialog::Accept, "4"); |
|
829 |
QCOMPARE(fd.labelText(QFileDialog::Accept), QString("4")); |
|
830 |
fd.setLabelText(QFileDialog::Reject, "5"); |
|
831 |
QCOMPARE(fd.labelText(QFileDialog::Reject), QString("5")); |
|
832 |
} |
|
833 |
||
834 |
void tst_QFiledialog::resolveSymlinks() |
|
835 |
{ |
|
836 |
QNonNativeFileDialog fd; |
|
837 |
||
838 |
// default |
|
839 |
QCOMPARE(fd.resolveSymlinks(), true); |
|
840 |
fd.setResolveSymlinks(false); |
|
841 |
QCOMPARE(fd.resolveSymlinks(), false); |
|
842 |
fd.setResolveSymlinks(true); |
|
843 |
QCOMPARE(fd.resolveSymlinks(), true); |
|
844 |
||
845 |
// the file dialog doesn't do anything based upon this, just passes it to the model |
|
846 |
// the model should fully test it, don't test it here |
|
847 |
} |
|
848 |
||
849 |
void tst_QFiledialog::selectFile_data() |
|
850 |
{ |
|
851 |
QTest::addColumn<QString>("file"); |
|
852 |
QTest::addColumn<int>("count"); |
|
853 |
QTest::newRow("null") << QString() << 1; |
|
854 |
QTest::newRow("file") << "foo" << 1; |
|
855 |
QTest::newRow("tmp") << "temp" << 1; |
|
856 |
} |
|
857 |
||
858 |
void tst_QFiledialog::selectFile() |
|
859 |
{ |
|
860 |
QFETCH(QString, file); |
|
861 |
QFETCH(int, count); |
|
862 |
QNonNativeFileDialog fd; |
|
863 |
QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model"); |
|
864 |
QVERIFY(model); |
|
865 |
fd.setDirectory(QDir::currentPath()); |
|
866 |
// default value |
|
867 |
QCOMPARE(fd.selectedFiles().count(), 1); |
|
868 |
||
869 |
QTemporaryFile tempFile(QDir::tempPath() + "/aXXXXXX"); |
|
870 |
bool inTemp = (file == "temp"); |
|
871 |
if (inTemp) { |
|
872 |
tempFile.open(); |
|
873 |
file = tempFile.fileName(); |
|
874 |
} |
|
875 |
||
876 |
fd.selectFile(file); |
|
877 |
QCOMPARE(fd.selectedFiles().count(), count); |
|
878 |
if (inTemp) { |
|
879 |
QCOMPARE(model->index(fd.directory().path()), model->index(QDir::tempPath())); |
|
880 |
} else { |
|
881 |
QCOMPARE(model->index(fd.directory().path()), model->index(QDir::currentPath())); |
|
882 |
} |
|
883 |
} |
|
884 |
||
885 |
void tst_QFiledialog::selectFiles() |
|
886 |
{ |
|
887 |
QNonNativeFileDialog fd; |
|
888 |
fd.setViewMode(QFileDialog::List); |
|
889 |
QString tempPath = QDir::tempPath() + '/' + "QFileDialogTestDir4SelectFiles"; |
|
890 |
QDir dir; |
|
891 |
QVERIFY(dir.mkpath(tempPath)); |
|
892 |
fd.setDirectory(tempPath); |
|
893 |
QSignalSpy spyCurrentChanged(&fd, SIGNAL(currentChanged(const QString &))); |
|
894 |
QSignalSpy spyDirectoryEntered(&fd, SIGNAL(directoryEntered(const QString &))); |
|
895 |
QSignalSpy spyFilesSelected(&fd, SIGNAL(filesSelected(const QStringList &))); |
|
896 |
QSignalSpy spyFilterSelected(&fd, SIGNAL(filterSelected(const QString &))); |
|
897 |
fd.show(); |
|
898 |
fd.setFileMode(QFileDialog::ExistingFiles); |
|
899 |
||
900 |
QString filesPath = fd.directory().absolutePath(); |
|
901 |
for (int i=0; i < 5; ++i) { |
|
902 |
QFile file(filesPath + QString::fromLatin1("/qfiledialog_auto_test_not_pres_%1").arg(i)); |
|
903 |
file.open(QIODevice::WriteOnly); |
|
904 |
file.resize(1024); |
|
905 |
file.flush(); |
|
906 |
file.close(); |
|
907 |
} |
|
908 |
||
909 |
// Get a list of files in the view and then get the corresponding index's |
|
910 |
QStringList list = fd.directory().entryList(QDir::Files); |
|
911 |
QModelIndexList toSelect; |
|
912 |
QVERIFY(list.count() > 1); |
|
913 |
QListView* listView = qFindChild<QListView*>(&fd, "listView"); |
|
914 |
QVERIFY(listView); |
|
915 |
for (int i = 0; i < list.count(); ++i) { |
|
916 |
fd.selectFile(fd.directory().path() + "/" + list.at(i)); |
|
917 |
#if defined(QT_MAC_USE_COCOA) || defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN) |
|
918 |
QEXPECT_FAIL("", "This test does not work on Mac, Windows, or Symbian", Abort); |
|
919 |
#endif |
|
920 |
QTRY_VERIFY(!listView->selectionModel()->selectedRows().isEmpty()); |
|
921 |
toSelect.append(listView->selectionModel()->selectedRows().last()); |
|
922 |
} |
|
923 |
QCOMPARE(spyFilesSelected.count(), 0); |
|
924 |
||
925 |
listView->selectionModel()->clear(); |
|
926 |
QCOMPARE(spyFilesSelected.count(), 0); |
|
927 |
||
928 |
// select the indexes |
|
929 |
for (int i = 0; i < toSelect.count(); ++i) { |
|
930 |
listView->selectionModel()->select(toSelect.at(i), |
|
931 |
QItemSelectionModel::Select | QItemSelectionModel::Rows); |
|
932 |
} |
|
933 |
QCOMPARE(fd.selectedFiles().count(), toSelect.count()); |
|
934 |
QCOMPARE(spyCurrentChanged.count(), 0); |
|
935 |
QCOMPARE(spyDirectoryEntered.count(), 0); |
|
936 |
QCOMPARE(spyFilesSelected.count(), 0); |
|
937 |
QCOMPARE(spyFilterSelected.count(), 0); |
|
938 |
for (int i=0; i < 5; ++i) |
|
939 |
QFile::remove(filesPath + QString::fromLatin1("/qfiledialog_auto_test_not_pres_%1").arg(i)); |
|
940 |
||
941 |
//If the selection is invalid then we fill the line edit but without the / |
|
942 |
QNonNativeFileDialog * dialog = new QNonNativeFileDialog( 0, "Save" ); |
|
943 |
dialog->setFileMode( QFileDialog::AnyFile ); |
|
944 |
dialog->setAcceptMode( QFileDialog::AcceptSave ); |
|
945 |
QString temporary = QDir::tempPath() + QLatin1String("/blah"); |
|
946 |
dialog->selectFile(temporary); |
|
947 |
dialog->show(); |
|
948 |
QTest::qWait(500); |
|
949 |
QLineEdit *lineEdit = qFindChild<QLineEdit*>(dialog, "fileNameEdit"); |
|
950 |
QVERIFY(lineEdit); |
|
951 |
QCOMPARE(lineEdit->text(),QLatin1String("blah")); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
952 |
delete dialog; |
0 | 953 |
} |
954 |
||
955 |
void tst_QFiledialog::viewMode() |
|
956 |
{ |
|
957 |
QNonNativeFileDialog fd; |
|
958 |
fd.setViewMode(QFileDialog::List); |
|
959 |
fd.show(); |
|
960 |
||
961 |
// find widgets |
|
962 |
QList<QTreeView*> treeView = qFindChildren<QTreeView*>(&fd, "treeView"); |
|
963 |
QCOMPARE(treeView.count(), 1); |
|
964 |
QList<QListView*> listView = qFindChildren<QListView*>(&fd, "listView"); |
|
965 |
QCOMPARE(listView.count(), 1); |
|
966 |
QList<QToolButton*> listButton = qFindChildren<QToolButton*>(&fd, "listModeButton"); |
|
967 |
QCOMPARE(listButton.count(), 1); |
|
968 |
QList<QToolButton*> treeButton = qFindChildren<QToolButton*>(&fd, "detailModeButton"); |
|
969 |
QCOMPARE(treeButton.count(), 1); |
|
970 |
||
971 |
// default value |
|
972 |
QCOMPARE(fd.viewMode(), QFileDialog::List); |
|
973 |
||
974 |
// detail |
|
975 |
fd.setViewMode(QFileDialog::ViewMode(QFileDialog::Detail)); |
|
976 |
||
977 |
QCOMPARE(QFileDialog::ViewMode(QFileDialog::Detail), fd.viewMode()); |
|
978 |
QCOMPARE(listView.at(0)->isVisible(), false); |
|
979 |
QCOMPARE(listButton.at(0)->isDown(), false); |
|
980 |
QCOMPARE(treeView.at(0)->isVisible(), true); |
|
981 |
QCOMPARE(treeButton.at(0)->isDown(), true); |
|
982 |
||
983 |
// list |
|
984 |
fd.setViewMode(QFileDialog::ViewMode(QFileDialog::List)); |
|
985 |
||
986 |
QCOMPARE(QFileDialog::ViewMode(QFileDialog::List), fd.viewMode()); |
|
987 |
QCOMPARE(treeView.at(0)->isVisible(), false); |
|
988 |
QCOMPARE(treeButton.at(0)->isDown(), false); |
|
989 |
QCOMPARE(listView.at(0)->isVisible(), true); |
|
990 |
QCOMPARE(listButton.at(0)->isDown(), true); |
|
991 |
} |
|
992 |
||
993 |
void tst_QFiledialog::proxymodel() |
|
994 |
{ |
|
995 |
QNonNativeFileDialog fd; |
|
996 |
QCOMPARE(fd.proxyModel(), (QAbstractProxyModel*)0); |
|
997 |
||
998 |
fd.setProxyModel(0); |
|
999 |
QCOMPARE(fd.proxyModel(), (QAbstractProxyModel*)0); |
|
1000 |
||
1001 |
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(&fd); |
|
1002 |
fd.setProxyModel(proxyModel); |
|
1003 |
QCOMPARE(fd.proxyModel(), (QAbstractProxyModel *)proxyModel); |
|
1004 |
||
1005 |
fd.setProxyModel(0); |
|
1006 |
QCOMPARE(fd.proxyModel(), (QAbstractProxyModel*)0); |
|
1007 |
} |
|
1008 |
||
1009 |
void tst_QFiledialog::setNameFilter() |
|
1010 |
{ |
|
1011 |
QNonNativeFileDialog fd; |
|
1012 |
fd.setFilter(QString()); |
|
1013 |
fd.setFilters(QStringList()); |
|
1014 |
} |
|
1015 |
||
1016 |
void tst_QFiledialog::focus() |
|
1017 |
{ |
|
1018 |
QNonNativeFileDialog fd; |
|
1019 |
fd.setDirectory(QDir::currentPath()); |
|
1020 |
fd.show(); |
|
1021 |
QApplication::setActiveWindow(&fd); |
|
1022 |
QTest::qWaitForWindowShown(&fd); |
|
1023 |
QTRY_COMPARE(fd.isVisible(), true); |
|
1024 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget*>(&fd)); |
|
1025 |
qApp->processEvents(); |
|
1026 |
||
1027 |
// make sure the tests work with focus follows mouse |
|
1028 |
QCursor::setPos(fd.geometry().center()); |
|
1029 |
QApplication::syncX(); |
|
1030 |
||
1031 |
QList<QWidget*> treeView = qFindChildren<QWidget*>(&fd, "fileNameEdit"); |
|
1032 |
QCOMPARE(treeView.count(), 1); |
|
1033 |
QVERIFY(treeView.at(0)); |
|
1034 |
QTRY_COMPARE(treeView.at(0)->hasFocus(), true); |
|
1035 |
QCOMPARE(treeView.at(0)->hasFocus(), true); |
|
1036 |
} |
|
1037 |
||
1038 |
||
1039 |
void tst_QFiledialog::historyBack() |
|
1040 |
{ |
|
1041 |
QNonNativeFileDialog fd; |
|
1042 |
QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model"); |
|
1043 |
QVERIFY(model); |
|
1044 |
QToolButton *backButton = qFindChild<QToolButton*>(&fd, "backButton"); |
|
1045 |
QVERIFY(backButton); |
|
1046 |
QToolButton *forwardButton = qFindChild<QToolButton*>(&fd, "forwardButton"); |
|
1047 |
QVERIFY(forwardButton); |
|
1048 |
||
1049 |
QSignalSpy spy(model, SIGNAL(rootPathChanged(const QString &))); |
|
1050 |
||
1051 |
QString home = fd.directory().absolutePath(); |
|
1052 |
QString desktop = QDir::homePath(); |
|
1053 |
QString temp = QDir::tempPath(); |
|
1054 |
||
1055 |
QCOMPARE(backButton->isEnabled(), false); |
|
1056 |
QCOMPARE(forwardButton->isEnabled(), false); |
|
1057 |
fd.setDirectory(temp); |
|
1058 |
qApp->processEvents(); |
|
1059 |
QCOMPARE(backButton->isEnabled(), true); |
|
1060 |
QCOMPARE(forwardButton->isEnabled(), false); |
|
1061 |
fd.setDirectory(desktop); |
|
1062 |
QCOMPARE(spy.count(), 2); |
|
1063 |
||
1064 |
backButton->click(); |
|
1065 |
qApp->processEvents(); |
|
1066 |
QCOMPARE(backButton->isEnabled(), true); |
|
1067 |
QCOMPARE(forwardButton->isEnabled(), true); |
|
1068 |
QCOMPARE(spy.count(), 3); |
|
1069 |
QString currentPath = qVariantValue<QString>(spy.last().first()); |
|
1070 |
QCOMPARE(model->index(currentPath), model->index(temp)); |
|
1071 |
||
1072 |
backButton->click(); |
|
1073 |
currentPath = qVariantValue<QString>(spy.last().first()); |
|
1074 |
QCOMPARE(currentPath, home); |
|
1075 |
QCOMPARE(backButton->isEnabled(), false); |
|
1076 |
QCOMPARE(forwardButton->isEnabled(), true); |
|
1077 |
QCOMPARE(spy.count(), 4); |
|
1078 |
||
1079 |
// nothing should change at this point |
|
1080 |
backButton->click(); |
|
1081 |
QCOMPARE(spy.count(), 4); |
|
1082 |
QCOMPARE(backButton->isEnabled(), false); |
|
1083 |
QCOMPARE(forwardButton->isEnabled(), true); |
|
1084 |
} |
|
1085 |
||
1086 |
void tst_QFiledialog::historyForward() |
|
1087 |
{ |
|
1088 |
QNonNativeFileDialog fd; |
|
1089 |
fd.setDirectory(QDir::currentPath()); |
|
1090 |
QToolButton *backButton = qFindChild<QToolButton*>(&fd, "backButton"); |
|
1091 |
QVERIFY(backButton); |
|
1092 |
QToolButton *forwardButton = qFindChild<QToolButton*>(&fd, "forwardButton"); |
|
1093 |
QVERIFY(forwardButton); |
|
1094 |
||
1095 |
QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model"); |
|
1096 |
QVERIFY(model); |
|
1097 |
QSignalSpy spy(model, SIGNAL(rootPathChanged(const QString &))); |
|
1098 |
||
1099 |
QString home = fd.directory().absolutePath(); |
|
1100 |
QString desktop = QDir::homePath(); |
|
1101 |
QString temp = QDir::tempPath(); |
|
1102 |
||
1103 |
fd.setDirectory(home); |
|
1104 |
fd.setDirectory(temp); |
|
1105 |
fd.setDirectory(desktop); |
|
1106 |
||
1107 |
backButton->click(); |
|
1108 |
QCOMPARE(forwardButton->isEnabled(), true); |
|
1109 |
QCOMPARE(model->index(qVariantValue<QString>(spy.last().first())), model->index(temp)); |
|
1110 |
||
1111 |
forwardButton->click(); |
|
1112 |
QCOMPARE(model->index(qVariantValue<QString>(spy.last().first())), model->index(desktop)); |
|
1113 |
QCOMPARE(backButton->isEnabled(), true); |
|
1114 |
QCOMPARE(forwardButton->isEnabled(), false); |
|
1115 |
QCOMPARE(spy.count(), 4); |
|
1116 |
||
1117 |
backButton->click(); |
|
1118 |
QCOMPARE(model->index(qVariantValue<QString>(spy.last().first())), model->index(temp)); |
|
1119 |
QCOMPARE(backButton->isEnabled(), true); |
|
1120 |
||
1121 |
backButton->click(); |
|
1122 |
QCOMPARE(model->index(qVariantValue<QString>(spy.last().first())), model->index(home)); |
|
1123 |
QCOMPARE(backButton->isEnabled(), false); |
|
1124 |
QCOMPARE(forwardButton->isEnabled(), true); |
|
1125 |
QCOMPARE(spy.count(), 6); |
|
1126 |
||
1127 |
forwardButton->click(); |
|
1128 |
QCOMPARE(model->index(qVariantValue<QString>(spy.last().first())), model->index(temp)); |
|
1129 |
backButton->click(); |
|
1130 |
QCOMPARE(model->index(qVariantValue<QString>(spy.last().first())), model->index(home)); |
|
1131 |
QCOMPARE(spy.count(), 8); |
|
1132 |
||
1133 |
forwardButton->click(); |
|
1134 |
QCOMPARE(model->index(qVariantValue<QString>(spy.last().first())), model->index(temp)); |
|
1135 |
forwardButton->click(); |
|
1136 |
QCOMPARE(model->index(qVariantValue<QString>(spy.last().first())), model->index(desktop)); |
|
1137 |
||
1138 |
backButton->click(); |
|
1139 |
QCOMPARE(model->index(qVariantValue<QString>(spy.last().first())), model->index(temp)); |
|
1140 |
backButton->click(); |
|
1141 |
QCOMPARE(model->index(qVariantValue<QString>(spy.last().first())), model->index(home)); |
|
1142 |
fd.setDirectory(desktop); |
|
1143 |
QCOMPARE(forwardButton->isEnabled(), false); |
|
1144 |
} |
|
1145 |
||
1146 |
void tst_QFiledialog::disableSaveButton_data() |
|
1147 |
{ |
|
1148 |
QTest::addColumn<QString>("path"); |
|
1149 |
QTest::addColumn<bool>("isEnabled"); |
|
1150 |
||
1151 |
QTest::newRow("valid path") << QDir::temp().absolutePath() + QDir::separator() + "qfiledialog.new_file" << true; |
|
1152 |
QTest::newRow("no path") << "" << false; |
|
1153 |
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_OPENBSD) |
|
1154 |
QTest::newRow("too long path") << "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" << false; |
|
1155 |
#endif |
|
1156 |
QTest::newRow("file") << "foo.html" << true; |
|
1157 |
} |
|
1158 |
||
1159 |
void tst_QFiledialog::disableSaveButton() |
|
1160 |
{ |
|
1161 |
QFETCH(QString, path); |
|
1162 |
QFETCH(bool, isEnabled); |
|
1163 |
||
1164 |
QNonNativeFileDialog fd(0, "caption", path); |
|
1165 |
fd.setAcceptMode(QFileDialog::AcceptSave); |
|
1166 |
QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(&fd, "buttonBox"); |
|
1167 |
QPushButton *button = buttonBox->button(QDialogButtonBox::Save); |
|
1168 |
QVERIFY(button); |
|
1169 |
QCOMPARE(button->isEnabled(), isEnabled); |
|
1170 |
} |
|
1171 |
||
1172 |
void tst_QFiledialog::saveButtonText_data() |
|
1173 |
{ |
|
1174 |
QTest::addColumn<QString>("path"); |
|
1175 |
QTest::addColumn<QString>("label"); |
|
1176 |
QTest::addColumn<QString>("caption"); |
|
1177 |
||
1178 |
QTest::newRow("empty path") << "" << QString() << QFileDialog::tr("&Save"); |
|
1179 |
QTest::newRow("file path") << "qfiledialog.new_file" << QString() << QFileDialog::tr("&Save"); |
|
1180 |
QTest::newRow("dir") << QDir::temp().absolutePath() << QString() << QFileDialog::tr("&Open"); |
|
1181 |
QTest::newRow("setTextLabel") << "qfiledialog.new_file" << "Mooo" << "Mooo"; |
|
1182 |
QTest::newRow("dir & label") << QDir::temp().absolutePath() << "Poo" << QFileDialog::tr("&Open"); |
|
1183 |
} |
|
1184 |
||
1185 |
void tst_QFiledialog::saveButtonText() |
|
1186 |
{ |
|
1187 |
QFETCH(QString, path); |
|
1188 |
QFETCH(QString, label); |
|
1189 |
QFETCH(QString, caption); |
|
1190 |
||
1191 |
QNonNativeFileDialog fd(0, "auto test", QDir::temp().absolutePath()); |
|
1192 |
fd.setAcceptMode(QFileDialog::AcceptSave); |
|
1193 |
if (!label.isNull()) |
|
1194 |
fd.setLabelText(QFileDialog::Accept, label); |
|
1195 |
fd.setDirectory(QDir::temp()); |
|
1196 |
fd.selectFile(path); |
|
1197 |
QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(&fd, "buttonBox"); |
|
1198 |
QVERIFY(buttonBox); |
|
1199 |
QPushButton *button = buttonBox->button(QDialogButtonBox::Save); |
|
1200 |
QVERIFY(button); |
|
1201 |
QCOMPARE(button->text(), caption); |
|
1202 |
} |
|
1203 |
||
1204 |
void tst_QFiledialog::clearLineEdit() |
|
1205 |
{ |
|
1206 |
QNonNativeFileDialog fd(0, "caption", "foo"); |
|
1207 |
fd.setViewMode(QFileDialog::List); |
|
1208 |
fd.setFileMode(QFileDialog::AnyFile); |
|
1209 |
fd.setOptions(QFileDialog::DontUseNativeDialog); |
|
1210 |
fd.show(); |
|
1211 |
||
1212 |
//play it really safe by creating a directory |
|
1213 |
QDir::home().mkdir("_____aaaaaaaaaaaaaaaaaaaaaa"); |
|
1214 |
||
1215 |
QLineEdit *lineEdit = qFindChild<QLineEdit*>(&fd, "fileNameEdit"); |
|
1216 |
QVERIFY(lineEdit); |
|
1217 |
QVERIFY(lineEdit->text() == "foo"); |
|
1218 |
fd.setDirectory(QDir::home()); |
|
1219 |
||
1220 |
QListView* list = qFindChild<QListView*>(&fd, "listView"); |
|
1221 |
QVERIFY(list); |
|
1222 |
||
1223 |
// saving a file the text shouldn't be cleared |
|
1224 |
fd.setDirectory(QDir::home()); |
|
1225 |
||
1226 |
QTest::qWait(1000); |
|
1227 |
#ifdef QT_KEYPAD_NAVIGATION |
|
1228 |
list->setEditFocus(true); |
|
1229 |
#endif |
|
1230 |
QTest::keyClick(list, Qt::Key_Down); |
|
1231 |
#ifndef Q_WS_MAC |
|
1232 |
QTest::keyClick(list, Qt::Key_Return); |
|
1233 |
#else |
|
1234 |
QTest::keyClick(list, Qt::Key_O, Qt::ControlModifier); |
|
1235 |
#endif |
|
1236 |
||
1237 |
QTest::qWait(2000); |
|
1238 |
QVERIFY(fd.directory().absolutePath() != QDir::home().absolutePath()); |
|
1239 |
QVERIFY(!lineEdit->text().isEmpty()); |
|
1240 |
||
1241 |
// selecting a dir the text should be cleared so one can just hit ok |
|
1242 |
// and it selects that directory |
|
1243 |
fd.setFileMode(QNonNativeFileDialog::Directory); |
|
1244 |
fd.setDirectory(QDir::home()); |
|
1245 |
||
1246 |
QTest::qWait(1000); |
|
1247 |
QTest::keyClick(list, Qt::Key_Down); |
|
1248 |
#ifndef Q_WS_MAC |
|
1249 |
QTest::keyClick(list, Qt::Key_Return); |
|
1250 |
#else |
|
1251 |
QTest::keyClick(list, Qt::Key_O, Qt::ControlModifier); |
|
1252 |
#endif |
|
1253 |
||
1254 |
QTest::qWait(2000); |
|
1255 |
QVERIFY(fd.directory().absolutePath() != QDir::home().absolutePath()); |
|
1256 |
QVERIFY(lineEdit->text().isEmpty()); |
|
1257 |
||
1258 |
//remove the dir |
|
1259 |
QDir::home().rmdir("_____aaaaaaaaaaaaaaaaaaaaaa"); |
|
1260 |
} |
|
1261 |
||
1262 |
void tst_QFiledialog::enableChooseButton() |
|
1263 |
{ |
|
1264 |
QNonNativeFileDialog fd; |
|
1265 |
fd.setFileMode(QFileDialog::Directory); |
|
1266 |
fd.show(); |
|
1267 |
QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(&fd, "buttonBox"); |
|
1268 |
QPushButton *button = buttonBox->button(QDialogButtonBox::Open); |
|
1269 |
QVERIFY(button); |
|
1270 |
QCOMPARE(button->isEnabled(), true); |
|
1271 |
} |
|
1272 |
||
1273 |
QT_BEGIN_NAMESPACE |
|
1274 |
typedef QString (*_qt_filedialog_existing_directory_hook)(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options); |
|
1275 |
extern Q_GUI_EXPORT _qt_filedialog_existing_directory_hook qt_filedialog_existing_directory_hook; |
|
1276 |
QT_END_NAMESPACE |
|
1277 |
QString existing(QWidget *, const QString &, const QString &, QFileDialog::Options) { |
|
1278 |
return "dir"; |
|
1279 |
} |
|
1280 |
||
1281 |
QT_BEGIN_NAMESPACE |
|
1282 |
typedef QString (*_qt_filedialog_open_filename_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options); |
|
1283 |
extern Q_GUI_EXPORT _qt_filedialog_open_filename_hook qt_filedialog_open_filename_hook; |
|
1284 |
QT_END_NAMESPACE |
|
1285 |
QString openName(QWidget *, const QString &, const QString &, const QString &, QString *, QFileDialog::Options) { |
|
1286 |
return "openName"; |
|
1287 |
} |
|
1288 |
||
1289 |
QT_BEGIN_NAMESPACE |
|
1290 |
typedef QStringList (*_qt_filedialog_open_filenames_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options); |
|
1291 |
extern Q_GUI_EXPORT _qt_filedialog_open_filenames_hook qt_filedialog_open_filenames_hook; |
|
1292 |
QT_END_NAMESPACE |
|
1293 |
QStringList openNames(QWidget *, const QString &, const QString &, const QString &, QString *, QFileDialog::Options) { |
|
1294 |
return QStringList("openNames"); |
|
1295 |
} |
|
1296 |
||
1297 |
QT_BEGIN_NAMESPACE |
|
1298 |
typedef QString (*_qt_filedialog_save_filename_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options); |
|
1299 |
extern Q_GUI_EXPORT _qt_filedialog_save_filename_hook qt_filedialog_save_filename_hook; |
|
1300 |
QT_END_NAMESPACE |
|
1301 |
QString saveName(QWidget *, const QString &, const QString &, const QString &, QString *, QFileDialog::Options) { |
|
1302 |
return "saveName"; |
|
1303 |
} |
|
1304 |
||
1305 |
||
1306 |
void tst_QFiledialog::hooks() |
|
1307 |
{ |
|
1308 |
qt_filedialog_existing_directory_hook = &existing; |
|
1309 |
qt_filedialog_save_filename_hook = &saveName; |
|
1310 |
qt_filedialog_open_filename_hook = &openName; |
|
1311 |
qt_filedialog_open_filenames_hook = &openNames; |
|
1312 |
||
1313 |
QCOMPARE(QFileDialog::getExistingDirectory(), QString("dir")); |
|
1314 |
QCOMPARE(QFileDialog::getOpenFileName(), QString("openName")); |
|
1315 |
QCOMPARE(QFileDialog::getOpenFileNames(), QStringList("openNames")); |
|
1316 |
QCOMPARE(QFileDialog::getSaveFileName(), QString("saveName")); |
|
1317 |
} |
|
1318 |
||
1319 |
QTEST_MAIN(tst_QFiledialog) |
|
1320 |
#include "tst_qfiledialog.moc" |