Exemple #1
0
void EventPresenter::handleDrop(const QPointF& pos, const QMimeData& mime)
{
  // We don't want to create a new state in BaseScenario
  auto scenar = dynamic_cast<Scenario::ProcessModel*>(m_model.parent());
  // todo Maybe the drop should be handled by the scenario presenter ?? or not

  // If the mime data has states in it we can handle it.
  if (scenar && mime.formats().contains(score::mime::messagelist()))
  {
    Mime<State::MessageList>::Deserializer des{mime};
    State::MessageList ml = des.deserialize();

    RedoMacroCommandDispatcher<Command::AddStateWithData> dispatcher{
        score::IDocument::documentContext(m_model).commandStack};

    auto cmd = new Command::CreateState{
        *scenar,
        m_model.id(),
        pos.y() / m_view->parentItem()->boundingRect().size().height()};
    dispatcher.submit(cmd);
    dispatcher.submit(new Command::AddMessagesToState{
        scenar->states.at(cmd->createdState()), std::move(ml)});

    dispatcher.commit();
  }
}
void CreationState::createToEvent_base(const Id<StateModel> & originalState)
{
    // make sure the hovered corresponding timenode dont have a date prior to original state date
    if(getDate(m_parentSM.model(), originalState) < getDate(m_parentSM.model(), hoveredEvent) )
        {
        auto cmd = new CreateConstraint_State{
                Path<ScenarioModel>{m_scenarioPath},
                originalState,
                hoveredEvent,
                currentPoint.y};

        m_dispatcher.submitCommand(cmd);

        createdConstraints.append(cmd->createdConstraint());
        createdStates.append(cmd->createdState());
    }//else do nothing
}
Exemple #3
0
Box CreateBox(RecordContext& context)
{
  // Get the clicked point in scenario and create a state + interval + state
  // there
  // Create an automation + a rack + a slot + process views for all
  // automations.
  auto default_end_date = context.point.date;
  auto cmd_start = new Scenario::Command::CreateTimeSync_Event_State{
      context.scenario, default_end_date, context.point.y};
  cmd_start->redo(context.context);
  context.dispatcher.submit(cmd_start);

  // TODO what happens if we go past the end of our scenario ? Stop recording
  // ??
  auto cmd_end = new Scenario::Command::CreateInterval_State_Event_TimeSync{
      context.scenario,
      cmd_start->createdState(),
      default_end_date,
      context.point.y};
  cmd_end->redo(context.context);
  context.dispatcher.submit(cmd_end);

  auto& cstr = context.scenario.intervals.at(cmd_end->createdInterval());

  auto cmd_move = new Scenario::Command::MoveNewEvent(
      context.scenario,
      cstr.id(),
      cmd_end->createdEvent(),
      default_end_date,
      0,
      true,
      ExpandMode::CannotExpand);
  context.dispatcher.submit(cmd_move);

  auto cmd_slot = new Scenario::Command::AddSlotToRack{cstr};
  cmd_slot->redo(context.context);
  context.dispatcher.submit(cmd_slot);

  auto cmd_showrack = new Scenario::Command::ShowRack{cstr};
  cmd_showrack->redo(context.context);
  context.dispatcher.submit(cmd_showrack);

  return {cstr, *cmd_move, cmd_end->createdEvent()};
}