From 6201e4adda316e5a582af687cdd2f1bcd19be31d Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Mon, 12 Oct 2009 21:12:39 +0200 Subject: Itemview: fix regression concerning Ctrl+rubber band selections When making a rubber band selection while Control is pressed in an itemview with extended selection, make sure that the selection state of the items inside the rubber band is toggled. This ammend commit 0644e3dce532b1df00a77d3a30c61d6b75d3ff30 Merge-request: 1759 Reviewed-by: Olivier Goffart Reviewed-by: Gabriel Task-number: QTBUG-1435 Task-number: 191545 --- src/gui/itemviews/qabstractitemview.cpp | 2 +- .../qabstractitemview/tst_qabstractitemview.cpp | 45 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 268e78e..13a1662 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -1697,7 +1697,7 @@ void QAbstractItemView::mouseMoveEvent(QMouseEvent *event) if ((event->buttons() & Qt::LeftButton) && d->selectionAllowed(index) && d->selectionModel) { setState(DragSelectingState); QItemSelectionModel::SelectionFlags command = selectionCommand(index, event); - if (command.testFlag(QItemSelectionModel::Toggle)) { + if (d->ctrlDragSelectionFlag != QItemSelectionModel::NoUpdate && command.testFlag(QItemSelectionModel::Toggle)) { command &= ~QItemSelectionModel::Toggle; command |= d->ctrlDragSelectionFlag; } diff --git a/tests/auto/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/qabstractitemview/tst_qabstractitemview.cpp index d6911d2..db840f4 100644 --- a/tests/auto/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/qabstractitemview/tst_qabstractitemview.cpp @@ -223,6 +223,7 @@ private slots: void task257481_emptyEditor(); void shiftArrowSelectionAfterScrolling(); void shiftSelectionAfterRubberbandSelection(); + void ctrlRubberbandSelection(); }; class MyAbstractItemDelegate : public QAbstractItemDelegate @@ -1388,5 +1389,49 @@ void tst_QAbstractItemView::shiftSelectionAfterRubberbandSelection() QVERIFY(selected.contains(index2)); } +void tst_QAbstractItemView::ctrlRubberbandSelection() +{ + QStandardItemModel model; + for (int i=0; i<3; ++i) { + QStandardItem *item = new QStandardItem(QString("%1").arg(i)); + model.setItem(i, 0, item); + } + + QListView view; + view.setFixedSize(150, 450); + view.setFlow(QListView::LeftToRight); + view.setGridSize(QSize(100, 100)); + view.setSelectionMode(QListView::ExtendedSelection); + view.setViewMode(QListView::IconMode); + view.setModel(&model); + view.show(); + QTest::qWait(30); + + QModelIndex index1 = model.index(1, 0); + QModelIndex index2 = model.index(2, 0); + + // Select item 1 + view.setCurrentIndex(index1); + QModelIndexList selected = view.selectionModel()->selectedIndexes(); + QCOMPARE(selected.count(), 1); + QVERIFY(selected.contains(index1)); + + // Now press control and draw a rubberband around items 1 and 2. + // The mouse move event has to be created manually because the QTest framework does not + // contain a function for mouse moves with buttons pressed. + QPoint pressPos = view.visualRect(index1).topLeft() - QPoint(1, 1); + QPoint releasePos = view.visualRect(index2).bottomRight() + QPoint(1, 1); + QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::ControlModifier, pressPos); + QMouseEvent moveEvent(QEvent::MouseMove, releasePos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier); + bool moveEventReceived = qApp->notify(view.viewport(), &moveEvent); + QVERIFY(moveEventReceived); + QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::ControlModifier, releasePos); + + // Verify that item 2 is selected now + selected = view.selectionModel()->selectedIndexes(); + QCOMPARE(selected.count(), 1); + QVERIFY(selected.contains(index2)); +} + QTEST_MAIN(tst_QAbstractItemView) #include "tst_qabstractitemview.moc" -- cgit v0.12 From 2d2e422107a93a2a84ba74399678496619329e58 Mon Sep 17 00:00:00 2001 From: Florian Vichot Date: Fri, 9 Oct 2009 16:53:50 +0200 Subject: QMetaObject::activate: reordered mutex locks/unlocks around spy Always call the callbacks unlocked to avoid deadlocks. (The others call to the callback ar unlocked) Reviewed-by: Olivier Goffart Merge-request: 1744 --- src/corelib/kernel/qobject.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index a8120cf..7be19b3 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -3332,6 +3332,7 @@ void QMetaObject::activate(QObject *sender, const QMetaObject *m, int local_sign QObjectConnectionListVector *connectionLists = sender->d_func()->connectionLists; if (!connectionLists) { + locker.unlock(); if (qt_signal_spy_callback_set.signal_end_callback != 0) qt_signal_spy_callback_set.signal_end_callback(sender, signal_absolute_index); return; @@ -3401,11 +3402,11 @@ void QMetaObject::activate(QObject *sender, const QMetaObject *m, int local_sign } #endif - locker.relock(); - if (qt_signal_spy_callback_set.slot_end_callback != 0) qt_signal_spy_callback_set.slot_end_callback(receiver, method); + locker.relock(); + QObjectPrivate::resetCurrentSender(receiver, ¤tSender, previousSender); if (connectionLists->orphaned) -- cgit v0.12 From fc5e8bb849232cce27d5f53491cd01628abad760 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 12 Oct 2009 23:22:54 +0200 Subject: Fix QUrl regression with setHost("::ffff:129.144.52.38") toEncoded was returning an empty host instead of [::ffff:129.144.52.38] Merge-request: 1735 Reviewed-by: Olivier Goffart --- src/corelib/io/qurl.cpp | 9 +++++++-- tests/auto/qurl/tst_qurl.cpp | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 22d0019..6001d9d 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -3874,10 +3874,15 @@ QByteArray QUrlPrivate::toEncoded(QUrl::FormattingOptions options) const } } - if (host.startsWith(QLatin1Char('['))) + if (host.startsWith(QLatin1Char('['))) { url += host.toLatin1(); - else + } else if (host.contains(QLatin1Char(':'))) { + url += '['; + url += host.toLatin1(); + url += ']'; + } else { url += QUrl::toAce(host); + } if (!(options & QUrl::RemovePort) && port != -1) { url += ':'; url += QString::number(port).toAscii(); diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp index 026c30e..72c13bf 100644 --- a/tests/auto/qurl/tst_qurl.cpp +++ b/tests/auto/qurl/tst_qurl.cpp @@ -137,6 +137,7 @@ private slots: void ipv6(); void ipv6_2_data(); void ipv6_2(); + void moreIpv6(); void toPercentEncoding_data(); void toPercentEncoding(); void isRelative_data(); @@ -2276,6 +2277,13 @@ void tst_QUrl::ipv6_2() QCOMPARE(url.toString(), output); } +void tst_QUrl::moreIpv6() +{ + QUrl waba1("http://www.kde.org/cgi/test.cgi"); + waba1.setHost("::ffff:129.144.52.38"); + QCOMPARE(QString::fromLatin1(waba1.toEncoded()), QString::fromLatin1("http://[::ffff:129.144.52.38]/cgi/test.cgi")); +} + void tst_QUrl::punycode_data() { QTest::addColumn("original"); -- cgit v0.12 From 1f8fae877a8f4fcaec77c7d2dc1376b7ade61aee Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 13 Oct 2009 12:50:42 +0200 Subject: Fixes tst_QGraphicsProxyWidget::setWidget_simple on Mac the palettePropagation test tests that the palette does not propagate from the widget to the proxy. And on Mac, the default palette for the line edit is not the same as the default palette Reviewed-by: Alexis --- tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index 58d7896..013a028 100644 --- a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -1532,7 +1532,7 @@ void tst_QGraphicsProxyWidget::setWidget_simple() // Properties // QCOMPARE(proxy.focusPolicy(), lineEdit->focusPolicy()); - QCOMPARE(proxy.palette(), lineEdit->palette()); + // QCOMPARE(proxy.palette(), lineEdit->palette()); #ifndef QT_NO_CURSOR QCOMPARE(proxy.cursor().shape(), lineEdit->cursor().shape()); #endif -- cgit v0.12 From d9d76d0f56b0e2b0ce09abf39c710a1e666fa09f Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 13 Oct 2009 13:55:44 +0200 Subject: Fix graphicsview test on Cocoa. Cocoa doesn't support regions update and always update the bounding rect (see comment in QWidgetPrivate::update_sys in qwidget_mac.cpp) Change tests that checked that we get the exact regions. Reviewed-by: MortenS --- tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 20 ++++++++++++++------ tests/auto/qgraphicsview/tst_qgraphicsview.cpp | 6 +++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 49b76ac..0a6f60e 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -82,6 +82,14 @@ Q_DECLARE_METATYPE(QRectF) #define Q_CHECK_PAINTEVENTS #endif +#if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA) +// On mac (cocoa) we always get full update. +// So check that the expected region is contained inside the actual +#define COMPARE_REGIONS(ACTUAL, EXPECTED) QVERIFY((EXPECTED).subtracted(ACTUAL).isEmpty()) +#else +#define COMPARE_REGIONS QTRY_COMPARE +#endif + static void sendMousePress(QGraphicsScene *scene, const QPointF &point, Qt::MouseButton button = Qt::LeftButton) { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); @@ -6290,7 +6298,7 @@ void tst_QGraphicsItem::opacityZeroUpdates() QRegion expectedRegion = parentDeviceBoundingRect.adjusted(-2, -2, 2, 2); expectedRegion += childDeviceBoundingRect.adjusted(-2, -2, 2, 2); - QTRY_COMPARE(view.paintedRegion, expectedRegion); + COMPARE_REGIONS(view.paintedRegion, expectedRegion); } class StacksBehindParentHelper : public QGraphicsRectItem @@ -7117,7 +7125,7 @@ void tst_QGraphicsItem::update() qApp->processEvents(); QCOMPARE(item->repaints, 1); QCOMPARE(view.repaints, 1); - QCOMPARE(view.paintedRegion, expectedRegion + expectedRegion.translated(50, 50)); + COMPARE_REGIONS(view.paintedRegion, expectedRegion + expectedRegion.translated(50, 50)); // Make sure moving a parent item triggers an update on the children // (even though the parent itself is outside the viewport). @@ -7392,7 +7400,7 @@ void tst_QGraphicsItem::moveItem() QRegion expectedParentRegion = parentDeviceBoundingRect; // old position parentDeviceBoundingRect.translate(20, 20); expectedParentRegion += parentDeviceBoundingRect; // new position - QCOMPARE(view.paintedRegion, expectedParentRegion); + COMPARE_REGIONS(view.paintedRegion, expectedParentRegion); RESET_COUNTERS @@ -7402,7 +7410,7 @@ void tst_QGraphicsItem::moveItem() QCOMPARE(child->repaints, 1); QCOMPARE(view.repaints, 1); const QRegion expectedChildRegion = expectedParentRegion.translated(20, 20); - QCOMPARE(view.paintedRegion, expectedChildRegion); + COMPARE_REGIONS(view.paintedRegion, expectedChildRegion); RESET_COUNTERS @@ -7413,7 +7421,7 @@ void tst_QGraphicsItem::moveItem() QCOMPARE(grandChild->repaints, 1); QCOMPARE(view.repaints, 1); const QRegion expectedGrandChildRegion = expectedParentRegion.translated(40, 40); - QCOMPARE(view.paintedRegion, expectedGrandChildRegion); + COMPARE_REGIONS(view.paintedRegion, expectedGrandChildRegion); RESET_COUNTERS @@ -7426,7 +7434,7 @@ void tst_QGraphicsItem::moveItem() expectedParentRegion.translate(20, 20); expectedParentRegion += expectedChildRegion.translated(20, 20); expectedParentRegion += expectedGrandChildRegion.translated(20, 20); - QCOMPARE(view.paintedRegion, expectedParentRegion); + COMPARE_REGIONS(view.paintedRegion, expectedParentRegion); } void tst_QGraphicsItem::sorting_data() diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index 8acaa72..389200b 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -2210,9 +2210,11 @@ void tst_QGraphicsView::viewportUpdateMode() // The view gets two updates for the update scene updates. QTRY_VERIFY(!view.lastUpdateRegions.isEmpty()); +#ifndef QT_MAC_USE_COCOA //cocoa doesn't support drawing regions QCOMPARE(view.lastUpdateRegions.last().rects().size(), 2); QCOMPARE(view.lastUpdateRegions.last().rects().at(0).size(), QSize(15, 15)); QCOMPARE(view.lastUpdateRegions.last().rects().at(1).size(), QSize(15, 15)); +#endif // Set full update mode. view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate); @@ -3431,10 +3433,12 @@ void tst_QGraphicsView::exposeRegion() // Make sure it triggers correct repaint on the view. QTRY_COMPARE(view.lastUpdateRegions.size(), 1); - QTRY_COMPARE(view.lastUpdateRegions.at(0), expectedExposeRegion); + COMPARE_REGIONS(view.lastUpdateRegions.at(0), expectedExposeRegion); // Make sure the item didn't get any repaints. +#ifndef QT_MAC_USE_COCOA QCOMPARE(item->paints, 0); +#endif } void tst_QGraphicsView::update_data() -- cgit v0.12 From 9c04890642f9836fe25289d91a470cdd2de4e183 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 13 Oct 2009 15:02:40 +0200 Subject: Fix some of the QWidget test on Cocoa --- tests/auto/qwidget/tst_qwidget.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index f8341c3..c000a12 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -4524,9 +4524,6 @@ void tst_QWidget::update() QCOMPARE(child.paintedRegion, child.visibleRegion()); QCOMPARE(w.numPaintEvents, 1); QCOMPARE(w.visibleRegion(), QRegion(w.rect())); -#ifdef QT_MAC_USE_COCOA - QEXPECT_FAIL(0, "Cocoa compositor paints the content view", Continue); -#endif QCOMPARE(w.paintedRegion, child.visibleRegion().translated(childOffset)); w.reset(); @@ -5136,15 +5133,6 @@ void tst_QWidget::windowMoveResize() // now hide widget.hide(); QTest::qWait(10); -#if defined (Q_WS_MAC) && defined(QT_MAC_USE_COCOA) - QEXPECT_FAIL("130,100 0x200, flags 800", - "Cocoa's Delegate sends a spurios move event when the window has a width of zero and non-zero height", - Abort); - - QEXPECT_FAIL("130,100 0x200, flags 0", - "Cocoa's Delegate sends a spurios move event when the window has a width of zero and non-zero height", - Abort); -#endif QTRY_COMPARE(widget.pos(), rect.topLeft()); QTRY_COMPARE(widget.size(), rect.size()); @@ -7466,8 +7454,8 @@ void tst_QWidget::updateWhileMinimized() UpdateWidget widget; // Filter out activation change and focus events to avoid update() calls in QWidget. widget.updateOnActivationChangeAndFocusIn = false; - widget.show(); widget.reset(); + widget.show(); QTest::qWaitForWindowShown(&widget); QApplication::processEvents(); QTRY_VERIFY(widget.numPaintEvents > 0); @@ -9267,7 +9255,8 @@ void tst_QWidget::rectOutsideCoordinatesLimit_task144779() QPixmap correct(main.size()); correct.fill(Qt::green); - QTRY_COMPARE(QPixmap::grabWindow(main.winId()).toImage(), correct.toImage()); + QTRY_COMPARE(QPixmap::grabWindow(main.winId()).toImage().convertToFormat(QImage::Format_RGB32), + correct.toImage().convertToFormat(QImage::Format_RGB32)); QApplication::restoreOverrideCursor(); } -- cgit v0.12 From 6420f43f30e2d5cf7ae74702f96c176d7bf22a84 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 13 Oct 2009 17:40:20 +0200 Subject: Fix sorting after changing a QTableView's header Keep the sorting states in sync with the header when setting custom headers Reviewed-by: Gabriel Task-number: QTBUG-3128 task-number: 234926 --- src/gui/itemviews/qtableview.cpp | 3 +++ tests/auto/qtableview/tst_qtableview.cpp | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/gui/itemviews/qtableview.cpp b/src/gui/itemviews/qtableview.cpp index 2d98258..a610b73 100644 --- a/src/gui/itemviews/qtableview.cpp +++ b/src/gui/itemviews/qtableview.cpp @@ -1117,6 +1117,9 @@ void QTableView::setHorizontalHeader(QHeaderView *header) connect(d->horizontalHeader, SIGNAL(sectionHandleDoubleClicked(int)), this, SLOT(resizeColumnToContents(int))); connect(d->horizontalHeader, SIGNAL(geometriesChanged()), this, SLOT(updateGeometries())); + + //update the sorting enabled states on the new header + setSortingEnabled(d->sortingEnabled); } /*! diff --git a/tests/auto/qtableview/tst_qtableview.cpp b/tests/auto/qtableview/tst_qtableview.cpp index eab5a35..5b11823 100644 --- a/tests/auto/qtableview/tst_qtableview.cpp +++ b/tests/auto/qtableview/tst_qtableview.cpp @@ -193,6 +193,7 @@ private slots: void mouseWheel(); void addColumnWhileEditing(); + void task234926_setHeaderSorting(); }; // Testing get/set functions @@ -3774,5 +3775,41 @@ void tst_QTableView::task191545_dragSelectRows() } } +void tst_QTableView::task234926_setHeaderSorting() +{ + QStringListModel model; + QStringList data; + data << "orange" << "apple" << "banana" << "lemon" << "pumpkin"; + QStringList sortedDataA = data; + QStringList sortedDataD = data; + qSort(sortedDataA); + qSort(sortedDataD.begin(), sortedDataD.end(), qGreater()); + model.setStringList(data); + QTableView view; + view.setModel(&model); +// view.show(); + QTest::qWait(20); + QCOMPARE(model.stringList(), data); + view.setSortingEnabled(true); + view.sortByColumn(0, Qt::AscendingOrder); + QApplication::processEvents(); + QCOMPARE(model.stringList() , sortedDataA); + + view.horizontalHeader()->setSortIndicator(0, Qt::DescendingOrder); + QApplication::processEvents(); + QCOMPARE(model.stringList() , sortedDataD); + + QHeaderView *h = new QHeaderView(Qt::Horizontal); + h->setModel(&model); + view.setHorizontalHeader(h); + h->setSortIndicator(0, Qt::AscendingOrder); + QApplication::processEvents(); + QCOMPARE(model.stringList() , sortedDataA); + + h->setSortIndicator(0, Qt::DescendingOrder); + QApplication::processEvents(); + QCOMPARE(model.stringList() , sortedDataD); +} + QTEST_MAIN(tst_QTableView) #include "tst_qtableview.moc" -- cgit v0.12 From 19030e2af098e319e3c3f3883c51e28364bf3ccf Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Tue, 13 Oct 2009 16:26:10 +0200 Subject: Sorting bug in QTableView fix When the DisplayRole is identical for two or more items, any modification of one item (e.g. backgroundColorRole) may trigger a re-ordering, which is obviously not an behaviour to be expected. Same fix as the one used for QTreewidget in c9eacfa1c791e2d228a3c8f0c119d02d7f46ee02. Task-number: QTBUG-4856 Task-number: 262056 Reviewed-by: Olivier Goffart --- src/gui/itemviews/qtablewidget.cpp | 2 ++ tests/auto/qtablewidget/tst_qtablewidget.cpp | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/gui/itemviews/qtablewidget.cpp b/src/gui/itemviews/qtablewidget.cpp index a086498..65758b8 100644 --- a/src/gui/itemviews/qtablewidget.cpp +++ b/src/gui/itemviews/qtablewidget.cpp @@ -571,6 +571,8 @@ void QTableModel::ensureSorted(int column, Qt::SortOrder order, colItems.remove(oldRow); vit = sortedInsertionIterator(vit, colItems.end(), order, item); int newRow = qMax((int)(vit - colItems.begin()), 0); + if ((newRow < oldRow) && !(*item < *colItems.at(oldRow - 1))) + newRow = oldRow; vit = colItems.insert(vit, item); if (newRow != oldRow) { changed = true; diff --git a/tests/auto/qtablewidget/tst_qtablewidget.cpp b/tests/auto/qtablewidget/tst_qtablewidget.cpp index 5aa2d1d..b85851f 100644 --- a/tests/auto/qtablewidget/tst_qtablewidget.cpp +++ b/tests/auto/qtablewidget/tst_qtablewidget.cpp @@ -102,6 +102,7 @@ private slots: void cellWidget(); void task231094(); void task219380_removeLastRow(); + void task262056_sortDuplicate(); private: QTableWidget *testWidget; @@ -1474,6 +1475,26 @@ void tst_QTableWidget::task219380_removeLastRow() QCOMPARE(testWidget->cellWidget(18, 0)->geometry(), testWidget->visualItemRect(&item)); } +void tst_QTableWidget::task262056_sortDuplicate() +{ + testWidget->setColumnCount(2); + testWidget->setRowCount(8); + testWidget->setSortingEnabled(true); + QStringList items = (QStringList() << "AAA" << "BBB" << "CCC" << "CCC" << "DDD"\ + << "EEE" << "FFF" << "GGG"); + for (int i = 0; i<8; i++ ) { + QTableWidgetItem *twi = new QTableWidgetItem(items.at(i)); + testWidget->setItem(i,0,twi); + testWidget->setItem(i,1,new QTableWidgetItem(QString("item %1").arg(i))); + } + testWidget->sortItems(0, Qt::AscendingOrder); + QSignalSpy layoutChangedSpy(testWidget->model(), SIGNAL(layoutChanged())); + testWidget->item(3,0)->setBackgroundColor(Qt::red); + + QCOMPARE(layoutChangedSpy.count(),0); + +} + QTEST_MAIN(tst_QTableWidget) #include "tst_qtablewidget.moc" -- cgit v0.12 From 4ee954db7f99ba7021b4b825852fe56c3bcb022c Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 14 Oct 2009 11:17:00 +0200 Subject: Compile the QTableView test on Mac Reviewed-by: Gabriel --- tests/auto/qtableview/tst_qtableview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/qtableview/tst_qtableview.cpp b/tests/auto/qtableview/tst_qtableview.cpp index 5b11823..78a0dfd 100644 --- a/tests/auto/qtableview/tst_qtableview.cpp +++ b/tests/auto/qtableview/tst_qtableview.cpp @@ -3783,7 +3783,7 @@ void tst_QTableView::task234926_setHeaderSorting() QStringList sortedDataA = data; QStringList sortedDataD = data; qSort(sortedDataA); - qSort(sortedDataD.begin(), sortedDataD.end(), qGreater()); + qSort(sortedDataD.begin(), sortedDataD.end(), qGreater()); model.setStringList(data); QTableView view; view.setModel(&model); -- cgit v0.12 From f151424797794cba5a3fdaf628eabaa75a5e7801 Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Wed, 14 Oct 2009 11:30:43 +0200 Subject: Make the autotest pass for descending order in QTableWidget It failed after this commit: 19030e2af098e319e3c3f3883c51e28364bf3ccf Reviewed-by: ogoffart --- src/gui/itemviews/qtablewidget.cpp | 2 +- src/gui/itemviews/qtreewidget.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/itemviews/qtablewidget.cpp b/src/gui/itemviews/qtablewidget.cpp index 65758b8..21c4e0a 100644 --- a/src/gui/itemviews/qtablewidget.cpp +++ b/src/gui/itemviews/qtablewidget.cpp @@ -571,7 +571,7 @@ void QTableModel::ensureSorted(int column, Qt::SortOrder order, colItems.remove(oldRow); vit = sortedInsertionIterator(vit, colItems.end(), order, item); int newRow = qMax((int)(vit - colItems.begin()), 0); - if ((newRow < oldRow) && !(*item < *colItems.at(oldRow - 1))) + if ((newRow < oldRow) && !(*item < *colItems.at(oldRow - 1)) && !(*colItems.at(oldRow - 1) < *item)) newRow = oldRow; vit = colItems.insert(vit, item); if (newRow != oldRow) { diff --git a/src/gui/itemviews/qtreewidget.cpp b/src/gui/itemviews/qtreewidget.cpp index 06342d8..040c498 100644 --- a/src/gui/itemviews/qtreewidget.cpp +++ b/src/gui/itemviews/qtreewidget.cpp @@ -623,7 +623,7 @@ void QTreeModel::ensureSorted(int column, Qt::SortOrder order, lit = sortedInsertionIterator(lit, lst.end(), order, item); int newRow = qMax(lit - lst.begin(), 0); - if ((newRow < oldRow) && !(*item < *lst.at(oldRow - 1))) + if ((newRow < oldRow) && !(*item < *lst.at(oldRow - 1)) && !(*lst.at(oldRow - 1) < *item )) newRow = oldRow; lit = lst.insert(lit, item); -- cgit v0.12 From 09afb304b21be21864036d39522d4418fe243b0b Mon Sep 17 00:00:00 2001 From: Alexis Menard Date: Wed, 14 Oct 2009 11:37:50 +0200 Subject: Make the test working on random directories so we are sure there was no crap before. Reviewed-by:ogoffart --- .../auto/qfilesystemmodel/tst_qfilesystemmodel.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp index 3b24352..f2d9017 100644 --- a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -806,21 +806,13 @@ void tst_QFileSystemModel::sort() myModel->d_func()->disableRecursiveSort = true; QDir dir(QDir::tempPath()); - dir.mkdir("sortTemp"); - dir.cd("sortTemp"); + //initialize the randomness + qsrand(QDateTime::currentDateTime().toTime_t()); + QString tempName = QLatin1String("sortTemp.") + QString::number(qrand()); + dir.mkdir(tempName); + dir.cd(tempName); QTRY_VERIFY(dir.exists()); - //To be sure we clean the dir if it was there before - QDirIterator it(dir.absolutePath(), QDir::NoDotAndDotDot); - while(it.hasNext()) - { - it.next(); - QFileInfo info = it.fileInfo(); - if (info.isDir()) - dir.rmdir(info.fileName()); - else - QFile::remove(info.absoluteFilePath()); - } const QString dirPath = dir.absolutePath(); QVERIFY(dir.exists()); @@ -882,11 +874,11 @@ void tst_QFileSystemModel::sort() delete myModel; dir.setPath(QDir::tempPath()); - dir.cd("sortTemp"); + dir.cd(tempName); tempFile.remove(); tempFile2.remove(); dir.cdUp(); - dir.rmdir("sortTemp"); + dir.rmdir(tempName); } -- cgit v0.12 From 9b9e8ece43cf50a295a2a41f161be4231605e0b5 Mon Sep 17 00:00:00 2001 From: Alexis Menard Date: Wed, 14 Oct 2009 13:32:27 +0200 Subject: Split QFileDialog auto-tests in two separate dirs. This will allow slow machines to complete those tests before being killed by pulse. Reviewed-by:TrustMe --- tests/auto/qfiledialog/tst_qfiledialog.cpp | 867 ---------------------- tests/auto/qfiledialog2/qfiledialog2.pro | 27 + tests/auto/qfiledialog2/tst_qfiledialog2.cpp | 1006 ++++++++++++++++++++++++++ 3 files changed, 1033 insertions(+), 867 deletions(-) create mode 100644 tests/auto/qfiledialog2/qfiledialog2.pro create mode 100644 tests/auto/qfiledialog2/tst_qfiledialog2.cpp diff --git a/tests/auto/qfiledialog/tst_qfiledialog.cpp b/tests/auto/qfiledialog/tst_qfiledialog.cpp index dc2ca61..2f9410b 100644 --- a/tests/auto/qfiledialog/tst_qfiledialog.cpp +++ b/tests/auto/qfiledialog/tst_qfiledialog.cpp @@ -140,36 +140,6 @@ private slots: void clearLineEdit(); void enableChooseButton(); void hooks(); - void listRoot(); - void heapCorruption(); - void deleteDirAndFiles(); - void filter(); - void showNameFilterDetails(); - void unc(); - void emptyUncPath(); - - void task178897_minimumSize(); - void task180459_lastDirectory_data(); - void task180459_lastDirectory(); - void task227304_proxyOnFileDialog(); - void task227930_correctNavigationKeyboardBehavior(); -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) - void task226366_lowerCaseHardDriveWindows(); -#endif - void task233037_selectingDirectory(); - void task235069_hideOnEscape(); - void task236402_dontWatchDeletedDir(); - void task203703_returnProperSeparator(); - void task228844_ensurePreviousSorting(); - void task239706_editableFilterCombo(); - void task218353_relativePaths(); - void task251321_sideBarHiddenEntries(); - void task251341_sideBarRemoveEntries(); - void task254490_selectFileMultipleTimes(); - void task257579_sideBarWithNonCleanUrls(); - void task259105_filtersCornerCases(); - - void QTBUG4419_lineEditSelectAll(); private: QByteArray userSettings; @@ -1345,842 +1315,5 @@ void tst_QFiledialog::hooks() QCOMPARE(QFileDialog::getSaveFileName(), QString("saveName")); } -void tst_QFiledialog::listRoot() -{ -#if defined QT_BUILD_INTERNAL - QFileInfoGatherer::fetchedRoot = false; - QString dir(QDir::currentPath()); - QNonNativeFileDialog fd(0, QString(), dir); - fd.show(); - QCOMPARE(QFileInfoGatherer::fetchedRoot,false); - fd.setDirectory(""); - QTest::qWait(500); - QCOMPARE(QFileInfoGatherer::fetchedRoot,true); -#endif -} - -void tst_QFiledialog::heapCorruption() -{ - QVector dialogs; - for (int i=0; i < 10; i++) { - QNonNativeFileDialog *f = new QNonNativeFileDialog(NULL); - dialogs << f; - } - qDeleteAll(dialogs); -} - -struct FriendlyQFileDialog : public QFileDialog -{ - friend class tst_QFileDialog; - Q_DECLARE_PRIVATE(QFileDialog) -}; - - -void tst_QFiledialog::deleteDirAndFiles() -{ -#if defined QT_BUILD_INTERNAL - QString tempPath = QDir::tempPath() + '/' + "QFileDialogTestDir4FullDelete"; - QDir dir; - QVERIFY(dir.mkpath(tempPath + "/foo")); - QVERIFY(dir.mkpath(tempPath + "/foo/B")); - QVERIFY(dir.mkpath(tempPath + "/foo/B")); - QVERIFY(dir.mkpath(tempPath + "/foo/c")); - QVERIFY(dir.mkpath(tempPath + "/bar")); - QFile(tempPath + "/foo/a"); - QTemporaryFile *t; - t = new QTemporaryFile(tempPath + "/foo/aXXXXXX"); - t->setAutoRemove(false); - t->open(); - t->close(); - delete t; - - t = new QTemporaryFile(tempPath + "/foo/B/yXXXXXX"); - t->setAutoRemove(false); - t->open(); - t->close(); - delete t; - FriendlyQFileDialog fd; - fd.setOption(QFileDialog::DontUseNativeDialog); - fd.d_func()->removeDirectory(tempPath); - QFileInfo info(tempPath); - QTest::qWait(2000); - QVERIFY(!info.exists()); -#endif -} - -void tst_QFiledialog::filter() -{ - QNonNativeFileDialog fd; - QAction *hiddenAction = qFindChild(&fd, "qt_show_hidden_action"); - QVERIFY(hiddenAction); - QVERIFY(hiddenAction->isEnabled()); - QVERIFY(!hiddenAction->isChecked()); - QDir::Filters filter = fd.filter(); - filter |= QDir::Hidden; - fd.setFilter(filter); - QVERIFY(hiddenAction->isChecked()); -} - -void tst_QFiledialog::showNameFilterDetails() -{ - QNonNativeFileDialog fd; - QComboBox *filters = qFindChild(&fd, "fileTypeCombo"); - QVERIFY(filters); - QVERIFY(fd.isNameFilterDetailsVisible()); - - - QStringList filterChoices; - filterChoices << "Image files (*.png *.xpm *.jpg)" - << "Text files (*.txt)" - << "Any files (*.*)"; - fd.setFilters(filterChoices); - - fd.setNameFilterDetailsVisible(false); - QCOMPARE(filters->itemText(0), QString("Image files")); - QCOMPARE(filters->itemText(1), QString("Text files")); - QCOMPARE(filters->itemText(2), QString("Any files")); - - fd.setNameFilterDetailsVisible(true); - QCOMPARE(filters->itemText(0), filterChoices.at(0)); - QCOMPARE(filters->itemText(1), filterChoices.at(1)); - QCOMPARE(filters->itemText(2), filterChoices.at(2)); -} - -void tst_QFiledialog::unc() -{ -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) - // Only test UNC on Windows./ - QString dir("\\\\" + QtNetworkSettings::winServerName() + "\\testsharewritable"); -#else - QString dir(QDir::currentPath()); -#endif - QVERIFY(QFile::exists(dir)); - QNonNativeFileDialog fd(0, QString(), dir); - QFileSystemModel *model = qFindChild(&fd, "qt_filesystem_model"); - QVERIFY(model); - QCOMPARE(model->index(fd.directory().absolutePath()), model->index(dir)); -} - -void tst_QFiledialog::emptyUncPath() -{ - QNonNativeFileDialog fd; - fd.show(); - QLineEdit *lineEdit = qFindChild(&fd, "fileNameEdit"); - QVERIFY(lineEdit); - // press 'keys' for the input - for (int i = 0; i < 3 ; ++i) - QTest::keyPress(lineEdit, Qt::Key_Backslash); - QFileSystemModel *model = qFindChild(&fd, "qt_filesystem_model"); - QVERIFY(model); -} - -void tst_QFiledialog::task178897_minimumSize() -{ - QNonNativeFileDialog fd; - QStringList history = fd.history(); - history << QDir::toNativeSeparators("/verylongdirectory/" - "aaaaaaaaaabbbbbbbbcccccccccccddddddddddddddeeeeeeeeeeeeffffffffffgggtggggggggghhhhhhhhiiiiiijjjk"); - fd.setHistory(history); - fd.show(); - - QSize ms = fd.layout()->minimumSize(); - QVERIFY(ms.width() < 400); -} - -void tst_QFiledialog::task180459_lastDirectory_data() -{ - QTest::addColumn("path"); - QTest::addColumn("directory"); - QTest::addColumn("isEnabled"); - QTest::addColumn("result"); - - QTest::newRow("path+file") << QDir::homePath() + QDir::separator() + "foo" - << QDir::homePath() << true - << QDir::homePath() + QDir::separator() + "foo" ; - QTest::newRow("no path") << "" - << QDir::tempPath() << false << QString(); - QTest::newRow("file") << "foo" - << QDir::currentPath() << true - << QDir::currentPath() + QDir::separator() + "foo" ; - QTest::newRow("path") << QDir::homePath() - << QDir::homePath() << false << QString(); - QTest::newRow("path not existing") << "/usr/bin/foo/bar/foo/foo.txt" - << QDir::tempPath() << true - << QDir::tempPath() + QDir::separator() + "foo.txt"; - -} - -void tst_QFiledialog::task180459_lastDirectory() -{ - //first visit the temp directory and close the dialog - QNonNativeFileDialog *dlg = new QNonNativeFileDialog(0, "", QDir::tempPath()); - QFileSystemModel *model = qFindChild(dlg, "qt_filesystem_model"); - QVERIFY(model); - QCOMPARE(model->index(QDir::tempPath()), model->index(dlg->directory().absolutePath())); - delete dlg; - - QFETCH(QString, path); - QFETCH(QString, directory); - QFETCH(bool, isEnabled); - QFETCH(QString, result); - - dlg = new QNonNativeFileDialog(0, "", path); - model = qFindChild(dlg, "qt_filesystem_model"); - QVERIFY(model); - dlg->setAcceptMode(QFileDialog::AcceptSave); - QCOMPARE(model->index(dlg->directory().absolutePath()), model->index(directory)); - - QDialogButtonBox *buttonBox = qFindChild(dlg, "buttonBox"); - QPushButton *button = buttonBox->button(QDialogButtonBox::Save); - QVERIFY(button); - QCOMPARE(button->isEnabled(), isEnabled); - if (isEnabled) - QCOMPARE(model->index(result), model->index(dlg->selectedFiles().first())); - - delete dlg; -} - - - -class FilterDirModel : public QSortFilterProxyModel -{ - -public: - FilterDirModel(QString root, QObject* parent=0):QSortFilterProxyModel(parent), m_root(root) - {} - ~FilterDirModel() - {}; - -protected: - bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const - { - QModelIndex parentIndex; - parentIndex = source_parent; - - QString path; - path = parentIndex.child(source_row,0).data(Qt::DisplayRole).toString(); - - do { - path = parentIndex.data(Qt::DisplayRole).toString() + "/" + path; - parentIndex = parentIndex.parent(); - } while(parentIndex.isValid()); - - QFileInfo info(path); - if (info.isDir() && (QDir(path) != m_root)) - return false; - return true; - } - - -private: - QDir m_root; - - -}; - -class sortProxy : public QSortFilterProxyModel -{ -public: - sortProxy(QObject *parent) : QSortFilterProxyModel(parent) - { - } -protected: - virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const - { - QFileSystemModel * const model = qobject_cast(sourceModel()); - const QFileInfo leftInfo(model->fileInfo(left)); - const QFileInfo rightInfo(model->fileInfo(right)); - - if (leftInfo.isDir() == rightInfo.isDir()) - return(leftInfo.filePath().compare(rightInfo.filePath(),Qt::CaseInsensitive) < 0); - else if (leftInfo.isDir()) - return(false); - else - return(true); - } -}; - -class CrashDialog : public QNonNativeFileDialog -{ - Q_OBJECT - -public: - CrashDialog(QWidget *parent, const QString &caption, const -QString &dir, const QString &filter) - : QNonNativeFileDialog(parent, caption, dir, filter) - { - sortProxy *proxyModel = new sortProxy(this); - setProxyModel(proxyModel); - } -}; - -void tst_QFiledialog::task227304_proxyOnFileDialog() -{ -#if defined QT_BUILD_INTERNAL - QNonNativeFileDialog fd(0, "", QDir::currentPath(), 0); - fd.setProxyModel(new FilterDirModel(QDir::currentPath())); - fd.show(); - QLineEdit *edit = qFindChild(&fd, "fileNameEdit"); - QTest::qWait(200); - QTest::keyClick(edit, Qt::Key_T); - QTest::keyClick(edit, Qt::Key_S); - QTest::qWait(200); - QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); - - CrashDialog *dialog = new CrashDialog(0, QString("crash dialog test"), QDir::homePath(), QString("*") ); - dialog->setFileMode(QFileDialog::ExistingFile); - dialog->show(); - - QListView *list = qFindChild(dialog, "listView"); - QTest::qWait(200); - QTest::keyClick(list, Qt::Key_Down); - QTest::keyClick(list, Qt::Key_Return); - QTest::qWait(200); - - dialog->close(); - fd.close(); - - QNonNativeFileDialog fd2(0, "I should not crash with a proxy", QDir::tempPath(), 0); - QSortFilterProxyModel *pm = new QSortFilterProxyModel; - fd2.setProxyModel(pm); - fd2.show(); - QSidebar *sidebar = qFindChild(&fd2, "sidebar"); - sidebar->setFocus(); - sidebar->selectUrl(QUrl::fromLocalFile(QDir::homePath())); - QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(1, 0)).center()); - QTest::qWait(250); - //We shouldn't crash -#endif -} - -void tst_QFiledialog::task227930_correctNavigationKeyboardBehavior() -{ - QDir current = QDir::currentPath(); - current.mkdir("test"); - current.cd("test"); - QFile file("test/out.txt"); - QFile file2("test/out2.txt"); - QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); - QVERIFY(file2.open(QIODevice::WriteOnly | QIODevice::Text)); - current.cdUp(); - current.mkdir("test2"); - QNonNativeFileDialog fd; - fd.setViewMode(QFileDialog::List); - fd.setDirectory(current.absolutePath()); - fd.show(); - QListView *list = qFindChild(&fd, "listView"); - QTest::qWait(200); - QTest::keyClick(list, Qt::Key_Down); - QTest::keyClick(list, Qt::Key_Return); - QTest::qWait(200); - QTest::mouseClick(list->viewport(), Qt::LeftButton,0); - QTest::keyClick(list, Qt::Key_Down); - QTest::keyClick(list, Qt::Key_Backspace); - QTest::qWait(200); - QTest::keyClick(list, Qt::Key_Down); - QTest::keyClick(list, Qt::Key_Down); - QTest::keyClick(list, Qt::Key_Return); - QTest::qWait(200); - QCOMPARE(fd.isVisible(), true); - QTest::qWait(200); - file.close(); - file2.close(); - file.remove(); - file2.remove(); - current.rmdir("test"); - current.rmdir("test2"); -} - -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) -void tst_QFiledialog::task226366_lowerCaseHardDriveWindows() -{ - QNonNativeFileDialog fd; - fd.setDirectory(QDir::root().path()); - fd.show(); - QLineEdit *edit = qFindChild(&fd, "fileNameEdit"); - QToolButton *buttonParent = qFindChild(&fd, "toParentButton"); - QTest::qWait(200); - QTest::mouseClick(buttonParent, Qt::LeftButton,0,QPoint(0,0)); - QTest::qWait(2000); - QTest::keyClick(edit, Qt::Key_C); - QTest::qWait(200); - QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); - QTest::qWait(200); - QCOMPARE(edit->text(), QString("C:")); - QTest::qWait(2000); - //i clear my previous selection in the completer - QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); - edit->clear(); - QTest::keyClick(edit, (char)(Qt::Key_C | Qt::SHIFT)); - QTest::qWait(200); - QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); - QCOMPARE(edit->text(), QString("C:")); -} -#endif - -void tst_QFiledialog::task233037_selectingDirectory() -{ - QDir current = QDir::currentPath(); - current.mkdir("test"); - QNonNativeFileDialog fd; - fd.setViewMode(QFileDialog::List); - fd.setDirectory(current.absolutePath()); - fd.setAcceptMode( QFileDialog::AcceptSave); - fd.show(); - QListView *list = qFindChild(&fd, "listView"); - QTest::qWait(3000); // Wait for sort to settle (I need a signal). -#ifdef QT_KEYPAD_NAVIGATION - list->setEditFocus(true); -#endif - QTest::keyClick(list, Qt::Key_Down); - QTest::qWait(100); - QDialogButtonBox *buttonBox = qFindChild(&fd, "buttonBox"); - QPushButton *button = buttonBox->button(QDialogButtonBox::Save); - QVERIFY(button); - QCOMPARE(button->isEnabled(), true); - current.rmdir("test"); -} - -void tst_QFiledialog::task235069_hideOnEscape() -{ - QDir current = QDir::currentPath(); - QNonNativeFileDialog fd; - fd.setViewMode(QFileDialog::List); - fd.setDirectory(current.absolutePath()); - fd.setAcceptMode( QFileDialog::AcceptSave); - fd.show(); - QListView *list = qFindChild(&fd, "listView"); - list->setFocus(); - QTest::qWait(200); - QTest::keyClick(list, Qt::Key_Escape); - QCOMPARE(fd.isVisible(), false); - QNonNativeFileDialog fd2; - fd2.setDirectory(current.absolutePath()); - fd2.setAcceptMode( QFileDialog::AcceptSave); - fd2.show(); - QLineEdit *edit = qFindChild(&fd2, "fileNameEdit"); - QTest::keyClick(edit, Qt::Key_Escape); - QCOMPARE(fd2.isVisible(), false); -} - -void tst_QFiledialog::task236402_dontWatchDeletedDir() -{ -#if defined QT_BUILD_INTERNAL - //THIS TEST SHOULD NOT DISPLAY WARNINGS - QDir current = QDir::currentPath(); - //make sure it is the first on the list - current.mkdir("aaaaaaaaaa"); - FriendlyQFileDialog fd; - fd.setViewMode(QFileDialog::List); - fd.setDirectory(current.absolutePath()); - fd.setAcceptMode( QFileDialog::AcceptSave); - fd.show(); - QListView *list = qFindChild(&fd, "listView"); - list->setFocus(); - QTest::qWait(200); - QTest::keyClick(list, Qt::Key_Return); - QTest::qWait(200); - QTest::keyClick(list, Qt::Key_Backspace); - QTest::keyClick(list, Qt::Key_Down); - QTest::qWait(200); - fd.d_func()->removeDirectory(current.absolutePath() + "/aaaaaaaaaa/"); - QTest::qWait(1000); -#endif -} - -void tst_QFiledialog::task203703_returnProperSeparator() -{ - QDir current = QDir::currentPath(); - current.mkdir("aaaaaaaaaaaaaaaaaa"); - QNonNativeFileDialog fd; - fd.setDirectory(current.absolutePath()); - fd.setViewMode(QFileDialog::List); - fd.setFileMode(QFileDialog::Directory); - fd.show(); - QTest::qWait(500); - QListView *list = qFindChild(&fd, "listView"); - list->setFocus(); - QTest::qWait(200); - QTest::keyClick(list, Qt::Key_Return); - QTest::qWait(1000); - QDialogButtonBox *buttonBox = qFindChild(&fd, "buttonBox"); - QPushButton *button = buttonBox->button(QDialogButtonBox::Cancel); - QTest::keyClick(button, Qt::Key_Return); - QTest::qWait(500); - QString result = fd.selectedFiles().first(); - QVERIFY(result.at(result.count() - 1) != '/'); - QVERIFY(!result.contains('\\')); - current.rmdir("aaaaaaaaaaaaaaaaaa"); -} - -void tst_QFiledialog::task228844_ensurePreviousSorting() -{ - QDir current = QDir::currentPath(); - current.mkdir("aaaaaaaaaaaaaaaaaa"); - current.cd("aaaaaaaaaaaaaaaaaa"); - current.mkdir("a"); - current.mkdir("b"); - current.mkdir("c"); - current.mkdir("d"); - current.mkdir("e"); - current.mkdir("f"); - current.mkdir("g"); - QTemporaryFile *tempFile = new QTemporaryFile(current.absolutePath() + "/rXXXXXX"); - tempFile->open(); - current.cdUp(); - - QNonNativeFileDialog fd; - fd.setDirectory(current.absolutePath()); - fd.setViewMode(QFileDialog::Detail); - fd.show(); - QTest::qWait(500); - QTreeView *tree = qFindChild(&fd, "treeView"); - tree->header()->setSortIndicator(3,Qt::DescendingOrder); - QTest::qWait(200); - QDialogButtonBox *buttonBox = qFindChild(&fd, "buttonBox"); - QPushButton *button = buttonBox->button(QDialogButtonBox::Open); - QTest::mouseClick(button, Qt::LeftButton); - QTest::qWait(500); - - QNonNativeFileDialog fd2; - fd2.setFileMode(QFileDialog::Directory); - fd2.restoreState(fd.saveState()); - current.cd("aaaaaaaaaaaaaaaaaa"); - fd2.setDirectory(current.absolutePath()); - fd2.show(); - QTest::qWait(500); - QTreeView *tree2 = qFindChild(&fd2, "treeView"); - tree2->setFocus(); - - QCOMPARE(tree2->rootIndex().data(QFileSystemModel::FilePathRole).toString(),current.absolutePath()); - - QDialogButtonBox *buttonBox2 = qFindChild(&fd2, "buttonBox"); - QPushButton *button2 = buttonBox2->button(QDialogButtonBox::Open); - fd2.selectFile("g"); - QTest::mouseClick(button2, Qt::LeftButton); - QTest::qWait(500); - - QCOMPARE(fd2.selectedFiles().first(), current.absolutePath() + QChar('/') + QLatin1String("g")); - - QNonNativeFileDialog fd3(0, "This is a third file dialog", tempFile->fileName()); - fd3.restoreState(fd.saveState()); - fd3.setFileMode(QFileDialog::Directory); - fd3.show(); - QTest::qWait(500); - QTreeView *tree3 = qFindChild(&fd3, "treeView"); - tree3->setFocus(); - - QCOMPARE(tree3->rootIndex().data(QFileSystemModel::FilePathRole).toString(), current.absolutePath()); - - QDialogButtonBox *buttonBox3 = qFindChild(&fd3, "buttonBox"); - QPushButton *button3 = buttonBox3->button(QDialogButtonBox::Open); - QTest::mouseClick(button3, Qt::LeftButton); - QTest::qWait(500); - - QCOMPARE(fd3.selectedFiles().first(), tempFile->fileName()); - - current.cd("aaaaaaaaaaaaaaaaaa"); - current.rmdir("a"); - current.rmdir("b"); - current.rmdir("c"); - current.rmdir("d"); - current.rmdir("e"); - current.rmdir("f"); - current.rmdir("g"); - tempFile->close(); - delete tempFile; - current.cdUp(); - current.rmdir("aaaaaaaaaaaaaaaaaa"); -} - - -void tst_QFiledialog::task239706_editableFilterCombo() -{ - QNonNativeFileDialog d; - d.setNameFilter("*.cpp *.h"); - - d.show(); - QTest::qWait(500); - - QList comboList = d.findChildren(); - QComboBox *filterCombo = 0; - foreach (QComboBox *combo, comboList) { - if (combo->objectName() == QString("fileTypeCombo")) { - filterCombo = combo; - break; - } - } - Q_ASSERT(filterCombo); - filterCombo->setEditable(true); - QTest::mouseClick(filterCombo, Qt::LeftButton); - QTest::keyPress(filterCombo, Qt::Key_X); - QTest::keyPress(filterCombo, Qt::Key_Enter); // should not trigger assertion failure -} - -void tst_QFiledialog::task218353_relativePaths() -{ - QDir appDir = QDir::current(); - QVERIFY(appDir.cdUp() != false); - QNonNativeFileDialog d(0, "TestDialog", ".."); - QCOMPARE(d.directory().absolutePath(), appDir.absolutePath()); - - d.setDirectory(appDir.absolutePath() + QLatin1String("/non-existing-directory/../another-non-existing-dir/../")); - QCOMPARE(d.directory().absolutePath(), appDir.absolutePath()); - - QDir::current().mkdir("test"); - appDir = QDir::current(); - d.setDirectory(appDir.absolutePath() + QLatin1String("/test/../test/../")); - QCOMPARE(d.directory().absolutePath(), appDir.absolutePath()); - appDir.rmdir("test"); -} - -void tst_QFiledialog::task251321_sideBarHiddenEntries() -{ -#if defined QT_BUILD_INTERNAL - QNonNativeFileDialog fd; - - QDir current = QDir::currentPath(); - current.mkdir(".hidden"); - QDir hiddenDir = QDir(".hidden"); - hiddenDir.mkdir("subdir"); - QDir hiddenSubDir = QDir(".hidden/subdir"); - hiddenSubDir.mkdir("happy"); - hiddenSubDir.mkdir("happy2"); - - QList urls; - urls << QUrl::fromLocalFile(hiddenSubDir.absolutePath()); - fd.setSidebarUrls(urls); - fd.show(); - QTest::qWait(250); - - QSidebar *sidebar = qFindChild(&fd, "sidebar"); - sidebar->setFocus(); - sidebar->selectUrl(QUrl::fromLocalFile(hiddenSubDir.absolutePath())); - QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(0, 0)).center()); - QTest::qWait(250); - - QFileSystemModel *model = qFindChild(&fd, "qt_filesystem_model"); - QCOMPARE(model->rowCount(model->index(hiddenSubDir.absolutePath())), 2); - - hiddenSubDir.rmdir("happy2"); - hiddenSubDir.rmdir("happy"); - hiddenDir.rmdir("subdir"); - current.rmdir(".hidden"); -#endif -} - -#if defined QT_BUILD_INTERNAL -class MyQSideBar : public QSidebar -{ -public : - MyQSideBar(QWidget *parent = 0) : QSidebar(parent) - {} - - void removeSelection() { - QList idxs = selectionModel()->selectedIndexes(); - QList indexes; - for (int i = 0; i < idxs.count(); i++) - indexes.append(idxs.at(i)); - - for (int i = 0; i < indexes.count(); ++i) - if (!indexes.at(i).data(Qt::UserRole + 1).toUrl().path().isEmpty()) - model()->removeRow(indexes.at(i).row()); - } -}; -#endif - -void tst_QFiledialog::task251341_sideBarRemoveEntries() -{ -#if defined QT_BUILD_INTERNAL - QNonNativeFileDialog fd; - - QDir current = QDir::currentPath(); - current.mkdir("testDir"); - QDir testSubDir = QDir("testDir"); - - QList urls; - urls << QUrl::fromLocalFile(testSubDir.absolutePath()); - urls << QUrl::fromLocalFile("NotFound"); - fd.setSidebarUrls(urls); - fd.show(); - QTest::qWait(250); - - QSidebar *sidebar = qFindChild(&fd, "sidebar"); - sidebar->setFocus(); - //We enter in the first bookmark - sidebar->selectUrl(QUrl::fromLocalFile(testSubDir.absolutePath())); - QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(0, 0)).center()); - QTest::qWait(250); - - QFileSystemModel *model = qFindChild(&fd, "qt_filesystem_model"); - //There is no file - QCOMPARE(model->rowCount(model->index(testSubDir.absolutePath())), 0); - //Icon is not enabled QUrlModel::EnabledRole - QVariant value = sidebar->model()->index(0, 0).data(Qt::UserRole + 2); - QCOMPARE(qvariant_cast(value), true); - - sidebar->setFocus(); - //We enter in the second bookmark which is invalid - sidebar->selectUrl(QUrl::fromLocalFile("NotFound")); - QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(1, 0)).center()); - QTest::qWait(250); - - //We fallback to root because the entry in the bookmark is invalid - QCOMPARE(model->rowCount(model->index("NotFound")), model->rowCount(model->index(model->rootPath()))); - //Icon is not enabled QUrlModel::EnabledRole - value = sidebar->model()->index(1, 0).data(Qt::UserRole + 2); - QCOMPARE(qvariant_cast(value), false); - - MyQSideBar mySideBar; - mySideBar.init(model, urls); - mySideBar.show(); - mySideBar.selectUrl(QUrl::fromLocalFile(testSubDir.absolutePath())); - QTest::qWait(1000); - mySideBar.removeSelection(); - - //We remove the first entry - QList expected; - expected << QUrl::fromLocalFile("NotFound"); - QCOMPARE(mySideBar.urls(), expected); - - mySideBar.selectUrl(QUrl::fromLocalFile("NotFound")); - mySideBar.removeSelection(); - - //We remove the second entry - expected.clear(); - QCOMPARE(mySideBar.urls(), expected); - - current.rmdir("testDir"); -#endif -} - -void tst_QFiledialog::task254490_selectFileMultipleTimes() -{ - QString tempPath = QDir::tempPath(); - QTemporaryFile *t; - t = new QTemporaryFile; - t->open(); - QNonNativeFileDialog fd(0, "TestFileDialog"); - - fd.setDirectory(tempPath); - fd.setViewMode(QFileDialog::List); - fd.setAcceptMode(QFileDialog::AcceptSave); - fd.setFileMode(QFileDialog::AnyFile); - - //This should select the file in the QFileDialog - fd.selectFile(t->fileName()); - - //This should clear the selection and write it into the filename line edit - fd.selectFile("new_file.txt"); - - fd.show(); - QTest::qWait(250); - - QLineEdit *lineEdit = qFindChild(&fd, "fileNameEdit"); - QVERIFY(lineEdit); - QCOMPARE(lineEdit->text(),QLatin1String("new_file.txt")); - QListView *list = qFindChild(&fd, "listView"); - QVERIFY(list); - QCOMPARE(list->selectionModel()->selectedRows(0).count(), 0); - - t->deleteLater(); -} - -void tst_QFiledialog::task257579_sideBarWithNonCleanUrls() -{ -#if defined QT_BUILD_INTERNAL - QDir tempDir = QDir::temp(); - QLatin1String dirname("autotest_task257579"); - tempDir.rmdir(dirname); //makes sure it doesn't exist any more - QVERIFY(tempDir.mkdir(dirname)); - QString url = QString::fromLatin1("%1/%2/..").arg(tempDir.absolutePath()).arg(dirname); - QNonNativeFileDialog fd; - fd.setSidebarUrls(QList() << QUrl::fromLocalFile(url)); - QSidebar *sidebar = qFindChild(&fd, "sidebar"); - QCOMPARE(sidebar->urls().count(), 1); - QVERIFY(sidebar->urls().first().toLocalFile() != url); - QCOMPARE(sidebar->urls().first().toLocalFile(), QDir::cleanPath(url)); - -#ifdef Q_OS_WIN - QCOMPARE(sidebar->model()->index(0,0).data().toString().toLower(), tempDir.dirName().toLower()); -#else - QCOMPARE(sidebar->model()->index(0,0).data().toString(), tempDir.dirName()); -#endif - - //all tests are finished, we can remove the temporary dir - QVERIFY(tempDir.rmdir(dirname)); -#endif -} - -void tst_QFiledialog::task259105_filtersCornerCases() -{ - QNonNativeFileDialog fd(0, "TestFileDialog"); - fd.setNameFilter(QLatin1String("All Files! (*);;Text Files (*.txt)")); - fd.setOption(QFileDialog::HideNameFilterDetails, true); - fd.show(); - QTest::qWait(250); - - //Extensions are hidden - QComboBox *filters = qFindChild(&fd, "fileTypeCombo"); - QVERIFY(filters); - QCOMPARE(filters->currentText(), QLatin1String("All Files!")); - filters->setCurrentIndex(1); - QCOMPARE(filters->currentText(), QLatin1String("Text Files")); - - //We should have the full names - fd.setOption(QFileDialog::HideNameFilterDetails, false); - QTest::qWait(250); - filters->setCurrentIndex(0); - QCOMPARE(filters->currentText(), QLatin1String("All Files! (*)")); - filters->setCurrentIndex(1); - QCOMPARE(filters->currentText(), QLatin1String("Text Files (*.txt)")); - - //Corner case undocumented of the task - fd.setNameFilter(QLatin1String("\352 (I like cheese) All Files! (*);;Text Files (*.txt)")); - QCOMPARE(filters->currentText(), QLatin1String("\352 (I like cheese) All Files! (*)")); - filters->setCurrentIndex(1); - QCOMPARE(filters->currentText(), QLatin1String("Text Files (*.txt)")); - - fd.setOption(QFileDialog::HideNameFilterDetails, true); - filters->setCurrentIndex(0); - QTest::qWait(500); - QCOMPARE(filters->currentText(), QLatin1String("\352 (I like cheese) All Files!")); - filters->setCurrentIndex(1); - QCOMPARE(filters->currentText(), QLatin1String("Text Files")); - - fd.setOption(QFileDialog::HideNameFilterDetails, true); - filters->setCurrentIndex(0); - QTest::qWait(500); - QCOMPARE(filters->currentText(), QLatin1String("\352 (I like cheese) All Files!")); - filters->setCurrentIndex(1); - QCOMPARE(filters->currentText(), QLatin1String("Text Files")); -} - -void tst_QFiledialog::QTBUG4419_lineEditSelectAll() -{ - QString tempPath = QDir::tempPath(); - QTemporaryFile *t; - t = new QTemporaryFile; - t->open(); - QNonNativeFileDialog fd(0, "TestFileDialog", t->fileName()); - - fd.setDirectory(tempPath); - fd.setViewMode(QFileDialog::List); - fd.setAcceptMode(QFileDialog::AcceptSave); - fd.setFileMode(QFileDialog::AnyFile); - - fd.show(); - QApplication::setActiveWindow(&fd); - QTest::qWaitForWindowShown(&fd); - QTRY_COMPARE(fd.isVisible(), true); - QTRY_COMPARE(QApplication::activeWindow(), static_cast(&fd)); - - QTest::qWait(250); - QLineEdit *lineEdit = qFindChild(&fd, "fileNameEdit"); - - QCOMPARE(tempPath + QChar('/') + lineEdit->text(), t->fileName()); - QCOMPARE(tempPath + QChar('/') + lineEdit->selectedText(), t->fileName()); -} - QTEST_MAIN(tst_QFiledialog) #include "tst_qfiledialog.moc" diff --git a/tests/auto/qfiledialog2/qfiledialog2.pro b/tests/auto/qfiledialog2/qfiledialog2.pro new file mode 100644 index 0000000..4ebf977 --- /dev/null +++ b/tests/auto/qfiledialog2/qfiledialog2.pro @@ -0,0 +1,27 @@ +############################################################ +# Project file for autotest for file qfiledialog.h +############################################################ + +load(qttest_p4) + +SOURCES += tst_qfiledialog2.cpp + +wince*|symbian { + addFiles.sources = *.cpp + addFiles.path = . + filesInDir.sources = *.pro + filesInDir.path = someDir + DEPLOYMENT += addFiles filesInDir +} + +symbian:TARGET.EPOCHEAPSIZE="0x100 0x1000000" +symbian:HEADERS += ../../../include/qtgui/private/qfileinfogatherer_p.h + +wince* { + DEFINES += SRCDIR=\\\"./\\\" +} else:symbian { + TARGET.UID3 = 0xE0340003 + DEFINES += SYMBIAN_SRCDIR_UID=$$lower($$replace(TARGET.UID3,"0x","")) +} else { + DEFINES += SRCDIR=\\\"$$PWD/\\\" +} diff --git a/tests/auto/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/qfiledialog2/tst_qfiledialog2.cpp new file mode 100644 index 0000000..18f94a9 --- /dev/null +++ b/tests/auto/qfiledialog2/tst_qfiledialog2.cpp @@ -0,0 +1,1006 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../../shared/util.h" +#include "../../../src/gui/dialogs/qsidebar_p.h" +#include "../../../src/gui/dialogs/qfilesystemmodel_p.h" +#include "../../../src/gui/dialogs/qfiledialog_p.h" + +#include "../network-settings.h" + +//TESTED_CLASS= +//TESTED_FILES= + +#if defined(Q_OS_SYMBIAN) +# define STRINGIFY(x) #x +# define TOSTRING(x) STRINGIFY(x) +# define SRCDIR "C:/Private/" TOSTRING(SYMBIAN_SRCDIR_UID) "/" +#endif + +class QNonNativeFileDialog : public QFileDialog +{ + Q_OBJECT +public: + QNonNativeFileDialog(QWidget *parent = 0, const QString &caption = QString(), const QString &directory = QString(), const QString &filter = QString()) + : QFileDialog(parent, caption, directory, filter) + { + setOption(QFileDialog::DontUseNativeDialog, true); + } +}; + +class tst_QFiledialog : public QObject +{ +Q_OBJECT + +public: + tst_QFiledialog(); + virtual ~tst_QFiledialog(); + +public slots: + void init(); + void cleanup(); + +private slots: + void listRoot(); + void heapCorruption(); + void deleteDirAndFiles(); + void filter(); + void showNameFilterDetails(); + void unc(); + void emptyUncPath(); + + void task178897_minimumSize(); + void task180459_lastDirectory_data(); + void task180459_lastDirectory(); + void task227304_proxyOnFileDialog(); + void task227930_correctNavigationKeyboardBehavior(); +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) + void task226366_lowerCaseHardDriveWindows(); +#endif + void task233037_selectingDirectory(); + void task235069_hideOnEscape(); + void task236402_dontWatchDeletedDir(); + void task203703_returnProperSeparator(); + void task228844_ensurePreviousSorting(); + void task239706_editableFilterCombo(); + void task218353_relativePaths(); + void task251321_sideBarHiddenEntries(); + void task251341_sideBarRemoveEntries(); + void task254490_selectFileMultipleTimes(); + void task257579_sideBarWithNonCleanUrls(); + void task259105_filtersCornerCases(); + + void QTBUG4419_lineEditSelectAll(); + +private: + QByteArray userSettings; +}; + +tst_QFiledialog::tst_QFiledialog() +{ +} + +tst_QFiledialog::~tst_QFiledialog() +{ +} + +void tst_QFiledialog::init() +{ + // Save the developers settings so they don't get mad when their sidebar folders are gone. + QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); + settings.beginGroup(QLatin1String("Qt")); + userSettings = settings.value(QLatin1String("filedialog")).toByteArray(); + settings.remove(QLatin1String("filedialog")); + + // populate it with some default settings + QNonNativeFileDialog fd; +#if defined(Q_OS_WINCE) + QTest::qWait(1000); +#endif +} + +void tst_QFiledialog::cleanup() +{ + QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); + settings.beginGroup(QLatin1String("Qt")); + settings.setValue(QLatin1String("filedialog"), userSettings); +} + +void tst_QFiledialog::listRoot() +{ +#if defined QT_BUILD_INTERNAL + QFileInfoGatherer::fetchedRoot = false; + QString dir(QDir::currentPath()); + QNonNativeFileDialog fd(0, QString(), dir); + fd.show(); + QCOMPARE(QFileInfoGatherer::fetchedRoot,false); + fd.setDirectory(""); + QTest::qWait(500); + QCOMPARE(QFileInfoGatherer::fetchedRoot,true); +#endif +} + +void tst_QFiledialog::heapCorruption() +{ + QVector dialogs; + for (int i=0; i < 10; i++) { + QNonNativeFileDialog *f = new QNonNativeFileDialog(NULL); + dialogs << f; + } + qDeleteAll(dialogs); +} + +struct FriendlyQFileDialog : public QFileDialog +{ + friend class tst_QFileDialog; + Q_DECLARE_PRIVATE(QFileDialog) +}; + + +void tst_QFiledialog::deleteDirAndFiles() +{ +#if defined QT_BUILD_INTERNAL + QString tempPath = QDir::tempPath() + '/' + "QFileDialogTestDir4FullDelete"; + QDir dir; + QVERIFY(dir.mkpath(tempPath + "/foo")); + QVERIFY(dir.mkpath(tempPath + "/foo/B")); + QVERIFY(dir.mkpath(tempPath + "/foo/B")); + QVERIFY(dir.mkpath(tempPath + "/foo/c")); + QVERIFY(dir.mkpath(tempPath + "/bar")); + QFile(tempPath + "/foo/a"); + QTemporaryFile *t; + t = new QTemporaryFile(tempPath + "/foo/aXXXXXX"); + t->setAutoRemove(false); + t->open(); + t->close(); + delete t; + + t = new QTemporaryFile(tempPath + "/foo/B/yXXXXXX"); + t->setAutoRemove(false); + t->open(); + t->close(); + delete t; + FriendlyQFileDialog fd; + fd.setOption(QFileDialog::DontUseNativeDialog); + fd.d_func()->removeDirectory(tempPath); + QFileInfo info(tempPath); + QTest::qWait(2000); + QVERIFY(!info.exists()); +#endif +} + +void tst_QFiledialog::filter() +{ + QNonNativeFileDialog fd; + QAction *hiddenAction = qFindChild(&fd, "qt_show_hidden_action"); + QVERIFY(hiddenAction); + QVERIFY(hiddenAction->isEnabled()); + QVERIFY(!hiddenAction->isChecked()); + QDir::Filters filter = fd.filter(); + filter |= QDir::Hidden; + fd.setFilter(filter); + QVERIFY(hiddenAction->isChecked()); +} + +void tst_QFiledialog::showNameFilterDetails() +{ + QNonNativeFileDialog fd; + QComboBox *filters = qFindChild(&fd, "fileTypeCombo"); + QVERIFY(filters); + QVERIFY(fd.isNameFilterDetailsVisible()); + + + QStringList filterChoices; + filterChoices << "Image files (*.png *.xpm *.jpg)" + << "Text files (*.txt)" + << "Any files (*.*)"; + fd.setFilters(filterChoices); + + fd.setNameFilterDetailsVisible(false); + QCOMPARE(filters->itemText(0), QString("Image files")); + QCOMPARE(filters->itemText(1), QString("Text files")); + QCOMPARE(filters->itemText(2), QString("Any files")); + + fd.setNameFilterDetailsVisible(true); + QCOMPARE(filters->itemText(0), filterChoices.at(0)); + QCOMPARE(filters->itemText(1), filterChoices.at(1)); + QCOMPARE(filters->itemText(2), filterChoices.at(2)); +} + +void tst_QFiledialog::unc() +{ +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) + // Only test UNC on Windows./ + QString dir("\\\\" + QtNetworkSettings::winServerName() + "\\testsharewritable"); +#else + QString dir(QDir::currentPath()); +#endif + QVERIFY(QFile::exists(dir)); + QNonNativeFileDialog fd(0, QString(), dir); + QFileSystemModel *model = qFindChild(&fd, "qt_filesystem_model"); + QVERIFY(model); + QCOMPARE(model->index(fd.directory().absolutePath()), model->index(dir)); +} + +void tst_QFiledialog::emptyUncPath() +{ + QNonNativeFileDialog fd; + fd.show(); + QLineEdit *lineEdit = qFindChild(&fd, "fileNameEdit"); + QVERIFY(lineEdit); + // press 'keys' for the input + for (int i = 0; i < 3 ; ++i) + QTest::keyPress(lineEdit, Qt::Key_Backslash); + QFileSystemModel *model = qFindChild(&fd, "qt_filesystem_model"); + QVERIFY(model); +} + +void tst_QFiledialog::task178897_minimumSize() +{ + QNonNativeFileDialog fd; + QStringList history = fd.history(); + history << QDir::toNativeSeparators("/verylongdirectory/" + "aaaaaaaaaabbbbbbbbcccccccccccddddddddddddddeeeeeeeeeeeeffffffffffgggtggggggggghhhhhhhhiiiiiijjjk"); + fd.setHistory(history); + fd.show(); + + QSize ms = fd.layout()->minimumSize(); + QVERIFY(ms.width() < 400); +} + +void tst_QFiledialog::task180459_lastDirectory_data() +{ + QTest::addColumn("path"); + QTest::addColumn("directory"); + QTest::addColumn("isEnabled"); + QTest::addColumn("result"); + + QTest::newRow("path+file") << QDir::homePath() + QDir::separator() + "foo" + << QDir::homePath() << true + << QDir::homePath() + QDir::separator() + "foo" ; + QTest::newRow("no path") << "" + << QDir::tempPath() << false << QString(); + QTest::newRow("file") << "foo" + << QDir::currentPath() << true + << QDir::currentPath() + QDir::separator() + "foo" ; + QTest::newRow("path") << QDir::homePath() + << QDir::homePath() << false << QString(); + QTest::newRow("path not existing") << "/usr/bin/foo/bar/foo/foo.txt" + << QDir::tempPath() << true + << QDir::tempPath() + QDir::separator() + "foo.txt"; + +} + +void tst_QFiledialog::task180459_lastDirectory() +{ + //first visit the temp directory and close the dialog + QNonNativeFileDialog *dlg = new QNonNativeFileDialog(0, "", QDir::tempPath()); + QFileSystemModel *model = qFindChild(dlg, "qt_filesystem_model"); + QVERIFY(model); + QCOMPARE(model->index(QDir::tempPath()), model->index(dlg->directory().absolutePath())); + delete dlg; + + QFETCH(QString, path); + QFETCH(QString, directory); + QFETCH(bool, isEnabled); + QFETCH(QString, result); + + dlg = new QNonNativeFileDialog(0, "", path); + model = qFindChild(dlg, "qt_filesystem_model"); + QVERIFY(model); + dlg->setAcceptMode(QFileDialog::AcceptSave); + QCOMPARE(model->index(dlg->directory().absolutePath()), model->index(directory)); + + QDialogButtonBox *buttonBox = qFindChild(dlg, "buttonBox"); + QPushButton *button = buttonBox->button(QDialogButtonBox::Save); + QVERIFY(button); + QCOMPARE(button->isEnabled(), isEnabled); + if (isEnabled) + QCOMPARE(model->index(result), model->index(dlg->selectedFiles().first())); + + delete dlg; +} + + + +class FilterDirModel : public QSortFilterProxyModel +{ + +public: + FilterDirModel(QString root, QObject* parent=0):QSortFilterProxyModel(parent), m_root(root) + {} + ~FilterDirModel() + {}; + +protected: + bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const + { + QModelIndex parentIndex; + parentIndex = source_parent; + + QString path; + path = parentIndex.child(source_row,0).data(Qt::DisplayRole).toString(); + + do { + path = parentIndex.data(Qt::DisplayRole).toString() + "/" + path; + parentIndex = parentIndex.parent(); + } while(parentIndex.isValid()); + + QFileInfo info(path); + if (info.isDir() && (QDir(path) != m_root)) + return false; + return true; + } + + +private: + QDir m_root; + + +}; + +class sortProxy : public QSortFilterProxyModel +{ +public: + sortProxy(QObject *parent) : QSortFilterProxyModel(parent) + { + } +protected: + virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const + { + QFileSystemModel * const model = qobject_cast(sourceModel()); + const QFileInfo leftInfo(model->fileInfo(left)); + const QFileInfo rightInfo(model->fileInfo(right)); + + if (leftInfo.isDir() == rightInfo.isDir()) + return(leftInfo.filePath().compare(rightInfo.filePath(),Qt::CaseInsensitive) < 0); + else if (leftInfo.isDir()) + return(false); + else + return(true); + } +}; + +class CrashDialog : public QNonNativeFileDialog +{ + Q_OBJECT + +public: + CrashDialog(QWidget *parent, const QString &caption, const +QString &dir, const QString &filter) + : QNonNativeFileDialog(parent, caption, dir, filter) + { + sortProxy *proxyModel = new sortProxy(this); + setProxyModel(proxyModel); + } +}; + +void tst_QFiledialog::task227304_proxyOnFileDialog() +{ +#if defined QT_BUILD_INTERNAL + QNonNativeFileDialog fd(0, "", QDir::currentPath(), 0); + fd.setProxyModel(new FilterDirModel(QDir::currentPath())); + fd.show(); + QLineEdit *edit = qFindChild(&fd, "fileNameEdit"); + QTest::qWait(200); + QTest::keyClick(edit, Qt::Key_T); + QTest::keyClick(edit, Qt::Key_S); + QTest::qWait(200); + QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); + + CrashDialog *dialog = new CrashDialog(0, QString("crash dialog test"), QDir::homePath(), QString("*") ); + dialog->setFileMode(QFileDialog::ExistingFile); + dialog->show(); + + QListView *list = qFindChild(dialog, "listView"); + QTest::qWait(200); + QTest::keyClick(list, Qt::Key_Down); + QTest::keyClick(list, Qt::Key_Return); + QTest::qWait(200); + + dialog->close(); + fd.close(); + + QNonNativeFileDialog fd2(0, "I should not crash with a proxy", QDir::tempPath(), 0); + QSortFilterProxyModel *pm = new QSortFilterProxyModel; + fd2.setProxyModel(pm); + fd2.show(); + QSidebar *sidebar = qFindChild(&fd2, "sidebar"); + sidebar->setFocus(); + sidebar->selectUrl(QUrl::fromLocalFile(QDir::homePath())); + QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(1, 0)).center()); + QTest::qWait(250); + //We shouldn't crash +#endif +} + +void tst_QFiledialog::task227930_correctNavigationKeyboardBehavior() +{ + QDir current = QDir::currentPath(); + current.mkdir("test"); + current.cd("test"); + QFile file("test/out.txt"); + QFile file2("test/out2.txt"); + QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); + QVERIFY(file2.open(QIODevice::WriteOnly | QIODevice::Text)); + current.cdUp(); + current.mkdir("test2"); + QNonNativeFileDialog fd; + fd.setViewMode(QFileDialog::List); + fd.setDirectory(current.absolutePath()); + fd.show(); + QListView *list = qFindChild(&fd, "listView"); + QTest::qWait(200); + QTest::keyClick(list, Qt::Key_Down); + QTest::keyClick(list, Qt::Key_Return); + QTest::qWait(200); + QTest::mouseClick(list->viewport(), Qt::LeftButton,0); + QTest::keyClick(list, Qt::Key_Down); + QTest::keyClick(list, Qt::Key_Backspace); + QTest::qWait(200); + QTest::keyClick(list, Qt::Key_Down); + QTest::keyClick(list, Qt::Key_Down); + QTest::keyClick(list, Qt::Key_Return); + QTest::qWait(200); + QCOMPARE(fd.isVisible(), true); + QTest::qWait(200); + file.close(); + file2.close(); + file.remove(); + file2.remove(); + current.rmdir("test"); + current.rmdir("test2"); +} + +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +void tst_QFiledialog::task226366_lowerCaseHardDriveWindows() +{ + QNonNativeFileDialog fd; + fd.setDirectory(QDir::root().path()); + fd.show(); + QLineEdit *edit = qFindChild(&fd, "fileNameEdit"); + QToolButton *buttonParent = qFindChild(&fd, "toParentButton"); + QTest::qWait(200); + QTest::mouseClick(buttonParent, Qt::LeftButton,0,QPoint(0,0)); + QTest::qWait(2000); + QTest::keyClick(edit, Qt::Key_C); + QTest::qWait(200); + QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); + QTest::qWait(200); + QCOMPARE(edit->text(), QString("C:")); + QTest::qWait(2000); + //i clear my previous selection in the completer + QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); + edit->clear(); + QTest::keyClick(edit, (char)(Qt::Key_C | Qt::SHIFT)); + QTest::qWait(200); + QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); + QCOMPARE(edit->text(), QString("C:")); +} +#endif + +void tst_QFiledialog::task233037_selectingDirectory() +{ + QDir current = QDir::currentPath(); + current.mkdir("test"); + QNonNativeFileDialog fd; + fd.setViewMode(QFileDialog::List); + fd.setDirectory(current.absolutePath()); + fd.setAcceptMode( QFileDialog::AcceptSave); + fd.show(); + QListView *list = qFindChild(&fd, "listView"); + QTest::qWait(3000); // Wait for sort to settle (I need a signal). +#ifdef QT_KEYPAD_NAVIGATION + list->setEditFocus(true); +#endif + QTest::keyClick(list, Qt::Key_Down); + QTest::qWait(100); + QDialogButtonBox *buttonBox = qFindChild(&fd, "buttonBox"); + QPushButton *button = buttonBox->button(QDialogButtonBox::Save); + QVERIFY(button); + QCOMPARE(button->isEnabled(), true); + current.rmdir("test"); +} + +void tst_QFiledialog::task235069_hideOnEscape() +{ + QDir current = QDir::currentPath(); + QNonNativeFileDialog fd; + fd.setViewMode(QFileDialog::List); + fd.setDirectory(current.absolutePath()); + fd.setAcceptMode( QFileDialog::AcceptSave); + fd.show(); + QListView *list = qFindChild(&fd, "listView"); + list->setFocus(); + QTest::qWait(200); + QTest::keyClick(list, Qt::Key_Escape); + QCOMPARE(fd.isVisible(), false); + QNonNativeFileDialog fd2; + fd2.setDirectory(current.absolutePath()); + fd2.setAcceptMode( QFileDialog::AcceptSave); + fd2.show(); + QLineEdit *edit = qFindChild(&fd2, "fileNameEdit"); + QTest::keyClick(edit, Qt::Key_Escape); + QCOMPARE(fd2.isVisible(), false); +} + +void tst_QFiledialog::task236402_dontWatchDeletedDir() +{ +#if defined QT_BUILD_INTERNAL + //THIS TEST SHOULD NOT DISPLAY WARNINGS + QDir current = QDir::currentPath(); + //make sure it is the first on the list + current.mkdir("aaaaaaaaaa"); + FriendlyQFileDialog fd; + fd.setViewMode(QFileDialog::List); + fd.setDirectory(current.absolutePath()); + fd.setAcceptMode( QFileDialog::AcceptSave); + fd.show(); + QListView *list = qFindChild(&fd, "listView"); + list->setFocus(); + QTest::qWait(200); + QTest::keyClick(list, Qt::Key_Return); + QTest::qWait(200); + QTest::keyClick(list, Qt::Key_Backspace); + QTest::keyClick(list, Qt::Key_Down); + QTest::qWait(200); + fd.d_func()->removeDirectory(current.absolutePath() + "/aaaaaaaaaa/"); + QTest::qWait(1000); +#endif +} + +void tst_QFiledialog::task203703_returnProperSeparator() +{ + QDir current = QDir::currentPath(); + current.mkdir("aaaaaaaaaaaaaaaaaa"); + QNonNativeFileDialog fd; + fd.setDirectory(current.absolutePath()); + fd.setViewMode(QFileDialog::List); + fd.setFileMode(QFileDialog::Directory); + fd.show(); + QTest::qWait(500); + QListView *list = qFindChild(&fd, "listView"); + list->setFocus(); + QTest::qWait(200); + QTest::keyClick(list, Qt::Key_Return); + QTest::qWait(1000); + QDialogButtonBox *buttonBox = qFindChild(&fd, "buttonBox"); + QPushButton *button = buttonBox->button(QDialogButtonBox::Cancel); + QTest::keyClick(button, Qt::Key_Return); + QTest::qWait(500); + QString result = fd.selectedFiles().first(); + QVERIFY(result.at(result.count() - 1) != '/'); + QVERIFY(!result.contains('\\')); + current.rmdir("aaaaaaaaaaaaaaaaaa"); +} + +void tst_QFiledialog::task228844_ensurePreviousSorting() +{ + QDir current = QDir::currentPath(); + current.mkdir("aaaaaaaaaaaaaaaaaa"); + current.cd("aaaaaaaaaaaaaaaaaa"); + current.mkdir("a"); + current.mkdir("b"); + current.mkdir("c"); + current.mkdir("d"); + current.mkdir("e"); + current.mkdir("f"); + current.mkdir("g"); + QTemporaryFile *tempFile = new QTemporaryFile(current.absolutePath() + "/rXXXXXX"); + tempFile->open(); + current.cdUp(); + + QNonNativeFileDialog fd; + fd.setDirectory(current.absolutePath()); + fd.setViewMode(QFileDialog::Detail); + fd.show(); + QTest::qWait(500); + QTreeView *tree = qFindChild(&fd, "treeView"); + tree->header()->setSortIndicator(3,Qt::DescendingOrder); + QTest::qWait(200); + QDialogButtonBox *buttonBox = qFindChild(&fd, "buttonBox"); + QPushButton *button = buttonBox->button(QDialogButtonBox::Open); + QTest::mouseClick(button, Qt::LeftButton); + QTest::qWait(500); + + QNonNativeFileDialog fd2; + fd2.setFileMode(QFileDialog::Directory); + fd2.restoreState(fd.saveState()); + current.cd("aaaaaaaaaaaaaaaaaa"); + fd2.setDirectory(current.absolutePath()); + fd2.show(); + QTest::qWait(500); + QTreeView *tree2 = qFindChild(&fd2, "treeView"); + tree2->setFocus(); + + QCOMPARE(tree2->rootIndex().data(QFileSystemModel::FilePathRole).toString(),current.absolutePath()); + + QDialogButtonBox *buttonBox2 = qFindChild(&fd2, "buttonBox"); + QPushButton *button2 = buttonBox2->button(QDialogButtonBox::Open); + fd2.selectFile("g"); + QTest::mouseClick(button2, Qt::LeftButton); + QTest::qWait(500); + + QCOMPARE(fd2.selectedFiles().first(), current.absolutePath() + QChar('/') + QLatin1String("g")); + + QNonNativeFileDialog fd3(0, "This is a third file dialog", tempFile->fileName()); + fd3.restoreState(fd.saveState()); + fd3.setFileMode(QFileDialog::Directory); + fd3.show(); + QTest::qWait(500); + QTreeView *tree3 = qFindChild(&fd3, "treeView"); + tree3->setFocus(); + + QCOMPARE(tree3->rootIndex().data(QFileSystemModel::FilePathRole).toString(), current.absolutePath()); + + QDialogButtonBox *buttonBox3 = qFindChild(&fd3, "buttonBox"); + QPushButton *button3 = buttonBox3->button(QDialogButtonBox::Open); + QTest::mouseClick(button3, Qt::LeftButton); + QTest::qWait(500); + + QCOMPARE(fd3.selectedFiles().first(), tempFile->fileName()); + + current.cd("aaaaaaaaaaaaaaaaaa"); + current.rmdir("a"); + current.rmdir("b"); + current.rmdir("c"); + current.rmdir("d"); + current.rmdir("e"); + current.rmdir("f"); + current.rmdir("g"); + tempFile->close(); + delete tempFile; + current.cdUp(); + current.rmdir("aaaaaaaaaaaaaaaaaa"); +} + + +void tst_QFiledialog::task239706_editableFilterCombo() +{ + QNonNativeFileDialog d; + d.setNameFilter("*.cpp *.h"); + + d.show(); + QTest::qWait(500); + + QList comboList = d.findChildren(); + QComboBox *filterCombo = 0; + foreach (QComboBox *combo, comboList) { + if (combo->objectName() == QString("fileTypeCombo")) { + filterCombo = combo; + break; + } + } + Q_ASSERT(filterCombo); + filterCombo->setEditable(true); + QTest::mouseClick(filterCombo, Qt::LeftButton); + QTest::keyPress(filterCombo, Qt::Key_X); + QTest::keyPress(filterCombo, Qt::Key_Enter); // should not trigger assertion failure +} + +void tst_QFiledialog::task218353_relativePaths() +{ + QDir appDir = QDir::current(); + QVERIFY(appDir.cdUp() != false); + QNonNativeFileDialog d(0, "TestDialog", ".."); + QCOMPARE(d.directory().absolutePath(), appDir.absolutePath()); + + d.setDirectory(appDir.absolutePath() + QLatin1String("/non-existing-directory/../another-non-existing-dir/../")); + QCOMPARE(d.directory().absolutePath(), appDir.absolutePath()); + + QDir::current().mkdir("test"); + appDir = QDir::current(); + d.setDirectory(appDir.absolutePath() + QLatin1String("/test/../test/../")); + QCOMPARE(d.directory().absolutePath(), appDir.absolutePath()); + appDir.rmdir("test"); +} + +void tst_QFiledialog::task251321_sideBarHiddenEntries() +{ +#if defined QT_BUILD_INTERNAL + QNonNativeFileDialog fd; + + QDir current = QDir::currentPath(); + current.mkdir(".hidden"); + QDir hiddenDir = QDir(".hidden"); + hiddenDir.mkdir("subdir"); + QDir hiddenSubDir = QDir(".hidden/subdir"); + hiddenSubDir.mkdir("happy"); + hiddenSubDir.mkdir("happy2"); + + QList urls; + urls << QUrl::fromLocalFile(hiddenSubDir.absolutePath()); + fd.setSidebarUrls(urls); + fd.show(); + QTest::qWait(250); + + QSidebar *sidebar = qFindChild(&fd, "sidebar"); + sidebar->setFocus(); + sidebar->selectUrl(QUrl::fromLocalFile(hiddenSubDir.absolutePath())); + QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(0, 0)).center()); + QTest::qWait(250); + + QFileSystemModel *model = qFindChild(&fd, "qt_filesystem_model"); + QCOMPARE(model->rowCount(model->index(hiddenSubDir.absolutePath())), 2); + + hiddenSubDir.rmdir("happy2"); + hiddenSubDir.rmdir("happy"); + hiddenDir.rmdir("subdir"); + current.rmdir(".hidden"); +#endif +} + +#if defined QT_BUILD_INTERNAL +class MyQSideBar : public QSidebar +{ +public : + MyQSideBar(QWidget *parent = 0) : QSidebar(parent) + {} + + void removeSelection() { + QList idxs = selectionModel()->selectedIndexes(); + QList indexes; + for (int i = 0; i < idxs.count(); i++) + indexes.append(idxs.at(i)); + + for (int i = 0; i < indexes.count(); ++i) + if (!indexes.at(i).data(Qt::UserRole + 1).toUrl().path().isEmpty()) + model()->removeRow(indexes.at(i).row()); + } +}; +#endif + +void tst_QFiledialog::task251341_sideBarRemoveEntries() +{ +#if defined QT_BUILD_INTERNAL + QNonNativeFileDialog fd; + + QDir current = QDir::currentPath(); + current.mkdir("testDir"); + QDir testSubDir = QDir("testDir"); + + QList urls; + urls << QUrl::fromLocalFile(testSubDir.absolutePath()); + urls << QUrl::fromLocalFile("NotFound"); + fd.setSidebarUrls(urls); + fd.show(); + QTest::qWait(250); + + QSidebar *sidebar = qFindChild(&fd, "sidebar"); + sidebar->setFocus(); + //We enter in the first bookmark + sidebar->selectUrl(QUrl::fromLocalFile(testSubDir.absolutePath())); + QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(0, 0)).center()); + QTest::qWait(250); + + QFileSystemModel *model = qFindChild(&fd, "qt_filesystem_model"); + //There is no file + QCOMPARE(model->rowCount(model->index(testSubDir.absolutePath())), 0); + //Icon is not enabled QUrlModel::EnabledRole + QVariant value = sidebar->model()->index(0, 0).data(Qt::UserRole + 2); + QCOMPARE(qvariant_cast(value), true); + + sidebar->setFocus(); + //We enter in the second bookmark which is invalid + sidebar->selectUrl(QUrl::fromLocalFile("NotFound")); + QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(1, 0)).center()); + QTest::qWait(250); + + //We fallback to root because the entry in the bookmark is invalid + QCOMPARE(model->rowCount(model->index("NotFound")), model->rowCount(model->index(model->rootPath()))); + //Icon is not enabled QUrlModel::EnabledRole + value = sidebar->model()->index(1, 0).data(Qt::UserRole + 2); + QCOMPARE(qvariant_cast(value), false); + + MyQSideBar mySideBar; + mySideBar.init(model, urls); + mySideBar.show(); + mySideBar.selectUrl(QUrl::fromLocalFile(testSubDir.absolutePath())); + QTest::qWait(1000); + mySideBar.removeSelection(); + + //We remove the first entry + QList expected; + expected << QUrl::fromLocalFile("NotFound"); + QCOMPARE(mySideBar.urls(), expected); + + mySideBar.selectUrl(QUrl::fromLocalFile("NotFound")); + mySideBar.removeSelection(); + + //We remove the second entry + expected.clear(); + QCOMPARE(mySideBar.urls(), expected); + + current.rmdir("testDir"); +#endif +} + +void tst_QFiledialog::task254490_selectFileMultipleTimes() +{ + QString tempPath = QDir::tempPath(); + QTemporaryFile *t; + t = new QTemporaryFile; + t->open(); + QNonNativeFileDialog fd(0, "TestFileDialog"); + + fd.setDirectory(tempPath); + fd.setViewMode(QFileDialog::List); + fd.setAcceptMode(QFileDialog::AcceptSave); + fd.setFileMode(QFileDialog::AnyFile); + + //This should select the file in the QFileDialog + fd.selectFile(t->fileName()); + + //This should clear the selection and write it into the filename line edit + fd.selectFile("new_file.txt"); + + fd.show(); + QTest::qWait(250); + + QLineEdit *lineEdit = qFindChild(&fd, "fileNameEdit"); + QVERIFY(lineEdit); + QCOMPARE(lineEdit->text(),QLatin1String("new_file.txt")); + QListView *list = qFindChild(&fd, "listView"); + QVERIFY(list); + QCOMPARE(list->selectionModel()->selectedRows(0).count(), 0); + + t->deleteLater(); +} + +void tst_QFiledialog::task257579_sideBarWithNonCleanUrls() +{ +#if defined QT_BUILD_INTERNAL + QDir tempDir = QDir::temp(); + QLatin1String dirname("autotest_task257579"); + tempDir.rmdir(dirname); //makes sure it doesn't exist any more + QVERIFY(tempDir.mkdir(dirname)); + QString url = QString::fromLatin1("%1/%2/..").arg(tempDir.absolutePath()).arg(dirname); + QNonNativeFileDialog fd; + fd.setSidebarUrls(QList() << QUrl::fromLocalFile(url)); + QSidebar *sidebar = qFindChild(&fd, "sidebar"); + QCOMPARE(sidebar->urls().count(), 1); + QVERIFY(sidebar->urls().first().toLocalFile() != url); + QCOMPARE(sidebar->urls().first().toLocalFile(), QDir::cleanPath(url)); + +#ifdef Q_OS_WIN + QCOMPARE(sidebar->model()->index(0,0).data().toString().toLower(), tempDir.dirName().toLower()); +#else + QCOMPARE(sidebar->model()->index(0,0).data().toString(), tempDir.dirName()); +#endif + + //all tests are finished, we can remove the temporary dir + QVERIFY(tempDir.rmdir(dirname)); +#endif +} + +void tst_QFiledialog::task259105_filtersCornerCases() +{ + QNonNativeFileDialog fd(0, "TestFileDialog"); + fd.setNameFilter(QLatin1String("All Files! (*);;Text Files (*.txt)")); + fd.setOption(QFileDialog::HideNameFilterDetails, true); + fd.show(); + QTest::qWait(250); + + //Extensions are hidden + QComboBox *filters = qFindChild(&fd, "fileTypeCombo"); + QVERIFY(filters); + QCOMPARE(filters->currentText(), QLatin1String("All Files!")); + filters->setCurrentIndex(1); + QCOMPARE(filters->currentText(), QLatin1String("Text Files")); + + //We should have the full names + fd.setOption(QFileDialog::HideNameFilterDetails, false); + QTest::qWait(250); + filters->setCurrentIndex(0); + QCOMPARE(filters->currentText(), QLatin1String("All Files! (*)")); + filters->setCurrentIndex(1); + QCOMPARE(filters->currentText(), QLatin1String("Text Files (*.txt)")); + + //Corner case undocumented of the task + fd.setNameFilter(QLatin1String("\352 (I like cheese) All Files! (*);;Text Files (*.txt)")); + QCOMPARE(filters->currentText(), QLatin1String("\352 (I like cheese) All Files! (*)")); + filters->setCurrentIndex(1); + QCOMPARE(filters->currentText(), QLatin1String("Text Files (*.txt)")); + + fd.setOption(QFileDialog::HideNameFilterDetails, true); + filters->setCurrentIndex(0); + QTest::qWait(500); + QCOMPARE(filters->currentText(), QLatin1String("\352 (I like cheese) All Files!")); + filters->setCurrentIndex(1); + QCOMPARE(filters->currentText(), QLatin1String("Text Files")); + + fd.setOption(QFileDialog::HideNameFilterDetails, true); + filters->setCurrentIndex(0); + QTest::qWait(500); + QCOMPARE(filters->currentText(), QLatin1String("\352 (I like cheese) All Files!")); + filters->setCurrentIndex(1); + QCOMPARE(filters->currentText(), QLatin1String("Text Files")); +} + +void tst_QFiledialog::QTBUG4419_lineEditSelectAll() +{ + QString tempPath = QDir::tempPath(); + QTemporaryFile *t; + t = new QTemporaryFile; + t->open(); + QNonNativeFileDialog fd(0, "TestFileDialog", t->fileName()); + + fd.setDirectory(tempPath); + fd.setViewMode(QFileDialog::List); + fd.setAcceptMode(QFileDialog::AcceptSave); + fd.setFileMode(QFileDialog::AnyFile); + + fd.show(); + QApplication::setActiveWindow(&fd); + QTest::qWaitForWindowShown(&fd); + QTRY_COMPARE(fd.isVisible(), true); + QTRY_COMPARE(QApplication::activeWindow(), static_cast(&fd)); + + QTest::qWait(250); + QLineEdit *lineEdit = qFindChild(&fd, "fileNameEdit"); + + QCOMPARE(tempPath + QChar('/') + lineEdit->text(), t->fileName()); + QCOMPARE(tempPath + QChar('/') + lineEdit->selectedText(), t->fileName()); +} + +QTEST_MAIN(tst_QFiledialog) +#include "tst_qfiledialog2.moc" -- cgit v0.12 From fad919927f2ab2ca3e9eebb59c5f3a9171b068a5 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 14 Oct 2009 18:08:58 +0200 Subject: Disable tst_QTableView::tabFocus to work when qt_tab_all_widget is disabled Logic copied from the QMenu test Also do the same in the QButtonGroup test --- tests/auto/qbuttongroup/tst_qbuttongroup.cpp | 11 ++++++----- tests/auto/qtableview/tst_qtableview.cpp | 6 ++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/auto/qbuttongroup/tst_qbuttongroup.cpp b/tests/auto/qbuttongroup/tst_qbuttongroup.cpp index a19f865..b568068 100644 --- a/tests/auto/qbuttongroup/tst_qbuttongroup.cpp +++ b/tests/auto/qbuttongroup/tst_qbuttongroup.cpp @@ -128,14 +128,15 @@ void tst_QButtonGroup::cleanup() { } +QT_BEGIN_NAMESPACE +extern bool qt_tab_all_widgets; +QT_END_NAMESPACE + + void tst_QButtonGroup::arrowKeyNavigation() { -#ifdef Q_WS_MAC - QSettings appleSettings(QLatin1String("apple.com")); - QVariant appleValue = appleSettings.value(QLatin1String("AppleKeyboardUIMode"), 0); - if (!(appleValue.toInt() & 0x2)) + if (!qt_tab_all_widgets) QSKIP("This test requires full keyboard control to be enabled.", SkipAll); -#endif QDialog dlg(0); QHBoxLayout layout(&dlg); diff --git a/tests/auto/qtableview/tst_qtableview.cpp b/tests/auto/qtableview/tst_qtableview.cpp index 78a0dfd..d92656c 100644 --- a/tests/auto/qtableview/tst_qtableview.cpp +++ b/tests/auto/qtableview/tst_qtableview.cpp @@ -3250,9 +3250,15 @@ void tst_QTableView::resizeToContents() } +QT_BEGIN_NAMESPACE + extern bool qt_tab_all_widgets; // qapplication_mac.cpp +QT_END_NAMESPACE void tst_QTableView::tabFocus() { + if (!qt_tab_all_widgets) + QSKIP("This test requires full keyboard control to be enabled.", SkipAll); + // QTableView enables tabKeyNavigation by default, but you should be able // to change focus on an empty table view, or on a table view that doesn't // have this property set. -- cgit v0.12 From 5e92ae16f80d6a0a824744fa4a2bdb7d6ce726e0 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 14 Oct 2009 18:23:35 +0200 Subject: stabilize QTableView test on cocoa --- tests/auto/qtableview/tst_qtableview.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/auto/qtableview/tst_qtableview.cpp b/tests/auto/qtableview/tst_qtableview.cpp index d92656c..5ff217c 100644 --- a/tests/auto/qtableview/tst_qtableview.cpp +++ b/tests/auto/qtableview/tst_qtableview.cpp @@ -2703,6 +2703,7 @@ void tst_QTableView::indexAt() QtTestTableView view; view.show(); + QTest::qWaitForWindowShown(&view); //some styles change the scroll mode in their polish view.setHorizontalScrollMode(QAbstractItemView::ScrollPerItem); @@ -2718,9 +2719,10 @@ void tst_QTableView::indexAt() for (int c = 0; c < columnCount; ++c) view.setColumnWidth(c, columnWidth); - QTest::qWait(0); // ### needed to pass the test + QTest::qWait(20); view.horizontalScrollBar()->setValue(horizontalScroll); view.verticalScrollBar()->setValue(verticalScroll); + QTest::qWait(20); QModelIndex index = view.indexAt(QPoint(x, y)); QCOMPARE(index.row(), expectedRow); -- cgit v0.12 From e479ba841f62cc4af709e97f8085d7779e14e3e9 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 15 Oct 2009 09:52:42 +0200 Subject: Compile tests under Windows --- tests/auto/qbuttongroup/tst_qbuttongroup.cpp | 2 +- tests/auto/qtableview/tst_qtableview.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/qbuttongroup/tst_qbuttongroup.cpp b/tests/auto/qbuttongroup/tst_qbuttongroup.cpp index b568068..8b0335c 100644 --- a/tests/auto/qbuttongroup/tst_qbuttongroup.cpp +++ b/tests/auto/qbuttongroup/tst_qbuttongroup.cpp @@ -129,7 +129,7 @@ void tst_QButtonGroup::cleanup() } QT_BEGIN_NAMESPACE -extern bool qt_tab_all_widgets; +extern bool Q_GUI_EXPORT qt_tab_all_widgets; QT_END_NAMESPACE diff --git a/tests/auto/qtableview/tst_qtableview.cpp b/tests/auto/qtableview/tst_qtableview.cpp index 5ff217c..d75cfa7 100644 --- a/tests/auto/qtableview/tst_qtableview.cpp +++ b/tests/auto/qtableview/tst_qtableview.cpp @@ -3253,7 +3253,7 @@ void tst_QTableView::resizeToContents() } QT_BEGIN_NAMESPACE - extern bool qt_tab_all_widgets; // qapplication_mac.cpp +extern bool Q_GUI_EXPORT qt_tab_all_widgets; // qapplication.cpp QT_END_NAMESPACE void tst_QTableView::tabFocus() -- cgit v0.12