ladybird/Userland/Applications/KeyboardSettings/CharacterMapFileListModel.h
sin-ack ca2c81251a 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>
2021-08-06 19:14:31 +02:00

49 lines
1.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Vector.h>
#include <LibGUI/Model.h>
class CharacterMapFileListModel final : public GUI::Model {
public:
static NonnullRefPtr<CharacterMapFileListModel> create(Vector<String>& filenames)
{
return adopt_ref(*new CharacterMapFileListModel(filenames));
}
virtual ~CharacterMapFileListModel() override { }
virtual int row_count(const GUI::ModelIndex&) const override
{
return m_filenames.size();
}
virtual int column_count(const GUI::ModelIndex&) const override
{
return 1;
}
virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override
{
VERIFY(index.is_valid());
VERIFY(index.column() == 0);
if (role == GUI::ModelRole::Display)
return m_filenames.at(index.row());
return {};
}
private:
explicit CharacterMapFileListModel(Vector<String>& filenames)
: m_filenames(filenames)
{
}
Vector<String>& m_filenames;
};