Cocoa: Fix QFontDialog, QColorDialog auto-tests

The new Cocoa event dispatcher made apparent some deficiencies in the
way the dialog helpers were being hidden. In particular, we would not stop
a dialog helper's modal loop when closing the dialog, resulting in the
auto-tests hanging. Also, since the QApplication event loop is runnig with
[NSApp run] in the stack, the previous workarounds are no longer needed.

Task-number: QTBUG-24321
Change-Id: Ifba713c286638d78a699c319a15683d09714f06f
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
This commit is contained in:
Gabriel de Dietrich 2013-08-26 19:29:33 +02:00 committed by The Qt Project
parent e4b2a0b4ba
commit df7944e7d7
7 changed files with 42 additions and 25 deletions

View File

@ -59,6 +59,8 @@ public:
void setCurrentColor(const QColor&); void setCurrentColor(const QColor&);
QColor currentColor() const; QColor currentColor() const;
bool event(QEvent *);
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -161,6 +161,10 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSColorPanelDelegate);
- (void)closePanel - (void)closePanel
{ {
if (mDialogIsExecuting) {
mDialogIsExecuting = false;
[NSApp stopModal];
}
[mColorPanel close]; [mColorPanel close];
} }
@ -488,6 +492,22 @@ QColor QCocoaColorDialogHelper::currentColor() const
return sharedColorPanel()->currentColor(); return sharedColorPanel()->currentColor();
} }
bool QCocoaColorDialogHelper::event(QEvent *e)
{
if (e->type() == QEvent::KeyPress) {
QKeyEvent *ke = static_cast<QKeyEvent *>(e);
if (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return) {
emit accept();
return true;
} else if (ke->key() == Qt::Key_Escape) {
emit reject();
return true;
}
}
return false;
}
QT_END_NAMESPACE QT_END_NAMESPACE
#endif // QT_NO_COLORDIALOG #endif // QT_NO_COLORDIALOG

View File

@ -203,6 +203,10 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSFontPanelDelegate);
- (void)closePanel - (void)closePanel
{ {
if (mDialogIsExecuting) {
mDialogIsExecuting = false;
[NSApp stopModal];
}
[mFontPanel close]; [mFontPanel close];
} }

View File

@ -2166,6 +2166,8 @@ void QColorDialog::keyPressEvent(QKeyEvent *e)
} }
e->accept(); e->accept();
return; return;
} else if (d->nativeDialogInUse && d->platformColorDialogHelper()->event(e)) {
return;
} }
QDialog::keyPressEvent(e); QDialog::keyPressEvent(e);
} }

View File

@ -983,14 +983,9 @@ void QFontDialog::setVisible(bool visible)
Q_D(QFontDialog); Q_D(QFontDialog);
if (d->canBeNativeDialog()) if (d->canBeNativeDialog())
d->setNativeDialogVisible(visible); d->setNativeDialogVisible(visible);
if (d->nativeDialogInUse) { // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below
// Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below // updates the state correctly, but skips showing the non-native version:
// updates the state correctly, but skips showing the non-native version: setAttribute(Qt::WA_DontShowOnScreen, d->nativeDialogInUse);
setAttribute(Qt::WA_DontShowOnScreen, true);
} else {
d->nativeDialogInUse = false;
setAttribute(Qt::WA_DontShowOnScreen, false);
}
QDialog::setVisible(visible); QDialog::setVisible(visible);
} }

View File

@ -144,13 +144,10 @@ void tst_QColorDialog::postKeyReturn() {
void tst_QColorDialog::testGetRgba() void tst_QColorDialog::testGetRgba()
{ {
#ifdef Q_OS_MAC QColorDialog cd;
QEXPECT_FAIL("", "Sending QTest::keyClick to OSX color dialog helper fails, see QTBUG-24320", Continue); cd.show();
#endif QTimer::singleShot(0, this, SLOT(postKeyReturn()));
bool ok = false; QTRY_COMPARE(cd.result(), int(QDialog::Accepted));
QTimer::singleShot(500, this, SLOT(postKeyReturn()));
QColorDialog::getRgba(0xffffffff, &ok);
QVERIFY(ok);
} }
void tst_QColorDialog::defaultOkButton() void tst_QColorDialog::defaultOkButton()

View File

@ -64,7 +64,7 @@ public:
public slots: public slots:
void postKeyReturn(); void postKeyReturn();
void testGetFont(); void testDefaultOkButton();
void testSetFont(); void testSetFont();
public slots: public slots:
@ -116,15 +116,12 @@ void tst_QFontDialog::postKeyReturn() {
} }
} }
void tst_QFontDialog::testGetFont() void tst_QFontDialog::testDefaultOkButton()
{ {
#ifdef Q_OS_MAC QFontDialog fd;
QEXPECT_FAIL("", "Sending QTest::keyClick to OSX font dialog helper fails, see QTBUG-24321", Continue); fd.show();
#endif QTimer::singleShot(0, this, SLOT(postKeyReturn()));
bool ok = false; QTRY_COMPARE(fd.result(), int(QDialog::Accepted));
QTimer::singleShot(2000, this, SLOT(postKeyReturn()));
QFontDialog::getFont(&ok);
QVERIFY(ok);
} }
void tst_QFontDialog::runSlotWithFailsafeTimer(const char *member) void tst_QFontDialog::runSlotWithFailsafeTimer(const char *member)
@ -144,7 +141,7 @@ void tst_QFontDialog::runSlotWithFailsafeTimer(const char *member)
void tst_QFontDialog::defaultOkButton() void tst_QFontDialog::defaultOkButton()
{ {
runSlotWithFailsafeTimer(SLOT(testGetFont())); runSlotWithFailsafeTimer(SLOT(testDefaultOkButton()));
} }
void tst_QFontDialog::testSetFont() void tst_QFontDialog::testSetFont()