diff options
Diffstat (limited to 'tests/auto/widgets')
21 files changed, 1119 insertions, 154 deletions
diff --git a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp index 096658ae02..b9ca831e0c 100644 --- a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp +++ b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp @@ -114,8 +114,8 @@ public: virtual ~tst_QFiledialog(); public slots: + void initTestCase(); void init(); - void cleanup(); private slots: void currentChangedSignal(); @@ -171,7 +171,7 @@ private slots: void tildeExpansion(); #endif // QT_BUILD_INTERNAL #endif - void getFileUrl(); + void rejectModalDialogs(); private: QByteArray userSettings; @@ -185,28 +185,25 @@ tst_QFiledialog::~tst_QFiledialog() { } +void tst_QFiledialog::initTestCase() +{ + QStandardPaths::setTestModeEnabled(true); +} + void tst_QFiledialog::init() { - // Save the developers settings so they don't get mad when their sidebar folders are gone. + // clean up the sidebar between each test QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); settings.beginGroup(QLatin1String("Qt")); - userSettings = settings.value(QLatin1String("filedialog")).toByteArray(); settings.remove(QLatin1String("filedialog")); - // populate it with some default settings + // populate the sidebar with some default settings QNonNativeFileDialog fd; #if defined(Q_OS_WINCE) QTest::qWait(1000); #endif } -void tst_QFiledialog::cleanup() -{ - QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); - settings.beginGroup(QLatin1String("Qt")); - settings.setValue(QLatin1String("filedialog"), userSettings); -} - class MyAbstractItemDelegate : public QAbstractItemDelegate { public: @@ -252,7 +249,10 @@ void tst_QFiledialog::directoryEnteredSignal() // sidebar QSidebar *sidebar = fd.findChild<QSidebar*>("sidebar"); - sidebar->setCurrentIndex(sidebar->model()->index(1, 0)); + QVERIFY(sidebar->model()->rowCount() >= 2); + QModelIndex secondItem = sidebar->model()->index(1, 0); + QVERIFY(secondItem.isValid()); + sidebar->setCurrentIndex(secondItem); QTest::keyPress(sidebar->viewport(), Qt::Key_Return); QCOMPARE(spyDirectoryEntered.count(), 1); spyDirectoryEntered.clear(); @@ -1451,7 +1451,7 @@ public slots: } }; -void tst_QFiledialog::getFileUrl() +void tst_QFiledialog::rejectModalDialogs() { // QTBUG-38672 , static functions should return empty Urls const QFileDialog::Options options = QFileDialog::DontUseNativeDialog; @@ -1472,6 +1472,18 @@ void tst_QFiledialog::getFileUrl() QVERIFY(url.isEmpty()); QVERIFY(!url.isValid()); + // Same test with local files + QString file = QFileDialog::getOpenFileName(0, QStringLiteral("getOpenFileName"), + QString(), QString(), Q_NULLPTR, options); + QVERIFY(file.isEmpty()); + + file = QFileDialog::getExistingDirectory(0, QStringLiteral("getExistingDirectory"), + QString(), options | QFileDialog::ShowDirsOnly); + QVERIFY(file.isEmpty()); + + file = QFileDialog::getSaveFileName(0, QStringLiteral("getSaveFileName"), + QString(), QString(), Q_NULLPTR, options); + QVERIFY(file.isEmpty()); } QTEST_MAIN(tst_QFiledialog) diff --git a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp index 060fa51293..86b9d7eee2 100644 --- a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp +++ b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp @@ -42,34 +42,34 @@ #include <QtTest/QtTest> -#include <qcoreapplication.h> +#include <qapplication.h> #include <qdebug.h> +#include <qprogressbar.h> #include <qprogressdialog.h> +#include <qpushbutton.h> #include <qlabel.h> +#include <qpointer.h> #include <qthread.h> +#include <qtranslator.h> class tst_QProgressDialog : public QObject { -Q_OBJECT + Q_OBJECT -public: - tst_QProgressDialog(); - virtual ~tst_QProgressDialog(); - -private slots: +private Q_SLOTS: + void cleanup(); void autoShow_data(); void autoShow(); void getSetCheck(); void task198202(); void QTBUG_31046(); + void settingCustomWidgets(); + void i18n(); }; -tst_QProgressDialog::tst_QProgressDialog() -{ -} - -tst_QProgressDialog::~tst_QProgressDialog() +void tst_QProgressDialog::cleanup() { + QVERIFY(QApplication::topLevelWindows().empty()); } void tst_QProgressDialog::autoShow_data() @@ -190,5 +190,94 @@ void tst_QProgressDialog::QTBUG_31046() QCOMPARE(50, dlg.value()); } +void tst_QProgressDialog::settingCustomWidgets() +{ + QPointer<QLabel> l = new QLabel; + QPointer<QPushButton> btn = new QPushButton; + QPointer<QProgressBar> bar = new QProgressBar; + QVERIFY(!l->parent()); + QVERIFY(!btn->parent()); + QVERIFY(!bar->parent()); + + { + QProgressDialog dlg; + + QVERIFY(!dlg.isAncestorOf(l)); + dlg.setLabel(l); + QVERIFY(dlg.isAncestorOf(l)); + QTest::ignoreMessage(QtWarningMsg, "QProgressDialog::setLabel: Attempt to set the same label again"); + dlg.setLabel(l); // setting the same widget again should not crash + QVERIFY(l); // and not delete the (old == new) widget + + QVERIFY(!dlg.isAncestorOf(btn)); + dlg.setCancelButton(btn); + QVERIFY(dlg.isAncestorOf(btn)); + QTest::ignoreMessage(QtWarningMsg, "QProgressDialog::setCancelButton: Attempt to set the same button again"); + dlg.setCancelButton(btn); // setting the same widget again should not crash + QVERIFY(btn); // and not delete the (old == new) widget + + QVERIFY(!dlg.isAncestorOf(bar)); + dlg.setBar(bar); + QEXPECT_FAIL("", "QProgressBar doesn't adopt custom progress bar as children", Continue); + QVERIFY(dlg.isAncestorOf(bar)); + QTest::ignoreMessage(QtWarningMsg, "QProgressDialog::setBar: Attempt to set the same progress bar again"); + dlg.setBar(bar); // setting the same widget again should not crash + QVERIFY(bar); // and not delete the (old == new) widget + } + + QVERIFY(!l); + QVERIFY(!btn); +#if 0 + QEXPECT_FAIL("", "QProgressBar doesn't clean up custom progress bars", Continue); + QVERIFY(!bar); +#else + // make cleanup() pass + delete bar; +#endif +} + +class QTestTranslator : public QTranslator +{ + const QString m_str; +public: + explicit QTestTranslator(QString str) : m_str(qMove(str)) {} + + QString translate(const char *, const char *sourceText, const char *, int) const Q_DECL_OVERRIDE + { return m_str + sourceText + m_str; } + + bool isEmpty() const Q_DECL_OVERRIDE { return false; } +}; + +template <typename Translator> +class QTranslatorGuard { + Translator t; +public: + template <typename Arg> + explicit QTranslatorGuard(Arg a) : t(qMove(a)) + { qApp->installTranslator(&t); } + ~QTranslatorGuard() + { qApp->removeTranslator(&t); } +}; + +void tst_QProgressDialog::i18n() +{ + QProgressDialog dlg; + QPushButton *btn = dlg.findChild<QPushButton*>(); + QVERIFY(btn); + const QString xxx = QStringLiteral("xxx"); + { + QTranslatorGuard<QTestTranslator> guard(xxx); + { + QPushButton *btn = dlg.findChild<QPushButton*>(); + QVERIFY(btn); + QTRY_COMPARE(btn->text(), QProgressDialog::tr("Cancel")); + QVERIFY(btn->text().startsWith(xxx)); + } + } + QVERIFY(btn); + QTRY_COMPARE(btn->text(), QProgressDialog::tr("Cancel")); + QVERIFY(!btn->text().startsWith(xxx)); +} + QTEST_MAIN(tst_QProgressDialog) #include "tst_qprogressdialog.moc" diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index e9aae1ec59..c89b05616d 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -389,6 +389,8 @@ private slots: void itemClipsChildrenToShape5(); void itemClipsTextChildToShape(); void itemClippingDiscovery(); + void itemContainsChildrenInShape(); + void itemContainsChildrenInShape2(); void ancestorFlags(); void untransformable(); void contextMenuEventPropagation(); @@ -5855,6 +5857,102 @@ void tst_QGraphicsItem::itemClippingDiscovery() QCOMPARE(scene.itemAt(90, 90), (QGraphicsItem *)0); } +class ItemCountsBoundingRectCalls : public QGraphicsRectItem +{ +public: + ItemCountsBoundingRectCalls(const QRectF & rect, QGraphicsItem *parent = 0) + : QGraphicsRectItem(rect, parent), boundingRectCalls(0) {} + QRectF boundingRect () const { + ++boundingRectCalls; + return QGraphicsRectItem::boundingRect(); + } + mutable int boundingRectCalls; +}; + +void tst_QGraphicsItem::itemContainsChildrenInShape() +{ + ItemCountsBoundingRectCalls *parent = new ItemCountsBoundingRectCalls(QRectF(0,0, 10, 10)); + ItemCountsBoundingRectCalls *childOutsideShape = new ItemCountsBoundingRectCalls(QRectF(0,0, 10, 10), parent); + childOutsideShape->setPos(20,0); + + QGraphicsScene scene; + scene.setItemIndexMethod(QGraphicsScene::NoIndex); + scene.addItem(parent); + + QVERIFY(parent->boundingRectCalls == childOutsideShape->boundingRectCalls); + + int oldParentBoundingRectCalls = parent->boundingRectCalls; + int oldChildBoundingRectCalls = childOutsideShape->boundingRectCalls; + + // First test that both items are searched if no optimization flags are set + QGraphicsItem* item = scene.itemAt(25,5); + + QVERIFY(item == childOutsideShape); + QVERIFY(parent->boundingRectCalls > oldParentBoundingRectCalls); + QVERIFY(childOutsideShape->boundingRectCalls > oldChildBoundingRectCalls); + QVERIFY(parent->boundingRectCalls == childOutsideShape->boundingRectCalls); + + oldParentBoundingRectCalls = parent->boundingRectCalls; + oldChildBoundingRectCalls = childOutsideShape->boundingRectCalls; + + // Repeat the test to make sure that no caching/indexing is in effect + item = scene.itemAt(25,5); + + QVERIFY(item == childOutsideShape); + QVERIFY(parent->boundingRectCalls > oldParentBoundingRectCalls); + QVERIFY(childOutsideShape->boundingRectCalls > oldChildBoundingRectCalls); + QVERIFY(parent->boundingRectCalls == childOutsideShape->boundingRectCalls); + + oldParentBoundingRectCalls = parent->boundingRectCalls; + oldChildBoundingRectCalls = childOutsideShape->boundingRectCalls; + + // Set the optimization flag and make sure that the child is not returned + // and that the child's boundingRect() method is never called. + parent->setFlag(QGraphicsItem::ItemContainsChildrenInShape); + item = scene.itemAt(25,5); + + QVERIFY(!(item)); + QVERIFY(parent->boundingRectCalls > oldParentBoundingRectCalls); + QVERIFY(childOutsideShape->boundingRectCalls == oldChildBoundingRectCalls); + QVERIFY(parent->boundingRectCalls > childOutsideShape->boundingRectCalls); +} + +void tst_QGraphicsItem::itemContainsChildrenInShape2() +{ + //The tested flag behaves almost identically to ItemClipsChildrenToShape + //in terms of optimizations but does not enforce the clip. + //This test makes sure there is no clip. + QGraphicsScene scene; + QGraphicsItem *rect = scene.addRect(0, 0, 50, 50, QPen(Qt::NoPen), QBrush(Qt::yellow)); + + QGraphicsItem *ellipse = scene.addEllipse(0, 0, 100, 100, QPen(Qt::NoPen), QBrush(Qt::green)); + ellipse->setParentItem(rect); + + QGraphicsItem *clippedEllipse = scene.addEllipse(0, 0, 50, 50, QPen(Qt::NoPen), QBrush(Qt::blue)); + clippedEllipse->setParentItem(ellipse); + + QGraphicsItem *clippedEllipse2 = scene.addEllipse(0, 0, 25, 25, QPen(Qt::NoPen), QBrush(Qt::red)); + clippedEllipse2->setParentItem(clippedEllipse); + + QVERIFY(!(ellipse->flags() & QGraphicsItem::ItemClipsChildrenToShape)); + QVERIFY(!(ellipse->flags() & QGraphicsItem::ItemContainsChildrenInShape)); + ellipse->setFlags(QGraphicsItem::ItemContainsChildrenInShape); + QVERIFY(!(ellipse->flags() & QGraphicsItem::ItemClipsChildrenToShape)); + QVERIFY((ellipse->flags() & QGraphicsItem::ItemContainsChildrenInShape)); + + QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); + image.fill(0); + QPainter painter(&image); + painter.setRenderHint(QPainter::Antialiasing); + scene.render(&painter); + painter.end(); + + QCOMPARE(image.pixel(2, 2), QColor(Qt::yellow).rgba()); + QCOMPARE(image.pixel(12, 12), QColor(Qt::red).rgba()); + QCOMPARE(image.pixel(2, 25), QColor(Qt::blue).rgba()); + QCOMPARE(image.pixel(2, 50), QColor(Qt::green).rgba()); +} + void tst_QGraphicsItem::ancestorFlags() { QGraphicsItem *level1 = new QGraphicsRectItem; @@ -5975,11 +6073,27 @@ void tst_QGraphicsItem::ancestorFlags() // Nobody handles child events level21->setHandlesChildEvents(false); - for (int i = 0; i < 2; ++i) { - QGraphicsItem::GraphicsItemFlag flag = !i ? QGraphicsItem::ItemClipsChildrenToShape - : QGraphicsItem::ItemIgnoresTransformations; - int ancestorFlag = !i ? QGraphicsItemPrivate::AncestorClipsChildren - : QGraphicsItemPrivate::AncestorIgnoresTransformations; + for (int i = 0; i < 3; ++i) { + QGraphicsItem::GraphicsItemFlag flag; + int ancestorFlag; + + switch (i) { + case(0): + flag = QGraphicsItem::ItemClipsChildrenToShape; + ancestorFlag = QGraphicsItemPrivate::AncestorClipsChildren; + break; + case(1): + flag = QGraphicsItem::ItemIgnoresTransformations; + ancestorFlag = QGraphicsItemPrivate::AncestorIgnoresTransformations; + break; + case(2): + flag = QGraphicsItem::ItemContainsChildrenInShape; + ancestorFlag = QGraphicsItemPrivate::AncestorContainsChildren; + break; + default: + qFatal("Unknown ancestor flag, please fix!"); + break; + } QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); QCOMPARE(int(level21->d_ptr->ancestorFlags), 0); diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index 8f57eca0a7..5bb8634b82 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -282,6 +282,9 @@ void tst_QGraphicsProxyWidget::initTestCase() #ifdef Q_OS_WINCE //disable magic for WindowsCE qApp->setAutoMaximizeThreshold(-1); #endif + // Disable menu animations to prevent the alpha widget from getting in the way + // in actionsContextMenu(). + QApplication::setEffectEnabled(Qt::UI_AnimateMenu, false); } // This will be called after the last test function is executed. @@ -298,6 +301,7 @@ void tst_QGraphicsProxyWidget::init() // This will be called after every test function. void tst_QGraphicsProxyWidget::cleanup() { + QVERIFY(QApplication::topLevelWidgets().isEmpty()); } void tst_QGraphicsProxyWidget::qgraphicsproxywidget_data() @@ -840,10 +844,11 @@ void tst_QGraphicsProxyWidget::focusOutEvent() QTRY_VERIFY(view.isVisible()); QTRY_COMPARE(QApplication::activeWindow(), (QWidget*)&view); - QWidget *widget = new QWidget; + QScopedPointer<QWidget> widgetGuard(new QWidget); + QWidget *widget = widgetGuard.data(); widget->setFocusPolicy(Qt::WheelFocus); if (hasWidget) - proxy->setWidget(widget); + proxy->setWidget(widgetGuard.take()); proxy->show(); proxy->setFocus(); QVERIFY(proxy->hasFocus()); @@ -970,13 +975,14 @@ void tst_QGraphicsProxyWidget::hoverEnterLeaveEvent() QVERIFY(QTest::qWaitForWindowActive(&view)); SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; - EventLogger *widget = new EventLogger; + QScopedPointer<EventLogger> widgetGuard(new EventLogger); + EventLogger *widget = widgetGuard.data(); widget->resize(50, 50); widget->setAttribute(Qt::WA_Hover, hoverEnabled); widget->setMouseTracking(true); view.resize(100, 100); if (hasWidget) - proxy->setWidget(widget); + proxy->setWidget(widgetGuard.take()); proxy->setPos(50, 0); scene.addItem(proxy); QTest::qWait(30); @@ -1001,9 +1007,6 @@ void tst_QGraphicsProxyWidget::hoverEnterLeaveEvent() QTRY_COMPARE(widget->hoverLeave, (hasWidget && hoverEnabled) ? 1 : 0); // does not work on all platforms //QCOMPARE(widget->moveCount, 0); - - if (!hasWidget) - delete widget; } #endif @@ -2447,6 +2450,13 @@ void tst_QGraphicsProxyWidget::setFocus_complexTwoWidgets() void tst_QGraphicsProxyWidget::popup_basic() { + QScopedPointer<QComboBox> box(new QComboBox); + QStyleOptionComboBox opt; + opt.initFrom(box.data()); + opt.editable = box->isEditable(); + if (box->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt)) + QSKIP("Does not work due to SH_Combobox_Popup"); + // ProxyWidget should automatically create proxy's when the widget creates a child QGraphicsScene *scene = new QGraphicsScene; QGraphicsView view(scene); @@ -2455,12 +2465,11 @@ void tst_QGraphicsProxyWidget::popup_basic() view.show(); SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; - QComboBox *box = new QComboBox; box->setGeometry(0, 0, 320, 40); box->addItems(QStringList() << "monday" << "tuesday" << "wednesday" << "thursday" << "saturday" << "sunday"); QCOMPARE(proxy->childItems().count(), 0); - proxy->setWidget(box); + proxy->setWidget(box.data()); proxy->show(); scene->addItem(proxy); @@ -2480,12 +2489,7 @@ void tst_QGraphicsProxyWidget::popup_basic() QGraphicsProxyWidget *child = (QGraphicsProxyWidget*)(proxy->childItems())[0]; QVERIFY(child->isWidget()); QVERIFY(child->widget()); - QStyleOptionComboBox opt; - opt.initFrom(box); - opt.editable = box->isEditable(); - if (box->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt)) - QSKIP("Does not work due to SH_Combobox_Popup"); - QCOMPARE(child->widget()->parent(), static_cast<QObject*>(box)); + QCOMPARE(child->widget()->parent(), static_cast<QObject*>(box.data())); QTRY_COMPARE(proxy->pos(), QPointF(box->pos())); QCOMPARE(child->x(), qreal(box->x())); @@ -2975,6 +2979,8 @@ void tst_QGraphicsProxyWidget::dontCrashWhenDie() QApplication::processEvents(); delete w; + // This leaves an invisible proxy widget behind. + qDeleteAll(QApplication::topLevelWidgets()); } void tst_QGraphicsProxyWidget::createProxyForChildWidget() @@ -3472,7 +3478,8 @@ void tst_QGraphicsProxyWidget::clickFocus() { QGraphicsScene scene; scene.setItemIndexMethod(QGraphicsScene::NoIndex); - QGraphicsProxyWidget *proxy = scene.addWidget(new QLineEdit); + QLineEdit *le1 = new QLineEdit; + QGraphicsProxyWidget *proxy = scene.addWidget(le1); QGraphicsView view(&scene); @@ -3524,6 +3531,7 @@ void tst_QGraphicsProxyWidget::clickFocus() scene.setFocusItem(0); proxy->setWidget(new QLineEdit); // resets focusWidget + delete le1; { QPointF lineEditCenter = proxy->mapToScene(proxy->boundingRect().center()); diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index dfc8465210..a4752126bc 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -267,6 +267,7 @@ private slots: void removeFullyTransparentItem(); void zeroScale(); void focusItemChangedSignal(); + void minimumRenderSize(); // task specific tests below me void task139710_bspTreeCrash(); @@ -4678,6 +4679,78 @@ void tst_QGraphicsScene::focusItemChangedSignal() } +class ItemCountsPaintCalls : public QGraphicsRectItem +{ +public: + ItemCountsPaintCalls(const QRectF & rect, QGraphicsItem *parent = 0) + : QGraphicsRectItem(rect, parent), repaints(0) {} + void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ) + { + QGraphicsRectItem::paint(painter, option, widget); + ++repaints; + } + int repaints; +}; + +void tst_QGraphicsScene::minimumRenderSize() +{ + Q_CHECK_PAINTEVENTS + + ItemCountsPaintCalls *bigParent = new ItemCountsPaintCalls(QRectF(0,0,100,100)); + ItemCountsPaintCalls *smallChild = new ItemCountsPaintCalls(QRectF(0,0,10,10), bigParent); + ItemCountsPaintCalls *smallerGrandChild = new ItemCountsPaintCalls(QRectF(0,0,1,1), smallChild); + QGraphicsScene scene; + scene.addItem(bigParent); + + CustomView view; + view.setScene(&scene); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + qApp->processEvents(); + + // Initially, everything should be repainted the same number of times + int viewRepaints = 0; + QTRY_VERIFY(view.repaints > viewRepaints); + viewRepaints = view.repaints; + + QVERIFY(viewRepaints == bigParent->repaints); + QVERIFY(viewRepaints == smallChild->repaints); + QVERIFY(viewRepaints == smallerGrandChild->repaints); + + // Setting a minimum render size should cause a repaint + scene.setMinimumRenderSize(0.5); + qApp->processEvents(); + + QTRY_VERIFY(view.repaints > viewRepaints); + viewRepaints = view.repaints; + + QVERIFY(viewRepaints == bigParent->repaints); + QVERIFY(viewRepaints == smallChild->repaints); + QVERIFY(viewRepaints == smallerGrandChild->repaints); + + // Scaling should cause a repaint of big items only. + view.scale(0.1, 0.1); + qApp->processEvents(); + + QTRY_VERIFY(view.repaints > viewRepaints); + viewRepaints = view.repaints; + + QVERIFY(viewRepaints == bigParent->repaints); + QVERIFY(viewRepaints == smallChild->repaints); + QVERIFY(smallChild->repaints > smallerGrandChild->repaints); + + // Scaling further should cause even fewer items to be repainted + view.scale(0.1, 0.1); // Stacks with previous scale + qApp->processEvents(); + + QTRY_VERIFY(view.repaints > viewRepaints); + viewRepaints = view.repaints; + + QVERIFY(viewRepaints == bigParent->repaints); + QVERIFY(bigParent->repaints > smallChild->repaints); + QVERIFY(smallChild->repaints > smallerGrandChild->repaints); +} + void tst_QGraphicsScene::taskQTBUG_15977_renderWithDeviceCoordinateCache() { QGraphicsScene scene; diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp index daca1d1516..237d4f8a29 100644 --- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp @@ -248,6 +248,7 @@ private slots: void testFocusPolicy_data(); void testFocusPolicy(); void QTBUG31411_noSelection(); + void QTBUG39324_settingSameInstanceOfIndexWidget(); }; class MyAbstractItemDelegate : public QAbstractItemDelegate @@ -1830,5 +1831,22 @@ void tst_QAbstractItemView::QTBUG31411_noSelection() QCOMPARE(selectionChangeSpy.count(), 0); } +void tst_QAbstractItemView::QTBUG39324_settingSameInstanceOfIndexWidget() +{ + QStringList list; + list << "FOO" << "bar"; + QScopedPointer<QStringListModel> model(new QStringListModel(list)); + + QScopedPointer<QTableView> table(new QTableView()); + table->setModel(model.data()); + + QModelIndex index = model->index(0,0); + QLineEdit *lineEdit = new QLineEdit(); + table->setIndexWidget(index, lineEdit); + table->setIndexWidget(index, lineEdit); + QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + table->show(); +} + QTEST_MAIN(tst_QAbstractItemView) #include "tst_qabstractitemview.moc" diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp index 38367fb4ee..33af273284 100644 --- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp +++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp @@ -178,6 +178,8 @@ private slots: void spansAfterColumnInsertion(); void spansAfterRowRemoval(); void spansAfterColumnRemoval(); + void editSpanFromDirections_data(); + void editSpanFromDirections(); void checkHeaderReset(); void checkHeaderMinSize(); @@ -1240,28 +1242,28 @@ void tst_QTableView::moveCursorStrikesBack_data() << IntList() << QRect(1, 2, 2, 3) << 2 << 0 << (IntList() << int(QtTestTableView::MoveNext)) - << 2 << 2; + << 2 << 1; QTest::newRow("Span, anchor column disabled") << -1 << -1 << IntList() << (IntList() << 1) << QRect(1, 2, 2, 3) << 2 << 0 << (IntList() << int(QtTestTableView::MoveNext)) - << 2 << 2; + << 2 << 1; QTest::newRow("Span, anchor row hidden") << 2 << -1 << IntList() << IntList() << QRect(1, 2, 2, 3) << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown)) - << 3 << 2; + << 2 << 1; QTest::newRow("Span, anchor row disabled") << -1 << -1 << (IntList() << 2) << IntList() << QRect(1, 2, 2, 3) << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown)) - << 3 << 2; + << 2 << 1; QTest::newRow("Move through span right") << -1 << -1 << IntList() @@ -3278,6 +3280,159 @@ void tst_QTableView::spansAfterColumnRemoval() VERIFY_SPANS_CONSISTENCY(&view); } +Q_DECLARE_METATYPE(Qt::Key) + +void tst_QTableView::editSpanFromDirections_data() +{ + QTest::addColumn<QList<Qt::Key> >("keyPresses"); + QTest::addColumn<QSharedPointer<QStandardItemModel> >("model"); + QTest::addColumn<int>("row"); + QTest::addColumn<int>("column"); + QTest::addColumn<int>("rowSpan"); + QTest::addColumn<int>("columnSpan"); + QTest::addColumn<QModelIndex>("expectedVisualCursorIndex"); + QTest::addColumn<QModelIndex>("expectedEditedIndex"); + + /* x = the cell that should be edited + c = the cell that should actually be the current index + +---+---+ + | | | + +---+---+ + | | x | + +---+ + + | | c | + +---+---+ + | | ^ | + +---+---+ */ + QList<Qt::Key> keyPresses; + keyPresses << Qt::Key_Right << Qt::Key_PageDown << Qt::Key_Up; + QSharedPointer<QStandardItemModel> model(new QStandardItemModel(4, 2)); + QTest::newRow("row span, bottom up") + << keyPresses << model << 1 << 1 << 2 << 1 << model->index(2, 1) << model->index(1, 1); + + /* +---+---+ + | | v | + +---+---+ + | |x,c| + +---+ + + | | | + +---+---+ + | | | + +---+---+ */ + keyPresses.clear(); + keyPresses << Qt::Key_Right << Qt::Key_Down; + model.reset(new QStandardItemModel(4, 2)); + QTest::newRow("row span, top down") + << keyPresses << model << 1 << 1 << 2 << 1 << model->index(1, 1) << model->index(1, 1); + + /* +---+---+---+ + | | | | + +---+---+---+ + | |x,c| < | + +---+ +---+ + | | | | + +---+---+---+ */ + keyPresses.clear(); + keyPresses << Qt::Key_End << Qt::Key_Down << Qt::Key_Left; + model.reset(new QStandardItemModel(3, 3)); + QTest::newRow("row span, right to left") + << keyPresses << model << 1 << 1 << 2 << 1 << model->index(1, 1) << model->index(1, 1); + + /* +---+---+---+ + | | | | + +---+---+---+ + | | x | | + +---+ +---+ + | > | c | | + +---+---+---+ */ + keyPresses.clear(); + keyPresses << Qt::Key_PageDown << Qt::Key_Right; + model.reset(new QStandardItemModel(3, 3)); + QTest::newRow("row span, left to right") + << keyPresses << model << 1 << 1 << 2 << 1 << model->index(2, 1) << model->index(1, 1); + + /* +---+---+---+ + | | | | + +---+---+---+ + |x,c | + +---+---+---+ + | ^ | | | + +---+---+---+ */ + keyPresses.clear(); + keyPresses << Qt::Key_PageDown << Qt::Key_Up; + model.reset(new QStandardItemModel(3, 3)); + QTest::newRow("col span, bottom up") + << keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 0) << model->index(1, 0); + + /* +---+---+---+ + | | | | + +---+---+---+ + | x c | + +---+---+---+ + | | ^ | | + +---+---+---+ */ + keyPresses.clear(); + keyPresses << Qt::Key_PageDown << Qt::Key_Right << Qt::Key_Up; + model.reset(new QStandardItemModel(3, 3)); + QTest::newRow("col span, bottom up #2") + << keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 1) << model->index(1, 0); + + /* +---+---+---+ + | | | v | + +---+---+---+ + | x c | + +---+---+---+ + | | | | + +---+---+---+ */ + keyPresses.clear(); + keyPresses << Qt::Key_End << Qt::Key_Down; + model.reset(new QStandardItemModel(3, 3)); + QTest::newRow("col span, top down") + << keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 2) << model->index(1, 0); +} + +class TableViewWithCursorExposed : public QTableView +{ +public: + TableViewWithCursorExposed() : + QTableView() { + } + +public: + QModelIndex visualCursorIndex() { + QTableViewPrivate *d = static_cast<QTableViewPrivate*>(qt_widget_private(this)); + return d->model->index(d->visualCursor.y(), d->visualCursor.x()); + } +}; + +void tst_QTableView::editSpanFromDirections() +{ + QFETCH(QList<Qt::Key>, keyPresses); + QFETCH(QSharedPointer<QStandardItemModel>, model); + QFETCH(int, row); + QFETCH(int, column); + QFETCH(int, rowSpan); + QFETCH(int, columnSpan); + QFETCH(QModelIndex, expectedVisualCursorIndex); + QFETCH(QModelIndex, expectedEditedIndex); + + TableViewWithCursorExposed view; + view.setModel(model.data()); + view.setSpan(row, column, rowSpan, columnSpan); + view.show(); + QVERIFY(QTest::qWaitForWindowActive(&view)); + + foreach (Qt::Key key, keyPresses) { + QTest::keyClick(&view, key); + } + QCOMPARE(view.visualCursorIndex(), expectedVisualCursorIndex); + QCOMPARE(view.selectionModel()->currentIndex(), expectedEditedIndex); + + QTest::keyClick(&view, Qt::Key_X); + QTest::keyClick(QApplication::focusWidget(), Qt::Key_Enter); + QTRY_COMPARE(view.model()->data(expectedEditedIndex).toString(), QLatin1String("x")); +} + class Model : public QAbstractTableModel { Q_OBJECT diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index 9d7d3d1f34..6c1e67a049 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -260,6 +260,7 @@ void tst_QApplication::cleanup() { // TODO: Add cleanup code here. // This will be executed immediately after each test is run. + QVERIFY(QApplication::topLevelWidgets().isEmpty()); } void tst_QApplication::staticSetup() @@ -916,10 +917,10 @@ bool isPathListIncluded(const QStringList &l, const QStringList &r) #define QT_TST_QAPP_DEBUG void tst_QApplication::libraryPaths() { - { #ifndef Q_OS_WINCE - QString testDir = QFileInfo(QFINDTESTDATA("test/test.pro")).absolutePath(); -#else + const QString testDir = QFileInfo(QFINDTESTDATA("test/test.pro")).absolutePath(); + QVERIFY(!testDir.isEmpty()); +#else // !Q_OS_WINCE // On Windows CE we need QApplication object to have valid // current Path. Therefore we need to identify it ourselves // here for the test. @@ -927,8 +928,9 @@ void tst_QApplication::libraryPaths() wchar_t module_name[MAX_PATH]; GetModuleFileName(0, module_name, MAX_PATH); filePath = QString::fromWCharArray(module_name); - QString testDir = filePath.path() + "/test"; -#endif + const QString testDir = filePath.path() + "/test"; +#endif // Q_OS_WINCE + { QApplication::setLibraryPaths(QStringList() << testDir); QCOMPARE(QApplication::libraryPaths(), (QStringList() << testDir)); @@ -964,8 +966,7 @@ void tst_QApplication::libraryPaths() "\nexpected:\n - " + expected.join("\n - "))); // setting the library paths overrides everything - QString testDir = QFileInfo(QFINDTESTDATA("test/test.pro")).absolutePath(); - QApplication::setLibraryPaths(QStringList() << testDir); + QApplication::setLibraryPaths(QStringList() << testDir); QVERIFY2(isPathListIncluded(QApplication::libraryPaths(), (QStringList() << testDir)), qPrintable("actual:\n - " + QApplication::libraryPaths().join("\n - ") + "\nexpected:\n - " + testDir)); @@ -987,7 +988,6 @@ void tst_QApplication::libraryPaths() qDebug() << "After adding plugins path:" << QApplication::libraryPaths(); #endif QCOMPARE(QApplication::libraryPaths().count(), count); - QString testDir = QFileInfo(QFINDTESTDATA("test/test.pro")).absolutePath(); QApplication::addLibraryPath(testDir); QCOMPARE(QApplication::libraryPaths().count(), count + 1); diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 4252fb673b..270de944c5 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -449,6 +449,8 @@ private: QWidget *testWidget; const QString m_platform; + QSize m_testWidgetSize; + QPoint m_availableTopLeft; const bool m_windowsAnimationsEnabled; }; @@ -644,9 +646,20 @@ void tst_QWidget::initTestCase() #ifdef Q_OS_WINCE //disable magic for WindowsCE qApp->setAutoMaximizeThreshold(-1); #endif + // Size of reference widget, 200 for < 2000, scale up for larger screens + // to avoid Windows warnings about minimum size for decorated windows. + int width = 200; + const QScreen *screen = QGuiApplication::primaryScreen(); + m_availableTopLeft = screen->availableGeometry().topLeft(); + const int screenWidth = screen->geometry().width(); + if (screenWidth > 2000) + width = 100 * ((screenWidth + 500) / 1000); + m_testWidgetSize = QSize(width, width); // Create the test class testWidget = new BezierViewer; - testWidget->resize(200,200); + testWidget->setWindowTitle(QStringLiteral("BezierViewer")); + testWidget->move(m_availableTopLeft + QPoint(screenWidth / 3, 50)); + testWidget->resize(m_testWidgetSize); testWidget->show(); QVERIFY(QTest::qWaitForWindowExposed(testWidget)); } @@ -667,6 +680,8 @@ void tst_QWidget::init() void tst_QWidget::cleanup() { + // Only 'testwidget', do not leak any other widgets. + QCOMPARE(QApplication::topLevelWidgets().size(), 1); } // Helper class... @@ -1115,6 +1130,9 @@ void tst_QWidget::enabledPropagation() void tst_QWidget::ignoreKeyEventsWhenDisabled_QTBUG27417() { QLineEdit lineEdit; + lineEdit.setWindowTitle(__FUNCTION__); + lineEdit.setMinimumWidth(m_testWidgetSize.width()); + centerOnScreen(&lineEdit); lineEdit.setDisabled(true); lineEdit.show(); QTest::keyClick(&lineEdit, Qt::Key_A); @@ -1124,6 +1142,9 @@ void tst_QWidget::ignoreKeyEventsWhenDisabled_QTBUG27417() void tst_QWidget::properTabHandlingWhenDisabled_QTBUG27417() { QWidget widget; + widget.setWindowTitle(__FUNCTION__); + widget.setMinimumWidth(m_testWidgetSize.width()); + centerOnScreen(&widget); QVBoxLayout *layout = new QVBoxLayout(); QLineEdit *lineEdit = new QLineEdit(); layout->addWidget(lineEdit); @@ -1211,7 +1232,7 @@ void tst_QWidget::isEnabledTo() QVERIFY( grandChildWidget->isEnabledTo( childWidget ) ); QVERIFY( !grandChildWidget->isEnabledTo( testWidget ) ); - QMainWindow* childDialog = new QMainWindow(testWidget); + QScopedPointer<QMainWindow> childDialog(new QMainWindow(testWidget)); testWidget->setEnabled(false); QVERIFY(!childDialog->isEnabled()); QVERIFY(childDialog->isEnabledTo(0)); @@ -1836,7 +1857,7 @@ void tst_QWidget::windowState() QSKIP("X11: Many window managers do not support window state properly, which causes this test to fail."); QPoint pos; - QSize size(200, 200); + QSize size = m_testWidgetSize; if (QGuiApplicationPrivate::platformIntegration()->defaultWindowState(Qt::Widget) == Qt::WindowFullScreen) { size = QGuiApplication::primaryScreen()->size(); @@ -2275,6 +2296,7 @@ void tst_QWidget::showMinimizedKeepsFocus() QTRY_COMPARE(qApp->focusWidget(), child); child->setParent(0); + QScopedPointer<QWidget> childGuard(child); QCOMPARE(window.focusWidget(), static_cast<QWidget*>(0)); QCOMPARE(qApp->focusWidget(), static_cast<QWidget*>(0)); } @@ -2342,8 +2364,9 @@ void tst_QWidget::showMinimizedKeepsFocus() void tst_QWidget::reparent() { QWidget parent; - parent.setWindowTitle("Toplevel"); - parent.setGeometry(300, 300, 200, 150); + parent.setWindowTitle(QStringLiteral("Toplevel ") + __FUNCTION__); + const QPoint parentPosition = m_availableTopLeft + QPoint(300, 300); + parent.setGeometry(QRect(parentPosition, m_testWidgetSize)); QWidget child(0); child.setObjectName("child"); @@ -2353,8 +2376,9 @@ void tst_QWidget::reparent() child.setPalette(pal1); QWidget childTLW(&child, Qt::Window); - childTLW.setObjectName("childTLW"); - childTLW.setGeometry(100, 100, 50, 50); + childTLW.setObjectName(QStringLiteral("childTLW ") + __FUNCTION__); + childTLW.setWindowTitle(childTLW.objectName()); + childTLW.setGeometry(QRect(m_availableTopLeft + QPoint(100, 100), m_testWidgetSize)); QPalette pal2; pal2.setColor(childTLW.backgroundRole(), Qt::yellow); childTLW.setPalette(pal2); @@ -2366,7 +2390,7 @@ void tst_QWidget::reparent() #ifdef Q_OS_WINCE parent.move(50, 50); #else - parent.move(300, 300); + parent.move(parentPosition); #endif QPoint childPos = parent.mapToGlobal(child.pos()); @@ -2446,7 +2470,8 @@ void tst_QWidget::normalGeometry() QCOMPARE(parent.normalGeometry(), parent.geometry()); QCOMPARE(child->normalGeometry(), QRect()); - parent.setGeometry(100, 100, 200, 200); + const QRect testGeom = QRect(m_availableTopLeft + QPoint(100 ,100), m_testWidgetSize); + parent.setGeometry(testGeom); parent.showNormal(); QVERIFY(QTest::qWaitForWindowExposed(&parent)); QApplication::processEvents(); @@ -3009,8 +3034,8 @@ void tst_QWidget::testContentsPropagation() void tst_QWidget::saveRestoreGeometry() { - const QPoint position(100, 100); - const QSize size(200, 200); + const QPoint position = m_availableTopLeft + QPoint(100, 100); + const QSize size = m_testWidgetSize; QByteArray savedGeometry; @@ -3232,19 +3257,21 @@ void tst_QWidget::widgetAt() { Q_CHECK_PAINTEVENTS + const QPoint referencePos = m_availableTopLeft + QPoint(100, 100); QScopedPointer<QWidget> w1(new QWidget(0, Qt::X11BypassWindowManagerHint)); - w1->setGeometry(0, 0, 160, 150); + w1->setGeometry(QRect(referencePos, QSize(m_testWidgetSize.width(), 150))); w1->setObjectName(QLatin1String("w1")); w1->setWindowTitle(w1->objectName()); QScopedPointer<QWidget> w2(new QWidget(0, Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint)); - w2->setGeometry(50,50, 160, 100); + w2->setGeometry(QRect(referencePos + QPoint(50, 50), QSize(m_testWidgetSize.width(), 100))); w2->setObjectName(QLatin1String("w2")); w2->setWindowTitle(w2->objectName()); w1->showNormal(); QVERIFY(QTest::qWaitForWindowExposed(w1.data())); qApp->processEvents(); + const QPoint testPos = referencePos + QPoint(100, 100); QWidget *wr; - QTRY_VERIFY((wr = QApplication::widgetAt(100, 100))); + QTRY_VERIFY((wr = QApplication::widgetAt((testPos)))); QCOMPARE(wr->objectName(), QString("w1")); w2->showNormal(); @@ -3252,27 +3279,27 @@ void tst_QWidget::widgetAt() qApp->processEvents(); qApp->processEvents(); qApp->processEvents(); - QTRY_VERIFY((wr = QApplication::widgetAt(100, 100))); + QTRY_VERIFY((wr = QApplication::widgetAt(testPos))); QCOMPARE(wr->objectName(), QString("w2")); w2->lower(); qApp->processEvents(); - QTRY_VERIFY((wr = QApplication::widgetAt(100, 100)) && wr->objectName() == QString("w1")); + QTRY_VERIFY((wr = QApplication::widgetAt(testPos)) && wr->objectName() == QString("w1")); w2->raise(); qApp->processEvents(); - QTRY_VERIFY((wr = QApplication::widgetAt(100, 100)) && wr->objectName() == QString("w2")); + QTRY_VERIFY((wr = QApplication::widgetAt(testPos)) && wr->objectName() == QString("w2")); QWidget *w3 = new QWidget(w2.data()); w3->setGeometry(10,10,50,50); w3->setObjectName("w3"); w3->showNormal(); qApp->processEvents(); - QTRY_VERIFY((wr = QApplication::widgetAt(100,100)) && wr->objectName() == QString("w3")); + QTRY_VERIFY((wr = QApplication::widgetAt(testPos)) && wr->objectName() == QString("w3")); w3->setAttribute(Qt::WA_TransparentForMouseEvents); qApp->processEvents(); - QTRY_VERIFY((wr = QApplication::widgetAt(100, 100)) && wr->objectName() == QString("w2")); + QTRY_VERIFY((wr = QApplication::widgetAt(testPos)) && wr->objectName() == QString("w2")); if (!QGuiApplicationPrivate::platformIntegration() ->hasCapability(QPlatformIntegration::WindowMasks)) { @@ -3280,7 +3307,7 @@ void tst_QWidget::widgetAt() } QRegion rgn = QRect(QPoint(0,0), w2->size()); - QPoint point = w2->mapFromGlobal(QPoint(100,100)); + QPoint point = w2->mapFromGlobal(testPos); rgn -= QRect(point, QSize(1,1)); w2->setMask(rgn); qApp->processEvents(); @@ -3291,16 +3318,16 @@ void tst_QWidget::widgetAt() if (!QGuiApplication::platformName().compare(QLatin1String("cocoa"), Qt::CaseInsensitive)) QEXPECT_FAIL("", "Window mask not implemented on Mac QTBUG-22326", Continue); - QTRY_VERIFY((wr = QApplication::widgetAt(100,100))); + QTRY_VERIFY((wr = QApplication::widgetAt(testPos))); QTRY_COMPARE(wr->objectName(), w1->objectName()); - QTRY_VERIFY((wr = QApplication::widgetAt(101,101))); + QTRY_VERIFY((wr = QApplication::widgetAt(testPos + QPoint(1, 1)))); QTRY_COMPARE(wr->objectName(), w2->objectName()); QBitmap bitmap(w2->size()); QPainter p(&bitmap); p.fillRect(bitmap.rect(), Qt::color1); p.setPen(Qt::color0); - p.drawPoint(w2->mapFromGlobal(QPoint(100,100))); + p.drawPoint(w2->mapFromGlobal(testPos)); p.end(); w2->setMask(bitmap); qApp->processEvents(); @@ -3310,8 +3337,8 @@ void tst_QWidget::widgetAt() #endif if (!QGuiApplication::platformName().compare(QLatin1String("cocoa"), Qt::CaseInsensitive)) QEXPECT_FAIL("", "Window mask not implemented on Mac QTBUG-22326", Continue); - QTRY_VERIFY(QApplication::widgetAt(100,100) == w1.data()); - QTRY_VERIFY(QApplication::widgetAt(101,101) == w2.data()); + QTRY_VERIFY(QApplication::widgetAt(testPos) == w1.data()); + QTRY_VERIFY(QApplication::widgetAt(testPos + QPoint(1, 1)) == w2.data()); } void tst_QWidget::task110173() @@ -3957,7 +3984,8 @@ void tst_QWidget::persistentWinId() void tst_QWidget::showNativeChild() { QWidget topLevel; - topLevel.setGeometry(0, 0, 160, 160); + topLevel.setGeometry(QRect(m_availableTopLeft + QPoint(100, 100), m_testWidgetSize)); + topLevel.setWindowTitle(__FUNCTION__); QWidget child(&topLevel); child.winId(); topLevel.show(); @@ -4420,36 +4448,39 @@ void tst_QWidget::setWindowGeometry_data() QTest::addColumn<int>("windowFlags"); QList<QList<QRect> > rects; + const int width = m_testWidgetSize.width(); + const int height = m_testWidgetSize.height(); + const QRect availableAdjusted = QApplication::desktop()->availableGeometry().adjusted(100, 100, -100, -100); rects << (QList<QRect>() - << QRect(100, 100, 200, 200) - << QApplication::desktop()->availableGeometry().adjusted(100, 100, -100, -100) - << QRect(130, 100, 0, 200) - << QRect(100, 50, 200, 0) - << QRect(130, 50, 0, 0)) + << QRect(m_availableTopLeft + QPoint(100, 100), m_testWidgetSize) + << availableAdjusted + << QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)) + << QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)) + << QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0))) << (QList<QRect>() - << QApplication::desktop()->availableGeometry().adjusted(100, 100, -100, -100) - << QRect(130, 100, 0, 200) - << QRect(100, 50, 200, 0) - << QRect(130, 50, 0, 0) - << QRect(100, 100, 200, 200)) + << availableAdjusted + << QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)) + << QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)) + << QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)) + << QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height))) << (QList<QRect>() - << QRect(130, 100, 0, 200) - << QRect(100, 50, 200, 0) - << QRect(130, 50, 0, 0) - << QRect(100, 100, 200, 200) - << QApplication::desktop()->availableGeometry().adjusted(100, 100, -100, -100)) + << QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)) + << QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)) + << QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)) + << QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height)) + << availableAdjusted) << (QList<QRect>() - << QRect(100, 50, 200, 0) - << QRect(130, 50, 0, 0) - << QRect(100, 100, 200, 200) - << QApplication::desktop()->availableGeometry().adjusted(100, 100, -100, -100) - << QRect(130, 100, 0, 200)) + << QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)) + << QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)) + << QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height)) + << availableAdjusted + << QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height))) << (QList<QRect>() - << QRect(130, 50, 0, 0) - << QRect(100, 100, 200, 200) - << QApplication::desktop()->availableGeometry().adjusted(100, 100, -100, -100) - << QRect(130, 100, 0, 200) - << QRect(100, 50, 200, 0)); + << QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)) + << QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height)) + << availableAdjusted + << QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)) + << QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0))); QList<int> windowFlags; windowFlags << 0 << Qt::FramelessWindowHint; @@ -5202,6 +5233,7 @@ public: void tst_QWidget::setFocus() { + const QPoint windowPos = testWidget->geometry().topRight() + QPoint(50, 0); { // move focus to another window testWidget->activateWindow(); @@ -5213,7 +5245,9 @@ void tst_QWidget::setFocus() // window and children never shown, nobody gets focus QWidget window; - window.resize(200, 200); + window.setWindowTitle(QStringLiteral("#1 ") + __FUNCTION__); + window.resize(m_testWidgetSize); + window.move(windowPos); QWidget child1(&window); child1.setFocusPolicy(Qt::StrongFocus); @@ -5235,7 +5269,9 @@ void tst_QWidget::setFocus() { // window and children show, but window not active, nobody gets focus QWidget window; - window.resize(200, 200); + window.setWindowTitle(QStringLiteral("#2 ") + __FUNCTION__); + window.resize(m_testWidgetSize); + window.move(windowPos); QWidget child1(&window); child1.setFocusPolicy(Qt::StrongFocus); @@ -5267,7 +5303,9 @@ void tst_QWidget::setFocus() { // window and children show, but window *is* active, children get focus QWidget window; - window.resize(200, 200); + window.setWindowTitle(QStringLiteral("#3 ") + __FUNCTION__); + window.resize(m_testWidgetSize); + window.move(windowPos); FocusWidget child1(&window); child1.setFocusPolicy(Qt::StrongFocus); @@ -5298,7 +5336,9 @@ void tst_QWidget::setFocus() { // window shown and active, children created, don't get focus, but get focus when shown QWidget window; - window.resize(200, 200); + window.setWindowTitle(QStringLiteral("#4 ") + __FUNCTION__); + window.resize(m_testWidgetSize); + window.move(windowPos); window.show(); window.activateWindow(); @@ -5337,7 +5377,9 @@ void tst_QWidget::setFocus() // window shown and active, children created, don't get focus, // even after setFocus(), hide(), then show() QWidget window; - window.resize(200, 200); + window.setWindowTitle(QStringLiteral("#5 ") + __FUNCTION__); + window.resize(m_testWidgetSize); + window.move(windowPos); window.show(); window.activateWindow(); @@ -5591,9 +5633,15 @@ void tst_QWidget::testWindowIconChangeEventPropagation() typedef QSharedPointer<EventSpy<QWindow> > WindowEventSpyPtr; // Create widget hierarchy. QWidget topLevelWidget; + topLevelWidget.setWindowTitle(QStringLiteral("TopLevel ") + __FUNCTION__); + topLevelWidget.resize(m_testWidgetSize); + topLevelWidget.move(m_availableTopLeft + QPoint(100, 100)); QWidget topLevelChild(&topLevelWidget); QDialog dialog(&topLevelWidget); + dialog.resize(m_testWidgetSize); + dialog.move(topLevelWidget.geometry().topRight() + QPoint(100, 0)); + dialog.setWindowTitle(QStringLiteral("Dialog ") + __FUNCTION__); QWidget dialogChild(&dialog); QWidgetList widgets; @@ -6295,6 +6343,7 @@ void tst_QWidget::renderInvisible() QSKIP("QTBUG-26424"); QScopedPointer<QCalendarWidget> calendar(new QCalendarWidget); + calendar->move(m_availableTopLeft + QPoint(100, 100)); // disable anti-aliasing to eliminate potential differences when subpixel antialiasing // is enabled on the screen QFont f; @@ -6305,6 +6354,8 @@ void tst_QWidget::renderInvisible() // Create a dummy focus widget to get rid of focus rect in reference image. QLineEdit dummyFocusWidget; + dummyFocusWidget.setMinimumWidth(m_testWidgetSize.width()); + dummyFocusWidget.move(calendar->geometry().bottomLeft() + QPoint(0, 100)); dummyFocusWidget.show(); QVERIFY(QTest::qWaitForWindowExposed(&dummyFocusWidget)); qApp->processEvents(); @@ -6615,12 +6666,15 @@ void tst_QWidget::render_task211796() { // Please don't die in a resize recursion. MyWidget widget; - widget.resize(200, 200); + widget.resize(m_testWidgetSize); + centerOnScreen(&widget); widget.show(); } { // Same check with a deeper hierarchy. QWidget widget; + widget.resize(m_testWidgetSize); + centerOnScreen(&widget); widget.show(); QWidget child(&widget); MyWidget grandChild; @@ -7305,7 +7359,7 @@ void tst_QWidget::alienWidgets() qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); QWidget parent; - parent.resize(200, 200); + parent.resize(m_testWidgetSize); QWidget child(&parent); QWidget grandChild(&child); QWidget greatGrandChild(&grandChild); @@ -7339,7 +7393,7 @@ void tst_QWidget::alienWidgets() // Ensure that hide() on an ancestor of a widget with // Qt::WA_DontCreateNativeAncestors still gets unmapped QWidget window; - window.resize(200, 200); + window.resize(m_testWidgetSize); QWidget widget(&window); QWidget child(&widget); child.setAttribute(Qt::WA_NativeWindow); @@ -7401,7 +7455,7 @@ void tst_QWidget::alienWidgets() // Make sure we don't create native windows when setting Qt::WA_X11NetWmWindowType attributes // on alien widgets (see task 194231). QWidget dummy; - dummy.resize(200, 200); + dummy.resize(m_testWidgetSize); QVERIFY(dummy.winId()); QWidget widget(&dummy); widget.setAttribute(Qt::WA_X11NetWmWindowTypeToolBar); @@ -7410,7 +7464,7 @@ void tst_QWidget::alienWidgets() { // Make sure we create native ancestors when setting Qt::WA_PaintOnScreen before show(). QWidget topLevel; - topLevel.resize(200, 200); + topLevel.resize(m_testWidgetSize); QWidget child(&topLevel); QWidget grandChild(&child); PaintOnScreenWidget greatGrandChild(&grandChild); @@ -7434,7 +7488,7 @@ void tst_QWidget::alienWidgets() { // Ensure that widgets reparented into Qt::WA_PaintOnScreen widgets become native. QWidget topLevel; - topLevel.resize(200, 200); + topLevel.resize(m_testWidgetSize); QWidget *widget = new PaintOnScreenWidget(&topLevel); widget->setAttribute(Qt::WA_PaintOnScreen); QWidget *child = new QWidget; @@ -7467,7 +7521,7 @@ void tst_QWidget::alienWidgets() { // Ensure that ancestors of a Qt::WA_PaintOnScreen widget stay native // if they are re-created (typically in QWidgetPrivate::setParent_sys) (task 210822). QWidget window; - window.resize(200, 200); + window.resize(m_testWidgetSize); QWidget child(&window); QWidget grandChild; @@ -7508,7 +7562,7 @@ void tst_QWidget::alienWidgets() QWidget *toolBar = new QWidget(&mainWindow); QWidget *dockWidget = new QWidget(&mainWindow); QWidget *centralWidget = new QWidget(&mainWindow); - centralWidget->setMinimumSize(QSize(200, 200)); + centralWidget->setMinimumSize(m_testWidgetSize); QWidget *button = new QWidget(centralWidget); QWidget *mdiArea = new QWidget(centralWidget); @@ -8255,12 +8309,16 @@ void tst_QWidget::paintOnScreenPossible() void tst_QWidget::reparentStaticWidget() { QWidget window1; + window1.setWindowTitle(QStringLiteral("window1 ") + __FUNCTION__); + window1.resize(m_testWidgetSize); + window1.move(m_availableTopLeft + QPoint(100, 100)); QWidget *child = new QWidget(&window1); child->setPalette(Qt::red); child->setAutoFillBackground(true); child->setAttribute(Qt::WA_StaticContents); - child->resize(160, 160); + child->resize(window1.width() - 40, window1.height() - 40); + child->setWindowTitle(QStringLiteral("child ") + __FUNCTION__); QWidget *grandChild = new QWidget(child); grandChild->setPalette(Qt::blue); @@ -8271,6 +8329,9 @@ void tst_QWidget::reparentStaticWidget() QVERIFY(QTest::qWaitForWindowExposed(&window1)); QWidget window2; + window2.setWindowTitle(QStringLiteral("window2 ") + __FUNCTION__); + window2.resize(m_testWidgetSize); + window2.move(window1.geometry().topRight() + QPoint(100, 0)); window2.show(); QVERIFY(QTest::qWaitForWindowExposed(&window2)); QTest::qWait(20); @@ -8312,6 +8373,10 @@ void tst_QWidget::reparentStaticWidget() QTest::qWait(20); QWidget paintOnScreen; + paintOnScreen.setWindowTitle(QStringLiteral("paintOnScreen ") + __FUNCTION__); + paintOnScreen.resize(m_testWidgetSize); + paintOnScreen.move(window1.geometry().bottomLeft() + QPoint(0, 50)); + paintOnScreen.setAttribute(Qt::WA_PaintOnScreen); paintOnScreen.show(); QVERIFY(QTest::qWaitForWindowExposed(&paintOnScreen)); @@ -8330,18 +8395,23 @@ void tst_QWidget::reparentStaticWidget() void tst_QWidget::QTBUG6883_reparentStaticWidget2() { QMainWindow mw; - QDockWidget *one = new QDockWidget("one", &mw); + mw.setWindowTitle(QStringLiteral("MainWindow ") + __FUNCTION__); + mw.move(m_availableTopLeft + QPoint(100, 100)); + + QDockWidget *one = new QDockWidget(QStringLiteral("Dock ") + __FUNCTION__, &mw); mw.addDockWidget(Qt::LeftDockWidgetArea, one , Qt::Vertical); QWidget *child = new QWidget(); child->setPalette(Qt::red); child->setAutoFillBackground(true); child->setAttribute(Qt::WA_StaticContents); - child->resize(100, 100); + child->resize(m_testWidgetSize); one->setWidget(child); QToolBar *mainTools = mw.addToolBar("Main Tools"); - mainTools->addWidget(new QLineEdit); + QLineEdit *le = new QLineEdit; + le->setMinimumWidth(m_testWidgetSize.width()); + mainTools->addWidget(le); mw.show(); QVERIFY(QTest::qWaitForWindowExposed(&mw)); @@ -8962,7 +9032,7 @@ void tst_QWidget::updateOnDestroyedSignal() QWidget widget; QWidget *child = new QWidget(&widget); - child->resize(200, 200); + child->resize(m_testWidgetSize); child->setAutoFillBackground(true); child->setPalette(Qt::red); @@ -8980,6 +9050,7 @@ void tst_QWidget::toplevelLineEditFocus() testWidget->hide(); QLineEdit w; + w.setMinimumWidth(m_testWidgetSize.width()); w.show(); QVERIFY(QTest::qWaitForWindowExposed(&w)); QTest::qWait(20); @@ -9139,7 +9210,10 @@ void tst_QWidget::activateWindow() // Create first mainwindow and set it active QScopedPointer<QMainWindow> mainwindow(new QMainWindow); QLabel* label = new QLabel(mainwindow.data()); + label->setMinimumWidth(m_testWidgetSize.width()); + mainwindow->setWindowTitle(QStringLiteral("#1 ") + __FUNCTION__); mainwindow->setCentralWidget(label); + mainwindow->move(m_availableTopLeft + QPoint(100, 100)); mainwindow->setVisible(true); mainwindow->activateWindow(); QVERIFY(QTest::qWaitForWindowActive(mainwindow.data())); @@ -9147,8 +9221,11 @@ void tst_QWidget::activateWindow() // Create second mainwindow and set it active QScopedPointer<QMainWindow> mainwindow2(new QMainWindow); + mainwindow2->setWindowTitle(QStringLiteral("#2 ") + __FUNCTION__); QLabel* label2 = new QLabel(mainwindow2.data()); + label2->setMinimumWidth(m_testWidgetSize.width()); mainwindow2->setCentralWidget(label2); + mainwindow2->move(mainwindow->geometry().bottomLeft() + QPoint(0, 50)); mainwindow2->setVisible(true); mainwindow2->activateWindow(); qApp->processEvents(); @@ -9170,10 +9247,7 @@ void tst_QWidget::openModal_taskQTBUG_5804() class Widget : public QWidget { public: - Widget(QWidget *parent) : QWidget(parent) - { - resize(200, 200); - } + Widget(QWidget *parent) : QWidget(parent) {} ~Widget() { QMessageBox msgbox; @@ -9183,6 +9257,10 @@ void tst_QWidget::openModal_taskQTBUG_5804() }; QScopedPointer<QWidget> win(new QWidget); + win->resize(m_testWidgetSize); + win->setWindowTitle(__FUNCTION__); + centerOnScreen(win.data()); + new Widget(win.data()); win->show(); QVERIFY(QTest::qWaitForWindowExposed(win.data())); @@ -9444,6 +9522,8 @@ void tst_QWidget::taskQTBUG_17333_ResizeInfiniteRecursion() void tst_QWidget::nativeChildFocus() { QWidget w; + w.setMinimumWidth(m_testWidgetSize.width()); + w.setWindowTitle(__FUNCTION__); QLayout *layout = new QVBoxLayout; w.setLayout(layout); QLineEdit *p1 = new QLineEdit; @@ -9452,6 +9532,7 @@ void tst_QWidget::nativeChildFocus() layout->addWidget(p2); p1->setObjectName("p1"); p2->setObjectName("p2"); + centerOnScreen(&w); w.show(); w.activateWindow(); p1->setFocus(); @@ -9588,8 +9669,9 @@ void tst_QWidget::grabMouse() GrabLoggerWidget *grabber = new GrabLoggerWidget(&log, &w); const QString grabberObjectName = QLatin1String("tst_qwidget_grabMouse_grabber"); grabber->setObjectName(grabberObjectName); - grabber->setMinimumSize(100, 100); + grabber->setMinimumSize(m_testWidgetSize); layout->addWidget(grabber); + centerOnScreen(&w); w.show(); qApp->setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); @@ -9616,9 +9698,12 @@ void tst_QWidget::grabKeyboard() w.setWindowTitle(w.objectName()); QLayout *layout = new QVBoxLayout(&w); QLineEdit *grabber = new QLineEdit(&w); + grabber->setMinimumWidth(m_testWidgetSize.width()); layout->addWidget(grabber); QLineEdit *nonGrabber = new QLineEdit(&w); + nonGrabber->setMinimumWidth(m_testWidgetSize.width()); layout->addWidget(nonGrabber); + centerOnScreen(&w); w.show(); qApp->setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); @@ -10211,11 +10296,11 @@ public: void tst_QWidget::keyboardModifiers() { - KeyboardWidget* w = new KeyboardWidget; - QTest::mouseClick(w, Qt::LeftButton, Qt::ControlModifier); - QCOMPARE(w->m_eventCounter, 1); - QCOMPARE(int(w->m_modifiers), int(Qt::ControlModifier)); - QCOMPARE(int(w->m_appModifiers), int(Qt::ControlModifier)); + KeyboardWidget w; + QTest::mouseClick(&w, Qt::LeftButton, Qt::ControlModifier); + QCOMPARE(w.m_eventCounter, 1); + QCOMPARE(int(w.m_modifiers), int(Qt::ControlModifier)); + QCOMPARE(int(w.m_appModifiers), int(Qt::ControlModifier)); } class DClickWidget : public QWidget diff --git a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp index d6b7fc20ed..8084d50fbe 100644 --- a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp +++ b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp @@ -61,7 +61,7 @@ static inline void setFrameless(QWidget *w) w->setWindowFlags(flags); } -class tst_QWidget_window : public QWidget +class tst_QWidget_window : public QObject { Q_OBJECT @@ -71,6 +71,7 @@ public: public slots: void initTestCase(); void cleanupTestCase(); + void cleanup(); private slots: void tst_min_max_size(); @@ -106,9 +107,13 @@ void tst_QWidget_window::cleanupTestCase() { } +void tst_QWidget_window::cleanup() +{ + QVERIFY(QApplication::topLevelWidgets().isEmpty()); +} + /* Test if the maximum/minimum size constraints - * are propagated from the wid src/widgets/kernel/qwidgetwindow_qpa_p.h -get to the QWidgetWindow + * are propagated from the widget to the QWidgetWindow * independently of whether they were set before or after * window creation (QTBUG-26745). */ diff --git a/tests/auto/widgets/kernel/qwidgetsvariant/tst_qwidgetsvariant.cpp b/tests/auto/widgets/kernel/qwidgetsvariant/tst_qwidgetsvariant.cpp index 286b887521..6264151c08 100644 --- a/tests/auto/widgets/kernel/qwidgetsvariant/tst_qwidgetsvariant.cpp +++ b/tests/auto/widgets/kernel/qwidgetsvariant/tst_qwidgetsvariant.cpp @@ -89,18 +89,16 @@ void tst_QWidgetsVariant::constructor_invalid() QFETCH(uint, typeId); { - MessageHandlerInvalidType msg; + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type, type id:")); QVariant variant(static_cast<QVariant::Type>(typeId)); QVERIFY(!variant.isValid()); QVERIFY(variant.userType() == QMetaType::UnknownType); - QVERIFY(msg.ok); } { - MessageHandlerInvalidType msg; + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type, type id:")); QVariant variant(typeId, /* copy */ 0); QVERIFY(!variant.isValid()); QVERIFY(variant.userType() == QMetaType::UnknownType); - QVERIFY(msg.ok); } } diff --git a/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp b/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp index a4d4e5d717..433fbc2bfe 100644 --- a/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp +++ b/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp @@ -46,6 +46,7 @@ #include <QStyleOptionGroupBox> #include <QVBoxLayout> #include <QRadioButton> +#include <QDialog> #include "qgroupbox.h" @@ -71,6 +72,7 @@ private slots: void setChecked_data(); void setChecked(); void enabledPropagation(); + void enabledChildPropagation(); void sizeHint(); void toggled(); void clicked_data(); @@ -288,6 +290,23 @@ void tst_QGroupBox::enabledPropagation() delete testWidget; } +void tst_QGroupBox::enabledChildPropagation() +{ + QGroupBox testWidget; + testWidget.setCheckable(true); + testWidget.setChecked(true); + // The value of isChecked() should be reflected in the isEnabled() of newly + // added child widgets, but not in top level widgets. + QWidget *childWidget = new QWidget(&testWidget); + QVERIFY(childWidget->isEnabled()); + QDialog *dialog = new QDialog(&testWidget); + QVERIFY(dialog->isEnabled()); + testWidget.setChecked(false); + childWidget = new QWidget(&testWidget); + QVERIFY(!childWidget->isEnabled()); + dialog = new QDialog(&testWidget); + QVERIFY(dialog->isEnabled()); +} void tst_QGroupBox::sizeHint() { diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 36f14cb1ba..0094a1112b 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -4185,8 +4185,14 @@ void tst_QLineEdit::clearButton() QTRY_COMPARE(filterModel->rowCount(), 2); // matches 'aa', 'ab' QTest::keyClick(filterLineEdit, 'b'); QTRY_COMPARE(filterModel->rowCount(), 1); // matches 'ab' - QTest::mouseClick(clearButton, Qt::LeftButton, 0, QRect(QPoint(0, 0), clearButton->size()).center()); + QSignalSpy spyEdited(filterLineEdit, &QLineEdit::textEdited); + const QPoint clearButtonCenterPos = QRect(QPoint(0, 0), clearButton->size()).center(); + QTest::mouseClick(clearButton, Qt::LeftButton, 0, clearButtonCenterPos); + QCOMPARE(spyEdited.count(), 1); + QTest::mouseClick(clearButton, Qt::LeftButton, 0, clearButtonCenterPos); QTRY_COMPARE(filterModel->rowCount(), 3); + QCoreApplication::processEvents(); + QCOMPARE(spyEdited.count(), 1); filterLineEdit->setReadOnly(true); // QTBUG-34315 QVERIFY(!clearButton->isEnabled()); diff --git a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp index 59021108a2..4f611cd06f 100644 --- a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp +++ b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp @@ -237,6 +237,8 @@ public: tst_QMdiArea(); public slots: void initTestCase(); + void cleanup(); + protected slots: void activeChanged(QMdiSubWindow *child); @@ -306,6 +308,11 @@ void tst_QMdiArea::initTestCase() #endif } +void tst_QMdiArea::cleanup() +{ + QVERIFY(QApplication::topLevelWidgets().isEmpty()); +} + // Old QWorkspace tests void tst_QMdiArea::activeChanged(QMdiSubWindow *child) { @@ -1271,6 +1278,7 @@ void tst_QMdiArea::removeSubWindow_2() mdiArea.addSubWindow(subWindow); QVERIFY(numberOfConnectedSignals(subWindow) >= 2); subWindow->setParent(0); + QScopedPointer<MySubWindow> subWindowGuard(subWindow); QCOMPARE(numberOfConnectedSignals(subWindow), 0); } @@ -2340,7 +2348,7 @@ void tst_QMdiArea::setViewMode() QVERIFY(QTest::qWaitForWindowExposed(&mdiArea)); QMdiSubWindow *activeSubWindow = mdiArea.activeSubWindow(); - const QList<QMdiSubWindow *> subWindows = mdiArea.subWindowList(); + QList<QMdiSubWindow *> subWindows = mdiArea.subWindowList(); // Default. QVERIFY(!activeSubWindow->isMaximized()); @@ -2410,9 +2418,12 @@ void tst_QMdiArea::setViewMode() // Remove sub-windows and make sure the tab is removed. foreach (QMdiSubWindow *subWindow, subWindows) { - if (subWindow != activeSubWindow) + if (subWindow != activeSubWindow) { mdiArea.removeSubWindow(subWindow); + delete subWindow; + } } + subWindows.clear(); QCOMPARE(tabBar->count(), 1); // Go back to default (QMdiArea::SubWindowView). diff --git a/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp b/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp index 87d87eb4bc..4b327c9ba8 100644 --- a/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp +++ b/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -58,6 +58,7 @@ #include <QStyle> #include <QStyleOptionTitleBar> #include <QPushButton> +#include <QScreen> #include <QSizeGrip> #include "../../../qtest-config.h" @@ -182,6 +183,7 @@ private slots: void mouseDoubleClick(); void setSystemMenu(); void restoreFocus(); + void restoreFocusOverCreation(); void changeFocusWithTab(); void closeEvent(); void setWindowTitle(); @@ -1126,6 +1128,7 @@ void tst_QMdiSubWindow::restoreFocus() expectedFocusWindow->showMinimized(); qApp->processEvents(); QVERIFY(expectedFocusWindow->isMinimized()); + qDebug() << expectedFocusWindow<< qApp->focusWidget(); QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(expectedFocusWindow)); // Minimized -> normal @@ -1178,6 +1181,48 @@ void tst_QMdiSubWindow::restoreFocus() QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(expectedFocusWindow)); } +class MultiWidget : public QWidget { +public: + explicit MultiWidget(QWidget *parent = 0) : QWidget(parent) + , m_lineEdit1(new QLineEdit(this)), m_lineEdit2(new QLineEdit(this)) + { + QVBoxLayout *lt = new QVBoxLayout(this); + lt->addWidget(m_lineEdit1); + lt->addWidget(m_lineEdit2); + } + + QLineEdit *m_lineEdit1; + QLineEdit *m_lineEdit2; +}; + +void tst_QMdiSubWindow::restoreFocusOverCreation() +{ + // QTBUG-38378, verify that the focus child of a subwindow + // is not "forgotten" when adding yet another subwindow. + QMdiArea mdiArea; + mdiArea.resize(800, 800); + mdiArea.move(QGuiApplication::primaryScreen()->availableGeometry().center() - QPoint(400, 400)); + mdiArea.setWindowTitle(QStringLiteral("restoreFocusOverCreation")); + + MultiWidget *subWidget1 = new MultiWidget; + MultiWidget *subWidget2 = new MultiWidget; + + QMdiSubWindow *subWindow1 = mdiArea.addSubWindow(subWidget1); + subWidget1->m_lineEdit2->setFocus(); + subWindow1->show(); + mdiArea.show(); + QApplication::setActiveWindow(&mdiArea); + QVERIFY(QTest::qWaitForWindowActive(&mdiArea)); + QCOMPARE(QApplication::focusWidget(), subWidget1->m_lineEdit2); + + QMdiSubWindow *subWindow2 = mdiArea.addSubWindow(subWidget2); + subWindow2->show(); + QTRY_COMPARE(QApplication::focusWidget(), subWidget2->m_lineEdit1); + + mdiArea.setActiveSubWindow(subWindow1); + QTRY_COMPARE(QApplication::focusWidget(), subWidget1->m_lineEdit2); +} + void tst_QMdiSubWindow::changeFocusWithTab() { QWidget *widget = new QWidget; diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp index b4be24f0e0..3b891152b1 100644 --- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp +++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -55,6 +55,7 @@ #include <qmenu.h> #include <qstyle.h> +#include <QTimer> #include <qdebug.h> Q_DECLARE_METATYPE(Qt::Key); @@ -132,6 +133,7 @@ private: enum { num_builtins = 10 }; QAction *activated, *highlighted, *builtins[num_builtins]; QString statustip; + bool m_onStatusTipTimerExecuted; }; // Testing get/set functions @@ -158,6 +160,7 @@ void tst_QMenu::getSetCheck() } tst_QMenu::tst_QMenu() + : m_onStatusTipTimerExecuted(false) { QApplication::setEffectEnabled(Qt::UI_AnimateMenu, false); } @@ -193,6 +196,7 @@ void tst_QMenu::init() { activated = highlighted = 0; lastMenu = 0; + m_onStatusTipTimerExecuted = false; } void tst_QMenu::createActions() @@ -492,8 +496,13 @@ void tst_QMenu::statusTip() //because showMenu calls QMenu::exec, we need to use a singleshot //to continue the test - QTimer::singleShot(200,this, SLOT(onStatusTipTimer())); + QTimer timer; + timer.setSingleShot(true); + connect(&timer, &QTimer::timeout, this, &tst_QMenu::onStatusTipTimer); + timer.setInterval(200); + timer.start(); btn->showMenu(); + QVERIFY(m_onStatusTipTimerExecuted); QVERIFY(statustip.isEmpty()); } @@ -513,6 +522,7 @@ void tst_QMenu::onStatusTipTimer() QCOMPARE(st, QString("sub action")); QVERIFY(menu->isVisible() == false); + m_onStatusTipTimerExecuted = true; } void tst_QMenu::widgetActionFocus() diff --git a/tests/auto/widgets/widgets/qopenglwidget/qopenglwidget.pro b/tests/auto/widgets/widgets/qopenglwidget/qopenglwidget.pro new file mode 100644 index 0000000000..bbc6e987af --- /dev/null +++ b/tests/auto/widgets/widgets/qopenglwidget/qopenglwidget.pro @@ -0,0 +1,8 @@ +CONFIG += testcase +CONFIG += parallel_test +TARGET = tst_qopenglwidget +QT += gui-private core-private testlib widgets + +SOURCES += tst_qopenglwidget.cpp + +win32-msvc2010:contains(QT_CONFIG, angle):CONFIG += insignificant_test # QTBUG-31611 diff --git a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp new file mode 100644 index 0000000000..14d06e7111 --- /dev/null +++ b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp @@ -0,0 +1,266 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtWidgets/QOpenGLWidget> +#include <QtGui/QOpenGLFunctions> +#include <QtGui/QPainter> +#include <QtTest/QtTest> +#include <QSignalSpy> + +class tst_QOpenGLWidget : public QObject +{ + Q_OBJECT + +private slots: + void create(); + void clearAndGrab(); + void clearAndResizeAndGrab(); + void createNonTopLevel(); + void painter(); + void reparentToAlreadyCreated(); + void reparentToNotYetCreated(); +}; + +void tst_QOpenGLWidget::create() +{ + QScopedPointer<QOpenGLWidget> w(new QOpenGLWidget); + QVERIFY(!w->isValid()); + QSignalSpy frameSwappedSpy(w.data(), SIGNAL(frameSwapped())); + w->show(); + QTest::qWaitForWindowExposed(w.data()); + QVERIFY(frameSwappedSpy.count() > 0); + + QVERIFY(w->isValid()); + QVERIFY(w->context()); + QVERIFY(w->context()->format() == w->format()); + QVERIFY(w->defaultFramebufferObject() != 0); +} + +class ClearWidget : public QOpenGLWidget, protected QOpenGLFunctions +{ +public: + ClearWidget(QWidget *parent, int expectedWidth, int expectedHeight) + : QOpenGLWidget(parent), + m_initCalled(false), m_paintCalled(false), m_resizeCalled(false), + m_resizeOk(false), + m_w(expectedWidth), m_h(expectedHeight) { } + + void initializeGL() Q_DECL_OVERRIDE { + m_initCalled = true; + initializeOpenGLFunctions(); + } + void paintGL() Q_DECL_OVERRIDE { + m_paintCalled = true; + glClearColor(1.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + } + void resizeGL(int w, int h) Q_DECL_OVERRIDE { + m_resizeCalled = true; + m_resizeOk = w == m_w && h == m_h; + } + + bool m_initCalled; + bool m_paintCalled; + bool m_resizeCalled; + bool m_resizeOk; + int m_w; + int m_h; +}; + +void tst_QOpenGLWidget::clearAndGrab() +{ + QScopedPointer<ClearWidget> w(new ClearWidget(0, 800, 600)); + w->resize(800, 600); + w->show(); + QTest::qWaitForWindowExposed(w.data()); + QVERIFY(w->m_initCalled); + QVERIFY(w->m_resizeCalled); + QVERIFY(w->m_resizeOk); + QVERIFY(w->m_paintCalled); + + QImage image = w->grabFramebuffer(); + QVERIFY(!image.isNull()); + QCOMPARE(image.width(), w->width()); + QCOMPARE(image.height(), w->height()); + QVERIFY(image.pixel(30, 40) == qRgb(255, 0, 0)); +} + +void tst_QOpenGLWidget::clearAndResizeAndGrab() +{ + QScopedPointer<QOpenGLWidget> w(new ClearWidget(0, 640, 480)); + w->resize(640, 480); + w->show(); + QTest::qWaitForWindowExposed(w.data()); + + QImage image = w->grabFramebuffer(); + QVERIFY(!image.isNull()); + QCOMPARE(image.width(), w->width()); + QCOMPARE(image.height(), w->height()); + w->resize(800, 600); + image = w->grabFramebuffer(); + QVERIFY(!image.isNull()); + QCOMPARE(image.width(), 800); + QCOMPARE(image.height(), 600); + QCOMPARE(image.width(), w->width()); + QCOMPARE(image.height(), w->height()); + QVERIFY(image.pixel(30, 40) == qRgb(255, 0, 0)); +} + +void tst_QOpenGLWidget::createNonTopLevel() +{ + QWidget w; + ClearWidget *glw = new ClearWidget(&w, 600, 700); + QSignalSpy frameSwappedSpy(glw, SIGNAL(frameSwapped())); + w.resize(400, 400); + w.show(); + QTest::qWaitForWindowExposed(&w); + QVERIFY(frameSwappedSpy.count() > 0); + + QVERIFY(glw->m_resizeCalled); + glw->m_resizeCalled = false; + QVERIFY(!glw->m_resizeOk); + glw->resize(600, 700); + + QVERIFY(glw->m_initCalled); + QVERIFY(glw->m_resizeCalled); + QVERIFY(glw->m_resizeOk); + QVERIFY(glw->m_paintCalled); + + QImage image = glw->grabFramebuffer(); + QVERIFY(!image.isNull()); + QCOMPARE(image.width(), glw->width()); + QCOMPARE(image.height(), glw->height()); + QVERIFY(image.pixel(30, 40) == qRgb(255, 0, 0)); + + glw->doneCurrent(); + QVERIFY(!QOpenGLContext::currentContext()); + glw->makeCurrent(); + QVERIFY(QOpenGLContext::currentContext() == glw->context() && glw->context()); +} + +class PainterWidget : public QOpenGLWidget, protected QOpenGLFunctions +{ +public: + PainterWidget(QWidget *parent) + : QOpenGLWidget(parent), m_clear(false) { } + + void initializeGL() Q_DECL_OVERRIDE { + initializeOpenGLFunctions(); + } + void paintGL() Q_DECL_OVERRIDE { + QPainter p(this); + QCOMPARE(p.device()->width(), width()); + QCOMPARE(p.device()->height(), height()); + p.fillRect(QRect(QPoint(0, 0), QSize(width(), height())), Qt::blue); + if (m_clear) { + p.beginNativePainting(); + glClearColor(0.0f, 1.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + p.endNativePainting(); + } + } + bool m_clear; +}; + +void tst_QOpenGLWidget::painter() +{ + QWidget w; + PainterWidget *glw = new PainterWidget(&w); + w.resize(640, 480); + glw->resize(320, 200); + w.show(); + QTest::qWaitForWindowExposed(&w); + + QImage image = glw->grabFramebuffer(); + QCOMPARE(image.width(), glw->width()); + QCOMPARE(image.height(), glw->height()); + QVERIFY(image.pixel(20, 10) == qRgb(0, 0, 255)); + + glw->m_clear = true; + image = glw->grabFramebuffer(); + QVERIFY(image.pixel(20, 10) == qRgb(0, 255, 0)); +} + +void tst_QOpenGLWidget::reparentToAlreadyCreated() +{ + QWidget w1; + PainterWidget *glw = new PainterWidget(&w1); + w1.resize(640, 480); + glw->resize(320, 200); + w1.show(); + QTest::qWaitForWindowExposed(&w1); + + QWidget w2; + w2.show(); + QTest::qWaitForWindowExposed(&w2); + + glw->setParent(&w2); + glw->show(); + + QImage image = glw->grabFramebuffer(); + QCOMPARE(image.width(), 320); + QCOMPARE(image.height(), 200); + QVERIFY(image.pixel(20, 10) == qRgb(0, 0, 255)); +} + +void tst_QOpenGLWidget::reparentToNotYetCreated() +{ + QWidget w1; + PainterWidget *glw = new PainterWidget(&w1); + w1.resize(640, 480); + glw->resize(320, 200); + w1.show(); + QTest::qWaitForWindowExposed(&w1); + + QWidget w2; + glw->setParent(&w2); + w2.show(); + QTest::qWaitForWindowExposed(&w2); + + QImage image = glw->grabFramebuffer(); + QCOMPARE(image.width(), 320); + QCOMPARE(image.height(), 200); + QVERIFY(image.pixel(20, 10) == qRgb(0, 0, 255)); +} + +QTEST_MAIN(tst_QOpenGLWidget) + +#include "tst_qopenglwidget.moc" diff --git a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp index 21034e8f1b..350ae23d8a 100644 --- a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp +++ b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp @@ -393,18 +393,31 @@ void tst_QSpinBox::valueChangedHelper(int value) actualValues << value; } +class MySpinBox: public QSpinBox +{ +public: + MySpinBox(QWidget *parent = 0) : QSpinBox(parent) {} + + void changeEvent(QEvent *ev) { + eventsReceived.append(ev->type()); + } + QList<QEvent::Type> eventsReceived; +}; + void tst_QSpinBox::setReadOnly() { - QSpinBox spin(0); + MySpinBox spin(0); spin.show(); QTest::keyClick(&spin, Qt::Key_Up); QCOMPARE(spin.value(), 1); spin.setReadOnly(true); + QCOMPARE(spin.eventsReceived, QList<QEvent::Type>() << QEvent::ReadOnlyChange); QTest::keyClick(&spin, Qt::Key_Up); QCOMPARE(spin.value(), 1); spin.stepBy(1); QCOMPARE(spin.value(), 2); spin.setReadOnly(false); + QCOMPARE(spin.eventsReceived, QList<QEvent::Type>() << QEvent::ReadOnlyChange << QEvent::ReadOnlyChange); QTest::keyClick(&spin, Qt::Key_Up); QCOMPARE(spin.value(), 3); } diff --git a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp index 06dd623368..fedf16271f 100644 --- a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp +++ b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp @@ -99,6 +99,7 @@ private slots: void taskQTBUG_10052_widgetLayoutWhenMoving(); void tabBarClicked(); + void autoHide(); }; // Testing get/set functions @@ -701,5 +702,32 @@ void tst_QTabBar::tabBarClicked() } } +void tst_QTabBar::autoHide() +{ + QTabBar tabBar; + QVERIFY(!tabBar.autoHide()); + QVERIFY(!tabBar.isVisible()); + tabBar.show(); + QVERIFY(tabBar.isVisible()); + tabBar.addTab("0"); + QVERIFY(tabBar.isVisible()); + tabBar.removeTab(0); + QVERIFY(tabBar.isVisible()); + + tabBar.setAutoHide(true); + QVERIFY(!tabBar.isVisible()); + tabBar.addTab("0"); + QVERIFY(!tabBar.isVisible()); + tabBar.addTab("1"); + QVERIFY(tabBar.isVisible()); + tabBar.removeTab(0); + QVERIFY(!tabBar.isVisible()); + tabBar.removeTab(0); + QVERIFY(!tabBar.isVisible()); + + tabBar.setAutoHide(false); + QVERIFY(tabBar.isVisible()); +} + QTEST_MAIN(tst_QTabBar) #include "tst_qtabbar.moc" diff --git a/tests/auto/widgets/widgets/widgets.pro b/tests/auto/widgets/widgets/widgets.pro index 29d1f7746c..423b3952d4 100644 --- a/tests/auto/widgets/widgets/widgets.pro +++ b/tests/auto/widgets/widgets/widgets.pro @@ -52,3 +52,5 @@ SUBDIRS=\ qmainwindow \ qtextedit \ qtoolbar \ + +contains(QT_CONFIG, opengl): SUBDIRS += qopenglwidget |