KeyboardSettings: Reuse generic GUI::ItemListModel

This change removes the manually created model class
in order to use a generic GUI::ItemListModel.

Besides from code reusability, it also makes the list
searchable as you type.
This commit is contained in:
Karol Kosek 2021-08-21 22:07:44 +02:00 committed by Andreas Kling
parent 4bad2bf100
commit d04c8d478f
Notes: sideshowbarker 2024-07-19 17:16:31 +09:00
2 changed files with 2 additions and 51 deletions

View file

@ -1,49 +0,0 @@
/*
* 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;
};

View file

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "CharacterMapFileListModel.h"
#include <AK/JsonObject.h>
#include <AK/QuickSort.h>
#include <LibCore/ConfigFile.h>
@ -16,6 +15,7 @@
#include <LibGUI/Button.h>
#include <LibGUI/CheckBox.h>
#include <LibGUI/ComboBox.h>
#include <LibGUI/ItemListModel.h>
#include <LibGUI/Label.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Menubar.h>
@ -122,7 +122,7 @@ int main(int argc, char** argv)
auto& character_map_file_combo = character_map_file_selection_container.add<GUI::ComboBox>();
character_map_file_combo.set_only_allow_values_from_model(true);
character_map_file_combo.set_model(*CharacterMapFileListModel::create(character_map_files));
character_map_file_combo.set_model(*GUI::ItemListModel<String>::create(character_map_files));
character_map_file_combo.set_selected_index(initial_keymap_index);
auto& num_lock_checkbox = root_widget.add<GUI::CheckBox>("Enable Num Lock on login");