1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:07:36 +00:00

Everywhere: Replace Model::update() with Model::invalidate()

Most of the models were just calling did_update anyway, which is
pointless since it can be unified to the base Model class. Instead, code
calling update() will now call invalidate(), which functions identically
and is more obvious in what it does.

Additionally, a default implementation is provided, which removes the
need to add empty implementations of update() for each model subclass.

Co-Authored-By: Ali Mohammad Pur <ali.mpfard@gmail.com>
This commit is contained in:
sin-ack 2021-05-25 14:13:19 +00:00 committed by Andreas Kling
parent 5cd2e0f3a2
commit ca2c81251a
100 changed files with 116 additions and 261 deletions

View file

@ -62,7 +62,7 @@ void IRCAppWindow::setup_client()
return static_cast<IRCWindow*>(m_container->active_widget());
};
m_client->aid_update_window_list = [this] {
m_window_list->model()->update();
m_window_list->model()->invalidate();
};
m_client->on_nickname_changed = [this](const String&) {
update_title();

View file

@ -36,7 +36,7 @@ void IRCChannel::add_member(const String& name, char prefix)
}
}
m_members.append({ name, prefix });
m_member_model->update();
m_member_model->invalidate();
}
void IRCChannel::remove_member(const String& name)
@ -69,7 +69,7 @@ void IRCChannel::handle_join(const String& nick, const String& hostmask)
return;
}
add_member(nick, (char)0);
m_member_model->update();
m_member_model->invalidate();
if (m_client.show_join_part_messages())
add_message(String::formatted("*** {} [{}] has joined {}", nick, hostmask, m_name), Color::MidGreen);
}
@ -83,7 +83,7 @@ void IRCChannel::handle_part(const String& nick, const String& hostmask)
} else {
remove_member(nick);
}
m_member_model->update();
m_member_model->invalidate();
if (m_client.show_join_part_messages())
add_message(String::formatted("*** {} [{}] has parted from {}", nick, hostmask, m_name), Color::MidGreen);
}
@ -97,7 +97,7 @@ void IRCChannel::handle_quit(const String& nick, const String& hostmask, const S
} else {
remove_member(nick);
}
m_member_model->update();
m_member_model->invalidate();
add_message(String::formatted("*** {} [{}] has quit ({})", nick, hostmask, message), Color::MidGreen);
}
@ -114,7 +114,7 @@ void IRCChannel::notify_nick_changed(const String& old_nick, const String& new_n
for (auto& member : m_members) {
if (member.name == old_nick) {
member.name = new_nick;
m_member_model->update();
m_member_model->invalidate();
if (m_client.show_nick_change_messages())
add_message(String::formatted("~ {} changed nickname to {}", old_nick, new_nick), Color::MidMagenta);
return;

View file

@ -50,11 +50,6 @@ GUI::Variant IRCChannelMemberListModel::data(const GUI::ModelIndex& index, GUI::
return {};
}
void IRCChannelMemberListModel::update()
{
did_update();
}
String IRCChannelMemberListModel::nick_at(const GUI::ModelIndex& index) const
{
return data(index, GUI::ModelRole::Display).to_string();

View file

@ -23,7 +23,6 @@ public:
virtual int column_count(const GUI::ModelIndex&) const override;
virtual String column_name(int column) const override;
virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override;
virtual void update() override;
virtual String nick_at(const GUI::ModelIndex& index) const;
private:

View file

@ -817,7 +817,7 @@ void IRCClient::register_subwindow(IRCWindow& subwindow)
subwindow.set_log_buffer(*m_log);
}
m_windows.append(&subwindow);
m_client_window_list_model->update();
m_client_window_list_model->invalidate();
}
void IRCClient::unregister_subwindow(IRCWindow& subwindow)
@ -831,7 +831,7 @@ void IRCClient::unregister_subwindow(IRCWindow& subwindow)
break;
}
}
m_client_window_list_model->update();
m_client_window_list_model->invalidate();
}
void IRCClient::handle_user_command(const String& input)
@ -1079,7 +1079,7 @@ void IRCClient::handle_kick_user_action(const String& channel, const String& nic
void IRCClient::handle_close_query_action(const String& nick)
{
m_queries.remove(nick);
m_client_window_list_model->update();
m_client_window_list_model->invalidate();
}
void IRCClient::handle_join_action(const String& channel)

View file

@ -64,8 +64,3 @@ GUI::Variant IRCWindowListModel::data(const GUI::ModelIndex& index, GUI::ModelRo
}
return {};
}
void IRCWindowListModel::update()
{
did_update();
}

View file

@ -25,7 +25,6 @@ public:
virtual int column_count(const GUI::ModelIndex&) const override;
virtual String column_name(int column) const override;
virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override;
virtual void update() override;
private:
explicit IRCWindowListModel(IRCClient&);