示例#1
0
QString QrsMetamodelLoader::validateRootNode(const qrRepo::RepoApi &repo, const Id &diagram)
{
	if (!repo.hasProperty(diagram, "nodeName")) {
		return QString();
	}

	const QString rootNode = repo.property(diagram, "nodeName").toString();
	for (const Id &child : repo.children(diagram)) {
		if (repo.name(child) == rootNode && (child.type() == metamodelNodeType || child.type() == metamodelGroupType)) {
			return rootNode;
		}
	}

	emit errorOccured(QObject::tr("Root node for diagram %1 (which is %2) does not exist!")
			.arg(repo.name(diagram)).arg(rootNode), diagram);
	return rootNode;
}
示例#2
0
void Binding::apply(const qrRepo::RepoApi &repo
		, const Id &id, QString &data)
{
	const QString property = mProperty.isEmpty()
			? mValue
			: mProperty == "name"
					? repo.name(id)
					: repo.property(id, mProperty).toString();

	if (mConverter) {
		data.replace(mLabel, mConverter->convert(property));
	} else {
		applyMulti(property, data);
	}
}
示例#3
0
QString QrsMetamodelLoader::validatePortName(const qrRepo::RepoApi &repo, const Id &id, const QString &name)
{
	if (name == "NonTyped") {
		return name;
	}

	for (const Id &port : repo.elementsByType(metamodelPortType.element())) {
		if (repo.name(port) == name) {
			return name;
		}
	}

	emit errorOccured(tr("Port type %1 not declared in metamodel"), id);
	return "NonTyped";
}
示例#4
0
QString QrsMetamodelLoader::validateName(const qrRepo::RepoApi &repo, const Id &id)
{
	const QString result = repo.name(id);
	if (result.isEmpty()) {
		emit errorOccured(tr("Name should not be empty"), id);
	}

	const QRegExp patten("[A-Za-z_]+([A-Za-z_0-9 :]*)");
	if (!patten.exactMatch(result)) {
		emit errorOccured(QObject::tr("Name should contain only latin letters, digits, spaces and underscores "
			"and should start with latin letter or underscore"), id);
	}

	return result;
}
示例#5
0
void QrsMetamodelLoader::parseProperties(const qrRepo::RepoApi &repo, ElementType &element, const Id &id)
{
	const IdList children = repo.children(id);

	for (const Id &child : children) {
		if (child.type() == metamodelAttributeType && repo.isLogicalElement(id)) {
			const QString type = repo.stringProperty(child, "attributeType");
			element.addProperty(repo.name(child), type
					, stringProperty(repo, child, "defaultValue", "string")
					, stringProperty(repo, child, "displayedName")
					, stringProperty(repo, child, "description")
					, type == "reference");
		}
	}
}
示例#6
0
void QrsMetamodelLoader::parseGroup(const qrRepo::RepoApi &repo
		, Metamodel &metamodel, const Id &diagram, const Id &id)
{
	/// @todo: We should not use XML here, PatternType must not parse XML at all.
	QDomDocument document;
	QDomElement groupElement = document.createElement("group");
	groupElement.setAttribute("name", validateName(repo, id));
	groupElement.setAttribute("rootNode", stringProperty(repo, id, "rootNode"));
	document.appendChild(groupElement);
	parseGroupNodes(repo, groupElement, id);
	PatternType *pattern = new PatternType(metamodel);
	pattern->setXml(document.toString(4));
	pattern->setDiagram(repo.name(diagram));
	metamodel.addElement(*pattern);
}
示例#7
0
void QrsMetamodelLoader::parsePorts(const qrRepo::RepoApi &repo
		, EdgeElementType &edge, const Id &id, const QString &direction)
{
	const QString propertyName = direction + "Ports";
	const QStringList ports = stringProperty(repo, id, propertyName).split(',', QString::SkipEmptyParts);
	QStringList result;
	for (const QString &port : ports) {
		const Id portId = Id::loadFromString(port);
		result << repo.name(portId);
	}

	if (direction == "from") {
		edge.setFromPortTypes(result);
	} else {
		edge.setToPortTypes(result);
	}
}
示例#8
0
void QrsMetamodelLoader::parseNode(const qrRepo::RepoApi &repo
		, Metamodel &metamodel, const Id &diagram, const Id &id)
{
	NodeElementType *node = new NodeElementType(metamodel);

	node->setName(validateName(repo, id));
	node->setFriendlyName(repo.stringProperty(id, "displayedName"));
	node->setDiagram(repo.name(diagram));
	node->setMouseGesture(stringProperty(repo, id, "path"));
	node->setDescription(stringProperty(repo, id, "description"));
	node->setHidden(boolProperty(repo, id, "abstract"));
	node->setResizable(boolProperty(repo, id, "isResizeable", true));
	node->setCreateChildrenFromMenu(boolProperty(repo, id, "createChildrenFromMenu"));

	parseSdfGraphics(repo, *node, id);
	parseContainerProperties(repo, *node, id);
	parseProperties(repo, *node, id);

	metamodel.addElement(*node);
}
示例#9
0
void QrsMetamodelLoader::parseEdge(const qrRepo::RepoApi &repo
		, Metamodel &metamodel, const Id &diagram, const Id &id)
{
	EdgeElementType *edge = new EdgeElementType(metamodel);

	edge->setName(validateName(repo, id));
	edge->setFriendlyName(repo.stringProperty(id, "displayedName"));
	edge->setDiagram(repo.name(diagram));
	edge->setDescription(stringProperty(repo, id, "description"));
	edge->setDividable(boolProperty(repo, id, "isDividable"));

	edge->setPenWidth(1);
	edge->setPenColor(Qt::black);
	edge->setPenStyle(parsePenStyle(stringProperty(repo, id, "lineType"), id));
	edge->setShapeType(parseLinkShape(stringProperty(repo, id, "shape"), id));

	const QString labelText = stringProperty(repo, id, "labelText");

	if (!labelText.isEmpty()) {
		LabelProperties label;
		const QString labelType = stringProperty(repo, id, "labelType");
		if (labelType.contains("static", Qt::CaseInsensitive)) {
			label = LabelProperties(0, 0, 0, labelText, 0);
		} else if (labelType.contains("dynamic", Qt::CaseInsensitive)) {
			label = LabelProperties(0, 0, 0, labelText, false, 0);
		} else {
			emit errorOccured(tr("Incorrect label type"), id);
		}

		label.setHard(boolProperty(repo, id, "hardLabel"));
		edge->addLabel(label);
	}

	parseAssociations(repo, *edge, id);
	parseProperties(repo, *edge, id);
	parsePorts(repo, *edge, id, "from");
	parsePorts(repo, *edge, id, "to");

	metamodel.addElement(*edge);
}