SaveConvertionManager::GraphicalFilter SaveConvertionManager::graphicalRecreate(
		const SaveConvertionManager::GraphicalReplacer &replacer
		, const SaveConvertionManager::GraphicalConstructor &constructor)
{
	return [replacer, constructor](const Id &block, GraphicalModelAssistInterface &graphicalApi) {
		// Just iterating throught the elements on some diagram, ignoring the diagram itself.
		if (isDiagramType(block)) {
			return false;
		}

		// For each element trying to find out what to replace it with.
		const Id newType = replacer(block, graphicalApi);
		if (newType.isNull()) {
			// Not every element be replaced, concrete implementation must decide it.
			return false;
		}

		// Then creating new element of some type...
		const Id newBlock = Id::createElementId(newType.editor(), newType.diagram(), newType.element());
		graphicalApi.createElement(graphicalApi.parent(block)
				, newBlock
				, false
				, graphicalApi.name(block)
				, graphicalApi.position(block)
				, graphicalApi.logicalId(block));
		// And initializing it...
		constructor(newBlock, block, graphicalApi);

		const bool isEdge = isEdgeType(block);
		if (isEdge) {
			// If out element is edge then connecting it to same elements as the old one was connected
			graphicalApi.setFrom(newBlock, graphicalApi.from(block));
			graphicalApi.setTo(newBlock, graphicalApi.to(block));
		} else {
			// Replacing old node in all incomming and outgoing edges of the old node with the new one.
			for (const Id &edge : graphicalApi.graphicalRepoApi().outgoingLinks(block)) {
				graphicalApi.mutableGraphicalRepoApi().setProperty(edge, "from", newBlock.toVariant());
			}

			for (const Id &edge : graphicalApi.graphicalRepoApi().incomingLinks(block)) {
				graphicalApi.mutableGraphicalRepoApi().setProperty(edge, "to", newBlock.toVariant());
			}
		}

		// And finally disposing of outdated entity.
		graphicalApi.removeElement(block);
		return true;
	};
}
Beispiel #2
0
void ExploserView::createAddExplosionMenu(const Element * const element
		, QMenu &contextMenu, QList<Explosion> const &explosions
		, const Id &alreadyConnectedElement) const
{
	bool hasAnyActions = false;
	const QString menuName = alreadyConnectedElement.isNull()
			? mCustomizer.addExplosionMenuName()
			: mCustomizer.changeExplosionMenuName();
	QMenu *addExplosionMenu = new QMenu(menuName);

	for (const Explosion &explosion : explosions) {
		for (const Id &elementId : mLogicalApi.logicalRepoApi().logicalElements(explosion.target())) {
			if (alreadyConnectedElement == elementId) {
				continue;
			}
			QAction *action = addExplosionMenu->addAction(mLogicalApi.logicalRepoApi().name(elementId));
			hasAnyActions = true;
			connect(action, SIGNAL(triggered()), SLOT(addExplosionActionTriggered()));
			QList<QVariant> tag;
			tag << element->logicalId().toVariant() << elementId.toVariant();
			action->setData(tag);
		}
	}

	if (hasAnyActions) {
		addExplosionMenu->addSeparator();
	}

	for (const Explosion &explosion : explosions) {
		const Id diagramType = mLogicalApi.editorManagerInterface().findElementByType(explosion.target().element());
		const QString name = mLogicalApi.editorManagerInterface().friendlyName(diagramType);
		const QString editorName = mLogicalApi.editorManagerInterface().friendlyName(Id(diagramType.editor()));
		QAction *action = addExplosionMenu->addAction(tr("New ") + editorName + "/" + name);
		hasAnyActions = true;
		connect(action, SIGNAL(triggered()), SLOT(addExplosionActionTriggered()));
		action->setData(QVariantList() << element->logicalId().toVariant() << diagramType.toVariant());
	}
	contextMenu.addMenu(addExplosionMenu);

	if (alreadyConnectedElement != Id()) {
		QAction * const gotoAction = contextMenu.addAction(mCustomizer.goToConnectedMenuName()
				, this, SLOT(goToActionTriggered()));
		gotoAction->setData(alreadyConnectedElement.toVariant());
	}
}
Beispiel #3
0
TEST(IdsTest, toUrlToStringToVariantTest) {
	QString const idString = "qrm:/editor/diagram/element/id";
	Id const id = Id::loadFromString(idString);

	EXPECT_EQ(id.toString(), idString);
	EXPECT_EQ(id.toUrl(), QUrl(idString));

	QVariant toVariant = id.toVariant();
	EXPECT_EQ(toVariant.value<Id>(), id);
}
Beispiel #4
0
void ExploserView::createRemoveExplosionMenu(const Element * const element, QMenu &contextMenu
		, const Id &outgoingConnection) const
{
	if (outgoingConnection.isNull()) {
		return;
	}

	QAction * const action = contextMenu.addAction(mCustomizer.deleteExplosionMenuName());
	connect(action, SIGNAL(triggered()), SLOT(removeExplosionActionTriggered()));
	action->setData(QVariantList() << element->logicalId().toVariant() << outgoingConnection.toVariant());
}
Beispiel #5
0
void ModelsAssistApi::setFrom(Id const &elem, Id const &newValue)
{
	setProperty(elem, newValue.toVariant(), roles::fromRole);
}