QSplitter: Exclude top level widgets from child event handling.

Prevent the splitter from adding them to the layout or showing
them.

Task-number: QTBUG-40132
Change-Id: Ife2be0bbd7e489570ef41f6f72a034b356c65f18
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
This commit is contained in:
Friedemann Kleint 2014-07-15 10:32:07 +02:00
parent e0dc27d791
commit cdba2439f9
2 changed files with 32 additions and 3 deletions

View File

@ -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 QtWidgets module of the Qt Toolkit.
@ -1224,7 +1224,9 @@ void QSplitter::childEvent(QChildEvent *c)
return;
}
QWidget *w = static_cast<QWidget*>(c->child());
if (c->added() && !d->blockChildAdd && !w->isWindow() && !d->findWidget(w)) {
if (w->isWindow())
return;
if (c->added() && !d->blockChildAdd && !d->findWidget(w)) {
d->insertWidget_helper(d->list.count(), w, false);
} else if (c->polished() && !d->blockChildAdd) {
if (isVisible() && !(w->isHidden() && w->testAttribute(Qt::WA_WState_ExplicitShowHide)))

View File

@ -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.
@ -54,6 +54,8 @@
#include <qtextedit.h>
#include <qtreeview.h>
#include <qlabel.h>
#include <qdialog.h>
#include <qscreen.h>
#include <qdebug.h> // for file error messages
QT_FORWARD_DECLARE_CLASS(QSplitter)
@ -94,6 +96,8 @@ private slots:
void taskQTBUG_4101_ensureOneNonCollapsedWidget_data();
void taskQTBUG_4101_ensureOneNonCollapsedWidget();
void setLayout();
void autoAdd();
private:
void removeThirdWidget();
void addThirdWidget();
@ -781,5 +785,28 @@ void tst_QSplitter::setLayout()
QCOMPARE(splitter.layout(), &layout);
}
void tst_QSplitter::autoAdd()
{
QSplitter splitter;
splitter.setWindowTitle("autoAdd");
splitter.setMinimumSize(QSize(200, 200));
splitter.move(QGuiApplication::primaryScreen()->availableGeometry().center() - QPoint(100, 100));
splitter.show();
QVERIFY(QTest::qWaitForWindowExposed(&splitter));
// Constructing a child widget on the splitter should
// automatically add and show it.
QWidget *childWidget = new QWidget(&splitter);
QCOMPARE(splitter.count(), 1);
QTRY_VERIFY(childWidget->isVisible());
// Deleting should automatically remove it
delete childWidget;
QCOMPARE(splitter.count(), 0);
// QTBUG-40132, top level windows should not be affected by this.
QDialog *dialog = new QDialog(&splitter);
QCOMPARE(splitter.count(), 0);
QCoreApplication::processEvents();
QVERIFY(!dialog->isVisible());
}
QTEST_MAIN(tst_QSplitter)
#include "tst_qsplitter.moc"