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