Fix setWindowFlags() for QMdiSubWindow.

It was impossible to hide/show the close button after a QMdiSubWindow
was created.

Task-number: QTBUG-9933
Task-number: QTBUG-27274

[ChangeLog][QtWidgets][QMdiSubWindow] Fixed setWindowFlags() for QMdiSubWindow.

Change-Id: I7db9a1bef5ba8a8ace729acb85682c8b3de9c33c
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Bastiaan Veelo 2013-11-16 01:02:22 +01:00 committed by The Qt Project
parent dd987a9ef0
commit 5e99b07a07
4 changed files with 27 additions and 51 deletions

View File

@ -9479,27 +9479,36 @@ void QWidget::updateGeometry()
*/
void QWidget::setWindowFlags(Qt::WindowFlags flags)
{
if (data->window_flags == flags)
Q_D(QWidget);
d->setWindowFlags(flags);
}
/*! \internal
Implemented in QWidgetPrivate so that QMdiSubWindowPrivate can reimplement it.
*/
void QWidgetPrivate::setWindowFlags(Qt::WindowFlags flags)
{
Q_Q(QWidget);
if (q->data->window_flags == flags)
return;
Q_D(QWidget);
if ((data->window_flags | flags) & Qt::Window) {
if ((q->data->window_flags | flags) & Qt::Window) {
// the old type was a window and/or the new type is a window
QPoint oldPos = pos();
bool visible = isVisible();
setParent(parentWidget(), flags);
QPoint oldPos = q->pos();
bool visible = q->isVisible();
q->setParent(q->parentWidget(), flags);
// if both types are windows or neither of them are, we restore
// the old position
if (!((data->window_flags ^ flags) & Qt::Window)
&& (visible || testAttribute(Qt::WA_Moved))) {
move(oldPos);
if (!((q->data->window_flags ^ flags) & Qt::Window)
&& (visible || q->testAttribute(Qt::WA_Moved))) {
q->move(oldPos);
}
// for backward-compatibility we change Qt::WA_QuitOnClose attribute value only when the window was recreated.
d->adjustQuitOnCloseAttribute();
adjustQuitOnCloseAttribute();
} else {
data->window_flags = flags;
q->data->window_flags = flags;
}
}

View File

@ -489,6 +489,7 @@ public:
void setWindowTitle_helper(const QString &cap);
void setWindowFilePath_helper(const QString &filePath);
void setWindowModified_helper();
virtual void setWindowFlags(Qt::WindowFlags windowFlags);
bool setMinimumSize_helper(int &minw, int &minh);
bool setMaximumSize_helper(int &maxw, int &maxh);

View File

@ -2057,13 +2057,13 @@ void QMdiSubWindowPrivate::restoreFocus()
/*!
\internal
### Please add QEvent::WindowFlagsChange event
*/
void QMdiSubWindowPrivate::setWindowFlags(Qt::WindowFlags windowFlags)
{
Q_Q(QMdiSubWindow);
if (!parent) {
q->setWindowFlags(windowFlags);
QWidgetPrivate::setWindowFlags(windowFlags);
return;
}
@ -2097,7 +2097,7 @@ void QMdiSubWindowPrivate::setWindowFlags(Qt::WindowFlags windowFlags)
delete sizeGrip;
#endif
q->setWindowFlags(windowFlags);
QWidgetPrivate::setWindowFlags(windowFlags);
updateGeometryConstraints();
updateActions();
QSize currentSize = q->size();

View File

@ -901,40 +901,12 @@ void tst_QMdiSubWindow::setWindowFlags()
QVERIFY(QTest::qWaitForWindowExposed(&workspace));
window->setWindowFlags(windowType | customFlags);
QEXPECT_FAIL("Qt::Widget", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::Window", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::Dialog", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::Sheet", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::Drawer", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::Popup", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::Tool", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::ToolTip", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::SplashScreen", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::Desktop", "QTBUG-27274", Continue);
QCOMPARE(window->windowType(), expectedWindowType);
if (!expectedCustomFlags) {
// We expect the same as 'customFlags'
if (!expectedCustomFlags) // We expect the same as 'customFlags'
QCOMPARE(window->windowFlags() & ~expectedWindowType, customFlags);
} else {
QEXPECT_FAIL("Qt::Widget", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::Window", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::Dialog", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::Sheet", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::Drawer", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::Popup", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::Tool", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::ToolTip", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::SplashScreen", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::Desktop", "QTBUG-27274", Continue);
QEXPECT_FAIL("Qt::SubWindow", "QTBUG-27274", Continue);
QEXPECT_FAIL("StandardAndFrameless", "QTBUG-27274", Continue);
QEXPECT_FAIL("StandardAndFramelessAndStaysOnTop", "QTBUG-27274", Continue);
QEXPECT_FAIL("Shade", "QTBUG-27274", Continue);
QEXPECT_FAIL("Context", "QTBUG-27274", Continue);
QEXPECT_FAIL("ShadeAndContext", "QTBUG-27274", Continue);
else
QCOMPARE(window->windowFlags() & ~expectedWindowType, expectedCustomFlags);
}
}
void tst_QMdiSubWindow::mouseDoubleClick()
@ -981,18 +953,12 @@ void tst_QMdiSubWindow::mouseDoubleClick()
sendMouseDoubleClick(window, mousePosition);
qApp->processEvents();
QVERIFY(!window->isShaded());
#ifndef Q_OS_MAC
QEXPECT_FAIL("", "QTBUG-27274", Continue);
#endif
QCOMPARE(window->geometry(), originalGeometry);
window->showMinimized();
QVERIFY(window->isMinimized());
sendMouseDoubleClick(window, mousePosition);
QVERIFY(!window->isMinimized());
#ifndef Q_OS_MAC
QEXPECT_FAIL("", "QTBUG-27274", Continue);
#endif
QCOMPARE(window->geometry(), originalGeometry);
}