Skip to content

Commit

Permalink
[state] Update gui when dropping a state process
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Feb 25, 2024
1 parent 05703ad commit ad79616
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,40 +112,65 @@ bool DropProcessOnState::drop(
const StateModel& st, const ProcessModel& scenar, const QMimeData& mime,
const score::DocumentContext& ctx)
{

const auto& handlers = ctx.app.interfaces<Process::ProcessDropHandlerList>();
const auto& factories = ctx.app.interfaces<Process::ProcessFactoryList>();

if(auto res = handlers.getDrop(mime, ctx); !res.empty())
{
auto t = handlers.getMaxDuration(res).value_or(TimeVal::fromMsecs(10000.));

DropProcessOnStateHelper dropper(st, scenar, ctx, t);

score::Dispatcher_T disp{dropper.macro()};
for(const auto& proc : res)
bool in_state = true;
if(res.size() != 1)
in_state = false;
if(!(qApp->keyboardModifiers() & Qt::ShiftModifier))
in_state = false;
auto proc_factory = factories.get(res[0].creation.key);
if(!(proc_factory->flags() & Process::ProcessFlags::SupportsState))
in_state = false;

if(in_state)
{
Process::ProcessModel* p = dropper.addProcess(
[&](Scenario::Command::Macro& m,
const IntervalModel& itv) -> Process::ProcessModel* {
return m.createProcessInNewSlot(itv, proc.creation);
},
proc.duration ? *proc.duration : t);
if(p && proc.setup)
// Create the process in the state if possible
Scenario::Command::Macro m{new Command::DropProcessInStateMacro, ctx};
score::Dispatcher_T disp{m};
for(const auto& proc : res)
{
proc.setup(*p, disp);
auto p = m.createProcess(st, proc.creation.key, proc.creation.customData);
if(p && proc.setup)
proc.setup(*p, disp);
}
m.commit();
}

if(res.size() == 1)
else
{
const auto& name = res.front().creation.prettyName;
auto& itv = dropper.interval();
if(!name.isEmpty())
auto t = handlers.getMaxDuration(res).value_or(TimeVal::fromMsecs(10000.));

DropProcessOnStateHelper dropper(st, scenar, ctx, t);

score::Dispatcher_T disp{dropper.macro()};
for(const auto& proc : res)
{
Process::ProcessModel* p = dropper.addProcess(
[&](Scenario::Command::Macro& m,
const IntervalModel& itv) -> Process::ProcessModel* {
return m.createProcessInNewSlot(itv, proc.creation);
},
proc.duration ? *proc.duration : t);
if(p && proc.setup)
{
proc.setup(*p, disp);
}
}

if(res.size() == 1)
{
dropper.macro().submit(new Scenario::Command::ChangeElementName{itv, name});
const auto& name = res.front().creation.prettyName;
auto& itv = dropper.interval();
if(!name.isEmpty())
{
dropper.macro().submit(new Scenario::Command::ChangeElementName{itv, name});
}
}
dropper.commit();
}
dropper.commit();
return true;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,12 @@ class SCORE_PLUGIN_SCENARIO_EXPORT DropProcessInIntervalMacro final
SCORE_COMMAND_DECL(
CommandFactoryName(), DropProcessInIntervalMacro, "Drop a process in an interval")
};

class SCORE_PLUGIN_SCENARIO_EXPORT DropProcessInStateMacro final
: public score::AggregateCommand
{
SCORE_COMMAND_DECL(
CommandFactoryName(), DropProcessInStateMacro, "Drop a process in a state")
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ void TemporalIntervalPresenter::on_defaultDurationChanged(const TimeVal& val)
on_layerModelPutToFront(i, slot.layers.front().model());
}
},
[this, w, slot_height](const NodalSlotPresenter& slot) {
[w, slot_height](const NodalSlotPresenter& slot) {
slot.view->setRect({0, 0, w, slot_height});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ StatePresenter::StatePresenter(
});
connect(m_view, &StateView::dropReceived, this, &StatePresenter::handleDrop);

model.stateProcesses.added.connect<&StatePresenter::on_processAdded>(this);
model.stateProcesses.removed.connect<&StatePresenter::on_processRemoved>(this);
updateStateView();
}

Expand Down Expand Up @@ -206,6 +208,15 @@ void StatePresenter::handleDrop(const QMimeData& mime)
}
}

void StatePresenter::on_processAdded(const Process::ProcessModel&)
{
updateStateView();
}
void StatePresenter::on_processRemoved(const Process::ProcessModel&)
{
updateStateView();
}

void StatePresenter::updateStateView()
{
m_view->setContainMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@

#include <verdigris>

namespace Process
{
class ProcessModel;
}
namespace Scenario
{
class StateModel;
class SCORE_PLUGIN_SCENARIO_EXPORT StatePresenter final : public QObject
class SCORE_PLUGIN_SCENARIO_EXPORT StatePresenter final
: public QObject
, public Nano::Observer
{
W_OBJECT(StatePresenter)

Expand All @@ -33,6 +39,8 @@ class SCORE_PLUGIN_SCENARIO_EXPORT StatePresenter final : public QObject
bool isSelected() const;

void handleDrop(const QMimeData& mime);
void on_processAdded(const Process::ProcessModel&);
void on_processRemoved(const Process::ProcessModel&);

public:
void pressed(const QPointF& arg_1)
Expand Down

0 comments on commit ad79616

Please sign in to comment.