Esempio n. 1
0
void PropertyEditor::NodeType::setup(const QmlObjectNode &fxObjectNode, const QString &stateName, const QUrl &qmlSpecificsFile, PropertyEditor *propertyEditor)
{
    if (!fxObjectNode.isValid())
        return;

    QDeclarativeContext *ctxt = m_view->rootContext();

    if (fxObjectNode.isValid()) {
        foreach (const PropertyName &propertyName, fxObjectNode.modelNode().metaInfo().propertyNames())
            createPropertyEditorValue(fxObjectNode, propertyName, fxObjectNode.instanceValue(propertyName), &m_backendValuesPropertyMap, propertyEditor);

        // className
        PropertyEditorValue *valueObject = qobject_cast<PropertyEditorValue*>(variantToQObject(m_backendValuesPropertyMap.value("className")));
        if (!valueObject)
            valueObject = new PropertyEditorValue(&m_backendValuesPropertyMap);
        valueObject->setName("className");
        valueObject->setModelNode(fxObjectNode.modelNode());
        valueObject->setValue(fxObjectNode.modelNode().simplifiedTypeName());
        QObject::connect(valueObject, SIGNAL(valueChanged(QString,QVariant)), &m_backendValuesPropertyMap, SIGNAL(valueChanged(QString,QVariant)));
        m_backendValuesPropertyMap.insert("className", QVariant::fromValue(valueObject));

        // id
        valueObject = qobject_cast<PropertyEditorValue*>(variantToQObject(m_backendValuesPropertyMap.value("id")));
        if (!valueObject)
            valueObject = new PropertyEditorValue(&m_backendValuesPropertyMap);
        valueObject->setName("id");
        valueObject->setValue(fxObjectNode.id());
        QObject::connect(valueObject, SIGNAL(valueChanged(QString,QVariant)), &m_backendValuesPropertyMap, SIGNAL(valueChanged(QString,QVariant)));
        m_backendValuesPropertyMap.insert("id", QVariant::fromValue(valueObject));

        // anchors
        m_backendAnchorBinding.setup(QmlItemNode(fxObjectNode.modelNode()));

        ctxt->setContextProperty("anchorBackend", &m_backendAnchorBinding);

        ctxt->setContextProperty("transaction", m_propertyEditorTransaction.data());

        m_contextObject->setSpecificsUrl(qmlSpecificsFile);

        m_contextObject->setStateName(stateName);
        if (!fxObjectNode.isValid())
            return;
        ctxt->setContextProperty("propertyCount", QVariant(fxObjectNode.modelNode().properties().count()));

        m_contextObject->setIsBaseState(fxObjectNode.isInBaseState());
        m_contextObject->setSelectionChanged(false);

        m_contextObject->setSelectionChanged(false);

        NodeMetaInfo metaInfo = fxObjectNode.modelNode().metaInfo();

        if (metaInfo.isValid()) {
            m_contextObject->setMajorVersion(metaInfo.majorVersion());
            m_contextObject->setMinorVersion(metaInfo.minorVersion());
        } else {
            m_contextObject->setMajorVersion(-1);
            m_contextObject->setMinorVersion(-1);
        }

    } else {
Esempio n. 2
0
QmlItemNode QmlItemNode::createQmlItemNode(AbstractView *view, const ItemLibraryEntry &itemLibraryEntry, const QPointF &position, NodeAbstractProperty parentproperty)
{
    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();

        typedef QPair<PropertyName, QString> PropertyBindingEntry;
        QList<PropertyBindingEntry> propertyBindingList;
        if (itemLibraryEntry.qmlSource().isEmpty()) {
            QList<QPair<PropertyName, QVariant> > propertyPairList;
            if (!position.isNull()) {
                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() == QStringLiteral("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 (parentproperty.isValid())
            parentproperty.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());
    }
Esempio n. 3
0
void MetaInfoPrivate::parseNonQmlClassRecursively(const QMetaObject *qMetaObject)
{
    Q_ASSERT_X(qMetaObject, Q_FUNC_INFO, "invalid QMetaObject");

    QString typeName;
    int majorVersion = -1;
    int minorVersion = -1;
    typeInfo(qMetaObject, &typeName, &majorVersion, &minorVersion);

    if (typeName.isEmpty()) {
        qWarning() << "Meta type system: Registered class has no name.";
        return;
    }

    NodeMetaInfo existingInfo = m_q->nodeMetaInfo(typeName, majorVersion, minorVersion);
    if (existingInfo.isValid()
        && existingInfo.majorVersion() == majorVersion
        && existingInfo.minorVersion() == minorVersion) {
        return;
    }

    NodeMetaInfo nodeMetaInfo(*m_q);
    nodeMetaInfo.setType(typeName, majorVersion, minorVersion);
    parseProperties(nodeMetaInfo, qMetaObject);
    parseClassInfo(nodeMetaInfo, qMetaObject);

    QString superTypeName;
    int superTypeMajorVersion = -1;
    int superTypeMinorVersion = -1;

    if (qMetaObject->superClass()) {
        typeInfo(qMetaObject->superClass(), &superTypeName, &superTypeMajorVersion, &superTypeMinorVersion);
        nodeMetaInfo.setSuperClass(superTypeName, superTypeMajorVersion, superTypeMinorVersion);
    }
    if (debug)
        qDebug() << "adding non qml type" << nodeMetaInfo.typeName() << nodeMetaInfo.majorVersion() << nodeMetaInfo.minorVersion()
                 << ", parent type" << superTypeName << superTypeMajorVersion << superTypeMinorVersion;

    m_q->addNodeInfo(nodeMetaInfo);

    if (const QMetaObject *superClass = qMetaObject->superClass())
        parseNonQmlClassRecursively(superClass);
}
void PropertyEditorContextObject::changeTypeName(const QString &typeName)
{

    if (!m_model || !m_model->rewriterView())
        return;

    /* Ideally we should not missuse the rewriterView
     * If we add more code here we have to forward the property editor view */
    RewriterView *rewriterView = m_model->rewriterView();

    if (rewriterView->selectedModelNodes().isEmpty())
        return;

    ModelNode selectedNode = rewriterView->selectedModelNodes().constFirst();

    try {
        RewriterTransaction transaction =
                rewriterView->beginRewriterTransaction(QByteArrayLiteral("PropertyEditorContextObject:changeTypeName"));

        NodeMetaInfo metaInfo = m_model->metaInfo(typeName.toLatin1());
        if (!metaInfo.isValid()) {
            Core::AsynchronousMessageBox::warning(tr("Invalid Type"),  tr("%1 is an invalid type.").arg(typeName));
            return;
        }
        if (selectedNode.isRootNode())
             rewriterView->changeRootNodeType(metaInfo.typeName(), metaInfo.majorVersion(), metaInfo.minorVersion());
        else
            selectedNode.changeType(metaInfo.typeName(), metaInfo.majorVersion(), metaInfo.minorVersion());

        transaction.commit();
    }  catch (RewritingException &exception) { //better safe than sorry! There always might be cases where we fail
        exception.showException();
    }


}
Esempio n. 5
0
static ModelNode createNodeFromNode(const ModelNode &modelNode,const QHash<QString, QString> &idRenamingHash, AbstractView *view)
{
    QList<QPair<PropertyName, QVariant> > propertyList;
    QList<QPair<PropertyName, QVariant> > variantPropertyList;
    foreach (const VariantProperty &variantProperty, modelNode.variantProperties()) {
        propertyList.append(QPair<PropertyName, QVariant>(variantProperty.name(), variantProperty.value()));
    }
    NodeMetaInfo nodeMetaInfo = view->model()->metaInfo(modelNode.type());
    ModelNode newNode(view->createModelNode(modelNode.type(), nodeMetaInfo.majorVersion(), nodeMetaInfo.minorVersion(),
                                            propertyList, variantPropertyList, modelNode.nodeSource(), modelNode.nodeSourceType()));
    syncBindingProperties(newNode, modelNode, idRenamingHash);
    syncId(newNode, modelNode, idRenamingHash);
    syncNodeProperties(newNode, modelNode, idRenamingHash, view);
    syncNodeListProperties(newNode, modelNode, idRenamingHash, view);

    return newNode;
}
Esempio n. 6
0
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();

        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>());
            }
        }

        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())
                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);
        }

        Q_ASSERT(newQmlItemNode.isValid());
    }