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/1189
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Alessandro Portale <alessandro.portale@nokia.com>
This commit is contained in:
Marco Bubke
2011-07-06 15:48:21 +02:00
parent a4c4d67772
commit 765ba3b4b9
40 changed files with 524 additions and 23 deletions

View File

@@ -1,6 +1,7 @@
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

View File

@@ -0,0 +1,114 @@
/**************************************************************************
**
** 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

View File

@@ -0,0 +1,100 @@
/**************************************************************************
**
** 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

View File

@@ -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();

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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() {}

View File

@@ -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");
}
}

View File

@@ -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();
};

View File

@@ -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()));

View File

@@ -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

View File

@@ -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()) {

View File

@@ -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

View File

@@ -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;

View File

@@ -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();

View File

@@ -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;
QmlItemNode parent(newParent->qmlItemNode());
if (parent.isValid()) {
if (parent.hasDefaultProperty())
item->qmlItemNode().setParentProperty(parent.nodeAbstractProperty(parent.defaultProperty()));
else
item->qmlItemNode().setParentProperty(parent.nodeAbstractProperty("data"));
QmlItemNode parent(newParent->qmlItemNode());
if (parent.isValid()) {
if (parent.hasDefaultProperty()) {
parentProperty = parent.nodeAbstractProperty(parent.defaultProperty());
} else {
parentProperty = parent.nodeAbstractProperty("data");
}
foreach (FormEditorItem* item, m_itemList) {
if (!item || !item->qmlItemNode().isValid())
continue;
if (parentProperty != item->qmlItemNode().modelNode().parentProperty())
nodeReparentVector.append(item->qmlItemNode().modelNode());
}
foreach (const ModelNode &nodeToReparented, nodeReparentVector)
parentProperty.reparentHere(nodeToReparented);
synchronizeParent(m_itemList, parentProperty.parentModelNode());
}
}

View File

@@ -70,7 +70,7 @@ public:
void setItems(const QList<FormEditorItem*> &itemList);
void setItem(FormEditorItem* item);
void synchronizeInstanceParent(const QList<FormEditorItem*> &itemList);
void synchronizeParent(const QList<FormEditorItem*> &itemList, const ModelNode &parentNode);
void begin(const QPointF& beginPoint);
void update(const QPointF& updatePoint, Snapping useSnapping, State stateToBeManipulated = UseActualState);
void reparentTo(FormEditorItem *newParent);
@@ -123,6 +123,7 @@ private:
QList<QGraphicsItem*> m_graphicsLineList;
bool m_isActive;
RewriterTransaction m_rewriterTransaction;
QPointF m_lastPosition;
};
}

View File

@@ -212,6 +212,8 @@ void ComponentView::instanceInformationsChange(const QMultiHash<ModelNode, Infor
void ComponentView::instancesRenderImageChanged(const QVector<ModelNode> &/*nodeList*/) {}
void ComponentView::instancesPreviewImageChanged(const QVector<ModelNode> &/*nodeList*/) {}
void ComponentView::instancesChildrenChanged(const QVector<ModelNode> &/*nodeList*/) {}
void ComponentView::instancesToken(const QString &/*tokenName*/, int /*tokenNumber*/, const QVector<ModelNode> &/*nodeVector*/) {}
void ComponentView::nodeSourceChanged(const ModelNode &, const QString & /*newNodeSource*/) {}
void ComponentView::rewriterBeginTransaction() {}

View File

@@ -81,6 +81,8 @@ public:
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void instancesToken(const QString &tokenName, int tokenNumber, const QVector<ModelNode> &nodeVector);
void nodeSourceChanged(const ModelNode &modelNode, const QString &newNodeSource);
void rewriterBeginTransaction();

View File

