From 474f1302eaf868e2b311d6561a69cae8f736a7c1 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 16 Jul 2024 17:31:57 +0200 Subject: app: move turn order management logic to turn_order --- app/include/turns/app/widgets/turn_order_view.hpp | 11 +----- app/src/widgets/participant_row.cpp | 1 + app/src/widgets/turn_order_view.cpp | 44 ++--------------------- app/src/windows/tracker.cpp | 20 +++++------ 4 files changed, 15 insertions(+), 61 deletions(-) (limited to 'app') diff --git a/app/include/turns/app/widgets/turn_order_view.hpp b/app/include/turns/app/widgets/turn_order_view.hpp index 07d1712..0122f4a 100644 --- a/app/include/turns/app/widgets/turn_order_view.hpp +++ b/app/include/turns/app/widgets/turn_order_view.hpp @@ -26,22 +26,13 @@ namespace turns::app::widgets turn_order_view(); - auto append(Glib::ustring name, float priority, domain::disposition disposition) -> void; - auto clear() -> void; - auto get(std::size_t index) -> Glib::RefPtr; - auto start() -> void; - auto remove(std::size_t index) -> void; - - auto get_is_empty() const noexcept -> bool; - auto property_is_empty() const -> Glib::PropertyProxy_ReadOnly; + auto get_model() const noexcept -> Glib::RefPtr; private: auto handle_create_row(Glib::RefPtr const item) -> Gtk::Widget *; Glib::RefPtr m_model; Gtk::ListBox * m_view; - - Glib::Property m_is_empty; }; } // namespace turns::app::widgets diff --git a/app/src/widgets/participant_row.cpp b/app/src/widgets/participant_row.cpp index 269aa15..54ad20e 100644 --- a/app/src/widgets/participant_row.cpp +++ b/app/src/widgets/participant_row.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace turns::app::widgets { diff --git a/app/src/widgets/turn_order_view.cpp b/app/src/widgets/turn_order_view.cpp index d5520ca..700dfd3 100644 --- a/app/src/widgets/turn_order_view.cpp +++ b/app/src/widgets/turn_order_view.cpp @@ -21,51 +21,13 @@ namespace turns::app::widgets , template_widget{TEMPLATE} , m_model{domain::turn_order::create()} , m_view{get_widget("view")} - , m_is_empty{*this, "is_empty", true} { - m_view->bind_model(m_model, sigc::mem_fun(*this, &turn_order_view::handle_create_row)); - - // clang-format off - Glib::Binding::bind_property(m_model->property_n_items(), - m_is_empty.get_proxy(), - Glib::Binding::Flags::DEFAULT, - [](auto n) { return n == 0; }); - // clang-format on - } - - auto turn_order_view::append(Glib::ustring name, float priority, domain::disposition disposition) -> void - { - auto participant = domain::participant::create(name, priority, disposition); - m_model->append(participant); - } - - auto turn_order_view::clear() -> void - { - m_model->remove_all(); - } - - auto turn_order_view::get(std::size_t index) -> Glib::RefPtr - { - return m_model->get_item(index); - } - - auto turn_order_view::start() -> void - { - } - - auto turn_order_view::remove(std::size_t index) -> void - { - m_model->remove(index); - } - - auto turn_order_view::get_is_empty() const noexcept -> bool - { - return m_is_empty; + m_view->bind_model(m_model->list_model(), sigc::mem_fun(*this, &turn_order_view::handle_create_row)); } - auto turn_order_view::property_is_empty() const -> Glib::PropertyProxy_ReadOnly + auto turn_order_view::get_model() const noexcept -> Glib::RefPtr { - return m_is_empty.get_proxy(); + return m_model; } auto turn_order_view::handle_create_row(Glib::RefPtr const item) -> Gtk::Widget * diff --git a/app/src/windows/tracker.cpp b/app/src/windows/tracker.cpp index 3c39a2f..639cf8a 100644 --- a/app/src/windows/tracker.cpp +++ b/app/src/windows/tracker.cpp @@ -36,31 +36,31 @@ namespace turns::app::windows { m_stack->add(*m_turn_order); - auto clear_action = add_action("clear", sigc::mem_fun(*m_turn_order, &widgets::turn_order_view::clear)); + auto clear_action = add_action("clear", sigc::mem_fun(*m_turn_order->get_model(), &domain::turn_order::remove_all)); add_action("add_participant", sigc::mem_fun(*this, &tracker::handle_add_participant)); add_action_with_parameter("delete", Glib::VARIANT_TYPE_INT32, sigc::mem_fun(*this, &tracker::handle_delete_participant)); add_action_with_parameter("edit", Glib::VARIANT_TYPE_INT32, sigc::mem_fun(*this, &tracker::handle_edit_participant)); - auto start_action = add_action("start", sigc::mem_fun(*m_turn_order, &widgets::turn_order_view::start)); + auto start_action = add_action("start", sigc::mem_fun(*m_turn_order->get_model(), &domain::turn_order::start)); - Glib::Binding::bind_property(m_turn_order->property_is_empty(), + Glib::Binding::bind_property(m_turn_order->get_model()->property_empty(), clear_action->property_enabled(), Glib::Binding::Flags::SYNC_CREATE | Glib::Binding::Flags::INVERT_BOOLEAN); - Glib::Binding::bind_property(m_turn_order->property_is_empty(), + Glib::Binding::bind_property(m_turn_order->get_model()->property_empty(), m_controls->property_reveal_child(), Glib::Binding::Flags::SYNC_CREATE | Glib::Binding::Flags::INVERT_BOOLEAN); - Glib::Binding::bind_property(m_turn_order->property_is_empty(), + Glib::Binding::bind_property(m_turn_order->get_model()->property_empty(), m_stack->property_visible_child(), Glib::Binding::Flags::SYNC_CREATE, [this](auto empty) { return empty ? m_empty : m_turn_order; }); - Glib::Binding::bind_property(m_turn_order->property_is_empty(), + Glib::Binding::bind_property(m_turn_order->get_model()->property_empty(), start_action->property_enabled(), Glib::Binding::Flags::SYNC_CREATE | Glib::Binding::Flags::INVERT_BOOLEAN); // clang-format off - Glib::Binding::bind_property(m_turn_order->property_is_empty(), + Glib::Binding::bind_property(m_turn_order->get_model()->property_empty(), m_subtitle, Glib::Binding::Flags::SYNC_CREATE, [](auto empty) { @@ -73,20 +73,20 @@ namespace turns::app::windows { auto [lifeline, dialog] = editor_for(nullptr); dialog->present(this); - dialog->signal_finished().connect(sigc::mem_fun(*m_turn_order, &widgets::turn_order_view::append)); + dialog->signal_finished().connect([this](auto n, auto p, auto d) { m_turn_order->get_model()->append(n, p, d); }); } auto tracker::handle_delete_participant(Glib::VariantBase param) -> void { auto index = Glib::VariantBase::cast_dynamic>(param); - m_turn_order->remove(index.get()); + m_turn_order->get_model()->remove(index.get()); } auto tracker::handle_edit_participant(Glib::VariantBase param) -> void { static_cast(param); auto index = Glib::VariantBase::cast_dynamic>(param); - auto participant = m_turn_order->get(index.get()); + auto participant = m_turn_order->get_model()->get_participant(index.get()); auto [lifeline, dialog] = editor_for(participant); dialog->present(this); } -- cgit v1.2.3