mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:07:34 +00:00
LibGUI: Make GTableModel a retainable object.
It became clear that this class needs to support multiple owners.
This commit is contained in:
parent
41c744b3c8
commit
f47945759b
22 changed files with 44 additions and 34 deletions
|
@ -125,7 +125,7 @@ void IRCAppWindow::setup_widgets()
|
|||
m_window_list = new GTableView(horizontal_container);
|
||||
m_window_list->set_headers_visible(false);
|
||||
m_window_list->set_alternating_row_colors(false);
|
||||
m_window_list->set_model(OwnPtr<IRCWindowListModel>(m_client.client_window_list_model()));
|
||||
m_window_list->set_model(m_client.client_window_list_model());
|
||||
m_window_list->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
m_window_list->set_preferred_size({ 100, 0 });
|
||||
m_client.client_window_list_model()->on_activation = [this] (IRCWindow& window) {
|
||||
|
|
|
@ -8,8 +8,8 @@ IRCChannel::IRCChannel(IRCClient& client, const String& name)
|
|||
: m_client(client)
|
||||
, m_name(name)
|
||||
, m_log(IRCLogBuffer::create())
|
||||
, m_member_model(IRCChannelMemberListModel::create(*this))
|
||||
{
|
||||
m_member_model = new IRCChannelMemberListModel(*this);
|
||||
m_window = m_client.aid_create_window(this, IRCWindow::Channel, m_name);
|
||||
m_window->set_log_buffer(*m_log);
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ public:
|
|||
const IRCLogBuffer& log() const { return *m_log; }
|
||||
IRCLogBuffer& log() { return *m_log; }
|
||||
|
||||
IRCChannelMemberListModel* member_model() { return m_member_model; }
|
||||
const IRCChannelMemberListModel* member_model() const { return m_member_model; }
|
||||
IRCChannelMemberListModel* member_model() { return m_member_model.ptr(); }
|
||||
const IRCChannelMemberListModel* member_model() const { return m_member_model.ptr(); }
|
||||
|
||||
int member_count() const { return m_members.size(); }
|
||||
String member_at(int i) { return m_members[i].name; }
|
||||
|
@ -63,6 +63,6 @@ private:
|
|||
bool m_open { false };
|
||||
|
||||
Retained<IRCLogBuffer> m_log;
|
||||
IRCChannelMemberListModel* m_member_model { nullptr };
|
||||
Retained<IRCChannelMemberListModel> m_member_model;
|
||||
IRCWindow* m_window { nullptr };
|
||||
};
|
||||
|
|
|
@ -8,7 +8,7 @@ class IRCChannel;
|
|||
class IRCChannelMemberListModel final : public GTableModel {
|
||||
public:
|
||||
enum Column { Name };
|
||||
explicit IRCChannelMemberListModel(IRCChannel&);
|
||||
static Retained<IRCChannelMemberListModel> create(IRCChannel& channel) { return adopt(*new IRCChannelMemberListModel(channel)); }
|
||||
virtual ~IRCChannelMemberListModel() override;
|
||||
|
||||
virtual int row_count() const override;
|
||||
|
@ -22,5 +22,7 @@ public:
|
|||
Function<void(const String&)> on_activation;
|
||||
|
||||
private:
|
||||
explicit IRCChannelMemberListModel(IRCChannel&);
|
||||
|
||||
IRCChannel& m_channel;
|
||||
};
|
||||
|
|
|
@ -31,10 +31,10 @@ IRCClient::IRCClient(const String& address, int port)
|
|||
: m_hostname(address)
|
||||
, m_port(port)
|
||||
, m_nickname("anon")
|
||||
, m_client_window_list_model(IRCWindowListModel::create(*this))
|
||||
, m_log(IRCLogBuffer::create())
|
||||
{
|
||||
m_socket = new GTCPSocket(this);
|
||||
m_client_window_list_model = new IRCWindowListModel(*this);
|
||||
}
|
||||
|
||||
IRCClient::~IRCClient()
|
||||
|
|
|
@ -46,8 +46,8 @@ public:
|
|||
void register_subwindow(IRCWindow&);
|
||||
void unregister_subwindow(IRCWindow&);
|
||||
|
||||
IRCWindowListModel* client_window_list_model() { return m_client_window_list_model; }
|
||||
const IRCWindowListModel* client_window_list_model() const { return m_client_window_list_model; }
|
||||
IRCWindowListModel* client_window_list_model() { return m_client_window_list_model.ptr(); }
|
||||
const IRCWindowListModel* client_window_list_model() const { return m_client_window_list_model.ptr(); }
|
||||
|
||||
int window_count() const { return m_windows.size(); }
|
||||
const IRCWindow& window_at(int index) const { return *m_windows.at(index); }
|
||||
|
@ -118,7 +118,6 @@ private:
|
|||
|
||||
IRCWindow* m_server_subwindow { nullptr };
|
||||
|
||||
IRCWindowListModel* m_client_window_list_model { nullptr };
|
||||
|
||||
Retained<IRCWindowListModel> m_client_window_list_model;
|
||||
Retained<IRCLogBuffer> m_log;
|
||||
};
|
||||
|
|
|
@ -9,8 +9,8 @@ Retained<IRCLogBuffer> IRCLogBuffer::create()
|
|||
}
|
||||
|
||||
IRCLogBuffer::IRCLogBuffer()
|
||||
: m_model(IRCLogBufferModel::create(*this))
|
||||
{
|
||||
m_model = new IRCLogBufferModel(*this);
|
||||
}
|
||||
|
||||
IRCLogBuffer::~IRCLogBuffer()
|
||||
|
|
|
@ -27,11 +27,11 @@ public:
|
|||
void add_message(const String& text, Color = Color::Black);
|
||||
void dump() const;
|
||||
|
||||
const IRCLogBufferModel* model() const { return m_model; }
|
||||
IRCLogBufferModel* model() { return m_model; }
|
||||
const IRCLogBufferModel* model() const { return m_model.ptr(); }
|
||||
IRCLogBufferModel* model() { return m_model.ptr(); }
|
||||
|
||||
private:
|
||||
IRCLogBuffer();
|
||||
IRCLogBufferModel* m_model { nullptr };
|
||||
Retained<IRCLogBufferModel> m_model;
|
||||
CircularQueue<Message, 1000> m_messages;
|
||||
};
|
||||
|
|
|
@ -13,7 +13,7 @@ public:
|
|||
__Count,
|
||||
};
|
||||
|
||||
explicit IRCLogBufferModel(Retained<IRCLogBuffer>&&);
|
||||
static Retained<IRCLogBufferModel> create(Retained<IRCLogBuffer>&& log_buffer) { return adopt(*new IRCLogBufferModel(move(log_buffer))); }
|
||||
virtual ~IRCLogBufferModel() override;
|
||||
|
||||
virtual int row_count() const override;
|
||||
|
@ -25,5 +25,7 @@ public:
|
|||
virtual void activate(const GModelIndex&) override;
|
||||
|
||||
private:
|
||||
explicit IRCLogBufferModel(Retained<IRCLogBuffer>&&);
|
||||
|
||||
Retained<IRCLogBuffer> m_log_buffer;
|
||||
};
|
||||
|
|
|
@ -32,7 +32,7 @@ IRCWindow::IRCWindow(IRCClient& client, void* owner, Type type, const String& na
|
|||
member_view->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
member_view->set_preferred_size({ 100, 0 });
|
||||
member_view->set_alternating_row_colors(false);
|
||||
member_view->set_model(OwnPtr<IRCChannelMemberListModel>(channel().member_model()));
|
||||
member_view->set_model(channel().member_model());
|
||||
}
|
||||
|
||||
m_text_editor = new GTextEditor(GTextEditor::SingleLine, this);
|
||||
|
@ -59,7 +59,7 @@ IRCWindow::~IRCWindow()
|
|||
void IRCWindow::set_log_buffer(const IRCLogBuffer& log_buffer)
|
||||
{
|
||||
m_log_buffer = &log_buffer;
|
||||
m_table_view->set_model(OwnPtr<IRCLogBufferModel>((IRCLogBufferModel*)log_buffer.model()));
|
||||
m_table_view->set_model(log_buffer.model());
|
||||
}
|
||||
|
||||
bool IRCWindow::is_active() const
|
||||
|
|
|
@ -12,7 +12,7 @@ public:
|
|||
Name,
|
||||
};
|
||||
|
||||
explicit IRCWindowListModel(IRCClient&);
|
||||
static Retained<IRCWindowListModel> create(IRCClient& client) { return adopt(*new IRCWindowListModel(client)); }
|
||||
virtual ~IRCWindowListModel() override;
|
||||
|
||||
virtual int row_count() const override;
|
||||
|
@ -26,5 +26,7 @@ public:
|
|||
Function<void(IRCWindow&)> on_activation;
|
||||
|
||||
private:
|
||||
explicit IRCWindowListModel(IRCClient&);
|
||||
|
||||
IRCClient& m_client;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue