<commit_before>#include <QtGui>
#include <QtCore/QDebug>

#include "editorViewMVIface.h"
#include "editorView.h"
#include "editorViewScene.h"
#include "../../qrkernel/definitions.h"
#include "../umllib/element.h"
#include "../pluginManager/editorManager.h"
#include "../mainwindow/mainWindow.h"

using namespace qReal;

EditorViewMViface::EditorViewMViface(EditorView *view, EditorViewScene *scene)
	: QAbstractItemView(0)
	, mScene(scene)
	, mView(view)
	, mGraphicalAssistApi(NULL)
	, mLogicalAssistApi(NULL)
{
	mScene->mv_iface = this;
	mScene->view = mView;
}

EditorViewMViface::~EditorViewMViface()
{
	clearItems();
}

QRect EditorViewMViface::visualRect(const QModelIndex &) const
{
	return QRect();
}

void EditorViewMViface::scrollTo(const QModelIndex &, ScrollHint)
{
}

QModelIndex EditorViewMViface::indexAt(const QPoint &) const
{
	return QModelIndex();
}

bool EditorViewMViface::isDescendentOf(const QModelIndex &descendent, const QModelIndex &ancestor)
{
	QModelIndex prev;
	QModelIndex curr = descendent;
	do {
		if (curr.parent() == ancestor)
			return true;
		prev = curr;
		curr = curr.parent();
	} while (curr != prev);
	return false;
}

QModelIndex EditorViewMViface::moveCursor(QAbstractItemView::CursorAction,
		Qt::KeyboardModifiers)
{
	return QModelIndex();
}

int EditorViewMViface::horizontalOffset() const
{
	return 0;
}

int EditorViewMViface::verticalOffset() const
{
	return 0;
}

bool EditorViewMViface::isIndexHidden(const QModelIndex &) const
{
	return false;
}

void EditorViewMViface::setSelection(const QRect&, QItemSelectionModel::SelectionFlags )
{
}

QRegion EditorViewMViface::visualRegionForSelection(const QItemSelection &) const
{
	return QRegion();
}

void EditorViewMViface::reset()
{
	mScene->clearScene();
	clearItems();

	if (model() && model()->rowCount(QModelIndex()) == 0)
		mScene->setEnabled(false);

	// so that our diagram be nicer
	QGraphicsRectItem *rect = mScene->addRect(QRect(-1000, -1000, 2000, 2000));
	mScene->removeItem(rect);
	delete rect;

	if (model())
		rowsInserted(rootIndex(), 0, model()->rowCount(rootIndex()) - 1);
}

void EditorViewMViface::setRootIndex(const QModelIndex &index)
{
	if (index == rootIndex())
		return;
	QAbstractItemView::setRootIndex(index);
	reset();
}

Id EditorViewMViface::rootId()
{
	return mGraphicalAssistApi->idByIndex(rootIndex());
}

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);
		elem->setAssistApi(mGraphicalAssistApi, mLogicalAssistApi);

		QPointF ePos = model()->data(current, roles::positionRole).toPointF();
		bool needToProcessChildren = true;
		if (elem) {
			elem->setPos(ePos);	//задаем позицию до определения родителя для того, чтобы правильно отработал itemChange
			elem->setId(currentId);

			NodeElement* nodeElement = dynamic_cast<NodeElement*>(elem);
			if (nodeElement)
				nodeElement->storeGeometry();

			if (item(parent) != NULL)
				elem->setParentItem(item(parent));
			else
				mScene->addItem(elem);<commit_msg>fix #254<commit_after>#include <QtGui>
#include <QtCore/QDebug>

#include "editorViewMVIface.h"
#include "editorView.h"
#include "editorViewScene.h"
#include "../../qrkernel/definitions.h"
#include "../umllib/element.h"
#include "../pluginManager/editorManager.h"
#include "../mainwindow/mainWindow.h"

using namespace qReal;

EditorViewMViface::EditorViewMViface(EditorView *view, EditorViewScene *scene)
	: QAbstractItemView(0)
	, mScene(scene)
	, mView(view)
	, mGraphicalAssistApi(NULL)
	, mLogicalAssistApi(NULL)
{
	mScene->mv_iface = this;
	mScene->view = mView;
}

EditorViewMViface::~EditorViewMViface()
{
	clearItems();
}

QRect EditorViewMViface::visualRect(const QModelIndex &) const
{
	return QRect();
}

void EditorViewMViface::scrollTo(const QModelIndex &, ScrollHint)
{
}

QModelIndex EditorViewMViface::indexAt(const QPoint &) const
{
	return QModelIndex();
}

bool EditorViewMViface::isDescendentOf(const QModelIndex &descendent, const QModelIndex &ancestor)
{
	QModelIndex prev;
	QModelIndex curr = descendent;
	do {
		if (curr.parent() == ancestor)
			return true;
		prev = curr;
		curr = curr.parent();
	} while (curr != prev);
	return false;
}

QModelIndex EditorViewMViface::moveCursor(QAbstractItemView::CursorAction,
		Qt::KeyboardModifiers)
{
	return QModelIndex();
}

int EditorViewMViface::horizontalOffset() const
{
	return 0;
}

int EditorViewMViface::verticalOffset() const
{
	return 0;
}

bool EditorViewMViface::isIndexHidden(const QModelIndex &) const
{
	return false;
}

void EditorViewMViface::setSelection(const QRect&, QItemSelectionModel::SelectionFlags )
{
}

QRegion EditorViewMViface::visualRegionForSelection(const QItemSelection &) const
{
	return QRegion();
}

void EditorViewMViface::reset()
{
	mScene->clearScene();
	clearItems();

	if (model() && model()->rowCount(QModelIndex()) == 0)
		mScene->setEnabled(false);

	// so that our diagram be nicer
	QGraphicsRectItem *rect = mScene->addRect(QRect(-1000, -1000, 2000, 2000));
	mScene->removeItem(rect);
	delete rect;

	if (model())
		rowsInserted(rootIndex(), 0, model()->rowCount(rootIndex()) - 1);
}

void EditorViewMViface::setRootIndex(const QModelIndex &index)
{
	if (index == rootIndex())
		return;
	QAbstractItemView::setRootIndex(index);
	reset();
}

Id EditorViewMViface::rootId()
{
	return mGraphicalAssistApi->idByIndex(rootIndex());
}

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);
		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));
			else
				mScene->addItem(elem);
{'fraction_non_alphanumeric': 0.14397212543554008, 'fraction_numerical': 0.006829268292682927, 'mean_word_length': 5.7317073170731705, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 55, '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': '2247910', 'n_tokens_mistral': 2611, 'n_tokens_neox': 2476, 'n_words': 487}