<commit_before>/* Copyright 2007-2016 QReal Research Group
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. */

#include "sdfRenderer.h"

#include <QtCore/QLineF>
#include <QtCore/QTime>
#include <QtCore/QDebug>
#include <QtCore/QRegExp>
#include <QtCore/QFileInfo>
#include <QtCore/QDir>
#include <QtWidgets/QApplication>
#include <QtGui/QFont>
#include <QtGui/QIcon>

#include <qrkernel/platformInfo.h>

using namespace qReal;

SdfRenderer::SdfRenderer()
	: mStartX(0), mStartY(0), mNeedScale(true), mElementRepo(0)
{
	mWorkingDirName = SettingsManager::value("workingDir").toString();
}

SdfRenderer::SdfRenderer(const QString path)
	: mStartX(0), mStartY(0), mNeedScale(true)
{
	if (!load(path))
	{
		qDebug() << "File " + path + " - loading failed!";
	}
	mWorkingDirName = SettingsManager::value("workingDir").toString();
}

SdfRenderer::~SdfRenderer()
{
}

bool SdfRenderer::load(const QString &filename)
{
	if (filename.isEmpty()) {
		return false;
	}

	QFile file(filename);

	if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
		return false;

	if (!doc.setContent(&file))
	{
		file.close();
		return false;
	}
	file.close();

	QDomElement docElem = doc.documentElement();
	first_size_x = docElem.attribute("sizex").toInt();
	first_size_y = docElem.attribute("sizey").toInt();

	return true;
}

bool SdfRenderer::load(const QDomDocument &document)
{
	doc = document;
	const QDomElement docElem = doc.firstChildElement("picture");
	first_size_x = docElem.attribute("sizex").toInt();
	first_size_y = docElem.attribute("sizey").toInt();

	return true;
}

bool SdfRenderer::load(const QDomElement &picture)
{
	doc.importNode(picture, true);
	const QDomElement docElem = doc.firstChildElement("picture");
	first_size_x = docElem.attribute("sizex").toInt();
	first_size_y = docElem.attribute("sizey").toInt();

	return true;<commit_msg>Fixed sdf loading after refactoring<commit_after>/* Copyright 2007-2016 QReal Research Group
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. */

#include "sdfRenderer.h"

#include <QtCore/QLineF>
#include <QtCore/QTime>
#include <QtCore/QDebug>
#include <QtCore/QRegExp>
#include <QtCore/QFileInfo>
#include <QtCore/QDir>
#include <QtWidgets/QApplication>
#include <QtGui/QFont>
#include <QtGui/QIcon>

#include <qrkernel/platformInfo.h>

using namespace qReal;

SdfRenderer::SdfRenderer()
	: mStartX(0), mStartY(0), mNeedScale(true), mElementRepo(0)
{
	mWorkingDirName = SettingsManager::value("workingDir").toString();
}

SdfRenderer::SdfRenderer(const QString path)
	: mStartX(0), mStartY(0), mNeedScale(true)
{
	if (!load(path))
	{
		qDebug() << "File " + path + " - loading failed!";
	}
	mWorkingDirName = SettingsManager::value("workingDir").toString();
}

SdfRenderer::~SdfRenderer()
{
}

bool SdfRenderer::load(const QString &filename)
{
	if (filename.isEmpty()) {
		return false;
	}

	QFile file(filename);

	if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
		return false;

	if (!doc.setContent(&file))
	{
		file.close();
		return false;
	}
	file.close();

	QDomElement docElem = doc.documentElement();
	first_size_x = docElem.attribute("sizex").toInt();
	first_size_y = docElem.attribute("sizey").toInt();

	return true;
}

bool SdfRenderer::load(const QDomDocument &document)
{
	doc = document;
	const QDomElement docElem = doc.firstChildElement("picture");
	first_size_x = docElem.attribute("sizex").toInt();
	first_size_y = docElem.attribute("sizey").toInt();

	return true;
}

bool SdfRenderer::load(const QDomElement &picture)
{
	doc.appendChild(doc.importNode(picture, true));
	const QDomElement docElem = doc.firstChildElement("picture");
	first_size_x = docElem.attribute("sizex").toInt();
	first_size_y = docElem.attribute("sizey").toInt();

	return true;
{'fraction_non_alphanumeric': 0.13641155386885936, 'fraction_numerical': 0.007168458781362007, 'mean_word_length': 5.410810810810811, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4544420', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1558, 'n_words': 391}