summaryrefslogtreecommitdiffstats
path: root/src/widgets/dialogs
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-02-10 21:10:21 +0100
committerLiang Qi <liang.qi@qt.io>2017-02-10 22:35:04 +0100
commit364b161122b567e3a6f7343d438fb540b9fb7e5c (patch)
tree3d49953be9a58295a8c956cf5fdb00f581020605 /src/widgets/dialogs
parente58401a75b29beb38d37a40072106d5ef7cb0336 (diff)
parent8a410f60ae39b06555d807581caf7cb8bfab4fac (diff)
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts: src/widgets/widgets/qmainwindowlayout_p.h Change-Id: Id406a67606b885052ed405b0fbc8eea7d9d03224
Diffstat (limited to 'src/widgets/dialogs')
-rw-r--r--src/widgets/dialogs/qdialog.cpp2
-rw-r--r--src/widgets/dialogs/qdialog_p.h18
-rw-r--r--src/widgets/dialogs/qinputdialog.cpp106
3 files changed, 60 insertions, 66 deletions
diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp
index e8883df527..e5715ecd57 100644
--- a/src/widgets/dialogs/qdialog.cpp
+++ b/src/widgets/dialogs/qdialog.cpp
@@ -557,8 +557,8 @@ int QDialog::exec()
void QDialog::done(int r)
{
Q_D(QDialog);
- hide();
setResult(r);
+ hide();
d->close_helper(QWidgetPrivate::CloseNoEvent);
d->resetModalitySetByOpen();
diff --git a/src/widgets/dialogs/qdialog_p.h b/src/widgets/dialogs/qdialog_p.h
index 1c7c5f3c2a..ae9e3bcc93 100644
--- a/src/widgets/dialogs/qdialog_p.h
+++ b/src/widgets/dialogs/qdialog_p.h
@@ -119,6 +119,24 @@ private:
mutable bool m_platformHelperCreated;
};
+template <typename T>
+class QAutoPointer {
+ QPointer<T> o;
+ struct internal { void func() {} };
+ typedef void (internal::*RestrictedBool)();
+public:
+ explicit QAutoPointer(T *t) Q_DECL_NOTHROW : o(t) {}
+ ~QAutoPointer() { delete o; }
+
+ T *operator->() const Q_DECL_NOTHROW { return get(); }
+ T *get() const Q_DECL_NOTHROW { return o; }
+ T &operator*() const { return *get(); }
+ operator RestrictedBool() const Q_DECL_NOTHROW { return o ? &internal::func : Q_NULLPTR; }
+ bool operator!() const Q_DECL_NOTHROW { return !o; }
+private:
+ Q_DISABLE_COPY(QAutoPointer);
+};
+
QT_END_NAMESPACE
#endif // QDIALOG_P_H
diff --git a/src/widgets/dialogs/qinputdialog.cpp b/src/widgets/dialogs/qinputdialog.cpp
index d09f77ea35..4ca3923d8d 100644
--- a/src/widgets/dialogs/qinputdialog.cpp
+++ b/src/widgets/dialogs/qinputdialog.cpp
@@ -1194,10 +1194,6 @@ void QInputDialog::done(int result)
\snippet dialogs/standarddialogs/dialog.cpp 3
- \warning Do not delete \a parent during the execution of the dialog. If you
- want to do this, you should create the dialog yourself using one of the
- QInputDialog constructors.
-
\sa getInt(), getDouble(), getItem(), getMultiLineText()
*/
@@ -1205,18 +1201,18 @@ QString QInputDialog::getText(QWidget *parent, const QString &title, const QStri
QLineEdit::EchoMode mode, const QString &text, bool *ok,
Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
{
- QInputDialog dialog(parent, flags);
- dialog.setWindowTitle(title);
- dialog.setLabelText(label);
- dialog.setTextValue(text);
- dialog.setTextEchoMode(mode);
- dialog.setInputMethodHints(inputMethodHints);
+ QAutoPointer<QInputDialog> dialog(new QInputDialog(parent, flags));
+ dialog->setWindowTitle(title);
+ dialog->setLabelText(label);
+ dialog->setTextValue(text);
+ dialog->setTextEchoMode(mode);
+ dialog->setInputMethodHints(inputMethodHints);
- int ret = dialog.exec();
+ const int ret = dialog->exec();
if (ok)
*ok = !!ret;
if (ret) {
- return dialog.textValue();
+ return dialog->textValue();
} else {
return QString();
}
@@ -1246,10 +1242,6 @@ QString QInputDialog::getText(QWidget *parent, const QString &title, const QStri
\snippet dialogs/standarddialogs/dialog.cpp 4
- \warning Do not delete \a parent during the execution of the dialog. If you
- want to do this, you should create the dialog yourself using one of the
- QInputDialog constructors.
-
\sa getInt(), getDouble(), getItem(), getText()
*/
@@ -1257,18 +1249,18 @@ QString QInputDialog::getMultiLineText(QWidget *parent, const QString &title, co
const QString &text, bool *ok, Qt::WindowFlags flags,
Qt::InputMethodHints inputMethodHints)
{
- QInputDialog dialog(parent, flags);
- dialog.setOptions(QInputDialog::UsePlainTextEditForTextInput);
- dialog.setWindowTitle(title);
- dialog.setLabelText(label);
- dialog.setTextValue(text);
- dialog.setInputMethodHints(inputMethodHints);
+ QAutoPointer<QInputDialog> dialog(new QInputDialog(parent, flags));
+ dialog->setOptions(QInputDialog::UsePlainTextEditForTextInput);
+ dialog->setWindowTitle(title);
+ dialog->setLabelText(label);
+ dialog->setTextValue(text);
+ dialog->setInputMethodHints(inputMethodHints);
- int ret = dialog.exec();
+ const int ret = dialog->exec();
if (ok)
*ok = !!ret;
if (ret) {
- return dialog.textValue();
+ return dialog->textValue();
} else {
return QString();
}
@@ -1298,28 +1290,24 @@ QString QInputDialog::getMultiLineText(QWidget *parent, const QString &title, co
\snippet dialogs/standarddialogs/dialog.cpp 0
- \warning Do not delete \a parent during the execution of the dialog. If you
- want to do this, you should create the dialog yourself using one of the
- QInputDialog constructors.
-
\sa getText(), getDouble(), getItem(), getMultiLineText()
*/
int QInputDialog::getInt(QWidget *parent, const QString &title, const QString &label, int value,
int min, int max, int step, bool *ok, Qt::WindowFlags flags)
{
- QInputDialog dialog(parent, flags);
- dialog.setWindowTitle(title);
- dialog.setLabelText(label);
- dialog.setIntRange(min, max);
- dialog.setIntValue(value);
- dialog.setIntStep(step);
+ QAutoPointer<QInputDialog> dialog(new QInputDialog(parent, flags));
+ dialog->setWindowTitle(title);
+ dialog->setLabelText(label);
+ dialog->setIntRange(min, max);
+ dialog->setIntValue(value);
+ dialog->setIntStep(step);
- int ret = dialog.exec();
+ const int ret = dialog->exec();
if (ok)
*ok = !!ret;
if (ret) {
- return dialog.intValue();
+ return dialog->intValue();
} else {
return value;
}
@@ -1350,10 +1338,6 @@ int QInputDialog::getInt(QWidget *parent, const QString &title, const QString &l
\snippet dialogs/standarddialogs/dialog.cpp 0
- \warning Do not delete \a parent during the execution of the dialog. If you
- want to do this, you should create the dialog yourself using one of the
- QInputDialog constructors.
-
\sa getText(), getDouble(), getItem(), getMultiLineText()
*/
@@ -1379,10 +1363,6 @@ int QInputDialog::getInt(QWidget *parent, const QString &title, const QString &l
\snippet dialogs/standarddialogs/dialog.cpp 1
- \warning Do not delete \a parent during the execution of the dialog. If you
- want to do this, you should create the dialog yourself using one of the
- QInputDialog constructors.
-
\sa getText(), getInt(), getItem(), getMultiLineText()
*/
@@ -1390,18 +1370,18 @@ double QInputDialog::getDouble(QWidget *parent, const QString &title, const QStr
double value, double min, double max, int decimals, bool *ok,
Qt::WindowFlags flags)
{
- QInputDialog dialog(parent, flags);
- dialog.setWindowTitle(title);
- dialog.setLabelText(label);
- dialog.setDoubleDecimals(decimals);
- dialog.setDoubleRange(min, max);
- dialog.setDoubleValue(value);
+ QAutoPointer<QInputDialog> dialog(new QInputDialog(parent, flags));
+ dialog->setWindowTitle(title);
+ dialog->setLabelText(label);
+ dialog->setDoubleDecimals(decimals);
+ dialog->setDoubleRange(min, max);
+ dialog->setDoubleValue(value);
- int ret = dialog.exec();
+ const int ret = dialog->exec();
if (ok)
*ok = !!ret;
if (ret) {
- return dialog.doubleValue();
+ return dialog->doubleValue();
} else {
return value;
}
@@ -1433,10 +1413,6 @@ double QInputDialog::getDouble(QWidget *parent, const QString &title, const QStr
\snippet dialogs/standarddialogs/dialog.cpp 2
- \warning Do not delete \a parent during the execution of the dialog. If you
- want to do this, you should create the dialog yourself using one of the
- QInputDialog constructors.
-
\sa getText(), getInt(), getDouble(), getMultiLineText()
*/
@@ -1446,19 +1422,19 @@ QString QInputDialog::getItem(QWidget *parent, const QString &title, const QStri
{
QString text(items.value(current));
- QInputDialog dialog(parent, flags);
- dialog.setWindowTitle(title);
- dialog.setLabelText(label);
- dialog.setComboBoxItems(items);
- dialog.setTextValue(text);
- dialog.setComboBoxEditable(editable);
- dialog.setInputMethodHints(inputMethodHints);
+ QAutoPointer<QInputDialog> dialog(new QInputDialog(parent, flags));
+ dialog->setWindowTitle(title);
+ dialog->setLabelText(label);
+ dialog->setComboBoxItems(items);
+ dialog->setTextValue(text);
+ dialog->setComboBoxEditable(editable);
+ dialog->setInputMethodHints(inputMethodHints);
- int ret = dialog.exec();
+ const int ret = dialog->exec();
if (ok)
*ok = !!ret;
if (ret) {
- return dialog.textValue();
+ return dialog->textValue();
} else {
return text;
}