void NodeProperty::setModelNode(const ModelNode &modelNode)
{
    if (!isValid())
        throw InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);

    if (!modelNode.isValid())
        throw InvalidArgumentException(__LINE__, __FUNCTION__, __FILE__, name());

    if (internalNode()->hasProperty(name())) { //check if oldValue != value
        Internal::InternalProperty::Pointer internalProperty = internalNode()->property(name());
        if (internalProperty->isNodeProperty()
            && internalProperty->toNodeProperty()->node() == modelNode.internalNode())
            return;
    }

    if (internalNode()->hasProperty(name()) && !internalNode()->property(name())->isNodeProperty())
        model()->d->removeProperty(internalNode()->property(name()));

    model()->d->reparentNode(internalNode(), name(), modelNode.internalNode(), false); //### we have to add a flag that this is not a list
}
Beispiel #2
0
void ModelRewriter::setAnchorMargin(const InternalNodeState::Pointer &state, const QString &propertyName, const QVariant &value)
{
    if (state.isNull() || !state->isValid())
        throw InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);

    if (state->propertyLocation(propertyName).isValid()) {
        if (value.toDouble() == 0.0 && state->isBaseState())
            m_modelToTextMerger.removeProperty(state, propertyName);
        else
            m_modelToTextMerger.changePropertyValue(state, propertyName, value);
    } else {
        if (value.toDouble() == 0.0 && state->isBaseState()) {
            // do nothing
        } else {
            m_modelToTextMerger.addProperty(state, propertyName, value);
        }
    }

    if (!modificationGroupActive())
        m_modelToTextMerger.applyChanges(*m_textModifier);
}
Beispiel #3
0
AbstractProperty BindingProperty::resolveToProperty() const
{
    if (!isValid())
        throw InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);

    QString binding = expression();
    ModelNode node = parentModelNode();
    QString element;
    if (binding.contains(QLatin1Char('.'))) {
        element = binding.split(QLatin1Char('.')).last();
        QString nodeBinding = binding;
        nodeBinding.chop(element.length());
        node = resolveBinding(nodeBinding, parentModelNode(), view());
    } else {
        element = binding;
    }

    if (node.isValid())
        return node.property(element);
    else
        return AbstractProperty();
}
Beispiel #4
0
void VariantProperty::setValue(const QVariant &value)
{
    Internal::WriteLocker locker(model());
    if (!isValid())
        throw InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);

    if (value.isNull())
        throw InvalidArgumentException(__LINE__, __FUNCTION__, __FILE__, name());

    if (internalNode()->hasProperty(name())) { //check if oldValue != value
        Internal::InternalProperty::Pointer internalProperty = internalNode()->property(name());
        if (internalProperty->isVariantProperty()
            && internalProperty->toVariantProperty()->value() == value
            && dynamicTypeName().isEmpty())

            return;
    }

    if (internalNode()->hasProperty(name()) && !internalNode()->property(name())->isVariantProperty())
        model()->d->removeProperty(internalNode()->property(name()));

    model()->d->setVariantProperty(internalNode(), name(), value);
}