2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2021-08-24 16:27:10 +01:00
|
|
|
* Copyright (c) 2021, Sam Atkins <atkinssj@gmail.com>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2021-08-24 16:27:10 +01:00
|
|
|
#include "StylePropertiesModel.h"
|
2020-06-13 19:22:30 +02:00
|
|
|
#include <AK/QuickSort.h>
|
2020-01-04 01:15:42 +01:00
|
|
|
|
2020-03-07 10:27:02 +01:00
|
|
|
namespace Web {
|
|
|
|
|
|
2021-08-24 16:27:10 +01:00
|
|
|
StylePropertiesModel::StylePropertiesModel(JsonObject properties)
|
|
|
|
|
: m_properties(move(properties))
|
2020-01-04 01:15:42 +01:00
|
|
|
{
|
2021-08-24 16:27:10 +01:00
|
|
|
m_properties.for_each_member([&](auto& property_name, auto& property_value) {
|
2020-05-28 14:20:12 +02:00
|
|
|
Value value;
|
2021-08-24 16:27:10 +01:00
|
|
|
value.name = property_name;
|
2020-05-28 14:20:12 +02:00
|
|
|
value.value = property_value.to_string();
|
|
|
|
|
m_values.append(value);
|
2020-01-04 01:15:42 +01:00
|
|
|
});
|
2020-06-13 19:22:30 +02:00
|
|
|
|
|
|
|
|
quick_sort(m_values, [](auto& a, auto& b) { return a.name < b.name; });
|
2020-01-04 01:15:42 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-24 16:27:10 +01:00
|
|
|
StylePropertiesModel::~StylePropertiesModel()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int StylePropertiesModel::row_count(GUI::ModelIndex const&) const
|
2020-01-04 01:15:42 +01:00
|
|
|
{
|
|
|
|
|
return m_values.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String StylePropertiesModel::column_name(int column_index) const
|
|
|
|
|
{
|
|
|
|
|
switch (column_index) {
|
|
|
|
|
case Column::PropertyName:
|
|
|
|
|
return "Name";
|
|
|
|
|
case Column::PropertyValue:
|
|
|
|
|
return "Value";
|
|
|
|
|
default:
|
2021-02-23 20:42:32 +01:00
|
|
|
VERIFY_NOT_REACHED();
|
2020-01-04 01:15:42 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-08-24 16:27:10 +01:00
|
|
|
|
|
|
|
|
GUI::Variant StylePropertiesModel::data(GUI::ModelIndex const& index, GUI::ModelRole role) const
|
2020-01-04 01:15:42 +01:00
|
|
|
{
|
|
|
|
|
auto& value = m_values[index.row()];
|
2020-08-16 16:00:07 +02:00
|
|
|
if (role == GUI::ModelRole::Display) {
|
2020-01-04 01:15:42 +01:00
|
|
|
if (index.column() == Column::PropertyName)
|
|
|
|
|
return value.name;
|
|
|
|
|
if (index.column() == Column::PropertyValue)
|
|
|
|
|
return value.value;
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-07 10:27:02 +01:00
|
|
|
}
|