1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 12:15:07 +00:00
serenity/Userland/Applications/KeyboardSettings/CharacterMapFileListModel.h
Andreas Kling b91c49364d AK: Rename adopt() to adopt_ref()
This makes it more symmetrical with adopt_own() (which is used to
create a NonnullOwnPtr from the result of a naked new.)
2021-04-23 16:46:57 +02:00

54 lines
1.2 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>& file_names)
{
return adopt_ref(*new CharacterMapFileListModel(file_names));
}
virtual ~CharacterMapFileListModel() override { }
virtual int row_count(const GUI::ModelIndex&) const override
{
return m_file_names.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_file_names.at(index.row());
return {};
}
virtual void update() override
{
did_update();
}
private:
explicit CharacterMapFileListModel(Vector<String>& file_names)
: m_file_names(file_names)
{
}
Vector<String>& m_file_names;
};