mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 12:55:09 +00:00
LibGUI+VisualBuilder: Support custom editing widgets for property values.
Implemented this by letting GAbstractViews provide a GModelEditingDelegate for a given index, which then knows how to create and setup a custom widget appropriate for the data type being edited.
This commit is contained in:
parent
1d0ada32cc
commit
6a0011dcea
8 changed files with 170 additions and 7 deletions
|
@ -24,6 +24,8 @@ String VBWidgetPropertyModel::column_name(int column) const
|
|||
return "Name";
|
||||
case Column::Value:
|
||||
return "Value";
|
||||
case Column::Type:
|
||||
return "Type";
|
||||
default:
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
@ -39,6 +41,12 @@ GModel::ColumnMetadata VBWidgetPropertyModel::column_metadata(int column) const
|
|||
|
||||
GVariant VBWidgetPropertyModel::data(const GModelIndex& index, Role role) const
|
||||
{
|
||||
if (role == Role::Custom) {
|
||||
auto& property = *m_widget.m_properties[index.row()];
|
||||
if (index.column() == Column::Type)
|
||||
return (int)property.value().type();
|
||||
return {};
|
||||
}
|
||||
if (role == Role::Display) {
|
||||
auto& property = *m_widget.m_properties[index.row()];
|
||||
switch (index.column()) {
|
||||
|
@ -46,6 +54,8 @@ GVariant VBWidgetPropertyModel::data(const GModelIndex& index, Role role) const
|
|||
return property.name();
|
||||
case Column::Value:
|
||||
return property.value();
|
||||
case Column::Type:
|
||||
return to_string(property.value().type());
|
||||
}
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
@ -54,6 +64,8 @@ GVariant VBWidgetPropertyModel::data(const GModelIndex& index, Role role) const
|
|||
switch (index.column()) {
|
||||
case Column::Name:
|
||||
return Color::Black;
|
||||
case Column::Type:
|
||||
return Color::Blue;
|
||||
case Column::Value:
|
||||
return property.is_readonly() ? Color(Color::MidGray) : Color(Color::Black);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue