diff options
author | Lasse Holmstedt <lasse.holmstedt@nokia.com> | 2010-07-15 13:38:10 +0200 |
---|---|---|
committer | Lasse Holmstedt <lasse.holmstedt@nokia.com> | 2010-07-15 13:40:16 +0200 |
commit | 0d163379dfe9f6080bc3412e6bbefa9d58f20bf1 (patch) | |
tree | 4aa65e0e7698a8fd2525a8f250eec8e0cf1b0969 /src/tools | |
parent | 28867b787fe4384d9a66768b55c0fe3ddb4f9887 (diff) | |
download | qt-creator-0d163379dfe9f6080bc3412e6bbefa9d58f20bf1.tar.gz |
Changed handling of selected items to use weak pointers
graphics items could be destroyed after selecting something.
Diffstat (limited to 'src/tools')
4 files changed, 29 insertions, 15 deletions
diff --git a/src/tools/qml/qmlobserver/editor/abstractformeditortool.cpp b/src/tools/qml/qmlobserver/editor/abstractformeditortool.cpp index b508b7eea3..c939cc7b79 100644 --- a/src/tools/qml/qmlobserver/editor/abstractformeditortool.cpp +++ b/src/tools/qml/qmlobserver/editor/abstractformeditortool.cpp @@ -60,15 +60,14 @@ QGraphicsScene* AbstractFormEditorTool::scene() const return view()->scene(); } -void AbstractFormEditorTool::setItems(const QList<QGraphicsItem*> &itemList) +void AbstractFormEditorTool::updateSelectedItems() { - m_itemList = itemList; - selectedItemsChanged(m_itemList); + selectedItemsChanged(items()); } QList<QGraphicsItem*> AbstractFormEditorTool::items() const { - return m_itemList; + return view()->selectedItems(); } bool AbstractFormEditorTool::topItemIsMovable(const QList<QGraphicsItem*> & itemList) diff --git a/src/tools/qml/qmlobserver/editor/abstractformeditortool.h b/src/tools/qml/qmlobserver/editor/abstractformeditortool.h index ae27805ab0..c59e031dec 100644 --- a/src/tools/qml/qmlobserver/editor/abstractformeditortool.h +++ b/src/tools/qml/qmlobserver/editor/abstractformeditortool.h @@ -74,7 +74,7 @@ public: virtual void clear() = 0; virtual void graphicsObjectsChanged(const QList<QGraphicsObject*> &itemList) = 0; - void setItems(const QList<QGraphicsItem*> &itemList); + void updateSelectedItems(); QList<QGraphicsItem*> items() const; bool topItemIsMovable(const QList<QGraphicsItem*> &itemList); @@ -89,7 +89,7 @@ public: static QDeclarativeItem *toQDeclarativeItem(QGraphicsItem *item); protected: - virtual void selectedItemsChanged(const QList<QGraphicsItem*> &itemList) = 0; + virtual void selectedItemsChanged(const QList<QGraphicsItem*> &objectList) = 0; QDeclarativeDesignView *view() const; QGraphicsScene* scene() const; diff --git a/src/tools/qml/qmlobserver/qdeclarativedesignview.cpp b/src/tools/qml/qmlobserver/qdeclarativedesignview.cpp index f1afaaa40e..c8019f2653 100644 --- a/src/tools/qml/qmlobserver/qdeclarativedesignview.cpp +++ b/src/tools/qml/qmlobserver/qdeclarativedesignview.cpp @@ -262,13 +262,29 @@ void QDeclarativeDesignView::changeTool(Constants::DesignTool tool, Constants::T void QDeclarativeDesignView::setSelectedItems(QList<QGraphicsItem *> items) { - m_currentSelection = items; - m_currentTool->setItems(items); + m_currentSelection.clear(); + foreach(QGraphicsItem *item, items) { + if (item) { + QGraphicsObject *obj = item->toGraphicsObject(); + if (obj) + m_currentSelection << obj; + } + } + m_currentTool->updateSelectedItems(); } -QList<QGraphicsItem *> QDeclarativeDesignView::selectedItems() const +QList<QGraphicsItem *> QDeclarativeDesignView::selectedItems() { - return m_currentSelection; + QList<QGraphicsItem *> selection; + foreach(const QWeakPointer<QGraphicsObject> &selectedObject, m_currentSelection) { + if (selectedObject.isNull()) { + m_currentSelection.removeOne(selectedObject); + } else { + selection << selectedObject.data(); + } + } + + return selection; } AbstractFormEditorTool *QDeclarativeDesignView::currentTool() const @@ -333,8 +349,6 @@ QList<QGraphicsItem*> QDeclarativeDesignView::selectableItems(const QRectF &scen void QDeclarativeDesignView::changeToSingleSelectTool() { - //qDebug() << "changing to selection tool"; - m_currentToolMode = Constants::SelectionToolMode; m_selectionTool->setRubberbandSelectionMode(false); @@ -352,7 +366,7 @@ void QDeclarativeDesignView::changeToSelectTool() m_currentTool->clear(); m_currentTool = m_selectionTool; m_currentTool->clear(); - m_currentTool->setItems(m_currentSelection); + m_currentTool->updateSelectedItems(); } void QDeclarativeDesignView::changeToMarqueeSelectTool() diff --git a/src/tools/qml/qmlobserver/qdeclarativedesignview.h b/src/tools/qml/qmlobserver/qdeclarativedesignview.h index fae5fca983..332d7f03fb 100644 --- a/src/tools/qml/qmlobserver/qdeclarativedesignview.h +++ b/src/tools/qml/qmlobserver/qdeclarativedesignview.h @@ -3,6 +3,7 @@ #include "qmlviewerconstants.h" #include <qdeclarativeview.h> +#include <QWeakPointer> QT_FORWARD_DECLARE_CLASS(QDeclarativeItem); QT_FORWARD_DECLARE_CLASS(QMouseEvent); @@ -32,7 +33,7 @@ public: ~QDeclarativeDesignView(); void setSelectedItems(QList<QGraphicsItem *> items); - QList<QGraphicsItem *> selectedItems() const; + QList<QGraphicsItem *> selectedItems(); AbstractFormEditorTool *currentTool() const; LayerItem *manipulatorLayer() const; @@ -102,7 +103,7 @@ private: private: QPointF m_cursorPos; - QList<QGraphicsItem *> m_currentSelection; + QList<QWeakPointer<QGraphicsObject> > m_currentSelection; Constants::DesignTool m_currentToolMode; AbstractFormEditorTool *m_currentTool; |