QmlDesigner: Implement command for synchronising the selection

This patch implements the command and dispatchers for
synchronising the selection between Qt Creator and the qml2puppet.

Qt5InformationNodeInstanceServer::changeSelection() is called whenever the selection
is changed in Qt Creator.

Qt5InformationNodeInstanceServer::changeSelection() allows to change the
selection from the qml2puppet.

Change-Id: I73a64d8dc2a3f330433f966b42a10229cbbff649
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Thomas Hartmann
2019-10-17 13:51:57 +02:00
committed by Alessandro Portale
parent e7b481bdee
commit 640044c8f8
23 changed files with 258 additions and 4 deletions

View File

@@ -0,0 +1,69 @@
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "changeselectioncommand.h"
#include <QDataStream>
#include <QDebug>
namespace QmlDesigner {
ChangeSelectionCommand::ChangeSelectionCommand() = default;
ChangeSelectionCommand::ChangeSelectionCommand(const QVector<qint32> &idVector)
: m_instanceIdVector(idVector)
{
}
QVector<qint32> ChangeSelectionCommand::instanceIds() const
{
return m_instanceIdVector;
}
QDataStream &operator<<(QDataStream &out, const ChangeSelectionCommand &command)
{
out << command.instanceIds();
return out;
}
QDataStream &operator>>(QDataStream &in, ChangeSelectionCommand &command)
{
in >> command.m_instanceIdVector;
return in;
}
QDebug operator <<(QDebug debug, const ChangeSelectionCommand &command)
{
return debug.nospace() << "ChangeSelectionCommand(instanceIdVector: " << command.m_instanceIdVector << ")";
}
bool operator ==(const ChangeSelectionCommand &first, const ChangeSelectionCommand &second)
{
return first.m_instanceIdVector == second.m_instanceIdVector;
}
} // namespace QmlDesigner

View File

@@ -0,0 +1,61 @@
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <QMetaType>
#include <QVector>
#include <QDataStream>
#include "instancecontainer.h"
namespace QmlDesigner {
class ChangeSelectionCommand
{
friend QDataStream &operator>>(QDataStream &in, ChangeSelectionCommand &command);
friend QDebug operator <<(QDebug debug, const ChangeSelectionCommand &command);
friend bool operator ==(const ChangeSelectionCommand &first,
const ChangeSelectionCommand &second);
public:
ChangeSelectionCommand();
explicit ChangeSelectionCommand(const QVector<qint32> &idVector);
QVector<qint32> instanceIds() const;
private:
QVector<qint32> m_instanceIdVector;
};
QDataStream &operator<<(QDataStream &out, const ChangeSelectionCommand &command);
QDataStream &operator>>(QDataStream &in, ChangeSelectionCommand &command);
bool operator ==(const ChangeSelectionCommand &first, const ChangeSelectionCommand &second);
QDebug operator <<(QDebug debug, const ChangeSelectionCommand &command);
} // namespace QmlDesigner
Q_DECLARE_METATYPE(QmlDesigner::ChangeSelectionCommand)

View File

@@ -26,6 +26,7 @@ HEADERS += $$PWD/valueschangedcommand.h
HEADERS += $$PWD/changeauxiliarycommand.h HEADERS += $$PWD/changeauxiliarycommand.h
HEADERS += $$PWD/removesharedmemorycommand.h HEADERS += $$PWD/removesharedmemorycommand.h
HEADERS += $$PWD/puppetalivecommand.h HEADERS += $$PWD/puppetalivecommand.h
HEADERS += $$PWD/changeselectioncommand.h
SOURCES += $$PWD/synchronizecommand.cpp SOURCES += $$PWD/synchronizecommand.cpp
SOURCES += $$PWD/debugoutputcommand.cpp SOURCES += $$PWD/debugoutputcommand.cpp
@@ -53,3 +54,4 @@ SOURCES += $$PWD/pixmapchangedcommand.cpp
SOURCES += $$PWD/changeauxiliarycommand.cpp SOURCES += $$PWD/changeauxiliarycommand.cpp
SOURCES += $$PWD/removesharedmemorycommand.cpp SOURCES += $$PWD/removesharedmemorycommand.cpp
SOURCES += $$PWD/puppetalivecommand.cpp SOURCES += $$PWD/puppetalivecommand.cpp
SOURCES += $$PWD/changeselectioncommand.cpp

View File