@@ -92,6 +92,11 @@ void DesignDocumentControllerView::instancesChildrenChanged(const QVector<ModelN
}
void DesignDocumentControllerView::instancesToken(const QString &/*tokenName*/, int /*tokenNumber*/, const QVector<ModelNode> &/*nodeVector*/)
{
}
void DesignDocumentControllerView::nodeSourceChanged(const ModelNode &, const QString & /*newNodeSource*/)
{

View File

@@ -68,6 +68,8 @@ public:
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void instancesToken(const QString &tokenName, int tokenNumber, const QVector<ModelNode> &nodeVector);
void nodeSourceChanged(const ModelNode &modelNode, const QString &newNodeSource);
void rewriterBeginTransaction();

View File

@@ -172,6 +172,11 @@ void ItemLibraryView::instancesChildrenChanged(const QVector<ModelNode> &/*nodeL
}
void ItemLibraryView::instancesToken(const QString &/*tokenName*/, int /*tokenNumber*/, const QVector<ModelNode> &/*nodeVector*/)
{
}
void ItemLibraryView::nodeSourceChanged(const ModelNode &, const QString & /*newNodeSource*/)
{

View File

@@ -84,6 +84,8 @@ public:
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void instancesToken(const QString &tokenName, int tokenNumber, const QVector<ModelNode> &nodeVector);
void nodeSourceChanged(const ModelNode &modelNode, const QString &newNodeSource);
void rewriterBeginTransaction();

View File

@@ -121,8 +121,11 @@ public:
void emitInstancesChildrenChanged(const QVector<ModelNode> &nodeList);
void emitRewriterBeginTransaction();
void emitRewriterEndTransaction();
void emitInstanceToken(const QString &token, int number, const QVector<ModelNode> &nodeVector);
void emitActualStateChanged(const ModelNode &node);
void sendTokenToInstances(const QString &token, int number, const QVector<ModelNode> &nodeVector);
virtual void modelAttached(Model *model);
virtual void modelAboutToBeDetached(Model *model);
@@ -144,6 +147,8 @@ public:
virtual void instancesRenderImageChanged(const QVector<ModelNode> &nodeList) = 0;
virtual void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList) = 0;
virtual void instancesChildrenChanged(const QVector<ModelNode> &nodeList) = 0;
virtual void instancesToken(const QString &tokenName, int tokenNumber, const QVector<ModelNode> &nodeVector) = 0;
virtual void nodeSourceChanged(const ModelNode &modelNode, const QString &newNodeSource) = 0;
virtual void rewriterBeginTransaction() = 0;

View File

@@ -47,6 +47,11 @@ class NodeAbstractProperty : public AbstractProperty
friend class QmlDesigner::ModelNode;
friend class QmlDesigner::Internal::ModelPrivate;
friend class QmlDesigner::AbstractProperty;
friend CORESHARED_EXPORT bool operator ==(const NodeAbstractProperty &property1, const NodeAbstractProperty &property2);
friend CORESHARED_EXPORT bool operator !=(const NodeAbstractProperty &property1, const NodeAbstractProperty &property2);
friend CORESHARED_EXPORT uint qHash(const NodeAbstractProperty& property);
public:
NodeAbstractProperty();
NodeAbstractProperty(const NodeAbstractProperty &property, AbstractView *view);
@@ -63,6 +68,13 @@ protected:
void reparentHere(const ModelNode &modelNode, bool isNodeList);
};
CORESHARED_EXPORT bool operator ==(const NodeAbstractProperty &property1, const NodeAbstractProperty &property2);
CORESHARED_EXPORT bool operator !=(const NodeAbstractProperty &property1, const NodeAbstractProperty &property2);
CORESHARED_EXPORT uint qHash(const NodeAbstractProperty& property);
CORESHARED_EXPORT QTextStream& operator<<(QTextStream &stream, const NodeAbstractProperty &property);
CORESHARED_EXPORT QDebug operator<<(QDebug debug, const NodeAbstractProperty &property);
} // namespace QmlDesigner
#endif // NODEABSTRACTPROPERTY_H

View File

@@ -70,6 +70,7 @@ class RemoveInstancesCommand;
class RemovePropertiesCommand;
class CompleteComponentCommand;
class InformationContainer;
class TokenCommand;
class CORESHARED_EXPORT NodeInstanceView : public AbstractView, public NodeInstanceClientInterface
{
@@ -107,10 +108,12 @@ public:
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void instancesToken(const QString &tokenName, int tokenNumber, const QVector<ModelNode> &nodeVector);
void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
void customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data);
void nodeSourceChanged(const ModelNode &modelNode, const QString &newNodeSource);
void rewriterBeginTransaction();
void rewriterEndTransaction();
@@ -136,11 +139,14 @@ public:
void childrenChanged(const ChildrenChangedCommand &command);
void statePreviewImagesChanged(const StatePreviewImageChangedCommand &command);
void componentCompleted(const ComponentCompletedCommand &command);
void token(const TokenCommand &command);
QImage statePreviewImage(const ModelNode &stateNode) const;
void setPathToQt(const QString &pathToQt);
void sendToken(const QString &token, int number, const QVector<ModelNode> &nodeVector);
signals:
void qmlPuppetCrashed();

View File

@@ -98,6 +98,7 @@ public:
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void instancesToken(const QString &tokenName, int tokenNumber, const QVector<ModelNode> &nodeVector);
void rewriterBeginTransaction();
void rewriterEndTransaction();

View File

