Esempio n. 1
0
static void
AddProcessAfterState(StateModel& statemodel, const Process::ProcessModel& proc)
{
  ProcessStateDataInterface* state = proc.startStateData();
  if (!state)
    return;

  auto next_proc_fun = [&](const State::MessageList& ml) {
    auto& messages = statemodel.messages();

    for (const ProcessStateWrapper& prev_proc : statemodel.previousProcesses())
    {
      prev_proc.process().setMessages(ml, messages.rootNode());
    }

    updateTreeWithMessageList(
        messages.rootNode(), ml, proc.id(), ProcessPosition::Following);
    statemodel.sig_statesUpdated();
  };

  statemodel.followingProcesses().emplace_back(state);
  auto& wrapper = statemodel.followingProcesses().back();
  QObject::connect(
      state,
      &ProcessStateDataInterface::messagesChanged,
      &wrapper,
      next_proc_fun);

  next_proc_fun(state->messages());
}
Esempio n. 2
0
InsertContentInState::InsertContentInState(
        const QJsonObject& stateData,
        Path<StateModel>&& targetState):
    m_state{std::move(targetState)}
{
    // TODO ask what should be copied ? the state due to the processes ? the user state ?
    // For now we copy the whole value.
    // First recreate the tree

    // TODO we should update the processes here, and provide an API to do this
    // properly.

    auto& state = m_state.find();

    m_oldNode = state.messages().rootNode();
    m_newNode = m_oldNode;
    updateTreeWithMessageList(
                m_newNode,
                flatten(unmarshall<MessageNode>(stateData["Messages"].toObject()))
            );
}
Esempio n. 3
0
static void AddProcessBeforeState(
    StateModel& statemodel,
    const Process::ProcessModel& proc)
{
  // TODO this should be fused with the notion of State Process.
  ProcessStateDataInterface* state = proc.endStateData();
  if (!state)
    return;

  auto prev_proc_fun = [&](const State::MessageList& ml) {
    // TODO have some collapsing between all the processes of a state
    // NOTE how to prevent these states from being played
    // twice ? mark them ?
    // TODO which one should be sent ? the ones
    // from the process ?
    auto& messages = statemodel.messages();

    for (const ProcessStateWrapper& next_proc :
         statemodel.followingProcesses())
    {
      next_proc.process().setMessages(ml, messages.rootNode());
    }

    updateTreeWithMessageList(
        messages.rootNode(), ml, proc.id(), ProcessPosition::Previous);
    statemodel.sig_statesUpdated();
  };

  statemodel.previousProcesses().emplace_back(state);
  auto& wrapper = statemodel.previousProcesses().back();
  QObject::connect(
      state,
      &ProcessStateDataInterface::messagesChanged,
      &wrapper,
      prev_proc_fun);

  prev_proc_fun(state->messages());
}