summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r--tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp7
-rw-r--r--tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp40
-rw-r--r--tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp106
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp141
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp40
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp73
-rw-r--r--tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp18
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp1
-rw-r--r--tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp37
-rw-r--r--tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp163
-rw-r--r--tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp46
-rw-r--r--tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp3
-rw-r--r--tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp22
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp286
-rwxr-xr-xtests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp40
-rw-r--r--tests/auto/widgets/kernel/qwidgetsvariant/tst_qwidgetsvariant.cpp6
-rw-r--r--tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp6
-rw-r--r--tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp28
-rw-r--r--tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp19
-rw-r--r--tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp42
-rw-r--r--tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp15
-rw-r--r--tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp47
-rw-r--r--tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp22
-rw-r--r--tests/auto/widgets/widgets/qopenglwidget/qopenglwidget.pro8
-rw-r--r--tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp266
-rw-r--r--tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp15
-rw-r--r--tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp37
-rw-r--r--tests/auto/widgets/widgets/qstatusbar/tst_qstatusbar.cpp20
-rw-r--r--tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp28
-rw-r--r--tests/auto/widgets/widgets/widgets.pro2
30 files changed, 1404 insertions, 180 deletions
diff --git a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp
index cd9ff28891..3a26d3c2f0 100644
--- a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp
+++ b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp
@@ -565,11 +565,14 @@ void tst_QDialog::snapToDefaultButton()
#ifdef QT_NO_CURSOR
QSKIP("Test relies on there being a cursor");
#else
+ if (qApp->platformName().toLower() == QLatin1String("wayland"))
+ QSKIP("Wayland: Wayland does not support setting the cursor position.");
+
QPoint topLeftPos = QApplication::desktop()->availableGeometry().topLeft();
topLeftPos = QPoint(topLeftPos.x() + 100, topLeftPos.y() + 100);
QPoint startingPos(topLeftPos.x() + 250, topLeftPos.y() + 250);
QCursor::setPos(startingPos);
- QVERIFY(QCursor::pos() == startingPos);
+ QCOMPARE(QCursor::pos(), startingPos);
QDialog dialog;
QPushButton *button = new QPushButton(&dialog);
button->setDefault(true);
@@ -581,7 +584,7 @@ void tst_QDialog::snapToDefaultButton()
QPoint localPos = button->mapFromGlobal(QCursor::pos());
QVERIFY(button->rect().contains(localPos));
} else {
- QVERIFY(startingPos == QCursor::pos());
+ QCOMPARE(startingPos, QCursor::pos());
}
}
#endif // !QT_NO_CURSOR
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..4e54c445b8 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,87 @@ 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);
+ 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);
+ QVERIFY(!bar);
+}
+
+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..8847a5748f 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();
@@ -459,6 +461,7 @@ private slots:
void touchEventPropagation_data();
void touchEventPropagation();
void deviceCoordinateCache_simpleRotations();
+ void resolvePaletteForItemChildren();
// task specific tests below me
void task141694_textItemEnsureVisible();
@@ -5855,6 +5858,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 +6074,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);
@@ -11581,5 +11696,21 @@ void tst_QGraphicsItem::QTBUG_21618_untransformable_sceneTransform()
QCOMPARE(item2_bottomright->deviceTransform(tx).map(QPointF()), QPointF(100, 300));
}
+void tst_QGraphicsItem::resolvePaletteForItemChildren()
+{
+ QGraphicsScene scene;
+ QGraphicsRectItem item(0, 0, 50, -150);
+ scene.addItem(&item);
+ QGraphicsWidget widget;
+ widget.setParentItem(&item);
+
+ QColor green(Qt::green);
+ QPalette paletteForScene = scene.palette();
+ paletteForScene.setColor(QPalette::Active, QPalette::Window, green);
+ scene.setPalette(paletteForScene);
+
+ QCOMPARE(widget.palette().color(QPalette::Active, QPalette::Window), green);
+}
+
QTEST_MAIN(tst_QGraphicsItem)
#include "tst_qgraphicsitem.moc"
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/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index 869b335a95..6f11609542 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -1653,6 +1653,7 @@ void tst_QHeaderView::saveRestore()
QByteArray s2 = h2.saveState();
QVERIFY(s1 == s2);
+ QVERIFY(!h2.restoreState(QByteArrayLiteral("Garbage")));
}
void tst_QHeaderView::defaultSectionSizeTest()
diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
index 78a3ad021b..bb05db0b15 100644
--- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
+++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
@@ -155,6 +155,7 @@ private slots:
void spacing();
void testScrollToWithHidden();
void testViewOptions();
+ void taskQTBUG_39902_mutualScrollBars();
};
// Testing get/set functions
@@ -2235,8 +2236,7 @@ void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys()
QTest::keyClick(&lv, Qt::Key_Down);
else
QTest::keyClick(&lv, Qt::Key_Right);
- QTest::qWait(100);
- QVERIFY(lv.rect().contains(lv.visualRect(lv.currentIndex())));
+ QTRY_VERIFY(lv.rect().contains(lv.visualRect(lv.currentIndex())));
}
// scroll backward
@@ -2245,8 +2245,7 @@ void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys()
QTest::keyClick(&lv, Qt::Key_Up);
else
QTest::keyClick(&lv, Qt::Key_Left);
- QTest::qWait(100);
- QVERIFY(lv.rect().contains(lv.visualRect(lv.currentIndex())));
+ QTRY_VERIFY(lv.rect().contains(lv.visualRect(lv.currentIndex())));
}
// scroll forward only half way
@@ -2255,8 +2254,7 @@ void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys()
QTest::keyClick(&lv, Qt::Key_Down);
else
QTest::keyClick(&lv, Qt::Key_Right);
- QTest::qWait(100);
- QVERIFY(lv.rect().contains(lv.visualRect(lv.currentIndex())));
+ QTRY_VERIFY(lv.rect().contains(lv.visualRect(lv.currentIndex())));
}
// scroll backward again
@@ -2265,8 +2263,7 @@ void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys()
QTest::keyClick(&lv, Qt::Key_Up);
else
QTest::keyClick(&lv, Qt::Key_Left);
- QTest::qWait(100);
- QVERIFY(lv.rect().contains(lv.visualRect(lv.currentIndex())));
+ QTRY_VERIFY(lv.rect().contains(lv.visualRect(lv.currentIndex())));
}
}
@@ -2359,5 +2356,29 @@ void tst_QListView::testViewOptions()
QCOMPARE(options.decorationPosition, QStyleOptionViewItem::Top);
}
+void tst_QListView::taskQTBUG_39902_mutualScrollBars()
+{
+ QWidget window;
+ window.resize(400, 300);
+ QListView *view = new QListView(&window);
+ QStandardItemModel model(200, 1);
+ const QSize itemSize(100, 20);
+ for (int i = 0; i < model.rowCount(); ++i)
+ model.setData(model.index(i, 0), itemSize, Qt::SizeHintRole);
+ view->setModel(&model);
+
+ window.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+ // make sure QListView is done with layouting the items (1/10 sec, like QListView)
+ QTest::qWait(100);
+
+ model.setRowCount(2);
+ for (int i = 0; i < model.rowCount(); ++i)
+ model.setData(model.index(i, 0), itemSize, Qt::SizeHintRole);
+ view->resize(itemSize.width() + view->frameWidth() * 2, model.rowCount() * itemSize.height() + view->frameWidth() * 2);
+ // this will end up in a stack overflow, if QTBUG-39902 is not fixed
+ QTest::qWait(100);
+}
+
QTEST_MAIN(tst_QListView)
#include "tst_qlistview.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/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
index d12fb06daa..653f158fc9 100644
--- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
@@ -212,6 +212,7 @@ private slots:
void rowSizeHint();
void setSortingEnabled();
void headerHidden();
+ void indentation();
void selection();
void removeAndInsertExpandedCol0();
@@ -439,7 +440,8 @@ void tst_QTreeView::getSetCheck()
// int QTreeView::indentation()
// void QTreeView::setIndentation(int)
- QCOMPARE(obj1.indentation(), 20);
+ const int styledIndentation = obj1.style()->pixelMetric(QStyle::PM_TreeViewIndentation, 0, &obj1);
+ QCOMPARE(obj1.indentation(), styledIndentation);
obj1.setIndentation(0);
QCOMPARE(obj1.indentation(), 0);
obj1.setIndentation(INT_MIN);
@@ -554,7 +556,8 @@ void tst_QTreeView::construction()
QCOMPARE(view.columnWidth(0), 0);
QCOMPARE(view.columnWidth(1), 0);
QVERIFY(view.header());
- QCOMPARE(view.indentation(), 20);
+ const int styledIndentation = view.style()->pixelMetric(QStyle::PM_TreeViewIndentation, 0, &view);
+ QCOMPARE(view.indentation(), styledIndentation);
QCOMPARE(view.indexAbove(QModelIndex()), QModelIndex());
QCOMPARE(view.indexBelow(QModelIndex()), QModelIndex());
QVERIFY(!view.isAnimated());
@@ -2372,6 +2375,9 @@ void tst_QTreeView::selectionOrderTest()
void tst_QTreeView::selection()
{
+ if (qApp->platformName().toLower() == QLatin1String("wayland"))
+ QSKIP("Wayland: This causes a crash triggered by setVisible(false)");
+
QTreeView treeView;
QStandardItemModel m(10, 2);
for (int i = 0;i < 10; ++i)
@@ -2573,6 +2579,42 @@ void tst_QTreeView::headerHidden()
QCOMPARE(view.header()->isHidden(), true);
}
+class TestTreeViewStyle : public QProxyStyle
+{
+public:
+ TestTreeViewStyle() : indentation(20) {}
+ int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const Q_DECL_OVERRIDE
+ {
+ if (metric == QStyle::PM_TreeViewIndentation)
+ return indentation;
+ else
+ return QProxyStyle::pixelMetric(metric, option, widget);
+ }
+ int indentation;
+};
+
+void tst_QTreeView::indentation()
+{
+ TestTreeViewStyle style1;
+ TestTreeViewStyle style2;
+ style1.indentation = 20;
+ style2.indentation = 30;
+
+ QTreeView view;
+ view.setStyle(&style1);
+ QCOMPARE(view.indentation(), style1.indentation);
+ view.setStyle(&style2);
+ QCOMPARE(view.indentation(), style2.indentation);
+ view.setIndentation(70);
+ QCOMPARE(view.indentation(), 70);
+ view.setStyle(&style1);
+ QCOMPARE(view.indentation(), 70);
+ view.resetIndentation();
+ QCOMPARE(view.indentation(), style1.indentation);
+ view.setStyle(&style2);
+ QCOMPARE(view.indentation(), style2.indentation);
+}
+
// From Task 145199 (crash when column 0 having at least one expanded item is removed and then
// inserted). The test passes simply if it doesn't crash, hence there are no calls
// to QCOMPARE() or QVERIFY().
diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
index 390858ac5b..a5da775d82 100644
--- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
+++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
@@ -3342,6 +3342,9 @@ void tst_QTreeWidget::setChildIndicatorPolicy()
void tst_QTreeWidget::task20345_sortChildren()
{
+ if (qApp->platformName().toLower() == QLatin1String("wayland"))
+ QSKIP("Wayland: This causes a crash triggered by setVisible(false)");
+
// This test case is considered successful if it is executed (no crash in sorting)
QTreeWidget tw;
tw.setColumnCount(3);
diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
index 9d7d3d1f34..7a2d42ec02 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);
@@ -1976,7 +1976,9 @@ public:
TouchEventPropagationTestWidget(QWidget *parent = 0)
: QWidget(parent), seenTouchEvent(false), acceptTouchEvent(false), seenMouseEvent(false), acceptMouseEvent(false)
- { }
+ {
+ setAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents);
+ }
void reset()
{
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 4252fb673b..b443cdcaa7 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));
@@ -1834,9 +1855,11 @@ void tst_QWidget::windowState()
{
if (m_platform == QStringLiteral("xcb"))
QSKIP("X11: Many window managers do not support window state properly, which causes this test to fail.");
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
QPoint pos;
- QSize size(200, 200);
+ QSize size = m_testWidgetSize;
if (QGuiApplicationPrivate::platformIntegration()->defaultWindowState(Qt::Widget)
== Qt::WindowFullScreen) {
size = QGuiApplication::primaryScreen()->size();
@@ -2036,6 +2059,8 @@ void tst_QWidget::showMaximized()
void tst_QWidget::showFullScreen()
{
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
QWidget plain;
QHBoxLayout *layout;
QWidget layouted;
@@ -2218,6 +2243,8 @@ void tst_QWidget::showMinimizedKeepsFocus()
{
if (m_platform == QStringLiteral("xcb"))
QSKIP("QTBUG-26424");
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
//here we test that minimizing a widget and restoring it doesn't change the focus inside of it
{
@@ -2275,6 +2302,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 +2370,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 +2382,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 +2396,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());
@@ -2405,6 +2435,8 @@ void tst_QWidget::icon()
void tst_QWidget::hideWhenFocusWidgetIsChild()
{
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
testWidget->activateWindow();
QScopedPointer<QWidget> parentWidget(new QWidget(testWidget));
parentWidget->setObjectName("parentWidget");
@@ -2439,6 +2471,8 @@ void tst_QWidget::hideWhenFocusWidgetIsChild()
void tst_QWidget::normalGeometry()
{
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
QWidget parent;
parent.setWindowTitle("NormalGeometry parent");
QWidget *child = new QWidget(&parent);
@@ -2446,7 +2480,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 +3044,10 @@ void tst_QWidget::testContentsPropagation()
void tst_QWidget::saveRestoreGeometry()
{
- const QPoint position(100, 100);
- const QSize size(200, 200);
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
+ const QPoint position = m_availableTopLeft + QPoint(100, 100);
+ const QSize size = m_testWidgetSize;
QByteArray savedGeometry;
@@ -3137,6 +3174,8 @@ void tst_QWidget::saveRestoreGeometry()
void tst_QWidget::restoreVersion1Geometry_data()
{
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
QTest::addColumn<QString>("fileName");
QTest::addColumn<uint>("expectedWindowState");
QTest::addColumn<QPoint>("expectedPosition");
@@ -3230,21 +3269,25 @@ void tst_QWidget::restoreVersion1Geometry()
void tst_QWidget::widgetAt()
{
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
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 +3295,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 +3323,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 +3334,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 +3353,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()
@@ -3547,6 +3590,8 @@ public:
*/
void tst_QWidget::optimizedResizeMove()
{
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
QWidget parent;
parent.resize(400, 400);
@@ -3957,7 +4002,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();
@@ -4293,6 +4339,8 @@ void tst_QWidget::isOpaque()
*/
void tst_QWidget::scroll()
{
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
const int w = qMin(500, qApp->desktop()->availableGeometry().width() / 2);
const int h = qMin(500, qApp->desktop()->availableGeometry().height() / 2);
@@ -4420,36 +4468,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;
@@ -4629,6 +4680,8 @@ void tst_QWidget::windowMoveResize()
{
if (m_platform == QStringLiteral("xcb"))
QSKIP("X11: Skip this test due to Window manager positioning issues.");
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
QFETCH(QList<QRect>, rects);
QFETCH(int, windowFlags);
@@ -4972,6 +5025,8 @@ void tst_QWidget::moveChild_data()
void tst_QWidget::moveChild()
{
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
QFETCH(QPoint, offset);
ColorWidget parent(0, Qt::Window | Qt::WindowStaysOnTopHint);
@@ -5021,6 +5076,8 @@ void tst_QWidget::moveChild()
void tst_QWidget::showAndMoveChild()
{
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
#if defined(UBUNTU_ONEIRIC)
QSKIP("QTBUG-30566 - Unstable auto-test");
#endif
@@ -5135,6 +5192,8 @@ public slots:
void tst_QWidget::multipleToplevelFocusCheck()
{
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
TopLevelFocusCheck w1;
TopLevelFocusCheck w2;
@@ -5202,6 +5261,7 @@ public:
void tst_QWidget::setFocus()
{
+ const QPoint windowPos = testWidget->geometry().topRight() + QPoint(50, 0);
{
// move focus to another window
testWidget->activateWindow();
@@ -5213,7 +5273,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 +5297,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 +5331,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 +5364,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 +5405,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 +5661,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;
@@ -5895,6 +5971,8 @@ QByteArray EventRecorder::msgEventListMismatch(const EventList &expected, const
void tst_QWidget::childEvents()
{
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
EventRecorder::EventList expected;
// Move away the cursor; otherwise it might result in an enter event if it's
@@ -6295,6 +6373,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 +6384,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 +6696,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;
@@ -7250,6 +7334,8 @@ void tst_QWidget::hideOpaqueChildWhileHidden()
#if !defined(Q_OS_WINCE)
void tst_QWidget::updateWhileMinimized()
{
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
#if defined(Q_OS_QNX) && (!defined(Q_OS_BLACKBERRY) || defined(Q_OS_BLACKBERRY_TABLET))
QSKIP("Platform does not support showMinimized()");
#endif
@@ -7305,7 +7391,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 +7425,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 +7487,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 +7496,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 +7520,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 +7553,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 +7594,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 +8341,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 +8361,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 +8405,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 +8427,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));
@@ -8729,6 +8831,8 @@ void tst_QWidget::maskedUpdate()
#ifndef QTEST_NO_CURSOR
void tst_QWidget::syntheticEnterLeave()
{
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
class MyWidget : public QWidget
{
public:
@@ -8833,6 +8937,8 @@ void tst_QWidget::syntheticEnterLeave()
#ifndef QTEST_NO_CURSOR
void tst_QWidget::taskQTBUG_4055_sendSyntheticEnterLeave()
{
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
class SELParent : public QWidget
{
public:
@@ -8962,7 +9068,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 +9086,7 @@ void tst_QWidget::toplevelLineEditFocus()
testWidget->hide();
QLineEdit w;
+ w.setMinimumWidth(m_testWidgetSize.width());
w.show();
QVERIFY(QTest::qWaitForWindowExposed(&w));
QTest::qWait(20);
@@ -9134,12 +9241,18 @@ void tst_QWidget::setGraphicsEffect()
void tst_QWidget::activateWindow()
{
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
+
// Test case for QTBUG-26711
// 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 +9260,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 +9286,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 +9296,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()));
@@ -9190,6 +9307,8 @@ void tst_QWidget::openModal_taskQTBUG_5804()
void tst_QWidget::focusProxyAndInputMethods()
{
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
QScopedPointer<QWidget> toplevel(new QWidget(0, Qt::X11BypassWindowManagerHint));
toplevel->resize(200, 200);
toplevel->setAttribute(Qt::WA_InputMethodEnabled, true);
@@ -9444,6 +9563,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 +9573,7 @@ void tst_QWidget::nativeChildFocus()
layout->addWidget(p2);
p1->setObjectName("p1");
p2->setObjectName("p2");
+ centerOnScreen(&w);
w.show();
w.activateWindow();
p1->setFocus();
@@ -9588,8 +9710,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 +9739,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));
@@ -9696,6 +9822,8 @@ void tst_QWidget::touchEventSynthesizedMouseEvent()
// Pass if the platform does not want mouse event synhesizing
if (!QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::SynthesizeMouseFromTouchEvents).toBool())
return;
+ if (m_platform == QStringLiteral("wayland"))
+ QSKIP("Wayland: This fails. Figure out why.");
{
// Simple case, we ignore the touch events, we get mouse events instead
@@ -10211,11 +10339,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 87e1c7a4f3..0240bde3e9 100755
--- a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp
+++ b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp
@@ -64,7 +64,7 @@ static inline void setFrameless(QWidget *w)
w->setWindowFlags(flags);
}
-class tst_QWidget_window : public QWidget
+class tst_QWidget_window : public QObject
{
Q_OBJECT
@@ -74,6 +74,7 @@ public:
public slots:
void initTestCase();
void cleanupTestCase();
+ void cleanup();
private slots:
void tst_min_max_size();
@@ -99,6 +100,7 @@ private slots:
#endif
void tst_qtbug35600();
+ void tst_updateWinId_QTBUG40681();
void tst_recreateWindow_QTBUG40817();
};
@@ -111,9 +113,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). */
@@ -603,6 +609,34 @@ void tst_QWidget_window::tst_qtbug35600()
// QTBUG-35600: program may crash here or on exit
}
+void tst_QWidget_window::tst_updateWinId_QTBUG40681()
+{
+ QWidget w;
+ QVBoxLayout *vl = new QVBoxLayout(&w);
+ QLabel *lbl = new QLabel("HELLO1");
+ lbl->setAttribute(Qt::WA_NativeWindow);
+ lbl->setObjectName("label1");
+ vl->addWidget(lbl);
+ w.setMinimumWidth(200);
+
+ w.show();
+
+ QVERIFY(QTest::qWaitForWindowExposed(&w));
+
+ QCOMPARE(lbl->winId(), lbl->windowHandle()->winId());
+
+ // simulate screen change and notification
+ QWindow *win = w.windowHandle();
+ w.windowHandle()->destroy();
+ lbl->windowHandle()->destroy();
+ w.windowHandle()->create();
+ lbl->windowHandle()->create();
+ QWindowPrivate *p = qt_window_private(win);
+ p->emitScreenChangedRecursion(win->screen());
+
+ QCOMPARE(lbl->winId(), lbl->windowHandle()->winId());
+}
+
void tst_QWidget_window::tst_recreateWindow_QTBUG40817()
{
QTabWidget tab;
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/kernel/qwindowcontainer/tst_qwindowcontainer.cpp b/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp
index cd6433bbe7..75ee52cf0e 100644
--- a/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp
+++ b/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp
@@ -193,7 +193,7 @@ void tst_QWindowContainer::testActivation()
QVERIFY(QTest::qWaitForWindowExposed(&root));
QVERIFY(QTest::qWaitForWindowActive(root.windowHandle()));
- QVERIFY(QGuiApplication::focusWindow() == root.windowHandle());
+ QCOMPARE(QGuiApplication::focusWindow(), root.windowHandle());
// Verify that all states in the root widget indicate it is active
QVERIFY(root.windowHandle()->isActive());
@@ -207,7 +207,7 @@ void tst_QWindowContainer::testActivation()
QTest::qWait(100);
window->requestActivate();
- QTRY_VERIFY(QGuiApplication::focusWindow() == window);
+ QTRY_COMPARE(QGuiApplication::focusWindow(), window);
// Verify that all states in the root widget still indicate it is active
QVERIFY(root.windowHandle()->isActive());
@@ -303,7 +303,7 @@ void tst_QWindowContainer::testDockWidget()
mainWindow.show();
QVERIFY(QTest::qWaitForWindowExposed(&mainWindow));
- QVERIFY(window->parent() == mainWindow.window()->windowHandle());
+ QCOMPARE(window->parent(), mainWindow.window()->windowHandle());
QTest::qWait(1000);
dock->setFloating(true);
diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
index c38c254b9a..40496dbebb 100644
--- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
+++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
@@ -53,6 +53,7 @@
#include <qdialog.h>
#include <qevent.h>
#include <qlineedit.h>
+#include <qlabel.h>
#include <qlistview.h>
#include <qheaderview.h>
#include <qlistwidget.h>
@@ -131,6 +132,7 @@ private slots:
void pixmapIcon();
void mouseWheel_data();
void mouseWheel();
+ void wheelClosingPopup();
void layoutDirection();
void itemListPosition();
void separatorItem_data();
@@ -2041,6 +2043,32 @@ void tst_QComboBox::mouseWheel()
}
}
+void tst_QComboBox::wheelClosingPopup()
+{
+ // QTBUG-40656, combo and other popups should close when the main window gets a wheel event.
+ QScrollArea scrollArea;
+ scrollArea.move(300, 300);
+ QWidget *widget = new QWidget;
+ scrollArea.setWidget(widget);
+ QVBoxLayout *layout = new QVBoxLayout(widget);
+ layout->setSizeConstraint(QLayout::SetMinAndMaxSize);
+ layout->addSpacing(100);
+ QComboBox *comboBox = new QComboBox;
+ comboBox->addItems(QStringList() << QStringLiteral("Won") << QStringLiteral("Too")
+ << QStringLiteral("3") << QStringLiteral("fore"));
+ layout->addWidget(comboBox);
+ layout->addSpacing(100);
+ const QPoint sizeP(scrollArea.width(), scrollArea.height());
+ scrollArea.move(QGuiApplication::primaryScreen()->availableGeometry().center() - sizeP / 2);
+ scrollArea.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&scrollArea));
+ comboBox->showPopup();
+ QTRY_VERIFY(comboBox->view() && comboBox->view()->isVisible());
+ QWheelEvent event(QPointF(10, 10), WHEEL_DELTA, Qt::NoButton, Qt::NoModifier);
+ QVERIFY(QCoreApplication::sendEvent(scrollArea.windowHandle(), &event));
+ QTRY_VERIFY(!comboBox->view()->isVisible());
+}
+
void tst_QComboBox::layoutDirection()
{
QComboBox box;
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 2d050cd5fa..63928db80f 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.
@@ -244,6 +244,7 @@ private slots:
#ifndef QT_NO_CLIPBOARD
void cut();
+ void cutWithoutSelection();
#endif
void maxLengthAndInputMask();
void returnPressedKeyEvent();
@@ -2977,7 +2978,37 @@ void tst_QLineEdit::cut()
testWidget->cut();
QCOMPARE(testWidget->text(), QString("Abcdefg defg hijklmno"));
}
-#endif
+
+void tst_QLineEdit::cutWithoutSelection()
+{
+ enum { selectionLength = 1 };
+
+ if (QKeySequence(QKeySequence::Cut).toString() != QLatin1String("Ctrl+X"))
+ QSKIP("Platform with non-standard keybindings");
+ QClipboard *clipboard = QGuiApplication::clipboard();
+ if (!PlatformClipboard::isAvailable()
+ || !QGuiApplication::platformName().compare("xcb", Qt::CaseInsensitive)) { // Avoid unstable X11 clipboard
+ clipboard = Q_NULLPTR;
+ }
+
+ if (clipboard)
+ clipboard->clear();
+ const QString origText = QStringLiteral("test");
+ QLineEdit lineEdit(origText);
+ lineEdit.setCursorPosition(0);
+ QVERIFY(!lineEdit.hasSelectedText());
+ QTest::keyClick(&lineEdit, Qt::Key_X, Qt::ControlModifier);
+ QCOMPARE(lineEdit.text(), origText); // No selection, unmodified.
+ if (clipboard)
+ QVERIFY(clipboard->text().isEmpty());
+ lineEdit.setSelection(0, selectionLength);
+ QTest::keyClick(&lineEdit, Qt::Key_X, Qt::ControlModifier);
+ QCOMPARE(lineEdit.text(), origText.right(origText.size() - selectionLength));
+ if (clipboard)
+ QCOMPARE(clipboard->text(), origText.left(selectionLength));
+}
+
+#endif // !QT_NO_CLIPBOARD
class InputMaskValidator : public QValidator
{
@@ -4186,9 +4217,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);
QTRY_COMPARE(clearButton->cursor().shape(), filterLineEdit->cursor().shape());
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..6c63d1ee90 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()
@@ -1037,6 +1047,14 @@ void tst_QMenu::QTBUG_37933_ampersands_data()
QTest::newRow("simple") << QString("Test") << QString("Test");
QTest::newRow("ampersand") << QString("&Test") << QString("Test");
QTest::newRow("double_ampersand") << QString("&Test && more") << QString("Test & more");
+ QTest::newRow("ampersand_in_parentheses") << QString("Test(&T) (&&) more") << QString("Test (&) more");
+ QTest::newRow("ampersand_in_parentheses_after_space") << QString("Test (&T)") << QString("Test");
+ QTest::newRow("ampersand_in_parentheses_after_spaces") << QString("Test (&T)") << QString("Test");
+ QTest::newRow("ampersand_in_parentheses_before_space") << QString("Test(&T) ") << QString("Test ");
+ QTest::newRow("only_ampersand_in_parentheses") << QString("(&T)") << QString("");
+ QTest::newRow("only_ampersand_in_parentheses_after_space") << QString(" (&T)") << QString("");
+ QTest::newRow("parentheses_after_space") << QString(" (Dummy)") << QString(" (Dummy)");
+ QTest::newRow("ampersand_after_space") << QString("About &Qt Project") << QString("About Qt Project");
}
void tst_qmenu_QTBUG_37933_ampersands();
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/qsplitter/tst_qsplitter.cpp b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp
index d66a10ae56..17fde2883a 100644
--- a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp
+++ b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp
@@ -56,6 +56,7 @@
#include <qlabel.h>
#include <qdialog.h>
#include <qscreen.h>
+#include <qproxystyle.h>
#include <qdebug.h> // for file error messages
QT_FORWARD_DECLARE_CLASS(QSplitter)
@@ -88,6 +89,7 @@ private slots:
void testRemoval();
void rubberBandNotInSplitter();
void saveAndRestoreStateOfNotYetShownSplitter();
+ void saveAndRestoreHandleWidth();
// task-specific tests below me:
void task187373_addAbstractScrollAreas();
@@ -301,6 +303,41 @@ void tst_QSplitter::saveAndRestoreStateOfNotYetShownSplitter()
delete spl;
}
+class TestSplitterStyle : public QProxyStyle
+{
+public:
+ TestSplitterStyle() : handleWidth(5) {}
+ int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const Q_DECL_OVERRIDE
+ {
+ if (metric == QStyle::PM_SplitterWidth)
+ return handleWidth;
+ else
+ return QProxyStyle::pixelMetric(metric, option, widget);
+ }
+ int handleWidth;
+};
+
+void tst_QSplitter::saveAndRestoreHandleWidth()
+{
+ TestSplitterStyle style;
+ style.handleWidth = 5;
+ QSplitter spl;
+ spl.setStyle(&style);
+
+ QCOMPARE(spl.handleWidth(), style.handleWidth);
+ style.handleWidth = 10;
+ QCOMPARE(spl.handleWidth(), style.handleWidth);
+ QByteArray ba = spl.saveState();
+ spl.setHandleWidth(20);
+ QCOMPARE(spl.handleWidth(), 20);
+ spl.setHandleWidth(-1);
+ QCOMPARE(spl.handleWidth(), style.handleWidth);
+ spl.setHandleWidth(15);
+ QCOMPARE(spl.handleWidth(), 15);
+ spl.restoreState(ba);
+ QCOMPARE(spl.handleWidth(), style.handleWidth);
+}
+
void tst_QSplitter::saveState_data()
{
QTest::addColumn<IntList>("initialSizes");
diff --git a/tests/auto/widgets/widgets/qstatusbar/tst_qstatusbar.cpp b/tests/auto/widgets/widgets/qstatusbar/tst_qstatusbar.cpp
index 8dd191e621..38eae1d19d 100644
--- a/tests/auto/widgets/widgets/qstatusbar/tst_qstatusbar.cpp
+++ b/tests/auto/widgets/widgets/qstatusbar/tst_qstatusbar.cpp
@@ -285,17 +285,21 @@ void tst_QStatusBar::QTBUG25492_msgtimeout()
QCOMPARE(testWidget->currentMessage(), QString("Ready"));
QCOMPARE(testWidget->currentMessage(), currentMessage);
- QTest::qWait(1000);
-
- // Set display message for 2 seconds again
- testWidget->showMessage("Ready", 2000);
- QCOMPARE(testWidget->currentMessage(), QString("Ready"));
+ // Set display message for 2 seconds
+ QElapsedTimer t;
+ t.start();
+ testWidget->showMessage("Ready 2000", 2000);
+ QCOMPARE(testWidget->currentMessage(), QString("Ready 2000"));
QCOMPARE(testWidget->currentMessage(), currentMessage);
- QTest::qWait(1500);
-
// Message disappears after 2 seconds
QTRY_VERIFY(testWidget->currentMessage().isNull());
+ qint64 ts = t.elapsed();
+
+ // XXX: ideally ts should be 2000, but sometimes it appears to go away early, probably due to timer granularity.
+ QVERIFY2(ts >= 1800, qPrintable("Timer was " + QString::number(ts)));
+ if (ts < 2000)
+ qWarning("QTBUG25492_msgtimeout: message vanished early, should be >= 2000, was %lld", ts);
QVERIFY(currentMessage.isNull());
// Set display message for 2 seconds first
@@ -303,8 +307,6 @@ void tst_QStatusBar::QTBUG25492_msgtimeout()
QCOMPARE(testWidget->currentMessage(), QString("Ready 25492"));
QCOMPARE(testWidget->currentMessage(), currentMessage);
- QTest::qWait(1000);
-
// Set display message forever again
testWidget->showMessage("Ready 25492", 0);
QCOMPARE(testWidget->currentMessage(), QString("Ready 25492"));
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