ModelNode QmlModelStateOperation::target() const { if (modelNode().property("target").isBindingProperty()) return modelNode().bindingProperty("target").resolveToModelNode(); else return ModelNode(); //exception? }
QmlModelState QmlModelState::duplicate(const QString &name) const { if (!isValid()) throw new InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__); QmlItemNode parentNode(modelNode().parentProperty().parentModelNode()); if (!parentNode.isValid()) throw new InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__); // QmlModelState newState(stateGroup().addState(name)); PropertyListType propertyList; propertyList.append(qMakePair(QString("name"), QVariant(name))); QmlModelState newState ( qmlModelView()->createQmlState(propertyList) ); foreach (const ModelNode &childNode, modelNode().nodeListProperty("changes").toModelNodeList()) { ModelNode newModelNode(qmlModelView()->createModelNode(childNode.type(), childNode.majorVersion(), childNode.minorVersion())); foreach (const BindingProperty &bindingProperty, childNode.bindingProperties()) newModelNode.bindingProperty(bindingProperty.name()).setExpression(bindingProperty.expression()); foreach (const VariantProperty &variantProperty, childNode.variantProperties()) newModelNode.variantProperty(variantProperty.name()) = variantProperty.value(); newState.modelNode().nodeListProperty("changes").reparentHere(newModelNode); } modelNode().parentProperty().reparentHere(newState); return newState; }
void QmlAnchorBindingProxy::fill() { RewriterTransaction transaction = m_fxItemNode.modelNode().view()->beginRewriterTransaction(); backupPropertyAndRemove(modelNode(), "x"); backupPropertyAndRemove(modelNode(), "y"); backupPropertyAndRemove(modelNode(), "width"); backupPropertyAndRemove(modelNode(), "height"); m_fxItemNode.anchors().fill(); setHorizontalCentered(false); setVerticalCentered(false); m_fxItemNode.anchors().removeMargin(AnchorLine::Right); m_fxItemNode.anchors().removeMargin(AnchorLine::Left); m_fxItemNode.anchors().removeMargin(AnchorLine::Top); m_fxItemNode.anchors().removeMargin(AnchorLine::Bottom); emit topAnchorChanged(); emit bottomAnchorChanged(); emit leftAnchorChanged(); emit rightAnchorChanged(); emit anchorsChanged(); }
void QmlAnchorBindingProxy::setLeftAnchor(bool anchor) { if (!m_qmlItemNode.hasNodeParent()) return; if (leftAnchored() == anchor) return; RewriterTransaction transaction = beginRewriterTransaction( QByteArrayLiteral("QmlAnchorBindingProxy::setLeftAnchor")); if (!anchor) { removeLeftAnchor(); } else { setDefaultRelativeLeftTarget(); anchorLeft(); backupPropertyAndRemove(modelNode(), "x"); if (rightAnchored()) backupPropertyAndRemove(modelNode(), "width"); } emit relativeAnchorTargetLeftChanged(); emit leftAnchorChanged(); if (hasAnchors() != anchor) emit anchorsChanged(); }
void QmlAnchorBindingProxy::fill() { RewriterTransaction transaction = beginRewriterTransaction( QByteArrayLiteral("QmlAnchorBindingProxy::fill")); backupPropertyAndRemove(modelNode(), "x"); backupPropertyAndRemove(modelNode(), "y"); backupPropertyAndRemove(modelNode(), "width"); backupPropertyAndRemove(modelNode(), "height"); m_qmlItemNode.anchors().fill(); setHorizontalCentered(false); setVerticalCentered(false); m_qmlItemNode.anchors().removeMargin(AnchorLineRight); m_qmlItemNode.anchors().removeMargin(AnchorLineLeft); m_qmlItemNode.anchors().removeMargin(AnchorLineTop); m_qmlItemNode.anchors().removeMargin(AnchorLineBottom); emit topAnchorChanged(); emit bottomAnchorChanged(); emit leftAnchorChanged(); emit rightAnchorChanged(); emit anchorsChanged(); }
void QmlAnchorBindingProxy::setTopAnchor(bool anchor) { if (!m_qmlItemNode.hasNodeParent()) return ; if (topAnchored() == anchor) return; RewriterTransaction transaction = beginRewriterTransaction( QByteArrayLiteral("QmlAnchorBindingProxy::setTopAnchor")); if (!anchor) { removeTopAnchor(); } else { setDefaultRelativeTopTarget(); anchorTop(); backupPropertyAndRemove(modelNode(), "y"); if (bottomAnchored()) backupPropertyAndRemove(modelNode(), "height"); } emit relativeAnchorTargetTopChanged(); emit topAnchorChanged(); if (hasAnchors() != anchor) emit anchorsChanged(); }
QVariant PropertyEditorValue::value() const { QVariant returnValue = m_value; if (modelNode().isValid() && modelNode().metaInfo().isValid() && modelNode().metaInfo().hasProperty(name())) if (modelNode().metaInfo().propertyTypeName(name()) == "QUrl") returnValue = returnValue.toUrl().toString(); return returnValue; }
void QmlAnchorBindingProxy::removeLeftAnchor() { RewriterTransaction transaction = m_fxItemNode.modelNode().view()->beginRewriterTransaction(); m_fxItemNode.anchors().removeAnchor(AnchorLine::Left); m_fxItemNode.anchors().removeMargin(AnchorLine::Left); restoreProperty(modelNode(), "x"); restoreProperty(modelNode(), "width"); }
void QmlPropertyChanges::removeProperty(const PropertyName &name) { RewriterTransaction transaction(view()->beginRewriterTransaction(QByteArrayLiteral("QmlPropertyChanges::removeProperty"))); if (name == "name") return; modelNode().removeProperty(name); if (modelNode().variantProperties().isEmpty() && modelNode().bindingProperties().count() < 2) modelNode().destroy(); }
void QmlAnchorBindingProxy::removeLeftAnchor() { RewriterTransaction transaction = m_qmlItemNode.modelNode().view()->beginRewriterTransaction(QByteArrayLiteral("QmlAnchorBindingProxy::removeLeftAnchor")); m_qmlItemNode.anchors().removeAnchor(AnchorLineLeft); m_qmlItemNode.anchors().removeMargin(AnchorLineLeft); restoreProperty(modelNode(), "x"); restoreProperty(modelNode(), "width"); }
void QmlPropertyChanges::removeProperty(const QString &name) { RewriterTransaction transaction(qmlModelView()->beginRewriterTransaction()); if (name == "name") return; modelNode().removeProperty(name); if (modelNode().variantProperties().isEmpty() && modelNode().bindingProperties().count() < 2) modelNode().destroy(); }
void QmlAnchorBindingProxy::removeTopAnchor() { RewriterTransaction transaction = m_fxItemNode.modelNode().view()->beginRewriterTransaction(); m_fxItemNode.anchors().removeAnchor(AnchorLine::Top); m_fxItemNode.anchors().removeMargin(AnchorLine::Top); restoreProperty(modelNode(), "y"); restoreProperty(modelNode(), "height"); }
void QmlAnchorBindingProxy::removeTopAnchor() { RewriterTransaction transaction = beginRewriterTransaction( QByteArrayLiteral("QmlAnchorBindingProxy::removeTopAnchor")); m_qmlItemNode.anchors().removeAnchor(AnchorLineTop); m_qmlItemNode.anchors().removeMargin(AnchorLineTop); restoreProperty(modelNode(), "y"); restoreProperty(modelNode(), "height"); }
/*! \brief Deletes this objects ModeNode and its dependencies from the model Every thing that belongs to this Object, the ModelNode and ChangeOperations are deleted from the model. */ void QmlObjectNode::destroy() { if (!isValid()) throw new InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__); foreach (const QmlModelStateOperation &stateOperation, allAffectingStatesOperations()) { stateOperation.modelNode().destroy(); //remove of belonging StatesOperations } removeStateOperationsForChildren(modelNode()); modelNode().destroy(); }
void QmlObjectNode::ensureAliasExport() { if (!isValid()) throw new InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__); if (!isAliasExported()) { modelNode().validId(); PropertyName modelNodeId = modelNode().id().toUtf8(); ModelNode rootModelNode = view()->rootModelNode(); rootModelNode.bindingProperty(modelNodeId).setDynamicTypeNameAndExpression("alias", modelNodeId); } }
void BehaviorWidget::setComplexNode(PropertyEditorNodeWrapper* complexNode) { m_complexNode = complexNode; m_propertyName = complexNode->propertyName(); m_modelNode = complexNode->parentModelNode(); if (!modelNode().isValid()) { m_BehaviorDialog->hide(); } m_BehaviorDialog->setup(modelNode(), propertyName()); }
QList<QmlModelStateOperation> QmlObjectNode::allAffectingStatesOperations() const { if (!isValid()) throw new InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__); QList<QmlModelStateOperation> returnList; foreach (const QmlModelState &state, allDefinedStates()) { if (state.affectsModelNode(modelNode())) returnList.append(state.stateOperations(modelNode())); } return returnList; }
void PropertyEditorValue::setValue(const QVariant &value) { if (!compareVariants(m_value, value) && !cleverDoubleCompare(value, m_value) && !cleverColorCompare(value, m_value)) m_value = value; fixAmbigousColorNames(modelNode(), name(), &m_value); fixUrl(modelNode(), name(), &m_value); if (m_value.isValid()) emit valueChangedQml(); emit isBoundChanged(); }
QString PropertyEditorValue::getTranslationContext() const { if (modelNode().isValid() && modelNode().metaInfo().isValid() && modelNode().metaInfo().hasProperty(name())) { if (modelNode().metaInfo().propertyTypeName(name()) == "QString" || modelNode().metaInfo().propertyTypeName(name()) == "string") { const QmlDesigner::QmlObjectNode objectNode(modelNode()); if (objectNode.isValid() && objectNode.hasBindingProperty(name())) { QRegExp rx("qsTranslate\\(\"(.*)\"\\s*,\\s*\".*\"\\s*\\)"); if (rx.exactMatch(expression())) return rx.cap(1); } } } return QString(); }
bool QmlObjectNode::isAliasExported() const { if (modelNode().isValid() && !modelNode().id().isEmpty()) { PropertyName modelNodeId = modelNode().id().toUtf8(); ModelNode rootModelNode = view()->rootModelNode(); Q_ASSERT(rootModelNode.isValid()); if (rootModelNode.hasBindingProperty(modelNodeId) && rootModelNode.bindingProperty(modelNodeId).isDynamic() && rootModelNode.bindingProperty(modelNodeId).expression().toUtf8() == modelNodeId) return true; } return false; }
bool PropertyEditorValue::isTranslated() const { if (modelNode().isValid() && modelNode().metaInfo().isValid() && modelNode().metaInfo().hasProperty(name())) if (modelNode().metaInfo().propertyTypeName(name()) == QLatin1String("QString") || modelNode().metaInfo().propertyTypeName(name()) == QLatin1String("string")) { const QmlDesigner::QmlObjectNode objectNode(modelNode()); if (objectNode.isValid() && objectNode.hasBindingProperty(name())) { //qsTr() QRegExp rx("qsTr(\"*\")"); rx.setPatternSyntax(QRegExp::Wildcard); return rx.exactMatch(expression()); } return false; } return false; }
QString QmlModelState::name() const { if (isBaseState()) return QString(); return modelNode().variantProperty("name").value().toString(); }
void QmlAnchorBindingProxy::resetLayout() { RewriterTransaction transaction = m_fxItemNode.modelNode().view()->beginRewriterTransaction(); m_fxItemNode.anchors().removeAnchors(); m_fxItemNode.anchors().removeMargins(); restoreProperty(modelNode(), "x"); restoreProperty(modelNode(), "y"); restoreProperty(modelNode(), "width"); restoreProperty(modelNode(), "height"); emit topAnchorChanged(); emit bottomAnchorChanged(); emit leftAnchorChanged(); emit rightAnchorChanged(); emit anchorsChanged(); }
void QmlAnchorBindingProxy::resetLayout() { RewriterTransaction transaction = beginRewriterTransaction( QByteArrayLiteral("QmlAnchorBindingProxy::resetLayout")); m_qmlItemNode.anchors().removeAnchors(); m_qmlItemNode.anchors().removeMargins(); restoreProperty(modelNode(), "x"); restoreProperty(modelNode(), "y"); restoreProperty(modelNode(), "width"); restoreProperty(modelNode(), "height"); emit topAnchorChanged(); emit bottomAnchorChanged(); emit leftAnchorChanged(); emit rightAnchorChanged(); emit anchorsChanged(); }
void PropertyEditorValue::setValueWithEmit(const QVariant &value) { if (m_value != value || isBound()) { QVariant newValue = value; if (modelNode().isValid() && modelNode().metaInfo().isValid() && modelNode().metaInfo().hasProperty(name())) if (modelNode().metaInfo().propertyTypeName(name()) == "QUrl") newValue = QUrl(newValue.toString()); if (cleverDoubleCompare(newValue, m_value)) return; if (cleverColorCompare(newValue, m_value)) return; setValue(newValue); m_isBound = false; emit valueChanged(name(), value); emit valueChangedQml(); emit isBoundChanged(); } }
bool PropertyEditorValue::hasPropertyAlias() const { if (!modelNode().isValid()) return false; if (modelNode().isRootNode()) return false; if (!modelNode().hasId()) return false; QString id = modelNode().id(); for (const QmlDesigner::BindingProperty &property : modelNode().view()->rootModelNode().bindingProperties()) if (property.expression() == (id + "." + nameAsQString())) return true; return false; }
void ObjectNodeInstance::setPropertyBinding(const QString &name, const QString &expression) { QDeclarativeProperty property(object(), name, context()); if (!property.isValid()) return; if (property.isProperty()) { QDeclarativeBinding *binding = new QDeclarativeBinding(expression, object(), context()); binding->setTarget(property); binding->setNotifyOnValueChanged(true); QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, binding); if (oldBinding) oldBinding->destroy(); binding->update(); } else { qWarning() << "Cannot set binding for property" << name << ": property is unknown for type" << (modelNode().isValid() ? modelNode().type() : "unknown"); } }
QList<QmlPropertyChanges> QmlModelState::propertyChanges() const { //### exception if not valid QList<QmlPropertyChanges> returnList; if (isBaseState()) return returnList; if (!modelNode().hasProperty("changes")) return returnList; Q_ASSERT(modelNode().property("changes").isNodeListProperty()); foreach (const ModelNode &childNode, modelNode().nodeListProperty("changes").toModelNodeList()) { //### exception if not valid QmlModelStateOperation if (QmlPropertyChanges(childNode).isValid()) returnList.append(QmlPropertyChanges(childNode)); } return returnList; }
QList<QmlObjectNode> QmlModelState::allAffectedNodes() const { QList<QmlObjectNode> returnList; foreach (const ModelNode &childNode, modelNode().nodeListProperty("changes").toModelNodeList()) { //### exception if not valid QmlModelStateOperation if (QmlModelStateOperation(childNode).isValid() && !returnList.contains(QmlModelStateOperation(childNode).target())) returnList.append(QmlModelStateOperation(childNode).target()); } return returnList; }
QmlPropertyChanges QmlModelState::propertyChanges(const ModelNode &node) { if (!isBaseState()) { addChangeSetIfNotExists(node); foreach (const ModelNode &childNode, modelNode().nodeListProperty("changes").toModelNodeList()) { //### exception if not valid QmlModelStateOperation if (QmlPropertyChanges::isValidQmlPropertyChanges(childNode) && QmlPropertyChanges(childNode).target().isValid() && QmlPropertyChanges(childNode).target() == node) return QmlPropertyChanges(childNode); //### exception if not valid(childNode); } }