diff options
author | Axel Spoerl <axel.spoerl@qt.io> | 2024-04-24 19:24:40 +0200 |
---|---|---|
committer | Axel Spoerl <axel.spoerl@qt.io> | 2024-04-26 17:26:07 +0000 |
commit | 913442a75a269048bea7968aa2708888e10611c4 (patch) | |
tree | 7e701125ddc52dcf11606318eba89bc61df9e43d | |
parent | 48a2ee1e9dc82bffdd533525fb4304a49ebf68ef (diff) |
Widgets focus abstraction: Skip isFocusChainConsistent w/o logging cat
QWidgetPrivate::isFocusChainConsistent() iterates over
QApplication::allWidgets() to identify and log inconsistencies.
In applications with many widgets, this has a major performance
impact.
Disable the check and return true, unless the logging category
qt.widgets.focus is enabled.
Adapt tst_QWidget::focusAbstraction() to enable the logging category.
This amends 58d5d4b7c2faaeaa2c2ccdabb3da6d37f9db880a.
Fixes: QTBUG-124666
Change-Id: Ia487b381ab45b052638b189bf56acaf4353b1a37
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 7 | ||||
-rw-r--r-- | tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 1 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index b302b32b88..e8342a4788 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -13614,7 +13614,8 @@ bool QWidgetPrivate::isInFocusChain() const when the focus chain has been initialized. A newly constructed widget is considered to have a consistent focus chain, while not being part of a focus chain. - This method returns \c true early, if a widget is pointing to itself. + The method always returns \c true, when the logging category "qt.widgets.focus" is disabled. + When it is enabled, the method returns \c true early, if a widget is pointing to itself. It returns \c false, if one of the following is detected: \list \li nullptr found in a previous/next pointer. @@ -13631,6 +13632,10 @@ bool QWidgetPrivate::isInFocusChain() const bool QWidgetPrivate::isFocusChainConsistent() const { Q_Q(const QWidget); + const bool skip = !QLoggingCategory("qt.widgets.focus").isDebugEnabled(); + if (skip) + return true; + if (!isInFocusChain()) return true; diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 0dde95cada..9b66002a2f 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -2017,6 +2017,7 @@ static QList<QWidget *> getFocusChain(QWidget *start, bool bForward) void tst_QWidget::focusAbstraction() { + QLoggingCategory::setFilterRules("qt.widgets.focus=true"); QWidget *widget1 = new QWidget; widget1->setObjectName("Widget 1"); QWidget *widget2 = new QWidget; |