summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Hartmann <thomas.hartmann@qt.io>2019-10-18 16:55:08 +0200
committerThomas Hartmann <thomas.hartmann@qt.io>2019-10-21 12:47:28 +0000
commit49379bfda7324c6ec0222c0f0c5ee6e40d98b222 (patch)
tree1042de859b5cbfa8b84c291e71d7f3c0c473dcbd
parentb4bc204a7d3b36f0d40e368ceb9f359622a41e2c (diff)
downloadqt-creator-49379bfda7324c6ec0222c0f0c5ee6e40d98b222.tar.gz
QmlDesigner: Add and dispatch ValuesModifiedCommand
We already have valuesChanged() which notifies that a property of the C++ QObject has changed. This patch adds valuesModified() which notifies that values in the data model should be changed. While valuesChanged() only changes the so called instance value, valuesModified() does change the internal data model and as a result the QML code. This is done in NodeInstanceView::valuesModified(). This enabled the qml2puppet to acutally change values, like a property editor would. Change-Id: I2493b9e626c4b194e332a7a096de3dbf2195514a Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
-rw-r--r--share/qtcreator/qml/qmlpuppet/commands/valueschangedcommand.cpp2
-rw-r--r--share/qtcreator/qml/qmlpuppet/commands/valueschangedcommand.h22
-rw-r--r--share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.cpp10
-rw-r--r--share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.h1
-rw-r--r--share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceclientinterface.h2
-rw-r--r--share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.cpp3
-rw-r--r--src/plugins/qmldesigner/designercore/include/nodeinstanceview.h1
-rw-r--r--src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.cpp9
-rw-r--r--src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp14
9 files changed, 58 insertions, 6 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/commands/valueschangedcommand.cpp b/share/qtcreator/qml/qmlpuppet/commands/valueschangedcommand.cpp
index 73c8138a43..c5468bc999 100644
--- a/share/qtcreator/qml/qmlpuppet/commands/valueschangedcommand.cpp
+++ b/share/qtcreator/qml/qmlpuppet/commands/valueschangedcommand.cpp
@@ -50,7 +50,7 @@ ValuesChangedCommand::ValuesChangedCommand(const QVector<PropertyValueContainer>
{
}
-QVector<PropertyValueContainer> ValuesChangedCommand::valueChanges() const
+const QVector<PropertyValueContainer> ValuesChangedCommand::valueChanges() const
{
return m_valueChangeVector;
}
diff --git a/share/qtcreator/qml/qmlpuppet/commands/valueschangedcommand.h b/share/qtcreator/qml/qmlpuppet/commands/valueschangedcommand.h
index 96050aee7f..bf7fe1e43d 100644
--- a/share/qtcreator/qml/qmlpuppet/commands/valueschangedcommand.h
+++ b/share/qtcreator/qml/qmlpuppet/commands/valueschangedcommand.h
@@ -42,7 +42,7 @@ public:
ValuesChangedCommand();
explicit ValuesChangedCommand(const QVector<PropertyValueContainer> &valueChangeVector);
- QVector<PropertyValueContainer> valueChanges() const;
+ const QVector<PropertyValueContainer> valueChanges() const;
quint32 keyNumber() const;
static void removeSharedMemorys(const QVector<qint32> &keyNumberVector);
@@ -59,6 +59,26 @@ QDataStream &operator>>(QDataStream &in, ValuesChangedCommand &command);
bool operator ==(const ValuesChangedCommand &first, const ValuesChangedCommand &second);
QDebug operator <<(QDebug debug, const ValuesChangedCommand &instance);
+
+/* ValuesChangedCommand is used to notify that the values of a specific instatiated
+ * QObject changed.
+ * The ValuesModifiedCommand is used to notify that a user changed a QML property and
+ * that this property should be changed in the data model.
+ */
+
+class ValuesModifiedCommand : public ValuesChangedCommand
+{
+public:
+ ValuesModifiedCommand()
+ {}
+ explicit ValuesModifiedCommand(const QVector<PropertyValueContainer> &valueChangeVector)
+ : ValuesChangedCommand(valueChangeVector)
+ {}
+
+};
+
} // namespace QmlDesigner
+
+Q_DECLARE_METATYPE(QmlDesigner::ValuesModifiedCommand)
Q_DECLARE_METATYPE(QmlDesigner::ValuesChangedCommand)
diff --git a/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.cpp b/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.cpp
index a4b9324699..3e57baffd0 100644
--- a/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.cpp
+++ b/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.cpp
@@ -130,6 +130,7 @@ bool compareCommands(const QVariant &command, const QVariant &controlCommand)
{
static const int informationChangedCommandType = QMetaType::type("InformationChangedCommand");
static const int valuesChangedCommandType = QMetaType::type("ValuesChangedCommand");
+ static const int valuesModifiedCommandType = QMetaType::type("ValuesModifiedCommand");
static const int pixmapChangedCommandType = QMetaType::type("PixmapChangedCommand");
static const int childrenChangedCommandType = QMetaType::type("ChildrenChangedCommand");
static const int statePreviewImageChangedCommandType = QMetaType::type("StatePreviewImageChangedCommand");
@@ -144,7 +145,9 @@ bool compareCommands(const QVariant &command, const QVariant &controlCommand)
return command.value<InformationChangedCommand>() == controlCommand.value<InformationChangedCommand>();
else if (command.userType() == valuesChangedCommandType)
return command.value<ValuesChangedCommand>() == controlCommand.value<ValuesChangedCommand>();
- else if (command.userType() == pixmapChangedCommandType)
+ else if (command.userType() == valuesModifiedCommandType)
+ return command.value<ValuesModifiedCommand>() == controlCommand.value<ValuesModifiedCommand>();
+ else if (command.userType() == pixmapChangedCommandType)
return command.value<PixmapChangedCommand>() == controlCommand.value<PixmapChangedCommand>();
else if (command.userType() == childrenChangedCommandType)
return command.value<ChildrenChangedCommand>() == controlCommand.value<ChildrenChangedCommand>();
@@ -202,6 +205,11 @@ void NodeInstanceClientProxy::valuesChanged(const ValuesChangedCommand &command)
writeCommand(QVariant::fromValue(command));
}
+void NodeInstanceClientProxy::valuesModified(const ValuesModifiedCommand &command)
+{
+ writeCommand(QVariant::fromValue(command));
+}
+
void NodeInstanceClientProxy::pixmapChanged(const PixmapChangedCommand &command)
{
writeCommand(QVariant::fromValue(command));
diff --git a/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.h b/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.h
index 8590a48a95..edf290f38a 100644
--- a/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.h
+++ b/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.h
@@ -67,6 +67,7 @@ public:
void informationChanged(const InformationChangedCommand &command) override;
void valuesChanged(const ValuesChangedCommand &command) override;
+ void valuesModified(const ValuesModifiedCommand &command) override;
void pixmapChanged(const PixmapChangedCommand &command) override;
void childrenChanged(const ChildrenChangedCommand &command) override;
void statePreviewImagesChanged(const StatePreviewImageChangedCommand &command) override;
diff --git a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceclientinterface.h b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceclientinterface.h
index 1f49f277f5..0b5a5ca334 100644
--- a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceclientinterface.h
+++ b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceclientinterface.h
@@ -30,6 +30,7 @@
namespace QmlDesigner {
class ValuesChangedCommand;
+class ValuesModifiedCommand;
class PixmapChangedCommand;
class InformationChangedCommand;
class ChildrenChangedCommand;
@@ -46,6 +47,7 @@ class NodeInstanceClientInterface
public:
virtual void informationChanged(const InformationChangedCommand &command) = 0;
virtual void valuesChanged(const ValuesChangedCommand &command) = 0;
+ virtual void valuesModified(const ValuesModifiedCommand &command) = 0;
virtual void pixmapChanged(const PixmapChangedCommand &command) = 0;
virtual void childrenChanged(const ChildrenChangedCommand &command) = 0;
virtual void statePreviewImagesChanged(const StatePreviewImageChangedCommand &command) = 0;
diff --git a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.cpp b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.cpp
index 90907b5092..d2b7cb2620 100644
--- a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.cpp
+++ b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.cpp
@@ -125,6 +125,9 @@ void NodeInstanceServerInterface::registerCommands()
qRegisterMetaType<ValuesChangedCommand>("ValuesChangedCommand");
qRegisterMetaTypeStreamOperators<ValuesChangedCommand>("ValuesChangedCommand");
+ qRegisterMetaType<ValuesModifiedCommand>("ValuesModifiedCommand");
+ qRegisterMetaTypeStreamOperators<ValuesModifiedCommand>("ValuesModifiedCommand");
+
qRegisterMetaType<PixmapChangedCommand>("PixmapChangedCommand");
qRegisterMetaTypeStreamOperators<PixmapChangedCommand>("PixmapChangedCommand");
diff --git a/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h b/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h
index 258fc9aa2d..1e1032900b 100644
--- a/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h
+++ b/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h
@@ -120,6 +120,7 @@ public:
void updatePosition(const QList<VariantProperty>& propertyList);
void valuesChanged(const ValuesChangedCommand &command) override;
+ void valuesModified(const ValuesModifiedCommand &command) override;
void pixmapChanged(const PixmapChangedCommand &command) override;
void informationChanged(const InformationChangedCommand &command) override;
void childrenChanged(const ChildrenChangedCommand &command) override;
diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.cpp
index c5b98bf325..3d57b3a16a 100644
--- a/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.cpp
+++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.cpp
@@ -271,6 +271,7 @@ void NodeInstanceServerProxy::dispatchCommand(const QVariant &command, PuppetStr
{
static const int informationChangedCommandType = QMetaType::type("InformationChangedCommand");
static const int valuesChangedCommandType = QMetaType::type("ValuesChangedCommand");
+ static const int valuesModifiedCommandType = QMetaType::type("ValuesModifiedCommand");
static const int pixmapChangedCommandType = QMetaType::type("PixmapChangedCommand");
static const int childrenChangedCommandType = QMetaType::type("ChildrenChangedCommand");
static const int statePreviewImageChangedCommandType = QMetaType::type("StatePreviewImageChangedCommand");
@@ -285,11 +286,13 @@ void NodeInstanceServerProxy::dispatchCommand(const QVariant &command, PuppetStr
return;
qCInfo(instanceViewBenchmark) << "dispatching command" << command.userType() << command.typeName();
- if (command.userType() == informationChangedCommandType) {
+ if (command.userType() == informationChangedCommandType) {
nodeInstanceClient()->informationChanged(command.value<InformationChangedCommand>());
- } else if (command.userType() == valuesChangedCommandType) {
+ } else if (command.userType() == valuesChangedCommandType) {
nodeInstanceClient()->valuesChanged(command.value<ValuesChangedCommand>());
- } else if (command.userType() == pixmapChangedCommandType) {
+ } else if (command.userType() == valuesModifiedCommandType) {
+ nodeInstanceClient()->valuesModified(command.value<ValuesModifiedCommand>());
+ } else if (command.userType() == pixmapChangedCommandType) {
nodeInstanceClient()->pixmapChanged(command.value<PixmapChangedCommand>());
} else if (command.userType() == childrenChangedCommandType) {
nodeInstanceClient()->childrenChanged(command.value<ChildrenChangedCommand>());
diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp
index 5d44e5069c..7200231267 100644
--- a/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp
+++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp
@@ -1190,6 +1190,20 @@ void NodeInstanceView::valuesChanged(const ValuesChangedCommand &command)
emitInstancePropertyChange(valuePropertyChangeList);
}
+void NodeInstanceView::valuesModified(const ValuesModifiedCommand &command)
+{
+ if (!model())
+ return;
+
+ for (const PropertyValueContainer &container : command.valueChanges()) {
+ if (hasInstanceForId(container.instanceId())) {
+ NodeInstance instance = instanceForId(container.instanceId());
+ if (instance.isValid())
+ instance.modelNode().variantProperty(container.name()).setValue(container.value());
+ }
+ }
+}
+
void NodeInstanceView::pixmapChanged(const PixmapChangedCommand &command)
{
if (!model())