NodeElement *CopyHandler::clone(bool toCursorPos, bool searchForParents) { EditorViewScene *evscene = dynamic_cast<EditorViewScene *>(mNode.scene()); qReal::Id typeId = mNode.id().type(); qReal::Id resultId = evscene->createElement(typeId.toString(), QPointF(), searchForParents); NodeElement *result = dynamic_cast<NodeElement *>(evscene->getElem(resultId)); copyProperties(*result, mNode); copyChildren(*result, mNode); QRectF contents = mNode.contentsRect(); if (toCursorPos) { contents.moveTo(evscene->getMousePos()); result->setGeometry(contents); result->storeGeometry(); } else { contents.moveTo(mNode.pos()); result->setGeometry(contents); } return result; }
void EditorViewMViface::handleNodeElementsForRowsInserted( const QList<QPair<NodeElement *, QPersistentModelIndex> > &nodes , const QModelIndex &parent ) { for (const QPair<NodeElement *, QPersistentModelIndex> &p : nodes) { NodeElement *elem = p.first; QPersistentModelIndex current = p.second; Id currentId = current.data(roles::idRole).value<Id>(); bool needToProcessChildren = true; if (elem) { QPointF ePos = model()->data(current, roles::positionRole).toPointF(); // setting position before parent definition 'itemChange' to work correctly elem->setPos(ePos); elem->setGeometry(mGraphicalAssistApi->configuration(elem->id()).boundingRect().translated(ePos.toPoint())); handleAddingSequenceForRowsInserted(parent, elem, current); handleElemDataForRowsInserted(elem, current); if (currentId.element() == "Class" && mGraphicalAssistApi->children(currentId).empty()) { needToProcessChildren = false; for (int i = 0; i < 2; i++) { QString curChildElementType = (i == 0) ? "MethodsContainer" : "FieldsContainer"; Id newUuid = Id("Kernel_metamodel", "Kernel", curChildElementType, QUuid::createUuid().toString()); mGraphicalAssistApi->createElement(currentId, newUuid , false, "(anonymous something)", QPointF(0, 0)); } } } if (needToProcessChildren && model()->hasChildren(current)) { rowsInserted(current, 0, model()->rowCount(current) - 1); } if (elem) { elem->alignToGrid(); } } }