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 {
void MetaInfoPrivate::parseClassInfo(NodeMetaInfo &nodeMetaInfo, const QMetaObject *qMetaObject) const { Q_ASSERT_X(qMetaObject, Q_FUNC_INFO, "invalid QMetaObject"); Q_ASSERT_X(nodeMetaInfo.isValid(), Q_FUNC_INFO, "invalid NodeMetaInfo"); for (int index = qMetaObject->classInfoCount() - 1 ; index >= 0 ; --index) { QMetaClassInfo classInfo = qMetaObject->classInfo(index); if (QLatin1String(classInfo.name()) == QLatin1String("DefaultProperty")) { nodeMetaInfo.setDefaultProperty(classInfo.value()); return; } } }
void MetaInfoPrivate::parseProperties(NodeMetaInfo &nodeMetaInfo, const QMetaObject *qMetaObject) const { Q_ASSERT_X(qMetaObject, Q_FUNC_INFO, "invalid QMetaObject"); Q_ASSERT_X(nodeMetaInfo.isValid(), Q_FUNC_INFO, "invalid NodeMetaInfo"); for (int i = qMetaObject->propertyOffset(); i < qMetaObject->propertyCount(); ++i) { QMetaProperty qProperty = qMetaObject->property(i); PropertyMetaInfo propertyInfo; propertyInfo.setName(QLatin1String(qProperty.name())); QString typeName(qProperty.typeName()); QString noStar = typeName; bool star = false; while (noStar.contains('*')) {//strip star noStar.chop(1); star = true; } if (m_QtTypesToQmlTypes.contains(noStar)) { typeName = star ? m_QtTypesToQmlTypes.value(noStar) + '*' : m_QtTypesToQmlTypes.value(noStar); //### versions } propertyInfo.setType(typeName); propertyInfo.setValid(true); propertyInfo.setReadable(qProperty.isReadable()); propertyInfo.setWritable(qProperty.isWritable()); propertyInfo.setResettable(qProperty.isResettable()); propertyInfo.setEnumType(qProperty.isEnumType()); propertyInfo.setFlagType(qProperty.isFlagType()); if (propertyInfo.isEnumType()) { EnumeratorMetaInfo enumerator; QMetaEnum qEnumerator = qProperty.enumerator(); enumerator.setValid(qEnumerator.isValid()); enumerator.setIsFlagType(qEnumerator.isFlag()); enumerator.setScope(qEnumerator.scope()); enumerator.setName(qEnumerator.name()); for (int i = 0 ;i < qEnumerator.keyCount(); i++) { enumerator.addElement(qEnumerator.valueToKey(i), i); } propertyInfo.setEnumerator(enumerator); } nodeMetaInfo.addProperty(propertyInfo); } }
/*! \brief Returns meta information for a property. An invalid PropertyMetaInfo object if the given property name is unknown. \throws InvalidMetaInfoException if the object is not valid */ PropertyMetaInfo NodeMetaInfo::property(const QString &propertyName, bool resolveDotSyntax) const { if (!isValid()) { qWarning() << "NodeMetaInfo is invalid"; return PropertyMetaInfo(); } if (resolveDotSyntax && propertyName.contains('.')) { const QStringList nameParts = propertyName.split('.'); NodeMetaInfo nodeInfo = *this; const int partCount = nameParts.size(); for (int i = 0; i < partCount; ++i) { const QString namePart(nameParts.at(i)); const PropertyMetaInfo propInfo = nodeInfo.property(namePart, false); if (!propInfo.isValid()) break; if (i + 1 == partCount) return propInfo; QString propertyType = propInfo.type(); if (propertyType.right(1) == "*") propertyType = propertyType.left(propertyType.size() - 1).trimmed(); nodeInfo = m_data->metaInfo.nodeMetaInfo(m_data->metaInfo.fromQtTypes(propertyType), majorVersion(), minorVersion()); if (!nodeInfo.isValid()) { qWarning() << "no type info available for" << propertyType; break; } } return PropertyMetaInfo(); } else { PropertyMetaInfo propertyMetaInfo; if (hasLocalProperty(propertyName)) { propertyMetaInfo = m_data->propertyMetaInfoHash.value(propertyName, PropertyMetaInfo()); } else { foreach (const NodeMetaInfo &superTypeMetaInfo, superClasses()) { Q_ASSERT(superTypeMetaInfo.isValid()); propertyMetaInfo = superTypeMetaInfo.property(propertyName); if (propertyMetaInfo.isValid()) break; } } return propertyMetaInfo; }
/*! \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 }
void TextEditItem::setFormEditorItem(FormEditorItem *formEditorItem) { m_formEditorItem = formEditorItem; QRectF rect = formEditorItem->qmlItemNode().instancePaintedBoundingRect().united(formEditorItem->qmlItemNode().instanceBoundingRect()).adjusted(-12, -4, 12 ,4); setGeometry(rect); NodeMetaInfo metaInfo = m_formEditorItem->qmlItemNode().modelNode().metaInfo(); if (metaInfo.isValid() && (metaInfo.isSubclassOf("QtQuick.TextEdit") || metaInfo.isSubclassOf("QtQuick.Controls.TextArea"))) { QSize maximumSize = rect.size().toSize(); activateTextEdit(maximumSize); } else { activateLineEdit(); } setTransform(formEditorItem->sceneTransform()); updateText(); }
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); }
QStringList DynamicPropertiesModel::possibleTargetProperties(const BindingProperty &bindingProperty) const { const ModelNode modelNode = bindingProperty.parentModelNode(); if (!modelNode.isValid()) { qWarning() << " BindingModel::possibleTargetPropertiesForRow invalid model node"; return QStringList(); } NodeMetaInfo metaInfo = modelNode.metaInfo(); if (metaInfo.isValid()) { QStringList possibleProperties; foreach (const PropertyName &propertyName, metaInfo.propertyNames()) { if (metaInfo.propertyIsWritable(propertyName)) possibleProperties << QString::fromLatin1(propertyName); } return possibleProperties; }
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(); } }