コード例 #1
0
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();
    }


}
コード例 #2
0
/*! \brief major number of the QtQuick version used
\return major number of QtQuickVersion
*/
int ModelNode::majorQtQuickVersion() const
{
    if (!isValid()) {
        Q_ASSERT_X(isValid(), Q_FUNC_INFO, "model node is invalid");
        throw InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);
    }

    if (metaInfo().isValid()) {
        NodeMetaInfo superClass = metaInfo().directSuperClass();

        while (superClass.isValid()) {
            if (superClass.typeName() == "QtQuick.Item")
                return superClass.majorVersion();
            superClass = superClass.directSuperClass();
        }
        return 1; //default
    }
    return 1; //default
}