QmlPuppet: Refactor ChangeBindingsCommand

Change-Id: Id3020a73f59a1adfd25066a37d083d923e77956b
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Michael Winkelmann
2020-08-19 14:07:10 +02:00
parent 098d32b370
commit 95aa7f42de
5 changed files with 19 additions and 48 deletions

View File

@@ -29,35 +29,9 @@
namespace QmlDesigner { namespace QmlDesigner {
ChangeBindingsCommand::ChangeBindingsCommand() = default;
ChangeBindingsCommand::ChangeBindingsCommand(const QVector<PropertyBindingContainer> &bindingChangeVector)
: m_bindingChangeVector (bindingChangeVector)
{
}
QVector<PropertyBindingContainer> ChangeBindingsCommand::bindingChanges() const
{
return m_bindingChangeVector;
}
QDataStream &operator<<(QDataStream &out, const ChangeBindingsCommand &command)
{
out << command.bindingChanges();
return out;
}
QDataStream &operator>>(QDataStream &in, ChangeBindingsCommand &command)
{
in >> command.m_bindingChangeVector;
return in;
}
QDebug operator <<(QDebug debug, const ChangeBindingsCommand &command) QDebug operator <<(QDebug debug, const ChangeBindingsCommand &command)
{ {
return debug.nospace() << "PropertyValueContainer(bindingChanges: " << command.m_bindingChangeVector << ")"; return debug.nospace() << "PropertyValueContainer(bindingChanges: " << command.bindingChanges << ")";
} }
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -34,24 +34,22 @@ namespace QmlDesigner {
class ChangeBindingsCommand class ChangeBindingsCommand
{ {
friend QDataStream &operator>>(QDataStream &in, ChangeBindingsCommand &command); public:
friend QDataStream &operator>>(QDataStream &in, ChangeBindingsCommand &command) {
in >> command.bindingChanges;
return in;
}
friend QDataStream &operator<<(QDataStream &out, const ChangeBindingsCommand &command) {
out << command.bindingChanges;
return out;
}
friend QDebug operator <<(QDebug debug, const ChangeBindingsCommand &command); friend QDebug operator <<(QDebug debug, const ChangeBindingsCommand &command);
public: QVector<PropertyBindingContainer> bindingChanges;
ChangeBindingsCommand();
explicit ChangeBindingsCommand(const QVector<PropertyBindingContainer> &bindingChangeVector);
QVector<PropertyBindingContainer> bindingChanges() const;
private:
QVector<PropertyBindingContainer> m_bindingChangeVector;
}; };
QDataStream &operator<<(QDataStream &out, const ChangeBindingsCommand &command);
QDataStream &operator>>(QDataStream &in, ChangeBindingsCommand &command);
QDebug operator <<(QDebug debug, const ChangeBindingsCommand &command);
} // namespace QmlDesigner } // namespace QmlDesigner
Q_DECLARE_METATYPE(QmlDesigner::ChangeBindingsCommand) Q_DECLARE_METATYPE(QmlDesigner::ChangeBindingsCommand)

View File

@@ -643,7 +643,7 @@ void NodeInstanceServer::changeAuxiliaryValues(const ChangeAuxiliaryCommand &com
void NodeInstanceServer::changePropertyBindings(const ChangeBindingsCommand &command) void NodeInstanceServer::changePropertyBindings(const ChangeBindingsCommand &command)
{ {
bool hasDynamicProperties = false; bool hasDynamicProperties = false;
foreach (const PropertyBindingContainer &container, command.bindingChanges()) { for (const PropertyBindingContainer &container : command.bindingChanges) {
hasDynamicProperties |= container.isDynamic(); hasDynamicProperties |= container.isDynamic();
setInstancePropertyBinding(container); setInstancePropertyBinding(container);
} }

View File

@@ -103,7 +103,7 @@ void Qt5TestNodeInstanceServer::changePropertyValues(const ChangeValuesCommand &
void Qt5TestNodeInstanceServer::changePropertyBindings(const ChangeBindingsCommand &command) void Qt5TestNodeInstanceServer::changePropertyBindings(const ChangeBindingsCommand &command)
{ {
bool hasDynamicProperties = false; bool hasDynamicProperties = false;
foreach (const PropertyBindingContainer &container, command.bindingChanges()) { for (const PropertyBindingContainer &container : command.bindingChanges) {
hasDynamicProperties |= container.isDynamic(); hasDynamicProperties |= container.isDynamic();
setInstancePropertyBinding(container); setInstancePropertyBinding(container);
} }

View File

@@ -543,9 +543,8 @@ void NodeInstanceView::auxiliaryDataChanged(const ModelNode &node,
ChangeValuesCommand changeValueCommand({container}); ChangeValuesCommand changeValueCommand({container});
m_nodeInstanceServer->changePropertyValues(changeValueCommand); m_nodeInstanceServer->changePropertyValues(changeValueCommand);
} else if (node.hasBindingProperty(name)) { } else if (node.hasBindingProperty(name)) {
PropertyBindingContainer container(instance.instanceId(), name, node.bindingProperty(name).expression(), TypeName()); PropertyBindingContainer container{instance.instanceId(), name, node.bindingProperty(name).expression(), TypeName()};
ChangeBindingsCommand changeValueCommand({container}); m_nodeInstanceServer->changePropertyBindings({{container}});
m_nodeInstanceServer->changePropertyBindings(changeValueCommand);
} }
} }
} }
@@ -1131,7 +1130,7 @@ ChangeBindingsCommand NodeInstanceView::createChangeBindingCommand(const QList<B
{ {
QVector<PropertyBindingContainer> containerList; QVector<PropertyBindingContainer> containerList;
foreach (const BindingProperty &property, propertyList) { for (const BindingProperty &property : propertyList) {
ModelNode node = property.parentModelNode(); ModelNode node = property.parentModelNode();
if (node.isValid() && hasInstanceForModelNode(node)) { if (node.isValid() && hasInstanceForModelNode(node)) {
NodeInstance instance = instanceForModelNode(node); NodeInstance instance = instanceForModelNode(node);
@@ -1141,7 +1140,7 @@ ChangeBindingsCommand NodeInstanceView::createChangeBindingCommand(const QList<B
} }
return ChangeBindingsCommand(containerList); return {containerList};
} }
ChangeIdsCommand NodeInstanceView::createChangeIdsCommand(const QList<NodeInstance> &instanceList) const ChangeIdsCommand NodeInstanceView::createChangeIdsCommand(const QList<NodeInstance> &instanceList) const