QDebug operator<<(QDebug debug, const NodeAbstractProperty &property) { return debug.nospace() << "NodeAbstractProperty(" << (property.isValid() ? property.name() : PropertyName("invalid")) << ')'; }
QPair<PropertyName, ServerNodeInstance> ObjectNodeInstance::anchor(const PropertyName &/*name*/) const { return qMakePair(PropertyName(), ServerNodeInstance()); }
QmlItemNode QmlItemNode::createQmlItemNode(AbstractView *view, const ItemLibraryEntry &itemLibraryEntry, const QPointF &position, QmlItemNode parentQmlItemNode) { if (!parentQmlItemNode.isValid()) parentQmlItemNode = QmlItemNode(view->rootModelNode()); Q_ASSERT(parentQmlItemNode.isValid()); QmlItemNode newQmlItemNode; try { RewriterTransaction transaction = view->beginRewriterTransaction(QByteArrayLiteral("QmlItemNode::createQmlItemNode")); NodeMetaInfo metaInfo = view->model()->metaInfo(itemLibraryEntry.typeName()); int minorVersion = metaInfo.minorVersion(); int majorVersion = metaInfo.majorVersion(); if (itemLibraryEntry.typeName().contains('.')) { const QString newImportUrl = itemLibraryEntry.requiredImport(); if (!itemLibraryEntry.requiredImport().isEmpty()) { const QString newImportVersion = QString("%1.%2").arg(QString::number(itemLibraryEntry.majorVersion()), QString::number(itemLibraryEntry.minorVersion())); Import newImport = Import::createLibraryImport(newImportUrl, newImportVersion); if (itemLibraryEntry.majorVersion() == -1 && itemLibraryEntry.minorVersion() == -1) newImport = Import::createFileImport(newImportUrl, QString()); else newImport = Import::createLibraryImport(newImportUrl, newImportVersion); foreach (const Import &import, view->model()->imports()) { if (import.isLibraryImport() && import.url() == newImport.url() && import.version() == newImport.version()) { // reuse this import newImport = import; break; } } if (!view->model()->hasImport(newImport, true, true)) view->model()->changeImports(QList<Import>() << newImport, QList<Import>()); } } typedef QPair<PropertyName, QString> PropertyBindingEntry; QList<PropertyBindingEntry> propertyBindingList; if (itemLibraryEntry.qmlSource().isEmpty()) { QList<QPair<PropertyName, QVariant> > propertyPairList; propertyPairList.append(qMakePair(PropertyName("x"), QVariant(qRound(position.x())))); propertyPairList.append(qMakePair(PropertyName("y"), QVariant(qRound(position.y())))); foreach (const PropertyContainer &property, itemLibraryEntry.properties()) { if (property.type() == QLatin1String("binding")) { propertyBindingList.append(PropertyBindingEntry(property.name(), property.value().toString())); } else { propertyPairList.append(qMakePair(property.name(), property.value())); } } newQmlItemNode = QmlItemNode(view->createModelNode(itemLibraryEntry.typeName(), majorVersion, minorVersion, propertyPairList)); } else { newQmlItemNode = createQmlItemNodeFromSource(view, itemLibraryEntry.qmlSource(), position); } if (parentQmlItemNode.hasDefaultPropertyName()) parentQmlItemNode.nodeAbstractProperty(parentQmlItemNode.defaultPropertyName()).reparentHere(newQmlItemNode); if (!newQmlItemNode.isValid()) return newQmlItemNode; newQmlItemNode.setId(view->generateNewId(itemLibraryEntry.name())); if (!view->currentState().isBaseState()) { newQmlItemNode.modelNode().variantProperty("opacity").setValue(0); newQmlItemNode.setVariantProperty("opacity", 1); } foreach (const PropertyBindingEntry &propertyBindingEntry, propertyBindingList) newQmlItemNode.modelNode().bindingProperty(propertyBindingEntry.first).setExpression(propertyBindingEntry.second); Q_ASSERT(newQmlItemNode.isValid()); }
void NodeInstanceView::auxiliaryDataChanged(const ModelNode &node, const PropertyName &name, const QVariant &data) { if ((node.isRootNode() && (name == "width" || name == "height")) || name.endsWith(PropertyName("@NodeInstance"))) { if (hasInstanceForModelNode(node)) { NodeInstance instance = instanceForModelNode(node); QVariant value = data; if (value.isValid()) { PropertyValueContainer container(instance.instanceId(), name, value, TypeName()); ChangeAuxiliaryCommand changeAuxiliaryCommand(QVector<PropertyValueContainer>() << container); nodeInstanceServer()->changeAuxiliaryValues(changeAuxiliaryCommand); } else { if (node.hasVariantProperty(name)) { PropertyValueContainer container(instance.instanceId(), name, node.variantProperty(name).value(), TypeName()); ChangeValuesCommand changeValueCommand(QVector<PropertyValueContainer>() << container); nodeInstanceServer()->changePropertyValues(changeValueCommand); } else if (node.hasBindingProperty(name)) { PropertyBindingContainer container(instance.instanceId(), name, node.bindingProperty(name).expression(), TypeName()); ChangeBindingsCommand changeValueCommand(QVector<PropertyBindingContainer>() << container); nodeInstanceServer()->changePropertyBindings(changeValueCommand); } } } } }