[ScenarioComponents] more considerations on Nano vd Qt for signal handling
This commit is contained in:
parent
aa25f22053
commit
7468c290b6
11 changed files with 121 additions and 78 deletions
2
Hardware/3rdparty/bugui
vendored
2
Hardware/3rdparty/bugui
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 9e937d4c88c835428ec30373f8a866854555b3ee
|
Subproject commit cdb5364672da1c0669c68020d7e5df418093c421
|
|
@ -13,8 +13,6 @@ struct EventWidget final : Nano::Observer
|
||||||
ScenarioWidget* scenario,
|
ScenarioWidget* scenario,
|
||||||
bugui::container_widget* parent);
|
bugui::container_widget* parent);
|
||||||
|
|
||||||
void paint(bugui::painter& painter) const override;
|
|
||||||
void on_press(int x, int y, bool pressed) override;
|
|
||||||
|
|
||||||
int y() const override;
|
int y() const override;
|
||||||
int height() const override;
|
int height() const override;
|
||||||
|
@ -24,6 +22,9 @@ struct EventWidget final : Nano::Observer
|
||||||
protected:
|
protected:
|
||||||
bool contains(int px, int py) const override;
|
bool contains(int px, int py) const override;
|
||||||
|
|
||||||
|
void paint(bugui::painter& painter) const override;
|
||||||
|
|
||||||
|
void on_press(int x, int y, bool pressed) override;
|
||||||
void on_state_added(Scenario::StateModel& state);
|
void on_state_added(Scenario::StateModel& state);
|
||||||
void on_state_removed(const Scenario::StateModel& state);
|
void on_state_removed(const Scenario::StateModel& state);
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,28 @@ IntervalWidget::IntervalWidget(Scenario::IntervalModel& interval,
|
||||||
ScenarioWidget* scenario,
|
ScenarioWidget* scenario,
|
||||||
bugui::container_widget* parent)
|
bugui::container_widget* parent)
|
||||||
: ScenarioComponentSpec<Scenario::IntervalModel>{interval, scenario, parent}
|
: ScenarioComponentSpec<Scenario::IntervalModel>{interval, scenario, parent}
|
||||||
{ }
|
{
|
||||||
|
connect(&model,
|
||||||
|
&Scenario::IntervalModel::heightPercentageChanged,
|
||||||
|
this,
|
||||||
|
[scenario] (double) { scenario->update(); });
|
||||||
|
|
||||||
|
connect(&model,
|
||||||
|
&Scenario::IntervalModel::dateChanged,
|
||||||
|
this,
|
||||||
|
[scenario] (const TimeVal&) { scenario->update(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
IntervalWidget::~IntervalWidget()
|
||||||
|
{
|
||||||
|
disconnect(&model,
|
||||||
|
&Scenario::IntervalModel::heightPercentageChanged,
|
||||||
|
this, 0);
|
||||||
|
|
||||||
|
disconnect(&model,
|
||||||
|
&Scenario::IntervalModel::dateChanged,
|
||||||
|
this, 0);
|
||||||
|
}
|
||||||
|
|
||||||
int IntervalWidget::x() const
|
int IntervalWidget::x() const
|
||||||
{
|
{
|
||||||
|
@ -62,3 +83,6 @@ void IntervalWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace hardware
|
} // namespace hardware
|
||||||
|
|
||||||
|
#include <wobjectimpl.h>
|
||||||
|
W_OBJECT_IMPL(Hardware::IntervalWidget);
|
||||||
|
|
|
@ -8,22 +8,28 @@
|
||||||
namespace Hardware
|
namespace Hardware
|
||||||
{
|
{
|
||||||
struct IntervalWidget final : ScenarioComponentSpec<Scenario::IntervalModel>
|
struct IntervalWidget final : ScenarioComponentSpec<Scenario::IntervalModel>
|
||||||
|
, QObject
|
||||||
{
|
{
|
||||||
explicit IntervalWidget(Scenario::IntervalModel& interval,
|
explicit IntervalWidget(Scenario::IntervalModel& interval,
|
||||||
ScenarioWidget* scenario,
|
ScenarioWidget* scenario,
|
||||||
bugui::container_widget* parent);
|
bugui::container_widget* parent);
|
||||||
|
|
||||||
void paint(bugui::painter& painter) const override;
|
~IntervalWidget() override;
|
||||||
void on_press(int x, int y, bool pressed) override;
|
|
||||||
void on_double_press(int x, int y) override;
|
|
||||||
void on_drag(int from_x, int from_y, int to_x, int to_y) override;
|
|
||||||
|
|
||||||
int x() const override;
|
int x() const override;
|
||||||
int y() const override;
|
int y() const override;
|
||||||
int width() const override;
|
int width() const override;
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
|
W_OBJECT(IntervalWidget)
|
||||||
|
|
||||||
bool contains(int px, int py) const override;
|
bool contains(int px, int py) const override;
|
||||||
|
|
||||||
|
void paint(bugui::painter& painter) const override;
|
||||||
|
|
||||||
|
void on_press(int x, int y, bool pressed) override;
|
||||||
|
void on_double_press(int x, int y) override;
|
||||||
|
void on_drag(int from_x, int from_y, int to_x, int to_y) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Hardware
|
} // namespace Hardware
|
||||||
|
|
|
@ -23,6 +23,10 @@ struct ScenarioComponent : T
|
||||||
virtual bool this_model(const Scenario::TimeSyncModel&) const { return false; };
|
virtual bool this_model(const Scenario::TimeSyncModel&) const { return false; };
|
||||||
virtual bool this_model(const Scenario::EventModel&) const { return false; };
|
virtual bool this_model(const Scenario::EventModel&) const { return false; };
|
||||||
virtual bool this_model(const Scenario::StateModel&) const { return false; };
|
virtual bool this_model(const Scenario::StateModel&) const { return false; };
|
||||||
|
virtual bool this_model(const Id<Scenario::IntervalModel>&) const { return false; };
|
||||||
|
virtual bool this_model(const Id<Scenario::TimeSyncModel>&) const { return false; };
|
||||||
|
virtual bool this_model(const Id<Scenario::EventModel>&) const { return false; };
|
||||||
|
virtual bool this_model(const Id<Scenario::StateModel>&) const { return false; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit ScenarioComponent(ScenarioWidget* s,
|
explicit ScenarioComponent(ScenarioWidget* s,
|
||||||
|
@ -44,6 +48,7 @@ template <typename T, typename Base = bugui::base_widget>
|
||||||
struct ScenarioComponentSpec : ScenarioComponent<Base>
|
struct ScenarioComponentSpec : ScenarioComponent<Base>
|
||||||
{
|
{
|
||||||
bool this_model(const T& m) const override { return m.id() == model.id(); };
|
bool this_model(const T& m) const override { return m.id() == model.id(); };
|
||||||
|
bool this_model(const Id<T>& m) const override { return m == model.id(); };
|
||||||
const T& get_model() const { return model; }
|
const T& get_model() const { return model; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -13,11 +13,6 @@ ScenarioWidget::ScenarioWidget(Scenario::ProcessModel* scenario,
|
||||||
model->intervals.mutable_added.connect<&ScenarioWidget::on_interval_added>(this);
|
model->intervals.mutable_added.connect<&ScenarioWidget::on_interval_added>(this);
|
||||||
model->intervals.removed.connect<&ScenarioWidget::on_interval_removed>(this);
|
model->intervals.removed.connect<&ScenarioWidget::on_interval_removed>(this);
|
||||||
|
|
||||||
connect(model,
|
|
||||||
&Scenario::ProcessModel::intervalMoved,
|
|
||||||
this,
|
|
||||||
&ScenarioWidget::on_interval_changed);
|
|
||||||
|
|
||||||
for(Scenario::IntervalModel& i : model->intervals)
|
for(Scenario::IntervalModel& i : model->intervals)
|
||||||
add_widget<IntervalWidget>(i, this);
|
add_widget<IntervalWidget>(i, this);
|
||||||
|
|
||||||
|
@ -28,14 +23,6 @@ ScenarioWidget::ScenarioWidget(Scenario::ProcessModel* scenario,
|
||||||
add_widget<TimeSyncWidget>(t, this);
|
add_widget<TimeSyncWidget>(t, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScenarioWidget::~ScenarioWidget()
|
|
||||||
{
|
|
||||||
disconnect(model,
|
|
||||||
&Scenario::ProcessModel::intervalMoved,
|
|
||||||
this,
|
|
||||||
&ScenarioWidget::on_interval_changed);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ScenarioWidget::x() const
|
int ScenarioWidget::x() const
|
||||||
{
|
{
|
||||||
return bugui::base_widget::parent->x();
|
return bugui::base_widget::parent->x();
|
||||||
|
@ -76,11 +63,6 @@ void ScenarioWidget::on_interval_removed(const Scenario::IntervalModel& interval
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScenarioWidget::on_interval_changed(const Scenario::IntervalModel*)
|
|
||||||
{
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScenarioWidget::on_time_sync_added(Scenario::TimeSyncModel& timeSync)
|
void ScenarioWidget::on_time_sync_added(Scenario::TimeSyncModel& timeSync)
|
||||||
{
|
{
|
||||||
add_widget<TimeSyncWidget>(timeSync, this);
|
add_widget<TimeSyncWidget>(timeSync, this);
|
||||||
|
@ -94,6 +76,3 @@ void ScenarioWidget::on_time_sync_removed(const Scenario::TimeSyncModel& timeSyn
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Hardware
|
} // namespace Hardware
|
||||||
|
|
||||||
#include "wobjectimpl.h"
|
|
||||||
W_OBJECT_IMPL(Hardware::ScenarioWidget)
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <wobjectdefs.h>
|
|
||||||
|
|
||||||
#include <Scenario/Process/ScenarioModel.hpp>
|
#include <Scenario/Process/ScenarioModel.hpp>
|
||||||
|
|
||||||
#include <widgets/container_widget.hpp>
|
#include <widgets/container_widget.hpp>
|
||||||
|
@ -11,16 +9,11 @@ namespace Hardware
|
||||||
class ScenarioWidget final
|
class ScenarioWidget final
|
||||||
: public bugui::container_widget
|
: public bugui::container_widget
|
||||||
, public Nano::Observer
|
, public Nano::Observer
|
||||||
, public QObject
|
|
||||||
{
|
{
|
||||||
W_OBJECT(ScenarioWidget)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ScenarioWidget(Scenario::ProcessModel* scenario,
|
explicit ScenarioWidget(Scenario::ProcessModel* scenario,
|
||||||
bugui::container_widget* parent);
|
bugui::container_widget* parent);
|
||||||
|
|
||||||
~ScenarioWidget() override;
|
|
||||||
|
|
||||||
int x() const override;
|
int x() const override;
|
||||||
int y() const override;
|
int y() const override;
|
||||||
int width() const override;
|
int width() const override;
|
||||||
|
@ -31,7 +24,6 @@ public:
|
||||||
private:
|
private:
|
||||||
void on_interval_added(Scenario::IntervalModel& interval);
|
void on_interval_added(Scenario::IntervalModel& interval);
|
||||||
void on_interval_removed(const Scenario::IntervalModel& interval);
|
void on_interval_removed(const Scenario::IntervalModel& interval);
|
||||||
void on_interval_changed(const Scenario::IntervalModel*);
|
|
||||||
|
|
||||||
void on_time_sync_added(Scenario::TimeSyncModel& timeSync);
|
void on_time_sync_added(Scenario::TimeSyncModel& timeSync);
|
||||||
void on_time_sync_removed(const Scenario::TimeSyncModel& timeSync);
|
void on_time_sync_removed(const Scenario::TimeSyncModel& timeSync);
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#include <Scenario/Document/State/StateModel.hpp>
|
#include <Scenario/Document/State/StateModel.hpp>
|
||||||
|
|
||||||
|
#include "ScenarioWidget.hpp"
|
||||||
|
#include "EventWidget.hpp"
|
||||||
#include "StateWidget.hpp"
|
#include "StateWidget.hpp"
|
||||||
#include "Hardware/Widgets/ScenarioWidget.hpp"
|
|
||||||
|
|
||||||
namespace Hardware
|
namespace Hardware
|
||||||
{
|
{
|
||||||
|
@ -9,7 +10,19 @@ StateWidget::StateWidget(Scenario::StateModel& state,
|
||||||
ScenarioWidget* scenario,
|
ScenarioWidget* scenario,
|
||||||
bugui::container_widget* parent)
|
bugui::container_widget* parent)
|
||||||
: ScenarioComponentSpec<Scenario::StateModel>{state, scenario, parent}
|
: ScenarioComponentSpec<Scenario::StateModel>{state, scenario, parent}
|
||||||
{ }
|
{
|
||||||
|
connect(&model,
|
||||||
|
&Scenario::StateModel::heightPercentageChanged,
|
||||||
|
this,
|
||||||
|
[parent] { static_cast<EventWidget*>(parent)->set_y_height(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
StateWidget::~StateWidget()
|
||||||
|
{
|
||||||
|
disconnect(&model,
|
||||||
|
&Scenario::StateModel::heightPercentageChanged,
|
||||||
|
this, 0);
|
||||||
|
}
|
||||||
|
|
||||||
int StateWidget::y() const
|
int StateWidget::y() const
|
||||||
{
|
{
|
||||||
|
@ -44,8 +57,11 @@ void StateWidget::on_double_press(int x, int y)
|
||||||
|
|
||||||
void StateWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
|
void StateWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
|
||||||
{
|
{
|
||||||
if (from_y != to_y)
|
double increment{to_y / static_cast<double>(scenario->height())};
|
||||||
model.setHeightPercentage(to_y / static_cast<double>(parent->height()));
|
model.setHeightPercentage(model.heightPercentage() + increment);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace Hardware
|
||||||
|
|
||||||
|
#include <wobjectimpl.h>
|
||||||
|
W_OBJECT_IMPL(Hardware::StateWidget)
|
||||||
|
|
|
@ -5,21 +5,26 @@
|
||||||
|
|
||||||
namespace Hardware
|
namespace Hardware
|
||||||
{
|
{
|
||||||
struct StateWidget final : ScenarioComponentSpec<Scenario::StateModel>
|
struct StateWidget final : QObject
|
||||||
|
, ScenarioComponentSpec<Scenario::StateModel>
|
||||||
{
|
{
|
||||||
explicit StateWidget(Scenario::StateModel& state,
|
explicit StateWidget(Scenario::StateModel& state,
|
||||||
ScenarioWidget* scenario,
|
ScenarioWidget* scenario,
|
||||||
bugui::container_widget* parent);
|
bugui::container_widget* parent);
|
||||||
|
|
||||||
|
~StateWidget() override;
|
||||||
|
|
||||||
|
int y() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
W_OBJECT(StateWidget)
|
||||||
|
|
||||||
|
bool contains(int px, int py) const override;
|
||||||
|
|
||||||
void paint(bugui::painter& painter) const override;
|
void paint(bugui::painter& painter) const override;
|
||||||
void on_press(int x, int y, bool pressed) override;
|
void on_press(int x, int y, bool pressed) override;
|
||||||
void on_double_press(int x, int y) override;
|
void on_double_press(int x, int y) override;
|
||||||
void on_drag(int from_x, int from_y, int to_x, int to_y) override;
|
void on_drag(int from_x, int from_y, int to_x, int to_y) override;
|
||||||
|
|
||||||
int y() const override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool contains(int px, int py) const override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace Hardware
|
} //namespace Hardware
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include <Scenario/Document/TimeSync/TimeSyncModel.hpp>
|
#include <Scenario/Document/TimeSync/TimeSyncModel.hpp>
|
||||||
|
|
||||||
#include "Hardware/Widgets/EventWidget.hpp"
|
#include "EventWidget.hpp"
|
||||||
#include "ScenarioWidget.hpp"
|
#include "ScenarioWidget.hpp"
|
||||||
#include "TimeSyncWidget.hpp"
|
#include "TimeSyncWidget.hpp"
|
||||||
|
|
||||||
|
@ -12,14 +12,41 @@ TimeSyncWidget::TimeSyncWidget(Scenario::TimeSyncModel& timeSync,
|
||||||
: ScenarioComponentSpec<Scenario::TimeSyncModel,
|
: ScenarioComponentSpec<Scenario::TimeSyncModel,
|
||||||
bugui::container_widget>{timeSync, scenario, parent}
|
bugui::container_widget>{timeSync, scenario, parent}
|
||||||
{
|
{
|
||||||
Scenario::ProcessModel* scen{scenario->get_model()};
|
connect(&model,
|
||||||
|
&Scenario::TimeSyncModel::dateChanged,
|
||||||
|
this,
|
||||||
|
[scenario] (const TimeVal&) { scenario->update(); });
|
||||||
|
|
||||||
scen->events.mutable_added.connect<&TimeSyncWidget::on_event_added>(this);
|
connect(&model,
|
||||||
scen->events.removed.connect<&TimeSyncWidget::on_event_removed>(this);
|
&Scenario::TimeSyncModel::newEvent,
|
||||||
|
this,
|
||||||
|
[scenario, this] (const Id<Scenario::EventModel>& eventId)
|
||||||
|
{ add_widget<EventWidget>(scenario->get_model()->events.at(eventId), scenario); });
|
||||||
|
|
||||||
for(Scenario::EventModel& e : scen->events)
|
connect(&model,
|
||||||
if (e.timeSync() == model.id())
|
&Scenario::TimeSyncModel::eventRemoved,
|
||||||
add_widget<EventWidget>(e, scenario);
|
this,
|
||||||
|
[scenario, this] (const Id<Scenario::EventModel>& eventId)
|
||||||
|
{
|
||||||
|
remove_widget([&eventId]
|
||||||
|
(const auto& w)
|
||||||
|
{ return static_cast<ScenarioComponent<>*>(w.get())->this_model(eventId); });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TimeSyncWidget::~TimeSyncWidget()
|
||||||
|
{
|
||||||
|
disconnect(&model,
|
||||||
|
&Scenario::TimeSyncModel::dateChanged,
|
||||||
|
this, 0);
|
||||||
|
|
||||||
|
disconnect(&model,
|
||||||
|
&Scenario::TimeSyncModel::newEvent,
|
||||||
|
this, 0);
|
||||||
|
|
||||||
|
disconnect(&model,
|
||||||
|
&Scenario::TimeSyncModel::eventRemoved,
|
||||||
|
this, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TimeSyncWidget::x() const
|
int TimeSyncWidget::x() const
|
||||||
|
@ -42,7 +69,7 @@ void TimeSyncWidget::set_y_height()
|
||||||
m_y = std::numeric_limits<int>::max();
|
m_y = std::numeric_limits<int>::max();
|
||||||
m_height = std::numeric_limits<int>::lowest();
|
m_height = std::numeric_limits<int>::lowest();
|
||||||
|
|
||||||
for(const auto& e : children)
|
for(const auto& e : bugui::container_widget::children)
|
||||||
{
|
{
|
||||||
int ey = e->y();
|
int ey = e->y();
|
||||||
if (ey <= m_y) m_y = ey;
|
if (ey <= m_y) m_y = ey;
|
||||||
|
@ -70,25 +97,12 @@ bool TimeSyncWidget::contains(int px, int py) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeSyncWidget::on_event_added(Scenario::EventModel& event)
|
|
||||||
{
|
|
||||||
if (event.timeSync() != model.id()) return;
|
|
||||||
|
|
||||||
add_widget<EventWidget>(event, scenario);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TimeSyncWidget::on_event_removed(const Scenario::EventModel& event)
|
|
||||||
{
|
|
||||||
if (event.timeSync() != model.id()) return;
|
|
||||||
|
|
||||||
remove_widget([&event]
|
|
||||||
(const auto& w)
|
|
||||||
{ return static_cast<ScenarioComponent<>*>(w.get())->this_model(event); });
|
|
||||||
}
|
|
||||||
|
|
||||||
void TimeSyncWidget::on_press(int x, int y, bool pressed)
|
void TimeSyncWidget::on_press(int x, int y, bool pressed)
|
||||||
{
|
{
|
||||||
qDebug() << "is inside!";
|
qDebug() << "is inside!";
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Hardware
|
} // namespace Hardware
|
||||||
|
|
||||||
|
#include <wobjectimpl.h>
|
||||||
|
W_OBJECT_IMPL(Hardware::TimeSyncWidget);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
namespace Hardware
|
namespace Hardware
|
||||||
{
|
{
|
||||||
struct TimeSyncWidget final : Nano::Observer
|
struct TimeSyncWidget final : QObject
|
||||||
, ScenarioComponentSpec<Scenario::TimeSyncModel,
|
, ScenarioComponentSpec<Scenario::TimeSyncModel,
|
||||||
bugui::container_widget>
|
bugui::container_widget>
|
||||||
{
|
{
|
||||||
|
@ -14,8 +14,7 @@ struct TimeSyncWidget final : Nano::Observer
|
||||||
ScenarioWidget* scenario,
|
ScenarioWidget* scenario,
|
||||||
bugui::container_widget* parent);
|
bugui::container_widget* parent);
|
||||||
|
|
||||||
void paint(bugui::painter& painter) const override;
|
~TimeSyncWidget() override;
|
||||||
void on_press(int x, int y, bool pressed) override;
|
|
||||||
|
|
||||||
int x() const override;
|
int x() const override;
|
||||||
int y() const override;
|
int y() const override;
|
||||||
|
@ -24,10 +23,12 @@ struct TimeSyncWidget final : Nano::Observer
|
||||||
void set_y_height();
|
void set_y_height();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
W_OBJECT(TimeSyncWidget)
|
||||||
|
|
||||||
bool contains(int px, int py) const override;
|
bool contains(int px, int py) const override;
|
||||||
|
|
||||||
void on_event_added(Scenario::EventModel& event);
|
void paint(bugui::painter& painter) const override;
|
||||||
void on_event_removed(const Scenario::EventModel& event);
|
void on_press(int x, int y, bool pressed) override;
|
||||||
|
|
||||||
int m_y;
|
int m_y;
|
||||||
int m_height;
|
int m_height;
|
||||||
|
|
Loading…
Add table
Reference in a new issue