Commit 765ba3b4 authored by Marco Bubke's avatar Marco Bubke

QmlDesigner: Prevent item hoping for reparenting

Because of the asynchronous nature of the formeditor the item can be between
to states. This looks like the item is hoping around. To prevent this a token
is sent to the instances and back. For the time frame the painting is disabled.

Change-Id: If7e937cba8171248464ad350bb14438c020b25f9
Reviewed-on: http://codereview.qt.nokia.com/1189Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarAlessandro Portale <alessandro.portale@nokia.com>
parent a4c4d677
INCLUDEPATH += $$PWD/
HEADERS += $$PWD/synchronizecommand.h
HEADERS += $$PWD/tokencommand.h
HEADERS += $$PWD/componentcompletedcommand.h
HEADERS += $$PWD/completecomponentcommand.h
HEADERS += $$PWD/statepreviewimagechangedcommand.h
......@@ -24,6 +25,7 @@ HEADERS += $$PWD/changeauxiliarycommand.h
SOURCES += $$PWD/synchronizecommand.cpp
SOURCES += $$PWD/tokencommand.cpp
SOURCES += $$PWD/componentcompletedcommand.cpp
SOURCES += $$PWD/completecomponentcommand.cpp
SOURCES += $$PWD/statepreviewimagechangedcommand.cpp
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "tokencommand.h"
namespace QmlDesigner {
TokenCommand::TokenCommand()
: m_tokenNumber(-1)
{
}
TokenCommand::TokenCommand(const QString &tokenName, qint32 tokenNumber, const QVector<qint32> &instanceIdVector)
: m_tokenName(tokenName),
m_tokenNumber(tokenNumber),
m_instanceIdVector(instanceIdVector)
{
}
QString TokenCommand::tokenName() const
{
return m_tokenName;
}
qint32 TokenCommand::tokenNumber() const
{
return m_tokenNumber;
}
QVector<qint32> TokenCommand::instances() const
{
return m_instanceIdVector;
}
QDataStream &operator<<(QDataStream &out, const TokenCommand &command)
{
out << command.tokenName();
out << command.tokenNumber();
out << command.instances();
return out;
}
QDataStream &operator>>(QDataStream &in, TokenCommand &command)
{
in >> command.m_tokenName;
in >> command.m_tokenNumber;
in >> command.m_instanceIdVector;
return in;
}
} // namespace QmlDesigner
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef QMLDESIGNER_TOKENCOMMAND_H
#define QMLDESIGNER_TOKENCOMMAND_H
#include <QMetaType>
#include <QVector>
namespace QmlDesigner {
class TokenCommand
{
friend QDataStream &operator>>(QDataStream &in, TokenCommand &command);
public:
TokenCommand();
TokenCommand(const QString &tokenName, qint32 tokenNumber, const QVector<qint32> &instances);
QString tokenName() const;
qint32 tokenNumber() const;
QVector<qint32> instances() const;
private:
QString m_tokenName;
qint32 m_tokenNumber;
QVector<qint32> m_instanceIdVector;
};
QDataStream &operator<<(QDataStream &out, const TokenCommand &command);
QDataStream &operator>>(QDataStream &in, TokenCommand &command);
} // namespace QmlDesigner
Q_DECLARE_METATYPE(QmlDesigner::TokenCommand)
#endif // QMLDESIGNER_TOKENCOMMAND_H
......@@ -57,6 +57,7 @@
#include "changestatecommand.h"
#include "completecomponentcommand.h"
#include "synchronizecommand.h"
#include "tokencommand.h"
#include "informationchangedcommand.h"
#include "pixmapchangedcommand.h"
......@@ -133,6 +134,11 @@ void NodeInstanceClientProxy::componentCompleted(const ComponentCompletedCommand
writeCommand(QVariant::fromValue(command));
}
void NodeInstanceClientProxy::token(const TokenCommand &command)
{
writeCommand(QVariant::fromValue(command));
}
void NodeInstanceClientProxy::flush()
{
}
......@@ -267,6 +273,10 @@ void NodeInstanceClientProxy::changeNodeSource(const ChangeNodeSourceCommand &co
{
nodeInstanceServer()->changeNodeSource(command);
}
void NodeInstanceClientProxy::redirectToken(const TokenCommand &command)
{
nodeInstanceServer()->token(command);
}
void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
{
......@@ -285,6 +295,7 @@ void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
static const int completeComponentCommandType = QMetaType::type("CompleteComponentCommand");
static const int synchronizeCommandType = QMetaType::type("SynchronizeCommand");
static const int changeNodeSourceCommandType = QMetaType::type("ChangeNodeSourceCommand");
static const int tokenCommandType = QMetaType::type("TokenCommand");
if (command.userType() == createInstancesCommandType) {
createInstances(command.value<CreateInstancesCommand>());
......@@ -314,6 +325,8 @@ void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
completeComponent(command.value<CompleteComponentCommand>());
else if (command.userType() == changeNodeSourceCommandType)
changeNodeSource(command.value<ChangeNodeSourceCommand>());
else if (command.userType() == tokenCommandType)
redirectToken(command.value<TokenCommand>());
else if (command.userType() == synchronizeCommandType) {
SynchronizeCommand synchronizeCommand = command.value<SynchronizeCommand>();
m_synchronizeId = synchronizeCommand.synchronizeId();
......
......@@ -75,6 +75,7 @@ public:
void childrenChanged(const ChildrenChangedCommand &command);
void statePreviewImagesChanged(const StatePreviewImageChangedCommand &command);
void componentCompleted(const ComponentCompletedCommand &command);
void token(const TokenCommand &command);
void flush();
void synchronizeWithClientProcess();
......@@ -101,6 +102,7 @@ protected:
void changeState(const ChangeStateCommand &command);
void completeComponent(const CompleteComponentCommand &command);
void changeNodeSource(const ChangeNodeSourceCommand &command);
void redirectToken(const TokenCommand &command);
private slots:
void readDataStream();
......
......@@ -74,6 +74,7 @@
#include "componentcompletedcommand.h"
#include "createscenecommand.h"
#include "changenodesourcecommand.h"
#include "tokencommand.h"
#include "dummycontextobject.h"
......@@ -338,6 +339,11 @@ void NodeInstanceServer::changeNodeSource(const ChangeNodeSourceCommand &command
startRenderTimer();
}
void NodeInstanceServer::token(const TokenCommand &/*command*/)
{
}
void NodeInstanceServer::setupImports(const QVector<AddImportContainer> &containerVector)
{
foreach (const AddImportContainer &container, containerVector) {
......
......@@ -92,6 +92,7 @@ public:
void changeState(const ChangeStateCommand &command);
void completeComponent(const CompleteComponentCommand &command);
void changeNodeSource(const ChangeNodeSourceCommand &command);
void token(const TokenCommand &command);
ServerNodeInstance instanceForId(qint32 id) const;
bool hasInstanceForId(qint32 id) const;
......@@ -152,7 +153,6 @@ protected:
virtual void collectItemChangesAndSendChangeCommands() = 0;
ValuesChangedCommand createValuesChangedCommand(const QList<ServerNodeInstance> &instanceList) const;
ValuesChangedCommand createValuesChangedCommand(const QVector<InstancePropertyPair> &propertyList) const;
PixmapChangedCommand createPixmapChangedCommand(const QList<ServerNodeInstance> &instanceList) const;
......
......@@ -43,6 +43,7 @@ class InformationChangedCommand;
class ChildrenChangedCommand;
class StatePreviewImageChangedCommand;
class ComponentCompletedCommand;
class TokenCommand;
class NodeInstanceClientInterface
{
......@@ -53,6 +54,7 @@ public:
virtual void childrenChanged(const ChildrenChangedCommand &command) = 0;
virtual void statePreviewImagesChanged(const StatePreviewImageChangedCommand &command) = 0;
virtual void componentCompleted(const ComponentCompletedCommand &command) = 0;
virtual void token(const TokenCommand &command) = 0;
virtual void flush() {};
virtual void synchronizeWithClientProcess() {}
......
......@@ -61,6 +61,7 @@
#include "statepreviewimagechangedcommand.h"
#include "componentcompletedcommand.h"
#include "synchronizecommand.h"
#include "tokencommand.h"
namespace QmlDesigner {
......@@ -169,6 +170,9 @@ void NodeInstanceServerInterface::registerCommands()
qRegisterMetaType<ChangeAuxiliaryCommand>("ChangeAuxiliaryCommand");
qRegisterMetaTypeStreamOperators<ChangeAuxiliaryCommand>("ChangeAuxiliaryCommand");
qRegisterMetaType<TokenCommand>("TokenCommand");
qRegisterMetaTypeStreamOperators<TokenCommand>("TokenCommand");
}
}
......@@ -55,6 +55,7 @@ class RemovePropertiesCommand;
class ChangeStateCommand;
class CompleteComponentCommand;
class ChangeNodeSourceCommand;
class TokenCommand;
class NodeInstanceServerInterface : public QObject
{
......@@ -81,6 +82,7 @@ public:
virtual void changeState(const ChangeStateCommand &command) = 0;
virtual void completeComponent(const CompleteComponentCommand &command) = 0;
virtual void changeNodeSource(const ChangeNodeSourceCommand &command) = 0;
virtual void token(const TokenCommand &command) = 0;
static void registerCommands();
};
......
......@@ -60,6 +60,7 @@
#include "completecomponentcommand.h"
#include "componentcompletedcommand.h"
#include "createscenecommand.h"
#include "tokencommand.h"
#include "dummycontextobject.h"
......@@ -72,6 +73,20 @@ Qt5InformationNodeInstanceServer::Qt5InformationNodeInstanceServer(NodeInstanceC
{
}
void Qt5InformationNodeInstanceServer::sendTokenBack()
{
foreach (const TokenCommand &command, m_tokenList)
nodeInstanceClient()->token(command);
m_tokenList.clear();
}
void Qt5InformationNodeInstanceServer::token(const TokenCommand &command)
{
m_tokenList.append(command);
startRenderTimer();
}
void Qt5InformationNodeInstanceServer::collectItemChangesAndSendChangeCommands()
{
static bool inFunction = false;
......@@ -125,6 +140,8 @@ void Qt5InformationNodeInstanceServer::collectItemChangesAndSendChangeCommands()
resetAllItems();
clearChangedPropertyList();
sendTokenBack();
if (!informationChangedInstanceSet.isEmpty())
nodeInstanceClient()->informationChanged(createAllInformationChangedCommand(informationChangedInstanceSet.toList()));
......
......@@ -34,6 +34,7 @@
#define QMLDESIGNER_QT5INFORMATIONNODEINSTANCESERVER_H
#include "qt5nodeinstanceserver.h"
#include "tokencommand.h"
namespace QmlDesigner {
......@@ -47,14 +48,18 @@ public:
void clearScene(const ClearSceneCommand &command);
void createScene(const CreateSceneCommand &command);
void completeComponent(const CompleteComponentCommand &command);
void token(const TokenCommand &command);
protected:
void collectItemChangesAndSendChangeCommands();
void sendChildrenChangedCommand(const QList<ServerNodeInstance> childList);
void sendTokenBack();
private:
QSet<ServerNodeInstance> m_parentChangedSet;
QList<ServerNodeInstance> m_completedComponentList;
QList<TokenCommand> m_tokenList;
};
} // namespace QmlDesigner
......
......@@ -75,6 +75,8 @@
#include "completecomponentcommand.h"
#include "componentcompletedcommand.h"
#include "createscenecommand.h"
#include "tokencommand.h"
#include "dummycontextobject.h"
......@@ -85,6 +87,20 @@ Qt4InformationNodeInstanceServer::Qt4InformationNodeInstanceServer(NodeInstanceC
{
}
void Qt4InformationNodeInstanceServer::sendTokenBack()
{
foreach (const TokenCommand &command, m_tokenList)
nodeInstanceClient()->token(command);
m_tokenList.clear();
}
void Qt4InformationNodeInstanceServer::token(const TokenCommand &command)
{
m_tokenList.append(command);
startRenderTimer();
}
void Qt4InformationNodeInstanceServer::collectItemChangesAndSendChangeCommands()
{
static bool inFunction = false;
......@@ -143,10 +159,7 @@ void Qt4InformationNodeInstanceServer::collectItemChangesAndSendChangeCommands()
clearChangedPropertyList();
resetAllItems();
if (!m_parentChangedSet.isEmpty()) {
sendChildrenChangedCommand(m_parentChangedSet.toList());
m_parentChangedSet.clear();
}
sendTokenBack();
if (!informationChangedInstanceSet.isEmpty())
nodeInstanceClient()->informationChanged(createAllInformationChangedCommand(informationChangedInstanceSet.toList()));
......@@ -154,6 +167,11 @@ void Qt4InformationNodeInstanceServer::collectItemChangesAndSendChangeCommands()
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()) {
......
......@@ -34,6 +34,7 @@
#define INFORMATIONNODEINSTANCESERVER_H
#include "qt4nodeinstanceserver.h"
#include "tokencommand.h"
namespace QmlDesigner {
......@@ -47,14 +48,17 @@ public:
void clearScene(const ClearSceneCommand &command);
void createScene(const CreateSceneCommand &command);
void completeComponent(const CompleteComponentCommand &command);
void token(const TokenCommand &command);
protected:
void collectItemChangesAndSendChangeCommands();
void sendChildrenChangedCommand(const QList<ServerNodeInstance> childList);
void sendTokenBack();
private:
QSet<ServerNodeInstance> m_parentChangedSet;
QList<ServerNodeInstance> m_completedComponentList;
QList<TokenCommand> m_tokenList;
};
} // namespace QmlDesigner
......
......@@ -490,6 +490,10 @@ void FormEditorView::instancesPreviewImageChanged(const QVector<ModelNode> &/*no
}
void FormEditorView::instancesToken(const QString &tokenName, int tokenNumber, const QVector<ModelNode> &nodeVector)
{
}
void FormEditorView::instancesChildrenChanged(const QVector<ModelNode> &nodeList)
{
QList<FormEditorItem*> itemNodeList;
......
......@@ -109,6 +109,7 @@ public:
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void instancesToken(const QString &tokenName, int tokenNumber, const QVector<ModelNode> &nodeVector);
void rewriterBeginTransaction();
void rewriterEndTransaction();
......
......@@ -88,22 +88,33 @@ void MoveManipulator::setItems(const QList<FormEditorItem*> &itemList)
}
}
void MoveManipulator::synchronizeInstanceParent(const QList<FormEditorItem*> &itemList)
void MoveManipulator::synchronizeParent(const QList<FormEditorItem*> &itemList, const ModelNode &parentNode)
{
if (m_view->model()) {
foreach (FormEditorItem *item, itemList) {
if (m_itemList.contains(item)) {
QmlItemNode parentItemNode = QmlItemNode(item->qmlItemNode().instanceParent());
if (parentItemNode.isValid()) {
bool snapperUpdated = false;
foreach (FormEditorItem *item, itemList) {
if (m_itemList.contains(item)) {
QmlItemNode parentItemNode = QmlItemNode(parentNode);
if (parentItemNode.isValid()) {
if (snapperUpdated == false && m_snapper.containerFormEditorItem() != m_view->scene()->itemForQmlItemNode(parentItemNode)) {
m_snapper.setContainerFormEditorItem(m_view->scene()->itemForQmlItemNode(parentItemNode));
m_snapper.setTransformtionSpaceFormEditorItem(m_snapper.containerFormEditorItem());
m_snapper.updateSnappingLines(m_itemList);
updateHashes();
break;
snapperUpdated = true;
}
}
}
}
update(m_lastPosition, NoSnapping, UseBaseState);
}
void MoveManipulator::synchronizeInstanceParent(const QList<FormEditorItem*> &itemList)
{
if (m_view->model() && !m_itemList.isEmpty())
synchronizeParent(itemList, m_itemList.first()->qmlItemNode().instanceParent());
}
void MoveManipulator::updateHashes()
......@@ -257,6 +268,7 @@ QHash<FormEditorItem*, QRectF> MoveManipulator::tanslatedBoundingRects(const QHa
*/
void MoveManipulator::update(const QPointF& updatePoint, Snapping useSnapping, State stateToBeManipulated)
{
m_lastPosition = updatePoint;
deleteSnapLines(); //Since they position is changed and the item is moved the snapping lines are
//are obsolete. The new updated snapping lines (color and visibility) will be
//calculated in snapPoint() called in moveNode() later
......@@ -329,6 +341,7 @@ void MoveManipulator::clear()
m_beginPositionHash.clear();
m_beginPositionInSceneSpaceHash.clear();
m_itemList.clear();
m_lastPosition = QPointF();
m_rewriterTransaction.commit();
......@@ -350,17 +363,30 @@ void MoveManipulator::reparentTo(FormEditorItem *newParent)
if (!itemsCanReparented())
return;
foreach (FormEditorItem* item, m_itemList) {
if (!item || !item->qmlItemNode().isValid())
continue;
QVector<ModelNode> nodeReparentVector;
NodeAbstractProperty parentProperty;