Commit 3cfa3762 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner: Fix wrong position for reparenting

Change-Id: Ie9d9a739e559d5cfc06849ff3e5c086e9ab2224c
DoneBy: Marco Bubke
Task-number: QTCREATORBUG-3962
Reviewed-on: http://codereview.qt.nokia.com/958Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@nokia.com>
parent b18ef1ff
......@@ -39,9 +39,10 @@ ChildrenChangedCommand::ChildrenChangedCommand()
{
}
ChildrenChangedCommand::ChildrenChangedCommand(qint32 parentInstanceId, const QVector<qint32> &children)
ChildrenChangedCommand::ChildrenChangedCommand(qint32 parentInstanceId, const QVector<qint32> &children, const QVector<InformationContainer> &informationVector)
: m_parentInstanceId(parentInstanceId),
m_childrenVector(children)
m_childrenVector(children),
m_informationVector(informationVector)
{
}
......@@ -55,11 +56,16 @@ qint32 ChildrenChangedCommand::parentInstanceId() const
return m_parentInstanceId;
}
QVector<InformationContainer> ChildrenChangedCommand::informations() const
{
return m_informationVector;
}
QDataStream &operator<<(QDataStream &out, const ChildrenChangedCommand &command)
{
out << command.parentInstanceId();
out << command.childrenInstances();
out << command.informations();
return out;
}
......@@ -67,6 +73,7 @@ QDataStream &operator>>(QDataStream &in, ChildrenChangedCommand &command)
{
in >> command.m_parentInstanceId;
in >> command.m_childrenVector;
in >> command.m_informationVector;
return in;
}
......
......@@ -35,7 +35,7 @@
#include <QMetaType>
#include <QVector>
#include "informationcontainer.h"
namespace QmlDesigner {
......@@ -44,14 +44,16 @@ class ChildrenChangedCommand
friend QDataStream &operator>>(QDataStream &in, ChildrenChangedCommand &command);
public:
ChildrenChangedCommand();
ChildrenChangedCommand(qint32 parentInstanceId, const QVector<qint32> &childrenInstances);
ChildrenChangedCommand(qint32 parentInstanceId, const QVector<qint32> &childrenInstancesconst, const QVector<InformationContainer> &informationVector);
QVector<qint32> childrenInstances() const;
qint32 parentInstanceId() const;
QVector<InformationContainer> informations() const;
private:
qint32 m_parentInstanceId;
QVector<qint32> m_childrenVector;
QVector<InformationContainer> m_informationVector;
};
QDataStream &operator<<(QDataStream &out, const ChildrenChangedCommand &command);
......
......@@ -812,17 +812,7 @@ NodeInstanceClientInterface *NodeInstanceServer::nodeInstanceClient() const
return m_nodeInstanceClient;
}
ChildrenChangedCommand NodeInstanceServer::createChildrenChangedCommand(const ServerNodeInstance &parentInstance, const QList<ServerNodeInstance> &instanceList) const
{
QVector<qint32> instanceVector;
foreach (const ServerNodeInstance &instance, instanceList)
instanceVector.append(instance.instanceId());
return ChildrenChangedCommand(parentInstance.instanceId(), instanceVector);
}
InformationChangedCommand NodeInstanceServer::createAllInformationChangedCommand(const QList<ServerNodeInstance> &instanceList, bool initial) const
static QVector<InformationContainer> createInformationVector(const QList<ServerNodeInstance> &instanceList, bool initial)
{
QVector<InformationContainer> informationVector;
......@@ -894,7 +884,23 @@ InformationChangedCommand NodeInstanceServer::createAllInformationChangedCommand
}
return InformationChangedCommand(informationVector);
return informationVector;
}
ChildrenChangedCommand NodeInstanceServer::createChildrenChangedCommand(const ServerNodeInstance &parentInstance, const QList<ServerNodeInstance> &instanceList) const
{
QVector<qint32> instanceVector;
foreach (const ServerNodeInstance &instance, instanceList)
instanceVector.append(instance.instanceId());
return ChildrenChangedCommand(parentInstance.instanceId(), instanceVector, createInformationVector(instanceList, false));
}
InformationChangedCommand NodeInstanceServer::createAllInformationChangedCommand(const QList<ServerNodeInstance> &instanceList, bool initial) const
{
return InformationChangedCommand(createInformationVector(instanceList, initial));
}
static bool supportedVariantType(QVariant::Type type)
......
......@@ -170,20 +170,22 @@ void Qt4InformationNodeInstanceServer::collectItemChangesAndSendChangeCommands()
}
}
informationChangedInstanceSet.subtract(m_parentChangedSet);
clearChangedPropertyList();
resetAllItems();
if (!m_parentChangedSet.isEmpty()) {
sendChildrenChangedCommand(m_parentChangedSet.toList());
m_parentChangedSet.clear();
}
if (!informationChangedInstanceSet.isEmpty())
nodeInstanceClient()->informationChanged(createAllInformationChangedCommand(informationChangedInstanceSet.toList()));
if (!propertyChangedList.isEmpty())
nodeInstanceClient()->valuesChanged(createValuesChangedCommand(propertyChangedList));
if (!m_parentChangedSet.isEmpty()) {
sendChildrenChangedCommand(m_parentChangedSet.toList());
m_parentChangedSet.clear();
}
if (adjustSceneRect) {
QRectF boundingRect = rootNodeInstance().boundingRect();
if (boundingRect.isValid()) {
......
......@@ -82,6 +82,7 @@ public:
virtual void formEditorItemsChanged(const QList<FormEditorItem*> &itemList) = 0;
virtual void instancesCompleted(const QList<FormEditorItem*> &itemList) = 0;
virtual void instancesParentChanged(const QList<FormEditorItem*> &itemList) = 0;
void setItems(const QList<FormEditorItem*> &itemList);
QList<FormEditorItem*> items() const;
......
......@@ -220,6 +220,10 @@ void AnchorTool::instancesCompleted(const QList<FormEditorItem*> &/*itemList*/)
{
}
void AnchorTool::instancesParentChanged(const QList<FormEditorItem *> &/*itemList*/)
{
}
AnchorLineHandleItem* AnchorTool::topAnchorLineHandleItem(const QList<QGraphicsItem*> & itemList)
{
foreach (QGraphicsItem *item, itemList) {
......
......@@ -74,6 +74,8 @@ public:
void formEditorItemsChanged(const QList<FormEditorItem*> &itemList);
void instancesCompleted(const QList<FormEditorItem*> &itemList);
void instancesParentChanged(const QList<FormEditorItem *> &itemList);
static AnchorLineHandleItem* topAnchorLineHandleItem(const QList<QGraphicsItem*> & itemList);
......
......@@ -217,6 +217,12 @@ void DragTool::instancesCompleted(const QList<FormEditorItem*> &itemList)
QmlDesignerItemLibraryDragAndDrop::CustomDragAndDrop::hide();
}
void DragTool::instancesParentChanged(const QList<FormEditorItem *> &itemList)
{
m_moveManipulator.synchronizeInstanceParent(itemList);
}
void DragTool::clearMoveDelay()
{
if (!m_blockMove)
......@@ -381,6 +387,7 @@ void DragTool::dragMoveEvent(QGraphicsSceneDragDropEvent * event)
QTimer::singleShot(1000, m_timerHandler.data(), SLOT(clearMoveDelay()));
}
}
if (event->mimeData()->hasFormat("application/vnd.bauhaus.libraryresource")) {
}
}
......
......@@ -86,6 +86,7 @@ public:
void itemsAboutToRemoved(const QList<FormEditorItem*> &itemList);
void selectedItemsChanged(const QList<FormEditorItem*> &itemList);
void instancesParentChanged(const QList<FormEditorItem *> &itemList);
void updateMoveManipulator();
......
......@@ -56,6 +56,7 @@
#include <zoomaction.h>
#include <nodeabstractproperty.h>
#include <nodelistproperty.h>
#include <commondefines.h>
namespace QmlDesigner {
......@@ -502,6 +503,7 @@ void FormEditorView::instancesChildrenChanged(const QVector<ModelNode> &nodeList
}
m_currentTool->formEditorItemsChanged(itemNodeList);
m_currentTool->instancesParentChanged(itemNodeList);
}
void FormEditorView::rewriterBeginTransaction()
......
......@@ -145,6 +145,10 @@ void ItemCreatorTool::instancesCompleted(const QList<FormEditorItem*> &/*itemLis
{
}
void ItemCreatorTool::instancesParentChanged(const QList<FormEditorItem *> &/*itemList*/)
{
}
void ItemCreatorTool::setItemString(const QString &itemString)
{
m_itemString = itemString;
......
......@@ -71,6 +71,7 @@ public:
void formEditorItemsChanged(const QList<FormEditorItem*> &itemList);
void instancesCompleted(const QList<FormEditorItem*> &itemList);
void instancesParentChanged(const QList<FormEditorItem *> &itemList);
void setItemString(const QString &itemString);
......
......@@ -88,6 +88,24 @@ void MoveManipulator::setItems(const QList<FormEditorItem*> &itemList)
}
}
void MoveManipulator::synchronizeInstanceParent(const QList<FormEditorItem*> &itemList)
{
if (m_view->model()) {
foreach (FormEditorItem *item, itemList) {
if (m_itemList.contains(item)) {
QmlItemNode parentItemNode = QmlItemNode(item->qmlItemNode().instanceParent());
if (parentItemNode.isValid()) {
m_snapper.setContainerFormEditorItem(m_view->scene()->itemForQmlItemNode(parentItemNode));
m_snapper.setTransformtionSpaceFormEditorItem(m_snapper.containerFormEditorItem());
m_snapper.updateSnappingLines(m_itemList);
updateHashes();
break;
}
}
}
}
}
void MoveManipulator::updateHashes()
{
// foreach (FormEditorItem* item, m_itemList)
......@@ -344,13 +362,6 @@ void MoveManipulator::reparentTo(FormEditorItem *newParent)
item->qmlItemNode().setParentProperty(parent.nodeAbstractProperty("data"));
}
}
if (m_view->model()) {
m_snapper.setContainerFormEditorItem(newParent);
m_snapper.setTransformtionSpaceFormEditorItem(m_snapper.containerFormEditorItem());
m_snapper.updateSnappingLines(m_itemList);
updateHashes();
}
}
......
......@@ -69,6 +69,7 @@ public:
~MoveManipulator();
void setItems(const QList<FormEditorItem*> &itemList);
void setItem(FormEditorItem* item);
void synchronizeInstanceParent(const QList<FormEditorItem*> &itemList);
void begin(const QPointF& beginPoint);
void update(const QPointF& updatePoint, Snapping useSnapping, State stateToBeManipulated = UseActualState);
......
......@@ -256,6 +256,11 @@ void MoveTool::instancesCompleted(const QList<FormEditorItem*> & /*itemList*/)
{
}
void MoveTool::instancesParentChanged(const QList<FormEditorItem *> &itemList)
{
m_moveManipulator.synchronizeInstanceParent(itemList);
}
bool MoveTool::haveSameParent(const QList<FormEditorItem*> &itemList)
{
if (itemList.isEmpty())
......
......@@ -67,7 +67,8 @@ public:
void selectedItemsChanged(const QList<FormEditorItem*> &itemList);
void instancesCompleted(const QList<FormEditorItem*> &/*itemList*/);
void instancesCompleted(const QList<FormEditorItem*> &itemList);
void instancesParentChanged(const QList<FormEditorItem *> &itemList);
void updateMoveManipulator();
......
......@@ -196,8 +196,14 @@ void ResizeTool::formEditorItemsChanged(const QList<FormEditorItem*> &itemList)
m_resizeIndicator.updateItems(itemList);
}
void ResizeTool::instancesCompleted(const QList<FormEditorItem*> &/*itemList*/)
{
}
void ResizeTool::instancesCompleted(const QList<FormEditorItem*> &/*itemList*/)
{
}
void ResizeTool::instancesParentChanged(const QList<FormEditorItem *> &/*itemList*/)
{
}
}
......@@ -67,9 +67,11 @@ public:
void clear();
void formEditorItemsChanged(const QList<FormEditorItem*> &itemList);
void instancesParentChanged(const QList<FormEditorItem *> &itemList);
void instancesCompleted(const QList<FormEditorItem*> &itemList);
private:
SelectionIndicator m_selectionIndicator;
ResizeIndicator m_resizeIndicator;
......
......@@ -275,6 +275,11 @@ void SelectionTool::instancesCompleted(const QList<FormEditorItem*> &/*itemList*
{
}
void SelectionTool::instancesParentChanged(const QList<FormEditorItem *> &/*itemList*/)
{
}
void SelectionTool::selectUnderPoint(QGraphicsSceneMouseEvent *event)
{
m_singleSelectionManipulator.begin(event->scenePos());
......
......@@ -80,6 +80,8 @@ public:
void formEditorItemsChanged(const QList<FormEditorItem*> &itemList);
void instancesCompleted(const QList<FormEditorItem*> &itemList);
void instancesParentChanged(const QList<FormEditorItem *> &itemList);
void selectUnderPoint(QGraphicsSceneMouseEvent *event);
......
......@@ -69,6 +69,7 @@ class ChangeIdsCommand;
class RemoveInstancesCommand;
class RemovePropertiesCommand;
class CompleteComponentCommand;
class InformationContainer;
class CORESHARED_EXPORT NodeInstanceView : public AbstractView, public NodeInstanceClientInterface
{
......@@ -161,6 +162,8 @@ private: // functions
void clearStateInstance();
NodeInstanceServerInterface *nodeInstanceServer() const;
QMultiHash<ModelNode, InformationName> informationChanged(const QVector<InformationContainer> &containerVector);
CreateSceneCommand createCreateSceneCommand();
ClearSceneCommand createClearSceneCommand() const;
......
......@@ -1058,14 +1058,11 @@ void NodeInstanceView::pixmapChanged(const PixmapChangedCommand &command)
emitInstancesRenderImageChanged(renderImageChangeSet.toList().toVector());
}
void NodeInstanceView::informationChanged(const InformationChangedCommand &command)
QMultiHash<ModelNode, InformationName> NodeInstanceView::informationChanged(const QVector<InformationContainer> &containerVector)
{
if (!model())
return;
QMultiHash<ModelNode, InformationName> informationChangeHash;
foreach(const InformationContainer &container, command.informations()) {
foreach (const InformationContainer &container, containerVector) {
if (hasInstanceForId(container.instanceId())) {
NodeInstance instance = instanceForId(container.instanceId());
if (instance.isValid()) {
......@@ -1076,6 +1073,16 @@ void NodeInstanceView::informationChanged(const InformationChangedCommand &comma
}
}
return informationChangeHash;
}
void NodeInstanceView::informationChanged(const InformationChangedCommand &command)
{
if (!model())
return;
QMultiHash<ModelNode, InformationName> informationChangeHash = informationChanged(command.informations());
if (!informationChangeHash.isEmpty())
emitInstanceInformationsChange(informationChangeHash);
}
......@@ -1138,6 +1145,7 @@ void NodeInstanceView::childrenChanged(const ChildrenChangedCommand &command)
if (!model())
return;
QVector<ModelNode> childNodeVector;
foreach(qint32 instanceId, command.childrenInstances()) {
......@@ -1148,6 +1156,11 @@ void NodeInstanceView::childrenChanged(const ChildrenChangedCommand &command)
}
}
QMultiHash<ModelNode, InformationName> informationChangeHash = informationChanged(command.informations());
if (!informationChangeHash.isEmpty())
emitInstanceInformationsChange(informationChangeHash);
if (!childNodeVector.isEmpty())
emitInstancesChildrenChanged(childNodeVector);
}
......
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