<commit_before>#include <QtGui>

#include "palettetoolbox.h"
#include "realrepoinfo.h"

PaletteToolbox::DraggableElement::DraggableElement(int classid, QWidget *parent/*0*/)
	: QWidget(parent)
{
	RealRepoInfo info;

	m_id = classid;
	m_text = info.objectName(classid);
	m_icon = info.objectIcon(classid);
	
	QHBoxLayout *layout = new QHBoxLayout(this);
	QLabel *icon = new QLabel(this);
	icon->setFixedSize(24,24);
	icon->setPixmap(m_icon.pixmap(24,24));
	layout->addWidget(icon);

	QLabel *text = new QLabel(this);
	text->setText(m_text);
	layout->addWidget(text);

	setLayout(layout);
}

PaletteToolbox::PaletteToolbox(QWidget *parent)
    : QToolBox(parent)
{
	RealRepoInfo info;
//  setAcceptDrops(true);
	QStringList categories = info.getObjectCategories();
	for (int i = 0; i < categories.size(); i++) {
		QWidget *tab = new QWidget(this);
		QVBoxLayout *layout = new QVBoxLayout(this);
		addItem(tab, categories[i]);

		foreach(int classid, info.getObjects(i)) {
			DraggableElement *element = new DraggableElement(classid, this);
			layout->addWidget(element);
		}
		
		tab->setLayout(layout);
	}
}

void PaletteToolbox::dragEnterEvent(QDragEnterEvent *event)
{
}

void PaletteToolbox::dropEvent(QDropEvent *event)
{
}

void PaletteToolbox::mousePressEvent(QMouseEvent *event)
{
	QWidget *atMouse = childAt(event->pos());
	if ( atMouse == this )
		return;

    DraggableElement *child = dynamic_cast<DraggableElement *>(atMouse->parent());
	if (!child)
		child = dynamic_cast<DraggableElement *>(atMouse);
	if (!child)
		return;

	QByteArray itemData;

	QDataStream stream(&itemData, QIODevice::WriteOnly);
	stream << -1;				// uuid
	stream << child->id();		// type
	stream << child->text();

    QMimeData *mimeData = new QMimeData;
	mimeData->setData("application/x-real-uml-data", itemData);
	// mimeData->setText(child->text());
        
    QDrag *drag = new QDrag(this);
	drag->setMimeData(mimeData);
    drag->setPixmap(child->icon().pixmap(32,32));

	if (drag->start(Qt::CopyAction | Qt::MoveAction) == Qt::MoveAction)
        child->close();
    else {
        child->show();
    }
}<commit_msg>Fixed segfault on palette<commit_after>#include <QtGui>

#include "palettetoolbox.h"
#include "realrepoinfo.h"

PaletteToolbox::DraggableElement::DraggableElement(int classid, QWidget *parent/*0*/)
	: QWidget(parent)
{
	RealRepoInfo info;

	m_id = classid;
	m_text = info.objectName(classid);
	m_icon = info.objectIcon(classid);

	QHBoxLayout *layout = new QHBoxLayout(this);
	QLabel *icon = new QLabel(this);
	icon->setFixedSize(24,24);
	icon->setPixmap(m_icon.pixmap(24,24));
	layout->addWidget(icon);

	QLabel *text = new QLabel(this);
	text->setText(m_text);
	layout->addWidget(text);

	setLayout(layout);
}

PaletteToolbox::PaletteToolbox(QWidget *parent)
	: QToolBox(parent)
{
	RealRepoInfo info;
	//  setAcceptDrops(true);
	QStringList categories = info.getObjectCategories();
	for (int i = 0; i < categories.size(); i++) {
		QWidget *tab = new QWidget(this);
		QVBoxLayout *layout = new QVBoxLayout(this);
		addItem(tab, categories[i]);

		foreach(int classid, info.getObjects(i)) {
			DraggableElement *element = new DraggableElement(classid, this);
			layout->addWidget(element);
		}

		tab->setLayout(layout);
	}
}

void PaletteToolbox::dragEnterEvent(QDragEnterEvent *event)
{
}

void PaletteToolbox::dropEvent(QDropEvent *event)
{
}

void PaletteToolbox::mousePressEvent(QMouseEvent *event)
{
	QWidget *atMouse = childAt(event->pos());
	if ( ! atMouse || atMouse == this )
		return;

	DraggableElement *child = dynamic_cast<DraggableElement *>(atMouse->parent());
	if (!child)
		child = dynamic_cast<DraggableElement *>(atMouse);
	if (!child)
		return;

	QByteArray itemData;

	QDataStream stream(&itemData, QIODevice::WriteOnly);
	stream << -1;				// uuid
	stream << child->id();		// type
	stream << child->text();

	QMimeData *mimeData = new QMimeData;
	mimeData->setData("application/x-real-uml-data", itemData);
	// mimeData->setText(child->text());

	QDrag *drag = new QDrag(this);
	drag->setMimeData(mimeData);

	QPixmap p = child->icon().pixmap(96,96);

	if ( ! p.isNull() )
		drag->setPixmap(child->icon().pixmap(96,96));

	if (drag->start(Qt::CopyAction | Qt::MoveAction) == Qt::MoveAction)
		child->close();
	else {
		child->show();
	}
}
{'fraction_non_alphanumeric': 0.16034644194756553, 'fraction_numerical': 0.007958801498127341, 'mean_word_length': 5.148201438848921, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 50, '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': '6814674', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1559, 'n_words': 277}