<commit_before>#include "editorviewscene.h"
#include "math.h"

#include <QGraphicsTextItem>
#include <QtGui>
#include <QtCore/QDebug>
#include <QtCore/QSettings>
#include <QGraphicsItem>

#include "editorviewmviface.h"
#include "editorview.h"
#include "mainwindow.h"
#include "../mainwindow/mainwindow.h"

using namespace qReal;

EditorViewScene::EditorViewScene(QObject * parent)
	:  QGraphicsScene(parent), mWindow(NULL), mPrevParent(0)
{
	QSettings settings("SPbSU", "QReal");
	mNeedDrawGrid = settings.value("ShowGrid", true).toBool();
	mWidthOfGrid = static_cast<double>(settings.value("GridWidth", 10).toInt()) / 100;
	mRealIndexGrid = settings.value("IndexGrid", 50).toInt();
	setItemIndexMethod(NoIndex);
	setEnabled(false);
	mRightButtonPressed = false;

	mActionSignalMapper = new QSignalMapper(this);
}

EditorViewScene::~EditorViewScene()
{
	delete mActionSignalMapper;
}

void EditorViewScene::drawIdealGesture()
{
	mouseMovementManager->drawIdealPath();
}

void EditorViewScene::printElementsOfRootDiagram()
{
	mouseMovementManager->setGesturesPainter(mWindow->gesturesPainter());
	mouseMovementManager->printElements();
}

void EditorViewScene::initMouseMoveManager()
{
	if (!mv_iface || !mv_iface->graphicalAssistApi())
		return;
	qReal::Id diagram = mv_iface->graphicalAssistApi()->idByIndex(mWindow->rootIndex());
	if (diagram == Id())
		// Root diagram is not set, for example, current tab is disabled. No need
		// to do anything with mouse manager.
		return;
	QList<qReal::Id> elements = mWindow->manager()->elements(diagram);
	mouseMovementManager = new MouseMovementManager(elements,
			mWindow->manager(), mWindow->gesturesPainter());
	connect(mWindow, SIGNAL(currentIdealGestureChanged()), this, SLOT(drawIdealGesture()));
	connect(mWindow, SIGNAL(gesturesShowed()), this, SLOT(printElementsOfRootDiagram()));
}

void EditorViewScene::drawGrid(QPainter *painter, const QRectF &rect)
{
	int const indexGrid = QSettings("SPbSU", "QReal").value("IndexGrid", 50).toInt();
	qreal const sceneX = rect.x();
	qreal const sceneY = rect.y();
	int startX = static_cast<int>(sceneX + 10) / indexGrid * indexGrid;
	int endX = static_cast<int>(sceneX + rect.width() - 10) / indexGrid * indexGrid;
	int startY = static_cast<int>(sceneY + 10) / indexGrid * indexGrid;
	int endY = static_cast<int>(sceneY + rect.height() - 10) / indexGrid * indexGrid;<commit_msg>fixed grid drawing on screen edges. closes #77 in robots<commit_after>#include "editorviewscene.h"
#include "math.h"

#include <QGraphicsTextItem>
#include <QtGui>
#include <QtCore/QDebug>
#include <QtCore/QSettings>
#include <QGraphicsItem>

#include "editorviewmviface.h"
#include "editorview.h"
#include "mainwindow.h"
#include "../mainwindow/mainwindow.h"

using namespace qReal;

EditorViewScene::EditorViewScene(QObject * parent)
	:  QGraphicsScene(parent), mWindow(NULL), mPrevParent(0)
{
	QSettings settings("SPbSU", "QReal");
	mNeedDrawGrid = settings.value("ShowGrid", true).toBool();
	mWidthOfGrid = static_cast<double>(settings.value("GridWidth", 10).toInt()) / 100;
	mRealIndexGrid = settings.value("IndexGrid", 50).toInt();
	setItemIndexMethod(NoIndex);
	setEnabled(false);
	mRightButtonPressed = false;

	mActionSignalMapper = new QSignalMapper(this);
}

EditorViewScene::~EditorViewScene()
{
	delete mActionSignalMapper;
}

void EditorViewScene::drawIdealGesture()
{
	mouseMovementManager->drawIdealPath();
}

void EditorViewScene::printElementsOfRootDiagram()
{
	mouseMovementManager->setGesturesPainter(mWindow->gesturesPainter());
	mouseMovementManager->printElements();
}

void EditorViewScene::initMouseMoveManager()
{
	if (!mv_iface || !mv_iface->graphicalAssistApi())
		return;
	qReal::Id diagram = mv_iface->graphicalAssistApi()->idByIndex(mWindow->rootIndex());
	if (diagram == Id())
		// Root diagram is not set, for example, current tab is disabled. No need
		// to do anything with mouse manager.
		return;
	QList<qReal::Id> elements = mWindow->manager()->elements(diagram);
	mouseMovementManager = new MouseMovementManager(elements,
			mWindow->manager(), mWindow->gesturesPainter());
	connect(mWindow, SIGNAL(currentIdealGestureChanged()), this, SLOT(drawIdealGesture()));
	connect(mWindow, SIGNAL(gesturesShowed()), this, SLOT(printElementsOfRootDiagram()));
}

void EditorViewScene::drawGrid(QPainter *painter, const QRectF &rect)
{
	int const indexGrid = QSettings("SPbSU", "QReal").value("IndexGrid", 50).toInt();
	qreal const sceneX = rect.x();
	qreal const sceneY = rect.y();

	int const indent = 100; // should be enough

	int startX = static_cast<int>(sceneX + 10) / indexGrid * indexGrid - indent;
	int endX = static_cast<int>(sceneX + rect.width() - 10) / indexGrid * indexGrid + indent;
	int startY = static_cast<int>(sceneY + 10) / indexGrid * indexGrid - indent;
	int endY = static_cast<int>(sceneY + rect.height() - 10) / indexGrid * indexGrid + indent;
{'fraction_non_alphanumeric': 0.14420706655710763, 'fraction_numerical': 0.008422350041084634, 'mean_word_length': 6.716323296354992, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 49, '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': '752861', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1602, 'n_words': 327}