mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-25 18:52:22 -05:00
ca2c81251a
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>
49 lines
1.1 KiB
C++
49 lines
1.1 KiB
C++
/*
|
||
* 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;
|
||
};
|