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>
This commit is contained in:
Thomas Hartmann
2019-10-18 16:55:08 +02:00
parent b4bc204a7d
commit 49379bfda7
9 changed files with 58 additions and 6 deletions

View File

@@ -50,7 +50,7 @@ ValuesChangedCommand::ValuesChangedCommand(const QVector<PropertyValueContainer>
{
}
QVector<PropertyValueContainer> ValuesChangedCommand::valueChanges() const
const QVector<PropertyValueContainer> ValuesChangedCommand::valueChanges() const
{
return m_valueChangeVector;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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