QGraphicsWidget: call normal "setParent" when setting a parent

QGraphicsWidgetPrivate::init had a special code path for setting
the item's parent. For some reason that code path caused the
ItemChildAddedChange notification not to be sent to the parent
element, which is wrong. Instead use the "normal" path, which is
what the QGraphicsItem constructor does anyhow.

Change-Id: Iad84cae05d797022a45977d35ca00c80c17c306a
Task-number: QTBUG-45867
Reviewed-by: Andreas Aardal Hanssen <andreas@hanssen.name>
bb10
Giuseppe D'Angelo 2015-05-01 18:31:54 +02:00
parent f44f2136e0
commit 3287e7a68a
2 changed files with 33 additions and 3 deletions

View File

@ -64,9 +64,7 @@ void QGraphicsWidgetPrivate::init(QGraphicsItem *parentItem, Qt::WindowFlags wFl
adjustWindowFlags(&wFlags);
windowFlags = wFlags;
if (parentItem)
setParentItemHelper(parentItem, 0, 0);
q->setParentItem(parentItem);
q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::DefaultType));
q->setGraphicsItem(q);

View File

@ -179,6 +179,7 @@ private slots:
void task250119_shortcutContext();
void QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems();
void QT_BUG_12056_tabFocusFirstUnsetWhenRemovingItems();
void QTBUG_45867_send_itemChildAddedChange_to_parent();
};
@ -3490,5 +3491,36 @@ void tst_QGraphicsWidget::QT_BUG_12056_tabFocusFirstUnsetWhenRemovingItems()
//This should not crash
}
void tst_QGraphicsWidget::QTBUG_45867_send_itemChildAddedChange_to_parent()
{
class GraphicsItem : public QGraphicsItem
{
public:
int m_itemChildAddedChangeNotificationsCount;
GraphicsItem()
: QGraphicsItem(),
m_itemChildAddedChangeNotificationsCount(0)
{
}
QRectF boundingRect() const Q_DECL_OVERRIDE { return QRectF(); }
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE {}
protected:
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) Q_DECL_OVERRIDE
{
if (change == QGraphicsItem::ItemChildAddedChange)
++m_itemChildAddedChangeNotificationsCount;
return QGraphicsItem::itemChange(change, value);
}
};
GraphicsItem item;
QGraphicsWidget widget(&item);
QCOMPARE(item.m_itemChildAddedChangeNotificationsCount, 1);
}
QTEST_MAIN(tst_QGraphicsWidget)
#include "tst_qgraphicswidget.moc"