From e2939ee2a903676c00c6711e2f5444f058fb6269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Tue, 17 May 2011 12:12:52 +0200 Subject: 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 (cherry picked from commit d03065da2999b8539d8c5160b58d56dd94373d6f) --- .../editor/liveselectionindicator.cpp | 73 +++++++--------------- .../editor/liveselectionindicator_p.h | 10 +-- .../editor/subcomponentmasklayeritem.cpp | 22 ++++--- 3 files changed, 38 insertions(+), 67 deletions(-) diff --git a/src/plugins/qmltooling/declarativeobserver/editor/liveselectionindicator.cpp b/src/plugins/qmltooling/declarativeobserver/editor/liveselectionindicator.cpp index 44167e3294..2752957314 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 - -#include +#include #include #include #include -#include - 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 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 > &itemList) { clear(); - // set selections to also all children if they are not editor items - foreach (const QWeakPointer &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 6d2b545be5..efd2c5f488 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 > &itemList); private: - QPolygonF addBoundingRectToPolygon(QGraphicsItem *item, QPolygonF &polygon); - -private: - QHash m_indicatorShapeHash; + QHash m_indicatorShapeHash; QWeakPointer 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 da6e82b826..27e20791d6 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 -- cgit v1.2.3 From 1c709a17fd50643587ca89ce30c0faf8e0573e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Tue, 17 May 2011 11:23:10 +0200 Subject: Pass QList as const reference when possible Avoids some reference counting. Reviewed-by: Kai Koehne Change-Id: I4de83aa4df6833fa2287ac1854bbb0052d15cee9 (cherry picked from commit bdd8f188ac352c99ee218318a59089f387a31d60) --- .../qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp | 9 +++++---- .../qmltooling/declarativeobserver/qdeclarativeviewobserver_p.h | 2 +- .../declarativeobserver/qdeclarativeviewobserver_p_p.h | 7 ++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp index 41346ffafe..5d2ab09b2f 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 items) +void QDeclarativeViewObserverPrivate::setSelectedItemsForTools(const QList &items) { foreach (const QWeakPointer &obj, currentSelection) { if (QGraphicsItem *item = obj.data()) { @@ -582,7 +582,7 @@ void QDeclarativeViewObserverPrivate::setSelectedItemsForTools(QListupdateSelectedItems(); } -void QDeclarativeViewObserverPrivate::setSelectedItems(QList items) +void QDeclarativeViewObserverPrivate::setSelectedItems(const QList &items) { QList > oldList = currentSelection; setSelectedItemsForTools(items); @@ -633,7 +633,8 @@ void QDeclarativeViewObserverPrivate::highlight(QGraphicsObject * item, ContextF highlight(QList() << item, flags); } -void QDeclarativeViewObserverPrivate::highlight(QList items, ContextFlags flags) +void QDeclarativeViewObserverPrivate::highlight(const QList &items, + ContextFlags flags) { if (items.isEmpty()) return; @@ -1064,7 +1065,7 @@ void QDeclarativeViewObserver::sendDesignModeBehavior(bool inDesignMode) data->debugService->sendMessage(message); } -void QDeclarativeViewObserver::sendCurrentObjects(QList objects) +void QDeclarativeViewObserver::sendCurrentObjects(const QList &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 4d66cae917..86d0d95321 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 items); + void sendCurrentObjects(const QList &); 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 57dae458a3..880959156b 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 selectableItems(const QPointF &scenePos) const; QList selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const; - void setSelectedItemsForTools(QList items); - void setSelectedItems(QList items); + void setSelectedItemsForTools(const QList &items); + void setSelectedItems(const QList &items); QList selectedItems() const; void changeTool(Constants::DesignTool tool, Constants::ToolFlags flags = Constants::NoToolFlags); void clearHighlight(); - void highlight(QList item, ContextFlags flags = ContextSensitive); + void highlight(const QList &item, + ContextFlags flags = ContextSensitive); void highlight(QGraphicsObject *item, ContextFlags flags = ContextSensitive); bool mouseInsideContextItem() const; -- cgit v1.2.3 From eea3b16fede420919b19c81c685df48ae5b59205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Tue, 24 May 2011 11:22:29 +0200 Subject: DeclarativeObserver: Removed the SubcomponentEditorTool This tool made selecting items in your QML app more complicated than necessary. Now, left-click will always just select the top-most item under the mouse and right-click will allow you to select any of the items below. Also, the highlighted bounding rect now always applies to just one item, instead of also including the children bounding rect. Reviewed-by: Kai Koehne Change-Id: I17b5ab397d951fd68711590469ca6e723a9cb0e6 (cherry picked from commit 73060143c30d38ea99e6d7a77ff81c94f58899d7) --- .../declarativeobserver/declarativeobserver.pro | 2 - .../editor/abstractliveedittool.cpp | 5 - .../editor/abstractliveedittool_p.h | 2 - .../editor/boundingrecthighlighter.cpp | 8 +- .../editor/liveselectiontool.cpp | 4 - .../editor/subcomponenteditortool.cpp | 364 --------------------- .../editor/subcomponenteditortool_p.h | 131 -------- .../qdeclarativeobserverprotocol.h | 2 - .../qdeclarativeviewobserver.cpp | 169 +--------- .../qdeclarativeviewobserver_p.h | 7 - .../qdeclarativeviewobserver_p_p.h | 20 +- 11 files changed, 17 insertions(+), 697 deletions(-) delete mode 100644 src/plugins/qmltooling/declarativeobserver/editor/subcomponenteditortool.cpp delete mode 100644 src/plugins/qmltooling/declarativeobserver/editor/subcomponenteditortool_p.h diff --git a/src/plugins/qmltooling/declarativeobserver/declarativeobserver.pro b/src/plugins/qmltooling/declarativeobserver/declarativeobserver.pro index 6c11efbc9e..93b4ccdb57 100644 --- a/src/plugins/qmltooling/declarativeobserver/declarativeobserver.pro +++ b/src/plugins/qmltooling/declarativeobserver/declarativeobserver.pro @@ -19,7 +19,6 @@ SOURCES += \ editor/liveselectionrectangle.cpp \ editor/liveselectionindicator.cpp \ editor/boundingrecthighlighter.cpp \ - editor/subcomponenteditortool.cpp \ editor/subcomponentmasklayeritem.cpp \ editor/zoomtool.cpp \ editor/colorpickertool.cpp \ @@ -40,7 +39,6 @@ HEADERS += \ editor/liveselectionrectangle_p.h \ editor/liveselectionindicator_p.h \ editor/boundingrecthighlighter_p.h \ - editor/subcomponenteditortool_p.h \ editor/subcomponentmasklayeritem_p.h \ editor/zoomtool_p.h \ editor/colorpickertool_p.h \ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool.cpp b/src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool.cpp index c2ea17c24c..a97a537cd6 100644 --- a/src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool.cpp +++ b/src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool.cpp @@ -85,11 +85,6 @@ QList AbstractLiveEditTool::items() const return observer()->selectedItems(); } -void AbstractLiveEditTool::enterContext(QGraphicsItem *itemToEnter) -{ - observer()->data->enterContext(itemToEnter); -} - bool AbstractLiveEditTool::topItemIsMovable(const QList & itemList) { QGraphicsItem *firstSelectableItem = topMovableGraphicsItem(itemList); diff --git a/src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool_p.h b/src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool_p.h index 7d46db6672..97aac35366 100644 --- a/src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool_p.h +++ b/src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool_p.h @@ -89,8 +89,6 @@ public: void updateSelectedItems(); QList items() const; - void enterContext(QGraphicsItem *itemToEnter); - bool topItemIsMovable(const QList &itemList); bool topItemIsResizeHandle(const QList &itemList); bool topSelectedItemIsMovable(const QList &itemList); diff --git a/src/plugins/qmltooling/declarativeobserver/editor/boundingrecthighlighter.cpp b/src/plugins/qmltooling/declarativeobserver/editor/boundingrecthighlighter.cpp index 068f6de153..e9594d50a6 100644 --- a/src/plugins/qmltooling/declarativeobserver/editor/boundingrecthighlighter.cpp +++ b/src/plugins/qmltooling/declarativeobserver/editor/boundingrecthighlighter.cpp @@ -253,12 +253,10 @@ void BoundingRectHighlighter::highlightAll(bool animate) return; } QGraphicsObject *item = box->highlightedObject.data(); - QRectF itemAndChildRect = item->boundingRect() | item->childrenBoundingRect(); - QPolygonF boundingRectInSceneSpace(item->mapToScene(itemAndChildRect)); - QPolygonF boundingRectInLayerItemSpace = mapFromScene(boundingRectInSceneSpace); - QRectF bboxRect - = m_view->adjustToScreenBoundaries(boundingRectInLayerItemSpace.boundingRect()); + QRectF boundingRectInSceneSpace(item->mapToScene(item->boundingRect()).boundingRect()); + QRectF boundingRectInLayerItemSpace = mapRectFromScene(boundingRectInSceneSpace); + QRectF bboxRect = m_view->adjustToScreenBoundaries(boundingRectInLayerItemSpace); QRectF edgeRect = bboxRect; edgeRect.adjust(-1, -1, 1, 1); diff --git a/src/plugins/qmltooling/declarativeobserver/editor/liveselectiontool.cpp b/src/plugins/qmltooling/declarativeobserver/editor/liveselectiontool.cpp index 62b6e01b31..872832c387 100644 --- a/src/plugins/qmltooling/declarativeobserver/editor/liveselectiontool.cpp +++ b/src/plugins/qmltooling/declarativeobserver/editor/liveselectiontool.cpp @@ -134,9 +134,6 @@ void LiveSelectionTool::mousePressEvent(QMouseEvent *event) void LiveSelectionTool::createContextMenu(QList itemList, QPoint globalPos) { - if (!QDeclarativeViewObserverPrivate::get(observer())->mouseInsideContextItem()) - return; - QMenu contextMenu; connect(&contextMenu, SIGNAL(hovered(QAction*)), this, SLOT(contextMenuElementHovered(QAction*))); @@ -192,7 +189,6 @@ void LiveSelectionTool::contextMenuElementSelected() QList() << item, false); m_singleSelectionManipulator.end(updatePt); - enterContext(item); } } diff --git a/src/plugins/qmltooling/declarativeobserver/editor/subcomponenteditortool.cpp b/src/plugins/qmltooling/declarativeobserver/editor/subcomponenteditortool.cpp deleted file mode 100644 index c3790e486d..0000000000 --- a/src/plugins/qmltooling/declarativeobserver/editor/subcomponenteditortool.cpp +++ /dev/null @@ -1,364 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "subcomponenteditortool_p.h" -#include "subcomponentmasklayeritem_p.h" -#include "livelayeritem_p.h" - -#include "../qdeclarativeviewobserver_p_p.h" - -#include -#include -#include -#include - -#include -#include - -QT_BEGIN_NAMESPACE - -const qreal MaxOpacity = 0.5f; - -SubcomponentEditorTool::SubcomponentEditorTool(QDeclarativeViewObserver *view) - : AbstractLiveEditTool(view), - m_animIncrement(0.05f), - m_animTimer(new QTimer(this)) -{ - QDeclarativeViewObserverPrivate *observerPrivate = - QDeclarativeViewObserverPrivate::get(view); - m_mask = new SubcomponentMaskLayerItem(view, observerPrivate->manipulatorLayer); - connect(m_animTimer, SIGNAL(timeout()), SLOT(animate())); - m_animTimer->setInterval(20); -} - -SubcomponentEditorTool::~SubcomponentEditorTool() -{ - -} - -void SubcomponentEditorTool::mousePressEvent(QMouseEvent * /*event*/) -{ - -} - -void SubcomponentEditorTool::mouseMoveEvent(QMouseEvent * /*event*/) -{ - -} - -bool SubcomponentEditorTool::containsCursor(const QPoint &mousePos) const -{ - if (!m_currentContext.size()) - return false; - - QPointF scenePos = view()->mapToScene(mousePos); - QRectF itemRect = m_currentContext.top()->boundingRect() - | m_currentContext.top()->childrenBoundingRect(); - QRectF polyRect = m_currentContext.top()->mapToScene(itemRect).boundingRect(); - - return polyRect.contains(scenePos); -} - -void SubcomponentEditorTool::mouseReleaseEvent(QMouseEvent * /*event*/) -{ - -} - -void SubcomponentEditorTool::mouseDoubleClickEvent(QMouseEvent *event) -{ - if (event->buttons() & Qt::LeftButton - && !containsCursor(event->pos()) - && m_currentContext.size() > 1) - { - aboutToPopContext(); - } -} - -void SubcomponentEditorTool::hoverMoveEvent(QMouseEvent *event) -{ - if (!containsCursor(event->pos()) && m_currentContext.size() > 1) { - QDeclarativeViewObserverPrivate::get(observer())->clearHighlight(); - } -} - -void SubcomponentEditorTool::wheelEvent(QWheelEvent * /*event*/) -{ - -} - -void SubcomponentEditorTool::keyPressEvent(QKeyEvent * /*event*/) -{ - -} - -void SubcomponentEditorTool::keyReleaseEvent(QKeyEvent * /*keyEvent*/) -{ - -} - -void SubcomponentEditorTool::itemsAboutToRemoved(const QList &/*itemList*/) -{ - -} - -void SubcomponentEditorTool::animate() -{ - if (m_animIncrement > 0) { - if (m_mask->opacity() + m_animIncrement < MaxOpacity) { - m_mask->setOpacity(m_mask->opacity() + m_animIncrement); - } else { - m_animTimer->stop(); - m_mask->setOpacity(MaxOpacity); - } - } else { - if (m_mask->opacity() + m_animIncrement > 0) { - m_mask->setOpacity(m_mask->opacity() + m_animIncrement); - } else { - m_animTimer->stop(); - m_mask->setOpacity(0); - popContext(); - emit contextPathChanged(m_path); - } - } - -} - -void SubcomponentEditorTool::clear() -{ - m_currentContext.clear(); - m_mask->setCurrentItem(0); - m_animTimer->stop(); - m_mask->hide(); - m_path.clear(); - - emit contextPathChanged(m_path); - emit cleared(); -} - -void SubcomponentEditorTool::selectedItemsChanged(const QList &/*itemList*/) -{ - -} - -void SubcomponentEditorTool::setCurrentItem(QGraphicsItem* contextItem) -{ - if (!contextItem) - return; - - QGraphicsObject *gfxObject = contextItem->toGraphicsObject(); - if (!gfxObject) - return; - - //QString parentClassName = gfxObject->metaObject()->className(); - //if (parentClassName.contains(QRegExp("_QMLTYPE_\\d+"))) - - bool containsSelectableItems = false; - foreach (QGraphicsItem *item, gfxObject->childItems()) { - if (item->type() == Constants::EditorItemType - || item->type() == Constants::ResizeHandleItemType) - { - continue; - } - containsSelectableItems = true; - break; - } - - if (containsSelectableItems) { - m_mask->setCurrentItem(gfxObject); - m_mask->setOpacity(0); - m_mask->show(); - m_animIncrement = 0.05f; - m_animTimer->start(); - - QDeclarativeViewObserverPrivate::get(observer())->clearHighlight(); - observer()->setSelectedItems(QList()); - - pushContext(gfxObject); - } -} - -QGraphicsItem *SubcomponentEditorTool::firstChildOfContext(QGraphicsItem *item) const -{ - if (!item) - return 0; - - if (isDirectChildOfContext(item)) - return item; - - QGraphicsItem *parent = item->parentItem(); - while (parent) { - if (isDirectChildOfContext(parent)) - return parent; - parent = parent->parentItem(); - } - - return 0; -} - -bool SubcomponentEditorTool::isChildOfContext(QGraphicsItem *item) const -{ - return (firstChildOfContext(item) != 0); -} - -bool SubcomponentEditorTool::isDirectChildOfContext(QGraphicsItem *item) const -{ - return (item->parentItem() == m_currentContext.top()); -} - -bool SubcomponentEditorTool::itemIsChildOfQmlSubComponent(QGraphicsItem *item) const -{ - if (item->parentItem() && item->parentItem() != m_currentContext.top()) { - QGraphicsObject *parent = item->parentItem()->toGraphicsObject(); - QString parentClassName = QLatin1String(parent->metaObject()->className()); - - if (parentClassName.contains(QRegExp(QLatin1String("_QMLTYPE_\\d+")))) { - return true; - } else { - return itemIsChildOfQmlSubComponent(parent); - } - } - - return false; -} - -void SubcomponentEditorTool::pushContext(QGraphicsObject *contextItem) -{ - connect(contextItem, SIGNAL(destroyed(QObject*)), this, SLOT(contextDestroyed(QObject*))); - connect(contextItem, SIGNAL(xChanged()), this, SLOT(resizeMask())); - connect(contextItem, SIGNAL(yChanged()), this, SLOT(resizeMask())); - connect(contextItem, SIGNAL(widthChanged()), this, SLOT(resizeMask())); - connect(contextItem, SIGNAL(heightChanged()), this, SLOT(resizeMask())); - connect(contextItem, SIGNAL(rotationChanged()), this, SLOT(resizeMask())); - - m_currentContext.push(contextItem); - QString title = titleForItem(contextItem); - emit contextPushed(title); - - m_path << title; - emit contextPathChanged(m_path); -} - -void SubcomponentEditorTool::aboutToPopContext() -{ - if (m_currentContext.size() > 2) { - popContext(); - emit contextPathChanged(m_path); - } else { - m_animIncrement = -0.05f; - m_animTimer->start(); - } -} - -QGraphicsObject *SubcomponentEditorTool::popContext() -{ - QGraphicsObject *popped = m_currentContext.pop(); - m_path.removeLast(); - - emit contextPopped(); - - disconnect(popped, SIGNAL(xChanged()), this, SLOT(resizeMask())); - disconnect(popped, SIGNAL(yChanged()), this, SLOT(resizeMask())); - disconnect(popped, SIGNAL(scaleChanged()), this, SLOT(resizeMask())); - disconnect(popped, SIGNAL(widthChanged()), this, SLOT(resizeMask())); - disconnect(popped, SIGNAL(heightChanged()), this, SLOT(resizeMask())); - - if (m_currentContext.size() > 1) { - QGraphicsObject *item = m_currentContext.top(); - m_mask->setCurrentItem(item); - m_mask->setOpacity(MaxOpacity); - m_mask->setVisible(true); - } else { - m_mask->setVisible(false); - } - - return popped; -} - -void SubcomponentEditorTool::resizeMask() -{ - QGraphicsObject *item = m_currentContext.top(); - m_mask->setCurrentItem(item); -} - -QGraphicsObject *SubcomponentEditorTool::currentRootItem() const -{ - return m_currentContext.top(); -} - -void SubcomponentEditorTool::contextDestroyed(QObject *contextToDestroy) -{ - disconnect(contextToDestroy, SIGNAL(destroyed(QObject*)), - this, SLOT(contextDestroyed(QObject*))); - - // pop out the whole context - it might not be safe anymore. - while (m_currentContext.size() > 1) { - m_currentContext.pop(); - m_path.removeLast(); - emit contextPopped(); - } - m_mask->setVisible(false); - - emit contextPathChanged(m_path); -} - -QGraphicsObject *SubcomponentEditorTool::setContext(int contextIndex) -{ - Q_ASSERT(contextIndex >= 0); - - // sometimes we have to delete the context while user was still clicking around, - // so just bail out. - if (contextIndex >= m_currentContext.size() -1) - return 0; - - while (m_currentContext.size() - 1 > contextIndex) { - popContext(); - } - emit contextPathChanged(m_path); - - return m_currentContext.top(); -} - -int SubcomponentEditorTool::contextIndex() const -{ - return m_currentContext.size() - 1; -} - -QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/declarativeobserver/editor/subcomponenteditortool_p.h b/src/plugins/qmltooling/declarativeobserver/editor/subcomponenteditortool_p.h deleted file mode 100644 index 29b29565bb..0000000000 --- a/src/plugins/qmltooling/declarativeobserver/editor/subcomponenteditortool_p.h +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef SUBCOMPONENTEDITORTOOL_H -#define SUBCOMPONENTEDITORTOOL_H - -#include "abstractliveedittool_p.h" - -#include -#include - -QT_FORWARD_DECLARE_CLASS(QGraphicsObject) -QT_FORWARD_DECLARE_CLASS(QPoint) -QT_FORWARD_DECLARE_CLASS(QTimer) - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class SubcomponentMaskLayerItem; - -class SubcomponentEditorTool : public AbstractLiveEditTool -{ - Q_OBJECT - -public: - SubcomponentEditorTool(QDeclarativeViewObserver *view); - ~SubcomponentEditorTool(); - - void mousePressEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - void mouseDoubleClickEvent(QMouseEvent *event); - - void hoverMoveEvent(QMouseEvent *event); - void wheelEvent(QWheelEvent *event); - - void keyPressEvent(QKeyEvent *event); - void keyReleaseEvent(QKeyEvent *keyEvent); - void itemsAboutToRemoved(const QList &itemList); - - void clear(); - - bool containsCursor(const QPoint &mousePos) const; - bool itemIsChildOfQmlSubComponent(QGraphicsItem *item) const; - - bool isChildOfContext(QGraphicsItem *item) const; - bool isDirectChildOfContext(QGraphicsItem *item) const; - QGraphicsItem *firstChildOfContext(QGraphicsItem *item) const; - - void setCurrentItem(QGraphicsItem *contextObject); - - void pushContext(QGraphicsObject *contextItem); - - QGraphicsObject *currentRootItem() const; - QGraphicsObject *setContext(int contextIndex); - int contextIndex() const; - -signals: - void exitContextRequested(); - void cleared(); - void contextPushed(const QString &contextTitle); - void contextPopped(); - void contextPathChanged(const QStringList &path); - -protected: - void selectedItemsChanged(const QList &itemList); - -private slots: - void animate(); - void contextDestroyed(QObject *context); - void resizeMask(); - -private: - QGraphicsObject *popContext(); - void aboutToPopContext(); - -private: - QStack m_currentContext; - QStringList m_path; - - qreal m_animIncrement; - SubcomponentMaskLayerItem *m_mask; - QTimer *m_animTimer; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // SUBCOMPONENTEDITORTOOL_H diff --git a/src/plugins/qmltooling/declarativeobserver/qdeclarativeobserverprotocol.h b/src/plugins/qmltooling/declarativeobserver/qdeclarativeobserverprotocol.h index 836163e4d7..62722acce7 100644 --- a/src/plugins/qmltooling/declarativeobserver/qdeclarativeobserverprotocol.h +++ b/src/plugins/qmltooling/declarativeobserver/qdeclarativeobserverprotocol.h @@ -65,7 +65,6 @@ public: ChangeTool = 1, ClearComponentCache = 2, ColorChanged = 3, - ContextPathUpdated = 4, CreateObject = 5, CurrentObjectsChanged = 6, DestroyObject = 7, @@ -75,7 +74,6 @@ public: Reloaded = 11, SetAnimationSpeed = 12, SetAnimationPaused = 18, - SetContextPathIdx = 13, SetCurrentObjects = 14, SetDesignMode = 15, ShowAppOnTop = 16, diff --git a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp index 5d2ab09b2f..a49a75868a 100644 --- a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp +++ b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp @@ -51,7 +51,6 @@ #include "editor/colorpickertool_p.h" #include "editor/livelayeritem_p.h" #include "editor/boundingrecthighlighter_p.h" -#include "editor/subcomponenteditortool_p.h" #include "editor/qmltoolbar_p.h" #include @@ -138,7 +137,6 @@ QDeclarativeViewObserver::QDeclarativeViewObserver(QDeclarativeView *view, data->zoomTool = new ZoomTool(this); data->colorPickerTool = new ColorPickerTool(this); data->boundingRectHighlighter = new BoundingRectHighlighter(this); - data->subcomponentEditorTool = new SubcomponentEditorTool(this); data->currentTool = data->selectionTool; // to capture ChildRemoved event when viewport changes @@ -158,14 +156,6 @@ QDeclarativeViewObserver::QDeclarativeViewObserver(QDeclarativeView *view, connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), this, SLOT(sendColorChanged(QColor))); - connect(data->subcomponentEditorTool, SIGNAL(cleared()), SIGNAL(inspectorContextCleared())); - connect(data->subcomponentEditorTool, SIGNAL(contextPushed(QString)), - SIGNAL(inspectorContextPushed(QString))); - connect(data->subcomponentEditorTool, SIGNAL(contextPopped()), - SIGNAL(inspectorContextPopped())); - connect(data->subcomponentEditorTool, SIGNAL(contextPathChanged(QStringList)), - this, SLOT(sendContextPathUpdated(QStringList))); - data->_q_changeToSingleSelectTool(); } @@ -173,15 +163,6 @@ QDeclarativeViewObserver::~QDeclarativeViewObserver() { } -void QDeclarativeViewObserver::setObserverContext(int contextIndex) -{ - if (data->subcomponentEditorTool->contextIndex() != contextIndex) { - QGraphicsObject *object = data->subcomponentEditorTool->setContext(contextIndex); - if (object) - setSelectedItems(QList() << object); - } -} - void QDeclarativeViewObserverPrivate::_q_setToolBoxVisible(bool visible) { #if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5) && !defined(Q_WS_SIMULATOR) @@ -196,7 +177,6 @@ void QDeclarativeViewObserverPrivate::_q_setToolBoxVisible(bool visible) void QDeclarativeViewObserverPrivate::_q_reloadView() { - subcomponentEditorTool->clear(); clearHighlight(); emit q->reloadRequested(); } @@ -318,10 +298,8 @@ bool QDeclarativeViewObserver::mouseMoveEvent(QMouseEvent *event) declarativeView()->setToolTip(QString()); } if (event->buttons()) { - data->subcomponentEditorTool->mouseMoveEvent(event); data->currentTool->mouseMoveEvent(event); } else { - data->subcomponentEditorTool->hoverMoveEvent(event); data->currentTool->hoverMoveEvent(event); } return true; @@ -331,7 +309,6 @@ bool QDeclarativeViewObserver::mouseReleaseEvent(QMouseEvent *event) { if (!data->designModeBehavior) return false; - data->subcomponentEditorTool->mouseReleaseEvent(event); data->cursorPos = event->pos(); data->currentTool->mouseReleaseEvent(event); @@ -366,11 +343,6 @@ bool QDeclarativeViewObserver::keyReleaseEvent(QKeyEvent *event) case Qt::Key_Z: data->_q_changeToZoomTool(); break; - case Qt::Key_Enter: - case Qt::Key_Return: - if (!data->selectedItems().isEmpty()) - data->subcomponentEditorTool->setCurrentItem(data->selectedItems().first()); - break; case Qt::Key_Space: setAnimationPaused(!data->animationPaused); break; @@ -435,41 +407,11 @@ void QDeclarativeViewObserverPrivate::_q_removeFromSelection(QObject *obj) setSelectedItems(items); } -QGraphicsItem *QDeclarativeViewObserverPrivate::currentRootItem() const -{ - return subcomponentEditorTool->currentRootItem(); -} - -bool QDeclarativeViewObserver::mouseDoubleClickEvent(QMouseEvent *event) +bool QDeclarativeViewObserver::mouseDoubleClickEvent(QMouseEvent * /*event*/) { if (!data->designModeBehavior) return false; - if (data->currentToolMode != Constants::SelectionToolMode - && data->currentToolMode != Constants::MarqueeSelectionToolMode) - return true; - - QGraphicsItem *itemToEnter = 0; - QList itemList = data->view->items(event->pos()); - data->filterForSelection(itemList); - - if (data->selectedItems().isEmpty() && !itemList.isEmpty()) { - itemToEnter = itemList.first(); - } else if (!data->selectedItems().isEmpty() && !itemList.isEmpty()) { - itemToEnter = itemList.first(); - } - - if (itemToEnter) - itemToEnter = data->subcomponentEditorTool->firstChildOfContext(itemToEnter); - - data->subcomponentEditorTool->setCurrentItem(itemToEnter); - data->subcomponentEditorTool->mouseDoubleClickEvent(event); - - if ((event->buttons() & Qt::LeftButton) && itemToEnter) { - if (QGraphicsObject *objectToEnter = itemToEnter->toGraphicsObject()) - setSelectedItems(QList() << objectToEnter); - } - return true; } @@ -481,16 +423,6 @@ bool QDeclarativeViewObserver::wheelEvent(QWheelEvent *event) return true; } -void QDeclarativeViewObserverPrivate::enterContext(QGraphicsItem *itemToEnter) -{ - QGraphicsItem *itemUnderCurrentContext = itemToEnter; - if (itemUnderCurrentContext) - itemUnderCurrentContext = subcomponentEditorTool->firstChildOfContext(itemToEnter); - - if (itemUnderCurrentContext) - subcomponentEditorTool->setCurrentItem(itemToEnter); -} - void QDeclarativeViewObserver::setDesignModeBehavior(bool value) { emit designModeBehaviorChanged(value); @@ -500,14 +432,6 @@ void QDeclarativeViewObserver::setDesignModeBehavior(bool value) sendDesignModeBehavior(value); data->designModeBehavior = value; - if (data->subcomponentEditorTool) { - data->subcomponentEditorTool->clear(); - data->clearHighlight(); - data->setSelectedItems(QList()); - - if (data->view->rootObject()) - data->subcomponentEditorTool->pushContext(data->view->rootObject()); - } if (!data->designModeBehavior) data->clearEditorItems(); @@ -628,13 +552,7 @@ void QDeclarativeViewObserverPrivate::clearHighlight() boundingRectHighlighter->clear(); } -void QDeclarativeViewObserverPrivate::highlight(QGraphicsObject * item, ContextFlags flags) -{ - highlight(QList() << item, flags); -} - -void QDeclarativeViewObserverPrivate::highlight(const QList &items, - ContextFlags flags) +void QDeclarativeViewObserverPrivate::highlight(const QList &items) { if (items.isEmpty()) return; @@ -642,8 +560,6 @@ void QDeclarativeViewObserverPrivate::highlight(const QList & QList objectList; foreach (QGraphicsItem *item, items) { QGraphicsItem *child = item; - if (flags & ContextSensitive) - child = subcomponentEditorTool->firstChildOfContext(item); if (child) { QGraphicsObject *childObject = child->toGraphicsObject(); @@ -655,30 +571,24 @@ void QDeclarativeViewObserverPrivate::highlight(const QList & boundingRectHighlighter->highlight(objectList); } -bool QDeclarativeViewObserverPrivate::mouseInsideContextItem() const -{ - return subcomponentEditorTool->containsCursor(cursorPos.toPoint()); -} - QList QDeclarativeViewObserverPrivate::selectableItems( const QPointF &scenePos) const { QList itemlist = view->scene()->items(scenePos); - return filterForCurrentContext(itemlist); + return filterForSelection(itemlist); } QList QDeclarativeViewObserverPrivate::selectableItems(const QPoint &pos) const { QList itemlist = view->items(pos); - return filterForCurrentContext(itemlist); + return filterForSelection(itemlist); } QList QDeclarativeViewObserverPrivate::selectableItems( const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const { QList itemlist = view->scene()->items(sceneRect, selectionMode); - - return filterForCurrentContext(itemlist); + return filterForSelection(itemlist); } void QDeclarativeViewObserverPrivate::_q_changeToSingleSelectTool() @@ -738,11 +648,6 @@ void QDeclarativeViewObserverPrivate::_q_changeToColorPickerTool() q->sendCurrentTool(Constants::ColorPickerMode); } -void QDeclarativeViewObserverPrivate::_q_changeContextPathIndex(int index) -{ - subcomponentEditorTool->setContext(index); -} - void QDeclarativeViewObserver::setAnimationSpeed(qreal slowDownFactor) { Q_ASSERT(slowDownFactor > 0); @@ -794,38 +699,13 @@ QList QDeclarativeViewObserverPrivate::filterForSelection( QList &itemlist) const { foreach (QGraphicsItem *item, itemlist) { - if (isEditorItem(item) || !subcomponentEditorTool->isChildOfContext(item)) + if (isEditorItem(item)) itemlist.removeOne(item); } return itemlist; } -QList QDeclarativeViewObserverPrivate::filterForCurrentContext( - QList &itemlist) const -{ - foreach (QGraphicsItem *item, itemlist) { - - if (isEditorItem(item) || !subcomponentEditorTool->isDirectChildOfContext(item)) { - - // if we're a child, but not directly, replace with the parent that is directly in context. - if (QGraphicsItem *contextParent = subcomponentEditorTool->firstChildOfContext(item)) { - if (contextParent != item) { - if (itemlist.contains(contextParent)) { - itemlist.removeOne(item); - } else { - itemlist.replace(itemlist.indexOf(item), contextParent); - } - } - } else { - itemlist.removeOne(item); - } - } - } - - return itemlist; -} - bool QDeclarativeViewObserverPrivate::isEditorItem(QGraphicsItem *item) const { return (item->type() == Constants::EditorItemType @@ -835,14 +715,8 @@ bool QDeclarativeViewObserverPrivate::isEditorItem(QGraphicsItem *item) const void QDeclarativeViewObserverPrivate::_q_onStatusChanged(QDeclarativeView::Status status) { - if (status == QDeclarativeView::Ready) { - if (view->rootObject()) { - if (subcomponentEditorTool->contextIndex() != -1) - subcomponentEditorTool->clear(); - subcomponentEditorTool->pushContext(view->rootObject()); - } + if (status == QDeclarativeView::Ready) q->sendReloaded(); - } } void QDeclarativeViewObserverPrivate::_q_onCurrentObjectsChanged(QList objects) @@ -850,17 +724,15 @@ void QDeclarativeViewObserverPrivate::_q_onCurrentObjectsChanged(QList QList items; QList gfxObjects; foreach (QObject *obj, objects) { - QDeclarativeItem* declarativeItem = qobject_cast(obj); - if (declarativeItem) { + if (QDeclarativeItem *declarativeItem = qobject_cast(obj)) { items << declarativeItem; - if (QGraphicsObject *gfxObj = declarativeItem->toGraphicsObject()) - gfxObjects << gfxObj; + gfxObjects << declarativeItem; } } if (designModeBehavior) { setSelectedItemsForTools(items); clearHighlight(); - highlight(gfxObjects, QDeclarativeViewObserverPrivate::IgnoreContext); + highlight(gfxObjects); } } @@ -943,9 +815,7 @@ void QDeclarativeViewObserver::handleMessage(const QByteArray &message) for (int i = 0; i < itemCount; ++i) { int debugId = -1; ds >> debugId; - QObject *obj = QDeclarativeDebugService::objectForId(debugId); - - if (obj) + if (QObject *obj = QDeclarativeDebugService::objectForId(debugId)) selectedObjects << obj; } @@ -1039,12 +909,6 @@ void QDeclarativeViewObserver::handleMessage(const QByteArray &message) } break; } - case ObserverProtocol::SetContextPathIdx: { - int contextPathIndex; - ds >> contextPathIndex; - data->_q_changeContextPathIndex(contextPathIndex); - break; - } case ObserverProtocol::ClearComponentCache: { data->_q_clearComponentCache(); break; @@ -1145,17 +1009,6 @@ void QDeclarativeViewObserver::sendColorChanged(const QColor &color) data->debugService->sendMessage(message); } -void QDeclarativeViewObserver::sendContextPathUpdated(const QStringList &contextPath) -{ - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ds << ObserverProtocol::ContextPathUpdated - << contextPath; - - data->debugService->sendMessage(message); -} - QString QDeclarativeViewObserver::idStringForObject(QObject *obj) const { int id = QDeclarativeDebugService::idForObject(obj); diff --git a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p.h b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p.h index 86d0d95321..5c70c98d9f 100644 --- a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p.h +++ b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p.h @@ -89,7 +89,6 @@ public: public Q_SLOTS: void sendColorChanged(const QColor &color); - void sendContextPathUpdated(const QStringList &contextPath); void setDesignModeBehavior(bool value); bool designModeBehavior(); @@ -99,8 +98,6 @@ public Q_SLOTS: void setAnimationSpeed(qreal factor); void setAnimationPaused(bool paused); - void setObserverContext(int contextIndex); - Q_SIGNALS: void designModeBehaviorChanged(bool inDesignMode); void showAppOnTopChanged(bool showAppOnTop); @@ -114,10 +111,6 @@ Q_SIGNALS: void animationSpeedChanged(qreal factor); void animationPausedChanged(bool paused); - void inspectorContextCleared(); - void inspectorContextPushed(const QString &contextTitle); - void inspectorContextPopped(); - protected: bool eventFilter(QObject *obj, QEvent *event); diff --git a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p_p.h b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p_p.h index 880959156b..19e48984f4 100644 --- a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p_p.h +++ b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p_p.h @@ -61,7 +61,6 @@ class ZoomTool; class ColorPickerTool; class LiveLayerItem; class BoundingRectHighlighter; -class SubcomponentEditorTool; class ToolBox; class AbstractLiveEditTool; @@ -69,11 +68,6 @@ class QDeclarativeViewObserverPrivate : public QObject { Q_OBJECT public: - enum ContextFlags { - IgnoreContext, - ContextSensitive - }; - QDeclarativeViewObserverPrivate(QDeclarativeViewObserver *); ~QDeclarativeViewObserverPrivate(); @@ -92,7 +86,6 @@ public: LiveSelectionTool *selectionTool; ZoomTool *zoomTool; ColorPickerTool *colorPickerTool; - SubcomponentEditorTool *subcomponentEditorTool; LiveLayerItem *manipulatorLayer; BoundingRectHighlighter *boundingRectHighlighter; @@ -110,7 +103,6 @@ public: void clearEditorItems(); void createToolBox(); void changeToSelectTool(); - QList filterForCurrentContext(QList &itemlist) const; QList filterForSelection(QList &itemlist) const; QList selectableItems(const QPoint &pos) const; @@ -125,17 +117,12 @@ public: Constants::ToolFlags flags = Constants::NoToolFlags); void clearHighlight(); - void highlight(const QList &item, - ContextFlags flags = ContextSensitive); - void highlight(QGraphicsObject *item, ContextFlags flags = ContextSensitive); + void highlight(const QList &item); + inline void highlight(QGraphicsObject *item) + { highlight(QList() << item); } - bool mouseInsideContextItem() const; bool isEditorItem(QGraphicsItem *item) const; - QGraphicsItem *currentRootItem() const; - - void enterContext(QGraphicsItem *itemToEnter); - public slots: void _q_setToolBoxVisible(bool visible); @@ -151,7 +138,6 @@ public slots: void _q_changeToMarqueeSelectTool(); void _q_changeToZoomTool(); void _q_changeToColorPickerTool(); - void _q_changeContextPathIndex(int index); void _q_clearComponentCache(); void _q_removeFromSelection(QObject *); -- cgit v1.2.3 From 9d8ebdf9d85c254ff201b6c5bbb03a4db4bcbd9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Wed, 25 May 2011 13:42:48 +0200 Subject: DeclarativeObserver: Fixed duplicates in item selection Only add items to the current selection that aren't already part of it. Also removed checking item for null, since it doesn't make sense to include null pointers in the list of items to select. Task-number: QTCREATORBUG-3426 Change-Id: I5a365570f87f72665b3382d05ca9937f56e8956b Reviewed-by: Christiaan Janssen (cherry picked from commit f75fda0365a4e4bf1f26dedc40d96d37a2599174) --- .../qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp index a49a75868a..bb238310a1 100644 --- a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp +++ b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp @@ -494,8 +494,8 @@ void QDeclarativeViewObserverPrivate::setSelectedItemsForTools(const QListtoGraphicsObject()) { + if (QGraphicsObject *obj = item->toGraphicsObject()) { + if (!currentSelection.contains(obj)) { QObject::connect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(_q_removeFromSelection(QObject*))); currentSelection.append(obj); -- cgit v1.2.3