diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-07-30 12:49:27 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2014-08-06 14:56:20 +0200 |
commit | 869a8f51b102566179c12474be0a40042c63aabb (patch) | |
tree | 8f1242dd2b908057e5a82f82c29b98125acca3bf /src/widgets/dialogs/qprogressdialog.cpp | |
parent | 18bb58a5a6f6669d6e55cc1e58b45a3437610185 (diff) |
QProgressDialog: Extract Method QProgressDialogPrivate::adoptChildWidget()
The same code was used in three methods. Collect it in one place.
Change-Id: I0e3bf14474590eb99e94d240aad8158fd8fbe033
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/widgets/dialogs/qprogressdialog.cpp')
-rw-r--r-- | src/widgets/dialogs/qprogressdialog.cpp | 50 |
1 files changed, 19 insertions, 31 deletions
diff --git a/src/widgets/dialogs/qprogressdialog.cpp b/src/widgets/dialogs/qprogressdialog.cpp index bcfdb03f2f..4a7ee41090 100644 --- a/src/widgets/dialogs/qprogressdialog.cpp +++ b/src/widgets/dialogs/qprogressdialog.cpp @@ -85,6 +85,7 @@ public: void layout(); void retranslateStrings(); void setCancelButtonText(const QString &cancelButtonText); + void adoptChildWidget(QWidget *c); void _q_disconnectOnClose(); QLabel *label; @@ -361,18 +362,7 @@ void QProgressDialog::setLabel(QLabel *label) } delete d->label; d->label = label; - if (label) { - if (label->parentWidget() == this) { - label->hide(); // until we resize - } else { - label->setParent(this, 0); - } - } - int w = qMax(isVisible() ? width() : 0, sizeHint().width()); - int h = qMax(isVisible() ? height() : 0, sizeHint().height()); - resize(w, h); - if (label) - label->show(); + d->adoptChildWidget(label); } @@ -424,11 +414,6 @@ void QProgressDialog::setCancelButton(QPushButton *cancelButton) delete d->cancel; d->cancel = cancelButton; if (cancelButton) { - if (cancelButton->parentWidget() == this) { - cancelButton->hide(); // until we resize - } else { - cancelButton->setParent(this, 0); - } connect(d->cancel, SIGNAL(clicked()), this, SIGNAL(canceled())); #ifndef QT_NO_SHORTCUT d->escapeShortcut = new QShortcut(Qt::Key_Escape, this, SIGNAL(canceled())); @@ -439,11 +424,7 @@ void QProgressDialog::setCancelButton(QPushButton *cancelButton) d->escapeShortcut = 0; #endif } - int w = qMax(isVisible() ? width() : 0, sizeHint().width()); - int h = qMax(isVisible() ? height() : 0, sizeHint().height()); - resize(w, h); - if (cancelButton) - cancelButton->show(); + d->adoptChildWidget(cancelButton); } /*! @@ -505,17 +486,24 @@ void QProgressDialog::setBar(QProgressBar *bar) } delete d->bar; d->bar = bar; - if (bar) { - if (bar->parentWidget() == this) - bar->hide(); // until we resize + d->adoptChildWidget(bar); +} + +void QProgressDialogPrivate::adoptChildWidget(QWidget *c) +{ + Q_Q(QProgressDialog); + + if (c) { + if (c->parentWidget() == q) + c->hide(); // until we resize else - bar->setParent(this, 0); + c->setParent(q, 0); } - int w = qMax(isVisible() ? width() : 0, sizeHint().width()); - int h = qMax(isVisible() ? height() : 0, sizeHint().height()); - resize(w, h); - if (bar) - bar->show(); + int w = qMax(q->isVisible() ? q->width() : 0, q->sizeHint().width()); + int h = qMax(q->isVisible() ? q->height() : 0, q->sizeHint().height()); + q->resize(w, h); + if (c) + c->show(); } |