QWidget: replace manual memory management with unique_ptr [6/N]: extra
Had to port a lot of caching temporaries, too. Decided to leave them as crefs to unique_ptr to catch any mischief users may be doing with the raw pointer instead (like deleting it). Also fixed a use of 0 as nullptr (by standardizing on pointer-to-bool conversion, as is done everywhere else in qwidget.cpp), and made one impregnable if condition readable. Change-Id: Ifdc240bf352c52de0bc3c186fa7a5f4cb2882dd0 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
9e86fdb6e8
commit
f556505f63
@ -404,7 +404,7 @@ void QGraphicsProxyWidgetPrivate::_q_removeWidgetSlot()
|
|||||||
{
|
{
|
||||||
Q_Q(QGraphicsProxyWidget);
|
Q_Q(QGraphicsProxyWidget);
|
||||||
if (!widget.isNull()) {
|
if (!widget.isNull()) {
|
||||||
if (QWExtra *extra = widget->d_func()->extra)
|
if (const auto &extra = widget->d_func()->extra)
|
||||||
extra->proxyWidget = 0;
|
extra->proxyWidget = 0;
|
||||||
}
|
}
|
||||||
widget = 0;
|
widget = 0;
|
||||||
@ -477,8 +477,8 @@ void QGraphicsProxyWidgetPrivate::updateProxyInputMethodAcceptanceFromWidget()
|
|||||||
*/
|
*/
|
||||||
void QGraphicsProxyWidgetPrivate::embedSubWindow(QWidget *subWin)
|
void QGraphicsProxyWidgetPrivate::embedSubWindow(QWidget *subWin)
|
||||||
{
|
{
|
||||||
QWExtra *extra;
|
const auto &extra = subWin->d_func()->extra;
|
||||||
if (!((extra = subWin->d_func()->extra) && extra->proxyWidget)) {
|
if (!extra || !extra->proxyWidget) {
|
||||||
QGraphicsProxyWidget *subProxy = new QGraphicsProxyWidget(q_func(), subWin->windowFlags());
|
QGraphicsProxyWidget *subProxy = new QGraphicsProxyWidget(q_func(), subWin->windowFlags());
|
||||||
subProxy->d_func()->setWidget_helper(subWin, false);
|
subProxy->d_func()->setWidget_helper(subWin, false);
|
||||||
}
|
}
|
||||||
@ -631,7 +631,7 @@ void QGraphicsProxyWidgetPrivate::setWidget_helper(QWidget *newWidget, bool auto
|
|||||||
if (!newWidget)
|
if (!newWidget)
|
||||||
return;
|
return;
|
||||||
if (!newWidget->isWindow()) {
|
if (!newWidget->isWindow()) {
|
||||||
QWExtra *extra = newWidget->parentWidget()->d_func()->extra;
|
const auto &extra = newWidget->parentWidget()->d_func()->extra;
|
||||||
if (!extra || !extra->proxyWidget) {
|
if (!extra || !extra->proxyWidget) {
|
||||||
qWarning("QGraphicsProxyWidget::setWidget: cannot embed widget %p "
|
qWarning("QGraphicsProxyWidget::setWidget: cannot embed widget %p "
|
||||||
"which is not a toplevel widget, and is not a child of an embedded widget", newWidget);
|
"which is not a toplevel widget, and is not a child of an embedded widget", newWidget);
|
||||||
@ -641,10 +641,10 @@ void QGraphicsProxyWidgetPrivate::setWidget_helper(QWidget *newWidget, bool auto
|
|||||||
|
|
||||||
// Register this proxy within the widget's private.
|
// Register this proxy within the widget's private.
|
||||||
// ### This is a bit backdoorish
|
// ### This is a bit backdoorish
|
||||||
QWExtra *extra = newWidget->d_func()->extra;
|
QWExtra *extra = newWidget->d_func()->extra.get();
|
||||||
if (!extra) {
|
if (!extra) {
|
||||||
newWidget->d_func()->createExtra();
|
newWidget->d_func()->createExtra();
|
||||||
extra = newWidget->d_func()->extra;
|
extra = newWidget->d_func()->extra.get();
|
||||||
}
|
}
|
||||||
QGraphicsProxyWidget **proxyWidget = &extra->proxyWidget;
|
QGraphicsProxyWidget **proxyWidget = &extra->proxyWidget;
|
||||||
if (*proxyWidget) {
|
if (*proxyWidget) {
|
||||||
|
@ -3388,7 +3388,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
|
|||||||
#if QT_CONFIG(graphicsview)
|
#if QT_CONFIG(graphicsview)
|
||||||
// QGraphicsProxyWidget handles its own propagation,
|
// QGraphicsProxyWidget handles its own propagation,
|
||||||
// and we must not change QDragManagers currentTarget.
|
// and we must not change QDragManagers currentTarget.
|
||||||
QWExtra *extra = w->window()->d_func()->extra;
|
const auto &extra = w->window()->d_func()->extra;
|
||||||
if (extra && extra->proxyWidget) {
|
if (extra && extra->proxyWidget) {
|
||||||
res = d->notify_helper(w, dragEvent);
|
res = d->notify_helper(w, dragEvent);
|
||||||
break;
|
break;
|
||||||
@ -3416,7 +3416,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
|
|||||||
#if QT_CONFIG(graphicsview)
|
#if QT_CONFIG(graphicsview)
|
||||||
// QGraphicsProxyWidget handles its own propagation,
|
// QGraphicsProxyWidget handles its own propagation,
|
||||||
// and we must not change QDragManagers currentTarget.
|
// and we must not change QDragManagers currentTarget.
|
||||||
QWExtra *extra = w->window()->d_func()->extra;
|
const auto &extra = w->window()->d_func()->extra;
|
||||||
bool isProxyWidget = extra && extra->proxyWidget;
|
bool isProxyWidget = extra && extra->proxyWidget;
|
||||||
if (!isProxyWidget)
|
if (!isProxyWidget)
|
||||||
#endif
|
#endif
|
||||||
|
@ -178,7 +178,7 @@ static bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidge
|
|||||||
// Below is Qt::WindowShortcut context
|
// Below is Qt::WindowShortcut context
|
||||||
QWidget *tlw = w->window();
|
QWidget *tlw = w->window();
|
||||||
#if QT_CONFIG(graphicsview)
|
#if QT_CONFIG(graphicsview)
|
||||||
if (auto topData = static_cast<QWidgetPrivate *>(QObjectPrivate::get(tlw))->extra) {
|
if (auto topData = static_cast<QWidgetPrivate *>(QObjectPrivate::get(tlw))->extra.get()) {
|
||||||
if (topData->proxyWidget) {
|
if (topData->proxyWidget) {
|
||||||
bool res = correctGraphicsWidgetContext(context, topData->proxyWidget, active_window);
|
bool res = correctGraphicsWidgetContext(context, topData->proxyWidget, active_window);
|
||||||
return res;
|
return res;
|
||||||
|
@ -148,7 +148,6 @@ extern QDesktopWidget *qt_desktopWidget; // qapplication.cpp
|
|||||||
|
|
||||||
QWidgetPrivate::QWidgetPrivate(int version)
|
QWidgetPrivate::QWidgetPrivate(int version)
|
||||||
: QObjectPrivate(version)
|
: QObjectPrivate(version)
|
||||||
, extra(0)
|
|
||||||
, focus_next(0)
|
, focus_next(0)
|
||||||
, focus_prev(0)
|
, focus_prev(0)
|
||||||
, focus_child(0)
|
, focus_child(0)
|
||||||
@ -1553,7 +1552,7 @@ QWidget::~QWidget()
|
|||||||
while (w->d_func()->extra && w->d_func()->extra->focus_proxy)
|
while (w->d_func()->extra && w->d_func()->extra->focus_proxy)
|
||||||
w = w->d_func()->extra->focus_proxy;
|
w = w->d_func()->extra->focus_proxy;
|
||||||
QWidget *window = w->window();
|
QWidget *window = w->window();
|
||||||
QWExtra *e = window ? window->d_func()->extra : 0;
|
QWExtra *e = window ? window->d_func()->extra.get() : nullptr ;
|
||||||
if (!e || !e->proxyWidget || (w->parentWidget() && w->parentWidget()->d_func()->focus_child == this))
|
if (!e || !e->proxyWidget || (w->parentWidget() && w->parentWidget()->d_func()->focus_child == this))
|
||||||
#endif
|
#endif
|
||||||
clearFocus();
|
clearFocus();
|
||||||
@ -1732,7 +1731,7 @@ void QWidgetPrivate::createTLExtra()
|
|||||||
void QWidgetPrivate::createExtra()
|
void QWidgetPrivate::createExtra()
|
||||||
{
|
{
|
||||||
if (!extra) { // if not exists
|
if (!extra) { // if not exists
|
||||||
extra = new QWExtra;
|
extra = qt_make_unique<QWExtra>();
|
||||||
extra->glContext = 0;
|
extra->glContext = 0;
|
||||||
#if QT_CONFIG(graphicsview)
|
#if QT_CONFIG(graphicsview)
|
||||||
extra->proxyWidget = 0;
|
extra->proxyWidget = 0;
|
||||||
@ -1780,9 +1779,8 @@ void QWidgetPrivate::deleteExtra()
|
|||||||
deleteTLSysExtra();
|
deleteTLSysExtra();
|
||||||
// extra->topextra->backingStore destroyed in QWidgetPrivate::deleteTLSysExtra()
|
// extra->topextra->backingStore destroyed in QWidgetPrivate::deleteTLSysExtra()
|
||||||
}
|
}
|
||||||
delete extra;
|
|
||||||
// extra->xic destroyed in QWidget::destroy()
|
// extra->xic destroyed in QWidget::destroy()
|
||||||
extra = 0;
|
extra.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1853,7 +1851,7 @@ QRegion QWidgetPrivate::overlappedRegion(const QRect &rect, bool breakAfterFirst
|
|||||||
|
|
||||||
const QRect siblingRect = sibling->d_func()->effectiveRectFor(sibling->data->crect);
|
const QRect siblingRect = sibling->d_func()->effectiveRectFor(sibling->data->crect);
|
||||||
if (qRectIntersects(siblingRect, r)) {
|
if (qRectIntersects(siblingRect, r)) {
|
||||||
const QWExtra *siblingExtra = sibling->d_func()->extra;
|
const auto &siblingExtra = sibling->d_func()->extra;
|
||||||
if (siblingExtra && siblingExtra->hasMask && !sibling->d_func()->graphicsEffect
|
if (siblingExtra && siblingExtra->hasMask && !sibling->d_func()->graphicsEffect
|
||||||
&& !siblingExtra->mask.translated(sibling->data->crect.topLeft()).intersects(r)) {
|
&& !siblingExtra->mask.translated(sibling->data->crect.topLeft()).intersects(r)) {
|
||||||
continue;
|
continue;
|
||||||
@ -3858,7 +3856,7 @@ QSize QWidget::sizeIncrement() const
|
|||||||
QSize QWidget::baseSize() const
|
QSize QWidget::baseSize() const
|
||||||
{
|
{
|
||||||
Q_D(const QWidget);
|
Q_D(const QWidget);
|
||||||
return (d->extra != 0 && d->extra->topextra != 0)
|
return (d->extra && d->extra->topextra)
|
||||||
? QSize(d->extra->topextra->basew, d->extra->topextra->baseh)
|
? QSize(d->extra->topextra->basew, d->extra->topextra->baseh)
|
||||||
: QSize(0, 0);
|
: QSize(0, 0);
|
||||||
}
|
}
|
||||||
@ -5858,7 +5856,7 @@ QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *
|
|||||||
QGraphicsProxyWidget *QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget *origin)
|
QGraphicsProxyWidget *QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget *origin)
|
||||||
{
|
{
|
||||||
if (origin) {
|
if (origin) {
|
||||||
QWExtra *extra = origin->d_func()->extra;
|
const auto &extra = origin->d_func()->extra;
|
||||||
if (extra && extra->proxyWidget)
|
if (extra && extra->proxyWidget)
|
||||||
return extra->proxyWidget;
|
return extra->proxyWidget;
|
||||||
return nearestGraphicsProxyWidget(origin->parentWidget());
|
return nearestGraphicsProxyWidget(origin->parentWidget());
|
||||||
@ -6404,7 +6402,7 @@ bool QWidget::hasFocus() const
|
|||||||
w = w->d_func()->extra->focus_proxy;
|
w = w->d_func()->extra->focus_proxy;
|
||||||
#if QT_CONFIG(graphicsview)
|
#if QT_CONFIG(graphicsview)
|
||||||
if (QWidget *window = w->window()) {
|
if (QWidget *window = w->window()) {
|
||||||
QWExtra *e = window->d_func()->extra;
|
const auto &e = window->d_func()->extra;
|
||||||
if (e && e->proxyWidget && e->proxyWidget->hasFocus() && window->focusWidget() == w)
|
if (e && e->proxyWidget && e->proxyWidget->hasFocus() && window->focusWidget() == w)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -6465,7 +6463,7 @@ void QWidget::setFocus(Qt::FocusReason reason)
|
|||||||
|
|
||||||
#if QT_CONFIG(graphicsview)
|
#if QT_CONFIG(graphicsview)
|
||||||
QWidget *previousProxyFocus = 0;
|
QWidget *previousProxyFocus = 0;
|
||||||
if (QWExtra *topData = window()->d_func()->extra) {
|
if (const auto &topData = window()->d_func()->extra) {
|
||||||
if (topData->proxyWidget && topData->proxyWidget->hasFocus()) {
|
if (topData->proxyWidget && topData->proxyWidget->hasFocus()) {
|
||||||
previousProxyFocus = topData->proxyWidget->widget()->focusWidget();
|
previousProxyFocus = topData->proxyWidget->widget()->focusWidget();
|
||||||
if (previousProxyFocus && previousProxyFocus->focusProxy())
|
if (previousProxyFocus && previousProxyFocus->focusProxy())
|
||||||
@ -6478,7 +6476,7 @@ void QWidget::setFocus(Qt::FocusReason reason)
|
|||||||
|
|
||||||
#if QT_CONFIG(graphicsview)
|
#if QT_CONFIG(graphicsview)
|
||||||
// Update proxy state
|
// Update proxy state
|
||||||
if (QWExtra *topData = window()->d_func()->extra) {
|
if (const auto &topData = window()->d_func()->extra) {
|
||||||
if (topData->proxyWidget && !topData->proxyWidget->hasFocus()) {
|
if (topData->proxyWidget && !topData->proxyWidget->hasFocus()) {
|
||||||
f->d_func()->updateFocusChild();
|
f->d_func()->updateFocusChild();
|
||||||
topData->proxyWidget->d_func()->focusFromWidgetToProxy = 1;
|
topData->proxyWidget->d_func()->focusFromWidgetToProxy = 1;
|
||||||
@ -6519,7 +6517,7 @@ void QWidget::setFocus(Qt::FocusReason reason)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if QT_CONFIG(graphicsview)
|
#if QT_CONFIG(graphicsview)
|
||||||
if (QWExtra *topData = window()->d_func()->extra) {
|
if (const auto &topData = window()->d_func()->extra) {
|
||||||
if (topData->proxyWidget) {
|
if (topData->proxyWidget) {
|
||||||
if (previousProxyFocus && previousProxyFocus != f) {
|
if (previousProxyFocus && previousProxyFocus != f) {
|
||||||
// Send event to self
|
// Send event to self
|
||||||
@ -6532,7 +6530,7 @@ void QWidget::setFocus(Qt::FocusReason reason)
|
|||||||
if (!isHidden()) {
|
if (!isHidden()) {
|
||||||
#if QT_CONFIG(graphicsview)
|
#if QT_CONFIG(graphicsview)
|
||||||
// Update proxy state
|
// Update proxy state
|
||||||
if (QWExtra *topData = window()->d_func()->extra)
|
if (const auto &topData = window()->d_func()->extra)
|
||||||
if (topData->proxyWidget && topData->proxyWidget->hasFocus())
|
if (topData->proxyWidget && topData->proxyWidget->hasFocus())
|
||||||
topData->proxyWidget->d_func()->updateProxyInputMethodAcceptanceFromWidget();
|
topData->proxyWidget->d_func()->updateProxyInputMethodAcceptanceFromWidget();
|
||||||
#endif
|
#endif
|
||||||
@ -6669,7 +6667,7 @@ void QWidget::clearFocus()
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if QT_CONFIG(graphicsview)
|
#if QT_CONFIG(graphicsview)
|
||||||
QWExtra *topData = d_func()->extra;
|
const auto &topData = d_func()->extra;
|
||||||
if (topData && topData->proxyWidget)
|
if (topData && topData->proxyWidget)
|
||||||
topData->proxyWidget->clearFocus();
|
topData->proxyWidget->clearFocus();
|
||||||
#endif
|
#endif
|
||||||
@ -6835,7 +6833,7 @@ bool QWidget::isActiveWindow() const
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
#if QT_CONFIG(graphicsview)
|
#if QT_CONFIG(graphicsview)
|
||||||
if (QWExtra *tlwExtra = tlw->d_func()->extra) {
|
if (const auto &tlwExtra = tlw->d_func()->extra) {
|
||||||
if (isVisible() && tlwExtra->proxyWidget)
|
if (isVisible() && tlwExtra->proxyWidget)
|
||||||
return tlwExtra->proxyWidget->isActiveWindow();
|
return tlwExtra->proxyWidget->isActiveWindow();
|
||||||
}
|
}
|
||||||
@ -10325,7 +10323,7 @@ void QWidget::setSizePolicy(QSizePolicy policy)
|
|||||||
d->size_policy = policy;
|
d->size_policy = policy;
|
||||||
|
|
||||||
#if QT_CONFIG(graphicsview)
|
#if QT_CONFIG(graphicsview)
|
||||||
if (QWExtra *extra = d->extra) {
|
if (const auto &extra = d->extra) {
|
||||||
if (extra->proxyWidget)
|
if (extra->proxyWidget)
|
||||||
extra->proxyWidget->setSizePolicy(policy);
|
extra->proxyWidget->setSizePolicy(policy);
|
||||||
}
|
}
|
||||||
|
@ -669,7 +669,7 @@ public:
|
|||||||
|
|
||||||
// Variables.
|
// Variables.
|
||||||
// Regular pointers (keep them together to avoid gaps on 64 bit architectures).
|
// Regular pointers (keep them together to avoid gaps on 64 bit architectures).
|
||||||
QWExtra *extra;
|
std::unique_ptr<QWExtra> extra;
|
||||||
QWidget *focus_next;
|
QWidget *focus_next;
|
||||||
QWidget *focus_prev;
|
QWidget *focus_prev;
|
||||||
QWidget *focus_child;
|
QWidget *focus_child;
|
||||||
@ -945,7 +945,7 @@ public:
|
|||||||
|
|
||||||
inline QWExtra *QWidgetPrivate::extraData() const
|
inline QWExtra *QWidgetPrivate::extraData() const
|
||||||
{
|
{
|
||||||
return extra;
|
return extra.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QTLWExtra *QWidgetPrivate::topData() const
|
inline QTLWExtra *QWidgetPrivate::topData() const
|
||||||
|
Loading…
Reference in New Issue
Block a user