diff options
author | Marco Bubke <marco.bubke@digia.com> | 2013-04-08 16:43:18 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@digia.com> | 2013-04-08 17:12:29 +0200 |
commit | 0203f7499bab33c35cebdb5360f223087dc1eed1 (patch) | |
tree | 0323bc8c7ca03b5fdfda4fbd03415ac642182820 /src | |
parent | 6a3a54ea9070d7f61867ebf7354677949c552553 (diff) | |
download | qt-creator-0203f7499bab33c35cebdb5360f223087dc1eed1.tar.gz |
QmlDesigner: Introduce WeakResizeController
WeakResizeController is a wrapper class for a weak pointer to the
ResizeControllerData.
Change-Id: I9052a26e6a5c29d2e794ceecc33075d3ae9970db
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
Diffstat (limited to 'src')
4 files changed, 74 insertions, 13 deletions
diff --git a/src/plugins/qmldesigner/components/formeditor/resizecontroller.cpp b/src/plugins/qmldesigner/components/formeditor/resizecontroller.cpp index f904421ae4..ed2ce931eb 100644 --- a/src/plugins/qmldesigner/components/formeditor/resizecontroller.cpp +++ b/src/plugins/qmldesigner/components/formeditor/resizecontroller.cpp @@ -158,6 +158,11 @@ ResizeController::ResizeController(const ResizeController &other) } +ResizeController::ResizeController(const WeakResizeController &resizeController) + : m_data(resizeController.m_data.toStrongRef()) +{ +} + ResizeController::~ResizeController() { } @@ -264,11 +269,6 @@ FormEditorItem* ResizeController::formEditorItem() const return m_data->formEditorItem.data(); } -QWeakPointer<ResizeControllerData> ResizeController::weakPointer() const -{ - return m_data; -} - bool ResizeController::isTopLeftHandle(const ResizeHandleItem *handle) const { return handle == m_data->topLeftItem; @@ -309,4 +309,41 @@ bool ResizeController::isBottomHandle(const ResizeHandleItem *handle) const return handle == m_data->bottomItem; } +WeakResizeController ResizeController::toWeakResizeController() const +{ + return WeakResizeController(*this); +} + +WeakResizeController::WeakResizeController() +{ + +} + +WeakResizeController::WeakResizeController(const WeakResizeController &resizeController) + : m_data(resizeController.m_data) +{ +} + +WeakResizeController::WeakResizeController(const ResizeController &resizeController) + : m_data(resizeController.m_data.toWeakRef()) +{ +} + +WeakResizeController::~WeakResizeController() +{ +} + +WeakResizeController &WeakResizeController::operator =(const WeakResizeController &other) +{ + if (m_data != other.m_data) + m_data = other.m_data; + + return *this; +} + +ResizeController WeakResizeController::toResizeController() const +{ + return ResizeController(*this); +} + } diff --git a/src/plugins/qmldesigner/components/formeditor/resizecontroller.h b/src/plugins/qmldesigner/components/formeditor/resizecontroller.h index d0d53bef5f..e5f4737908 100644 --- a/src/plugins/qmldesigner/components/formeditor/resizecontroller.h +++ b/src/plugins/qmldesigner/components/formeditor/resizecontroller.h @@ -41,15 +41,17 @@ class LayerItem; class ResizeHandleItem; class ResizeControllerData; +class WeakResizeController; + class ResizeController { + friend class WeakResizeController; public: - friend class ResizeHandleItem; - ResizeController(); ResizeController(LayerItem *layerItem, FormEditorItem *formEditorItem); ResizeController(const ResizeController &resizeController); + ResizeController(const WeakResizeController &resizeController); ~ResizeController(); ResizeController& operator=(const ResizeController &other); @@ -73,13 +75,32 @@ public: bool isRightHandle(const ResizeHandleItem *handle) const; bool isBottomHandle(const ResizeHandleItem *handle) const; + WeakResizeController toWeakResizeController() const; + + private: // functions ResizeController(const QSharedPointer<ResizeControllerData> &data); - QWeakPointer<ResizeControllerData> weakPointer() const; private: // variables QSharedPointer<ResizeControllerData> m_data; }; +class WeakResizeController +{ + friend class ResizeController; +public: + WeakResizeController(); + WeakResizeController(const WeakResizeController &resizeController); + WeakResizeController(const ResizeController &resizeController); + ~WeakResizeController(); + + WeakResizeController& operator=(const WeakResizeController &other); + + ResizeController toResizeController() const; + +private: // variables + QWeakPointer<ResizeControllerData> m_data; +}; + } #endif // RESIZECONTROLLER_H diff --git a/src/plugins/qmldesigner/components/formeditor/resizehandleitem.cpp b/src/plugins/qmldesigner/components/formeditor/resizehandleitem.cpp index 794812ed3b..407a385cf2 100644 --- a/src/plugins/qmldesigner/components/formeditor/resizehandleitem.cpp +++ b/src/plugins/qmldesigner/components/formeditor/resizehandleitem.cpp @@ -36,7 +36,7 @@ namespace QmlDesigner { ResizeHandleItem::ResizeHandleItem(QGraphicsItem *parent, const ResizeController &resizeController) : QGraphicsPixmapItem(QPixmap(":/icon/handle/resize_handle.png"), parent), - m_resizeControllerData(resizeController.weakPointer()) + m_weakResizeController(resizeController.toWeakResizeController()) { setShapeMode(QGraphicsPixmapItem::BoundingRectShape); setOffset(-pixmap().rect().center()); @@ -44,6 +44,10 @@ ResizeHandleItem::ResizeHandleItem(QGraphicsItem *parent, const ResizeController setFlag(QGraphicsItem::ItemIgnoresTransformations, true); } +ResizeHandleItem::~ResizeHandleItem() +{ +} + void ResizeHandleItem::setHandlePosition(const QPointF & globalPosition, const QPointF & itemSpacePosition) { m_itemSpacePosition = itemSpacePosition; @@ -62,8 +66,7 @@ QPainterPath ResizeHandleItem::shape() const ResizeController ResizeHandleItem::resizeController() const { - Q_ASSERT(!m_resizeControllerData.isNull()); - return ResizeController(m_resizeControllerData.toStrongRef()); + return ResizeController(m_weakResizeController.toResizeController()); } ResizeHandleItem* ResizeHandleItem::fromGraphicsItem(QGraphicsItem *item) diff --git a/src/plugins/qmldesigner/components/formeditor/resizehandleitem.h b/src/plugins/qmldesigner/components/formeditor/resizehandleitem.h index 1dc203347c..35d68d5e8e 100644 --- a/src/plugins/qmldesigner/components/formeditor/resizehandleitem.h +++ b/src/plugins/qmldesigner/components/formeditor/resizehandleitem.h @@ -48,7 +48,7 @@ public: ResizeHandleItem(QGraphicsItem *parent, const ResizeController &resizeController); - + ~ResizeHandleItem(); void setHandlePosition(const QPointF & globalPosition, const QPointF & itemSpacePosition); int type() const; @@ -72,7 +72,7 @@ public: QPointF itemSpacePosition() const; private: - QWeakPointer<ResizeControllerData> m_resizeControllerData; + WeakResizeController m_weakResizeController; QPointF m_itemSpacePosition; }; |