Commit 16e5b618 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner: Turn FormEditor item into QGraphicsItem

QGraphicsObject is a QObject and significantly heavier
then QGraphicsItem. There is no need to use
QGraphicsObject in our case.
Using QGraphicsItem instead is simply good practice.

Change-Id: I65f9db85eace25fd0e7873093e903d923eb338dc
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent fde2bc25
......@@ -52,7 +52,7 @@ public:
private:
QPointer<LayerItem> m_layerItem;
QPointer<FormEditorItem> m_formEditorItem;
FormEditorItem *m_formEditorItem = nullptr;
QPointer<AnchorIndicatorGraphicsItem> m_indicatorTopShape;
QPointer<AnchorIndicatorGraphicsItem> m_indicatorBottomShape;
QPointer<AnchorIndicatorGraphicsItem> m_indicatorLeftShape;
......
......@@ -50,7 +50,7 @@ public:
private:
QPointer<LayerItem> m_layerItem;
QPointer<FormEditorItem> m_formEditorItem;
FormEditorItem *m_formEditorItem = nullptr;
QPointer<BindingIndicatorGraphicsItem> m_indicatorTopShape;
QPointer<BindingIndicatorGraphicsItem> m_indicatorBottomShape;
QPointer<BindingIndicatorGraphicsItem> m_indicatorLeftShape;
......
......@@ -61,7 +61,7 @@ void DragTool::clear()
{
m_moveManipulator.clear();
m_selectionIndicator.clear();
m_movingItem.clear();
m_movingItem = nullptr;
}
void DragTool::mousePressEvent(const QList<QGraphicsItem*> &, QGraphicsSceneMouseEvent *)
......@@ -117,7 +117,7 @@ void DragTool::beginWithPoint(const QPointF &beginPoint)
{
m_movingItem = scene()->itemForQmlItemNode(m_dragNode);
m_moveManipulator.setItem(m_movingItem.data());
m_moveManipulator.setItem(m_movingItem);
m_moveManipulator.begin(beginPoint);
}
......@@ -167,9 +167,9 @@ FormEditorItem* DragTool::targetContainerOrRootItem(const QList<QGraphicsItem*>
void DragTool::formEditorItemsChanged(const QList<FormEditorItem*> & itemList)
{
if (m_movingItem && itemList.contains(m_movingItem.data())) {
if (m_movingItem && itemList.contains(m_movingItem)) {
QList<FormEditorItem*> updateItemList;
updateItemList.append(m_movingItem.data());
updateItemList.append(m_movingItem);
m_selectionIndicator.updateItems(updateItemList);
}
}
......@@ -373,7 +373,7 @@ void DragTool::end(Snapper::Snapping useSnapping)
void DragTool::move(const QPointF &scenePosition, const QList<QGraphicsItem*> &itemList)
{
if (m_movingItem) {
FormEditorItem *containerItem = targetContainerOrRootItem(itemList, m_movingItem.data());
FormEditorItem *containerItem = targetContainerOrRootItem(itemList, m_movingItem);
if (containerItem && m_movingItem->parentItem() &&
containerItem != m_movingItem->parentItem()) {
......
......@@ -92,7 +92,7 @@ protected:
private:
MoveManipulator m_moveManipulator;
SelectionIndicator m_selectionIndicator;
QPointer<FormEditorItem> m_movingItem;
FormEditorItem *m_movingItem = nullptr;
RewriterTransaction m_rewriterTransaction;
QmlItemNode m_dragNode;
bool m_blockMove;
......
......@@ -47,7 +47,7 @@ FormEditorScene *FormEditorItem::scene() const {
}
FormEditorItem::FormEditorItem(const QmlItemNode &qmlItemNode, FormEditorScene* scene)
: QGraphicsObject(scene->formLayerItem()),
: QGraphicsItem(scene->formLayerItem()),
m_snappingLineCreator(this),
m_qmlItemNode(qmlItemNode),
m_borderWidth(1.0),
......
......@@ -45,10 +45,8 @@ namespace Internal {
class MoveController;
}
class QMLDESIGNERCORE_EXPORT FormEditorItem : public QGraphicsObject
class QMLDESIGNERCORE_EXPORT FormEditorItem : public QGraphicsItem
{
Q_OBJECT
friend class QmlDesigner::FormEditorScene;
public:
~FormEditorItem();
......
......@@ -100,7 +100,7 @@ void FormEditorView::setupFormEditorItemTree(const QmlItemNode &qmlItemNode)
foreach (const QmlObjectNode &nextNode, qmlItemNode.allDirectSubNodes()) //TODO instance children
//If the node has source for components/custom parsers we ignore it.
if (QmlItemNode(nextNode).isValid() && nextNode.modelNode().nodeSourceType() == ModelNode::NodeWithoutSource)
if (QmlItemNode::isValidQmlItemNode(nextNode) && nextNode.modelNode().nodeSourceType() == ModelNode::NodeWithoutSource)
setupFormEditorItemTree(nextNode.toQmlItemNode());
}
......@@ -216,8 +216,7 @@ void FormEditorView::nodeAboutToBeRemoved(const ModelNode &removedNode)
void FormEditorView::rootNodeTypeChanged(const QString &/*type*/, int /*majorVersion*/, int /*minorVersion*/)
{
foreach (FormEditorItem *item, m_scene->allFormEditorItems()) {
item->setParentItem(0);
item->setParent(0);
item->setParentItem(nullptr);
}
foreach (FormEditorItem *item, m_scene->allFormEditorItems()) {
......
......@@ -44,7 +44,7 @@ public:
QPointer<LayerItem> layerItem;
QPointer<FormEditorItem> formEditorItem;
FormEditorItem *formEditorItem = nullptr;
QSharedPointer<ResizeHandleItem> topLeftItem;
QSharedPointer<ResizeHandleItem> topRightItem;
QSharedPointer<ResizeHandleItem> bottomLeftItem;
......@@ -262,7 +262,7 @@ void ResizeController::updatePosition()
FormEditorItem* ResizeController::formEditorItem() const
{
return m_data->formEditorItem.data();
return m_data->formEditorItem;
}
bool ResizeController::isTopLeftHandle(const ResizeHandleItem *handle) const
......
......@@ -159,7 +159,7 @@ void ColorTool::itemsAboutToRemoved(const QList<FormEditorItem*> &removedItemLis
if (m_colorDialog.isNull())
return;
if (removedItemList.contains(m_formEditorItem.data()))
if (removedItemList.contains(m_formEditorItem))
view()->changeToSelectionTool();
}
......@@ -167,12 +167,12 @@ void ColorTool::selectedItemsChanged(const QList<FormEditorItem*> &itemList)
{
if (m_colorDialog.data()
&& m_oldColor.isValid())
m_formEditorItem.data()->qmlItemNode().setVariantProperty("color", m_oldColor);
m_formEditorItem->qmlItemNode().setVariantProperty("color", m_oldColor);
if (!itemList.isEmpty()
&& itemList.first()->qmlItemNode().modelNode().metaInfo().hasProperty("color")) {
m_formEditorItem = itemList.first();
m_oldColor = m_formEditorItem.data()->qmlItemNode().modelValue("color").value<QColor>();
m_oldColor = m_formEditorItem->qmlItemNode().modelValue("color").value<QColor>();
if (m_colorDialog.isNull()) {
m_colorDialog = new QColorDialog(view()->formEditorWidget()->parentWidget());
......@@ -227,9 +227,9 @@ void ColorTool::colorDialogRejected()
{
if (m_formEditorItem) {
if (m_oldColor.isValid())
m_formEditorItem.data()->qmlItemNode().setVariantProperty("color", m_oldColor);
m_formEditorItem->qmlItemNode().setVariantProperty("color", m_oldColor);
else
m_formEditorItem.data()->qmlItemNode().removeProperty("color");
m_formEditorItem->qmlItemNode().removeProperty("color");
}
......@@ -239,7 +239,7 @@ void ColorTool::colorDialogRejected()
void ColorTool::currentColorChanged(const QColor &color)
{
if (m_formEditorItem) {
m_formEditorItem.data()->qmlItemNode().setVariantProperty("color", color);
m_formEditorItem->qmlItemNode().setVariantProperty("color", color);
}
}
......
......@@ -82,7 +82,7 @@ private:
private:
QPointer<QColorDialog> m_colorDialog;
QPointer<FormEditorItem> m_formEditorItem;
FormEditorItem *m_formEditorItem = nullptr;
QColor m_oldColor;
};
......
......@@ -179,7 +179,7 @@ void SourceTool::mouseDoubleClickEvent(const QList<QGraphicsItem*> &itemList, QG
void SourceTool::itemsAboutToRemoved(const QList<FormEditorItem*> &removedItemList)
{
if (removedItemList.contains(m_formEditorItem.data()))
if (removedItemList.contains(m_formEditorItem))
view()->changeToSelectionTool();
}
......@@ -193,7 +193,7 @@ void SourceTool::selectedItemsChanged(const QList<FormEditorItem*> &itemList)
{
if (!itemList.isEmpty()) {
m_formEditorItem = itemList.first();
m_oldFileName = m_formEditorItem.data()->qmlItemNode().modelValue("source").toString();
m_oldFileName = m_formEditorItem->qmlItemNode().modelValue("source").toString();
QString openDirectory = baseDirectory(view()->model()->fileUrl());
if (openDirectory.isEmpty())
......@@ -246,7 +246,7 @@ void SourceTool::fileSelected(const QString &fileName)
QDir modelFileDirectory = QFileInfo(modelFilePath).absoluteDir();
QString relativeFilePath = modelFileDirectory.relativeFilePath(fileName);
if (m_oldFileName != relativeFilePath) {
m_formEditorItem.data()->qmlItemNode().setVariantProperty("source", relativeFilePath);
m_formEditorItem->qmlItemNode().setVariantProperty("source", relativeFilePath);
}
}
......
......@@ -83,7 +83,7 @@ private:
/* members */
QPointer<FormEditorItem> m_formEditorItem;
FormEditorItem *m_formEditorItem = nullptr;
QString m_oldFileName;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment