<commit_before>#include "graphicalModelView.h"

#include <QtCore/QUuid>
#include <QtCore/QDebug>

#include "logicalModel.h"

using namespace qReal;
using namespace models::details;
using namespace modelsImplementation;

GraphicalModelView::GraphicalModelView(LogicalModel * const model)
	: AbstractView(model)
{
}

void GraphicalModelView::rowsInserted(QModelIndex const &parent, int start, int end)
{
	QPersistentModelIndex const parentIndex = parent.sibling(parent.row(), 0);
	Id const parentLogicalId = parentIndex.data(roles::logicalIdRole).value<Id>();

	for (int row = start; row <= end; ++row) {
		QPersistentModelIndex const current = model()->index(row, 0, parent);
		Id const logicalId = current.data(roles::logicalIdRole).value<Id>();
		if (parentLogicalId == Id())
			return;
		QString const name = current.data(Qt::DisplayRole).toString();
		if (logicalId == Id())
			// No logical Id for this item, so logical model shouldn't care
			// about it.
			continue;

		// Add this element to a root for now. To be able to do something
		// useful, we need to establish a correspondence between logical
		// and graphical model hierarchy. It is not always easy since
		// some elements have no correspondences in another model, and tree
		// structures may be very different by themselves.
		LogicalModel * const mLogicalModel = static_cast<LogicalModel *>(mModel);
		mLogicalModel->addElementToModel(parentLogicalId, logicalId, logicalId, name, QPoint(0, 0));
	}
}

void GraphicalModelView::dataChanged(QModelIndex const &topLeft, QModelIndex const &bottomRight)
{
	for (int row = topLeft.row(); row <= bottomRight.row(); ++row) {
		QModelIndex current = topLeft.sibling(row, 0);

		Id const logicalId = current.data(roles::logicalIdRole).value<Id>();<commit_msg>fixed crash with adding new metamodel<commit_after>#include "graphicalModelView.h"

#include <QtCore/QUuid>
#include <QtCore/QDebug>

#include "logicalModel.h"

using namespace qReal;
using namespace models::details;
using namespace modelsImplementation;

GraphicalModelView::GraphicalModelView(LogicalModel * const model)
	: AbstractView(model)
{
}

void GraphicalModelView::rowsInserted(QModelIndex const &parent, int start, int end)
{
	QPersistentModelIndex const parentIndex = parent.sibling(parent.row(), 0);
	Id parentLogicalId = parentIndex.data(roles::logicalIdRole).value<Id>();

	for (int row = start; row <= end; ++row) {
		QPersistentModelIndex const current = model()->index(row, 0, parent);
		Id const logicalId = current.data(roles::logicalIdRole).value<Id>();
		if (parentLogicalId == Id())
			parentLogicalId = Id::rootId();
		QString const name = current.data(Qt::DisplayRole).toString();
		if (logicalId == Id())
			// No logical Id for this item, so logical model shouldn't care
			// about it.
			continue;

		// Add this element to a root for now. To be able to do something
		// useful, we need to establish a correspondence between logical
		// and graphical model hierarchy. It is not always easy since
		// some elements have no correspondences in another model, and tree
		// structures may be very different by themselves.
		LogicalModel * const mLogicalModel = static_cast<LogicalModel *>(mModel);
		mLogicalModel->addElementToModel(parentLogicalId, logicalId, logicalId, name, QPoint(0, 0));
	}
}

void GraphicalModelView::dataChanged(QModelIndex const &topLeft, QModelIndex const &bottomRight)
{
	for (int row = topLeft.row(); row <= bottomRight.row(); ++row) {
		QModelIndex current = topLeft.sibling(row, 0);

		Id const logicalId = current.data(roles::logicalIdRole).value<Id>();
{'fraction_non_alphanumeric': 0.11579241071428571, 'fraction_numerical': 0.0027901785714285715, 'mean_word_length': 5.191709844559585, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7649094', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1077, 'n_words': 330}