diff options
9 files changed, 53 insertions, 77 deletions
diff --git a/src/declarative/qml/qdeclarativedirparser.cpp b/src/declarative/qml/qdeclarativedirparser.cpp index d4abbee..1d4db40 100644 --- a/src/declarative/qml/qdeclarativedirparser.cpp +++ b/src/declarative/qml/qdeclarativedirparser.cpp @@ -240,7 +240,7 @@ QList<QDeclarativeDirParser::Component> QDeclarativeDirParser::components() cons } #ifdef QT_CREATOR -QList<TypeInfo> QDeclarativeDirParser::typeInfos() const +QList<QDeclarativeDirParser::TypeInfo> QDeclarativeDirParser::typeInfos() const { return _typeInfos; } diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp index e806dbf..ae28049 100644 --- a/src/declarative/qml/qdeclarativeproperty.cpp +++ b/src/declarative/qml/qdeclarativeproperty.cpp @@ -183,6 +183,9 @@ QDeclarativeProperty::QDeclarativeProperty(QObject *obj, const QString &name) /*! Creates a QDeclarativeProperty for the property \a name of \a obj using the \l{QDeclarativeContext} {context} \a ctxt. + + Creating a QDeclarativeProperty without a context will render some + properties - like attached properties - inaccessible. */ QDeclarativeProperty::QDeclarativeProperty(QObject *obj, const QString &name, QDeclarativeContext *ctxt) : d(new QDeclarativePropertyPrivate) diff --git a/src/plugins/qmltooling/declarativeobserver/editor/liveselectionindicator.cpp b/src/plugins/qmltooling/declarativeobserver/editor/liveselectionindicator.cpp index 44167e3..2752957 100644 --- a/src/plugins/qmltooling/declarativeobserver/editor/liveselectionindicator.cpp +++ b/src/plugins/qmltooling/declarativeobserver/editor/liveselectionindicator.cpp @@ -44,20 +44,17 @@ #include "../qdeclarativeviewobserver_p_p.h" #include "../qmlobserverconstants_p.h" -#include <QtCore/QDebug> - -#include <QtGui/QGraphicsPolygonItem> +#include <QtGui/QGraphicsRectItem> #include <QtGui/QGraphicsObject> #include <QtGui/QGraphicsScene> #include <QtGui/QPen> -#include <cmath> - QT_BEGIN_NAMESPACE -LiveSelectionIndicator::LiveSelectionIndicator(QDeclarativeViewObserver *editorView, - QGraphicsObject *layerItem) - : m_layerItem(layerItem), m_view(editorView) +LiveSelectionIndicator::LiveSelectionIndicator(QDeclarativeViewObserver *viewObserver, + QGraphicsObject *layerItem) + : m_layerItem(layerItem) + , m_view(viewObserver) { } @@ -68,24 +65,23 @@ LiveSelectionIndicator::~LiveSelectionIndicator() void LiveSelectionIndicator::show() { - foreach (QGraphicsPolygonItem *item, m_indicatorShapeHash.values()) + foreach (QGraphicsRectItem *item, m_indicatorShapeHash) item->show(); } void LiveSelectionIndicator::hide() { - foreach (QGraphicsPolygonItem *item, m_indicatorShapeHash.values()) + foreach (QGraphicsRectItem *item, m_indicatorShapeHash) item->hide(); } void LiveSelectionIndicator::clear() { if (!m_layerItem.isNull()) { - QHashIterator<QGraphicsItem*, QGraphicsPolygonItem *> iter(m_indicatorShapeHash); - while (iter.hasNext()) { - iter.next(); - m_layerItem.data()->scene()->removeItem(iter.value()); - delete iter.value(); + QGraphicsScene *scene = m_layerItem.data()->scene(); + foreach (QGraphicsRectItem *item, m_indicatorShapeHash) { + scene->removeItem(item); + delete item; } } @@ -93,56 +89,29 @@ void LiveSelectionIndicator::clear() } -QPolygonF LiveSelectionIndicator::addBoundingRectToPolygon(QGraphicsItem *item, QPolygonF &polygon) -{ - // ### remove this if statement when QTBUG-12172 gets fixed - if (item->boundingRect() != QRectF(0,0,0,0)) { - QPolygonF bounding = item->mapToScene(item->boundingRect()); - if (bounding.isClosed()) //avoid crashes if there is an infinite scale. - polygon = polygon.united(bounding); - } - - foreach (QGraphicsItem *child, item->childItems()) { - if (!QDeclarativeViewObserverPrivate::get(m_view)->isEditorItem(child)) - addBoundingRectToPolygon(child, polygon); - } - return polygon; -} - void LiveSelectionIndicator::setItems(const QList<QWeakPointer<QGraphicsObject> > &itemList) { clear(); - // set selections to also all children if they are not editor items - foreach (const QWeakPointer<QGraphicsObject> &object, itemList) { if (object.isNull()) continue; QGraphicsItem *item = object.data(); - QGraphicsPolygonItem *newSelectionIndicatorGraphicsItem - = new QGraphicsPolygonItem(m_layerItem.data()); if (!m_indicatorShapeHash.contains(item)) { - m_indicatorShapeHash.insert(item, newSelectionIndicatorGraphicsItem); - - QPolygonF boundingShapeInSceneSpace; - addBoundingRectToPolygon(item, boundingShapeInSceneSpace); - - QRectF boundingRect - = m_view->adjustToScreenBoundaries(boundingShapeInSceneSpace.boundingRect()); - QPolygonF boundingRectInLayerItemSpace = m_layerItem.data()->mapFromScene(boundingRect); - - QPen pen; - pen.setColor(QColor(108, 141, 221)); - newSelectionIndicatorGraphicsItem->setData(Constants::EditorItemDataKey, - QVariant(true)); - newSelectionIndicatorGraphicsItem->setFlag(QGraphicsItem::ItemIsSelectable, false); - newSelectionIndicatorGraphicsItem->setPolygon(boundingRectInLayerItemSpace); - newSelectionIndicatorGraphicsItem->setPen(pen); + QGraphicsRectItem *selectionIndicator = new QGraphicsRectItem(m_layerItem.data()); + m_indicatorShapeHash.insert(item, selectionIndicator); + + const QRectF boundingRect = m_view->adjustToScreenBoundaries(item->mapRectToScene(item->boundingRect())); + const QRectF boundingRectInLayerItemSpace = m_layerItem.data()->mapRectFromScene(boundingRect); + + selectionIndicator->setData(Constants::EditorItemDataKey, true); + selectionIndicator->setFlag(QGraphicsItem::ItemIsSelectable, false); + selectionIndicator->setRect(boundingRectInLayerItemSpace); + selectionIndicator->setPen(QColor(108, 141, 221)); } } } QT_END_NAMESPACE - diff --git a/src/plugins/qmltooling/declarativeobserver/editor/liveselectionindicator_p.h b/src/plugins/qmltooling/declarativeobserver/editor/liveselectionindicator_p.h index 6d2b545..efd2c5f 100644 --- a/src/plugins/qmltooling/declarativeobserver/editor/liveselectionindicator_p.h +++ b/src/plugins/qmltooling/declarativeobserver/editor/liveselectionindicator_p.h @@ -47,7 +47,7 @@ QT_BEGIN_NAMESPACE class QGraphicsObject; -class QGraphicsPolygonItem; +class QGraphicsRectItem; class QGraphicsItem; class QPolygonF; QT_END_NAMESPACE @@ -63,7 +63,7 @@ class QDeclarativeViewObserver; class LiveSelectionIndicator { public: - LiveSelectionIndicator(QDeclarativeViewObserver* editorView, QGraphicsObject *layerItem); + LiveSelectionIndicator(QDeclarativeViewObserver *viewObserver, QGraphicsObject *layerItem); ~LiveSelectionIndicator(); void show(); @@ -74,13 +74,9 @@ public: void setItems(const QList<QWeakPointer<QGraphicsObject> > &itemList); private: - QPolygonF addBoundingRectToPolygon(QGraphicsItem *item, QPolygonF &polygon); - -private: - QHash<QGraphicsItem*, QGraphicsPolygonItem *> m_indicatorShapeHash; + QHash<QGraphicsItem*, QGraphicsRectItem *> m_indicatorShapeHash; QWeakPointer<QGraphicsObject> m_layerItem; QDeclarativeViewObserver *m_view; - }; QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/declarativeobserver/editor/subcomponentmasklayeritem.cpp b/src/plugins/qmltooling/declarativeobserver/editor/subcomponentmasklayeritem.cpp index da6e82b..27e2079 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 diff --git a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp index 41346ff..5d2ab09 100644 --- a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp +++ b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp @@ -557,7 +557,7 @@ void QDeclarativeViewObserverPrivate::changeTool(Constants::DesignTool tool, } } -void QDeclarativeViewObserverPrivate::setSelectedItemsForTools(QList<QGraphicsItem *> items) +void QDeclarativeViewObserverPrivate::setSelectedItemsForTools(const QList<QGraphicsItem *> &items) { foreach (const QWeakPointer<QGraphicsObject> &obj, currentSelection) { if (QGraphicsItem *item = obj.data()) { @@ -582,7 +582,7 @@ void QDeclarativeViewObserverPrivate::setSelectedItemsForTools(QList<QGraphicsIt currentTool->updateSelectedItems(); } -void QDeclarativeViewObserverPrivate::setSelectedItems(QList<QGraphicsItem *> items) +void QDeclarativeViewObserverPrivate::setSelectedItems(const QList<QGraphicsItem *> &items) { QList<QWeakPointer<QGraphicsObject> > oldList = currentSelection; setSelectedItemsForTools(items); @@ -633,7 +633,8 @@ void QDeclarativeViewObserverPrivate::highlight(QGraphicsObject * item, ContextF highlight(QList<QGraphicsObject*>() << item, flags); } -void QDeclarativeViewObserverPrivate::highlight(QList<QGraphicsObject *> items, ContextFlags flags) +void QDeclarativeViewObserverPrivate::highlight(const QList<QGraphicsObject *> &items, + ContextFlags flags) { if (items.isEmpty()) return; @@ -1064,7 +1065,7 @@ void QDeclarativeViewObserver::sendDesignModeBehavior(bool inDesignMode) data->debugService->sendMessage(message); } -void QDeclarativeViewObserver::sendCurrentObjects(QList<QObject*> objects) +void QDeclarativeViewObserver::sendCurrentObjects(const QList<QObject*> &objects) { QByteArray message; QDataStream ds(&message, QIODevice::WriteOnly); diff --git a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p.h b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p.h index 4d66cae..86d0d95 100644 --- a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p.h +++ b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p.h @@ -78,7 +78,7 @@ public: bool showAppOnTop() const; void sendDesignModeBehavior(bool inDesignMode); - void sendCurrentObjects(QList<QObject*> items); + void sendCurrentObjects(const QList<QObject*> &); void sendAnimationSpeed(qreal slowDownFactor); void sendAnimationPaused(bool paused); void sendCurrentTool(Constants::DesignTool toolId); diff --git a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p_p.h b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p_p.h index 57dae45..8809591 100644 --- a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p_p.h +++ b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p_p.h @@ -117,15 +117,16 @@ public: QList<QGraphicsItem*> selectableItems(const QPointF &scenePos) const; QList<QGraphicsItem*> selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const; - void setSelectedItemsForTools(QList<QGraphicsItem *> items); - void setSelectedItems(QList<QGraphicsItem *> items); + void setSelectedItemsForTools(const QList<QGraphicsItem *> &items); + void setSelectedItems(const QList<QGraphicsItem *> &items); QList<QGraphicsItem *> selectedItems() const; void changeTool(Constants::DesignTool tool, Constants::ToolFlags flags = Constants::NoToolFlags); void clearHighlight(); - void highlight(QList<QGraphicsObject *> item, ContextFlags flags = ContextSensitive); + void highlight(const QList<QGraphicsObject *> &item, + ContextFlags flags = ContextSensitive); void highlight(QGraphicsObject *item, ContextFlags flags = ContextSensitive); bool mouseInsideContextItem() const; diff --git a/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp b/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp index 361d7f3..8871e45 100644 --- a/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp +++ b/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp @@ -1027,7 +1027,7 @@ void tst_QDeclarativeDebug::setBindingForObject() // set handler // rootObject = findRootObject(); - QCOMPARE(rootObject.children().size(), 4); // Rectangle, Text, MouseArea, QDeclarativeComponentAttached + QCOMPARE(rootObject.children().size(), 5); // Rectangle, Text, MouseArea, Component.onCompleted, NonScriptPropertyElement QDeclarativeDebugObjectReference mouseAreaObject = rootObject.children().at(2); QDeclarativeDebugObjectQuery *q_obj = m_dbg->queryObjectRecursive(mouseAreaObject, this); waitForQuery(q_obj); |