Beispiel #1
0
static inline void applyProperties(ModelNode &node, const QHash<PropertyName, QVariant> &propertyHash)
{
    QHash<PropertyName, QVariant> auxiliaryData  = node.auxiliaryData();

    foreach (const PropertyName &propertyName, auxiliaryData.keys()) {
        if (node.hasAuxiliaryData(propertyName))
            node.setAuxiliaryData(propertyName, QVariant());
    }

    QHashIterator<PropertyName, QVariant> propertyIterator(propertyHash);
    while (propertyIterator.hasNext()) {
        propertyIterator.next();
        const PropertyName propertyName = propertyIterator.key();
        if (propertyName == "width" || propertyName == "height") {
            node.setAuxiliaryData(propertyIterator.key(), propertyIterator.value());
        } else if (node.property(propertyIterator.key()).isDynamic() &&
                   node.property(propertyIterator.key()).dynamicTypeName() == "alias" &&
                   node.property(propertyIterator.key()).isBindingProperty()) {
            AbstractProperty targetProperty = node.bindingProperty(propertyIterator.key()).resolveToProperty();
            if (targetProperty.isValid())
                targetProperty.parentModelNode().setAuxiliaryData(targetProperty.name() + "@NodeInstance", propertyIterator.value());
        } else {
            node.setAuxiliaryData(propertyIterator.key() + "@NodeInstance", propertyIterator.value());
        }
    }
}
Beispiel #2
0
static ModelNode resolveBinding(const QString &binding, ModelNode currentNode, AbstractView* view)
{
    int i = 0;
    QString element = binding.split(QLatin1Char('.')).at(0);
    while (!element.isEmpty())
    {
        if (element == "parent") {
            if (currentNode.hasParentProperty())
                currentNode = currentNode.parentProperty().toNodeAbstractProperty().parentModelNode();
            else
                return ModelNode(); //binding not valid
        } else if (currentNode.hasProperty(element)) {
            if (currentNode.property(element).isNodeProperty()) {
                currentNode = currentNode.nodeProperty(element).modelNode();
            } else {
                currentNode = view->modelNodeForId(element); //id
                if (!currentNode.isValid())
                    return ModelNode(); //binding not valid
            }
        } else {
            currentNode = view->modelNodeForId(element); //id
        }
        i++;
        if (i < binding.split(QLatin1Char('.')).count())
            element = binding.split(QLatin1Char('.')).at(i);
        else
            element.clear();
    }
    return currentNode;

}
QString QmlTextGenerator::propertiesToQml(const ModelNode &node, int indentDepth) const
{
    QString topPart;
    QString bottomPart;

    QStringList nodePropertyNames = node.propertyNames();
    bool addToTop = true;

    foreach (const QString &propertyName, m_propertyOrder) {
        if (QLatin1String("id") == propertyName) {
            // the model handles the id property special, so:
            if (!node.id().isEmpty()) {
                QString idLine(indentDepth, QLatin1Char(' '));
                idLine += QLatin1String("id: ");
                idLine += node.id();
                idLine += QLatin1Char('\n');

                if (addToTop)
                    topPart.append(idLine);
                else
                    bottomPart.append(idLine);
            }
        } else if (propertyName.isEmpty()) {
            addToTop = false;
        } else if (nodePropertyNames.removeAll(propertyName)) {
            const QString newContent = propertyToQml(node.property(propertyName), indentDepth);

            if (addToTop)
                topPart.append(newContent);
            else
                bottomPart.append(newContent);
        }
    }

    foreach (const QString &propertyName, nodePropertyNames) {
        bottomPart.prepend(propertyToQml(node.property(propertyName), indentDepth));
    }
static QList<ModelNode> acceptedModelNodeChildren(const ModelNode &parentNode)
{
    QList<ModelNode> children;
    PropertyNameList properties;

    if (parentNode.metaInfo().hasDefaultProperty())
        properties.append(parentNode.metaInfo().defaultPropertyName());

#ifndef DISABLE_VISIBLE_PROPERTIES
    properties.append(visibleProperties(parentNode));
#endif

    foreach (const PropertyName &propertyName, properties) {
        AbstractProperty property(parentNode.property(propertyName));
        if (property.isNodeAbstractProperty())
            children.append(property.toNodeAbstractProperty().directSubNodes());
    }
Beispiel #5
0
 void BehaviorDialog::setup(const ModelNode &node, const QString propertyName)
{
        m_modelNode = node;
        m_ui->duration->setValue(100);
        m_ui->velocity->setValue(2);
        m_ui->spring->setValue(2);
        m_ui->damping->setValue(2);
        m_ui->stackedWidget->setCurrentIndex(0);
        m_ui->curve->setCurrentIndex(0);

        if (m_modelNode.isValid()) {
            m_propertyName = propertyName;
            m_ui->id->setText(m_modelNode.id());
            m_ui->type->setText(m_modelNode.simplifiedTypeName());
            m_ui->propertyName->setText(propertyName);
            if (m_modelNode.hasProperty(m_propertyName) && m_modelNode.property(m_propertyName).isNodeProperty()) {
                NodeProperty nodeProperty(m_modelNode.nodeProperty(m_propertyName));
                if (nodeProperty.modelNode().type() == "Qt/SpringFollow") {
                    ModelNode springFollow = nodeProperty.modelNode();
                    m_ui->curve->setCurrentIndex(1);
                    m_ui->stackedWidget->setCurrentIndex(1);
                    if (springFollow.hasProperty("velocity") && springFollow.property("velocity").isVariantProperty())
                         m_ui->velocity->setValue(springFollow.variantProperty("velocity").value().toDouble());
                    if (springFollow.hasProperty("spring") && springFollow.property("spring").isVariantProperty())
                         m_ui->spring->setValue(springFollow.variantProperty("spring").value().toDouble());
                    if (springFollow.hasProperty("damping") && springFollow.property("damping").isVariantProperty())
                         m_ui->damping->setValue(springFollow.variantProperty("damping").value().toDouble());
                    if (springFollow.hasProperty("source") && springFollow.property("source").isVariantProperty())
                         m_ui->source->setText(springFollow.variantProperty("source").value().toString());
                } else if (nodeProperty.modelNode().type() == "Qt/Behavior") {
                    if (nodeProperty.modelNode().hasProperty("animation") &&
                        nodeProperty.modelNode().property("animation").isNodeProperty() &&
                        nodeProperty.modelNode().nodeProperty("animation").modelNode().type() == "Qt/NumberAnimation") {
                            m_ui->curve->setCurrentIndex(0);
                            ModelNode animation =  nodeProperty.modelNode().nodeProperty("animation").modelNode();
                            if (animation.hasProperty("duration") && animation.property("duration").isVariantProperty())
                                m_ui->duration->setValue(animation.variantProperty("duration").value().toInt());
                            if (animation.hasProperty("easing") && animation.property("easing").isVariantProperty()) {
                                QStringList easingItems;
                                for (int i = 0; i < m_ui->curve->count(); i++)
                                    easingItems.append(m_ui->curve->itemText(i));
                                m_ui->curve->setCurrentIndex(easingItems.indexOf(animation.variantProperty("easing").value().toString()));
                            }
                    }
                }
            }
        }
}
Beispiel #6
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();
}