From f657dda888498deac6c6f6aa36ed23ea455e0d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Tue, 30 May 2017 12:40:11 +0200 Subject: [PATCH] QtWidgets: Change QTLWExtra::window from QWindow to QWidgetWindow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Revert commit a1d4e4c9: We’re now using QWidgetWindow API from QWidget code. Add QWidgetPrivate::windowHandle() which returns a QWidgetWindow pointer. Use this function to remove casts where QWidgetWindow API is used. Change-Id: Ie66a69b5c0461f297996118dc907e1d7b3d78df5 Reviewed-by: Friedemann Kleint Reviewed-by: Tor Arne Vestbø --- src/widgets/kernel/qwidget.cpp | 15 +++++---------- src/widgets/kernel/qwidget_p.h | 11 ++++++++++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index b9aff2a58b..95e1a247bb 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1415,7 +1415,7 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO if (!q->testAttribute(Qt::WA_NativeWindow) && !q->isWindow()) return; // we only care about real toplevels - QWindow *win = topData()->window; + QWidgetWindow *win = topData()->window; // topData() ensures the extra is created but does not ensure 'window' is non-null // in case the extra was already valid. if (!win) { @@ -1516,8 +1516,7 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO q->setAttribute(Qt::WA_OutsideWSRange, true); } else if (q->isVisible()) { // If widget is already shown, set window visible, too - QWidgetWindow *widgetWindow = qobject_cast(win); - widgetWindow->setNativeWindowVisibility(true); + win->setNativeWindowVisibility(true); } } @@ -2640,11 +2639,7 @@ WId QWidget::effectiveWinId() const QWindow *QWidget::windowHandle() const { Q_D(const QWidget); - QTLWExtra *extra = d->maybeTopData(); - if (extra) - return extra->window; - - return 0; + return d->windowHandle(); } #ifndef QT_NO_STYLE_STYLESHEET @@ -7955,7 +7950,7 @@ void QWidgetPrivate::show_sys() { Q_Q(QWidget); - QWidgetWindow *window = qobject_cast(q->windowHandle()); + QWidgetWindow *window = windowHandle(); if (q->testAttribute(Qt::WA_DontShowOnScreen)) { invalidateBuffer(q->rect()); @@ -8094,7 +8089,7 @@ void QWidgetPrivate::hide_sys() { Q_Q(QWidget); - QWidgetWindow *window = qobject_cast(q->windowHandle()); + QWidgetWindow *window = windowHandle(); if (q->testAttribute(Qt::WA_DontShowOnScreen)) { q->setAttribute(Qt::WA_Mapped, false); diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index 2c397aec88..b830895788 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -76,6 +76,7 @@ QT_BEGIN_NAMESPACE // Extra QWidget data // - to minimize memory usage for members that are seldom used. // - top-level widgets have extra extra data to reduce cost further +class QWidgetWindow; class QPaintEngine; class QPixmap; class QWidgetBackingStore; @@ -160,7 +161,7 @@ struct QTLWExtra { QWidgetBackingStoreTracker backingStoreTracker; QBackingStore *backingStore; QPainter *sharedPainter; - QWindow *window; + QWidgetWindow *window; QOpenGLContext *shareContext; // Implicit pointers (shared_null). @@ -338,6 +339,7 @@ public: QPainter *sharedPainter() const; void setSharedPainter(QPainter *painter); QWidgetBackingStore *maybeBackingStore() const; + QWidgetWindow *windowHandle() const; void init(QWidget *desktopWidget, Qt::WindowFlags f); void create_sys(WId window, bool initializeWindow, bool destroyOldWindow); void createRecursively(); @@ -987,6 +989,13 @@ inline QWidgetBackingStore *QWidgetPrivate::maybeBackingStore() const return x ? x->backingStoreTracker.data() : 0; } +inline QWidgetWindow *QWidgetPrivate::windowHandle() const +{ + if (QTLWExtra *x = maybeTopData()) + return x->window; + return nullptr; +} + QT_END_NAMESPACE #endif // QWIDGET_P_H