static QPointF createParentAnchorPoint(const QmlItemNode &parentQmlItemNode, AnchorLine::Type anchorLineType, const QmlItemNode &childQmlItemNode) { QRectF parentBoundingRect = parentQmlItemNode.instanceSceneTransform().mapRect(parentQmlItemNode.instanceBoundingRect().adjusted(0., 0., 1., 1.)); QRectF childBoundingRect = childQmlItemNode.instanceSceneTransform().mapRect(childQmlItemNode.instanceBoundingRect().adjusted(0., 0., 1., 1.)); QPointF anchorPoint; switch (anchorLineType) { case AnchorLine::Top: anchorPoint = QPointF(childBoundingRect.center().x(), parentBoundingRect.top()); break; case AnchorLine::Bottom: anchorPoint = QPointF(childBoundingRect.center().x(), parentBoundingRect.bottom()); break; case AnchorLine::Left: anchorPoint = QPointF(parentBoundingRect.left(), childBoundingRect.center().y()); break; case AnchorLine::Right: anchorPoint = QPointF(parentBoundingRect.right(), childBoundingRect.center().y()); break; default: break; } return anchorPoint; }
static QPointF createAnchorPoint(const QmlItemNode &qmlItemNode, AnchorLine::Type anchorLineType) { QRectF boundingRect = qmlItemNode.instanceBoundingRect().adjusted(0., 0., 1., 1.); QPointF anchorPoint; switch (anchorLineType) { case AnchorLine::Top: anchorPoint = QPointF(boundingRect.center().x(), boundingRect.top()); break; case AnchorLine::Bottom: anchorPoint = QPointF(boundingRect.center().x(), boundingRect.bottom()); break; case AnchorLine::Left: anchorPoint = QPointF(boundingRect.left(), boundingRect.center().y()); break; case AnchorLine::Right: anchorPoint = QPointF(boundingRect.right(), boundingRect.center().y()); break; default: break; } return qmlItemNode.instanceSceneTransform().map(anchorPoint); }
void BindingIndicator::setItems(const QList<FormEditorItem *> &itemList) { clear(); if (itemList.count() == 1) { m_formEditorItem = itemList.first(); QmlItemNode qmlItemNode = m_formEditorItem->qmlItemNode(); if (qmlItemNode.hasBindingProperty("x")) { m_indicatorTopShape = new BindingIndicatorGraphicsItem(m_layerItem.data()); m_indicatorTopShape->updateBindingIndicator(leftLine(qmlItemNode)); } if (qmlItemNode.hasBindingProperty("y")) { m_indicatorLeftShape = new BindingIndicatorGraphicsItem(m_layerItem.data()); m_indicatorLeftShape->updateBindingIndicator(topLine(qmlItemNode)); } if (qmlItemNode.hasBindingProperty("width")) { m_indicatorRightShape = new BindingIndicatorGraphicsItem(m_layerItem.data()); m_indicatorRightShape->updateBindingIndicator(rightLine(qmlItemNode)); } if (qmlItemNode.hasBindingProperty("height")) { m_indicatorBottomShape = new BindingIndicatorGraphicsItem(m_layerItem.data()); m_indicatorBottomShape->updateBindingIndicator(bottomLine(qmlItemNode)); } } }
QRectF QmlAnchorBindingProxy::boundingBox(const QmlItemNode &node) { if (node.isValid()) return node.instanceTransformWithContentTransform().mapRect(node.instanceBoundingRect()); return QRect(); }
QmlItemNode QmlItemNode::createQmlItemNode(AbstractView *view, const ItemLibraryEntry &itemLibraryEntry, const QPointF &position, QmlItemNode parentQmlItemNode) { if (!parentQmlItemNode.isValid()) parentQmlItemNode = QmlItemNode(view->rootModelNode()); Q_ASSERT(parentQmlItemNode.isValid()); NodeAbstractProperty parentProperty = parentQmlItemNode.defaultNodeAbstractProperty(); return QmlItemNode::createQmlItemNode(view, itemLibraryEntry, position, parentProperty); }
static QList<QmlItemNode> allQmlItemsRecursive(const QmlItemNode &qmlItemNode) { QList<QmlItemNode> qmlItemNodeList; if (qmlItemNode.isValid()) { qmlItemNodeList.append(qmlItemNode); foreach (const ModelNode &modelNode, qmlItemNode.modelNode().directSubModelNodes()) { if (QmlItemNode::isValidQmlItemNode(modelNode)) qmlItemNodeList.append(allQmlItemsRecursive(modelNode)); } }
QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryEntry, const QPointF &position, QmlItemNode parentNode) { if (!parentNode.isValid()) parentNode = rootQmlItemNode(); Q_ASSERT(parentNode.isValid()); QmlItemNode newNode; RewriterTransaction transaction = beginRewriterTransaction(); { 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)))); foreach (const PropertyContainer &property, itemLibraryEntry.properties()) propertyPairList.append(qMakePair(property.name(), property.value())); newNode = createQmlItemNode(itemLibraryEntry.typeName(), itemLibraryEntry.majorVersion(), itemLibraryEntry.minorVersion(), propertyPairList); parentNode.nodeAbstractProperty("data").reparentHere(newNode); Q_ASSERT(newNode.isValid()); 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 try { newNode.setId(id); } catch (InvalidIdException &e) { // should never happen QMessageBox::warning(0, tr("Invalid Id"), e.description()); } if (!currentState().isBaseState()) { newNode.modelNode().variantProperty("opacity") = 0; newNode.setVariantProperty("opacity", 1); } Q_ASSERT(newNode.isValid()); } Q_ASSERT(newNode.isValid()); return newNode; }
QmlItemNode QmlModelView::createQmlItemNodeFromImage(const QString &imageName, const QPointF &position, QmlItemNode parentNode) { if (!parentNode.isValid()) parentNode = rootQmlItemNode(); if (!parentNode.isValid()) return QmlItemNode(); QmlItemNode newNode; RewriterTransaction transaction = beginRewriterTransaction(); { 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)))); QString relativeImageName = imageName; //use relative path if (QFileInfo(model()->fileUrl().toLocalFile()).exists()) { QDir fileDir(QFileInfo(model()->fileUrl().toLocalFile()).absolutePath()); relativeImageName = fileDir.relativeFilePath(imageName); } propertyPairList.append(qMakePair(QString("source"), QVariant(relativeImageName))); newNode = createQmlItemNode("Qt/Image",4, 7, propertyPairList); parentNode.nodeAbstractProperty("data").reparentHere(newNode); Q_ASSERT(newNode.isValid()); QString id; int i = 1; QString name("image"); name.remove(QLatin1Char(' ')); 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()); } Q_ASSERT(newNode.isValid()); return newNode; }
void FormEditorView::removeNodeFromScene(const QmlItemNode &qmlItemNode) { if (qmlItemNode.isValid()) { QList<QmlItemNode> nodeList; nodeList.append(qmlItemNode.allSubModelNodes()); nodeList.append(qmlItemNode); QList<FormEditorItem*> removedItemList; removedItemList.append(scene()->itemsForQmlItemNodes(nodeList)); m_currentTool->itemsAboutToRemoved(removedItemList); qDeleteAll(removedItemList); } }
static QList<QmlItemNode> allFxItemsRecursive(const QmlItemNode &fxNode) { QList<QmlItemNode> returnList; if (fxNode.isValid()) { returnList.append(fxNode); QList<QmlItemNode> allChildNodes; foreach (const ModelNode &node, fxNode.modelNode().allDirectSubModelNodes()) { if (QmlItemNode(node).isValid()) allChildNodes.append(node); } foreach (const QmlItemNode &node, allChildNodes) { returnList.append(allFxItemsRecursive(node)); }
static inline QPointF getUpperLeftPosition(const QList<ModelNode> &modelNodeList) { QPointF postion(std::numeric_limits<qreal>::max(), std::numeric_limits<qreal>::max()); foreach (const ModelNode &modelNode, modelNodeList) { if (QmlItemNode::isValidQmlItemNode(modelNode)) { QmlItemNode qmlIitemNode = QmlItemNode(modelNode); if (qmlIitemNode.instancePosition().x() < postion.x()) postion.setX(qmlIitemNode.instancePosition().x()); if (qmlIitemNode.instancePosition().y() < postion.y()) postion.setY(qmlIitemNode.instancePosition().y()); } } return postion; }
virtual void updateContext() { defaultAction()->setSelectionContext(selectionContext()); if (selectionContext().isValid()) { defaultAction()->setEnabled(isEnabled(selectionContext())); defaultAction()->setVisible(isVisible(selectionContext())); defaultAction()->setCheckable(true); QmlItemNode itemNode = QmlItemNode(selectionContext().currentSingleSelectedNode()); if (itemNode.isValid()) defaultAction()->setChecked(itemNode.instanceValue("visible").toBool()); else defaultAction()->setEnabled(false); } }
QString QmlAnchorBindingProxy::idForNode(const QmlItemNode &qmlItemNode) const { if (m_qmlItemNode.instanceParent().modelNode() == qmlItemNode) return QStringLiteral("parent"); return qmlItemNode.id(); }
void FormEditorView::hideNodeFromScene(const QmlItemNode &qmlItemNode) { if (qmlItemNode.isValid()) { FormEditorItem *item = m_scene->itemForQmlItemNode(qmlItemNode); QList<QmlItemNode> nodeList; nodeList.append(qmlItemNode.allSubModelNodes()); nodeList.append(qmlItemNode); QList<FormEditorItem*> removedItemList; removedItemList.append(scene()->itemsForQmlItemNodes(nodeList)); m_currentTool->itemsAboutToRemoved(removedItemList); item->setFormEditorVisible(false); } }
//This method does the setup of the initial FormEditorItem tree in the scene void FormEditorView::setupFormEditorItemTree(const QmlItemNode &qmlItemNode) { m_scene->addFormEditorItem(qmlItemNode); foreach (const QmlItemNode &nextNode, qmlItemNode.children()) //TODO instance children setupFormEditorItemTree(nextNode); }
foreach (FormEditorItem *formEditorItem, itemList) { if (formEditorItem == m_formEditorItem) { QmlItemNode sourceQmlItemNode = m_formEditorItem->qmlItemNode(); if (!sourceQmlItemNode.modelNode().isRootNode()) { QmlAnchors qmlAnchors = formEditorItem->qmlItemNode().anchors(); if (qmlAnchors.modelHasAnchor(AnchorLine::Top)) { if (m_indicatorTopShape.isNull()) m_indicatorTopShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); m_indicatorTopShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Top), qmlAnchors.modelAnchor(AnchorLine::Top)); } else { delete m_indicatorTopShape; } if (qmlAnchors.modelHasAnchor(AnchorLine::Bottom)) { if (m_indicatorBottomShape.isNull()) m_indicatorBottomShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); m_indicatorBottomShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Bottom), qmlAnchors.modelAnchor(AnchorLine::Bottom)); } else { delete m_indicatorBottomShape; } if (qmlAnchors.modelHasAnchor(AnchorLine::Left)) { if (m_indicatorLeftShape.isNull()) m_indicatorLeftShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); m_indicatorLeftShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Left), qmlAnchors.modelAnchor(AnchorLine::Left)); } else { delete m_indicatorLeftShape; } if (qmlAnchors.modelHasAnchor(AnchorLine::Right)) { if (m_indicatorRightShape.isNull()) m_indicatorRightShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); m_indicatorRightShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Right), qmlAnchors.modelAnchor(AnchorLine::Right)); } else { delete m_indicatorRightShape; } } return; } }
//This method does the setup of the initial FormEditorItem tree in the scene void FormEditorView::setupFormEditorItemTree(const QmlItemNode &qmlItemNode) { m_scene->addFormEditorItem(qmlItemNode); foreach (const QmlObjectNode &nextNode, qmlItemNode.allDirectSubNodes()) //TODO instance children if (QmlItemNode(nextNode).isValid()) setupFormEditorItemTree(nextNode.toQmlItemNode()); }
//This method does the setup of the initial FormEditorItem tree in the scene void FormEditorView::setupFormEditorItemTree(const QmlItemNode &qmlItemNode) { m_scene->addFormEditorItem(qmlItemNode); foreach (const QmlObjectNode &nextNode, qmlItemNode.allDirectSubNodes()) //TODO instance children //If the node has source for components/custom parsers we ignore it. if (QmlItemNode(nextNode).isValid() && nextNode.modelNode().nodeSourceType() == ModelNode::NodeWithoutSource) setupFormEditorItemTree(nextNode.toQmlItemNode()); }
void MoveManipulator::synchronizeParent(const QList<FormEditorItem*> &itemList, const ModelNode &parentNode) { bool snapperUpdated = false; foreach (FormEditorItem *item, itemList) { if (m_itemList.contains(item)) { QmlItemNode parentItemNode = QmlItemNode(parentNode); if (parentItemNode.isValid()) { if (snapperUpdated == false && m_snapper.containerFormEditorItem() != m_view->scene()->itemForQmlItemNode(parentItemNode)) { m_snapper.setContainerFormEditorItem(m_view->scene()->itemForQmlItemNode(parentItemNode)); m_snapper.setTransformtionSpaceFormEditorItem(m_snapper.containerFormEditorItem()); m_snapper.updateSnappingLines(m_itemList); snapperUpdated = true; } } } } }
void QmlAnchors::setAnchor(AnchorLine::Type sourceAnchorLine, const QmlItemNode &targetQmlItemNode, AnchorLine::Type targetAnchorLine) { RewriterTransaction transaction = qmlItemNode().qmlModelView()->beginRewriterTransaction(); if (qmlItemNode().isInBaseState()) { if ((qmlItemNode().nodeInstance().hasAnchor("anchors.fill") && (sourceAnchorLine & AnchorLine::Fill)) || ((qmlItemNode().nodeInstance().hasAnchor("anchors.centerIn") && (sourceAnchorLine & AnchorLine::Center)))) { removeAnchor(sourceAnchorLine); } const QString propertyName = anchorPropertyName(sourceAnchorLine); QString targetExpression = targetQmlItemNode.modelNode().validId(); if (targetQmlItemNode.modelNode() == qmlItemNode().modelNode().parentProperty().parentModelNode()) targetExpression = "parent"; targetExpression = targetExpression + QLatin1Char('.') + lineTypeToString(targetAnchorLine); qmlItemNode().modelNode().bindingProperty(propertyName).setExpression(targetExpression); } }
virtual void updateContext() { defaultAction()->setSelectionContext(selectionContext()); if (selectionContext().isValid()) { defaultAction()->setEnabled(isEnabled(selectionContext())); defaultAction()->setVisible(isVisible(selectionContext())); defaultAction()->setCheckable(true); QmlItemNode itemNode = QmlItemNode(selectionContext().currentSingleSelectedNode()); if (itemNode.isValid()) { bool flag = false; if (itemNode.modelNode().hasProperty(m_propertyName) || itemNode.propertyAffectedByCurrentState(m_propertyName)) { flag = itemNode.modelValue(m_propertyName).toBool(); } defaultAction()->setChecked(flag); } else { defaultAction()->setEnabled(false); } } }
foreach (FormEditorItem *formEditorItem, itemList) { if (formEditorItem == m_formEditorItem) { QmlItemNode qmlItemNode = m_formEditorItem->qmlItemNode(); if (qmlItemNode.hasBindingProperty("x")) { if (m_indicatorTopShape.isNull()) m_indicatorTopShape = new BindingIndicatorGraphicsItem(m_layerItem.data()); m_indicatorTopShape->updateBindingIndicator(leftLine(qmlItemNode)); } else { delete m_indicatorTopShape; } if (qmlItemNode.hasBindingProperty("y")) { if (m_indicatorLeftShape.isNull()) m_indicatorLeftShape = new BindingIndicatorGraphicsItem(m_layerItem.data()); m_indicatorLeftShape->updateBindingIndicator(topLine(qmlItemNode)); } else { delete m_indicatorLeftShape; } if (qmlItemNode.hasBindingProperty("width")) { if (m_indicatorRightShape.isNull()) m_indicatorRightShape = new BindingIndicatorGraphicsItem(m_layerItem.data()); m_indicatorRightShape->updateBindingIndicator(rightLine(qmlItemNode)); } else { delete m_indicatorRightShape; } if (qmlItemNode.hasBindingProperty("height")) { if (m_indicatorBottomShape.isNull()) m_indicatorBottomShape = new BindingIndicatorGraphicsItem(m_layerItem.data()); m_indicatorBottomShape->updateBindingIndicator(bottomLine(qmlItemNode)); } else { delete m_indicatorBottomShape; } return; } }
bool QmlAnchors::canAnchor(const QmlItemNode &targetModelNode) const { if (!qmlItemNode().isInBaseState()) return false; if (targetModelNode == qmlItemNode().instanceParent()) return true; if (qmlItemNode().instanceParent() == targetModelNode.instanceParent()) return true; return false; }
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()); }
bool itemIsResizable(const QmlItemNode &qmlItemNode) { return qmlItemNode.isValid() && qmlItemNode.instanceIsResizable() && qmlItemNode.modelIsMovable() && qmlItemNode.modelIsResizable() && !qmlItemNode.instanceHasRotationTransform() && !qmlItemNode.instanceIsInLayoutable(); }
void AnchorIndicator::setItems(const QList<FormEditorItem *> &itemList) { clear(); if (itemList.count() == 1) { m_formEditorItem = itemList.first(); QmlItemNode sourceQmlItemNode = m_formEditorItem->qmlItemNode(); if (!sourceQmlItemNode.modelNode().isRootNode()) { QmlAnchors qmlAnchors = sourceQmlItemNode.anchors(); if (qmlAnchors.modelHasAnchor(AnchorLine::Top)) { m_indicatorTopShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); m_indicatorTopShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Top), qmlAnchors.modelAnchor(AnchorLine::Top)); } if (qmlAnchors.modelHasAnchor(AnchorLine::Bottom)) { m_indicatorBottomShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); m_indicatorBottomShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Bottom), qmlAnchors.modelAnchor(AnchorLine::Bottom)); } if (qmlAnchors.modelHasAnchor(AnchorLine::Left)) { m_indicatorLeftShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); m_indicatorLeftShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Left), qmlAnchors.modelAnchor(AnchorLine::Left)); } if (qmlAnchors.modelHasAnchor(AnchorLine::Right)) { m_indicatorRightShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); m_indicatorRightShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Right), qmlAnchors.modelAnchor(AnchorLine::Right)); } } } }
void DragTool::createQmlItemNodeFromImage(const QString &imageName, QmlItemNode parentNode, QPointF scenePos) { if (!parentNode.isValid()) return; MetaInfo metaInfo = MetaInfo::global(); FormEditorItem *parentItem = scene()->itemForQmlItemNode(parentNode); QPointF pos = parentItem->mapFromScene(scenePos); m_dragNode = view()->createQmlItemNodeFromImage(imageName, pos, parentNode); QList<QmlItemNode> nodeList; nodeList.append(m_dragNode); m_selectionIndicator.setItems(scene()->itemsForQmlItemNodes(nodeList)); }
void DragTool::createQmlItemNodeFromImage(const QString &imageName, const QmlItemNode &parentNode, const QPointF &scenePosition) { if (parentNode.isValid()) { MetaInfo metaInfo = MetaInfo::global(); FormEditorItem *parentItem = scene()->itemForQmlItemNode(parentNode); QPointF positonInItemSpace = parentItem->qmlItemNode().instanceSceneContentItemTransform().inverted().map(scenePosition); m_dragNode = QmlItemNode::createQmlItemNodeFromImage(view(), imageName, positonInItemSpace, parentNode); QList<QmlItemNode> nodeList; nodeList.append(m_dragNode); m_selectionIndicator.setItems(scene()->itemsForQmlItemNodes(nodeList)); } }
QLineF bottomLine(const QmlItemNode &qmlItemNode) { QRectF rectangle = qmlItemNode.instanceSceneTransform().mapRect(qmlItemNode.instanceBoundingRect()).adjusted(1, 0, 0, 0); return QLineF(rectangle.bottomLeft(), rectangle.bottomRight()); }
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()); }