@@ -67,6 +67,7 @@
#include "endpuppetcommand.h" #include "endpuppetcommand.h"
#include "debugoutputcommand.h" #include "debugoutputcommand.h"
#include "puppetalivecommand.h" #include "puppetalivecommand.h"
#include "changeselectioncommand.h"
namespace QmlDesigner { namespace QmlDesigner {
@@ -136,6 +137,7 @@ bool compareCommands(const QVariant &command, const QVariant &controlCommand)
static const int synchronizeCommandType = QMetaType::type("SynchronizeCommand"); static const int synchronizeCommandType = QMetaType::type("SynchronizeCommand");
static const int tokenCommandType = QMetaType::type("TokenCommand"); static const int tokenCommandType = QMetaType::type("TokenCommand");
static const int debugOutputCommandType = QMetaType::type("DebugOutputCommand"); static const int debugOutputCommandType = QMetaType::type("DebugOutputCommand");
static const int changeSelectionCommandType = QMetaType::type("ChangeSelectionCommand");
if (command.userType() == controlCommand.userType()) { if (command.userType() == controlCommand.userType()) {
if (command.userType() == informationChangedCommandType) if (command.userType() == informationChangedCommandType)
@@ -156,6 +158,8 @@ bool compareCommands(const QVariant &command, const QVariant &controlCommand)
return command.value<TokenCommand>() == controlCommand.value<TokenCommand>(); return command.value<TokenCommand>() == controlCommand.value<TokenCommand>();
else if (command.userType() == debugOutputCommandType) else if (command.userType() == debugOutputCommandType)
return command.value<DebugOutputCommand>() == controlCommand.value<DebugOutputCommand>(); return command.value<DebugOutputCommand>() == controlCommand.value<DebugOutputCommand>();
else if (command.userType() == changeSelectionCommandType)
return command.value<ChangeSelectionCommand>() == controlCommand.value<ChangeSelectionCommand>();
} }
return false; return false;
@@ -233,6 +237,11 @@ void NodeInstanceClientProxy::puppetAlive(const PuppetAliveCommand &command)
writeCommand(QVariant::fromValue(command)); writeCommand(QVariant::fromValue(command));
} }
void NodeInstanceClientProxy::selectionChanged(const ChangeSelectionCommand &command)
{
writeCommand(QVariant::fromValue(command));
}
void NodeInstanceClientProxy::flush() void NodeInstanceClientProxy::flush()
{ {
} }
@@ -252,9 +261,6 @@ qint64 NodeInstanceClientProxy::bytesToWrite() const
QVariant NodeInstanceClientProxy::readCommandFromIOStream(QIODevice *ioDevice, quint32 *readCommandCounter, quint32 *blockSize) QVariant NodeInstanceClientProxy::readCommandFromIOStream(QIODevice *ioDevice, quint32 *readCommandCounter, quint32 *blockSize)
{ {
QDataStream in(ioDevice); QDataStream in(ioDevice);
in.setVersion(QDataStream::Qt_4_8); in.setVersion(QDataStream::Qt_4_8);
@@ -416,6 +422,11 @@ void NodeInstanceClientProxy::redirectToken(const EndPuppetCommand & /*command*/
QCoreApplication::exit(); QCoreApplication::exit();
} }
void NodeInstanceClientProxy::changeSelection(const ChangeSelectionCommand &command)
{
nodeInstanceServer()->changeSelection(command);
}
void NodeInstanceClientProxy::dispatchCommand(const QVariant &command) void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
{ {
static const int createInstancesCommandType = QMetaType::type("CreateInstancesCommand"); static const int createInstancesCommandType = QMetaType::type("CreateInstancesCommand");
@@ -436,6 +447,7 @@ void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
static const int removeSharedMemoryCommandType = QMetaType::type("RemoveSharedMemoryCommand"); static const int removeSharedMemoryCommandType = QMetaType::type("RemoveSharedMemoryCommand");
static const int tokenCommandType = QMetaType::type("TokenCommand"); static const int tokenCommandType = QMetaType::type("TokenCommand");
static const int endPuppetCommandType = QMetaType::type("EndPuppetCommand"); static const int endPuppetCommandType = QMetaType::type("EndPuppetCommand");
static const int changeSelectionCommandType = QMetaType::type("ChangeSelectionCommand");
const int commandType = command.userType(); const int commandType = command.userType();
@@ -476,6 +488,9 @@ void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
else if (commandType == synchronizeCommandType) { else if (commandType == synchronizeCommandType) {
SynchronizeCommand synchronizeCommand = command.value<SynchronizeCommand>(); SynchronizeCommand synchronizeCommand = command.value<SynchronizeCommand>();
m_synchronizeId = synchronizeCommand.synchronizeId(); m_synchronizeId = synchronizeCommand.synchronizeId();
} else if (commandType == changeSelectionCommandType) {
ChangeSelectionCommand changeSelectionCommand = command.value<ChangeSelectionCommand>();
changeSelection(changeSelectionCommand);
} else { } else {
Q_ASSERT(false); Q_ASSERT(false);
} }

View File

@@ -56,7 +56,7 @@ class CompleteComponentCommand;
class ChangeStateCommand; class ChangeStateCommand;
class ChangeNodeSourceCommand; class ChangeNodeSourceCommand;
class EndPuppetCommand; class EndPuppetCommand;
class ChangeSelectionCommand;
class NodeInstanceClientProxy : public QObject, public NodeInstanceClientInterface class NodeInstanceClientProxy : public QObject, public NodeInstanceClientInterface
{ {
@@ -74,6 +74,7 @@ public:
void token(const TokenCommand &command) override; void token(const TokenCommand &command) override;
void debugOutput(const DebugOutputCommand &command) override; void debugOutput(const DebugOutputCommand &command) override;
void puppetAlive(const PuppetAliveCommand &command); void puppetAlive(const PuppetAliveCommand &command);
void selectionChanged(const ChangeSelectionCommand &command) override;
void flush() override; void flush() override;
void synchronizeWithClientProcess() override; void synchronizeWithClientProcess() override;
@@ -104,6 +105,7 @@ protected:
void removeSharedMemory(const RemoveSharedMemoryCommand &command); void removeSharedMemory(const RemoveSharedMemoryCommand &command);
void redirectToken(const TokenCommand &command); void redirectToken(const TokenCommand &command);
void redirectToken(const EndPuppetCommand &command); void redirectToken(const EndPuppetCommand &command);
void changeSelection(const ChangeSelectionCommand &command);
static QVariant readCommandFromIOStream(QIODevice *ioDevice, quint32 *readCommandCounter, quint32 *blockSize); static QVariant readCommandFromIOStream(QIODevice *ioDevice, quint32 *readCommandCounter, quint32 *blockSize);
protected slots: protected slots:

View File

@@ -39,6 +39,7 @@ class TokenCommand;
class RemoveSharedMemoryCommand; class RemoveSharedMemoryCommand;
class DebugOutputCommand; class DebugOutputCommand;
class PuppetAliveCommand; class PuppetAliveCommand;
class ChangeSelectionCommand;
class NodeInstanceClientInterface class NodeInstanceClientInterface
{ {
@@ -51,6 +52,7 @@ public:
virtual void componentCompleted(const ComponentCompletedCommand &command) = 0; virtual void componentCompleted(const ComponentCompletedCommand &command) = 0;
virtual void token(const TokenCommand &command) = 0; virtual void token(const TokenCommand &command) = 0;
virtual void debugOutput(const DebugOutputCommand &command) = 0; virtual void debugOutput(const DebugOutputCommand &command) = 0;
virtual void selectionChanged(const ChangeSelectionCommand &command) = 0;
virtual void flush() {} virtual void flush() {}
virtual void synchronizeWithClientProcess() {} virtual void synchronizeWithClientProcess() {}

View File

@@ -45,6 +45,7 @@
#include "completecomponentcommand.h" #include "completecomponentcommand.h"
#include "addimportcontainer.h" #include "addimportcontainer.h"
#include "changenodesourcecommand.h" #include "changenodesourcecommand.h"
#include "changeselectioncommand.h"
#include "informationchangedcommand.h" #include "informationchangedcommand.h"
#include "pixmapchangedcommand.h" #include "pixmapchangedcommand.h"
@@ -103,6 +104,9 @@ void NodeInstanceServerInterface::registerCommands()
qRegisterMetaType<RemoveInstancesCommand>("RemoveInstancesCommand"); qRegisterMetaType<RemoveInstancesCommand>("RemoveInstancesCommand");
qRegisterMetaTypeStreamOperators<RemoveInstancesCommand>("RemoveInstancesCommand"); qRegisterMetaTypeStreamOperators<RemoveInstancesCommand>("RemoveInstancesCommand");
qRegisterMetaType<ChangeSelectionCommand>("ChangeSelectionCommand");
qRegisterMetaTypeStreamOperators<ChangeSelectionCommand>("ChangeSelectionCommand");
qRegisterMetaType<RemovePropertiesCommand>("RemovePropertiesCommand"); qRegisterMetaType<RemovePropertiesCommand>("RemovePropertiesCommand");
qRegisterMetaTypeStreamOperators<RemovePropertiesCommand>("RemovePropertiesCommand"); qRegisterMetaTypeStreamOperators<RemovePropertiesCommand>("RemovePropertiesCommand");

View File

@@ -49,6 +49,7 @@ class CompleteComponentCommand;
class ChangeNodeSourceCommand; class ChangeNodeSourceCommand;
class TokenCommand; class TokenCommand;
class RemoveSharedMemoryCommand; class RemoveSharedMemoryCommand;
class ChangeSelectionCommand;
class NodeInstanceServerInterface : public QObject class NodeInstanceServerInterface : public QObject
{ {
@@ -77,6 +78,7 @@ public:
virtual void changeNodeSource(const ChangeNodeSourceCommand &command) = 0; virtual void changeNodeSource(const ChangeNodeSourceCommand &command) = 0;
virtual void token(const TokenCommand &command) = 0; virtual void token(const TokenCommand &command) = 0;
virtual void removeSharedMemory(const RemoveSharedMemoryCommand &command) = 0; virtual void removeSharedMemory(const RemoveSharedMemoryCommand &command) = 0;
virtual void changeSelection(const ChangeSelectionCommand &command) = 0;
virtual void benchmark(const QString &) virtual void benchmark(const QString &)
{} {}

View File

@@ -66,6 +66,7 @@
#include <changenodesourcecommand.h> #include <changenodesourcecommand.h>
#include <tokencommand.h> #include <tokencommand.h>
#include <removesharedmemorycommand.h> #include <removesharedmemorycommand.h>
#include <changeselectioncommand.h>
#include <QDebug> #include <QDebug>
#include <QQmlEngine> #include <QQmlEngine>
@@ -330,6 +331,10 @@ void NodeInstanceServer::clearScene(const ClearSceneCommand &/*command*/)
m_fileUrl.clear(); m_fileUrl.clear();
} }
void NodeInstanceServer::changeSelection(const ChangeSelectionCommand & /*command*/)
{
}
void NodeInstanceServer::removeInstances(const RemoveInstancesCommand &command) void NodeInstanceServer::removeInstances(const RemoveInstancesCommand &command)
{ {
ServerNodeInstance oldState = activeStateInstance(); ServerNodeInstance oldState = activeStateInstance();
@@ -1157,6 +1162,17 @@ ComponentCompletedCommand NodeInstanceServer::createComponentCompletedCommand(co
return ComponentCompletedCommand(idVector); return ComponentCompletedCommand(idVector);
} }
ChangeSelectionCommand NodeInstanceServer::createChangeSelectionCommand(const QList<ServerNodeInstance> &instanceList)
{
QVector<qint32> idVector;
for (const ServerNodeInstance &instance : instanceList) {
if (instance.instanceId() >= 0)
idVector.append(instance.instanceId());
}
return ChangeSelectionCommand(idVector);
}
ValuesChangedCommand NodeInstanceServer::createValuesChangedCommand(const QVector<InstancePropertyPair> &propertyList) const ValuesChangedCommand NodeInstanceServer::createValuesChangedCommand(const QVector<InstancePropertyPair> &propertyList) const
{ {
QVector<PropertyValueContainer> valueVector; QVector<PropertyValueContainer> valueVector;

View File

@@ -68,6 +68,7 @@ class ComponentCompletedCommand;
class AddImportContainer; class AddImportContainer;
class MockupTypeContainer; class MockupTypeContainer;
class IdContainer; class IdContainer;
class ChangeSelectionCommand;
namespace Internal { namespace Internal {
class ChildrenChangeEventFilter; class ChildrenChangeEventFilter;
@@ -101,6 +102,7 @@ public:
void changeNodeSource(const ChangeNodeSourceCommand &command) override; void changeNodeSource(const ChangeNodeSourceCommand &command) override;
void token(const TokenCommand &command) override; void token(const TokenCommand &command) override;
void removeSharedMemory(const RemoveSharedMemoryCommand &command) override; void removeSharedMemory(const RemoveSharedMemoryCommand &command) override;
void changeSelection(const ChangeSelectionCommand &command) override;
ServerNodeInstance instanceForId(qint32 id) const; ServerNodeInstance instanceForId(qint32 id) const;
bool hasInstanceForId(qint32 id) const; bool hasInstanceForId(qint32 id) const;
@@ -170,6 +172,7 @@ protected:
InformationChangedCommand createAllInformationChangedCommand(const QList<ServerNodeInstance> &instanceList, bool initial = false) const; InformationChangedCommand createAllInformationChangedCommand(const QList<ServerNodeInstance> &instanceList, bool initial = false) const;
ChildrenChangedCommand createChildrenChangedCommand(const ServerNodeInstance &parentInstance, const QList<ServerNodeInstance> &instanceList) const; ChildrenChangedCommand createChildrenChangedCommand(const ServerNodeInstance &parentInstance, const QList<ServerNodeInstance> &instanceList) const;
ComponentCompletedCommand createComponentCompletedCommand(const QList<ServerNodeInstance> &instanceList); ComponentCompletedCommand createComponentCompletedCommand(const QList<ServerNodeInstance> &instanceList);
ChangeSelectionCommand createChangeSelectionCommand(const QList<ServerNodeInstance> &instanceList);
void addChangedProperty(const InstancePropertyPair &property); void addChangedProperty(const InstancePropertyPair &property);

View File

@@ -55,6 +55,7 @@
#include "createscenecommand.h" #include "createscenecommand.h"
#include "tokencommand.h" #include "tokencommand.h"
#include "removesharedmemorycommand.h" #include "removesharedmemorycommand.h"
#include "changeselectioncommand.h"
#include "dummycontextobject.h" #include "dummycontextobject.h"
@@ -147,6 +148,12 @@ bool Qt5InformationNodeInstanceServer::isDirtyRecursiveForParentInstances(QQuick
return false; return false;
} }
/* This method allows changing the selection from the puppet */
void Qt5InformationNodeInstanceServer::selectInstance(const ServerNodeInstance &instance)
{
nodeInstanceClient()->selectionChanged(createChangeSelectionCommand({instance}));
}
QObject *Qt5InformationNodeInstanceServer::findRootNodeOf3DViewport( QObject *Qt5InformationNodeInstanceServer::findRootNodeOf3DViewport(
const QList<ServerNodeInstance> &instanceList) const const QList<ServerNodeInstance> &instanceList) const
{ {
@@ -358,4 +365,10 @@ void QmlDesigner::Qt5InformationNodeInstanceServer::removeSharedMemory(const Qml
ValuesChangedCommand::removeSharedMemorys(command.keyNumbers()); ValuesChangedCommand::removeSharedMemorys(command.keyNumbers());
} }
void Qt5InformationNodeInstanceServer::changeSelection(const ChangeSelectionCommand &command)
{
// keep track of selection.
qDebug() << Q_FUNC_INFO << command;
}
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -42,6 +42,7 @@ public:
void completeComponent(const CompleteComponentCommand &command) override; void completeComponent(const CompleteComponentCommand &command) override;
void token(const TokenCommand &command) override; void token(const TokenCommand &command) override;
void removeSharedMemory(const RemoveSharedMemoryCommand &command) override; void removeSharedMemory(const RemoveSharedMemoryCommand &command) override;
void changeSelection(const ChangeSelectionCommand &command) override;
protected: protected:
void collectItemChangesAndSendChangeCommands() override; void collectItemChangesAndSendChangeCommands() override;
@@ -49,6 +50,7 @@ protected:
void sendTokenBack(); void sendTokenBack();
bool isDirtyRecursiveForNonInstanceItems(QQuickItem *item) const; bool isDirtyRecursiveForNonInstanceItems(QQuickItem *item) const;
bool isDirtyRecursiveForParentInstances(QQuickItem *item) const; bool isDirtyRecursiveForParentInstances(QQuickItem *item) const;
void selectInstance(const ServerNodeInstance &instance);
private: private:
void setup3DEditView(const QList<ServerNodeInstance> &instanceList); void setup3DEditView(const QList<ServerNodeInstance> &instanceList);

View File

@@ -151,6 +151,11 @@ void Qt5TestNodeInstanceServer::clearScene(const ClearSceneCommand &command)
Qt5NodeInstanceServer::clearScene(command); Qt5NodeInstanceServer::clearScene(command);
} }
void Qt5TestNodeInstanceServer::changeSelection(const ChangeSelectionCommand &)
{
}
void Qt5TestNodeInstanceServer::removeInstances(const RemoveInstancesCommand &command) void Qt5TestNodeInstanceServer::removeInstances(const RemoveInstancesCommand &command)
{ {
ServerNodeInstance oldState = activeStateInstance(); ServerNodeInstance oldState = activeStateInstance();

View File

@@ -50,6 +50,7 @@ public:
void completeComponent(const CompleteComponentCommand &command) override; void completeComponent(const CompleteComponentCommand &command) override;
void changeNodeSource(const ChangeNodeSourceCommand &command) override; void changeNodeSource(const ChangeNodeSourceCommand &command) override;
void removeSharedMemory(const RemoveSharedMemoryCommand &command) override; void removeSharedMemory(const RemoveSharedMemoryCommand &command) override;
void changeSelection(const ChangeSelectionCommand &command) override;
using Qt5NodeInstanceServer::createInstances; using Qt5NodeInstanceServer::createInstances;

View File

@@ -138,6 +138,7 @@ extend_qtc_plugin(QmlDesigner
synchronizecommand.cpp synchronizecommand.h synchronizecommand.cpp synchronizecommand.h
tokencommand.cpp tokencommand.h tokencommand.cpp tokencommand.h
valueschangedcommand.cpp valueschangedcommand.h valueschangedcommand.cpp valueschangedcommand.h
changeselectioncommand.cpp changeselectioncommand.h
) )
extend_qtc_plugin(QmlDesigner extend_qtc_plugin(QmlDesigner

View File

@@ -64,6 +64,7 @@ class ChangeValuesCommand;
class ChangeBindingsCommand; class ChangeBindingsCommand;
class ChangeIdsCommand; class ChangeIdsCommand;
class RemoveInstancesCommand; class RemoveInstancesCommand;
class ChangeSelectionCommand;
class RemovePropertiesCommand; class RemovePropertiesCommand;
class CompleteComponentCommand; class CompleteComponentCommand;
class InformationContainer; class InformationContainer;
@@ -134,6 +135,11 @@ public:
void sendToken(const QString &token, int number, const QVector<ModelNode> &nodeVector); void sendToken(const QString &token, int number, const QVector<ModelNode> &nodeVector);
void selectionChanged(const ChangeSelectionCommand &command) override;
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> &lastSelectedNodeList) override;
protected: protected:
void timerEvent(QTimerEvent *event) override; void timerEvent(QTimerEvent *event) override;
@@ -173,6 +179,7 @@ private: // functions
ChangeBindingsCommand createChangeBindingCommand(const QList<BindingProperty> &propertyList) const; ChangeBindingsCommand createChangeBindingCommand(const QList<BindingProperty> &propertyList) const;
ChangeIdsCommand createChangeIdsCommand(const QList<NodeInstance> &instanceList) const; ChangeIdsCommand createChangeIdsCommand(const QList<NodeInstance> &instanceList) const;
RemoveInstancesCommand createRemoveInstancesCommand(const QList<ModelNode> &nodeList) const; RemoveInstancesCommand createRemoveInstancesCommand(const QList<ModelNode> &nodeList) const;
ChangeSelectionCommand createChangeSelectionCommand(const QList<ModelNode> &nodeList) const;
RemoveInstancesCommand createRemoveInstancesCommand(const ModelNode &node) const; RemoveInstancesCommand createRemoveInstancesCommand(const ModelNode &node) const;
RemovePropertiesCommand createRemovePropertiesCommand(const QList<AbstractProperty> &propertyList) const; RemovePropertiesCommand createRemovePropertiesCommand(const QList<AbstractProperty> &propertyList) const;
RemoveSharedMemoryCommand createRemoveSharedMemoryCommand(const QString &sharedMemoryTypeName, quint32 keyNumber); RemoveSharedMemoryCommand createRemoveSharedMemoryCommand(const QString &sharedMemoryTypeName, quint32 keyNumber);

View File

@@ -41,6 +41,7 @@
#include <changestatecommand.h> #include <changestatecommand.h>
#include <completecomponentcommand.h> #include <completecomponentcommand.h>
#include <changenodesourcecommand.h> #include <changenodesourcecommand.h>
#include <changeselectioncommand.h>
#include <informationchangedcommand.h> #include <informationchangedcommand.h>
#include <pixmapchangedcommand.h> #include <pixmapchangedcommand.h>
@@ -278,6 +279,7 @@ void NodeInstanceServerProxy::dispatchCommand(const QVariant &command, PuppetStr
static const int tokenCommandType = QMetaType::type("TokenCommand"); static const int tokenCommandType = QMetaType::type("TokenCommand");
static const int debugOutputCommandType = QMetaType::type("DebugOutputCommand"); static const int debugOutputCommandType = QMetaType::type("DebugOutputCommand");
static const int puppetAliveCommandType = QMetaType::type("PuppetAliveCommand"); static const int puppetAliveCommandType = QMetaType::type("PuppetAliveCommand");
static const int changeSelectionCommandType = QMetaType::type("ChangeSelectionCommand");
if (m_destructing) if (m_destructing)
return; return;
@@ -299,6 +301,8 @@ void NodeInstanceServerProxy::dispatchCommand(const QVariant &command, PuppetStr
nodeInstanceClient()->token(command.value<TokenCommand>()); nodeInstanceClient()->token(command.value<TokenCommand>());
} else if (command.userType() == debugOutputCommandType) { } else if (command.userType() == debugOutputCommandType) {
nodeInstanceClient()->debugOutput(command.value<DebugOutputCommand>()); nodeInstanceClient()->debugOutput(command.value<DebugOutputCommand>());
} else if (command.userType() == changeSelectionCommandType) {
nodeInstanceClient()->selectionChanged(command.value<ChangeSelectionCommand>());
} else if (command.userType() == puppetAliveCommandType) { } else if (command.userType() == puppetAliveCommandType) {
puppetAlive(puppetStreamType); puppetAlive(puppetStreamType);
} else if (command.userType() == synchronizeCommandType) { } else if (command.userType() == synchronizeCommandType) {
@@ -645,6 +649,11 @@ void NodeInstanceServerProxy::removeInstances(const RemoveInstancesCommand &comm
writeCommand(QVariant::fromValue(command)); writeCommand(QVariant::fromValue(command));
} }
void NodeInstanceServerProxy::changeSelection(const ChangeSelectionCommand &command)
{
writeCommand(QVariant::fromValue(command));
}
void NodeInstanceServerProxy::removeProperties(const RemovePropertiesCommand &command) void NodeInstanceServerProxy::removeProperties(const RemovePropertiesCommand &command)
{ {
writeCommand(QVariant::fromValue(command)); writeCommand(QVariant::fromValue(command));

View File

@@ -71,6 +71,7 @@ public:
void createScene(const CreateSceneCommand &command) override; void createScene(const CreateSceneCommand &command) override;
void clearScene(const ClearSceneCommand &command) override; void clearScene(const ClearSceneCommand &command) override;
void removeInstances(const RemoveInstancesCommand &command) override; void removeInstances(const RemoveInstancesCommand &command) override;
void changeSelection(const ChangeSelectionCommand &command) override;
void removeProperties(const RemovePropertiesCommand &command) override; void removeProperties(const RemovePropertiesCommand &command) override;
void changePropertyBindings(const ChangeBindingsCommand &command) override; void changePropertyBindings(const ChangeBindingsCommand &command) override;
void changePropertyValues(const ChangeValuesCommand &command) override; void changePropertyValues(const ChangeValuesCommand &command) override;

View File

@@ -51,6 +51,7 @@
#include "changeauxiliarycommand.h" #include "changeauxiliarycommand.h"
#include "changebindingscommand.h" #include "changebindingscommand.h"
#include "changeidscommand.h" #include "changeidscommand.h"
#include "changeselectioncommand.h"
#include "changenodesourcecommand.h" #include "changenodesourcecommand.h"
#include "removeinstancescommand.h" #include "removeinstancescommand.h"
#include "removepropertiescommand.h" #include "removepropertiescommand.h"
@@ -1109,6 +1110,21 @@ RemoveInstancesCommand NodeInstanceView::createRemoveInstancesCommand(const QLis
return RemoveInstancesCommand(idList); return RemoveInstancesCommand(idList);
} }
ChangeSelectionCommand NodeInstanceView::createChangeSelectionCommand(const QList<ModelNode> &nodeList) const
{
QVector<qint32> idList;
foreach (const ModelNode &node, nodeList) {
if (node.isValid() && hasInstanceForModelNode(node)) {
NodeInstance instance = instanceForModelNode(node);
if (instance.instanceId() >= 0)
idList.append(instance.instanceId());
}
}
return ChangeSelectionCommand(idList);
}
RemoveInstancesCommand NodeInstanceView::createRemoveInstancesCommand(const ModelNode &node) const RemoveInstancesCommand NodeInstanceView::createRemoveInstancesCommand(const ModelNode &node) const
{ {
QVector<qint32> idList; QVector<qint32> idList;
@@ -1364,6 +1380,20 @@ void NodeInstanceView::sendToken(const QString &token, int number, const QVector
nodeInstanceServer()->token(TokenCommand(token, number, instanceIdVector)); nodeInstanceServer()->token(TokenCommand(token, number, instanceIdVector));
} }
void NodeInstanceView::selectionChanged(const ChangeSelectionCommand &command)
{
foreach (const qint32 &instanceId, command.instanceIds()) {
if (hasModelNodeForInternalId(instanceId))
selectModelNode(modelNodeForInternalId(instanceId));
}
}
void NodeInstanceView::selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> & /*lastSelectedNodeList*/)
{
nodeInstanceServer()->changeSelection(createChangeSelectionCommand(selectedNodeList));
}
void NodeInstanceView::timerEvent(QTimerEvent *event) void NodeInstanceView::timerEvent(QTimerEvent *event)
{ {
if (m_restartProcessTimerId == event->timerId()) if (m_restartProcessTimerId == event->timerId())

View File

@@ -1464,6 +1464,10 @@ void ModelPrivate::changeSelectedNodes(const QList<InternalNode::Pointer> &newSe
Q_ASSERT(view != nullptr); Q_ASSERT(view != nullptr);
view->selectedNodesChanged(toModelNodeList(newSelectedNodeList, view.data()), toModelNodeList(oldSelectedNodeList, view.data())); view->selectedNodesChanged(toModelNodeList(newSelectedNodeList, view.data()), toModelNodeList(oldSelectedNodeList, view.data()));
} }
if (nodeInstanceView())
nodeInstanceView()->selectedNodesChanged(toModelNodeList(newSelectedNodeList, nodeInstanceView()),
toModelNodeList(oldSelectedNodeList, nodeInstanceView()));
} }
QList<InternalNode::Pointer> ModelPrivate::selectedNodes() const QList<InternalNode::Pointer> ModelPrivate::selectedNodes() const

View File

@@ -167,6 +167,8 @@ Project {
"commands/tokencommand.h", "commands/tokencommand.h",
"commands/valueschangedcommand.cpp", "commands/valueschangedcommand.cpp",
"commands/valueschangedcommand.h", "commands/valueschangedcommand.h",
"commands/changeselectioncommand.cpp",
"commands/changeselectioncommand.h",
"container/addimportcontainer.cpp", "container/addimportcontainer.cpp",
"container/addimportcontainer.h", "container/addimportcontainer.h",
"container/idcontainer.cpp", "container/idcontainer.cpp",

View File

@@ -44,6 +44,7 @@ extend_qtc_executable(qml2puppet
statepreviewimagechangedcommand.cpp statepreviewimagechangedcommand.h statepreviewimagechangedcommand.cpp statepreviewimagechangedcommand.h
synchronizecommand.cpp synchronizecommand.h synchronizecommand.cpp synchronizecommand.h
tokencommand.cpp tokencommand.h tokencommand.cpp tokencommand.h
changeselectioncommand.cpp changeselectioncommand.h
valueschangedcommand.cpp valueschangedcommand.cpp
) )

View File

@@ -93,6 +93,8 @@ QtcTool {
"commands/tokencommand.h", "commands/tokencommand.h",
"commands/valueschangedcommand.cpp", "commands/valueschangedcommand.cpp",
"commands/valueschangedcommand.h", "commands/valueschangedcommand.h",
"commands/changeselectioncommand.cpp",
"commands/changeselectioncommand.h",
"container/addimportcontainer.cpp", "container/addimportcontainer.cpp",
"container/addimportcontainer.h", "container/addimportcontainer.h",
"container/idcontainer.cpp", "container/idcontainer.cpp",