@@ -143,6 +143,8 @@ public:
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void instancesToken(const QString &tokenName, int tokenNumber, const QVector<ModelNode> &nodeVector);
void nodeSourceChanged(const ModelNode &modelNode, const QString &newNodeSource);
void rewriterBeginTransaction();

View File

@@ -65,6 +65,7 @@
#include "imagecontainer.h"
#include "statepreviewimagechangedcommand.h"
#include "componentcompletedcommand.h"
#include "tokencommand.h"
#include "synchronizecommand.h"
@@ -241,6 +242,7 @@ void NodeInstanceServerProxy::dispatchCommand(const QVariant &command)
static const int statePreviewImageChangedCommandType = QMetaType::type("StatePreviewImageChangedCommand");
static const int componentCompletedCommandType = QMetaType::type("ComponentCompletedCommand");
static const int synchronizeCommandType = QMetaType::type("SynchronizeCommand");
static const int tokenCommandType = QMetaType::type("TokenCommand");
if (command.userType() == informationChangedCommandType)
nodeInstanceClient()->informationChanged(command.value<InformationChangedCommand>());
@@ -254,6 +256,8 @@ void NodeInstanceServerProxy::dispatchCommand(const QVariant &command)
nodeInstanceClient()->statePreviewImagesChanged(command.value<StatePreviewImageChangedCommand>());
else if (command.userType() == componentCompletedCommandType)
nodeInstanceClient()->componentCompleted(command.value<ComponentCompletedCommand>());
else if (command.userType() == tokenCommandType)
nodeInstanceClient()->token(command.value<TokenCommand>());
else if (command.userType() == synchronizeCommandType) {
SynchronizeCommand synchronizeCommand = command.value<SynchronizeCommand>();
m_synchronizeId = synchronizeCommand.synchronizeId();
@@ -523,4 +527,9 @@ void NodeInstanceServerProxy::changeNodeSource(const ChangeNodeSourceCommand &co
writeCommand(QVariant::fromValue(command));
}
void NodeInstanceServerProxy::token(const TokenCommand &command)
{
writeCommand(QVariant::fromValue(command));
}
} // namespace QmlDesigner

View File

@@ -71,6 +71,7 @@ public:
void changeState(const ChangeStateCommand &command);
void completeComponent(const CompleteComponentCommand &command);
void changeNodeSource(const ChangeNodeSourceCommand &command);
void token(const TokenCommand &command);
protected:
void writeCommand(const QVariant &command);

View File

@@ -80,6 +80,7 @@
#include "statepreviewimagechangedcommand.h"
#include "completecomponentcommand.h"
#include "componentcompletedcommand.h"
#include "tokencommand.h"
#include "nodeinstanceserverproxy.h"
@@ -483,6 +484,11 @@ void NodeInstanceView::instancesChildrenChanged(const QVector<ModelNode> &/*node
}
void NodeInstanceView::instancesToken(const QString &/*tokenName*/, int /*tokenNumber*/, const QVector<ModelNode> &/*nodeVector*/)
{
}
void NodeInstanceView::auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data)
{
if (node.isRootNode() && (name == "width" || name == "height")) {
@@ -1165,4 +1171,30 @@ void NodeInstanceView::childrenChanged(const ChildrenChangedCommand &command)
emitInstancesChildrenChanged(childNodeVector);
}
void NodeInstanceView::token(const TokenCommand &command)
{
if (!model())
return;
QVector<ModelNode> nodeVector;
foreach (const qint32 &instanceId, command.instances()) {
if (hasModelNodeForInternalId(instanceId)) {
nodeVector.append(modelNodeForInternalId(instanceId));
}
}
emitInstanceToken(command.tokenName(), command.tokenNumber(), nodeVector);
}
void NodeInstanceView::sendToken(const QString &token, int number, const QVector<ModelNode> &nodeVector)
{
QVector<qint32> instanceIdVector;
foreach (const ModelNode &node, nodeVector)
instanceIdVector.append(node.internalId());
nodeInstanceServer()->token(TokenCommand(token, number, instanceIdVector));
}
}

View File

