diff options
author | Thomas Hartmann <thomas.hartmann@qt.io> | 2019-10-17 13:51:57 +0200 |
---|---|---|
committer | Alessandro Portale <alessandro.portale@qt.io> | 2019-10-21 05:52:13 +0000 |
commit | 640044c8f8d7c290558c63c636be7821f9a8a223 (patch) | |
tree | 5ec8d9dba9e5324cc42268c1b4a76a7c6c9dda5b | |
parent | e7b481bdee9759a3dc5efc3d55400394654fc592 (diff) | |
download | qt-creator-640044c8f8d7c290558c63c636be7821f9a8a223.tar.gz |
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>
23 files changed, 258 insertions, 4 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/commands/changeselectioncommand.cpp b/share/qtcreator/qml/qmlpuppet/commands/changeselectioncommand.cpp new file mode 100644 index 0000000000..a634e76b8f --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/commands/changeselectioncommand.cpp @@ -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 diff --git a/share/qtcreator/qml/qmlpuppet/commands/changeselectioncommand.h b/share/qtcreator/qml/qmlpuppet/commands/changeselectioncommand.h new file mode 100644 index 0000000000..a5962c5dcb --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/commands/changeselectioncommand.h @@ -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) diff --git a/share/qtcreator/qml/qmlpuppet/commands/commands.pri b/share/qtcreator/qml/qmlpuppet/commands/commands.pri index 3bf0305103..78dfcd8eb1 100644 --- a/share/qtcreator/qml/qmlpuppet/commands/commands.pri +++ b/share/qtcreator/qml/qmlpuppet/commands/commands.pri @@ -26,6 +26,7 @@ HEADERS += $$PWD/valueschangedcommand.h HEADERS += $$PWD/changeauxiliarycommand.h HEADERS += $$PWD/removesharedmemorycommand.h HEADERS += $$PWD/puppetalivecommand.h +HEADERS += $$PWD/changeselectioncommand.h SOURCES += $$PWD/synchronizecommand.cpp SOURCES += $$PWD/debugoutputcommand.cpp @@ -53,3 +54,4 @@ SOURCES += $$PWD/pixmapchangedcommand.cpp SOURCES += $$PWD/changeauxiliarycommand.cpp SOURCES += $$PWD/removesharedmemorycommand.cpp SOURCES += $$PWD/puppetalivecommand.cpp +SOURCES += $$PWD/changeselectioncommand.cpp diff --git a/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.cpp b/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.cpp index 5ac0e1057b..a4b9324699 100644 --- a/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.cpp +++ b/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.cpp @@ -67,6 +67,7 @@ #include "endpuppetcommand.h" #include "debugoutputcommand.h" #include "puppetalivecommand.h" +#include "changeselectioncommand.h" namespace QmlDesigner { @@ -136,6 +137,7 @@ bool compareCommands(const QVariant &command, const QVariant &controlCommand) static const int synchronizeCommandType = QMetaType::type("SynchronizeCommand"); static const int tokenCommandType = QMetaType::type("TokenCommand"); static const int debugOutputCommandType = QMetaType::type("DebugOutputCommand"); + static const int changeSelectionCommandType = QMetaType::type("ChangeSelectionCommand"); if (command.userType() == controlCommand.userType()) { if (command.userType() == informationChangedCommandType) @@ -156,6 +158,8 @@ bool compareCommands(const QVariant &command, const QVariant &controlCommand) return command.value<TokenCommand>() == controlCommand.value<TokenCommand>(); else if (command.userType() == debugOutputCommandType) return command.value<DebugOutputCommand>() == controlCommand.value<DebugOutputCommand>(); + else if (command.userType() == changeSelectionCommandType) + return command.value<ChangeSelectionCommand>() == controlCommand.value<ChangeSelectionCommand>(); } return false; @@ -233,6 +237,11 @@ void NodeInstanceClientProxy::puppetAlive(const PuppetAliveCommand &command) writeCommand(QVariant::fromValue(command)); } +void NodeInstanceClientProxy::selectionChanged(const ChangeSelectionCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + void NodeInstanceClientProxy::flush() { } @@ -252,9 +261,6 @@ qint64 NodeInstanceClientProxy::bytesToWrite() const QVariant NodeInstanceClientProxy::readCommandFromIOStream(QIODevice *ioDevice, quint32 *readCommandCounter, quint32 *blockSize) { - - - QDataStream in(ioDevice); in.setVersion(QDataStream::Qt_4_8); @@ -416,6 +422,11 @@ void NodeInstanceClientProxy::redirectToken(const EndPuppetCommand & /*command*/ QCoreApplication::exit(); } +void NodeInstanceClientProxy::changeSelection(const ChangeSelectionCommand &command) +{ + nodeInstanceServer()->changeSelection(command); +} + void NodeInstanceClientProxy::dispatchCommand(const QVariant &command) { 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 tokenCommandType = QMetaType::type("TokenCommand"); static const int endPuppetCommandType = QMetaType::type("EndPuppetCommand"); + static const int changeSelectionCommandType = QMetaType::type("ChangeSelectionCommand"); const int commandType = command.userType(); @@ -476,6 +488,9 @@ void NodeInstanceClientProxy::dispatchCommand(const QVariant &command) else if (commandType == synchronizeCommandType) { SynchronizeCommand synchronizeCommand = command.value<SynchronizeCommand>(); m_synchronizeId = synchronizeCommand.synchronizeId(); + } else if (commandType == changeSelectionCommandType) { + ChangeSelectionCommand changeSelectionCommand = command.value<ChangeSelectionCommand>(); + changeSelection(changeSelectionCommand); } else { Q_ASSERT(false); } diff --git a/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.h b/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.h index 2c53a77c90..8590a48a95 100644 --- a/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.h +++ b/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.h @@ -56,7 +56,7 @@ class CompleteComponentCommand; class ChangeStateCommand; class ChangeNodeSourceCommand; class EndPuppetCommand; - +class ChangeSelectionCommand; class NodeInstanceClientProxy : public QObject, public NodeInstanceClientInterface { @@ -74,6 +74,7 @@ public: void token(const TokenCommand &command) override; void debugOutput(const DebugOutputCommand &command) override; void puppetAlive(const PuppetAliveCommand &command); + void selectionChanged(const ChangeSelectionCommand &command) override; void flush() override; void synchronizeWithClientProcess() override; @@ -104,6 +105,7 @@ protected: void removeSharedMemory(const RemoveSharedMemoryCommand &command); void redirectToken(const TokenCommand &command); void redirectToken(const EndPuppetCommand &command); + void changeSelection(const ChangeSelectionCommand &command); static QVariant readCommandFromIOStream(QIODevice *ioDevice, quint32 *readCommandCounter, quint32 *blockSize); protected slots: diff --git a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceclientinterface.h b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceclientinterface.h index 43c50b510c..1f49f277f5 100644 --- a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceclientinterface.h +++ b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceclientinterface.h @@ -39,6 +39,7 @@ class TokenCommand; class RemoveSharedMemoryCommand; class DebugOutputCommand; class PuppetAliveCommand; +class ChangeSelectionCommand; class NodeInstanceClientInterface { @@ -51,6 +52,7 @@ public: virtual void componentCompleted(const ComponentCompletedCommand &command) = 0; virtual void token(const TokenCommand &command) = 0; virtual void debugOutput(const DebugOutputCommand &command) = 0; + virtual void selectionChanged(const ChangeSelectionCommand &command) = 0; virtual void flush() {} virtual void synchronizeWithClientProcess() {} diff --git a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.cpp b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.cpp index 8d1ad20c31..90907b5092 100644 --- a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.cpp +++ b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.cpp @@ -45,6 +45,7 @@ #include "completecomponentcommand.h" #include "addimportcontainer.h" #include "changenodesourcecommand.h" +#include "changeselectioncommand.h" #include "informationchangedcommand.h" #include "pixmapchangedcommand.h" @@ -103,6 +104,9 @@ void NodeInstanceServerInterface::registerCommands() qRegisterMetaType<RemoveInstancesCommand>("RemoveInstancesCommand"); qRegisterMetaTypeStreamOperators<RemoveInstancesCommand>("RemoveInstancesCommand"); + qRegisterMetaType<ChangeSelectionCommand>("ChangeSelectionCommand"); + qRegisterMetaTypeStreamOperators<ChangeSelectionCommand>("ChangeSelectionCommand"); + qRegisterMetaType<RemovePropertiesCommand>("RemovePropertiesCommand"); qRegisterMetaTypeStreamOperators<RemovePropertiesCommand>("RemovePropertiesCommand"); diff --git a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.h b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.h index 0fddbde5c0..b452c802be 100644 --- a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.h +++ b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.h @@ -49,6 +49,7 @@ class CompleteComponentCommand; class ChangeNodeSourceCommand; class TokenCommand; class RemoveSharedMemoryCommand; +class ChangeSelectionCommand; class NodeInstanceServerInterface : public QObject { @@ -77,6 +78,7 @@ public: virtual void changeNodeSource(const ChangeNodeSourceCommand &command) = 0; virtual void token(const TokenCommand &command) = 0; virtual void removeSharedMemory(const RemoveSharedMemoryCommand &command) = 0; + virtual void changeSelection(const ChangeSelectionCommand &command) = 0; virtual void benchmark(const QString &) {} diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp index 60d34c909d..356d173e09 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp @@ -66,6 +66,7 @@ #include <changenodesourcecommand.h> #include <tokencommand.h> #include <removesharedmemorycommand.h> +#include <changeselectioncommand.h> #include <QDebug> #include <QQmlEngine> @@ -330,6 +331,10 @@ void NodeInstanceServer::clearScene(const ClearSceneCommand &/*command*/) m_fileUrl.clear(); } +void NodeInstanceServer::changeSelection(const ChangeSelectionCommand & /*command*/) +{ +} + void NodeInstanceServer::removeInstances(const RemoveInstancesCommand &command) { ServerNodeInstance oldState = activeStateInstance(); @@ -1157,6 +1162,17 @@ ComponentCompletedCommand NodeInstanceServer::createComponentCompletedCommand(co 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 { QVector<PropertyValueContainer> valueVector; diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.h index fb8b081b45..65c2bdfac1 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.h +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.h @@ -68,6 +68,7 @@ class ComponentCompletedCommand; class AddImportContainer; class MockupTypeContainer; class IdContainer; +class ChangeSelectionCommand; namespace Internal { class ChildrenChangeEventFilter; @@ -101,6 +102,7 @@ public: void changeNodeSource(const ChangeNodeSourceCommand &command) override; void token(const TokenCommand &command) override; void removeSharedMemory(const RemoveSharedMemoryCommand &command) override; + void changeSelection(const ChangeSelectionCommand &command) override; ServerNodeInstance instanceForId(qint32 id) const; bool hasInstanceForId(qint32 id) const; @@ -170,6 +172,7 @@ protected: InformationChangedCommand createAllInformationChangedCommand(const QList<ServerNodeInstance> &instanceList, bool initial = false) const; ChildrenChangedCommand createChildrenChangedCommand(const ServerNodeInstance &parentInstance, const QList<ServerNodeInstance> &instanceList) const; ComponentCompletedCommand createComponentCompletedCommand(const QList<ServerNodeInstance> &instanceList); + ChangeSelectionCommand createChangeSelectionCommand(const QList<ServerNodeInstance> &instanceList); void addChangedProperty(const InstancePropertyPair &property); diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp index 2b644b5959..4754181a77 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp @@ -55,6 +55,7 @@ #include "createscenecommand.h" #include "tokencommand.h" #include "removesharedmemorycommand.h" +#include "changeselectioncommand.h" #include "dummycontextobject.h" @@ -147,6 +148,12 @@ bool Qt5InformationNodeInstanceServer::isDirtyRecursiveForParentInstances(QQuick return false; } +/* This method allows changing the selection from the puppet */ +void Qt5InformationNodeInstanceServer::selectInstance(const ServerNodeInstance &instance) +{ + nodeInstanceClient()->selectionChanged(createChangeSelectionCommand({instance})); +} + QObject *Qt5InformationNodeInstanceServer::findRootNodeOf3DViewport( const QList<ServerNodeInstance> &instanceList) const { @@ -358,4 +365,10 @@ void QmlDesigner::Qt5InformationNodeInstanceServer::removeSharedMemory(const Qml ValuesChangedCommand::removeSharedMemorys(command.keyNumbers()); } +void Qt5InformationNodeInstanceServer::changeSelection(const ChangeSelectionCommand &command) +{ + // keep track of selection. + qDebug() << Q_FUNC_INFO << command; +} + } // namespace QmlDesigner diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h index 9254cb4157..962336ccdc 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h @@ -42,6 +42,7 @@ public: void completeComponent(const CompleteComponentCommand &command) override; void token(const TokenCommand &command) override; void removeSharedMemory(const RemoveSharedMemoryCommand &command) override; + void changeSelection(const ChangeSelectionCommand &command) override; protected: void collectItemChangesAndSendChangeCommands() override; @@ -49,6 +50,7 @@ protected: void sendTokenBack(); bool isDirtyRecursiveForNonInstanceItems(QQuickItem *item) const; bool isDirtyRecursiveForParentInstances(QQuickItem *item) const; + void selectInstance(const ServerNodeInstance &instance); private: void setup3DEditView(const QList<ServerNodeInstance> &instanceList); diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5testnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5testnodeinstanceserver.cpp index cb5af3dc80..fed075a486 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5testnodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5testnodeinstanceserver.cpp @@ -151,6 +151,11 @@ void Qt5TestNodeInstanceServer::clearScene(const ClearSceneCommand &command) Qt5NodeInstanceServer::clearScene(command); } +void Qt5TestNodeInstanceServer::changeSelection(const ChangeSelectionCommand &) +{ + +} + void Qt5TestNodeInstanceServer::removeInstances(const RemoveInstancesCommand &command) { ServerNodeInstance oldState = activeStateInstance(); diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5testnodeinstanceserver.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5testnodeinstanceserver.h index af30c423d6..18c2056174 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5testnodeinstanceserver.h +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5testnodeinstanceserver.h @@ -50,6 +50,7 @@ public: void completeComponent(const CompleteComponentCommand &command) override; void changeNodeSource(const ChangeNodeSourceCommand &command) override; void removeSharedMemory(const RemoveSharedMemoryCommand &command) override; + void changeSelection(const ChangeSelectionCommand &command) override; using Qt5NodeInstanceServer::createInstances; diff --git a/src/plugins/qmldesigner/CMakeLists.txt b/src/plugins/qmldesigner/CMakeLists.txt index 9bf5fab113..c645a96774 100644 --- a/src/plugins/qmldesigner/CMakeLists.txt +++ b/src/plugins/qmldesigner/CMakeLists.txt @@ -138,6 +138,7 @@ extend_qtc_plugin(QmlDesigner synchronizecommand.cpp synchronizecommand.h tokencommand.cpp tokencommand.h valueschangedcommand.cpp valueschangedcommand.h + changeselectioncommand.cpp changeselectioncommand.h ) extend_qtc_plugin(QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h b/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h index f77ac4645b..258fc9aa2d 100644 --- a/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h +++ b/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h @@ -64,6 +64,7 @@ class ChangeValuesCommand; class ChangeBindingsCommand; class ChangeIdsCommand; class RemoveInstancesCommand; +class ChangeSelectionCommand; class RemovePropertiesCommand; class CompleteComponentCommand; class InformationContainer; @@ -134,6 +135,11 @@ public: 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: void timerEvent(QTimerEvent *event) override; @@ -173,6 +179,7 @@ private: // functions ChangeBindingsCommand createChangeBindingCommand(const QList<BindingProperty> &propertyList) const; ChangeIdsCommand createChangeIdsCommand(const QList<NodeInstance> &instanceList) const; RemoveInstancesCommand createRemoveInstancesCommand(const QList<ModelNode> &nodeList) const; + ChangeSelectionCommand createChangeSelectionCommand(const QList<ModelNode> &nodeList) const; RemoveInstancesCommand createRemoveInstancesCommand(const ModelNode &node) const; RemovePropertiesCommand createRemovePropertiesCommand(const QList<AbstractProperty> &propertyList) const; RemoveSharedMemoryCommand createRemoveSharedMemoryCommand(const QString &sharedMemoryTypeName, quint32 keyNumber); diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.cpp index e7d60b25d2..c5b98bf325 100644 --- a/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.cpp +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.cpp @@ -41,6 +41,7 @@ #include <changestatecommand.h> #include <completecomponentcommand.h> #include <changenodesourcecommand.h> +#include <changeselectioncommand.h> #include <informationchangedcommand.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 debugOutputCommandType = QMetaType::type("DebugOutputCommand"); static const int puppetAliveCommandType = QMetaType::type("PuppetAliveCommand"); + static const int changeSelectionCommandType = QMetaType::type("ChangeSelectionCommand"); if (m_destructing) return; @@ -299,6 +301,8 @@ void NodeInstanceServerProxy::dispatchCommand(const QVariant &command, PuppetStr nodeInstanceClient()->token(command.value<TokenCommand>()); } else if (command.userType() == debugOutputCommandType) { nodeInstanceClient()->debugOutput(command.value<DebugOutputCommand>()); + } else if (command.userType() == changeSelectionCommandType) { + nodeInstanceClient()->selectionChanged(command.value<ChangeSelectionCommand>()); } else if (command.userType() == puppetAliveCommandType) { puppetAlive(puppetStreamType); } else if (command.userType() == synchronizeCommandType) { @@ -645,6 +649,11 @@ void NodeInstanceServerProxy::removeInstances(const RemoveInstancesCommand &comm writeCommand(QVariant::fromValue(command)); } +void NodeInstanceServerProxy::changeSelection(const ChangeSelectionCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + void NodeInstanceServerProxy::removeProperties(const RemovePropertiesCommand &command) { writeCommand(QVariant::fromValue(command)); diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.h b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.h index b1525b4408..a6a7f6ce99 100644 --- a/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.h +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.h @@ -71,6 +71,7 @@ public: void createScene(const CreateSceneCommand &command) override; void clearScene(const ClearSceneCommand &command) override; void removeInstances(const RemoveInstancesCommand &command) override; + void changeSelection(const ChangeSelectionCommand &command) override; void removeProperties(const RemovePropertiesCommand &command) override; void changePropertyBindings(const ChangeBindingsCommand &command) override; void changePropertyValues(const ChangeValuesCommand &command) override; diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp index 66d503078b..5d44e5069c 100644 --- a/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp @@ -51,6 +51,7 @@ #include "changeauxiliarycommand.h" #include "changebindingscommand.h" #include "changeidscommand.h" +#include "changeselectioncommand.h" #include "changenodesourcecommand.h" #include "removeinstancescommand.h" #include "removepropertiescommand.h" @@ -1109,6 +1110,21 @@ RemoveInstancesCommand NodeInstanceView::createRemoveInstancesCommand(const QLis 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 { QVector<qint32> idList; @@ -1364,6 +1380,20 @@ void NodeInstanceView::sendToken(const QString &token, int number, const QVector 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) { if (m_restartProcessTimerId == event->timerId()) diff --git a/src/plugins/qmldesigner/designercore/model/model.cpp b/src/plugins/qmldesigner/designercore/model/model.cpp index 8699389182..e3598b09c0 100644 --- a/src/plugins/qmldesigner/designercore/model/model.cpp +++ b/src/plugins/qmldesigner/designercore/model/model.cpp @@ -1464,6 +1464,10 @@ void ModelPrivate::changeSelectedNodes(const QList<InternalNode::Pointer> &newSe Q_ASSERT(view != nullptr); 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 diff --git a/src/plugins/qmldesigner/qmldesignerplugin.qbs b/src/plugins/qmldesigner/qmldesignerplugin.qbs index c62c75be98..0d7b54c68e 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.qbs +++ b/src/plugins/qmldesigner/qmldesignerplugin.qbs @@ -167,6 +167,8 @@ Project { "commands/tokencommand.h", "commands/valueschangedcommand.cpp", "commands/valueschangedcommand.h", + "commands/changeselectioncommand.cpp", + "commands/changeselectioncommand.h", "container/addimportcontainer.cpp", "container/addimportcontainer.h", "container/idcontainer.cpp", diff --git a/src/tools/qml2puppet/CMakeLists.txt b/src/tools/qml2puppet/CMakeLists.txt index 3715ae9349..3db1cb34cd 100644 --- a/src/tools/qml2puppet/CMakeLists.txt +++ b/src/tools/qml2puppet/CMakeLists.txt @@ -44,6 +44,7 @@ extend_qtc_executable(qml2puppet statepreviewimagechangedcommand.cpp statepreviewimagechangedcommand.h synchronizecommand.cpp synchronizecommand.h tokencommand.cpp tokencommand.h + changeselectioncommand.cpp changeselectioncommand.h valueschangedcommand.cpp ) diff --git a/src/tools/qml2puppet/qml2puppet.qbs b/src/tools/qml2puppet/qml2puppet.qbs index 02a6f6e31f..bc67e79a1a 100644 --- a/src/tools/qml2puppet/qml2puppet.qbs +++ b/src/tools/qml2puppet/qml2puppet.qbs @@ -93,6 +93,8 @@ QtcTool { "commands/tokencommand.h", "commands/valueschangedcommand.cpp", "commands/valueschangedcommand.h", + "commands/changeselectioncommand.cpp", + "commands/changeselectioncommand.h", "container/addimportcontainer.cpp", "container/addimportcontainer.h", "container/idcontainer.cpp", |