summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2024-07-16 17:31:57 +0200
committerFelix Morgner <felix.morgner@gmail.com>2024-07-16 20:10:59 +0200
commit474f1302eaf868e2b311d6561a69cae8f736a7c1 (patch)
tree175a359a653c9ed96835e41e055f5ac011c7ce33 /app/src
parent2fd48d4ee446cb84f38605371eb9a05c70dde590 (diff)
downloadturns-474f1302eaf868e2b311d6561a69cae8f736a7c1.tar.xz
turns-474f1302eaf868e2b311d6561a69cae8f736a7c1.zip
app: move turn order management logic to turn_order
Diffstat (limited to 'app/src')
-rw-r--r--app/src/widgets/participant_row.cpp1
-rw-r--r--app/src/widgets/turn_order_view.cpp44
-rw-r--r--app/src/windows/tracker.cpp20
3 files changed, 14 insertions, 51 deletions
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 <glibmm/i18n.h>
#include <glibmm/ustring.h>
#include <glibmm/variant.h>
+#include <gtkmm/stringlist.h>
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<turn_order_view, Gtk::ScrolledWindow>{TEMPLATE}
, m_model{domain::turn_order::create()}
, m_view{get_widget<Gtk::ListBox>("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<domain::participant>
- {
- 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<bool>
+ auto turn_order_view::get_model() const noexcept -> Glib::RefPtr<domain::turn_order>
{
- return m_is_empty.get_proxy();
+ return m_model;
}
auto turn_order_view::handle_create_row(Glib::RefPtr<Glib::Object> 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<Glib::Variant<int>>(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<void>(param);
auto index = Glib::VariantBase::cast_dynamic<Glib::Variant<int>>(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);
}