ladybird/Applications/DisplayProperties/ItemListModel.h
Jesse Buhagiar ecbc0322c1 Applications: Create a display properties manager
An interactive application to modify the current display settings, such as
the current wallpaper as well as the screen resolution. Currently we're
adding the resolutions ourselves, because there's currently no way to
detect was resolutions the current display adapter supports (or at least
I can't see one... Maybe VBE does and I'm stupid). It even comes with
a very nice template'd `ItemList` that can support a vector of any type,
which makes life much simpler.
2019-09-07 16:51:15 +02:00

55 lines
1.1 KiB
C++

#pragma once
#include <AK/NonnullRefPtr.h>
#include <AK/Vector.h>
#include <LibGUI/GModel.h>
template<typename T>
class ItemListModel final : public GModel {
public:
static NonnullRefPtr<ItemListModel> create(Vector<T>& data) { return adopt(*new ItemListModel<T>(data)); }
virtual ~ItemListModel() override {}
virtual int row_count(const GModelIndex&) const override
{
return m_data.size();
}
virtual int column_count(const GModelIndex&) const override
{
return 1;
}
virtual String column_name(int) const override
{
return "Data";
}
virtual ColumnMetadata column_metadata(int) const override
{
return { 70, TextAlignment::CenterLeft };
}
virtual GVariant data(const GModelIndex& index, Role role = Role::Display) const override
{
if (role == Role::Display)
return m_data.at(index.row());
return {};
}
virtual void update() override
{
did_update();
}
private:
explicit ItemListModel(Vector<T>& data)
: m_data(data)
{
}
Vector<T>& m_data;
};