Widgets: add QWidgetPrivate::deepestFocusProxy()

Factor out searching for the deepest focus proxy
in to a private function. Other than being called
from QWidget::setFocus(), this function will also be
used in subsequent patches.

Change-Id: I4450a42e362eccb64f8a88c7ea83b415101973b9
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
This commit is contained in:
Richard Moe Gustavsen 2017-09-13 16:05:14 +02:00
parent 9467ebcf15
commit 1fe27f79f7
2 changed files with 25 additions and 3 deletions

View File

@ -6523,9 +6523,9 @@ void QWidget::setFocus(Qt::FocusReason reason)
if (!isEnabled())
return;
QWidget *f = this;
while (f->d_func()->extra && f->d_func()->extra->focus_proxy)
f = f->d_func()->extra->focus_proxy;
QWidget *f = d_func()->deepestFocusProxy();
if (!f)
f = this;
if (QApplication::focusWidget() == f
#if 0 // Used to be included in Qt4 for Q_WS_WIN
@ -6622,6 +6622,27 @@ void QWidget::setFocus(Qt::FocusReason reason)
}
}
/*!\internal
* A focus proxy can have its own focus proxy, which can have its own
* proxy, and so on. This helper function returns the widget that sits
* at the bottom of the proxy chain, and therefore the one that should
* normally get focus if this widget receives a focus request.
*/
QWidget *QWidgetPrivate::deepestFocusProxy() const
{
Q_Q(const QWidget);
QWidget *focusProxy = q->focusProxy();
if (!focusProxy)
return nullptr;
while (QWidget *nextFocusProxy = focusProxy->focusProxy())
focusProxy = nextFocusProxy;
return focusProxy;
}
void QWidgetPrivate::setFocus_sys()
{
Q_Q(QWidget);

View File

@ -369,6 +369,7 @@ public:
void lower_sys();
void stackUnder_sys(QWidget *);
QWidget *deepestFocusProxy() const;
void setFocus_sys();
void updateFocusChild();