コード例 #1
0
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();
		}
	}
}
コード例 #2
0
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);
}