@@ -429,6 +429,18 @@ void AbstractView::emitRewriterBeginTransaction()
model()->m_d->notifyRewriterBeginTransaction();
}
void AbstractView::sendTokenToInstances(const QString &token, int number, const QVector<ModelNode> &nodeVector)
{
if (nodeInstanceView())
nodeInstanceView()->sendToken(token, number, nodeVector);
}
void AbstractView::emitInstanceToken(const QString &token, int number, const QVector<ModelNode> &nodeVector)
{
if (nodeInstanceView())
model()->m_d->notifyInstanceToken(token, number, nodeVector);
}
void AbstractView::emitRewriterEndTransaction()
{
if (model())

View File

@@ -681,6 +681,36 @@ void ModelPrivate::notifyRewriterEndTransaction()
}
}
void ModelPrivate::notifyInstanceToken(const QString &token, int number, const QVector<ModelNode> &nodeVector)
{
bool resetModel = false;
QString description;
QVector<Internal::InternalNode::Pointer> internalVector(toInternalNodeVector(nodeVector));
try {
if (rewriterView())
rewriterView()->instancesToken(token, number, toModelNodeVector(internalVector, rewriterView()));
} catch (RewritingException &e) {
description = e.description();
resetModel = true;
}
foreach (const QWeakPointer<AbstractView> &view, m_viewList) {
Q_ASSERT(view != 0);
view->instancesToken(token, number, toModelNodeVector(internalVector, view.data()));
}
if (nodeInstanceView()) {
nodeInstanceView()->instancesToken(token, number, toModelNodeVector(internalVector, nodeInstanceView()));
}
if (resetModel) {
resetModelByRewriter(description);
}
}
void ModelPrivate::notifyCustomNotification(const AbstractView *senderView, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data)
{
bool resetModel = false;

View File

@@ -156,12 +156,13 @@ public:
void notifyInstancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void notifyInstancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void notifyInstancesChildrenChanged(const QVector<ModelNode> &nodeList);
void notifyInstanceToken(const QString &token, int number, const QVector<ModelNode> &nodeVector);
void notifyActualStateChanged(const ModelNode &node);
void notifyRewriterBeginTransaction();
void notifyRewriterEndTransaction();
void setSelectedNodes(const QList<InternalNodePointer> &selectedNodeList);
void clearSelectedNodes();
QList<InternalNodePointer> selectedNodes() const;

View File

@@ -141,4 +141,36 @@ QList<ModelNode> NodeAbstractProperty::allSubNodes()
return toModelNodeList(property->allSubNodes(), view());
}
/*!
\brief Returns if the the two property handles reference the same property in the same node
*/
bool operator ==(const NodeAbstractProperty &property1, const NodeAbstractProperty &property2)
{
return AbstractProperty(property1) == AbstractProperty(property2);
}
/*!
\brief Returns if the the two property handles do not reference the same property in the same node
*/
bool operator !=(const NodeAbstractProperty &property1, const NodeAbstractProperty &property2)
{
return !(property1 == property2);
}
uint qHash(const NodeAbstractProperty &property)
{
return qHash(AbstractProperty(property));
}
QDebug operator<<(QDebug debug, const NodeAbstractProperty &property)
{
return debug.nospace() << "NodeAbstractProperty(" << (property.isValid() ? property.name() : QLatin1String("invalid")) << ')';
}
QTextStream& operator<<(QTextStream &stream, const NodeAbstractProperty &property)
{
stream << "NodeAbstractProperty(" << property.name() << ')';
return stream;
}
} // namespace QmlDesigner

View File

@@ -414,6 +414,11 @@ void QmlModelView::importsChanged(const QList<Import> &/*addedImports*/, const Q
}
void QmlModelView::instancesToken(const QString &/*tokenName*/, int /*tokenNumber*/, const QVector<ModelNode> &/*nodeVector*/)
{
}
void QmlModelView::nodeSourceChanged(const ModelNode &, const QString & /*newNodeSource*/)
{

View File

@@ -407,6 +407,11 @@ void RewriterView::instancesChildrenChanged(const QVector<ModelNode> & /*nodeLis
}
void RewriterView::instancesToken(const QString &/*tokenName*/, int /*tokenNumber*/, const QVector<ModelNode> &/*nodeVector*/)
{
}
void RewriterView::nodeSourceChanged(const ModelNode &, const QString & /*newNodeSource*/)
{

View File

@@ -260,6 +260,13 @@ void ViewLogger::instancesChildrenChanged(const QVector<ModelNode> &nodeList)
m_output << time() << indent("node: ") << node << endl;
}
void ViewLogger::instancesToken(const QString &tokenName, int tokenNumber, const QVector<ModelNode> &nodeVector)
{
m_output << time() << indent("instancesToken:") << tokenName << tokenNumber << endl;
foreach (const ModelNode &node, nodeVector)
m_output << time() << indent("node: ") << node << endl;
}
void ViewLogger::nodeSourceChanged(const ModelNode &node, const QString & /*newNodeSource*/)
{
m_output << time() << indent("nodeSourceChanged:") << endl;

View File

@@ -81,6 +81,8 @@ public:
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void instancesToken(const QString &tokenName, int tokenNumber, const QVector<ModelNode> &nodeVector);
void nodeSourceChanged(const ModelNode &modelNode, const QString &newNodeSource);
void rewriterBeginTransaction();