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

Everywhere: "indexes" => "indices"

I've wasted a silly amount of time in the past fretting over which
of these words to use. Let's just choose one and use it everywhere. :^)
This commit is contained in:
Andreas Kling 2021-04-29 22:23:52 +02:00
parent 7ae7170d61
commit 3d4afe7614
29 changed files with 139 additions and 139 deletions

View file

@ -43,13 +43,13 @@ void AbstractView::set_model(RefPtr<Model> model)
m_model = move(model);
if (m_model)
m_model->register_view({}, *this);
model_did_update(GUI::Model::InvalidateAllIndexes);
model_did_update(GUI::Model::InvalidateAllIndices);
scroll_to_top();
}
void AbstractView::model_did_update(unsigned int flags)
{
if (!model() || (flags & GUI::Model::InvalidateAllIndexes)) {
if (!model() || (flags & GUI::Model::InvalidateAllIndices)) {
stop_editing();
m_edit_index = {};
m_hovered_index = {};
@ -630,9 +630,9 @@ void AbstractView::do_search(String&& searching)
return;
}
auto found_indexes = model()->matches(searching, Model::MatchesFlag::FirstMatchOnly | Model::MatchesFlag::MatchAtStart | Model::MatchesFlag::CaseInsensitive, model()->parent_index(cursor_index()));
if (!found_indexes.is_empty() && found_indexes[0].is_valid()) {
auto& index = found_indexes[0];
auto found_indices = model()->matches(searching, Model::MatchesFlag::FirstMatchOnly | Model::MatchesFlag::MatchAtStart | Model::MatchesFlag::CaseInsensitive, model()->parent_index(cursor_index()));
if (!found_indices.is_empty() && found_indices[0].is_valid()) {
auto& index = found_indices[0];
m_highlighted_search_index = index;
m_searching = move(searching);
set_selection(index);

View file

@ -629,17 +629,17 @@ Vector<ModelIndex, 1> FileSystemModel::matches(const StringView& searching, unsi
{
Node& node = const_cast<Node&>(this->node(index));
node.reify_if_needed();
Vector<ModelIndex, 1> found_indexes;
Vector<ModelIndex, 1> found_indices;
for (auto& child : node.children) {
if (string_matches(child.name, searching, flags)) {
const_cast<Node&>(child).reify_if_needed();
found_indexes.append(child.index(Column::Name));
found_indices.append(child.index(Column::Name));
if (flags & FirstMatchOnly)
break;
}
}
return found_indexes;
return found_indices;
}
}

View file

@ -106,10 +106,10 @@ bool FilteringProxyModel::is_searchable() const
Vector<ModelIndex, 1> FilteringProxyModel::matches(const StringView& searching, unsigned flags, const ModelIndex& index)
{
auto found_indexes = m_model.matches(searching, flags, index);
for (size_t i = 0; i < found_indexes.size(); i++)
found_indexes[i] = map(found_indexes[i]);
return found_indexes;
auto found_indices = m_model.matches(searching, flags, index);
for (size_t i = 0; i < found_indices.size(); i++)
found_indices[i] = map(found_indices[i]);
return found_indices;
}
}

View file

@ -122,7 +122,7 @@ auto IconView::item_data_from_content_position(const Gfx::IntPoint& content_posi
void IconView::model_did_update(unsigned flags)
{
AbstractView::model_did_update(flags);
if (!model() || (flags & GUI::Model::InvalidateAllIndexes)) {
if (!model() || (flags & GUI::Model::InvalidateAllIndices)) {
m_item_data_cache.clear();
AbstractView::clear_selection();
m_selected_count_cache = 0;

View file

@ -37,8 +37,8 @@ public:
class Model : public RefCounted<Model> {
public:
enum UpdateFlag {
DontInvalidateIndexes = 0,
InvalidateAllIndexes = 1 << 0,
DontInvalidateIndices = 0,
InvalidateAllIndices = 1 << 0,
};
enum MatchesFlag {
@ -88,7 +88,7 @@ protected:
Model();
void for_each_view(Function<void(AbstractView&)>);
void did_update(unsigned flags = UpdateFlag::InvalidateAllIndexes);
void did_update(unsigned flags = UpdateFlag::InvalidateAllIndices);
static bool string_matches(const StringView& str, const StringView& needle, unsigned flags)
{

View file

@ -14,13 +14,13 @@ namespace GUI {
void ModelSelection::remove_matching(Function<bool(const ModelIndex&)> filter)
{
Vector<ModelIndex> to_remove;
for (auto& index : m_indexes) {
for (auto& index : m_indices) {
if (filter(index))
to_remove.append(index);
}
if (!to_remove.is_empty()) {
for (auto& index : to_remove)
m_indexes.remove(index);
m_indices.remove(index);
notify_selection_changed();
}
}
@ -28,19 +28,19 @@ void ModelSelection::remove_matching(Function<bool(const ModelIndex&)> filter)
void ModelSelection::set(const ModelIndex& index)
{
VERIFY(index.is_valid());
if (m_indexes.size() == 1 && m_indexes.contains(index))
if (m_indices.size() == 1 && m_indices.contains(index))
return;
m_indexes.clear();
m_indexes.set(index);
m_indices.clear();
m_indices.set(index);
notify_selection_changed();
}
void ModelSelection::add(const ModelIndex& index)
{
VERIFY(index.is_valid());
if (m_indexes.contains(index))
if (m_indices.contains(index))
return;
m_indexes.set(index);
m_indices.set(index);
notify_selection_changed();
}
@ -59,28 +59,28 @@ void ModelSelection::add_all(const Vector<ModelIndex>& indices)
void ModelSelection::toggle(const ModelIndex& index)
{
VERIFY(index.is_valid());
if (m_indexes.contains(index))
m_indexes.remove(index);
if (m_indices.contains(index))
m_indices.remove(index);
else
m_indexes.set(index);
m_indices.set(index);
notify_selection_changed();
}
bool ModelSelection::remove(const ModelIndex& index)
{
VERIFY(index.is_valid());
if (!m_indexes.contains(index))
if (!m_indices.contains(index))
return false;
m_indexes.remove(index);
m_indices.remove(index);
notify_selection_changed();
return true;
}
void ModelSelection::clear()
{
if (m_indexes.is_empty())
if (m_indices.is_empty())
return;
m_indexes.clear();
m_indices.clear();
notify_selection_changed();
}

View file

@ -25,12 +25,12 @@ public:
{
}
int size() const { return m_indexes.size(); }
bool is_empty() const { return m_indexes.is_empty(); }
bool contains(const ModelIndex& index) const { return m_indexes.contains(index); }
int size() const { return m_indices.size(); }
bool is_empty() const { return m_indices.is_empty(); }
bool contains(const ModelIndex& index) const { return m_indices.contains(index); }
bool contains_row(int row) const
{
for (auto& index : m_indexes) {
for (auto& index : m_indices) {
if (index.row() == row)
return true;
}
@ -47,33 +47,33 @@ public:
template<typename Callback>
void for_each_index(Callback callback)
{
for (auto& index : indexes())
for (auto& index : indices())
callback(index);
}
template<typename Callback>
void for_each_index(Callback callback) const
{
for (auto& index : indexes())
for (auto& index : indices())
callback(index);
}
Vector<ModelIndex> indexes() const
Vector<ModelIndex> indices() const
{
Vector<ModelIndex> selected_indexes;
Vector<ModelIndex> selected_indices;
for (auto& index : m_indexes)
selected_indexes.append(index);
for (auto& index : m_indices)
selected_indices.append(index);
return selected_indexes;
return selected_indices;
}
// FIXME: This doesn't guarantee that what you get is the lowest or "first" index selected..
ModelIndex first() const
{
if (m_indexes.is_empty())
if (m_indices.is_empty())
return {};
return *m_indexes.begin();
return *m_indices.begin();
}
void remove_matching(Function<bool(const ModelIndex&)>);
@ -94,7 +94,7 @@ private:
void notify_selection_changed();
AbstractView& m_view;
HashTable<ModelIndex> m_indexes;
HashTable<ModelIndex> m_indices;
bool m_disable_notify { false };
bool m_notify_pending { false };
};

View file

@ -24,7 +24,7 @@ SortingProxyModel::~SortingProxyModel()
void SortingProxyModel::invalidate(unsigned int flags)
{
if (flags == UpdateFlag::DontInvalidateIndexes) {
if (flags == UpdateFlag::DontInvalidateIndices) {
sort(m_last_key_column, m_last_sort_order);
} else {
m_mappings.clear();
@ -201,20 +201,20 @@ void SortingProxyModel::sort_mapping(Mapping& mapping, int column, SortOrder sor
// Update the view's selection.
view.selection().change_from_model({}, [&](ModelSelection& selection) {
Vector<ModelIndex> selected_indexes_in_source;
Vector<ModelIndex> stale_indexes_in_selection;
Vector<ModelIndex> selected_indices_in_source;
Vector<ModelIndex> stale_indices_in_selection;
selection.for_each_index([&](const ModelIndex& index) {
if (index.parent() == mapping.source_parent) {
stale_indexes_in_selection.append(index);
selected_indexes_in_source.append(source().index(old_source_rows[index.row()], index.column(), mapping.source_parent));
stale_indices_in_selection.append(index);
selected_indices_in_source.append(source().index(old_source_rows[index.row()], index.column(), mapping.source_parent));
}
});
for (auto& index : stale_indexes_in_selection) {
for (auto& index : stale_indices_in_selection) {
selection.remove(index);
}
for (auto& index : selected_indexes_in_source) {
for (auto& index : selected_indices_in_source) {
for (size_t i = 0; i < mapping.source_rows.size(); ++i) {
if (mapping.source_rows[i] == index.row()) {
auto new_source_index = this->index(i, index.column(), mapping.source_parent);
@ -237,7 +237,7 @@ void SortingProxyModel::sort(int column, SortOrder sort_order)
m_last_key_column = column;
m_last_sort_order = sort_order;
did_update(UpdateFlag::DontInvalidateIndexes);
did_update(UpdateFlag::DontInvalidateIndices);
}
SortingProxyModel::InternalMapIterator SortingProxyModel::build_mapping(const ModelIndex& source_parent)
@ -287,10 +287,10 @@ bool SortingProxyModel::is_searchable() const
Vector<ModelIndex, 1> SortingProxyModel::matches(const StringView& searching, unsigned flags, const ModelIndex& proxy_index)
{
auto found_indexes = source().matches(searching, flags, map_to_source(proxy_index));
for (size_t i = 0; i < found_indexes.size(); i++)
found_indexes[i] = map_to_proxy(found_indexes[i]);
return found_indexes;
auto found_indices = source().matches(searching, flags, map_to_source(proxy_index));
for (size_t i = 0; i < found_indices.size(); i++)
found_indices[i] = map_to_proxy(found_indices[i]);
return found_indices;
}
}

View file

@ -46,7 +46,7 @@ public:
private:
explicit SortingProxyModel(NonnullRefPtr<Model> source);
// NOTE: The internal_data() of indexes points to the corresponding Mapping object for that index.
// NOTE: The internal_data() of indices points to the corresponding Mapping object for that index.
struct Mapping {
Vector<int> source_rows;
Vector<int> proxy_rows;
@ -63,7 +63,7 @@ private:
Model& source() { return *m_source; }
const Model& source() const { return *m_source; }
void invalidate(unsigned flags = Model::UpdateFlag::DontInvalidateIndexes);
void invalidate(unsigned flags = Model::UpdateFlag::DontInvalidateIndices);
InternalMapIterator build_mapping(const ModelIndex& proxy_index);
NonnullRefPtr<Model> m_source;