本文整理汇总了C++中QmlItemNode::defaultProperty方法的典型用法代码示例。如果您正苦于以下问题:C++ QmlItemNode::defaultProperty方法的具体用法?C++ QmlItemNode::defaultProperty怎么用?C++ QmlItemNode::defaultProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QmlItemNode
的用法示例。
在下文中一共展示了QmlItemNode::defaultProperty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createQmlItemNode
QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryEntry, const QPointF &position, QmlItemNode parentNode)
{
if (!parentNode.isValid())
parentNode = rootQmlItemNode();
Q_ASSERT(parentNode.isValid());
QmlItemNode newNode;
try {
RewriterTransaction transaction = beginRewriterTransaction();
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);
foreach (const Import &import, model()->imports()) {
if (import.isLibraryImport()
&& import.url() == newImport.url()
&& import.version() == newImport.version()) {
// reuse this import
newImport = import;
break;
}
}
if (!model()->hasImport(newImport, true, true)) {
model()->changeImports(QList<Import>() << newImport, QList<Import>());
}
}
}
QList<QPair<QString, QVariant> > propertyPairList;
propertyPairList.append(qMakePair(QString("x"), QVariant(round(position.x(), 4))));
propertyPairList.append(qMakePair(QString("y"), QVariant(round(position.y(), 4))));
if (itemLibraryEntry.qml().isEmpty()) {
foreach (const PropertyContainer &property, itemLibraryEntry.properties())
propertyPairList.append(qMakePair(property.name(), property.value()));
newNode = createQmlItemNode(itemLibraryEntry.typeName(), itemLibraryEntry.majorVersion(), itemLibraryEntry.minorVersion(), propertyPairList);
} else {
QScopedPointer<Model> inputModel(Model::create("QtQuick.Rectangle", 1, 0, model()));
inputModel->setFileUrl(model()->fileUrl());
QPlainTextEdit textEdit;
textEdit.setPlainText(Utils::FileReader::fetchQrc(itemLibraryEntry.qml()));
NotIndentingTextEditModifier modifier(&textEdit);
QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, 0));
rewriterView->setCheckSemanticErrors(false);
rewriterView->setTextModifier(&modifier);
inputModel->attachView(rewriterView.data());
if (rewriterView->errors().isEmpty() && rewriterView->rootModelNode().isValid()) {
ModelNode rootModelNode = rewriterView->rootModelNode();
inputModel->detachView(rewriterView.data());
rootModelNode.variantProperty("x") = propertyPairList.first().second;
rootModelNode.variantProperty("y") = propertyPairList.at(1).second;
ModelMerger merger(this);
newNode = merger.insertModel(rootModelNode);
}
}
if (parentNode.hasDefaultProperty()) {
parentNode.nodeAbstractProperty(parentNode.defaultProperty()).reparentHere(newNode);
}
if (!newNode.isValid())
return newNode;
QString id;
int i = 1;
QString name(itemLibraryEntry.name().toLower());
//remove forbidden characters
name.replace(QRegExp(QLatin1String("[^a-zA-Z0-9_]")), QLatin1String("_"));
do {
id = name + QString::number(i);
i++;
} while (hasId(id)); //If the name already exists count upwards
newNode.setId(id);
if (!currentState().isBaseState()) {
newNode.modelNode().variantProperty("opacity") = 0;
newNode.setVariantProperty("opacity", 1);
}
Q_ASSERT(newNode.isValid());
}