mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:48:11 +00:00
VisualBuilder: Convert Vector<OwnPtr> to NonnullOwnPtrVector.
This commit is contained in:
parent
31a2a6ca2d
commit
e2798d6208
5 changed files with 17 additions and 15 deletions
|
@ -89,7 +89,7 @@ Direction VBWidget::grabber_at(const Point& position) const
|
||||||
void VBWidget::for_each_property(Function<void(VBProperty&)> callback)
|
void VBWidget::for_each_property(Function<void(VBProperty&)> callback)
|
||||||
{
|
{
|
||||||
for (auto& it : m_properties) {
|
for (auto& it : m_properties) {
|
||||||
callback(*it);
|
callback(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,8 +176,8 @@ void VBWidget::setup_properties()
|
||||||
void VBWidget::synchronize_properties()
|
void VBWidget::synchronize_properties()
|
||||||
{
|
{
|
||||||
for (auto& prop : m_properties) {
|
for (auto& prop : m_properties) {
|
||||||
if (prop->m_getter)
|
if (prop.m_getter)
|
||||||
prop->m_value = prop->m_getter(*gwidget());
|
prop.m_value = prop.m_getter(*gwidget());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_property_model->update();
|
m_property_model->update();
|
||||||
|
@ -186,11 +186,11 @@ void VBWidget::synchronize_properties()
|
||||||
VBProperty& VBWidget::property(const String& name)
|
VBProperty& VBWidget::property(const String& name)
|
||||||
{
|
{
|
||||||
for (auto& prop : m_properties) {
|
for (auto& prop : m_properties) {
|
||||||
if (prop->name() == name)
|
if (prop.name() == name)
|
||||||
return *prop;
|
return prop;
|
||||||
}
|
}
|
||||||
m_properties.append(make<VBProperty>(*this, name, GVariant()));
|
m_properties.append(make<VBProperty>(*this, name, GVariant()));
|
||||||
return *m_properties.last();
|
return m_properties.last();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VBWidget::property_did_change()
|
void VBWidget::property_did_change()
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
#include "VBWidgetType.h"
|
#include "VBWidgetType.h"
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/RefCounted.h>
|
#include <AK/NonnullOwnPtrVector.h>
|
||||||
#include <AK/NonnullRefPtr.h>
|
#include <AK/NonnullRefPtr.h>
|
||||||
|
#include <AK/RefCounted.h>
|
||||||
#include <AK/Weakable.h>
|
#include <AK/Weakable.h>
|
||||||
#include <LibDraw/Rect.h>
|
#include <LibDraw/Rect.h>
|
||||||
|
|
||||||
|
@ -79,7 +80,7 @@ private:
|
||||||
VBWidgetType m_type { VBWidgetType::None };
|
VBWidgetType m_type { VBWidgetType::None };
|
||||||
VBForm& m_form;
|
VBForm& m_form;
|
||||||
GWidget* m_gwidget { nullptr };
|
GWidget* m_gwidget { nullptr };
|
||||||
Vector<OwnPtr<VBProperty>> m_properties;
|
NonnullOwnPtrVector<VBProperty> m_properties;
|
||||||
NonnullRefPtr<VBWidgetPropertyModel> m_property_model;
|
NonnullRefPtr<VBWidgetPropertyModel> m_property_model;
|
||||||
Rect m_transform_origin_rect;
|
Rect m_transform_origin_rect;
|
||||||
};
|
};
|
||||||
|
|
|
@ -42,13 +42,13 @@ GModel::ColumnMetadata VBWidgetPropertyModel::column_metadata(int column) const
|
||||||
GVariant VBWidgetPropertyModel::data(const GModelIndex& index, Role role) const
|
GVariant VBWidgetPropertyModel::data(const GModelIndex& index, Role role) const
|
||||||
{
|
{
|
||||||
if (role == Role::Custom) {
|
if (role == Role::Custom) {
|
||||||
auto& property = *m_widget.m_properties[index.row()];
|
auto& property = m_widget.m_properties[index.row()];
|
||||||
if (index.column() == Column::Type)
|
if (index.column() == Column::Type)
|
||||||
return (int)property.value().type();
|
return (int)property.value().type();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
if (role == Role::Display) {
|
if (role == Role::Display) {
|
||||||
auto& property = *m_widget.m_properties[index.row()];
|
auto& property = m_widget.m_properties[index.row()];
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case Column::Name:
|
case Column::Name:
|
||||||
return property.name();
|
return property.name();
|
||||||
|
@ -60,7 +60,7 @@ GVariant VBWidgetPropertyModel::data(const GModelIndex& index, Role role) const
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
if (role == Role::ForegroundColor) {
|
if (role == Role::ForegroundColor) {
|
||||||
auto& property = *m_widget.m_properties[index.row()];
|
auto& property = m_widget.m_properties[index.row()];
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case Column::Name:
|
case Column::Name:
|
||||||
return Color::Black;
|
return Color::Black;
|
||||||
|
@ -77,7 +77,7 @@ GVariant VBWidgetPropertyModel::data(const GModelIndex& index, Role role) const
|
||||||
void VBWidgetPropertyModel::set_data(const GModelIndex& index, const GVariant& value)
|
void VBWidgetPropertyModel::set_data(const GModelIndex& index, const GVariant& value)
|
||||||
{
|
{
|
||||||
ASSERT(index.column() == Column::Value);
|
ASSERT(index.column() == Column::Value);
|
||||||
auto& property = *m_widget.m_properties[index.row()];
|
auto& property = m_widget.m_properties[index.row()];
|
||||||
ASSERT(!property.is_readonly());
|
ASSERT(!property.is_readonly());
|
||||||
property.set_value(value);
|
property.set_value(value);
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,6 @@ bool VBWidgetPropertyModel::is_editable(const GModelIndex& index) const
|
||||||
{
|
{
|
||||||
if (index.column() != Column::Value)
|
if (index.column() != Column::Value)
|
||||||
return false;
|
return false;
|
||||||
auto& property = *m_widget.m_properties[index.row()];
|
auto& property = m_widget.m_properties[index.row()];
|
||||||
return !property.is_readonly();
|
return !property.is_readonly();
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ static GWidget* build_gwidget(VBWidgetType type, GWidget* parent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GWidget* VBWidgetRegistry::build_gwidget(VBWidget& widget, VBWidgetType type, GWidget* parent, Vector<OwnPtr<VBProperty>>& properties)
|
GWidget* VBWidgetRegistry::build_gwidget(VBWidget& widget, VBWidgetType type, GWidget* parent, NonnullOwnPtrVector<VBProperty>& properties)
|
||||||
{
|
{
|
||||||
auto* gwidget = ::build_gwidget(type, parent);
|
auto* gwidget = ::build_gwidget(type, parent);
|
||||||
auto add_readonly_property = [&](const String& name, const GVariant& value) {
|
auto add_readonly_property = [&](const String& name, const GVariant& value) {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "VBWidgetType.h"
|
#include "VBWidgetType.h"
|
||||||
#include <AK/AKString.h>
|
#include <AK/AKString.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
|
#include <AK/NonnullOwnPtrVector.h>
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
|
|
||||||
class GWidget;
|
class GWidget;
|
||||||
|
@ -18,7 +19,7 @@ public:
|
||||||
callback((VBWidgetType)i);
|
callback((VBWidgetType)i);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GWidget* build_gwidget(VBWidget&, VBWidgetType, GWidget* parent, Vector<OwnPtr<VBProperty>>&);
|
static GWidget* build_gwidget(VBWidget&, VBWidgetType, GWidget* parent, NonnullOwnPtrVector<VBProperty>&);
|
||||||
};
|
};
|
||||||
|
|
||||||
String to_class_name(VBWidgetType);
|
String to_class_name(VBWidgetType);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue