int QrsMetamodelLoader::intProperty(const qrRepo::RepoApi &repo, const Id &id
		, const QString &propertyName, int defaultValue)
{
	if (!repo.hasProperty(id, propertyName)) {
		return defaultValue;
	}

	return parseInt(repo.stringProperty(id, propertyName), id);
}
QString QrsMetamodelLoader::stringProperty(const qrRepo::RepoApi &repo, const Id &id
		, const QString &propertyName, const QString &defaultValue)
{
	if (!repo.hasProperty(id, propertyName)) {
		return defaultValue;
	}

	return repo.stringProperty(id, propertyName);
}
bool QrsMetamodelLoader::boolProperty(const qrRepo::RepoApi &repo, const Id &id
		, const QString &propertyName, bool defaultValue)
{
	if (!repo.hasProperty(id, propertyName)) {
		return defaultValue;
	}

	return repo.stringProperty(id, propertyName) == "true";
}
QVector<int> QrsMetamodelLoader::intVectorProperty(const qrRepo::RepoApi &repo, const Id &id
		, const QString &propertyName, const QVector<int> &defaultValue)
{
	if (!repo.hasProperty(id, propertyName)) {
		return defaultValue;
	}

	const QStringList values = repo.stringProperty(id, propertyName).split(",", QString::SkipEmptyParts);
	QVector<int> result(values.size());
	for (int i = 0; i < values.size(); ++i) {
		result[i] = parseInt(values[i], id);
	}

	return result;
}
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;
}