<commit_before>#include <QtGui/QGuiApplication>
#include <QQmlContext>
#include <QStateMachine>
#include <QDebug>
#include <memory>
#include "./window.h"
#include "./scene.h"
#include "./nodes.h"
#include "./label_node.h"
#include "./input/invoke_manager.h"
#include "./input/signal_manager.h"
#include "./input/scxml_importer.h"
#include "./mouse_shape_controller.h"
#include "./labeller_model.h"
#include "./labels_model.h"
#include "./labelling/labels.h"
#include "./picking_controller.h"
#include "./forces_visualizer_node.h"
#include "./default_scene_creator.h"

void onLabelChangedUpdateLabelNodes(std::shared_ptr<Nodes> nodes,
                                    Labels::Action action, const Label &label)
{
  auto labelNodes = nodes->getLabelNodes();
  auto labelNode = std::find_if(labelNodes.begin(), labelNodes.end(),
                                [label](std::shared_ptr<LabelNode> labelNode)
                                {
    return labelNode->label.id == label.id;
  });

  if (labelNode == labelNodes.end())
  {
    nodes->addNode(std::make_shared<LabelNode>(label));
  }
  else if (action == Labels::Action::Delete)
  {
    nodes->removeNode(*labelNode);
  }
  else
  {
    (*labelNode)->label = label;
  }
};

int main(int argc, char **argv)
{
  qputenv("QT_MESSAGE_PATTERN",
          QString("%{time [yyyy'-'MM'-'dd' "
                  "'hh':'mm':'ss]} "
                  "%{if-fatal}\033[31;1m%{endif}"
                  "%{if-critical}\033[31m%{endif}"
                  "%{if-warning}\033[33m%{endif}"
                  "%{if-info}\033[34m%{endif}"
                  "- %{threadid} "
                  "%{if-category}%{category}: %{endif}%{message}"
                  "%{if-warning}\n\t%{file}:%{line}\n\t%{backtrace depth=3 "
                  "separator=\"\n\t\"}%{endif}"
                  "%{if-critical}\n\t%{file}:%{line}\n\t%{backtrace depth=3 "
                  "separator=\"\n\t\"}%{endif}\033[0m").toUtf8());
  if (qgetenv("QT_LOGGING_CONF").size() == 0)
    qputenv("QT_LOGGING_CONF", "../config/logging.ini");

  QGuiApplication application(argc, argv);

  qInfo() << "Application start";

  auto invokeManager = std::shared_ptr<InvokeManager>(new InvokeManager());
  auto nodes = std::make_shared<Nodes>();
  auto labels = std::make_shared<Labels>();
  auto labeller = std::make_shared<Forces::Labeller>(labels);
  auto forcesVisualizerNode = std::make_shared<ForcesVisualizerNode>(labeller);
  nodes->addNode(forcesVisualizerNode);

  DefaultSceneCreator sceneCreator(nodes, labels);
  sceneCreator.create();
  auto scene = std::make_shared<Scene>(invokeManager, nodes, labels, labeller);

  auto unsubscribeLabelChanges = labels->subscribe(
      std::bind(&onLabelChangedUpdateLabelNodes, nodes, std::placeholders::_1,<commit_msg>Extract function to setup logging and add documentation.<commit_after>#include <QtGui/QGuiApplication>
#include <QQmlContext>
#include <QStateMachine>
#include <QDebug>
#include <memory>
#include "./window.h"
#include "./scene.h"
#include "./nodes.h"
#include "./label_node.h"
#include "./input/invoke_manager.h"
#include "./input/signal_manager.h"
#include "./input/scxml_importer.h"
#include "./mouse_shape_controller.h"
#include "./labeller_model.h"
#include "./labels_model.h"
#include "./labelling/labels.h"
#include "./picking_controller.h"
#include "./forces_visualizer_node.h"
#include "./default_scene_creator.h"

void onLabelChangedUpdateLabelNodes(std::shared_ptr<Nodes> nodes,
                                    Labels::Action action, const Label &label)
{
  auto labelNodes = nodes->getLabelNodes();
  auto labelNode = std::find_if(labelNodes.begin(), labelNodes.end(),
                                [label](std::shared_ptr<LabelNode> labelNode)
                                {
    return labelNode->label.id == label.id;
  });

  if (labelNode == labelNodes.end())
  {
    nodes->addNode(std::make_shared<LabelNode>(label));
  }
  else if (action == Labels::Action::Delete)
  {
    nodes->removeNode(*labelNode);
  }
  else
  {
    (*labelNode)->label = label;
  }
};

/**
 * \brief Setup logging
 *
 * [Documentation for the
 * pattern](http://doc.qt.io/qt-5/qtglobal.html#qSetMessagePattern)
 *
 * [Documentation for console formatting]
 * (https://en.wikipedia.org/wiki/ANSI_escape_code#Colors)
 */
void setupLogging()
{
  qputenv("QT_MESSAGE_PATTERN",
          QString("%{time [yyyy'-'MM'-'dd' "
                  "'hh':'mm':'ss]} "
                  "%{if-fatal}\033[31;1m%{endif}"
                  "%{if-critical}\033[31m%{endif}"
                  "%{if-warning}\033[33m%{endif}"
                  "%{if-info}\033[34m%{endif}"
                  "- %{threadid} "
                  "%{if-category}%{category}: %{endif}%{message}"
                  "%{if-warning}\n\t%{file}:%{line}\n\t%{backtrace depth=3 "
                  "separator=\"\n\t\"}%{endif}"
                  "%{if-critical}\n\t%{file}:%{line}\n\t%{backtrace depth=3 "
                  "separator=\"\n\t\"}%{endif}\033[0m").toUtf8());
  if (qgetenv("QT_LOGGING_CONF").size() == 0)
    qputenv("QT_LOGGING_CONF", "../config/logging.ini");
}

int main(int argc, char **argv)
{
  setupLogging();

  QGuiApplication application(argc, argv);

  qInfo() << "Application start";

  auto invokeManager = std::shared_ptr<InvokeManager>(new InvokeManager());
  auto nodes = std::make_shared<Nodes>();
  auto labels = std::make_shared<Labels>();
  auto labeller = std::make_shared<Forces::Labeller>(labels);
  auto forcesVisualizerNode = std::make_shared<ForcesVisualizerNode>(labeller);
  nodes->addNode(forcesVisualizerNode);

  DefaultSceneCreator sceneCreator(nodes, labels);
  sceneCreator.create();
  auto scene = std::make_shared<Scene>(invokeManager, nodes, labels, labeller);

  auto unsubscribeLabelChanges = labels->subscribe(
      std::bind(&onLabelChangedUpdateLabelNodes, nodes, std::placeholders::_1,
{'fraction_non_alphanumeric': 0.1769112889494296, 'fraction_numerical': 0.010386514558147455, 'mean_word_length': 3.2534395365677047, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 45, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2428130', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1888, 'n_words': 293}