Micro-optimize QProgressDialogPrivate::ensureSizeIsAtLeastSizeHint()

QWidget::isVisible() is an inline call, but sizeHint() is a virtual function.
Use QSize operations to call each one only once.

Also reduces the number of q-> qualifications needed.

It must be noted that this change is not entirely behavior-preserving:
If sizeHint() returns a negative component, and the dialog is not
visible, resize() will be called with that negative component now,
instead of zero as was the case previously.

I believe this is not a problem, because the way sizeHint() is currently
implemented, the width cannot be less than 200 and for the height to be
negative, the sum of label, bar and button size hint height would need
to be negative, which is next to impossible.

Change-Id: Ie8ba110e193532921eb4732a0393a377e38d7f7e
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
Marc Mutz 2014-07-30 13:07:31 +02:00
parent f74566e08b
commit e3e2e68774

View File

@ -505,9 +505,10 @@ void QProgressDialogPrivate::ensureSizeIsAtLeastSizeHint()
{
Q_Q(QProgressDialog);
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);
QSize size = q->sizeHint();
if (q->isVisible())
size = size.expandedTo(q->size());
q->resize(size);
}