qpa: Remove QPlatformDialogHelper::deleteNativeDialog()

This function isn't really needed. The QDialogPrivate destructor deletes
the platform helper, so the QDialog destructor does not need to do it.
Subclasses of QPlatformDialogHelper are now responsible for deleting any
native resources they create.

The one place in QFileDialog that needs to recreate the native dialog
can simply recreate the helper. QDialogPrivate::deleteNativeDialog() now
becomes QDialogPrivate::deletePlatformHelper(), which resets all state
to allow the platform helper to be recreated.

Change-Id: I58adfe8801e02e63b3cb4a9a3a0b8cb5b3c7b161
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
Bradley T. Hughes 2012-05-09 13:55:25 +02:00 committed by Qt by Nokia
parent d223b30c42
commit 5f43422ddf
12 changed files with 31 additions and 51 deletions

View File

@ -91,9 +91,6 @@ public:
virtual QVariant styleHint(StyleHint hint) const;
virtual void exec() = 0;
virtual void deleteNativeDialog() = 0;
virtual bool show(Qt::WindowFlags windowFlags,
Qt::WindowModality windowModality,
QWindow *parent) = 0;

View File

@ -54,7 +54,6 @@ public:
virtual ~QCocoaColorDialogHelper();
void exec();
void deleteNativeDialog();
bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent);
void hide();

View File

@ -343,7 +343,12 @@ QCocoaColorDialogHelper::QCocoaColorDialogHelper() :
}
QCocoaColorDialogHelper::~QCocoaColorDialogHelper()
{ }
{
if (!mDelegate)
return;
[reinterpret_cast<QT_MANGLE_NAMESPACE(QNSColorPanelDelegate) *>(mDelegate) release];
mDelegate = 0;
}
void QCocoaColorDialogHelper::exec()
{
@ -358,14 +363,6 @@ void QCocoaColorDialogHelper::exec()
emit reject();
}
void QCocoaColorDialogHelper::deleteNativeDialog()
{
if (!mDelegate)
return;
[reinterpret_cast<QT_MANGLE_NAMESPACE(QNSColorPanelDelegate) *>(mDelegate) release];
mDelegate = 0;
}
bool QCocoaColorDialogHelper::show(Qt::WindowFlags, Qt::WindowModality windowModality, QWindow *parent)
{
if (windowModality == Qt::WindowModal) {

View File

@ -60,7 +60,6 @@ public:
bool defaultNameFilterDisables() const;
void deleteNativeDialog();
bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent);
void hide();
void setDirectory(const QString &directory);

View File

@ -511,7 +511,10 @@ QCocoaFileDialogHelper::QCocoaFileDialogHelper()
QCocoaFileDialogHelper::~QCocoaFileDialogHelper()
{
if (!mDelegate)
return;
[reinterpret_cast<QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *>(mDelegate) release];
mDelegate = 0;
}
void QCocoaFileDialogHelper::QNSOpenSavePanelDelegate_selectionChanged(const QString &newPath)
@ -602,12 +605,6 @@ QString QCocoaFileDialogHelper::selectedNameFilter() const
return index != -1 ? options()->nameFilters().at(index) : QString();
}
void QCocoaFileDialogHelper::deleteNativeDialog()
{
[reinterpret_cast<QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *>(mDelegate) release];
mDelegate = 0;
}
void QCocoaFileDialogHelper::hide()
{
hideCocoaFilePanel();

View File

@ -54,12 +54,10 @@ class QCocoaFontDialogHelper : public QPlatformFontDialogHelper
{
public:
QCocoaFontDialogHelper();
virtual ~QCocoaFontDialogHelper();
~QCocoaFontDialogHelper();
void exec();
void deleteNativeDialog();
bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent);
void hide();

View File

@ -362,7 +362,12 @@ QCocoaFontDialogHelper::QCocoaFontDialogHelper() :
}
QCocoaFontDialogHelper::~QCocoaFontDialogHelper()
{ }
{
if (!mDelegate)
return;
[reinterpret_cast<QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) *>(mDelegate) release];
mDelegate = 0;
}
void QCocoaFontDialogHelper::exec()
{
@ -377,14 +382,6 @@ void QCocoaFontDialogHelper::exec()
emit reject();
}
void QCocoaFontDialogHelper::deleteNativeDialog()
{
if (!mDelegate)
return;
[reinterpret_cast<QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) *>(mDelegate) release];
mDelegate = 0;
}
bool QCocoaFontDialogHelper::show(Qt::WindowFlags, Qt::WindowModality windowModality, QWindow *parent)
{
if (windowModality == Qt::WindowModal) {

View File

@ -425,6 +425,12 @@ QWindowsDialogHelperBase<BaseClass>::QWindowsDialogHelperBase() :
{
}
template <class BaseClass>
QWindowsDialogHelperBase<BaseClass>::~QWindowsDialogHelperBase()
{
delete m_nativeDialog;
}
template <class BaseClass>
QWindowsNativeDialogBase *QWindowsDialogHelperBase<BaseClass>::nativeDialog() const
{
@ -444,15 +450,6 @@ QWindowsNativeDialogBase *QWindowsDialogHelperBase<BaseClass>::ensureNativeDialo
return m_nativeDialog;
}
template <class BaseClass>
void QWindowsDialogHelperBase<BaseClass>::deleteNativeDialog()
{
if (QWindowsContext::verboseDialogs)
qDebug("%s" , __FUNCTION__);
delete m_nativeDialog;
m_nativeDialog = 0;
}
/*!
\class QWindowsDialogThread
\brief Run a non-modal native dialog in a separate thread.

View File

@ -67,7 +67,6 @@ class QWindowsDialogHelperBase : public BaseClass
public:
virtual void exec();
virtual void deleteNativeDialog();
virtual bool show(Qt::WindowFlags windowFlags,
Qt::WindowModality windowModality,
QWindow *parent);
@ -78,6 +77,7 @@ public:
protected:
QWindowsDialogHelperBase();
~QWindowsDialogHelperBase();
QWindowsNativeDialogBase *nativeDialog() const;
private:

View File

@ -123,12 +123,12 @@ QVariant QDialogPrivate::styleHint(QPlatformDialogHelper::StyleHint hint) const
return QPlatformDialogHelper::defaultStyleHint(hint);
}
void QDialogPrivate::deleteNativeDialog()
void QDialogPrivate::deletePlatformHelper()
{
if (QPlatformDialogHelper *helper = platformHelper()) {
helper->deleteNativeDialog();
nativeDialogInUse = false;
}
delete m_platformHelper;
m_platformHelper = 0;
m_platformHelperCreated = false;
nativeDialogInUse = false;
}
/*!
@ -335,7 +335,6 @@ QDialog::~QDialog()
} QT_CATCH(...) {
// we're in the destructor - just swallow the exception
}
d->deleteNativeDialog();
}
/*!

View File

@ -83,7 +83,7 @@ public:
QWindow *parentWindow() const;
bool setNativeDialogVisible(bool visible);
QVariant styleHint(QPlatformDialogHelper::StyleHint hint) const;
void deleteNativeDialog();
void deletePlatformHelper();
QPointer<QPushButton> mainDef;
Qt::Orientation orientation;

View File

@ -1371,7 +1371,7 @@ void QFileDialog::setAcceptMode(QFileDialog::AcceptMode mode)
}
d->retranslateWindowTitle();
// we need to recreate the native dialog when changing the AcceptMode
d->deleteNativeDialog();
d->deletePlatformHelper();
// clear WA_DontShowOnScreen so that d->canBeNativeDialog() doesn't return false incorrectly
setAttribute(Qt::WA_DontShowOnScreen, false);
}