diff options
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.cpp | 3 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene.cpp | 14 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene_p.h | 1 | ||||
-rw-r--r-- | tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 41 |
4 files changed, 59 insertions, 0 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 4f77aa8..280c365 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -1262,6 +1262,9 @@ void QGraphicsItem::setFlags(GraphicsItemFlags flags) d_ptr->updateAncestorFlag(ItemClipsChildrenToShape); } + if (d_ptr->scene && oldFlags & ItemClipsChildrenToShape) + d_ptr->scene->d_func()->addToUnindexedItems(this); + if ((flags & ItemClipsToShape) != (oldFlags & ItemClipsToShape)) d_ptr->invalidateCachedClipPath(); diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 0fded89..5c3e9bd 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -448,6 +448,20 @@ void QGraphicsScenePrivate::addToIndex(QGraphicsItem *item) /*! \internal */ +void QGraphicsScenePrivate::addToUnindexedItems(QGraphicsItem *item) +{ + if (indexMethod == QGraphicsScene::BspTreeIndex) { + item->d_func()->index = -1; + unindexedItems << item; + + for (int i = 0 ; i < item->d_ptr->children.size() ; ++i) + addToUnindexedItems(item->d_ptr->children.at(i)); + } +} + +/*! + \internal +*/ void QGraphicsScenePrivate::removeFromIndex(QGraphicsItem *item) { if (indexMethod == QGraphicsScene::BspTreeIndex) { diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h index 3c72874..62bcbfb 100644 --- a/src/gui/graphicsview/qgraphicsscene_p.h +++ b/src/gui/graphicsview/qgraphicsscene_p.h @@ -89,6 +89,7 @@ public: QList<QGraphicsItem *> estimateItemsInRect(const QRectF &rect) const; void addToIndex(QGraphicsItem *item); void removeFromIndex(QGraphicsItem *item); + void addToUnindexedItems(QGraphicsItem *item); void resetIndex(); QGraphicsSceneBspTree bspTree; diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 55e9b34..215334c 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -47,12 +47,14 @@ #include <QAbstractTextDocumentLayout> #include <QBitmap> #include <QCursor> +#include <QLabel> #include <QDial> #include <QGraphicsItem> #include <QGraphicsScene> #include <QGraphicsSceneEvent> #include <QGraphicsView> #include <QGraphicsWidget> +#include <QGraphicsProxyWidget> #include <QPainter> #include <QScrollBar> #include <QVBoxLayout> @@ -196,6 +198,7 @@ private slots: void itemClipsChildrenToShape(); void itemClipsChildrenToShape2(); void itemClipsChildrenToShape3(); + void itemClipsChildrenToShape4(); void itemClipsTextChildToShape(); void itemClippingDiscovery(); void ancestorFlags(); @@ -4724,6 +4727,44 @@ void tst_QGraphicsItem::itemClipsChildrenToShape3() QCOMPARE(scene.itemAt(175,175), (QGraphicsItem *)0); } +class MyProxyWidget : public QGraphicsProxyWidget +{ +public: + MyProxyWidget(QGraphicsItem *parent) : QGraphicsProxyWidget(parent) + { + painted = false; + } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + { + QGraphicsProxyWidget::paint(painter, option, widget); + painted = true; + } + bool painted; +}; + +void tst_QGraphicsItem::itemClipsChildrenToShape4() +{ + QGraphicsScene scene; + QGraphicsView view(&scene); + + QGraphicsWidget * outerWidget = new QGraphicsWidget(); + outerWidget->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true); + MyProxyWidget * innerWidget = new MyProxyWidget(outerWidget); + QLabel * label = new QLabel(); + label->setText("Welcome back my friends to the show that never ends..."); + innerWidget->setWidget(label); + view.resize(300, 300); + scene.addItem(outerWidget); + outerWidget->resize( 200, 100 ); + scene.addEllipse( 100, 100, 100, 50 ); // <-- this is important to trigger the right codepath* + //now the label is shown + outerWidget->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false ); + QApplication::setActiveWindow(&view); + view.show(); + QTRY_COMPARE(QApplication::activeWindow(), (QWidget *)&view); + QTRY_COMPARE(innerWidget->painted, true); +} void tst_QGraphicsItem::itemClipsTextChildToShape() { |