<commit_before>/*
 * Qumulus UML editor
 * Author: <NAME>
 * Author: <NAME>
 *
 */

#include "PackageShape.h"

#include <QtCore/QXmlStreamWriter>
#include <QtGui/QBrush>
#include <QtGui/QPainter>

#include <Uml/Kernel/Package.h>

QUML_BEGIN_NAMESPACE_GD

PackageShape::PackageShape(QuUK::Element* e, 
        DiagramElement* p) :
        SelectableShape(e, p) {
    constexpr int kPackageZOrdering = -2;
    setZValue(kPackageZOrdering);
    updateSizeConstraints();
    resize(0, 0);
}

PackageShape::PackageShape(const PackageShape& c) :
        SelectableShape(c) {}

QuUK::Package* PackageShape::modelElement() const {
    return dynamic_cast<QuUK::Package*>(SelectableShape::modelElement());
}

void PackageShape::updateSizeConstraints() {
    setMinimumSize({100, 10 + std::max(packageNameWidth(), 50)});
}

void PackageShape::resize(double w, double h) {
    w = minimumSize().width() == -1 ? w : std::max(w, minimumSize().width());
    h = minimumSize().height() == -1 ? h : std::max(h, minimumSize().height());

    setSize({w, h});
}

void PackageShape::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, 
        QWidget* widget) {
    updateSizeConstraints();
    resize(size());

    painter->setBrush(Qt::white);

    painter->drawRect(0, 0, 30, 10);
    painter->drawRect(0, 10, width(), height() - 10);

    QFont font = sharedStyle()->font();
    font.setBold(true);
    painter->setFont(font);
    painter->drawText(0, 12, width(), height(), 
            Qt::AlignTop | Qt::AlignHCenter,
            modelElement()->name());

    SelectableShape::paint(painter, option, widget);
}

int PackageShape::packageNameWidth() const {
    QFont font = sharedStyle()->font();
    font.setBold(true);

    QFontMetrics m(font);
    return m.width(modelElement()->name());
}

void PackageShape::writeXml(QXmlStreamWriter& writer) const {
    writer.writeStartElement("Package");
    writer.writeAttribute("id", uniqueId());
    writer.writeAttribute("x", QString::number(pos().x()));
    writer.writeAttribute("y", QString::number(pos().y()));
    writer.writeAttribute("width", QString::number(width()));
    writer.writeAttribute("height", QString::number(height()));
    writer.writeAttribute("modelelement", modelElement()->uniqueId());

    writer.writeEndElement();
}

QUML_END_NAMESPACE_GD
<commit_msg>Fix Package size bug.<commit_after>/*
 * Qumulus UML editor
 * Author: <NAME>
 * Author: <NAME>
 *
 */

#include "PackageShape.h"

#include <QtCore/QXmlStreamWriter>
#include <QtGui/QBrush>
#include <QtGui/QPainter>

#include <Uml/Kernel/Package.h>

QUML_BEGIN_NAMESPACE_GD

PackageShape::PackageShape(QuUK::Element* e,
        DiagramElement* p) :
        SelectableShape(e, p) {
    constexpr int kPackageZOrdering = -2;
    setZValue(kPackageZOrdering);
    updateSizeConstraints();
    resize(0, 0);
}

PackageShape::PackageShape(const PackageShape& c) :
        SelectableShape(c) {}

QuUK::Package* PackageShape::modelElement() const {
    return dynamic_cast<QuUK::Package*>(SelectableShape::modelElement());
}

void PackageShape::updateSizeConstraints() {
    setMinimumSize({10 + std::max(packageNameWidth(), 50), 50});
}

void PackageShape::resize(double w, double h) {
    w = minimumSize().width() == -1 ? w : std::max(w, minimumSize().width());
    h = minimumSize().height() == -1 ? h : std::max(h, minimumSize().height());

    setSize({w, h});
}

void PackageShape::paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
        QWidget* widget) {
    updateSizeConstraints();
    resize(size());

    painter->setBrush(Qt::white);

    painter->drawRect(0, 0, 30, 10);
    painter->drawRect(0, 10, width(), height() - 10);

    QFont font = sharedStyle()->font();
    font.setBold(true);
    painter->setFont(font);
    painter->drawText(0, 12, width(), height(),
            Qt::AlignTop | Qt::AlignHCenter,
            modelElement()->name());

    SelectableShape::paint(painter, option, widget);
}

int PackageShape::packageNameWidth() const {
    QFont font = sharedStyle()->font();
    font.setBold(true);

    QFontMetrics m(font);
    return m.width(modelElement()->name());
}

void PackageShape::writeXml(QXmlStreamWriter& writer) const {
    writer.writeStartElement("Package");
    writer.writeAttribute("id", uniqueId());
    writer.writeAttribute("x", QString::number(pos().x()));
    writer.writeAttribute("y", QString::number(pos().y()));
    writer.writeAttribute("width", QString::number(width()));
    writer.writeAttribute("height", QString::number(height()));
    writer.writeAttribute("modelelement", modelElement()->uniqueId());

    writer.writeEndElement();
}

QUML_END_NAMESPACE_GD

{'fraction_non_alphanumeric': 0.1713121783876501, 'fraction_numerical': 0.010934819897084048, 'mean_word_length': 4.593525179856115, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 37, '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': '6706787', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1462, 'n_words': 267}