Commit 1f2e1fa5 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner.navigator: keep position while reparenting

Task-number: QTCREATORBUG-3252
Change-Id: I03f335b1bc9943251dffba016ccf1d9b7b1e081e
Reviewed-on: http://codereview.qt.nokia.com/2170Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@nokia.com>
parent cdbd2344
......@@ -35,6 +35,7 @@
#include <nodeabstractproperty.h>
#include <nodelistproperty.h>
#include <nodeproperty.h>
#include <variantproperty.h>
#include <metainfo.h>
#include <qgraphicswidget.h>
#include <qmlmodelview.h>
......@@ -45,6 +46,18 @@
#include <QMimeData>
#include <QMessageBox>
#include <QApplication>
#include <QTransform>
#include <QPointF>
static inline void setScenePos(const QmlDesigner::ModelNode &modelNode,const QPointF &pos)
{
QmlDesigner::QmlItemNode parentNode = modelNode.parentProperty().parentQmlObjectNode().toQmlItemNode();
if (parentNode.isValid()) {
QPointF localPos = parentNode.instanceSceneTransform().inverted().map(pos);
modelNode.variantProperty(QLatin1String("x")) = localPos.toPoint().x();
modelNode.variantProperty(QLatin1String("y")) = localPos.toPoint().y();
}
}
namespace QmlDesigner {
......@@ -542,7 +555,14 @@ void NavigatorTreeModel::moveNodesInteractive(NodeAbstractProperty parentPropert
currentNode.removeProperty("y");
parentProperty.reparentHere(currentNode);
} else {
parentProperty.reparentHere(node);
if (QmlItemNode(node).isValid()) {
QPointF scenePos = QmlItemNode(node).instanceScenePosition();
parentProperty.reparentHere(node);
if (!scenePos.isNull())
setScenePos(node, scenePos);
} else {
parentProperty.reparentHere(node);
}
}
}
......
......@@ -38,8 +38,18 @@
#include <nodeproperty.h>
#include <nodelistproperty.h>
#include <variantproperty.h>
#include <QHeaderView>
static inline void setScenePos(const QmlDesigner::ModelNode &modelNode,const QPointF &pos)
{
QmlDesigner::QmlItemNode parentNode = modelNode.parentProperty().parentQmlObjectNode().toQmlItemNode();
if (parentNode.isValid()) {
QPointF localPos = parentNode.instanceSceneTransform().inverted().map(pos);
modelNode.variantProperty(QLatin1String("x")) = localPos.toPoint().x();
modelNode.variantProperty(QLatin1String("y")) = localPos.toPoint().y();
}
}
namespace QmlDesigner {
......@@ -275,8 +285,16 @@ void NavigatorView::leftButtonClicked()
bool blocked = blockSelectionChangedSignal(true);
foreach (const ModelNode &node, selectedModelNodes()) {
if (!node.isRootNode() && !node.parentProperty().parentModelNode().isRootNode())
node.parentProperty().parentModelNode().parentProperty().reparentHere(node);
if (!node.isRootNode() && !node.parentProperty().parentModelNode().isRootNode()) {
if (QmlItemNode(node).isValid()) {
QPointF scenePos = QmlItemNode(node).instanceScenePosition();
node.parentProperty().parentModelNode().parentProperty().reparentHere(node);
if (!scenePos.isNull())
setScenePos(node, scenePos);
} else {
node.parentProperty().parentModelNode().parentProperty().reparentHere(node);
}
}
}
updateItemSelection();
blockSelectionChangedSignal(blocked);
......@@ -294,7 +312,15 @@ void NavigatorView::rightButtonClicked()
index--;
if (index >= 0) { //for the first node the semantics are not clear enough. Wrapping would be irritating.
ModelNode newParent = node.parentProperty().toNodeListProperty().at(index);
newParent.nodeAbstractProperty(newParent.metaInfo().defaultPropertyName()).reparentHere(node);
if (QmlItemNode(node).isValid()) {
QPointF scenePos = QmlItemNode(node).instanceScenePosition();
newParent.nodeAbstractProperty(newParent.metaInfo().defaultPropertyName()).reparentHere(node);
if (!scenePos.isNull())
setScenePos(node, scenePos);
} else {
newParent.nodeAbstractProperty(newParent.metaInfo().defaultPropertyName()).reparentHere(node);
}
}
}
}
......
......@@ -80,6 +80,7 @@ public:
QRectF instancePaintedBoundingRect() const;
QTransform instanceTransform() const;
QTransform instanceSceneTransform() const;
QPointF instanceScenePosition() const;
QPointF instancePosition() const;
QSizeF instanceSize() const;
int instancePenWidth() const;
......
......@@ -244,6 +244,17 @@ QTransform QmlItemNode::instanceSceneTransform() const
return nodeInstance().sceneTransform();
}
QPointF QmlItemNode::instanceScenePosition() const
{
QmlItemNode parentNode = instanceParent().toQmlItemNode();
if (!parentNode.isValid())
parentNode = modelNode().parentProperty().parentQmlObjectNode().toQmlItemNode();
if (parentNode.isValid())
return parentNode.instanceSceneTransform().map(nodeInstance().position());
return QPointF();
}
QPointF QmlItemNode::instancePosition() const
{
return nodeInstance().position();
......
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