void NodeElement::arrangeLinks() { //Episode I: Home Jumps for (EdgeElement* edge : mEdgeList) { NodeElement* src = edge->src(); NodeElement* dst = edge->dst(); edge->reconnectToNearestPorts(this == src, this == dst); } //Episode II: Home Ports Arranging arrangeLinearPorts(); //Episode III: Remote Jumps for (EdgeElement* edge : mEdgeList) { NodeElement* src = edge->src(); NodeElement* dst = edge->dst(); NodeElement* other = edge->otherSide(this); edge->reconnectToNearestPorts(other == src, other == dst); } //Episode IV: Remote Arrangigng QSet<NodeElement*> arranged; for (EdgeElement* edge : mEdgeList) { NodeElement* other = edge->otherSide(this); if (other && !arranged.contains(other)) { other->arrangeLinearPorts(); arranged.insert(other); } } }
void NodeElement::changeFoldState() { mIsFolded = !mIsFolded; for (QGraphicsItem* childItem : childItems()) { NodeElement* curItem = dynamic_cast<NodeElement*>(childItem); if (curItem) { curItem->setVisible(!mIsFolded); curItem->setLinksVisible(!mIsFolded); } } if (mIsFolded) { mCurUnfoldedContents = mContents; mFoldedContents.moveTo(pos()); setGeometry(mFoldedContents); } else { mCurUnfoldedContents.moveTo(pos()); setGeometry(mCurUnfoldedContents); } mGraphicalAssistApi.mutableGraphicalRepoApi().setProperty(mId, "folded", mIsFolded ? "true" : "false"); NodeElement* parent = dynamic_cast<NodeElement*>(parentItem()); if (parent) { parent->resize(); } updateLabels(); }
void EmbeddedLinker::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { hide(); master->selectionState(false); EditorViewScene* scene = dynamic_cast<EditorViewScene*>(master->scene()); if (!mPressed && scene && mEdge) { mEdge->hide(); QPointF const &eScenePos = event->scenePos(); NodeElement *under = dynamic_cast<NodeElement*>(scene->itemAt(eScenePos)); mEdge->show(); int result = 0; if (!under) { result = scene->launchEdgeMenu(mEdge, master, eScenePos); NodeElement *target = dynamic_cast<NodeElement*>(scene->getLastCreated()); if (result == -1) { mEdge = NULL; } else if ((result == +1) && target) { QPointF const &posRelativeToTheTarget = target->mapFromScene(eScenePos); mEdge->placeEndTo(mapFromItem(target, target->getNearestPort(posRelativeToTheTarget))); mEdge->connectToPort(); //it provokes to move target somehow, so it needs to place edge end and connect to port again mEdge->placeEndTo(mapFromItem(target, target->getNearestPort(posRelativeToTheTarget))); mEdge->adjustLink(); } } if (result != -1) { mEdge->connectToPort(); } } }
void NodeElement::drawPlaceholder(QGraphicsRectItem *placeholder, QPointF pos) { // for non-sorting containers no need for drawing placeholder so just make them marked if (!mElementImpl->isSortingContainer()) { setOpacity(0.2); return; } // binary search? No because we need to know summary height of prev elements NodeElement *nextItem = nullptr; for (QGraphicsItem* childItem : childItems()) { NodeElement *curItem = dynamic_cast<NodeElement*>(childItem); if (curItem) { if (curItem->scenePos().y() > pos.y()) { nextItem = curItem; break; } } } erasePlaceholder(false); mPlaceholder = placeholder; mPlaceholder->setParentItem(this); if(nextItem) { mPlaceholder->stackBefore(nextItem); } resize(); }
bool BaseMultiMappingElement::initNode() { using namespace core::objectmodel; using namespace core; bool result = ObjectElement::initNode(); if( result ) { BaseMapping* multimapping = this->getTypedObject()->toBaseMapping(); NodeElement* currentNodeElement = dynamic_cast<NodeElement *>(getParent()); simulation::Node* currentNode = dynamic_cast<simulation::Node* >( currentNodeElement->getTypedObject() ); helper::vector<core::BaseState*> inputStates = multimapping->getFrom(); helper::vector<core::BaseState*> outputStates = multimapping->getTo(); helper::vector<core::BaseState*>::iterator iterState; helper::vector<simulation::Node*> inputNodes, outputNodes; /* get the Nodes corresponding to each input BaseState context */ for( iterState = inputStates.begin(); iterState != inputStates.end(); ++iterState) { simulation::Node* node = dynamic_cast< simulation::Node* >((*iterState)->getContext()); inputNodes.push_back(node); } /* */ /* get the Nodes corresponding to each output BaseState context */ for( iterState = outputStates.begin(); iterState != outputStates.end(); ++iterState) { simulation::Node* node = dynamic_cast< simulation::Node* >((*iterState)->getContext()); outputNodes.push_back(node); } helper::vector<simulation::Node*>::iterator iterNode; BaseNode* currentBaseNode; /* filter out inputNodes which already belong to the currentNode ancestors */ helper::vector<simulation::Node*> otherInputNodes; helper::vector<simulation::Node*> ancestorInputNodes; iterNode = inputNodes.begin(); currentBaseNode = currentNode; for( iterNode = inputNodes.begin(); iterNode != inputNodes.end(); ++iterNode) { if( !currentBaseNode->hasAncestor(*iterNode) ) { otherInputNodes.push_back(*iterNode); } else { ancestorInputNodes.push_back(*iterNode); } } updateSceneGraph(multimapping, ancestorInputNodes, otherInputNodes, outputNodes ); } return result; }
void ResizeCommand::resizeTree(QMap<Id, QRectF> const &snapshot, const Id &root) { NodeElement *element = nodeById(root); for (NodeElement *child : element->childNodes()) { if (snapshot.contains(child->id())) { resizeTree(snapshot, child->id()); } } resize(element, snapshot[root]); }
void NodeElement::adjustLinks() { for (EdgeElement *edge : mEdgeList) { edge->adjustLink(); } for (QGraphicsItem *child : childItems()) { NodeElement *element = dynamic_cast<NodeElement*>(child); if (element) { element->adjustLinks(); } } }
void ResizeCommand::makeHierarchySnapshot(NodeElement *node, QMap<Id, QRectF> &target) { // Here we remembering all binded items geometries. // Binded items are just element`s hierarchy: // all parents and children (siblings are not considered) makeChildrenSnapshot(node, target); for (NodeElement *parentElement = node; parentElement; parentElement = dynamic_cast<NodeElement *>(parentElement->parentItem())) { target.insert(parentElement->id(), geometryOf(parentElement)); addEdges(parentElement); } }
void NodeElement::setLinksVisible(bool isVisible) { for (EdgeElement *curEdge : mEdgeList) { curEdge->setVisible(isVisible); } for (QGraphicsItem* childItem : childItems()) { NodeElement* curItem = dynamic_cast<NodeElement*>(childItem); if (curItem) { curItem->setLinksVisible(isVisible); } } }
void SceneGridHandler::drawGuides() { const int drift = 5; // A dirft for scene not to resize from guide lines. const QPointF nodeScenePos = mNode->scenePos(); const QRectF contentsRect = mNode->contentsRect(); const QRectF sceneRect = mNode->scene()->sceneRect().adjusted(drift, drift, -drift, -drift); deleteGuides(); QList<QGraphicsItem *> list = getAdjancedNodes(); qreal myX1 = nodeScenePos.x() + contentsRect.x(); qreal myY1 = nodeScenePos.y() + contentsRect.y(); qreal myX2 = myX1 + contentsRect.width(); qreal myY2 = myY1 + contentsRect.height(); for (QGraphicsItem *graphicsItem : list) { NodeElement *item = dynamic_cast<NodeElement *>(graphicsItem); if (item == nullptr || item->parentItem() != nullptr || item == mNode) { continue; } const QPointF point = item->scenePos(); const QRectF contents = item->contentsRect(); const qreal pointX1 = point.x() + contents.x() - spacing; const qreal pointY1 = point.y() + contents.y() - spacing; const qreal pointX2 = pointX1 + contents.width() + 2 * spacing; const qreal pointY2 = pointY1 + contents.height() + 2 * spacing; if (pointX1 != myX1 || pointY1 != myY1) { const qreal deltaY1 = qAbs(pointY1 - myY1); const qreal deltaY2 = qAbs(pointY2 - myY2); const qreal deltaX1 = qAbs(pointX1 - myX1); const qreal deltaX2 = qAbs(pointX2 - myX2); buildLineY(deltaY1, pointY1, 0, myY1, myY2, sceneRect); buildLineY(deltaY2, pointY2, contentsRect.height(), myY1, myY2, sceneRect); buildLineX(deltaX1, pointX1, 0, myX1, myX2, sceneRect); buildLineX(deltaX2, pointX2, contentsRect.width(), myX1, myX2, sceneRect); buildLineY(qAbs(pointY1 - myY2), pointY1, contentsRect.height(), myY1, myY2, sceneRect); buildLineX(qAbs(pointX1 - myX2), pointX1, contentsRect.width(), myX1, myX2, sceneRect); buildLineY(qAbs(pointY2 - myY1), pointY2, 0, myY1, myY2, sceneRect); buildLineX(qAbs(pointX2 - myX1), pointX2, 0, myX1, myX2, sceneRect); } } }
void PasteNodeCommand::restoreElement() { Id const logicalId = mMVIface->graphicalAssistApi()->logicalId(mResult); mMVIface->graphicalAssistApi()->setProperties(logicalId, mNodeData.logicalProperties); mMVIface->graphicalAssistApi()->setProperties(mResult, mNodeData.graphicalProperties); mMVIface->graphicalAssistApi()->setPosition(mResult, getNewGraphicalPos()); if (mCopiedIds->contains(mNodeData.parentId)) { mMVIface->graphicalAssistApi()->changeParent(mResult, mCopiedIds->value(mNodeData.parentId), getNewPos()); } NodeElement *element = mScene->getNodeById(mResult); if (element) { element->updateData(); } }
void SceneGridHandler::drawGuides() { QPointF const nodeScenePos = mNode->scenePos(); QRectF const contentsRect = mNode->contentsRect(); QRectF const sceneRect = mNode->scene()->sceneRect(); delUnusedLines(); QList<QGraphicsItem *> list = getAdjancedNodes(); qreal myX1 = nodeScenePos.x() + contentsRect.x(); qreal myY1 = nodeScenePos.y() + contentsRect.y(); qreal myX2 = myX1 + contentsRect.width(); qreal myY2 = myY1 + contentsRect.height(); foreach (QGraphicsItem *graphicsItem, list) { NodeElement *item = dynamic_cast<NodeElement *>(graphicsItem); if (item == NULL || item->parentItem() != NULL || item == mNode) { continue; } QPointF const point = item->scenePos(); QRectF const contents = item->contentsRect(); qreal const pointX1 = point.x() + contents.x() - spacing; qreal const pointY1 = point.y() + contents.y() - spacing; qreal const pointX2 = pointX1 + contents.width() + 2 * spacing; qreal const pointY2 = pointY1 + contents.height() + 2 * spacing; if (pointX1 != myX1 || pointY1 != myY1) { qreal const deltaY1 = qAbs(pointY1 - myY1); qreal const deltaY2 = qAbs(pointY2 - myY2); qreal const deltaX1 = qAbs(pointX1 - myX1); qreal const deltaX2 = qAbs(pointX2 - myX2); buildLineY(deltaY1, pointY1, 0, myY1, myY2, sceneRect); buildLineY(deltaY2, pointY2, contentsRect.height(), myY1, myY2, sceneRect); buildLineX(deltaX1, pointX1, 0, myX1, myX2, sceneRect); buildLineX(deltaX2, pointX2, contentsRect.width(), myX1, myX2, sceneRect); buildLineY(qAbs(pointY1 - myY2), pointY1, contentsRect.height(), myY1, myY2, sceneRect); buildLineX(qAbs(pointX1 - myX2), pointX1, contentsRect.width(), myX1, myX2, sceneRect); buildLineY(qAbs(pointY2 - myY1), pointY2, 0, myY1, myY2, sceneRect); buildLineX(qAbs(pointX2 - myX1), pointX2, 0, myX1, myX2, sceneRect); } }
QList<NodeElement *> ClipboardHandler::getNodesForCopying() { QList<NodeElement *> nodes; for (QGraphicsItem * const item : mScene.selectedItems()) { NodeElement *node = dynamic_cast<NodeElement *>(item); if (node && !mScene.selectedItems().contains(node->parentItem())) { nodes << node; } } for (NodeElement * const node : nodes) { addChildren(node, nodes); } return nodes; }
void EmbeddedLinker::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { updateMasterEdges(); hide(); mMaster->selectionState(false); EditorViewScene* scene = dynamic_cast<EditorViewScene*>(mMaster->scene()); if (!mPressed && scene && mEdge) { mEdge->hide(); QPointF const &eScenePos = event->scenePos(); NodeElement *under = dynamic_cast<NodeElement*>(scene->itemAt(eScenePos, QTransform())); mEdge->show(); int result = 0; commands::CreateElementCommand *createElementFromMenuCommand = NULL; if (!under) { result = scene->launchEdgeMenu(mEdge, mMaster, eScenePos, &createElementFromMenuCommand); NodeElement *target = dynamic_cast<NodeElement*>(scene->getLastCreated()); if (result == -1) { mEdge = NULL; } else if ((result == 1) && target) { mEdge->setDst(target); target->storeGeometry(); } } if (result != -1) { mEdge->connectToPort(); mEdge->adjustNeighborLinks(); mEdge->correctArrow(); mEdge->correctInception(); mEdge->adjustNeighborLinks(); // This will restore edge state after undo/redo commands::ReshapeEdgeCommand *reshapeEdge = new commands::ReshapeEdgeCommand(mEdge); reshapeEdge->startTracking(); reshapeEdge->stopTracking(); reshapeEdge->setUndoEnabled(false); if (createElementFromMenuCommand) { createElementFromMenuCommand->addPostAction(reshapeEdge); mCreateEdgeCommand->addPostAction(createElementFromMenuCommand); } else { mCreateEdgeCommand->addPostAction(reshapeEdge); } } } mPressed = false; mEdge = NULL; }
void LineHandler::adjust() { QPolygonF line = mEdge->line(); NodeElement *src = mEdge->src(); NodeElement *dst = mEdge->dst(); if (src && src->isSelected() && dst && dst->isSelected() && !mEdge->isLoop()) { QPointF offset = mEdge->mapFromItem(src, src->portPos(mEdge->fromPort())) - line.first(); mEdge->setPos(mEdge->pos() + offset); return; } if (src) { line.first() = mEdge->mapFromItem(src, src->portPos(mEdge->fromPort())); } if (dst) { line.last() = mEdge->mapFromItem(dst, dst->portPos(mEdge->toPort())); } mEdge->setLine(line); if (mEdge->isLoop()) { mEdge->createLoopEdge(); } }
void ResizeCommand::resizeHierarchy(QMap<Id, QRectF> const &snapshot) { for (const Id &id : snapshot.keys()) { NodeElement *element = nodeById(id); if (!element->parentItem()) { resizeTree(snapshot, id); } } // Updating linker position if (mScene->selectedItems().size() == 1) { QGraphicsItem *selectedItem = mScene->selectedItems()[0]; NodeElement *selectedNode = dynamic_cast<NodeElement *>(selectedItem); if (selectedNode) { selectedNode->setVisibleEmbeddedLinkers(true); } } }
bool InsertIntoEdgeCommand::execute() { if (mCreateCommand) { mCreateCommand->redo(); mFirstId = mCreateCommand->result(); mLastId = mCreateCommand->result(); } EdgeElement *edge = mRemoveOldEdge ? mScene.getEdgeById(mOldEdge) : mScene.edgeForInsertion(mPos); if (!edge) { return true; } NodeElement *oldSrc = edge->src(); NodeElement *oldDst = edge->dst(); if (oldSrc && oldDst && oldSrc->id() != mFirstId && oldDst->id() != mLastId) { mParentId = (mParentId == Id::rootId()) ? mScene.rootItemId() : mParentId; Id type = edge->id().type(); initCommand(mCreateFirst, type); initCommand(mCreateSecond, type); makeLink(mCreateFirst, oldSrc, mScene.getNodeById(mFirstId)); makeLink(mCreateSecond, mScene.getNodeById(mLastId), oldDst); mConfiguration = mGraphicalAssistApi.configuration(edge->id()); if (!mRemoveOldEdge) { mRemoveOldEdge = new RemoveElementCommand(mLogicalAssistApi, mGraphicalAssistApi, mExploser , mScene.rootItemId(), mParentId, edge->id(), mIsLogical , mGraphicalAssistApi.name(edge->id()), mGraphicalAssistApi.position(edge->id())); } mRemoveOldEdge->redo(); mElementShifting.clear(); mScene.resolveOverlaps(mScene.getNodeById(mLastId), mPos, mShift, mElementShifting); mScene.resolveOverlaps(mScene.getNodeById(mFirstId), mPos, mShift, mElementShifting); } return true; }
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(); } } }
void CopyHandler::copyChildren(NodeElement const &destination, NodeElement const &source) const { foreach (QGraphicsItem * const child, source.childItems()) { NodeElement * const element = dynamic_cast<NodeElement *>(child); if (!element) { continue; } CopyHandler copyHandler(*element, mGraphicalAssistApi); NodeElement const * const copyOfChild = copyHandler.clone(); mGraphicalAssistApi.changeParent(copyOfChild->id(), destination.id(), element->pos()); } }
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 EmbeddedLinker::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { hide(); mMaster->selectionState(false); EditorViewScene* scene = dynamic_cast<EditorViewScene*>(mMaster->scene()); if (!mPressed && scene && mEdge) { mEdge->hide(); QPointF const &eScenePos = event->scenePos(); NodeElement *under = dynamic_cast<NodeElement*>(scene->itemAt(eScenePos, QTransform())); mEdge->show(); int result = 0; commands::CreateElementCommand *createElementFromMenuCommand = NULL; if (!under) { result = scene->launchEdgeMenu(mEdge, mMaster, eScenePos, false, &createElementFromMenuCommand); } else { bool canBeConnected = false; foreach(PossibleEdge const &pEdge, mEdge->src()->getPossibleEdges()) { if (pEdge.first.second.element() == under->id().element()) { canBeConnected = true; } else { // pEdge.second.first is true, if edge can connect items in only one direction. if (!pEdge.second.first) { canBeConnected = (pEdge.first.first.element() == under->id().element()); } } } if (under->isContainer()) { result = scene->launchEdgeMenu(mEdge, mMaster, eScenePos, canBeConnected, &createElementFromMenuCommand); } else { if (!canBeConnected) { result = -1; } } } NodeElement *target = dynamic_cast<NodeElement*>(scene->getLastCreated()); if (result == -1) { mEdge = NULL; } else if ((result == 1) && target) { mEdge->setDst(target); target->storeGeometry(); } if (result != -1) { mEdge->connectToPort(); updateMasterEdge(); // This will restore edge state after undo/redo commands::ReshapeEdgeCommand *reshapeEdge = new commands::ReshapeEdgeCommand(mEdge); reshapeEdge->startTracking(); reshapeEdge->stopTracking(); reshapeEdge->setUndoEnabled(false); if (createElementFromMenuCommand) { createElementFromMenuCommand->addPostAction(reshapeEdge); mCreateEdgeCommand->addPostAction(createElementFromMenuCommand); } else { mCreateEdgeCommand->addPostAction(reshapeEdge); } } }
void NodeElement::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (dynamic_cast<NodeElement *>(scene()->mouseGrabberItem()) == this) { ungrabMouse(); } if (event->button() == Qt::RightButton) { event->accept(); return; } deleteGuides(); storeGeometry(); if (scene() && (scene()->selectedItems().size() == 1) && isSelected()) { setVisibleEmbeddedLinkers(true); } if (mDragState == None) { Element::mouseReleaseEvent(event); } EditorViewScene *evScene = dynamic_cast<EditorViewScene *>(scene()); commands::InsertIntoEdgeCommand *insertCommand = new commands::InsertIntoEdgeCommand( *evScene, mModels, id(), id(), Id::rootId(), event->scenePos(), boundingRect().bottomRight(), false); bool shouldProcessResize = true; // we should use mHighlightedNode to determine if there is a highlighted node // insert current element into them and set mHighlightedNode to nullptr // but because of mouseRelease twice triggering we can't do it // This may cause more bugs if (flags() & ItemIsMovable) { if (mHighlightedNode) { NodeElement *newParent = mHighlightedNode; Element *insertBefore = mHighlightedNode->getPlaceholderNextElement(); mHighlightedNode->erasePlaceholder(false); // commented because of bug with double event sending (see #204) // mHighlightedNode = nullptr; QPointF newPos = mapToItem(newParent, mapFromScene(scenePos())); AbstractCommand *parentCommand = changeParentCommand(newParent->id(), newPos); mController->execute(parentCommand); // Position change already processed in change parent command shouldProcessResize = parentCommand == nullptr; setPos(newPos); if (insertBefore) { mGraphicalAssistApi.stackBefore(id(), insertBefore->id()); } newParent->resize(); while (newParent) { newParent->mContents = newParent->mContents.normalized(); newParent->storeGeometry(); newParent = dynamic_cast<NodeElement*>(newParent->parentItem()); } } else { AbstractCommand *parentCommand = changeParentCommand(evScene->rootItemId(), scenePos()); mController->execute(parentCommand); // Position change already processed in change parent command shouldProcessResize = parentCommand == nullptr; } } for (EdgeElement* edge : mEdgeList) { edge->layOut(); if (SettingsManager::value("ActivateGrid").toBool()) { edge->alignToGrid(); } } if (shouldProcessResize && mResizeCommand) { mResizeCommand->addPostAction(insertCommand); endResize(); } updateBySelection(); mDragState = None; }
void EditorViewMViface::rowsInserted(QModelIndex const &parent, int start, int end) { for (int row = start; row <= end; ++row) { mScene->setEnabled(true); QPersistentModelIndex current = model()->index(row, 0, parent); if (!isDescendentOf(current, rootIndex())) continue; Id currentId = current.data(roles::idRole).value<Id>(); if (currentId == Id::rootId()) continue; Id parentUuid; if (parent != rootIndex()) parentUuid = parent.data(roles::idRole).value<Id>(); if (!parent.isValid()) { setRootIndex(current); continue; } Element* elem = mScene->mainWindow()->manager()->graphicalObject(currentId); if (elem) { elem->setAssistApi(mGraphicalAssistApi, mLogicalAssistApi); } QPointF ePos = model()->data(current, roles::positionRole).toPointF(); bool needToProcessChildren = true; if (elem) { elem->setPos(ePos); //задаем позицию до определения родителя для того, чтобы правильно отработал itemChange elem->setId(currentId); /*commented out because of real sizes of elements are incorrectly changing here into initial sizes*/ // NodeElement* nodeElement = dynamic_cast<NodeElement*>(elem); // if (nodeElement) // nodeElement->storeGeometry(); if (item(parent) != NULL) { elem->setParentItem(item(parent)); QModelIndex next = current.sibling(current.row() + 1, 0); if(next.isValid() && item(next) != NULL) { elem->stackBefore(item(next)); } } else { mScene->addItem(elem); } setItem(current, elem); elem->updateData(); elem->connectToPort(); elem->checkConnectionsToPort(); elem->initPossibleEdges(); elem->initTitles(); // elem->initEmbeddedControls(); //todo: нужно привести в порядок всякие init~() bool isEdgeFromEmbeddedLinker = false; QList<QGraphicsItem*> selectedItems = mScene->selectedItems(); if (selectedItems.size() == 1) { NodeElement* master = dynamic_cast<NodeElement*>(selectedItems.at(0)); if (master && master->connectionInProgress()) { isEdgeFromEmbeddedLinker = true; } } if (!isEdgeFromEmbeddedLinker) { mScene->clearSelection(); elem->setSelected(true); } NodeElement* nodeElem = dynamic_cast<NodeElement*>(elem); if (nodeElem && currentId.element() == "Class" && mGraphicalAssistApi->children(currentId).empty()) { needToProcessChildren = false; for (int i = 0; i < 2; i++) { QString curChildElementType; if (i == 0) curChildElementType = "MethodsContainer"; else curChildElementType = "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); NodeElement * nodeElement = dynamic_cast<NodeElement*>(elem); if (nodeElement) nodeElement->alignToGrid(); } QAbstractItemView::rowsInserted(parent, start, end); }
ResizeHandler::ResizeHandler(NodeElement &resizingNode) : mTargetNode(resizingNode) , mElementType(resizingNode.nodeType()) { }
void CopyHandler::copyProperties(NodeElement const &destination, NodeElement const &source) const { mGraphicalAssistApi.copyProperties(destination.id(), source.id()); }