QmlDesigner: Add Qt5InformationNodeInstanceServer::modifyProperties()

This method allows to modify properties in the data model from
the puppet. For performance reasons, properties should be modified
in bulks. Each bulk will be one step on the undo stack.

Change-Id: I7dbef02781706c8638981512ca0ec45d24c54545
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Thomas Hartmann
2019-10-23 16:29:31 +02:00
parent 0ddd473cc0
commit 9469432035
4 changed files with 42 additions and 0 deletions

View File

@@ -1190,6 +1190,31 @@ ValuesChangedCommand NodeInstanceServer::createValuesChangedCommand(const QVecto
return ValuesChangedCommand(valueVector); return ValuesChangedCommand(valueVector);
} }
ValuesModifiedCommand NodeInstanceServer::createValuesModifiedCommand(
const QVector<InstancePropertyValueTriple> &propertyList) const
{
QVector<PropertyValueContainer> valueVector;
for (const InstancePropertyValueTriple &property : propertyList) {
const PropertyName propertyName = property.propertyName;
const ServerNodeInstance instance = property.instance;
const QVariant propertyValue = property.propertyValue;
if (instance.isValid()) {
if (QMetaType::isRegistered(propertyValue.userType())
&& supportedVariantType(propertyValue.type())) {
valueVector.append(PropertyValueContainer(instance.instanceId(),
propertyName,
propertyValue,
PropertyName()));
}
}
}
return ValuesModifiedCommand(valueVector);
}
QByteArray NodeInstanceServer::importCode() const QByteArray NodeInstanceServer::importCode() const
{ {
return m_importCode; return m_importCode;

View File

@@ -60,6 +60,7 @@ namespace QmlDesigner {
class NodeInstanceClientInterface; class NodeInstanceClientInterface;
class ValuesChangedCommand; class ValuesChangedCommand;
class ValuesModifiedCommand;
class PixmapChangedCommand; class PixmapChangedCommand;
class InformationChangedCommand; class InformationChangedCommand;
class ChildrenChangedCommand; class ChildrenChangedCommand;
@@ -82,6 +83,11 @@ public:
using IdPropertyPair = QPair<qint32, QString>; using IdPropertyPair = QPair<qint32, QString>;
using InstancePropertyPair= QPair<ServerNodeInstance, PropertyName>; using InstancePropertyPair= QPair<ServerNodeInstance, PropertyName>;
using DummyPair = QPair<QString, QPointer<QObject> >; using DummyPair = QPair<QString, QPointer<QObject> >;
using InstancePropertyValueTriple = struct {
ServerNodeInstance instance;
PropertyName propertyName;
QVariant propertyValue;
};
explicit NodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient); explicit NodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient);
@@ -168,6 +174,7 @@ protected:
ValuesChangedCommand createValuesChangedCommand(const QList<ServerNodeInstance> &instanceList) const; ValuesChangedCommand createValuesChangedCommand(const QList<ServerNodeInstance> &instanceList) const;
ValuesChangedCommand createValuesChangedCommand(const QVector<InstancePropertyPair> &propertyList) const; ValuesChangedCommand createValuesChangedCommand(const QVector<InstancePropertyPair> &propertyList) const;
ValuesModifiedCommand createValuesModifiedCommand(const QVector<InstancePropertyValueTriple> &propertyList) const;
PixmapChangedCommand createPixmapChangedCommand(const QList<ServerNodeInstance> &instanceList) const; PixmapChangedCommand createPixmapChangedCommand(const QList<ServerNodeInstance> &instanceList) const;
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;

View File

@@ -165,6 +165,15 @@ void Qt5InformationNodeInstanceServer::selectInstance(const ServerNodeInstance &
nodeInstanceClient()->selectionChanged(createChangeSelectionCommand({instance})); nodeInstanceClient()->selectionChanged(createChangeSelectionCommand({instance}));
} }
/* This method allows changing property values from the puppet
* For performance reasons (and the undo stack) properties should always be modifed in 'bulks'.
*/
void Qt5InformationNodeInstanceServer::modifyProperties(
const QVector<NodeInstanceServer::InstancePropertyValueTriple> &properties)
{
nodeInstanceClient()->valuesModified(createValuesModifiedCommand(properties));
}
QObject *Qt5InformationNodeInstanceServer::findRootNodeOf3DViewport( QObject *Qt5InformationNodeInstanceServer::findRootNodeOf3DViewport(
const QList<ServerNodeInstance> &instanceList) const const QList<ServerNodeInstance> &instanceList) const
{ {

View File

@@ -51,6 +51,7 @@ protected:
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); void selectInstance(const ServerNodeInstance &instance);
void modifyProperties(const QVector<InstancePropertyValueTriple> &properties);
private: private:
void setup3DEditView(const QList<ServerNodeInstance> &instanceList); void setup3DEditView(const QList<ServerNodeInstance> &instanceList);