<commit_before>#include "gradientlineqmladaptor.h"

#include <qdeclarative.h>
#include <QMessageBox>

#include <nodeproperty.h>
#include <nodelistproperty.h>
#include <nodemetainfo.h>
#include <abstractview.h>
#include <rewritingexception.h>
#include <variantproperty.h>

namespace QmlDesigner {

GradientLineQmlAdaptor::GradientLineQmlAdaptor(QWidget *parent) :
    QmlEditorWidgets::GradientLine(parent)
{
    setActive(false);
    connect(this, SIGNAL(gradientChanged()), this, SLOT(writeGradient()));
}

void GradientLineQmlAdaptor::setItemNode(const QVariant &itemNode)
{

    if (!itemNode.value<ModelNode>().isValid())
        return;
    m_itemNode = itemNode.value<ModelNode>();
    emit itemNodeChanged();
}

static inline QColor normalizeColor(const QColor &color)
{
    QColor newColor = QColor(color.name());
    newColor.setAlpha(color.alpha());
    return newColor;
}

static inline qreal roundReal(qreal real)
{
    int i = real * 100;
    return qreal(i) / 100;
}

void GradientLineQmlAdaptor::setupGradient()
{
    if (!active())
        return;

    ModelNode modelNode = m_itemNode.modelNode();
    QLinearGradient newGradient;
    QVector<QGradientStop> stops;

    if (!modelNode.isValid())
        return;

    if (modelNode.hasProperty(gradientName())) { //gradient exists

        ModelNode gradientNode = modelNode.nodeProperty(gradientName()).modelNode();
        QList<ModelNode> stopList = gradientNode.nodeListProperty("stops").toModelNodeList();

        foreach (const ModelNode &stopNode, stopList) {
            QmlObjectNode stopObjectNode = stopNode;
            if (stopObjectNode.isValid()) {
                qreal position = stopObjectNode.instanceValue("position").toReal();
                QColor color = stopObjectNode.instanceValue("color").value<QColor>();
                stops.append( QPair<qreal, QColor>(position, color));
            }
        }
    } else {
        stops.append( QPair<qreal, QColor>(0, activeColor()));
        stops.append( QPair<qreal, QColor>(1, QColor(Qt::black)));
    }

    newGradient.setStops(stops);
    setGradient(newGradient);
}

void GradientLineQmlAdaptor::writeGradient()
{<commit_msg>QmlDesigner.propertyEditor: read gradient data from model<commit_after>#include "gradientlineqmladaptor.h"

#include <qdeclarative.h>
#include <QMessageBox>

#include <nodeproperty.h>
#include <nodelistproperty.h>
#include <nodemetainfo.h>
#include <abstractview.h>
#include <rewritingexception.h>
#include <variantproperty.h>

namespace QmlDesigner {

GradientLineQmlAdaptor::GradientLineQmlAdaptor(QWidget *parent) :
    QmlEditorWidgets::GradientLine(parent)
{
    setActive(false);
    connect(this, SIGNAL(gradientChanged()), this, SLOT(writeGradient()));
}

void GradientLineQmlAdaptor::setItemNode(const QVariant &itemNode)
{

    if (!itemNode.value<ModelNode>().isValid())
        return;
    m_itemNode = itemNode.value<ModelNode>();
    emit itemNodeChanged();
}

static inline QColor normalizeColor(const QColor &color)
{
    QColor newColor = QColor(color.name());
    newColor.setAlpha(color.alpha());
    return newColor;
}

static inline qreal roundReal(qreal real)
{
    int i = real * 100;
    return qreal(i) / 100;
}

void GradientLineQmlAdaptor::setupGradient()
{
    if (!active())
        return;

    ModelNode modelNode = m_itemNode.modelNode();
    QLinearGradient newGradient;
    QVector<QGradientStop> stops;

    if (!modelNode.isValid())
        return;

    if (modelNode.hasProperty(gradientName())) { //gradient exists

        ModelNode gradientNode = modelNode.nodeProperty(gradientName()).modelNode();
        QList<ModelNode> stopList = gradientNode.nodeListProperty("stops").toModelNodeList();

        foreach (const ModelNode &stopNode, stopList) {
            QmlObjectNode stopObjectNode = stopNode;
            if (stopObjectNode.isValid()) {
                qreal position = stopNode.variantProperty("position").value().toReal();
                QColor color = stopNode.variantProperty("color").value().value<QColor>();
                stops.append( QPair<qreal, QColor>(position, color));
            }
        }
    } else {
        stops.append( QPair<qreal, QColor>(0, activeColor()));
        stops.append( QPair<qreal, QColor>(1, QColor(Qt::black)));
    }

    newGradient.setStops(stops);
    setGradient(newGradient);
}

void GradientLineQmlAdaptor::writeGradient()
{
{'fraction_non_alphanumeric': 0.1275626423690205, 'fraction_numerical': 0.0036446469248291574, 'mean_word_length': 3.9281705948372614, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, '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': '4444242', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1354, 'n_words': 247}