<commit_before>/// HEADER
#include <csapex/view/widgets/message_preview_widget.h>

/// PROJECT
#include <csapex/msg/direct_connection.h>
#include <csapex/manager/message_renderer_manager.h>
#include <csapex/msg/io.h>
#include <csapex/msg/generic_value_message.hpp>
#include <csapex/msg/any_message.h>
#include <csapex/utility/uuid_provider.h>
#include <csapex/utility/exceptions.h>

/// SYSTEM
#include <QApplication>
#include <QGraphicsPixmapItem>
#include <QFocusEvent>
#include <iostream>

using namespace csapex;
using namespace csapex::impl;

PreviewInput::PreviewInput(QPointer<MessagePreviewWidget> parent)
    : Input(UUIDProvider::makeUUID_without_parent("message_preview_in")),
      parent_(parent)
{
    setType(std::make_shared<connection_types::AnyMessage>());
    setVirtual(true);
}

void PreviewInput::setToken(TokenPtr token)
{
    Input::setToken(token);

    if(isConnected()) {
        TokenDataConstPtr msg = token->getTokenData();

        if(!parent_) {
            return;
        }
        try {
            if(auto m = msg::message_cast<connection_types::GenericValueMessage<int>>(msg)) {
                parent_->displayTextRequest(QString::number(m->value));
                return;

            } else if(auto m = msg::message_cast<connection_types::GenericValueMessage<float>>(msg)) {
                parent_->displayTextRequest(QString::number(m->value));
                return;

            } else if(auto m = msg::message_cast<connection_types::GenericValueMessage<double>>(msg)) {
                parent_->displayTextRequest(QString::number(m->value));
                return;

            } else if(auto m = msg::message_cast<connection_types::GenericValueMessage<std::string>>(msg)) {
                parent_->displayTextRequest(QString::fromStdString(m->value));
                return;
            }
            MessageRenderer::Ptr renderer = MessageRendererManager::instance().createMessageRenderer(msg);
            if(renderer) {
                std::unique_ptr<QImage> img = renderer->render(msg);
                if(parent_) {
                    parent_->displayImageRequest(*img);
                }
            }
        } catch(const std::exception& e) {
            // silent death
        }
    }
}

void PreviewInput::detach()
{
    parent_.clear();
}

MessagePreviewWidget::MessagePreviewWidget()
    : pm_item_(nullptr), txt_item_(nullptr)<commit_msg>Fix message preview for int, float, double and string<commit_after>/// HEADER
#include <csapex/view/widgets/message_preview_widget.h>

/// PROJECT
#include <csapex/msg/direct_connection.h>
#include <csapex/manager/message_renderer_manager.h>
#include <csapex/msg/io.h>
#include <csapex/msg/generic_value_message.hpp>
#include <csapex/msg/any_message.h>
#include <csapex/utility/uuid_provider.h>
#include <csapex/utility/exceptions.h>

/// SYSTEM
#include <QApplication>
#include <QGraphicsPixmapItem>
#include <QFocusEvent>
#include <iostream>

using namespace csapex;
using namespace csapex::impl;

PreviewInput::PreviewInput(QPointer<MessagePreviewWidget> parent)
    : Input(UUIDProvider::makeUUID_without_parent("message_preview_in")),
      parent_(parent)
{
    setType(std::make_shared<connection_types::AnyMessage>());
    setVirtual(true);
}

void PreviewInput::setToken(TokenPtr token)
{
    Input::setToken(token);

    if(isConnected()) {
        TokenDataConstPtr message = token->getTokenData();

        if(!parent_) {
            return;
        }
        try {
            if(msg::isExactValue<std::string>(this)) {
                parent_->displayTextRequest(QString::fromStdString(msg::getValue<std::string>(this)));

            } else if(msg::isExactValue<int>(this)) {
                parent_->displayTextRequest(QString::number(msg::getValue<int>(this)));

            } else if(msg::isExactValue<float>(this)) {
                parent_->displayTextRequest(QString::number(msg::getValue<float>(this)));

            } else if(msg::isExactValue<double>(this)) {
                parent_->displayTextRequest(QString::number(msg::getValue<float>(this)));

            } else {
                MessageRenderer::Ptr renderer = MessageRendererManager::instance().createMessageRenderer(message);
                if(renderer) {
                    std::unique_ptr<QImage> img = renderer->render(message);
                    if(parent_) {
                        parent_->displayImageRequest(*img);
                    }
                }
            }
        } catch(const std::exception& e) {
            // silent death
        }
    }
}

void PreviewInput::detach()
{
    parent_.clear();
}

MessagePreviewWidget::MessagePreviewWidget()
    : pm_item_(nullptr), txt_item_(nullptr)
{'fraction_non_alphanumeric': 0.13392857142857142, 'fraction_numerical': 0.0, 'mean_word_length': 3.066551426101988, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 67, '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': '5560558', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1368, 'n_words': 184}