diff options
author | Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> | 2011-05-17 10:12:52 (GMT) |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> | 2011-05-17 10:12:52 (GMT) |
commit | d03065da2999b8539d8c5160b58d56dd94373d6f (patch) | |
tree | 06ce3546fdea4d6876746182cd3d659141dda353 /src/plugins/qmltooling/declarativeobserver/editor/subcomponentmasklayeritem.cpp | |
parent | 01a374fe8a6ac0b6e374081c07720e77c61effff (diff) | |
download | Qt-d03065da2999b8539d8c5160b58d56dd94373d6f.zip Qt-d03065da2999b8539d8c5160b58d56dd94373d6f.tar.gz Qt-d03065da2999b8539d8c5160b58d56dd94373d6f.tar.bz2 |
Fixed crashes in Observer mode related to infinite bounding rects
Bug fixed by avoiding uniting or subtracting QPolygonF with potentially
infinite coordinates.
The LiveSelectionIndicator now uses a QGraphicsRectItem rather than a
QGraphicsPolygonItem and displays only the boundaries of selected
objects, not including their children.
The SubcomponentMaskLayerItem now works with rectangles and uses a
QRegion to determine the area around the current context, converting
this to a polygon only as a last step.
Reviewed-by: Kai Koehne
Task-number: QTCREATORBUG-4559
Change-Id: I266f5387fa67017fc50215282a95b4ee6498be6d
Diffstat (limited to 'src/plugins/qmltooling/declarativeobserver/editor/subcomponentmasklayeritem.cpp')
-rw-r--r-- | src/plugins/qmltooling/declarativeobserver/editor/subcomponentmasklayeritem.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/plugins/qmltooling/declarativeobserver/editor/subcomponentmasklayeritem.cpp b/src/plugins/qmltooling/declarativeobserver/editor/subcomponentmasklayeritem.cpp index 15d2a2c..3543160 100644 --- a/src/plugins/qmltooling/declarativeobserver/editor/subcomponentmasklayeritem.cpp +++ b/src/plugins/qmltooling/declarativeobserver/editor/subcomponentmasklayeritem.cpp @@ -86,6 +86,13 @@ static QRectF resizeRect(const QRectF &newRect, const QRectF &oldRect) return result; } +static QPolygonF regionToPolygon(const QRegion ®ion) +{ + QPainterPath path; + foreach (const QRect &rect, region.rects()) + path.addRect(rect); + return path.toFillPolygon(); +} void SubcomponentMaskLayerItem::setCurrentItem(QGraphicsItem *item) { @@ -95,25 +102,24 @@ void SubcomponentMaskLayerItem::setCurrentItem(QGraphicsItem *item) if (!m_currentItem) return; - QPolygonF viewPoly(QRectF(m_observer->declarativeView()->rect())); - viewPoly = m_observer->declarativeView()->mapToScene(viewPoly.toPolygon()); + QRect viewRect = m_observer->declarativeView()->rect(); + viewRect = m_observer->declarativeView()->mapToScene(viewRect).boundingRect().toRect(); QRectF itemRect = item->boundingRect() | item->childrenBoundingRect(); - QPolygonF itemPoly(itemRect); - itemPoly = item->mapToScene(itemPoly); + itemRect = item->mapRectToScene(itemRect); // if updating the same item as before, resize the rectangle only bigger, not smaller. if (prevItem == item && prevItem != 0) { - m_itemPolyRect = resizeRect(itemPoly.boundingRect(), m_itemPolyRect); + m_itemPolyRect = resizeRect(itemRect, m_itemPolyRect); } else { - m_itemPolyRect = itemPoly.boundingRect(); + m_itemPolyRect = itemRect; } QRectF borderRect = m_itemPolyRect; borderRect.adjust(-1, -1, 1, 1); m_borderRect->setRect(borderRect); - itemPoly = viewPoly.subtracted(QPolygonF(m_itemPolyRect)); - setPolygon(itemPoly); + const QRegion externalRegion = QRegion(viewRect).subtracted(m_itemPolyRect.toRect()); + setPolygon(regionToPolygon(externalRegion)); } QGraphicsItem *SubcomponentMaskLayerItem::currentItem() const |