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>
This commit is contained in:
Marc Mutz 2014-07-30 12:49:27 +02:00
parent 18bb58a5a6
commit 869a8f51b1

View File

@ -85,6 +85,7 @@ public:
void layout(); void layout();
void retranslateStrings(); void retranslateStrings();
void setCancelButtonText(const QString &cancelButtonText); void setCancelButtonText(const QString &cancelButtonText);
void adoptChildWidget(QWidget *c);
void _q_disconnectOnClose(); void _q_disconnectOnClose();
QLabel *label; QLabel *label;
@ -361,18 +362,7 @@ void QProgressDialog::setLabel(QLabel *label)
} }
delete d->label; delete d->label;
d->label = label; d->label = label;
if (label) { d->adoptChildWidget(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();
} }
@ -424,11 +414,6 @@ void QProgressDialog::setCancelButton(QPushButton *cancelButton)
delete d->cancel; delete d->cancel;
d->cancel = cancelButton; d->cancel = cancelButton;
if (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())); connect(d->cancel, SIGNAL(clicked()), this, SIGNAL(canceled()));
#ifndef QT_NO_SHORTCUT #ifndef QT_NO_SHORTCUT
d->escapeShortcut = new QShortcut(Qt::Key_Escape, this, SIGNAL(canceled())); d->escapeShortcut = new QShortcut(Qt::Key_Escape, this, SIGNAL(canceled()));
@ -439,11 +424,7 @@ void QProgressDialog::setCancelButton(QPushButton *cancelButton)
d->escapeShortcut = 0; d->escapeShortcut = 0;
#endif #endif
} }
int w = qMax(isVisible() ? width() : 0, sizeHint().width()); d->adoptChildWidget(cancelButton);
int h = qMax(isVisible() ? height() : 0, sizeHint().height());
resize(w, h);
if (cancelButton)
cancelButton->show();
} }
/*! /*!
@ -505,17 +486,24 @@ void QProgressDialog::setBar(QProgressBar *bar)
} }
delete d->bar; delete d->bar;
d->bar = bar; d->bar = bar;
if (bar) { d->adoptChildWidget(bar);
if (bar->parentWidget() == this) }
bar->hide(); // until we resize
void QProgressDialogPrivate::adoptChildWidget(QWidget *c)
{
Q_Q(QProgressDialog);
if (c) {
if (c->parentWidget() == q)
c->hide(); // until we resize
else else
bar->setParent(this, 0); c->setParent(q, 0);
} }
int w = qMax(isVisible() ? width() : 0, sizeHint().width()); int w = qMax(q->isVisible() ? q->width() : 0, q->sizeHint().width());
int h = qMax(isVisible() ? height() : 0, sizeHint().height()); int h = qMax(q->isVisible() ? q->height() : 0, q->sizeHint().height());
resize(w, h); q->resize(w, h);
if (bar) if (c)
bar->show(); c->show();
} }