summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-08-29 08:26:44 +0430
committerAndreas Kling <kling@serenityos.org>2020-08-29 17:42:03 +0200
commite75247a75b227b57b64852a83b8f5cbd280b5d04 (patch)
treef6bd844b3683e363754d9ef74d654b821becb7b2
parent2f9a07107234ce776717760f3374ee430e9ae192 (diff)
downloadserenity-e75247a75b227b57b64852a83b8f5cbd280b5d04.zip
DisplaySettings+LibGUI: Move ItemListModel into LibGUI
Without this model, comboboxes are abysmal to work with, so let's not redefine it every time.
-rw-r--r--Applications/DisplaySettings/DisplaySettings.cpp8
-rw-r--r--Libraries/LibGUI/ItemListModel.h (renamed from Applications/DisplaySettings/ItemListModel.h)22
2 files changed, 17 insertions, 13 deletions
diff --git a/Applications/DisplaySettings/DisplaySettings.cpp b/Applications/DisplaySettings/DisplaySettings.cpp
index 22fd9bdeb3..6ef0f91c44 100644
--- a/Applications/DisplaySettings/DisplaySettings.cpp
+++ b/Applications/DisplaySettings/DisplaySettings.cpp
@@ -25,7 +25,7 @@
*/
#include "DisplaySettings.h"
-#include "ItemListModel.h"
+#include <LibGUI/ItemListModel.h>
#include <AK/StringBuilder.h>
#include <LibCore/ConfigFile.h>
#include <LibCore/DirIterator.h>
@@ -122,7 +122,7 @@ void DisplaySettingsWidget::create_frame()
m_wallpaper_combo->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_wallpaper_combo->set_preferred_size(0, 22);
m_wallpaper_combo->set_only_allow_values_from_model(true);
- m_wallpaper_combo->set_model(*ItemListModel<AK::String>::create(m_wallpapers));
+ m_wallpaper_combo->set_model(*GUI::ItemListModel<AK::String>::create(m_wallpapers));
m_wallpaper_combo->on_change = [this](auto& text, const GUI::ModelIndex& index) {
String path = text;
if (m_monitor_widget->set_wallpaper(path)) {
@@ -180,7 +180,7 @@ void DisplaySettingsWidget::create_frame()
m_mode_combo->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_mode_combo->set_preferred_size(0, 22);
m_mode_combo->set_only_allow_values_from_model(true);
- m_mode_combo->set_model(*ItemListModel<AK::String>::create(m_modes));
+ m_mode_combo->set_model(*GUI::ItemListModel<AK::String>::create(m_modes));
m_mode_combo->on_change = [this](auto&, const GUI::ModelIndex& index) {
this->m_monitor_widget->set_wallpaper_mode(m_modes.at(index.row()));
this->m_monitor_widget->update();
@@ -203,7 +203,7 @@ void DisplaySettingsWidget::create_frame()
m_resolution_combo->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_resolution_combo->set_preferred_size(0, 22);
m_resolution_combo->set_only_allow_values_from_model(true);
- m_resolution_combo->set_model(*ItemListModel<Gfx::IntSize>::create(m_resolutions));
+ m_resolution_combo->set_model(*GUI::ItemListModel<Gfx::IntSize>::create(m_resolutions));
m_resolution_combo->on_change = [this](auto&, const GUI::ModelIndex& index) {
this->m_monitor_widget->set_desktop_resolution(m_resolutions.at(index.row()));
this->m_monitor_widget->update();
diff --git a/Applications/DisplaySettings/ItemListModel.h b/Libraries/LibGUI/ItemListModel.h
index 1ce1122ac7..1546dce35d 100644
--- a/Applications/DisplaySettings/ItemListModel.h
+++ b/Libraries/LibGUI/ItemListModel.h
@@ -30,19 +30,21 @@
#include <AK/Vector.h>
#include <LibGUI/Model.h>
+namespace GUI {
+
template<typename T>
-class ItemListModel final : public GUI::Model {
+class ItemListModel final : public Model {
public:
- static NonnullRefPtr<ItemListModel> create(Vector<T>& data) { return adopt(*new ItemListModel<T>(data)); }
+ static NonnullRefPtr<ItemListModel> create(const Vector<T>& data) { return adopt(*new ItemListModel<T>(data)); }
virtual ~ItemListModel() override { }
- virtual int row_count(const GUI::ModelIndex&) const override
+ virtual int row_count(const ModelIndex&) const override
{
return m_data.size();
}
- virtual int column_count(const GUI::ModelIndex&) const override
+ virtual int column_count(const ModelIndex&) const override
{
return 1;
}
@@ -52,11 +54,11 @@ public:
return "Data";
}
- virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override
+ virtual Variant data(const ModelIndex& index, ModelRole role) const override
{
- if (role == GUI::ModelRole::TextAlignment)
+ if (role == ModelRole::TextAlignment)
return Gfx::TextAlignment::CenterLeft;
- if (role == GUI::ModelRole::Display)
+ if (role == ModelRole::Display)
return m_data.at(index.row());
return {};
@@ -68,10 +70,12 @@ public:
}
private:
- explicit ItemListModel(Vector<T>& data)
+ explicit ItemListModel(const Vector<T>& data)
: m_data(data)
{
}
- Vector<T>& m_data;
+ const Vector<T>& m_data;
};
+
+}